kdiff3.cpp 42.5 KB
Newer Older
Joachim Eibl's avatar
Joachim Eibl committed
1
2
3
4
/***************************************************************************
                          kdiff3.cpp  -  description
                             -------------------
    begin                : Don Jul 11 12:31:29 CEST 2002
Joachim Eibl's avatar
Joachim Eibl committed
5
    copyright            : (C) 2002-2007 by Joachim Eibl
Joachim Eibl's avatar
Joachim Eibl committed
6
    email                : joachim.eibl at gmx.de
Joachim Eibl's avatar
Joachim Eibl committed
7
8
9
10
11
12
13
14
15
16
17
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

Joachim Eibl's avatar
Joachim Eibl committed
18
19
#include "difftextwindow.h"
#include "mergeresultwindow.h"
Joachim Eibl's avatar
Joachim Eibl committed
20

21
#include <cassert>
Joachim Eibl's avatar
Joachim Eibl committed
22
23

// include files for QT
Joachim Eibl's avatar
Joachim Eibl committed
24
25
26
27
28
29
30
#include <QDir>
#include <QPrinter>
#include <QPainter>
#include <QSplitter>
#include <QLineEdit>
#include <QCheckBox>
#include <QPushButton>
Joachim Eibl's avatar
Joachim Eibl committed
31
32
33
34
35
36
#include <QMenu>
#include <QLabel>
#include <QTextEdit>
#include <QLayout>
#include <QPaintDevice>
#include <QStatusBar>
Joachim Eibl's avatar
Joachim Eibl committed
37
#include <QDesktopWidget>
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
38
#include <QPrinter>
Joachim Eibl's avatar
Joachim Eibl committed
39
#include <QPrintDialog>
Joachim Eibl's avatar
Joachim Eibl committed
40
41
42
43
44

// include files for KDE
#include <kiconloader.h>
#include <kmessagebox.h>
#include <kfiledialog.h>
Michael Reeves's avatar
Michael Reeves committed
45
#include <QMenuBar>
Joachim Eibl's avatar
Joachim Eibl committed
46
47
48
#include <kstatusbar.h>
#include <klocale.h>
#include <kconfig.h>
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
49
#include <kstandardaction.h>
Joachim Eibl's avatar
Joachim Eibl committed
50
51
#include <kcmdlineargs.h>
//#include <kkeydialog.h>
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
52
53
54
55
56
#include <kglobal.h>
#include <ktoggleaction.h>
#include <ktoolbar.h>
#include <kiconloader.h>
#include <kactioncollection.h>
Michael Reeves's avatar
Michael Reeves committed
57
#include <KConfigGroup>
Joachim Eibl's avatar
Joachim Eibl committed
58
59
60
61
62

// application specific includes
#include "kdiff3.h"
#include "optiondialog.h"
#include "fileaccess.h"
63
#include "progress.h"
Joachim Eibl's avatar
Joachim Eibl committed
64
65
#include "kdiff3_part.h"
#include "directorymergewindow.h"
Joachim Eibl's avatar
Joachim Eibl committed
66
#include "smalldialogs.h"
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
67
#include "guiutils.h" // namespace KDiff3
Joachim Eibl's avatar
Joachim Eibl committed
68
69

#define ID_STATUS_MSG 1
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
70
#define MAIN_TOOLBAR_NAME "mainToolBar"
Joachim Eibl's avatar
Joachim Eibl committed
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93

KActionCollection* KDiff3App::actionCollection()
{
   if ( m_pKDiff3Shell==0 )
      return m_pKDiff3Part->actionCollection();
   else
      return m_pKDiff3Shell->actionCollection();
}

KStatusBar* KDiff3App::statusBar()
{
   if ( m_pKDiff3Shell==0 )
      return 0;
   else
      return m_pKDiff3Shell->statusBar();
}

KToolBar* KDiff3App::toolBar(const char* toolBarId )
{
   if ( m_pKDiff3Shell==0 )
      return 0;
   else
      return m_pKDiff3Shell->toolBar( toolBarId );
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
94
//return m_pKDiff3Shell->toolBar();
Joachim Eibl's avatar
Joachim Eibl committed
95
96
97
98
99
100
101
}

bool KDiff3App::isPart()
{
   return m_pKDiff3Shell==0;
}

Joachim Eibl's avatar
Joachim Eibl committed
102
103
104
105
bool KDiff3App::isFileSaved()
{
   return m_bFileSaved;
}
Joachim Eibl's avatar
Joachim Eibl committed
106

Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
107
108
109
110
111
bool KDiff3App::isDirComparison()
{
   return m_bDirCompare;
}

Joachim Eibl's avatar
Joachim Eibl committed
112
KDiff3App::KDiff3App(QWidget* pParent, const char* /*name*/, KDiff3Part* pKDiff3Part )
Joachim Eibl's avatar
Joachim Eibl committed
113
   : QSplitter(pParent)  //previously KMainWindow
Joachim Eibl's avatar
Joachim Eibl committed
114
{
Joachim Eibl's avatar
Joachim Eibl committed
115
   setObjectName( "KDiff3App" );
Joachim Eibl's avatar
Joachim Eibl committed
116
   m_pKDiff3Part = pKDiff3Part;
117
   m_pKDiff3Shell = qobject_cast<KParts::MainWindow*>(pParent);
Joachim Eibl's avatar
Joachim Eibl committed
118

Joachim Eibl's avatar
Joachim Eibl committed
119
120
   setWindowTitle( "KDiff3" );
   setOpaqueResize(false); // faster resizing
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
121
   setUpdatesEnabled(false);
Joachim Eibl's avatar
Joachim Eibl committed
122
123

   m_pMainSplitter = 0;
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
124
   m_pDirectoryMergeSplitter = 0;
Joachim Eibl's avatar
Joachim Eibl committed
125
126
127
128
129
130
   m_pDirectoryMergeWindow = 0;
   m_pCornerWidget = 0;
   m_pMainWidget = 0;
   m_pDiffTextWindow1 = 0;
   m_pDiffTextWindow2 = 0;
   m_pDiffTextWindow3 = 0;
Joachim Eibl's avatar
Joachim Eibl committed
131
132
133
   m_pDiffTextWindowFrame1 = 0;
   m_pDiffTextWindowFrame2 = 0;
   m_pDiffTextWindowFrame3 = 0;
Joachim Eibl's avatar
Joachim Eibl committed
134
135
136
137
138
139
   m_pDiffWindowSplitter = 0;
   m_pOverview        = 0;
   m_bTripleDiff = false;
   m_pMergeResultWindow = 0;
   m_pMergeWindowFrame = 0;
   m_bOutputModified = false;
Joachim Eibl's avatar
Joachim Eibl committed
140
   m_bFileSaved = false;
Joachim Eibl's avatar
Joachim Eibl committed
141
   m_bTimerBlock = false;
Joachim Eibl's avatar
Joachim Eibl committed
142
   m_pHScrollBar = 0;
143
144
   m_pDiffVScrollBar = 0;
   m_pMergeVScrollBar = 0;
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
145
   viewToolBar = 0;
146
   m_bRecalcWordWrapPosted = false;
Joachim Eibl's avatar
Joachim Eibl committed
147

Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
148
   // Needed before any file operations via FileAccess happen.
Joachim Eibl's avatar
Joachim Eibl committed
149
   if (!g_pProgressDialog)
Joachim Eibl's avatar
Joachim Eibl committed
150
   {
Joachim Eibl's avatar
Joachim Eibl committed
151
      g_pProgressDialog = new ProgressDialog(0);
Joachim Eibl's avatar
Joachim Eibl committed
152
153
      g_pProgressDialog->setStayHidden( true );
   }
Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
154

Joachim Eibl's avatar
Joachim Eibl committed
155
156
   // All default values must be set before calling readOptions().
   m_pOptionDialog = new OptionDialog( m_pKDiff3Shell!=0, this );
157
   connect(m_pOptionDialog, &OptionDialog::applyDone, this, &KDiff3App::slotRefresh);
Joachim Eibl's avatar
Joachim Eibl committed
158

159
160
161
   // This is just a convenience variable to make code that accesses options more readable
   m_pOptions = &m_pOptionDialog->m_options;

Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
162
   m_pOptionDialog->readOptions( isPart() ? m_pKDiff3Part->componentData().config() : KGlobal::config() );
Joachim Eibl's avatar
Joachim Eibl committed
163

Joachim Eibl's avatar
Joachim Eibl committed
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
   // Option handling: Only when pParent==0 (no parent)
   KCmdLineArgs *args = isPart() ? 0 : KCmdLineArgs::parsedArgs();

   if (args)
   {
      QString s;
      QString title;
      if ( args->isSet("confighelp") )
      {
         s = m_pOptionDialog->calcOptionHelp();
         title = i18n("Current Configuration:");
      }
      else
      {
         s = m_pOptionDialog->parseOptions( args->getOptionList("cs") );
         title = i18n("Config Option Error:");
      }
      if (!s.isEmpty())
      {
Joachim Eibl's avatar
Joachim Eibl committed
183
#if defined(_WIN32) || defined(Q_OS_OS2) 
Joachim Eibl's avatar
Joachim Eibl committed
184
185
         // A windows program has no console
         //KMessageBox::information(0, s,i18n("KDiff3-Usage"));
Joachim Eibl's avatar
Joachim Eibl committed
186
187
188
189
190
191
         QDialog* pDialog = new QDialog(this);
         pDialog->setAttribute( Qt::WA_DeleteOnClose );
         pDialog->setModal( true );
         pDialog->setWindowTitle(title);
         QVBoxLayout* pVBoxLayout = new QVBoxLayout( pDialog );
         QTextEdit* pTextEdit = new QTextEdit(pDialog);
Joachim Eibl's avatar
Joachim Eibl committed
192
193
         pTextEdit->setText(s);
         pTextEdit->setReadOnly(true);
Joachim Eibl's avatar
Joachim Eibl committed
194
         pTextEdit->setWordWrapMode(QTextOption::NoWrap);
Joachim Eibl's avatar
Joachim Eibl committed
195
196
197
198
         pVBoxLayout->addWidget(pTextEdit);
         pDialog->resize(600,400);
         pDialog->exec();
#else
199
200
         fprintf(stderr, "%s\n", title.toLatin1().constData());
         fprintf(stderr, "%s\n", s.toLatin1().constData());
Joachim Eibl's avatar
Joachim Eibl committed
201
202
203
204
205
#endif
         exit(1);
      }
   }

206
207
208
   m_sd1.setOptions(m_pOptions);
   m_sd2.setOptions(m_pOptions);
   m_sd3.setOptions(m_pOptions);
Joachim Eibl's avatar
Joachim Eibl committed
209

Joachim Eibl's avatar
Joachim Eibl committed
210
211
212
213
214
   if (args!=0)
   {
      m_outputFilename = args->getOption("output");
      if ( m_outputFilename.isEmpty() )
         m_outputFilename = args->getOption("out");
215
216
      if ( ! m_outputFilename.isEmpty() )
         m_outputFilename = FileAccess( m_outputFilename, true ).absoluteFilePath();
Joachim Eibl's avatar
Joachim Eibl committed
217
   }
Michael Reeves's avatar
Michael Reeves committed
218
219
  
   m_bAutoFlag = false;//disable --auto option git hard codes this unwanted flag.
220
   m_bAutoMode = m_bAutoFlag || m_pOptions->m_bAutoSaveAndQuitOnMergeWithoutConflicts;
Joachim Eibl's avatar
Joachim Eibl committed
221
   if ( m_bAutoMode && m_outputFilename.isEmpty() )
Joachim Eibl's avatar
Joachim Eibl committed
222
   {
Joachim Eibl's avatar
Joachim Eibl committed
223
224
225
      if ( m_bAutoFlag )
      {
         //KMessageBox::information(this, i18n("Option --auto used, but no output file specified."));
226
         fprintf(stderr, "%s\n", (const char*)i18n("Option --auto used, but no output file specified.").toLatin1());
Joachim Eibl's avatar
Joachim Eibl committed
227
228
      }
      m_bAutoMode = false;
Joachim Eibl's avatar
Joachim Eibl committed
229
   }
Joachim Eibl's avatar
Joachim Eibl committed
230
   g_pProgressDialog->setStayHidden( m_bAutoMode );
Joachim Eibl's avatar
Joachim Eibl committed
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246

   if ( m_outputFilename.isEmpty() && args!=0 && args->isSet("merge") )
   {
      m_outputFilename = "unnamed.txt";
      m_bDefaultFilename = true;
   }
   else
      m_bDefaultFilename = false;

   g_bAutoSolve = args!=0 && !args->isSet("qall");  // Note that this is effective only once.

   if ( args!=0 )
   {
      m_sd1.setFilename( args->getOption("base") );
      if ( m_sd1.isEmpty() )
      {
Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
247
248
249
         if ( args->count() > 0 ) m_sd1.setFilename( args->url(0).url() ); // args->arg(0)
         if ( args->count() > 1 ) m_sd2.setFilename( args->url(1).url() );
         if ( args->count() > 2 ) m_sd3.setFilename( args->url(2).url() );
Joachim Eibl's avatar
Joachim Eibl committed
250
251
252
      }
      else
      {
Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
253
254
         if ( args->count() > 0 ) m_sd2.setFilename( args->url(0).url() );
         if ( args->count() > 1 ) m_sd3.setFilename( args->url(1).url() );
Joachim Eibl's avatar
Joachim Eibl committed
255
256
      }

Joachim Eibl's avatar
Joachim Eibl committed
257

Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
258
259
      QStringList aliasList = args->getOptionList("fname");
      QStringList::Iterator ali = aliasList.begin();
Joachim Eibl's avatar
Joachim Eibl committed
260

Joachim Eibl's avatar
0.9.86    
Joachim Eibl committed
261
262
263
      QString an1 = args->getOption("L1");
      if ( !an1.isEmpty() )              { m_sd1.setAliasName(an1);         }
      else if ( ali != aliasList.end() ) { m_sd1.setAliasName(*ali); ++ali; }
Joachim Eibl's avatar
Joachim Eibl committed
264

Joachim Eibl's avatar
0.9.86    
Joachim Eibl committed
265
266
267
      QString an2 = args->getOption("L2");
      if ( !an2.isEmpty() )              { m_sd2.setAliasName(an2);         }
      else if ( ali != aliasList.end() ) { m_sd2.setAliasName(*ali); ++ali; }
Joachim Eibl's avatar
Joachim Eibl committed
268

Joachim Eibl's avatar
0.9.86    
Joachim Eibl committed
269
270
271
      QString an3 = args->getOption("L3");
      if ( !an3.isEmpty() )              { m_sd3.setAliasName(an3);         }
      else if ( ali != aliasList.end() ) { m_sd3.setAliasName(*ali); ++ali; }
Joachim Eibl's avatar
Joachim Eibl committed
272
   }
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
273

Joachim Eibl's avatar
Joachim Eibl committed
274
275
276
277
278
279
   ///////////////////////////////////////////////////////////////////
   // call inits to invoke all other construction parts
   initActions(actionCollection());
   initStatusBar();

   m_pFindDialog = new FindDialog( this );
280
   connect(m_pFindDialog, &FindDialog::findNext, this, &KDiff3App::slotEditFindNext);
Joachim Eibl's avatar
Joachim Eibl committed
281

282
283
284
285
286
287
   autoAdvance->setChecked( m_pOptions->m_bAutoAdvance );
   showWhiteSpaceCharacters->setChecked( m_pOptions->m_bShowWhiteSpaceCharacters );
   showWhiteSpace->setChecked( m_pOptions->m_bShowWhiteSpace );
   showWhiteSpaceCharacters->setEnabled( m_pOptions->m_bShowWhiteSpace );
   showLineNumbers->setChecked( m_pOptions->m_bShowLineNumbers );
   wordWrap->setChecked( m_pOptions->m_bWordWrap );
Joachim Eibl's avatar
Joachim Eibl committed
288
289
   if ( ! isPart() )
   {
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
290
//  TODO 
291
//       viewToolBar->setChecked( m_pOptions->m_bShowToolBar );
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
292
293
//       slotViewToolBar();

294
      viewStatusBar->setChecked( m_pOptions->m_bShowStatusBar );
Joachim Eibl's avatar
Joachim Eibl committed
295
      slotViewStatusBar();
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
296
297
298
299
/*
   vrusu - commented out as new KToolBar does not hase setParPos
   TODO figure out how to restore bar position
      if( toolBar(MAIN_TOOLBAR_NAME)!=0 )
300
301
302
         toolBar(MAIN_TOOLBAR_NAME)->setBarPos( (KToolBar::BarPosition) m_pOptions->m_toolBarPos );*/
/*      QSize size = m_pOptions->m_geometry;
      QPoint pos = m_pOptions->m_position;
Joachim Eibl's avatar
Joachim Eibl committed
303
304
305
306
307
308
309
310
311
      if(!size.isEmpty())
      {
         m_pKDiff3Shell->resize( size );
         QRect visibleRect = QRect( pos, size ) & QApplication::desktop()->rect();
         if ( visibleRect.width()>100 && visibleRect.height()>100 )
            m_pKDiff3Shell->move( pos );
      }*/
   }
   slotRefresh();
Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
312

Joachim Eibl's avatar
Joachim Eibl committed
313
   m_pMainSplitter = this; //new QSplitter(this);
Joachim Eibl's avatar
Joachim Eibl committed
314
   m_pMainSplitter->setOrientation( Qt::Vertical );
Joachim Eibl's avatar
Joachim Eibl committed
315
316
//   setCentralWidget( m_pMainSplitter );
   m_pDirectoryMergeSplitter = new QSplitter( m_pMainSplitter );
Joachim Eibl's avatar
Joachim Eibl committed
317
   m_pDirectoryMergeSplitter->setObjectName("DirectoryMergeSplitter");
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
318
   m_pMainSplitter->addWidget( m_pDirectoryMergeSplitter );
Joachim Eibl's avatar
Joachim Eibl committed
319
   m_pDirectoryMergeSplitter->setOrientation( Qt::Horizontal );
320
   m_pDirectoryMergeWindow = new DirectoryMergeWindow( m_pDirectoryMergeSplitter, m_pOptions,
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
321
322
      KIconLoader::global() );
   m_pDirectoryMergeSplitter->addWidget(m_pDirectoryMergeWindow);
Joachim Eibl's avatar
Joachim Eibl committed
323
324
   m_pDirectoryMergeInfo = new DirectoryMergeInfo( m_pDirectoryMergeSplitter );
   m_pDirectoryMergeWindow->setDirectoryMergeInfo( m_pDirectoryMergeInfo );
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
325
326
   m_pDirectoryMergeSplitter->addWidget(m_pDirectoryMergeInfo);

327
   connect(m_pDirectoryMergeWindow, &DirectoryMergeWindow::startDiffMerge, this, &KDiff3App::slotFileOpen2);
328
329
   connect( m_pDirectoryMergeWindow->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)), this, SLOT(slotUpdateAvailabilities()));
   connect( m_pDirectoryMergeWindow->selectionModel(), SIGNAL(currentChanged(const QModelIndex&,const QModelIndex&)), this, SLOT(slotUpdateAvailabilities()));
330
331
332
   connect(m_pDirectoryMergeWindow, &DirectoryMergeWindow::checkIfCanContinue, this, &KDiff3App::slotCheckIfCanContinue);
   connect(m_pDirectoryMergeWindow, &DirectoryMergeWindow::updateAvailabilities, this, &KDiff3App::slotUpdateAvailabilities);
   connect(m_pDirectoryMergeWindow, &DirectoryMergeWindow::statusBarMessage, this, &KDiff3App::slotStatusMsg);
Joachim Eibl's avatar
Joachim Eibl committed
333

Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
334
   m_pDirectoryMergeWindow->initDirectoryMergeActions( this, actionCollection() );
Joachim Eibl's avatar
Joachim Eibl committed
335
336
337
338
339
340
341
342
343
344

   if ( args!=0 )  args->clear(); // Free up some memory.

   if (m_pKDiff3Shell==0)
   {
      completeInit();
   }
}


Joachim Eibl's avatar
Joachim Eibl committed
345
void KDiff3App::completeInit( const QString& fn1, const QString& fn2, const QString& fn3 )
Joachim Eibl's avatar
Joachim Eibl committed
346
347
348
{
   if (m_pKDiff3Shell!=0)
   {
349
350
      QSize size=m_pOptions->m_geometry;
      QPoint pos=m_pOptions->m_position;
Joachim Eibl's avatar
Joachim Eibl committed
351
352
353
      if(!size.isEmpty())
      {
         m_pKDiff3Shell->resize( size );
Joachim Eibl's avatar
Joachim Eibl committed
354

Joachim Eibl's avatar
Joachim Eibl committed
355
356
357
         QRect visibleRect = QRect( pos, size ) & QApplication::desktop()->rect();
         if ( visibleRect.width()>100 && visibleRect.height()>100 )
            m_pKDiff3Shell->move( pos );
Joachim Eibl's avatar
Joachim Eibl committed
358
         if (!m_bAutoMode)
Joachim Eibl's avatar
Joachim Eibl committed
359
         {
360
            if ( m_pOptions->m_bMaximised )
Joachim Eibl's avatar
Joachim Eibl committed
361
362
363
364
               m_pKDiff3Shell->showMaximized();
            else
               m_pKDiff3Shell->show();
         }
Joachim Eibl's avatar
Joachim Eibl committed
365
366
      }
   }
Joachim Eibl's avatar
Joachim Eibl committed
367
368
369
   if ( ! fn1.isEmpty() )  { m_sd1.setFilename(fn1); }
   if ( ! fn2.isEmpty() )  { m_sd2.setFilename(fn2); }
   if ( ! fn3.isEmpty() )  { m_sd3.setFilename(fn3); }
Joachim Eibl's avatar
Joachim Eibl committed
370

Joachim Eibl's avatar
Joachim Eibl committed
371
   bool bSuccess = improveFilenames(false);
Joachim Eibl's avatar
Joachim Eibl committed
372

Joachim Eibl's avatar
Joachim Eibl committed
373
   if ( m_bAutoFlag && m_bAutoMode && m_bDirCompare )
Joachim Eibl's avatar
Joachim Eibl committed
374
   {
375
      fprintf(stderr, "%s\n", (const char*)i18n("Option --auto ignored for directory comparison.").toLatin1());
Joachim Eibl's avatar
Joachim Eibl committed
376
      m_bAutoMode = false;
Joachim Eibl's avatar
Joachim Eibl committed
377
378
379
380
381
   }
   if (!m_bDirCompare)
   {
      m_pDirectoryMergeSplitter->hide();

Joachim Eibl's avatar
Joachim Eibl committed
382
383
      init( m_bAutoMode );
      if ( m_bAutoMode )
Joachim Eibl's avatar
Joachim Eibl committed
384
      {
Joachim Eibl's avatar
Joachim Eibl committed
385
         SourceData* pSD=0;
Joachim Eibl's avatar
Joachim Eibl committed
386
387
         if ( m_sd3.isEmpty() )
         {
Joachim Eibl's avatar
Joachim Eibl committed
388
            if ( m_totalDiffStatus.bBinaryAEqB ){ pSD = &m_sd1; }
Joachim Eibl's avatar
Joachim Eibl committed
389
390
391
         }
         else
         {
Joachim Eibl's avatar
Joachim Eibl committed
392
393
394
            if      ( m_totalDiffStatus.bBinaryBEqC ){ pSD = &m_sd3; } // B==C (assume A is old)
            else if ( m_totalDiffStatus.bBinaryAEqB ){ pSD = &m_sd3; } // assuming C has changed
            else if ( m_totalDiffStatus.bBinaryAEqC ){ pSD = &m_sd2; } // assuming B has changed
Joachim Eibl's avatar
Joachim Eibl committed
395
396
         }

Joachim Eibl's avatar
Joachim Eibl committed
397
         if ( pSD!=0 )
Joachim Eibl's avatar
Joachim Eibl committed
398
399
400
         {
            // Save this file directly, not via the merge result window.
            bool bSuccess = false;
Joachim Eibl's avatar
Joachim Eibl committed
401
            FileAccess fa( m_outputFilename );
402
            if ( m_pOptions->m_bDmCreateBakFiles && fa.exists() )
Joachim Eibl's avatar
Joachim Eibl committed
403
404
            {
               QString newName = m_outputFilename + ".orig";
Joachim Eibl's avatar
Joachim Eibl committed
405
406
               if ( FileAccess::exists( newName ) ) FileAccess::removeFile( newName );
               if ( !FileAccess::exists( newName ) ) fa.rename( newName );
Joachim Eibl's avatar
Joachim Eibl committed
407
            }
Joachim Eibl's avatar
Joachim Eibl committed
408

Joachim Eibl's avatar
Joachim Eibl committed
409
            bSuccess = pSD->saveNormalDataAs( m_outputFilename );
Joachim Eibl's avatar
Joachim Eibl committed
410
411
412
413
414
            if ( bSuccess ) ::exit(0);
            else KMessageBox::error( this, i18n("Saving failed.") );
         }
         else if ( m_pMergeResultWindow->getNrOfUnsolvedConflicts() == 0 )
         {
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
415
            bool bSuccess = m_pMergeResultWindow->saveDocument( m_pMergeResultWindowTitle->getFileName(), m_pMergeResultWindowTitle->getEncoding(), m_pMergeResultWindowTitle->getLineEndStyle() );
Joachim Eibl's avatar
Joachim Eibl committed
416
417
418
419
            if ( bSuccess ) ::exit(0);
         }
      }
   }
Joachim Eibl's avatar
Joachim Eibl committed
420
   m_bAutoMode = false;
Joachim Eibl's avatar
Joachim Eibl committed
421

Joachim Eibl's avatar
Joachim Eibl committed
422
   if (m_pKDiff3Shell)
Joachim Eibl's avatar
Joachim Eibl committed
423
   {
424
      if ( m_pOptions->m_bMaximised )
Joachim Eibl's avatar
Joachim Eibl committed
425
426
427
428
429
430
         m_pKDiff3Shell->showMaximized();
      else
         m_pKDiff3Shell->show();
   }

   g_pProgressDialog->setStayHidden( false );
Joachim Eibl's avatar
Joachim Eibl committed
431

Joachim Eibl's avatar
Joachim Eibl committed
432
   if (statusBar() !=0 )
Joachim Eibl's avatar
Joachim Eibl committed
433
      statusBar()->setSizeGripEnabled(true);
Joachim Eibl's avatar
Joachim Eibl committed
434
435
436
437
438
439
440
441

   slotClipboardChanged(); // For initialisation.

   slotUpdateAvailabilities();

   if ( ! m_bDirCompare  &&  m_pKDiff3Shell!=0 )
   {
      bool bFileOpenError = false;
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
442
443
444
      if ( (! m_sd1.isEmpty() && !m_sd1.hasData())  ||
           (! m_sd2.isEmpty() && !m_sd2.hasData())  ||
           (! m_sd3.isEmpty() && !m_sd3.hasData()) )
Joachim Eibl's avatar
Joachim Eibl committed
445
446
447
      {
         QString text( i18n("Opening of these files failed:") );
         text += "\n\n";
Joachim Eibl's avatar
Joachim Eibl committed
448
         if ( ! m_sd1.isEmpty() && !m_sd1.hasData() )
Joachim Eibl's avatar
Joachim Eibl committed
449
            text += " - " + m_sd1.getAliasName() + "\n";
Joachim Eibl's avatar
Joachim Eibl committed
450
         if ( ! m_sd2.isEmpty() && !m_sd2.hasData() )
Joachim Eibl's avatar
Joachim Eibl committed
451
            text += " - " + m_sd2.getAliasName() + "\n";
Joachim Eibl's avatar
Joachim Eibl committed
452
         if ( ! m_sd3.isEmpty() && !m_sd3.hasData() )
Joachim Eibl's avatar
Joachim Eibl committed
453
454
            text += " - " + m_sd3.getAliasName() + "\n";

Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
455
         KMessageBox::sorry( this, text, i18n("File Open Error") );
Joachim Eibl's avatar
Joachim Eibl committed
456
457
458
459
460
461
         bFileOpenError = true;
      }

      if ( m_sd1.isEmpty() || m_sd2.isEmpty() || bFileOpenError )
         slotFileOpen();
   }
Joachim Eibl's avatar
0.9.86    
Joachim Eibl committed
462
463
464
465
   else if ( !bSuccess )  // Directory open failed
   {
      slotFileOpen();
   }
Joachim Eibl's avatar
Joachim Eibl committed
466
467
468
469
470
471
472
}

KDiff3App::~KDiff3App()
{

}

Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
473
474
475
476
/**
 * Helper function used to create actions into the ac collection
 */

Joachim Eibl's avatar
Joachim Eibl committed
477
478
void KDiff3App::initActions( KActionCollection* ac )
{
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
479
480
481
482
483
484
   if (ac==0)
      KMessageBox::error(0, "actionCollection==0");

   fileOpen = KStandardAction::open(this, SLOT(slotFileOpen()), ac);
   fileOpen->setStatusTip(i18n("Opens documents for comparison..."));

Michael Reeves's avatar
Michael Reeves committed
485
   fileReload = KDiff3::createAction< QAction >( i18n("Reload"), KShortcut( Qt::Key_F5 ), this, SLOT(slotReload()), ac, "file_reload" );
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
486
487
488
489
490

   fileSave = KStandardAction::save(this, SLOT(slotFileSave()), ac);
   fileSave->setStatusTip(i18n("Saves the merge result. All conflicts must be solved!"));
   fileSaveAs = KStandardAction::saveAs(this, SLOT(slotFileSaveAs()), ac);
   fileSaveAs->setStatusTip(i18n("Saves the current document as..."));
Joachim Eibl's avatar
Joachim Eibl committed
491
#ifndef QT_NO_PRINTER
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
492
493
   filePrint = KStandardAction::print(this, SLOT(slotFilePrint()), ac);
   filePrint->setStatusTip(i18n("Print the differences"));
Joachim Eibl's avatar
Joachim Eibl committed
494
#endif
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
495
496
497
498
499
500
501
   fileQuit = KStandardAction::quit(this, SLOT(slotFileQuit()), ac);
   fileQuit->setStatusTip(i18n("Quits the application"));
   editCut = KStandardAction::cut(this, SLOT(slotEditCut()), ac);
   editCut->setStatusTip(i18n("Cuts the selected section and puts it to the clipboard"));
   editCopy = KStandardAction::copy(this, SLOT(slotEditCopy()), ac);
   editCopy->setStatusTip(i18n("Copies the selected section to the clipboard"));
   editPaste = KStandardAction::paste(this, SLOT(slotEditPaste()), ac);
Joachim Eibl's avatar
Joachim Eibl committed
502
   editPaste->setStatusTip(i18n("Pastes the clipboard contents to current position"));
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
503
504
505
506
507
508
509
510
511
512
513
514
   editSelectAll = KStandardAction::selectAll(this, SLOT(slotEditSelectAll()), ac);
   editSelectAll->setStatusTip(i18n("Select everything in current window"));
   editFind = KStandardAction::find(this, SLOT(slotEditFind()), ac);
   editFind->setStatusTip(i18n("Search for a string"));
   editFindNext = KStandardAction::findNext(this, SLOT(slotEditFindNext()), ac);
   editFindNext->setStatusTip(i18n("Search again for the string"));
/*   FIXME figure out how to implement this action
   viewToolBar = KStandardAction::showToolbar(this, SLOT(slotViewToolBar()), ac);
   viewToolBar->setStatusTip(i18n("Enables/disables the toolbar")); */
   viewStatusBar = KStandardAction::showStatusbar(this, SLOT(slotViewStatusBar()), ac);
   viewStatusBar->setStatusTip(i18n("Enables/disables the statusbar"));
   KStandardAction::keyBindings(this, SLOT(slotConfigureKeys()), ac);
Michael Reeves's avatar
Michael Reeves committed
515
   QAction * pAction = KStandardAction::preferences(this, SLOT(slotConfigure()), ac );
Joachim Eibl's avatar
Joachim Eibl committed
516
   if ( isPart() )
Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
517
      pAction->setText(i18n("Configure KDiff3..."));
Joachim Eibl's avatar
Joachim Eibl committed
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533


#include "xpm/downend.xpm"
#include "xpm/currentpos.xpm"
#include "xpm/down1arrow.xpm"
#include "xpm/down2arrow.xpm"
#include "xpm/upend.xpm"
#include "xpm/up1arrow.xpm"
#include "xpm/up2arrow.xpm"
#include "xpm/prevunsolved.xpm"
#include "xpm/nextunsolved.xpm"
#include "xpm/iconA.xpm"
#include "xpm/iconB.xpm"
#include "xpm/iconC.xpm"
#include "xpm/autoadvance.xpm"
#include "xpm/showwhitespace.xpm"
Joachim Eibl's avatar
Joachim Eibl committed
534
#include "xpm/showwhitespacechars.xpm"
Joachim Eibl's avatar
Joachim Eibl committed
535
536
537
#include "xpm/showlinenumbers.xpm"
//#include "reload.xpm"

Michael Reeves's avatar
Michael Reeves committed
538
   goCurrent = KDiff3::createAction< QAction >( i18n("Go to Current Delta"), QIcon(QPixmap(currentpos)), i18n("Current\nDelta"), KShortcut( Qt::CTRL+Qt::Key_Space ), this, SLOT(slotGoCurrent()), ac, "go_current");
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
539

Michael Reeves's avatar
Michael Reeves committed
540
   goTop = KDiff3::createAction< QAction >(i18n("Go to First Delta"), QIcon(QPixmap(upend)), i18n("First\nDelta"), this, SLOT(slotGoTop()), ac, "go_top");
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
541

Michael Reeves's avatar
Michael Reeves committed
542
   goBottom = KDiff3::createAction< QAction >(i18n("Go to Last Delta"), QIcon(QPixmap(downend)), i18n("Last\nDelta"), this, SLOT(slotGoBottom()), ac, "go_bottom");
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
543

Joachim Eibl's avatar
Joachim Eibl committed
544
   QString omitsWhitespace = ".\n" + i18n("(Skips white space differences when \"Show White Space\" is disabled.)");
Joachim Eibl's avatar
Joachim Eibl committed
545
   QString includeWhitespace = ".\n" + i18n("(Does not skip white space differences even when \"Show White Space\" is disabled.)");
Michael Reeves's avatar
Michael Reeves committed
546
   goPrevDelta = KDiff3::createAction< QAction >(i18n("Go to Previous Delta"), QIcon(QPixmap(up1arrow)), i18n("Prev\nDelta"), KShortcut( Qt::CTRL+Qt::Key_Up), this, SLOT(slotGoPrevDelta()), ac, "go_prev_delta");
Joachim Eibl's avatar
Joachim Eibl committed
547
   goPrevDelta->setToolTip( goPrevDelta->text() + omitsWhitespace );
Michael Reeves's avatar
Michael Reeves committed
548
   goNextDelta = KDiff3::createAction< QAction >(i18n("Go to Next Delta"), QIcon(QPixmap(down1arrow)), i18n("Next\nDelta"), KShortcut( Qt::CTRL+Qt::Key_Down ), this, SLOT(slotGoNextDelta()), ac, "go_next_delta");
Joachim Eibl's avatar
Joachim Eibl committed
549
   goNextDelta->setToolTip( goNextDelta->text() + omitsWhitespace );
Michael Reeves's avatar
Michael Reeves committed
550
   goPrevConflict = KDiff3::createAction< QAction >(i18n("Go to Previous Conflict"), QIcon(QPixmap(up2arrow)), i18n("Prev\nConflict"), KShortcut( Qt::CTRL+Qt::Key_PageUp ), this, SLOT(slotGoPrevConflict()), ac, "go_prev_conflict");
Joachim Eibl's avatar
Joachim Eibl committed
551
   goPrevConflict->setToolTip( goPrevConflict->text() + omitsWhitespace );
Michael Reeves's avatar
Michael Reeves committed
552
   goNextConflict = KDiff3::createAction< QAction >(i18n("Go to Next Conflict"), QIcon(QPixmap(down2arrow)), i18n("Next\nConflict"), KShortcut( Qt::CTRL+Qt::Key_PageDown ), this, SLOT(slotGoNextConflict()), ac, "go_next_conflict");
Joachim Eibl's avatar
Joachim Eibl committed
553
   goNextConflict->setToolTip( goNextConflict->text() + omitsWhitespace );
Michael Reeves's avatar
Michael Reeves committed
554
   goPrevUnsolvedConflict = KDiff3::createAction< QAction >(i18n("Go to Previous Unsolved Conflict"), QIcon(QPixmap(prevunsolved)), i18n("Prev\nUnsolved"), this, SLOT(slotGoPrevUnsolvedConflict()), ac, "go_prev_unsolved_conflict");
Joachim Eibl's avatar
Joachim Eibl committed
555
   goPrevUnsolvedConflict->setToolTip( goPrevUnsolvedConflict->text() + includeWhitespace );
Michael Reeves's avatar
Michael Reeves committed
556
   goNextUnsolvedConflict = KDiff3::createAction< QAction >(i18n("Go to Next Unsolved Conflict"), QIcon(QPixmap(nextunsolved)), i18n("Next\nUnsolved"), this, SLOT(slotGoNextUnsolvedConflict()), ac, "go_next_unsolved_conflict");
Joachim Eibl's avatar
Joachim Eibl committed
557
   goNextUnsolvedConflict->setToolTip( goNextUnsolvedConflict->text() + includeWhitespace );
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
558
559
560
561
562
   chooseA = KDiff3::createAction< KToggleAction >(i18n("Select Line(s) From A"), QIcon(QPixmap(iconA)), i18n("Choose\nA"), KShortcut( Qt::CTRL+Qt::Key_1 ), this, SLOT(slotChooseA()), ac, "merge_choose_a");
   chooseB = KDiff3::createAction< KToggleAction >(i18n("Select Line(s) From B"), QIcon(QPixmap(iconB)), i18n("Choose\nB"), KShortcut( Qt::CTRL+Qt::Key_2 ), this, SLOT(slotChooseB()), ac, "merge_choose_b");
   chooseC = KDiff3::createAction< KToggleAction >(i18n("Select Line(s) From C"), QIcon(QPixmap(iconC)), i18n("Choose\nC"), KShortcut( Qt::CTRL+Qt::Key_3 ), this, SLOT(slotChooseC()), ac, "merge_choose_c");
   autoAdvance = KDiff3::createAction< KToggleAction >(i18n("Automatically Go to Next Unsolved Conflict After Source Selection"), QIcon(QPixmap(autoadvance)), i18n("Auto\nNext"), this, SLOT(slotAutoAdvanceToggled()), ac, "merge_autoadvance");

563
   showWhiteSpaceCharacters = KDiff3::createAction< KToggleAction >(i18n("Show Space && Tabulator Characters"), QIcon(QPixmap(showwhitespacechars)), i18n("White\nCharacters"), this, SLOT(slotShowWhiteSpaceToggled()), ac, "diff_show_whitespace_characters");
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
564
565
566
   showWhiteSpace = KDiff3::createAction< KToggleAction >(i18n("Show White Space"), QIcon(QPixmap(showwhitespace)), i18n("White\nDeltas"), this, SLOT(slotShowWhiteSpaceToggled()), ac, "diff_show_whitespace");

   showLineNumbers = KDiff3::createAction< KToggleAction >(i18n("Show Line Numbers"), QIcon(QPixmap(showlinenumbers)), i18n("Line\nNumbers"), this, SLOT(slotShowLineNumbersToggled()), ac, "diff_showlinenumbers");
Michael Reeves's avatar
Michael Reeves committed
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
   chooseAEverywhere = KDiff3::createAction< QAction >(i18n("Choose A Everywhere"), KShortcut( Qt::CTRL+Qt::SHIFT+Qt::Key_1 ), this, SLOT(slotChooseAEverywhere()), ac, "merge_choose_a_everywhere");
   chooseBEverywhere = KDiff3::createAction< QAction >(i18n("Choose B Everywhere"), KShortcut( Qt::CTRL+Qt::SHIFT+Qt::Key_2 ), this, SLOT(slotChooseBEverywhere()), ac, "merge_choose_b_everywhere");
   chooseCEverywhere = KDiff3::createAction< QAction >(i18n("Choose C Everywhere"), KShortcut( Qt::CTRL+Qt::SHIFT+Qt::Key_3 ), this, SLOT(slotChooseCEverywhere()), ac, "merge_choose_c_everywhere");
   chooseAForUnsolvedConflicts = KDiff3::createAction< QAction >(i18n("Choose A for All Unsolved Conflicts"), this, SLOT(slotChooseAForUnsolvedConflicts()), ac, "merge_choose_a_for_unsolved_conflicts");
   chooseBForUnsolvedConflicts = KDiff3::createAction< QAction >(i18n("Choose B for All Unsolved Conflicts"), this, SLOT(slotChooseBForUnsolvedConflicts()), ac, "merge_choose_b_for_unsolved_conflicts");
   chooseCForUnsolvedConflicts = KDiff3::createAction< QAction >(i18n("Choose C for All Unsolved Conflicts"), this, SLOT(slotChooseCForUnsolvedConflicts()), ac, "merge_choose_c_for_unsolved_conflicts");
   chooseAForUnsolvedWhiteSpaceConflicts = KDiff3::createAction< QAction >(i18n("Choose A for All Unsolved Whitespace Conflicts"), this, SLOT(slotChooseAForUnsolvedWhiteSpaceConflicts()), ac, "merge_choose_a_for_unsolved_whitespace_conflicts");
   chooseBForUnsolvedWhiteSpaceConflicts = KDiff3::createAction< QAction >(i18n("Choose B for All Unsolved Whitespace Conflicts"), this, SLOT(slotChooseBForUnsolvedWhiteSpaceConflicts()), ac, "merge_choose_b_for_unsolved_whitespace_conflicts");
   chooseCForUnsolvedWhiteSpaceConflicts = KDiff3::createAction< QAction >(i18n("Choose C for All Unsolved Whitespace Conflicts"), this, SLOT(slotChooseCForUnsolvedWhiteSpaceConflicts()), ac, "merge_choose_c_for_unsolved_whitespace_conflicts");
   autoSolve    = KDiff3::createAction< QAction >(i18n("Automatically Solve Simple Conflicts"),  this, SLOT(slotAutoSolve()),    ac, "merge_autosolve");
   unsolve      = KDiff3::createAction< QAction >(i18n("Set Deltas to Conflicts"),               this, SLOT(slotUnsolve()),      ac, "merge_autounsolve");
   mergeRegExp  = KDiff3::createAction< QAction >(i18n("Run Regular Expression Auto Merge"),     this, SLOT(slotRegExpAutoMerge()),ac, "merge_regexp_automerge" );
   mergeHistory = KDiff3::createAction< QAction >(i18n("Automatically Solve History Conflicts"), this, SLOT(slotMergeHistory()), ac, "merge_versioncontrol_history" );
   splitDiff    = KDiff3::createAction< QAction >(i18n("Split Diff At Selection"),               this, SLOT(slotSplitDiff()),    ac, "merge_splitdiff");
   joinDiffs    = KDiff3::createAction< QAction >(i18n("Join Selected Diffs"),                   this, SLOT(slotJoinDiffs()),    ac, "merge_joindiffs");
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
582
583
584
585

   showWindowA = KDiff3::createAction< KToggleAction >(i18n("Show Window A"), this, SLOT(slotShowWindowAToggled()), ac, "win_show_a");
   showWindowB = KDiff3::createAction< KToggleAction >(i18n("Show Window B"), this, SLOT(slotShowWindowBToggled()), ac, "win_show_b");
   showWindowC = KDiff3::createAction< KToggleAction >(i18n("Show Window C"), this, SLOT(slotShowWindowCToggled()), ac, "win_show_c");
Michael Reeves's avatar
Michael Reeves committed
586
   winFocusNext = KDiff3::createAction< QAction >(i18n("Focus Next Window"), KShortcut( Qt::ALT+Qt::Key_Right ), this, SLOT(slotWinFocusNext()), ac, "win_focus_next");
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
587
588
589
590
591
592

   overviewModeNormal = KDiff3::createAction< KToggleAction >(i18n("Normal Overview"), this, SLOT(slotOverviewNormal()), ac, "diff_overview_normal");
   overviewModeAB     = KDiff3::createAction< KToggleAction >(i18n("A vs. B Overview"), this, SLOT(slotOverviewAB()), ac, "diff_overview_ab");
   overviewModeAC     = KDiff3::createAction< KToggleAction >(i18n("A vs. C Overview"), this, SLOT(slotOverviewAC()), ac, "diff_overview_ac");
   overviewModeBC     = KDiff3::createAction< KToggleAction >(i18n("B vs. C Overview"), this, SLOT(slotOverviewBC()), ac, "diff_overview_bc");
   wordWrap     = KDiff3::createAction< KToggleAction >(i18n("Word Wrap Diff Windows"), this, SLOT(slotWordWrapToggled()), ac, "diff_wordwrap");
Michael Reeves's avatar
Michael Reeves committed
593
594
   addManualDiffHelp  = KDiff3::createAction< QAction >(i18n("Add Manual Diff Alignment"), KShortcut( Qt::CTRL+Qt::Key_Y ), this, SLOT(slotAddManualDiffHelp()), ac, "diff_add_manual_diff_help");
   clearManualDiffHelpList  = KDiff3::createAction< QAction >(i18n("Clear All Manual Diff Alignments"), KShortcut( Qt::CTRL+Qt::SHIFT+Qt::Key_Y ), this, SLOT(slotClearManualDiffHelpList()), ac, "diff_clear_manual_diff_help_list");
Joachim Eibl's avatar
Joachim Eibl committed
595

Joachim Eibl's avatar
Joachim Eibl committed
596
#if defined(_WIN32) || defined(Q_OS_OS2)
Michael Reeves's avatar
Michael Reeves committed
597
   KDiff3::createAction< QAction >(i18n("Focus Next Window"), KShortcut(Qt::CTRL+Qt::Key_Tab), this, SLOT(slotWinFocusNext()), ac, "win_focus_next");
Joachim Eibl's avatar
Joachim Eibl committed
598
#endif
Michael Reeves's avatar
Michael Reeves committed
599
600
   winFocusPrev = KDiff3::createAction< QAction >(i18n("Focus Prev Window"), KShortcut( Qt::ALT+Qt::Key_Left ), this, SLOT(slotWinFocusPrev()), ac, "win_focus_prev");
   winToggleSplitOrientation = KDiff3::createAction< QAction >(i18n("Toggle Split Orientation"), this, SLOT(slotWinToggleSplitterOrientation()), ac, "win_toggle_split_orientation");
Joachim Eibl's avatar
Joachim Eibl committed
601

Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
602
   dirShowBoth = KDiff3::createAction< KToggleAction >(i18n("Dir && Text Split Screen View"), this, SLOT(slotDirShowBoth()), ac, "win_dir_show_both");
Joachim Eibl's avatar
Joachim Eibl committed
603
   dirShowBoth->setChecked( true );
Michael Reeves's avatar
Michael Reeves committed
604
   dirViewToggle = KDiff3::createAction< QAction >(i18n("Toggle Between Dir && Text View"), this, SLOT(slotDirViewToggle()), ac, "win_dir_view_toggle");
Joachim Eibl's avatar
Joachim Eibl committed
605

Joachim Eibl's avatar
Joachim Eibl committed
606
   m_pMergeEditorPopupMenu = new QMenu( this );
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
607
/*   chooseA->plug( m_pMergeEditorPopupMenu );
Joachim Eibl's avatar
Joachim Eibl committed
608
   chooseB->plug( m_pMergeEditorPopupMenu );
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
609
610
611
612
   chooseC->plug( m_pMergeEditorPopupMenu );*/
   m_pMergeEditorPopupMenu->addAction( chooseA );
   m_pMergeEditorPopupMenu->addAction( chooseB );
   m_pMergeEditorPopupMenu->addAction( chooseC );
Joachim Eibl's avatar
Joachim Eibl committed
613
614
}

Joachim Eibl's avatar
0.9.80    
Joachim Eibl committed
615

Joachim Eibl's avatar
Joachim Eibl committed
616
617
618
619
620
621
622
623
624
625
void KDiff3App::showPopupMenu( const QPoint& point )
{
   m_pMergeEditorPopupMenu->popup( point );
}

void KDiff3App::initStatusBar()
{
  ///////////////////////////////////////////////////////////////////
  // STATUSBAR
  if (statusBar() !=0 )
Joachim Eibl's avatar
Joachim Eibl committed
626
     statusBar()->showMessage( i18n("Ready.") );
Joachim Eibl's avatar
Joachim Eibl committed
627
628
}

Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
629
void KDiff3App::saveOptions( KSharedConfigPtr config )
Joachim Eibl's avatar
Joachim Eibl committed
630
{
Joachim Eibl's avatar
Joachim Eibl committed
631
   if ( !m_bAutoMode )
Joachim Eibl's avatar
Joachim Eibl committed
632
   {
Joachim Eibl's avatar
Joachim Eibl committed
633
      if (!isPart())
Joachim Eibl's avatar
Joachim Eibl committed
634
      {
635
         m_pOptions->m_bMaximised = m_pKDiff3Shell->isMaximized();
Joachim Eibl's avatar
Joachim Eibl committed
636
637
         if( ! m_pKDiff3Shell->isMaximized() && m_pKDiff3Shell->isVisible() )
         {
638
639
            m_pOptions->m_geometry = m_pKDiff3Shell->size();
            m_pOptions->m_position = m_pKDiff3Shell->pos();
Joachim Eibl's avatar
Joachim Eibl committed
640
         }
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
641
642
643
/*  TODO change this option as now KToolbar uses QToolbar positioning style
         if ( toolBar(MAIN_TOOLBAR_NAME)!=0 )
            m_pOptionDialog->m_toolBarPos = (int) toolBar(MAIN_TOOLBAR_NAME)->allowedAreas();*/
Joachim Eibl's avatar
Joachim Eibl committed
644
      }
Joachim Eibl's avatar
Joachim Eibl committed
645

Joachim Eibl's avatar
Joachim Eibl committed
646
647
      m_pOptionDialog->saveOptions( config );
   }
Joachim Eibl's avatar
Joachim Eibl committed
648
649
650
651
652
653
654
}




bool KDiff3App::queryClose()
{
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
655
   saveOptions( isPart() ? m_pKDiff3Part->componentData().config() : KGlobal::config() );
Joachim Eibl's avatar
Joachim Eibl committed
656
657
658
659
660

   if(m_bOutputModified)
   {
      int result = KMessageBox::warningYesNoCancel(this,
         i18n("The merge result hasn't been saved."),
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
661
662
663
         i18n("Warning"), 
         KGuiItem( i18n("Save && Quit") ), 
         KGuiItem( i18n("Quit Without Saving") ) );
Joachim Eibl's avatar
Joachim Eibl committed
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
      if ( result==KMessageBox::Cancel )
         return false;
      else if ( result==KMessageBox::Yes )
      {
         slotFileSave();
         if ( m_bOutputModified )
         {
            KMessageBox::sorry(this, i18n("Saving the merge result failed."), i18n("Warning") );
            return false;
         }
      }
   }

   m_bOutputModified = false;

   if ( m_pDirectoryMergeWindow->isDirectoryMergeInProgress() )
   {
      int result = KMessageBox::warningYesNo(this,
         i18n("You are currently doing a directory merge. Are you sure, you want to abort?"),
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
683
684
685
         i18n("Warning"), 
         KStandardGuiItem::quit(), 
         KStandardGuiItem::cont() /* i18n("Continue Merging") */ );
Joachim Eibl's avatar
Joachim Eibl committed
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
      if ( result!=KMessageBox::Yes )
         return false;
   }

   return true;
}


/////////////////////////////////////////////////////////////////////
// SLOT IMPLEMENTATION
/////////////////////////////////////////////////////////////////////


void KDiff3App::slotFileSave()
{
   if ( m_bDefaultFilename )
   {
      slotFileSaveAs();
   }
   else
   {
      slotStatusMsg(i18n("Saving file..."));

Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
709
      bool bSuccess = m_pMergeResultWindow->saveDocument( m_outputFilename, m_pMergeResultWindowTitle->getEncoding(), m_pMergeResultWindowTitle->getLineEndStyle() );
Joachim Eibl's avatar
Joachim Eibl committed
710
711
      if ( bSuccess )
      {
Joachim Eibl's avatar
Joachim Eibl committed
712
         m_bFileSaved = true;
Joachim Eibl's avatar
Joachim Eibl committed
713
714
         m_bOutputModified = false;
         if ( m_bDirCompare )
Joachim Eibl's avatar
Joachim Eibl committed
715
            m_pDirectoryMergeWindow->mergeResultSaved( m_outputFilename );
Joachim Eibl's avatar
Joachim Eibl committed
716
717
718
719
720
721
722
723
724
725
      }

      slotStatusMsg(i18n("Ready."));
   }
}

void KDiff3App::slotFileSaveAs()
{
  slotStatusMsg(i18n("Saving file with a new filename..."));

Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
726
  QString s = KFileDialog::getSaveUrl( QDir::currentPath(), 0, this, i18n("Save As...") ).url();
Joachim Eibl's avatar
Joachim Eibl committed
727
728
729
  if(!s.isEmpty())
  {
     m_outputFilename = s;
Joachim Eibl's avatar
Joachim Eibl committed
730
     m_pMergeResultWindowTitle->setFileName( m_outputFilename );
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
731
     bool bSuccess = m_pMergeResultWindow->saveDocument( m_outputFilename, m_pMergeResultWindowTitle->getEncoding(), m_pMergeResultWindowTitle->getLineEndStyle() );
Joachim Eibl's avatar
Joachim Eibl committed
732
733
734
735
     if ( bSuccess )
     {
        m_bOutputModified = false;
        if ( m_bDirCompare )
Joachim Eibl's avatar
Joachim Eibl committed
736
           m_pDirectoryMergeWindow->mergeResultSaved( m_outputFilename );
Joachim Eibl's avatar
Joachim Eibl committed
737
     }
Michael Reeves's avatar
Michael Reeves committed
738
     //setWindowTitle(url.fileName(),doc->isModified());
Joachim Eibl's avatar
Joachim Eibl committed
739
740
741
742
743
744
745
746

     m_bDefaultFilename = false;
  }

  slotStatusMsg(i18n("Ready."));
}


Joachim Eibl's avatar
Joachim Eibl committed
747
748
749
750
751
752
753
754
755
756
757
void printDiffTextWindow( MyPainter& painter, const QRect& view, const QString& headerText, DiffTextWindow* pDiffTextWindow, int line, int linesPerPage, QColor fgColor )
{
   QRect clipRect = view;
   clipRect.setTop(0);
   painter.setClipRect( clipRect );
   painter.translate( view.left() , 0 );
   QFontMetrics fm = painter.fontMetrics();
   //if ( fm.width(headerText) > view.width() )
   {
      // A simple wrapline algorithm
      int l=0;
Joachim Eibl's avatar
Joachim Eibl committed
758
      for (int p=0; p<headerText.length(); )
Joachim Eibl's avatar
Joachim Eibl committed
759
760
      {
         QString s = headerText.mid(p);
Joachim Eibl's avatar
Joachim Eibl committed
761
         int i;
Joachim Eibl's avatar
Joachim Eibl committed
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
         for(i=2;i<s.length();++i) 
            if (fm.width(s,i)>view.width())
            {
               --i;
               break;
            }
         //QString s2 = s.left(i);
         painter.drawText( 0, l*fm.height() + fm.ascent(), s.left(i) );
         p+=i;
         ++l;
      }
      painter.setPen( fgColor );
      painter.drawLine( 0, view.top()-2, view.width(), view.top()-2 );
   }

   painter.translate( 0, view.top() );
   pDiffTextWindow->print( painter, view, line, linesPerPage );
Joachim Eibl's avatar
Joachim Eibl committed
779
   painter.resetMatrix();
Joachim Eibl's avatar
Joachim Eibl committed
780
781
782
783
784
785
}

void KDiff3App::slotFilePrint()
{
   if ( !m_pDiffTextWindow1 )
      return;
Joachim Eibl's avatar
Joachim Eibl committed
786
787
788
789
#ifdef QT_NO_PRINTER
   slotStatusMsg( i18n( "Printing not implemented." ) );
#endif
#ifndef QT_NO_PRINTER
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
790
   QPrinter printer;
Joachim Eibl's avatar
Joachim Eibl committed
791
   QPrintDialog printDialog(&printer, this);
Joachim Eibl's avatar
Joachim Eibl committed
792
793
794
795
796
797
798
799
800

   int firstSelectionD3LIdx = -1;
   int lastSelectionD3LIdx = -1;
   if (                           m_pDiffTextWindow1 ) { m_pDiffTextWindow1->getSelectionRange(&firstSelectionD3LIdx, &lastSelectionD3LIdx, eD3LLineCoords); }
   if ( firstSelectionD3LIdx<0 && m_pDiffTextWindow2 ) { m_pDiffTextWindow2->getSelectionRange(&firstSelectionD3LIdx, &lastSelectionD3LIdx, eD3LLineCoords); }
   if ( firstSelectionD3LIdx<0 && m_pDiffTextWindow3 ) { m_pDiffTextWindow3->getSelectionRange(&firstSelectionD3LIdx, &lastSelectionD3LIdx, eD3LLineCoords); }
#ifdef KREPLACEMENTS_H  // Currently PrintSelection is not supported in KDEs print dialog.
   if ( firstSelectionD3LIdx>=0 )
   {
Joachim Eibl's avatar
Joachim Eibl committed
801
      printDialog.addEnabledOption(QPrintDialog::PrintSelection);
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
802
803
      //printer.setOptionEnabled(QPrinter::PrintSelection,true);
      printDialog.setPrintRange(QAbstractPrintDialog::Selection);
Joachim Eibl's avatar
Joachim Eibl committed
804
805
806
   }
#endif

Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
807
808
809
810
   if ( firstSelectionD3LIdx == -1 )
      printDialog.setPrintRange(QAbstractPrintDialog::AllPages);
   //printDialog.setMinMax(0,0);
   printDialog.setFromTo(0,0);
Joachim Eibl's avatar
Joachim Eibl committed
811
812
813
814
815
816
817
818

   int currentFirstLine = m_pDiffTextWindow1->getFirstLine();
   int currentFirstD3LIdx = m_pDiffTextWindow1->convertLineToDiff3LineIdx( currentFirstLine );

   // do some printer initialization
   printer.setFullPage( false );

   // initialize the printer using the print dialog
Joachim Eibl's avatar
Joachim Eibl committed
819
   if (printDialog.exec()== QDialog::Accepted)
Joachim Eibl's avatar
Joachim Eibl committed
820
821
822
   {
      slotStatusMsg( i18n( "Printing..." ) );
      // create a painter to paint on the printer object
823
      MyPainter painter( &printer, m_pOptions->m_bRightToLeftLanguage, width(), fontMetrics().width('W') );
Joachim Eibl's avatar
Joachim Eibl committed
824

Joachim Eibl's avatar
Joachim Eibl committed
825
826
      QPaintDevice* pPaintDevice = painter.device();
      int dpiy = pPaintDevice->logicalDpiY();
Joachim Eibl's avatar
Joachim Eibl committed
827
828
829
      int columnDistance = (int) ( (0.5/2.54)*dpiy ); // 0.5 cm between the columns

      int columns = m_bTripleDiff ? 3 : 2;
Joachim Eibl's avatar
Joachim Eibl committed
830
      int columnWidth = ( pPaintDevice->width()  - (columns-1)*columnDistance ) / columns;
Joachim Eibl's avatar
Joachim Eibl committed
831

832
      QFont f = m_pOptions->m_font;
Joachim Eibl's avatar
Joachim Eibl committed
833
      f.setPointSizeF(f.pointSizeF()-1); // Print with slightly smaller font.
Joachim Eibl's avatar
Joachim Eibl committed
834
835
836
837
838
839
840
841
842
843
844
      painter.setFont( f );
      QFontMetrics fm = painter.fontMetrics();

      QString topLineText = i18n("Top line"); 

      //int headerWidth = fm.width( m_sd1.getAliasName() + ", "+topLineText+": 01234567" );
      int headerLines = fm.width( m_sd1.getAliasName() + ", "+topLineText+": 01234567" )/columnWidth+1;

      int headerMargin = headerLines * fm.height() + 3; // Text + one horizontal line
      int footerMargin = fm.height() + 3;

Joachim Eibl's avatar
Joachim Eibl committed
845
846
847
848
      QRect view ( 0, headerMargin, pPaintDevice->width(), pPaintDevice->height() - (headerMargin + footerMargin) );
      QRect view1( 0*(columnWidth + columnDistance), view.top(), columnWidth, view.height() );
      QRect view2( 1*(columnWidth + columnDistance), view.top(), columnWidth, view.height() );
      QRect view3( 2*(columnWidth + columnDistance), view.top(), columnWidth, view.height() );
Joachim Eibl's avatar
Joachim Eibl committed
849

850
      int linesPerPage = view.height() / fm.lineSpacing();
851
      if ( m_pOptions->m_bWordWrap )
Joachim Eibl's avatar
Joachim Eibl committed
852
853
      {
         // For printing the lines are wrapped differently (this invalidates the first line)
854
         recalcWordWrap( columnWidth );
Joachim Eibl's avatar
Joachim Eibl committed
855
856
857
858
859
860
      }

      int totalNofLines = max2(m_pDiffTextWindow1->getNofLines(), m_pDiffTextWindow2->getNofLines());
      if ( m_bTripleDiff && m_pDiffTextWindow3)
         totalNofLines = max2(totalNofLines, m_pDiffTextWindow3->getNofLines());

Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
861
      QList<int> pageList;// = printer.pageList();
Joachim Eibl's avatar
Joachim Eibl committed
862
863
864
865
866
867
868
869
870
871

      bool bPrintCurrentPage=false;
      bool bFirstPrintedPage = false;

      bool bPrintSelection = false;
      int totalNofPages = (totalNofLines+linesPerPage-1) / linesPerPage;
      int line=-1;
      int selectionEndLine = -1;

#ifdef KREPLACEMENTS_H
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
872
      if ( printer.printRange()==QPrinter::AllPages )
Joachim Eibl's avatar
Joachim Eibl committed
873
874
875
876
877
878
879
      {
         pageList.clear();
         for(int i=0; i<totalNofPages; ++i)
         {
            pageList.push_back(i+1);
         }
      }
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
880
881
882
883
884
885
886
887
      else if ( printer.printRange()==QPrinter::PageRange )
      {
         pageList.clear();
         for(int i=printer.fromPage(); i<=printer.toPage(); ++i)
         {
            pageList.push_back(i);
         }
      }
Joachim Eibl's avatar
Joachim Eibl committed
888

Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
889
      if ( printer.printRange()==QPrinter::Selection )
Joachim Eibl's avatar
Joachim Eibl committed
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
#else
      if ( !pageList.empty() && pageList.front()==9999 )
#endif
      {
         bPrintSelection = true;
         if ( firstSelectionD3LIdx >=0 )
         {
            line = m_pDiffTextWindow1->convertDiff3LineIdxToLine( firstSelectionD3LIdx );
            selectionEndLine = m_pDiffTextWindow1->convertDiff3LineIdxToLine( lastSelectionD3LIdx+1 );
            totalNofPages = (selectionEndLine-line+linesPerPage-1) / linesPerPage;
         }
      }

      int page = 1;

Joachim Eibl's avatar
Joachim Eibl committed
905
      QList<int>::iterator pageListIt = pageList.begin();
Joachim Eibl's avatar
Joachim Eibl committed
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
      for(;;)
      {
         if (!bPrintSelection)
         {
            if (pageListIt==pageList.end())
               break;
            page = *pageListIt;
            line = (page - 1) * linesPerPage;
            if (page==10000)  // This means "Print the current page"
            {
               bPrintCurrentPage=true;
               // Detect the first visible line in the window.
               line = m_pDiffTextWindow1->convertDiff3LineIdxToLine( currentFirstD3LIdx );
            }
         }
         else
         {
            if ( line>=selectionEndLine )
            {
               break;
            }
            else
            {
               if ( selectionEndLine-line < linesPerPage )
                  linesPerPage=selectionEndLine-line;
            }
         }
         if (line>=0 && line<totalNofLines )
         {

            if (bFirstPrintedPage)
               printer.newPage();

            painter.setClipping(true);

941
            painter.setPen( m_pOptions->m_colorA );
Joachim Eibl's avatar
Joachim Eibl committed
942
            QString headerText1 = m_sd1.getAliasName() + ", "+topLineText+": " + QString::number(m_pDiffTextWindow1->calcTopLineInFile(line)+1);
943
            printDiffTextWindow( painter, view1, headerText1, m_pDiffTextWindow1, line, linesPerPage, m_pOptions->m_fgColor );
Joachim Eibl's avatar
Joachim Eibl committed
944

945
            painter.setPen( m_pOptions->m_colorB );
Joachim Eibl's avatar
Joachim Eibl committed
946
            QString headerText2 = m_sd2.getAliasName() + ", "+topLineText+": " + QString::number(m_pDiffTextWindow2->calcTopLineInFile(line)+1);
947
            printDiffTextWindow( painter, view2, headerText2, m_pDiffTextWindow2, line, linesPerPage, m_pOptions->m_fgColor );
Joachim Eibl's avatar
Joachim Eibl committed
948
949
950

            if ( m_bTripleDiff && m_pDiffTextWindow3 )
            {
951
               painter.setPen( m_pOptions->m_colorC );
Joachim Eibl's avatar
Joachim Eibl committed
952
               QString headerText3 = m_sd3.getAliasName() + ", "+topLineText+": " + QString::number(m_pDiffTextWindow3->calcTopLineInFile(line)+1);
953
               printDiffTextWindow( painter, view3, headerText3, m_pDiffTextWindow3, line, linesPerPage, m_pOptions->m_fgColor );
Joachim Eibl's avatar
Joachim Eibl committed
954
955
956
            }
            painter.setClipping(false);

957
            painter.setPen( m_pOptions->m_fgColor );
Joachim Eibl's avatar
Joachim Eibl committed
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
            painter.drawLine( 0, view.bottom()+3, view.width(), view.bottom()+3 ); 
            QString s = bPrintCurrentPage ? QString("") 
                                          : QString::number( page ) + "/" + QString::number(totalNofPages);
            if ( bPrintSelection ) s+=" (" + i18n("Selection") + ")";
            painter.drawText( (view.right() - painter.fontMetrics().width( s ))/2,
                        view.bottom() + painter.fontMetrics().ascent() + 5, s );

            bFirstPrintedPage = true;
         }

         if ( bPrintSelection )
         {
            line+=linesPerPage;
            ++page;
         }
         else
         {
            ++pageListIt;
         }
      }

      painter.end();

981
      if ( m_pOptions->m_bWordWrap )
Joachim Eibl's avatar
Joachim Eibl committed
982
983
984
985
986
987
988
989
990
991
992
      {
         recalcWordWrap();
         m_pDiffVScrollBar->setValue( m_pDiffTextWindow1->convertDiff3LineIdxToLine( currentFirstD3LIdx ) );
      }

      slotStatusMsg( i18n( "Printing completed." ) );
   }
   else
   {
      slotStatusMsg( i18n( "Printing aborted." ) );
   }
Joachim Eibl's avatar
Joachim Eibl committed
993
#endif
Joachim Eibl's avatar
Joachim Eibl committed
994
995
}

Joachim Eibl's avatar
Joachim Eibl committed
996
997
998
999
1000
1001
1002
void KDiff3App::slotFileQuit()
{
   slotStatusMsg(i18n("Exiting..."));

   if( !queryClose() )
       return;      // Don't quit

Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
1003
   KApplication::exit( isFileSaved() || isDirComparison() ? 0 : 1 );
Joachim Eibl's avatar
Joachim Eibl committed
1004
1005
1006
1007
1008
1009
}



void KDiff3App::slotViewToolBar()
{
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
1010
   assert( viewToolBar != 0 );
Joachim Eibl's avatar
Joachim Eibl committed
1011
   slotStatusMsg(i18n("Toggling toolbar..."));
1012
   m_pOptions->m_bShowToolBar = viewToolBar->isChecked();
Joachim Eibl's avatar
Joachim Eibl committed
1013
1014
   ///////////////////////////////////////////////////////////////////
   // turn Toolbar on or off
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
1015
   if ( toolBar(MAIN_TOOLBAR_NAME) !=0 )
Joachim Eibl's avatar
Joachim Eibl committed
1016
   {
1017
      if(!m_pOptions->m_bShowToolBar)
Joachim Eibl's avatar
Joachim Eibl committed
1018
      {
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
1019
         toolBar(MAIN_TOOLBAR_NAME)->hide();
Joachim Eibl's avatar
Joachim Eibl committed
1020
1021
1022
      }
      else
      {
Joachim Eibl's avatar
0.9.93    
Joachim Eibl committed
1023
         toolBar(MAIN_TOOLBAR_NAME)->show();
Joachim Eibl's avatar
Joachim Eibl committed
1024
1025
1026
1027
1028
1029
1030
1031
1032
      }
   }

   slotStatusMsg(i18n("Ready."));
}

void KDiff3App::slotViewStatusBar()
{
   slotStatusMsg(i18n("Toggle the statusbar..."));
1033
   m_pOptions->m_bShowStatusBar = viewStatusBar->isChecked();
Joachim Eibl's avatar
Joachim Eibl committed
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
   ///////////////////////////////////////////////////////////////////
   //turn Statusbar on or off
   if (statusBar() !=0 )
   {
      if(!viewStatusBar->isChecked())
      {
         statusBar()->hide();
      }
      else
      {
         statusBar()->show();
      }
   }

   slotStatusMsg(i18n("Ready."));
}


void KDiff3App::slotStatusMsg(const QString &text)
{
   ///////////////////////////////////////////////////////////////////
   // change status message permanently
   if (statusBar() !=0 )
   {
Joachim Eibl's avatar
Joachim Eibl committed
1058
1059
      statusBar()->clearMessage();
      statusBar()->showMessage( text );
Joachim Eibl's avatar
Joachim Eibl committed
1060
1061
1062
1063
1064
1065
   }
}




Joachim Eibl's avatar
Joachim Eibl committed
1066
//#include "kdiff3.moc"