annotate kdiff3/src/kdiff3.cpp @ 26:07416314eb5e

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