comparison kdiff3/src/kdiff3.cpp @ 8:86d21651c8db

KDiff3 version 0.9.70
author joachim99
date Mon, 06 Oct 2003 18:50:45 +0000
parents
children 07416314eb5e
comparison
equal deleted inserted replaced
7:ff98a43bbfea 8:86d21651c8db
1 /***************************************************************************
2 kdiff3.cpp - description
3 -------------------
4 begin : Don Jul 11 12:31:29 CEST 2002
5 copyright : (C) 2002 by Joachim Eibl
6 email : joachim.eibl@gmx.de
7 ***************************************************************************/
8
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18 /***************************************************************************
19 * $Log$
20 * Revision 1.1 2003/10/06 18:38:48 joachim99
21 * KDiff3 version 0.9.70
22 * *
23 ***************************************************************************/
24
25 #include "diff.h"
26
27 #include <iostream>
28
29 // include files for QT
30 #include <qdir.h>
31 #include <qprinter.h>
32 #include <qpainter.h>
33 #include <qsplitter.h>
34 #include <qlayout.h>
35 #include <qlineedit.h>
36 #include <qcheckbox.h>
37 #include <qpushbutton.h>
38 #include <qpopupmenu.h>
39 #include <qlabel.h>
40
41 // include files for KDE
42 #include <kiconloader.h>
43 #include <kmessagebox.h>
44 #include <kfiledialog.h>
45 #include <kmenubar.h>
46 #include <kstatusbar.h>
47 #include <klocale.h>
48 #include <kconfig.h>
49 #include <kstdaction.h>
50 #include <kcmdlineargs.h>
51 //#include <kkeydialog.h>
52
53 // application specific includes
54 #include "kdiff3.h"
55 #include "optiondialog.h"
56 #include "fileaccess.h"
57 #include "kdiff3_part.h"
58 #include "directorymergewindow.h"
59
60 #define ID_STATUS_MSG 1
61
62 KActionCollection* KDiff3App::actionCollection()
63 {
64 if ( m_pKDiff3Shell==0 )
65 return m_pKDiff3Part->actionCollection();
66 else
67 return m_pKDiff3Shell->actionCollection();
68 }
69
70 KStatusBar* KDiff3App::statusBar()
71 {
72 if ( m_pKDiff3Shell==0 )
73 return 0;
74 else
75 return m_pKDiff3Shell->statusBar();
76 }
77
78 KToolBar* KDiff3App::toolBar(const char* toolBarId )
79 {
80 if ( m_pKDiff3Shell==0 )
81 return 0;
82 else
83 return m_pKDiff3Shell->toolBar( toolBarId );
84 }
85
86 bool KDiff3App::isPart()
87 {
88 return m_pKDiff3Shell==0;
89 }
90
91
92 KDiff3App::KDiff3App(QWidget* pParent, const char* name, KDiff3Part* pKDiff3Part )
93 :QSplitter(pParent, name) //previously KMainWindow
94 {
95 m_pKDiff3Part = pKDiff3Part;
96 m_pKDiff3Shell = dynamic_cast<KParts::MainWindow*>(pParent);
97
98 setCaption( "KDiff3" );
99
100 m_pMainSplitter = 0;
101 m_pDirectoryMergeWindow = 0;
102 m_pCornerWidget = 0;
103 m_pMainWidget = 0;
104 m_pDiffTextWindow1 = 0;
105 m_pDiffTextWindow2 = 0;
106 m_pDiffTextWindow3 = 0;
107 m_pDiffWindowSplitter = 0;
108 m_pOverview = 0;
109 m_bTripleDiff = false;
110 m_pMergeResultWindow = 0;
111 m_pMergeWindowFrame = 0;
112 m_bOutputModified = false;
113 m_bTimerBlock = false;
114
115 // Option handling: Only when pParent==0 (no parent)
116 KCmdLineArgs *args = isPart() ? 0 : KCmdLineArgs::parsedArgs();
117
118 if (args!=0)
119 {
120 m_outputFilename = args->getOption("output");
121 if ( m_outputFilename.isEmpty() )
122 m_outputFilename = args->getOption("out");
123 }
124
125 m_bAuto = args!=0 && args->isSet("auto");
126 if ( m_bAuto && m_outputFilename.isEmpty() )
127 {
128 //KMessageBox::information(this, i18n("Option --auto used, but no output file specified."));
129 std::cerr << i18n("Option --auto used, but no output file specified.").ascii()<<std::endl;
130 m_bAuto = false;
131 }
132
133 if ( m_outputFilename.isEmpty() && args!=0 && args->isSet("merge") )
134 {
135 m_outputFilename = "unnamed.txt";
136 m_bDefaultFilename = true;
137 }
138 else
139 m_bDefaultFilename = false;
140
141 g_bAutoSolve = args!=0 && !args->isSet("qall"); // Note that this is effective only once.
142
143 if ( args!=0 )
144 {
145 m_sd1.setFilename( args->getOption("base") );
146 if ( m_sd1.isEmpty() )
147 {
148 if ( args->count() > 0 ) m_sd1.setFilename( args->arg(0) );
149 if ( args->count() > 1 ) m_sd2.setFilename( args->arg(1) );
150 if ( args->count() > 2 ) m_sd3.setFilename( args->arg(2) );
151 }
152 else
153 {
154 if ( args->count() > 0 ) m_sd2.setFilename( args->arg(0) );
155 if ( args->count() > 1 ) m_sd3.setFilename( args->arg(1) );
156 }
157
158 QCStringList aliasList = args->getOptionList("fname");
159 QCStringList::Iterator ali = aliasList.begin();
160 if ( ali != aliasList.end() ) { m_sd1.setAliasName(*ali); ++ali; }
161 if ( ali != aliasList.end() ) { m_sd2.setAliasName(*ali); ++ali; }
162 if ( ali != aliasList.end() ) { m_sd3.setAliasName(*ali); ++ali; }
163 }
164 g_pProgressDialog = new ProgressDialog(this);
165 ///////////////////////////////////////////////////////////////////
166 // call inits to invoke all other construction parts
167 initActions(actionCollection());
168 initStatusBar();
169
170 m_pFindDialog = new FindDialog( this );
171 connect( m_pFindDialog, SIGNAL(findNext()), this, SLOT(slotEditFindNext()));
172
173 // All default values must be set before calling readOptions().
174 m_pOptionDialog = new OptionDialog( m_pKDiff3Shell!=0, this );
175 connect( m_pOptionDialog, SIGNAL(applyClicked()), this, SLOT(slotRefresh()) );
176
177 readOptions( isPart() ? m_pKDiff3Part->instance()->config() : kapp->config() );
178
179 m_pMainSplitter = this; //new QSplitter(this);
180 m_pMainSplitter->setOrientation( Vertical );
181 // setCentralWidget( m_pMainSplitter );
182 m_pDirectoryMergeSplitter = new QSplitter( m_pMainSplitter );
183 m_pDirectoryMergeSplitter->setOrientation( Horizontal );
184 m_pDirectoryMergeWindow = new DirectoryMergeWindow( m_pDirectoryMergeSplitter, m_pOptionDialog,
185 KApplication::kApplication()->iconLoader() );
186 m_pDirectoryMergeInfo = new DirectoryMergeInfo( m_pDirectoryMergeSplitter );
187 m_pDirectoryMergeWindow->setDirectoryMergeInfo( m_pDirectoryMergeInfo );
188 connect( m_pDirectoryMergeWindow, SIGNAL(startDiffMerge(QString,QString,QString,QString,QString,QString,QString)),
189 this, SLOT( slotFileOpen2(QString,QString,QString,QString,QString,QString,QString)));
190 connect( m_pDirectoryMergeWindow, SIGNAL(selectionChanged()), this, SLOT(slotUpdateAvailabilities()));
191 connect( m_pDirectoryMergeWindow, SIGNAL(currentChanged(QListViewItem*)), this, SLOT(slotUpdateAvailabilities()));
192 connect( m_pDirectoryMergeWindow, SIGNAL(checkIfCanContinue(bool*)), this, SLOT(slotCheckIfCanContinue(bool*)));
193 connect( m_pDirectoryMergeWindow, SIGNAL(updateAvailabilities()), this, SLOT(slotUpdateAvailabilities()));
194
195 initDirectoryMergeActions();
196
197 if ( args!=0 ) args->clear(); // Free up some memory.
198
199 if (m_pKDiff3Shell==0)
200 {
201 completeInit();
202 }
203 }
204
205
206 void KDiff3App::completeInit()
207 {
208 if (m_pKDiff3Shell!=0)
209 {
210 QSize size=kapp->config()->readSizeEntry("Geometry");
211 QPoint pos=kapp->config()->readPointEntry("Position");
212 if(!size.isEmpty())
213 {
214 m_pKDiff3Shell->resize( size );
215 m_pKDiff3Shell->move( pos );
216 }
217 }
218
219 m_bDirCompare = improveFilenames();
220 if ( m_bAuto && m_bDirCompare )
221 {
222 std::cerr << i18n("Option --auto ignored for directory comparison.").ascii()<<std::endl;
223 m_bAuto = false;
224 }
225 if (!m_bDirCompare)
226 {
227 m_pDirectoryMergeSplitter->hide();
228
229 init( m_bAuto );
230 if ( m_bAuto )
231 {
232 const char* pBuf = 0;
233 unsigned int size = 0;
234 if ( m_sd3.isEmpty() )
235 {
236 if ( m_totalDiffStatus.bBinaryAEqB ){ pBuf=m_sd1.m_pBuf; size=m_sd1.m_size; }
237 }
238 else
239 {
240 if ( m_totalDiffStatus.bBinaryBEqC ){ pBuf=m_sd3.m_pBuf; size=m_sd3.m_size; }
241 else if ( m_totalDiffStatus.bBinaryAEqB ){ pBuf=m_sd3.m_pBuf; size=m_sd3.m_size; }
242 else if ( m_totalDiffStatus.bBinaryAEqC ){ pBuf=m_sd2.m_pBuf; size=m_sd2.m_size; }
243 }
244
245 if ( pBuf!=0 )
246 {
247 // Save this file directly, not via the merge result window.
248 bool bSuccess = false;
249 if ( m_pOptionDialog->m_bDmCreateBakFiles && QDir().exists( m_outputFilename ) )
250 {
251 QString newName = m_outputFilename + ".orig";
252 if ( QDir().exists( newName ) ) QFile::remove(newName);
253 if ( !QDir().exists( newName ) ) QDir().rename( m_outputFilename, newName );
254 }
255 QFile file( m_outputFilename );
256 if ( file.open( IO_WriteOnly ) )
257 {
258 bSuccess = (long)size == file.writeBlock ( pBuf, size );
259 file.close();
260 }
261 if ( bSuccess ) ::exit(0);
262 else KMessageBox::error( this, i18n("Saving failed.") );
263 }
264 else if ( m_pMergeResultWindow->getNrOfUnsolvedConflicts() == 0 )
265 {
266 bool bSuccess = m_pMergeResultWindow->saveDocument( m_outputFilename );
267 if ( bSuccess ) ::exit(0);
268 }
269 }
270 }
271
272 if (statusBar() !=0 )
273 statusBar()->setSizeGripEnabled(false);
274
275 slotClipboardChanged(); // For initialisation.
276
277 slotUpdateAvailabilities();
278
279 if ( ! m_bDirCompare && m_pKDiff3Shell!=0 )
280 {
281 bool bFileOpenError = false;
282 if ( ! m_sd1.isEmpty() && m_sd1.m_pBuf==0 ||
283 ! m_sd2.isEmpty() && m_sd2.m_pBuf==0 ||
284 ! m_sd3.isEmpty() && m_sd3.m_pBuf==0 )
285 {
286 QString text( i18n("Opening of these files failed:") );
287 text += "\n\n";
288 if ( ! m_sd1.isEmpty() && m_sd1.m_pBuf==0 )
289 text += " - " + m_sd1.getAliasName() + "\n";
290 if ( ! m_sd2.isEmpty() && m_sd2.m_pBuf==0 )
291 text += " - " + m_sd2.getAliasName() + "\n";
292 if ( ! m_sd3.isEmpty() && m_sd3.m_pBuf==0 )
293 text += " - " + m_sd3.getAliasName() + "\n";
294
295 KMessageBox::sorry( this, text, i18n("File open error") );
296 bFileOpenError = true;
297 }
298
299 if ( m_sd1.isEmpty() || m_sd2.isEmpty() || bFileOpenError )
300 slotFileOpen();
301 }
302 }
303
304 KDiff3App::~KDiff3App()
305 {
306
307 }
308
309 void KDiff3App::initActions( KActionCollection* ac )
310 {
311 if (ac==0) KMessageBox::error(0, "actionCollection==0");
312
313 fileOpen = KStdAction::open(this, SLOT(slotFileOpen()), ac);
314 fileOpen->setStatusText(i18n("Opens documents for comparison ..."));
315 fileSave = KStdAction::save(this, SLOT(slotFileSave()), ac);
316 fileSave->setStatusText(i18n("Saves the merge result. All conflicts must be solved!"));
317 fileSaveAs = KStdAction::saveAs(this, SLOT(slotFileSaveAs()), ac);
318 fileSaveAs->setStatusText(i18n("Saves the current document as..."));
319 fileQuit = KStdAction::quit(this, SLOT(slotFileQuit()), ac);
320 fileQuit->setStatusText(i18n("Quits the application"));
321 editCut = KStdAction::cut(this, SLOT(slotEditCut()), ac);
322 editCut->setStatusText(i18n("Cuts the selected section and puts it to the clipboard"));
323 editCopy = KStdAction::copy(this, SLOT(slotEditCopy()), ac);
324 editCopy->setStatusText(i18n("Copies the selected section to the clipboard"));
325 editPaste = KStdAction::paste(this, SLOT(slotEditPaste()), ac);
326 editPaste->setStatusText(i18n("Pastes the clipboard contents to actual position"));
327 editFind = KStdAction::find(this, SLOT(slotEditFind()), ac);
328 editFind->setStatusText(i18n("Search for a string"));
329 editFindNext = KStdAction::findNext(this, SLOT(slotEditFindNext()), ac);
330 editFindNext->setStatusText(i18n("Search again for the string"));
331 viewToolBar = KStdAction::showToolbar(this, SLOT(slotViewToolBar()), ac);
332 viewToolBar->setStatusText(i18n("Enables/disables the toolbar"));
333 viewStatusBar = KStdAction::showStatusbar(this, SLOT(slotViewStatusBar()), ac);
334 viewStatusBar->setStatusText(i18n("Enables/disables the statusbar"));
335 KStdAction::keyBindings(this, SLOT(slotConfigureKeys()), ac);
336 KAction* pAction = KStdAction::preferences(this, SLOT(slotConfigure()), ac );
337 if ( isPart() )
338 pAction->setText("Configure KDiff3 ...");
339
340
341 #include "xpm/downend.xpm"
342 #include "xpm/currentpos.xpm"
343 #include "xpm/down1arrow.xpm"
344 #include "xpm/down2arrow.xpm"
345 #include "xpm/upend.xpm"
346 #include "xpm/up1arrow.xpm"
347 #include "xpm/up2arrow.xpm"
348 #include "xpm/prevunsolved.xpm"
349 #include "xpm/nextunsolved.xpm"
350 #include "xpm/iconA.xpm"
351 #include "xpm/iconB.xpm"
352 #include "xpm/iconC.xpm"
353 #include "xpm/autoadvance.xpm"
354 #include "xpm/showwhitespace.xpm"
355 #include "xpm/showlinenumbers.xpm"
356 //#include "reload.xpm"
357
358 goCurrent = new KAction(i18n("Go to Current Delta"), QIconSet(QPixmap(currentpos)), CTRL+Key_Space, this, SLOT(slotGoCurrent()), ac, "go_current");
359 goTop = new KAction(i18n("Go to First Delta"), QIconSet(QPixmap(upend)), 0, this, SLOT(slotGoTop()), ac, "go_top");
360 goBottom = new KAction(i18n("Go to Last Delta"), QIconSet(QPixmap(downend)), 0, this, SLOT(slotGoBottom()), ac, "go_bottom");
361 goPrevDelta = new KAction(i18n("Go to PrevDelta"), QIconSet(QPixmap(up1arrow)), CTRL+Key_Up, this, SLOT(slotGoPrevDelta()), ac, "go_prev_delta");
362 goNextDelta = new KAction(i18n("Go to NextDelta"), QIconSet(QPixmap(down1arrow)), CTRL+Key_Down, this, SLOT(slotGoNextDelta()), ac, "go_next_delta");
363 goPrevConflict = new KAction(i18n("Go to Previous Conflict"), QIconSet(QPixmap(up2arrow)), CTRL+Key_PageUp, this, SLOT(slotGoPrevConflict()), ac, "go_prev_conflict");
364 goNextConflict = new KAction(i18n("Go to Next Conflict"), QIconSet(QPixmap(down2arrow)), CTRL+Key_PageDown, this, SLOT(slotGoNextConflict()), ac, "go_next_conflict");
365 goPrevUnsolvedConflict = new KAction(i18n("Go to Previous Unsolved Conflict"), QIconSet(QPixmap(prevunsolved)), 0, this, SLOT(slotGoPrevUnsolvedConflict()), ac, "go_prev_unsolved_conflict");
366 goNextUnsolvedConflict = new KAction(i18n("Go to Next Unsolved Conflict"), QIconSet(QPixmap(nextunsolved)), 0, this, SLOT(slotGoNextUnsolvedConflict()), ac, "go_next_unsolved_conflict");
367 chooseA = new KToggleAction(i18n("Select line(s) from A"), QIconSet(QPixmap(iconA)), CTRL+Key_1, this, SLOT(slotChooseA()), ac, "merge_choose_a");
368 chooseB = new KToggleAction(i18n("Select line(s) from B"), QIconSet(QPixmap(iconB)), CTRL+Key_2, this, SLOT(slotChooseB()), ac, "merge_choose_b");
369 chooseC = new KToggleAction(i18n("Select line(s) from C"), QIconSet(QPixmap(iconC)), CTRL+Key_3, this, SLOT(slotChooseC()), ac, "merge_choose_c");
370 autoAdvance = new KToggleAction(i18n("Automatically go to next unsolved conflict after source selection"), QIconSet(QPixmap(autoadvance)), 0, this, SLOT(slotAutoAdvanceToggled()), ac, "merge_autoadvance");
371 showWhiteSpace = new KToggleAction(i18n("Show space and tabulator characters for differences"), QIconSet(QPixmap(showwhitespace)), 0, this, SLOT(slotShowWhiteSpaceToggled()), ac, "merge_showwhitespace");
372 showLineNumbers = new KToggleAction(i18n("Show line numbers"), QIconSet(QPixmap(showlinenumbers)), 0, this, SLOT(slotShowLineNumbersToggled()), ac, "merge_showlinenumbers");
373 chooseAEverywhere = new KAction(i18n("Choose A Everywhere"), CTRL+SHIFT+Key_1, this, SLOT(slotChooseAEverywhere()), ac, "merge_choose_a_everywhere");
374 chooseBEverywhere = new KAction(i18n("Choose B Everywhere"), CTRL+SHIFT+Key_2, this, SLOT(slotChooseBEverywhere()), ac, "merge_choose_b_everywhere");
375 chooseCEverywhere = new KAction(i18n("Choose C Everywhere"), CTRL+SHIFT+Key_3, this, SLOT(slotChooseCEverywhere()), ac, "merge_choose_c_everywhere");
376 autoSolve = new KAction(i18n("Automatically solve simple conflicts"), 0, this, SLOT(slotAutoSolve()), ac, "merge_autosolve");
377 unsolve = new KAction(i18n("Set deltas to conflicts"), 0, this, SLOT(slotUnsolve()), actionCollection(), "merge_autounsolve");
378 fileReload = new KAction(i18n("Reload"), /*QIconSet(QPixmap(reloadIcon)),*/ 0, this, SLOT(slotReload()), ac, "file_reload");
379 showWindowA = new KToggleAction(i18n("Show Window A"), 0, this, SLOT(slotShowWindowAToggled()), ac, "win_show_a");
380 showWindowB = new KToggleAction(i18n("Show Window B"), 0, this, SLOT(slotShowWindowBToggled()), ac, "win_show_b");
381 showWindowC = new KToggleAction(i18n("Show Window C"), 0, this, SLOT(slotShowWindowCToggled()), ac, "win_show_c");
382 winFocusNext = new KAction(i18n("Focus Next Window"), ALT+Key_Right, this, SLOT(slotWinFocusNext()), ac, "win_focus_next");
383 winFocusPrev = new KAction(i18n("Focus Prev Window"), ALT+Key_Left, this, SLOT(slotWinFocusPrev()), ac, "win_focus_prev");
384 winToggleSplitOrientation = new KAction(i18n("Toggle Split Orientation"), 0, this, SLOT(slotWinToggleSplitterOrientation()), ac, "win_toggle_split_orientation");
385 }
386
387 void KDiff3App::initDirectoryMergeActions()
388 {
389 #include "xpm/startmerge.xpm"
390 //dirOpen = new KAction(i18n("Open directories ..."), 0, this, SLOT(slotDirOpen()), actionCollection(), "dir_open");
391 dirStartOperation = new KAction(i18n("Start/Continue directory merge"), Key_F5, m_pDirectoryMergeWindow, SLOT(mergeContinue()), actionCollection(), "dir_start_operation");
392 dirCompareCurrent = new KAction(i18n("Compare selected file"), 0, m_pDirectoryMergeWindow, SLOT(compareCurrentFile()), actionCollection(), "dir_compare_current");
393 dirMergeCurrent = new KAction(i18n("Merge current file"), QIconSet(QPixmap(startmerge)), 0, this, SLOT(slotMergeCurrentFile()), actionCollection(), "merge_current");
394 dirShowBoth = new KToggleAction(i18n("Dir and Text Split Screen View"), 0, this, SLOT(slotDirShowBoth()), actionCollection(), "win_dir_show_both");
395 dirShowBoth->setChecked( true );
396 dirViewToggle = new KAction(i18n("Toggle between Dir and Text View"), 0, this, SLOT(slotDirViewToggle()), actionCollection(), "win_dir_view_toggle");
397 dirFoldAll = new KAction(i18n("Fold all subdirs"), 0, m_pDirectoryMergeWindow, SLOT(slotFoldAllSubdirs()), actionCollection(), "dir_fold_all");
398 dirUnfoldAll = new KAction(i18n("Unfold all subdirs"), 0, m_pDirectoryMergeWindow, SLOT(slotUnfoldAllSubdirs()), actionCollection(), "dir_unfold_all");
399 dirRescan = new KAction(i18n("Rescan"), 0, m_pDirectoryMergeWindow, SLOT(reload()), actionCollection(), "dir_rescan");
400 dirChooseAEverywhere = new KAction(i18n("Choose A for all items"), 0, m_pDirectoryMergeWindow, SLOT(slotChooseAEverywhere()), actionCollection(), "dir_choose_a_everywhere");
401 dirChooseBEverywhere = new KAction(i18n("Choose B for all items"), 0, m_pDirectoryMergeWindow, SLOT(slotChooseBEverywhere()), actionCollection(), "dir_choose_b_everywhere");
402 dirChooseCEverywhere = new KAction(i18n("Choose C for all items"), 0, m_pDirectoryMergeWindow, SLOT(slotChooseCEverywhere()), actionCollection(), "dir_choose_c_everywhere");
403 dirAutoChoiceEverywhere = new KAction(i18n("Auto-choose operation for all items"), 0, m_pDirectoryMergeWindow, SLOT(slotAutoChooseEverywhere()), actionCollection(), "dir_autochoose_everywhere");
404 dirDoNothingEverywhere = new KAction(i18n("No operation for all items"), 0, m_pDirectoryMergeWindow, SLOT(slotNoOpEverywhere()), actionCollection(), "dir_nothing_everywhere");
405 // choose A/B/C/Suggestion/NoOp everywhere
406
407
408 m_pMergeEditorPopupMenu = new QPopupMenu( this );
409 chooseA->plug( m_pMergeEditorPopupMenu );
410 chooseB->plug( m_pMergeEditorPopupMenu );
411 chooseC->plug( m_pMergeEditorPopupMenu );
412 }
413
414 void KDiff3App::showPopupMenu( const QPoint& point )
415 {
416 m_pMergeEditorPopupMenu->popup( point );
417 }
418
419 void KDiff3App::initStatusBar()
420 {
421 ///////////////////////////////////////////////////////////////////
422 // STATUSBAR
423 if (statusBar() !=0 )
424 statusBar()->message( i18n("Ready.") );
425 }
426
427 void KDiff3App::saveOptions( KConfig* config )
428 {
429 if ( !isPart() )
430 {
431 config->setGroup("General Options");
432 config->writeEntry("Geometry", m_pKDiff3Shell->size());
433 config->writeEntry("Position", m_pKDiff3Shell->pos());
434 config->writeEntry("Show Toolbar", viewToolBar->isChecked());
435 config->writeEntry("Show Statusbar",viewStatusBar->isChecked());
436 if(toolBar("mainToolBar")!=0)
437 config->writeEntry("ToolBarPos", (int) toolBar("mainToolBar")->barPos());
438 }
439 m_pOptionDialog->m_bAutoAdvance = autoAdvance->isChecked();
440 m_pOptionDialog->m_bShowWhiteSpace = showWhiteSpace->isChecked();
441 m_pOptionDialog->m_bShowLineNumbers = showLineNumbers->isChecked();
442
443 if ( m_pDiffWindowSplitter!=0 )
444 {
445 m_pOptionDialog->m_bHorizDiffWindowSplitting = m_pDiffWindowSplitter->orientation()==Horizontal;
446 }
447
448 m_pOptionDialog->saveOptions( config );
449 }
450
451
452 void KDiff3App::readOptions( KConfig* config )
453 {
454 if( !isPart() )
455 {
456 config->setGroup("General Options");
457
458 // bar status settings
459 bool bViewToolbar = config->readBoolEntry("Show Toolbar", true);
460 viewToolBar->setChecked(bViewToolbar);
461 slotViewToolBar();
462
463 bool bViewStatusbar = config->readBoolEntry("Show Statusbar", true);
464 viewStatusBar->setChecked(bViewStatusbar);
465 slotViewStatusBar();
466
467
468 // bar position settings
469 KToolBar::BarPosition toolBarPos;
470 toolBarPos=(KToolBar::BarPosition) config->readNumEntry("ToolBarPos", KToolBar::Top);
471 if( toolBar("mainToolBar")!=0 )
472 toolBar("mainToolBar")->setBarPos(toolBarPos);
473
474 QSize size=config->readSizeEntry("Geometry");
475 QPoint pos=config->readPointEntry("Position");
476 if(!size.isEmpty())
477 {
478 m_pKDiff3Shell->resize( size );
479 m_pKDiff3Shell->move( pos );
480 }
481 }
482 m_pOptionDialog->readOptions( config );
483
484 slotRefresh();
485 }
486
487
488 bool KDiff3App::queryClose()
489 {
490 saveOptions( isPart() ? m_pKDiff3Part->instance()->config() : kapp->config() );
491
492 if(m_bOutputModified)
493 {
494 int result = KMessageBox::warningYesNoCancel(this,
495 i18n("The merge result hasn't been saved."),
496 i18n("Warning"), i18n("Save and quit"), i18n("Quit without saving") );
497 if ( result==KMessageBox::Cancel )
498 return false;
499 else if ( result==KMessageBox::Yes )
500 {
501 slotFileSave();
502 if ( m_bOutputModified )
503 {
504 KMessageBox::sorry(this, i18n("Saving the merge result failed."), i18n("Warning") );
505 return false;
506 }
507 }
508 }
509
510 m_bOutputModified = false;
511
512 if ( m_pDirectoryMergeWindow->isDirectoryMergeInProgress() )
513 {
514 int result = KMessageBox::warningYesNo(this,
515 i18n("You are currently doing a directory merge. Are you sure, you want to abort?"),
516 i18n("Warning"), i18n("Yes - Quit"), i18n("No - Continue merging") );
517 if ( result!=KMessageBox::Yes )
518 return false;
519 }
520
521 return true;
522 }
523
524
525 /////////////////////////////////////////////////////////////////////
526 // SLOT IMPLEMENTATION
527 /////////////////////////////////////////////////////////////////////
528
529
530 void KDiff3App::slotFileSave()
531 {
532 if ( m_bDefaultFilename )
533 {
534 slotFileSaveAs();
535 }
536 else
537 {
538 slotStatusMsg(i18n("Saving file..."));
539
540 bool bSuccess = m_pMergeResultWindow->saveDocument( m_outputFilename );
541 if ( bSuccess )
542 {
543 m_bOutputModified = false;
544 if ( m_bDirCompare )
545 m_pDirectoryMergeWindow->mergeResultSaved(m_outputFilename);
546 }
547
548 slotStatusMsg(i18n("Ready."));
549 }
550 }
551
552 void KDiff3App::slotFileSaveAs()
553 {
554 slotStatusMsg(i18n("Saving file with a new filename..."));
555
556 QString s = KFileDialog::getSaveURL( QDir::currentDirPath(), 0, this, i18n("Save as...") ).url();
557 if(!s.isEmpty())
558 {
559 m_outputFilename = s;
560 bool bSuccess = m_pMergeResultWindow->saveDocument( m_outputFilename );
561 if ( bSuccess )
562 {
563 m_bOutputModified = false;
564 if ( m_bDirCompare )
565 m_pDirectoryMergeWindow->mergeResultSaved(m_outputFilename);
566 }
567 //setCaption(url.fileName(),doc->isModified());
568
569 m_bDefaultFilename = false;
570 }
571
572 slotStatusMsg(i18n("Ready."));
573 }
574
575
576 void KDiff3App::slotFileQuit()
577 {
578 slotStatusMsg(i18n("Exiting..."));
579
580 if( !queryClose() )
581 return; // Don't quit
582
583 KApplication::exit(0);
584 }
585
586
587
588 void KDiff3App::slotViewToolBar()
589 {
590 slotStatusMsg(i18n("Toggling toolbar..."));
591 ///////////////////////////////////////////////////////////////////
592 // turn Toolbar on or off
593 if ( toolBar("mainToolBar") !=0 )
594 {
595 if(!viewToolBar->isChecked())
596 {
597 toolBar("mainToolBar")->hide();
598 }
599 else
600 {
601 toolBar("mainToolBar")->show();
602 }
603 }
604
605 slotStatusMsg(i18n("Ready."));
606 }
607
608 void KDiff3App::slotViewStatusBar()
609 {
610 slotStatusMsg(i18n("Toggle the statusbar..."));
611 ///////////////////////////////////////////////////////////////////
612 //turn Statusbar on or off
613 if (statusBar() !=0 )
614 {
615 if(!viewStatusBar->isChecked())
616 {
617 statusBar()->hide();
618 }
619 else
620 {
621 statusBar()->show();
622 }
623 }
624
625 slotStatusMsg(i18n("Ready."));
626 }
627
628
629 void KDiff3App::slotStatusMsg(const QString &text)
630 {
631 ///////////////////////////////////////////////////////////////////
632 // change status message permanently
633 if (statusBar() !=0 )
634 {
635 statusBar()->clear();
636 statusBar()->message( text );
637 }
638 }
639
640
641
642 FindDialog::FindDialog(QWidget* pParent)
643 : QDialog( pParent )
644 {
645 QGridLayout* layout = new QGridLayout( this );
646 layout->setMargin(5);
647 layout->setSpacing(5);
648
649 int line=0;
650 layout->addMultiCellWidget( new QLabel(i18n("Searchtext:"),this), line,line,0,1 );
651 ++line;
652
653 m_pSearchString = new QLineEdit( this );
654 layout->addMultiCellWidget( m_pSearchString, line,line,0,1 );
655 ++line;
656
657 m_pCaseSensitive = new QCheckBox(i18n("Case Sensitive"),this);
658 layout->addWidget( m_pCaseSensitive, line, 1 );
659
660 m_pSearchInA = new QCheckBox(i18n("Search A"),this);
661 layout->addWidget( m_pSearchInA, line, 0 );
662 m_pSearchInA->setChecked( true );
663 ++line;
664
665 m_pSearchInB = new QCheckBox(i18n("Search B"),this);
666 layout->addWidget( m_pSearchInB, line, 0 );
667 m_pSearchInB->setChecked( true );
668 ++line;
669
670 m_pSearchInC = new QCheckBox(i18n("Search C"),this);
671 layout->addWidget( m_pSearchInC, line, 0 );
672 m_pSearchInC->setChecked( true );
673 ++line;
674
675 m_pSearchInOutput = new QCheckBox(i18n("Search Output"),this);
676 layout->addWidget( m_pSearchInOutput, line, 0 );
677 m_pSearchInOutput->setChecked( true );
678 ++line;
679
680 QPushButton* pButton = new QPushButton( i18n("Search"), this );
681 layout->addWidget( pButton, line, 0 );
682 connect( pButton, SIGNAL(clicked()), this, SLOT(accept()));
683
684 pButton = new QPushButton( i18n("Cancel"), this );
685 layout->addWidget( pButton, line, 1 );
686 connect( pButton, SIGNAL(clicked()), this, SLOT(reject()));
687
688 hide();
689 }
690
691 #include "kdiff3.moc"