joachim99@8: /*************************************************************************** joachim99@8: kdiff3.cpp - description joachim99@8: ------------------- joachim99@8: begin : Don Jul 11 12:31:29 CEST 2002 joachim99@8: copyright : (C) 2002 by Joachim Eibl joachim99@8: email : joachim.eibl@gmx.de joachim99@8: ***************************************************************************/ joachim99@8: joachim99@8: /*************************************************************************** joachim99@8: * * joachim99@8: * This program is free software; you can redistribute it and/or modify * joachim99@8: * it under the terms of the GNU General Public License as published by * joachim99@8: * the Free Software Foundation; either version 2 of the License, or * joachim99@8: * (at your option) any later version. * joachim99@8: * * joachim99@8: ***************************************************************************/ joachim99@8: joachim99@8: /*************************************************************************** joachim99@8: * $Log$ joachim99@8: * Revision 1.1 2003/10/06 18:38:48 joachim99 joachim99@8: * KDiff3 version 0.9.70 joachim99@8: * * joachim99@8: ***************************************************************************/ joachim99@8: joachim99@8: #include "diff.h" joachim99@8: joachim99@8: #include joachim99@8: joachim99@8: // include files for QT joachim99@8: #include joachim99@8: #include joachim99@8: #include joachim99@8: #include joachim99@8: #include joachim99@8: #include joachim99@8: #include joachim99@8: #include joachim99@8: #include joachim99@8: #include joachim99@8: joachim99@8: // include files for KDE joachim99@8: #include joachim99@8: #include joachim99@8: #include joachim99@8: #include joachim99@8: #include joachim99@8: #include joachim99@8: #include joachim99@8: #include joachim99@8: #include joachim99@8: //#include joachim99@8: joachim99@8: // application specific includes joachim99@8: #include "kdiff3.h" joachim99@8: #include "optiondialog.h" joachim99@8: #include "fileaccess.h" joachim99@8: #include "kdiff3_part.h" joachim99@8: #include "directorymergewindow.h" joachim99@8: joachim99@8: #define ID_STATUS_MSG 1 joachim99@8: joachim99@8: KActionCollection* KDiff3App::actionCollection() joachim99@8: { joachim99@8: if ( m_pKDiff3Shell==0 ) joachim99@8: return m_pKDiff3Part->actionCollection(); joachim99@8: else joachim99@8: return m_pKDiff3Shell->actionCollection(); joachim99@8: } joachim99@8: joachim99@8: KStatusBar* KDiff3App::statusBar() joachim99@8: { joachim99@8: if ( m_pKDiff3Shell==0 ) joachim99@8: return 0; joachim99@8: else joachim99@8: return m_pKDiff3Shell->statusBar(); joachim99@8: } joachim99@8: joachim99@8: KToolBar* KDiff3App::toolBar(const char* toolBarId ) joachim99@8: { joachim99@8: if ( m_pKDiff3Shell==0 ) joachim99@8: return 0; joachim99@8: else joachim99@8: return m_pKDiff3Shell->toolBar( toolBarId ); joachim99@8: } joachim99@8: joachim99@8: bool KDiff3App::isPart() joachim99@8: { joachim99@8: return m_pKDiff3Shell==0; joachim99@8: } joachim99@8: joachim99@8: joachim99@8: KDiff3App::KDiff3App(QWidget* pParent, const char* name, KDiff3Part* pKDiff3Part ) joachim99@8: :QSplitter(pParent, name) //previously KMainWindow joachim99@8: { joachim99@8: m_pKDiff3Part = pKDiff3Part; joachim99@8: m_pKDiff3Shell = dynamic_cast(pParent); joachim99@8: joachim99@8: setCaption( "KDiff3" ); joachim99@8: joachim99@8: m_pMainSplitter = 0; joachim99@8: m_pDirectoryMergeWindow = 0; joachim99@8: m_pCornerWidget = 0; joachim99@8: m_pMainWidget = 0; joachim99@8: m_pDiffTextWindow1 = 0; joachim99@8: m_pDiffTextWindow2 = 0; joachim99@8: m_pDiffTextWindow3 = 0; joachim99@8: m_pDiffWindowSplitter = 0; joachim99@8: m_pOverview = 0; joachim99@8: m_bTripleDiff = false; joachim99@8: m_pMergeResultWindow = 0; joachim99@8: m_pMergeWindowFrame = 0; joachim99@8: m_bOutputModified = false; joachim99@8: m_bTimerBlock = false; joachim99@8: joachim99@8: // Option handling: Only when pParent==0 (no parent) joachim99@8: KCmdLineArgs *args = isPart() ? 0 : KCmdLineArgs::parsedArgs(); joachim99@8: joachim99@8: if (args!=0) joachim99@8: { joachim99@8: m_outputFilename = args->getOption("output"); joachim99@8: if ( m_outputFilename.isEmpty() ) joachim99@8: m_outputFilename = args->getOption("out"); joachim99@8: } joachim99@8: joachim99@8: m_bAuto = args!=0 && args->isSet("auto"); joachim99@8: if ( m_bAuto && m_outputFilename.isEmpty() ) joachim99@8: { joachim99@8: //KMessageBox::information(this, i18n("Option --auto used, but no output file specified.")); joachim99@8: std::cerr << i18n("Option --auto used, but no output file specified.").ascii()<isSet("merge") ) joachim99@8: { joachim99@8: m_outputFilename = "unnamed.txt"; joachim99@8: m_bDefaultFilename = true; joachim99@8: } joachim99@8: else joachim99@8: m_bDefaultFilename = false; joachim99@8: joachim99@8: g_bAutoSolve = args!=0 && !args->isSet("qall"); // Note that this is effective only once. joachim99@8: joachim99@8: if ( args!=0 ) joachim99@8: { joachim99@8: m_sd1.setFilename( args->getOption("base") ); joachim99@8: if ( m_sd1.isEmpty() ) joachim99@8: { joachim99@8: if ( args->count() > 0 ) m_sd1.setFilename( args->arg(0) ); joachim99@8: if ( args->count() > 1 ) m_sd2.setFilename( args->arg(1) ); joachim99@8: if ( args->count() > 2 ) m_sd3.setFilename( args->arg(2) ); joachim99@8: } joachim99@8: else joachim99@8: { joachim99@8: if ( args->count() > 0 ) m_sd2.setFilename( args->arg(0) ); joachim99@8: if ( args->count() > 1 ) m_sd3.setFilename( args->arg(1) ); joachim99@8: } joachim99@8: joachim99@8: QCStringList aliasList = args->getOptionList("fname"); joachim99@8: QCStringList::Iterator ali = aliasList.begin(); joachim99@8: if ( ali != aliasList.end() ) { m_sd1.setAliasName(*ali); ++ali; } joachim99@8: if ( ali != aliasList.end() ) { m_sd2.setAliasName(*ali); ++ali; } joachim99@8: if ( ali != aliasList.end() ) { m_sd3.setAliasName(*ali); ++ali; } joachim99@8: } joachim99@8: g_pProgressDialog = new ProgressDialog(this); joachim99@8: /////////////////////////////////////////////////////////////////// joachim99@8: // call inits to invoke all other construction parts joachim99@8: initActions(actionCollection()); joachim99@8: initStatusBar(); joachim99@8: joachim99@8: m_pFindDialog = new FindDialog( this ); joachim99@8: connect( m_pFindDialog, SIGNAL(findNext()), this, SLOT(slotEditFindNext())); joachim99@8: joachim99@8: // All default values must be set before calling readOptions(). joachim99@8: m_pOptionDialog = new OptionDialog( m_pKDiff3Shell!=0, this ); joachim99@8: connect( m_pOptionDialog, SIGNAL(applyClicked()), this, SLOT(slotRefresh()) ); joachim99@8: joachim99@8: readOptions( isPart() ? m_pKDiff3Part->instance()->config() : kapp->config() ); joachim99@8: joachim99@8: m_pMainSplitter = this; //new QSplitter(this); joachim99@8: m_pMainSplitter->setOrientation( Vertical ); joachim99@8: // setCentralWidget( m_pMainSplitter ); joachim99@8: m_pDirectoryMergeSplitter = new QSplitter( m_pMainSplitter ); joachim99@8: m_pDirectoryMergeSplitter->setOrientation( Horizontal ); joachim99@8: m_pDirectoryMergeWindow = new DirectoryMergeWindow( m_pDirectoryMergeSplitter, m_pOptionDialog, joachim99@8: KApplication::kApplication()->iconLoader() ); joachim99@8: m_pDirectoryMergeInfo = new DirectoryMergeInfo( m_pDirectoryMergeSplitter ); joachim99@8: m_pDirectoryMergeWindow->setDirectoryMergeInfo( m_pDirectoryMergeInfo ); joachim99@8: connect( m_pDirectoryMergeWindow, SIGNAL(startDiffMerge(QString,QString,QString,QString,QString,QString,QString)), joachim99@8: this, SLOT( slotFileOpen2(QString,QString,QString,QString,QString,QString,QString))); joachim99@8: connect( m_pDirectoryMergeWindow, SIGNAL(selectionChanged()), this, SLOT(slotUpdateAvailabilities())); joachim99@8: connect( m_pDirectoryMergeWindow, SIGNAL(currentChanged(QListViewItem*)), this, SLOT(slotUpdateAvailabilities())); joachim99@8: connect( m_pDirectoryMergeWindow, SIGNAL(checkIfCanContinue(bool*)), this, SLOT(slotCheckIfCanContinue(bool*))); joachim99@8: connect( m_pDirectoryMergeWindow, SIGNAL(updateAvailabilities()), this, SLOT(slotUpdateAvailabilities())); joachim99@8: joachim99@8: initDirectoryMergeActions(); joachim99@8: joachim99@8: if ( args!=0 ) args->clear(); // Free up some memory. joachim99@8: joachim99@8: if (m_pKDiff3Shell==0) joachim99@8: { joachim99@8: completeInit(); joachim99@8: } joachim99@8: } joachim99@8: joachim99@8: joachim99@8: void KDiff3App::completeInit() joachim99@8: { joachim99@8: if (m_pKDiff3Shell!=0) joachim99@8: { joachim99@8: QSize size=kapp->config()->readSizeEntry("Geometry"); joachim99@8: QPoint pos=kapp->config()->readPointEntry("Position"); joachim99@8: if(!size.isEmpty()) joachim99@8: { joachim99@8: m_pKDiff3Shell->resize( size ); joachim99@8: m_pKDiff3Shell->move( pos ); joachim99@8: } joachim99@8: } joachim99@8: joachim99@8: m_bDirCompare = improveFilenames(); joachim99@8: if ( m_bAuto && m_bDirCompare ) joachim99@8: { joachim99@8: std::cerr << i18n("Option --auto ignored for directory comparison.").ascii()<hide(); joachim99@8: joachim99@8: init( m_bAuto ); joachim99@8: if ( m_bAuto ) joachim99@8: { joachim99@8: const char* pBuf = 0; joachim99@8: unsigned int size = 0; joachim99@8: if ( m_sd3.isEmpty() ) joachim99@8: { joachim99@8: if ( m_totalDiffStatus.bBinaryAEqB ){ pBuf=m_sd1.m_pBuf; size=m_sd1.m_size; } joachim99@8: } joachim99@8: else joachim99@8: { joachim99@8: if ( m_totalDiffStatus.bBinaryBEqC ){ pBuf=m_sd3.m_pBuf; size=m_sd3.m_size; } joachim99@8: else if ( m_totalDiffStatus.bBinaryAEqB ){ pBuf=m_sd3.m_pBuf; size=m_sd3.m_size; } joachim99@8: else if ( m_totalDiffStatus.bBinaryAEqC ){ pBuf=m_sd2.m_pBuf; size=m_sd2.m_size; } joachim99@8: } joachim99@8: joachim99@8: if ( pBuf!=0 ) joachim99@8: { joachim99@8: // Save this file directly, not via the merge result window. joachim99@8: bool bSuccess = false; joachim99@8: if ( m_pOptionDialog->m_bDmCreateBakFiles && QDir().exists( m_outputFilename ) ) joachim99@8: { joachim99@8: QString newName = m_outputFilename + ".orig"; joachim99@8: if ( QDir().exists( newName ) ) QFile::remove(newName); joachim99@8: if ( !QDir().exists( newName ) ) QDir().rename( m_outputFilename, newName ); joachim99@8: } joachim99@8: QFile file( m_outputFilename ); joachim99@8: if ( file.open( IO_WriteOnly ) ) joachim99@8: { joachim99@8: bSuccess = (long)size == file.writeBlock ( pBuf, size ); joachim99@8: file.close(); joachim99@8: } joachim99@8: if ( bSuccess ) ::exit(0); joachim99@8: else KMessageBox::error( this, i18n("Saving failed.") ); joachim99@8: } joachim99@8: else if ( m_pMergeResultWindow->getNrOfUnsolvedConflicts() == 0 ) joachim99@8: { joachim99@8: bool bSuccess = m_pMergeResultWindow->saveDocument( m_outputFilename ); joachim99@8: if ( bSuccess ) ::exit(0); joachim99@8: } joachim99@8: } joachim99@8: } joachim99@8: joachim99@8: if (statusBar() !=0 ) joachim99@8: statusBar()->setSizeGripEnabled(false); joachim99@8: joachim99@8: slotClipboardChanged(); // For initialisation. joachim99@8: joachim99@8: slotUpdateAvailabilities(); joachim99@8: joachim99@8: if ( ! m_bDirCompare && m_pKDiff3Shell!=0 ) joachim99@8: { joachim99@8: bool bFileOpenError = false; joachim99@8: if ( ! m_sd1.isEmpty() && m_sd1.m_pBuf==0 || joachim99@8: ! m_sd2.isEmpty() && m_sd2.m_pBuf==0 || joachim99@8: ! m_sd3.isEmpty() && m_sd3.m_pBuf==0 ) joachim99@8: { joachim99@8: QString text( i18n("Opening of these files failed:") ); joachim99@8: text += "\n\n"; joachim99@8: if ( ! m_sd1.isEmpty() && m_sd1.m_pBuf==0 ) joachim99@8: text += " - " + m_sd1.getAliasName() + "\n"; joachim99@8: if ( ! m_sd2.isEmpty() && m_sd2.m_pBuf==0 ) joachim99@8: text += " - " + m_sd2.getAliasName() + "\n"; joachim99@8: if ( ! m_sd3.isEmpty() && m_sd3.m_pBuf==0 ) joachim99@8: text += " - " + m_sd3.getAliasName() + "\n"; joachim99@8: joachim99@8: KMessageBox::sorry( this, text, i18n("File open error") ); joachim99@8: bFileOpenError = true; joachim99@8: } joachim99@8: joachim99@8: if ( m_sd1.isEmpty() || m_sd2.isEmpty() || bFileOpenError ) joachim99@8: slotFileOpen(); joachim99@8: } joachim99@8: } joachim99@8: joachim99@8: KDiff3App::~KDiff3App() joachim99@8: { joachim99@8: joachim99@8: } joachim99@8: joachim99@8: void KDiff3App::initActions( KActionCollection* ac ) joachim99@8: { joachim99@8: if (ac==0) KMessageBox::error(0, "actionCollection==0"); joachim99@8: joachim99@8: fileOpen = KStdAction::open(this, SLOT(slotFileOpen()), ac); joachim99@8: fileOpen->setStatusText(i18n("Opens documents for comparison ...")); joachim99@8: fileSave = KStdAction::save(this, SLOT(slotFileSave()), ac); joachim99@8: fileSave->setStatusText(i18n("Saves the merge result. All conflicts must be solved!")); joachim99@8: fileSaveAs = KStdAction::saveAs(this, SLOT(slotFileSaveAs()), ac); joachim99@8: fileSaveAs->setStatusText(i18n("Saves the current document as...")); joachim99@8: fileQuit = KStdAction::quit(this, SLOT(slotFileQuit()), ac); joachim99@8: fileQuit->setStatusText(i18n("Quits the application")); joachim99@8: editCut = KStdAction::cut(this, SLOT(slotEditCut()), ac); joachim99@8: editCut->setStatusText(i18n("Cuts the selected section and puts it to the clipboard")); joachim99@8: editCopy = KStdAction::copy(this, SLOT(slotEditCopy()), ac); joachim99@8: editCopy->setStatusText(i18n("Copies the selected section to the clipboard")); joachim99@8: editPaste = KStdAction::paste(this, SLOT(slotEditPaste()), ac); joachim99@8: editPaste->setStatusText(i18n("Pastes the clipboard contents to actual position")); joachim99@8: editFind = KStdAction::find(this, SLOT(slotEditFind()), ac); joachim99@8: editFind->setStatusText(i18n("Search for a string")); joachim99@8: editFindNext = KStdAction::findNext(this, SLOT(slotEditFindNext()), ac); joachim99@8: editFindNext->setStatusText(i18n("Search again for the string")); joachim99@8: viewToolBar = KStdAction::showToolbar(this, SLOT(slotViewToolBar()), ac); joachim99@8: viewToolBar->setStatusText(i18n("Enables/disables the toolbar")); joachim99@8: viewStatusBar = KStdAction::showStatusbar(this, SLOT(slotViewStatusBar()), ac); joachim99@8: viewStatusBar->setStatusText(i18n("Enables/disables the statusbar")); joachim99@8: KStdAction::keyBindings(this, SLOT(slotConfigureKeys()), ac); joachim99@8: KAction* pAction = KStdAction::preferences(this, SLOT(slotConfigure()), ac ); joachim99@8: if ( isPart() ) joachim99@8: pAction->setText("Configure KDiff3 ..."); joachim99@8: joachim99@8: joachim99@8: #include "xpm/downend.xpm" joachim99@8: #include "xpm/currentpos.xpm" joachim99@8: #include "xpm/down1arrow.xpm" joachim99@8: #include "xpm/down2arrow.xpm" joachim99@8: #include "xpm/upend.xpm" joachim99@8: #include "xpm/up1arrow.xpm" joachim99@8: #include "xpm/up2arrow.xpm" joachim99@8: #include "xpm/prevunsolved.xpm" joachim99@8: #include "xpm/nextunsolved.xpm" joachim99@8: #include "xpm/iconA.xpm" joachim99@8: #include "xpm/iconB.xpm" joachim99@8: #include "xpm/iconC.xpm" joachim99@8: #include "xpm/autoadvance.xpm" joachim99@8: #include "xpm/showwhitespace.xpm" joachim99@8: #include "xpm/showlinenumbers.xpm" joachim99@8: //#include "reload.xpm" joachim99@8: joachim99@8: goCurrent = new KAction(i18n("Go to Current Delta"), QIconSet(QPixmap(currentpos)), CTRL+Key_Space, this, SLOT(slotGoCurrent()), ac, "go_current"); joachim99@8: goTop = new KAction(i18n("Go to First Delta"), QIconSet(QPixmap(upend)), 0, this, SLOT(slotGoTop()), ac, "go_top"); joachim99@8: goBottom = new KAction(i18n("Go to Last Delta"), QIconSet(QPixmap(downend)), 0, this, SLOT(slotGoBottom()), ac, "go_bottom"); joachim99@8: goPrevDelta = new KAction(i18n("Go to PrevDelta"), QIconSet(QPixmap(up1arrow)), CTRL+Key_Up, this, SLOT(slotGoPrevDelta()), ac, "go_prev_delta"); joachim99@8: goNextDelta = new KAction(i18n("Go to NextDelta"), QIconSet(QPixmap(down1arrow)), CTRL+Key_Down, this, SLOT(slotGoNextDelta()), ac, "go_next_delta"); joachim99@8: goPrevConflict = new KAction(i18n("Go to Previous Conflict"), QIconSet(QPixmap(up2arrow)), CTRL+Key_PageUp, this, SLOT(slotGoPrevConflict()), ac, "go_prev_conflict"); joachim99@8: goNextConflict = new KAction(i18n("Go to Next Conflict"), QIconSet(QPixmap(down2arrow)), CTRL+Key_PageDown, this, SLOT(slotGoNextConflict()), ac, "go_next_conflict"); joachim99@8: goPrevUnsolvedConflict = new KAction(i18n("Go to Previous Unsolved Conflict"), QIconSet(QPixmap(prevunsolved)), 0, this, SLOT(slotGoPrevUnsolvedConflict()), ac, "go_prev_unsolved_conflict"); joachim99@8: goNextUnsolvedConflict = new KAction(i18n("Go to Next Unsolved Conflict"), QIconSet(QPixmap(nextunsolved)), 0, this, SLOT(slotGoNextUnsolvedConflict()), ac, "go_next_unsolved_conflict"); joachim99@8: chooseA = new KToggleAction(i18n("Select line(s) from A"), QIconSet(QPixmap(iconA)), CTRL+Key_1, this, SLOT(slotChooseA()), ac, "merge_choose_a"); joachim99@8: chooseB = new KToggleAction(i18n("Select line(s) from B"), QIconSet(QPixmap(iconB)), CTRL+Key_2, this, SLOT(slotChooseB()), ac, "merge_choose_b"); joachim99@8: chooseC = new KToggleAction(i18n("Select line(s) from C"), QIconSet(QPixmap(iconC)), CTRL+Key_3, this, SLOT(slotChooseC()), ac, "merge_choose_c"); joachim99@8: 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: showWhiteSpace = new KToggleAction(i18n("Show space and tabulator characters for differences"), QIconSet(QPixmap(showwhitespace)), 0, this, SLOT(slotShowWhiteSpaceToggled()), ac, "merge_showwhitespace"); joachim99@8: showLineNumbers = new KToggleAction(i18n("Show line numbers"), QIconSet(QPixmap(showlinenumbers)), 0, this, SLOT(slotShowLineNumbersToggled()), ac, "merge_showlinenumbers"); joachim99@8: chooseAEverywhere = new KAction(i18n("Choose A Everywhere"), CTRL+SHIFT+Key_1, this, SLOT(slotChooseAEverywhere()), ac, "merge_choose_a_everywhere"); joachim99@8: chooseBEverywhere = new KAction(i18n("Choose B Everywhere"), CTRL+SHIFT+Key_2, this, SLOT(slotChooseBEverywhere()), ac, "merge_choose_b_everywhere"); joachim99@8: chooseCEverywhere = new KAction(i18n("Choose C Everywhere"), CTRL+SHIFT+Key_3, this, SLOT(slotChooseCEverywhere()), ac, "merge_choose_c_everywhere"); joachim99@8: autoSolve = new KAction(i18n("Automatically solve simple conflicts"), 0, this, SLOT(slotAutoSolve()), ac, "merge_autosolve"); joachim99@8: unsolve = new KAction(i18n("Set deltas to conflicts"), 0, this, SLOT(slotUnsolve()), actionCollection(), "merge_autounsolve"); joachim99@8: fileReload = new KAction(i18n("Reload"), /*QIconSet(QPixmap(reloadIcon)),*/ 0, this, SLOT(slotReload()), ac, "file_reload"); joachim99@8: showWindowA = new KToggleAction(i18n("Show Window A"), 0, this, SLOT(slotShowWindowAToggled()), ac, "win_show_a"); joachim99@8: showWindowB = new KToggleAction(i18n("Show Window B"), 0, this, SLOT(slotShowWindowBToggled()), ac, "win_show_b"); joachim99@8: showWindowC = new KToggleAction(i18n("Show Window C"), 0, this, SLOT(slotShowWindowCToggled()), ac, "win_show_c"); joachim99@8: winFocusNext = new KAction(i18n("Focus Next Window"), ALT+Key_Right, this, SLOT(slotWinFocusNext()), ac, "win_focus_next"); joachim99@8: winFocusPrev = new KAction(i18n("Focus Prev Window"), ALT+Key_Left, this, SLOT(slotWinFocusPrev()), ac, "win_focus_prev"); joachim99@8: winToggleSplitOrientation = new KAction(i18n("Toggle Split Orientation"), 0, this, SLOT(slotWinToggleSplitterOrientation()), ac, "win_toggle_split_orientation"); joachim99@8: } joachim99@8: joachim99@8: void KDiff3App::initDirectoryMergeActions() joachim99@8: { joachim99@8: #include "xpm/startmerge.xpm" joachim99@8: //dirOpen = new KAction(i18n("Open directories ..."), 0, this, SLOT(slotDirOpen()), actionCollection(), "dir_open"); joachim99@8: dirStartOperation = new KAction(i18n("Start/Continue directory merge"), Key_F5, m_pDirectoryMergeWindow, SLOT(mergeContinue()), actionCollection(), "dir_start_operation"); joachim99@8: dirCompareCurrent = new KAction(i18n("Compare selected file"), 0, m_pDirectoryMergeWindow, SLOT(compareCurrentFile()), actionCollection(), "dir_compare_current"); joachim99@8: dirMergeCurrent = new KAction(i18n("Merge current file"), QIconSet(QPixmap(startmerge)), 0, this, SLOT(slotMergeCurrentFile()), actionCollection(), "merge_current"); joachim99@8: dirShowBoth = new KToggleAction(i18n("Dir and Text Split Screen View"), 0, this, SLOT(slotDirShowBoth()), actionCollection(), "win_dir_show_both"); joachim99@8: dirShowBoth->setChecked( true ); joachim99@8: dirViewToggle = new KAction(i18n("Toggle between Dir and Text View"), 0, this, SLOT(slotDirViewToggle()), actionCollection(), "win_dir_view_toggle"); joachim99@8: dirFoldAll = new KAction(i18n("Fold all subdirs"), 0, m_pDirectoryMergeWindow, SLOT(slotFoldAllSubdirs()), actionCollection(), "dir_fold_all"); joachim99@8: dirUnfoldAll = new KAction(i18n("Unfold all subdirs"), 0, m_pDirectoryMergeWindow, SLOT(slotUnfoldAllSubdirs()), actionCollection(), "dir_unfold_all"); joachim99@8: dirRescan = new KAction(i18n("Rescan"), 0, m_pDirectoryMergeWindow, SLOT(reload()), actionCollection(), "dir_rescan"); joachim99@8: dirChooseAEverywhere = new KAction(i18n("Choose A for all items"), 0, m_pDirectoryMergeWindow, SLOT(slotChooseAEverywhere()), actionCollection(), "dir_choose_a_everywhere"); joachim99@8: dirChooseBEverywhere = new KAction(i18n("Choose B for all items"), 0, m_pDirectoryMergeWindow, SLOT(slotChooseBEverywhere()), actionCollection(), "dir_choose_b_everywhere"); joachim99@8: dirChooseCEverywhere = new KAction(i18n("Choose C for all items"), 0, m_pDirectoryMergeWindow, SLOT(slotChooseCEverywhere()), actionCollection(), "dir_choose_c_everywhere"); joachim99@8: dirAutoChoiceEverywhere = new KAction(i18n("Auto-choose operation for all items"), 0, m_pDirectoryMergeWindow, SLOT(slotAutoChooseEverywhere()), actionCollection(), "dir_autochoose_everywhere"); joachim99@8: dirDoNothingEverywhere = new KAction(i18n("No operation for all items"), 0, m_pDirectoryMergeWindow, SLOT(slotNoOpEverywhere()), actionCollection(), "dir_nothing_everywhere"); joachim99@8: // choose A/B/C/Suggestion/NoOp everywhere joachim99@8: joachim99@8: joachim99@8: m_pMergeEditorPopupMenu = new QPopupMenu( this ); joachim99@8: chooseA->plug( m_pMergeEditorPopupMenu ); joachim99@8: chooseB->plug( m_pMergeEditorPopupMenu ); joachim99@8: chooseC->plug( m_pMergeEditorPopupMenu ); joachim99@8: } joachim99@8: joachim99@8: void KDiff3App::showPopupMenu( const QPoint& point ) joachim99@8: { joachim99@8: m_pMergeEditorPopupMenu->popup( point ); joachim99@8: } joachim99@8: joachim99@8: void KDiff3App::initStatusBar() joachim99@8: { joachim99@8: /////////////////////////////////////////////////////////////////// joachim99@8: // STATUSBAR joachim99@8: if (statusBar() !=0 ) joachim99@8: statusBar()->message( i18n("Ready.") ); joachim99@8: } joachim99@8: joachim99@8: void KDiff3App::saveOptions( KConfig* config ) joachim99@8: { joachim99@8: if ( !isPart() ) joachim99@8: { joachim99@8: config->setGroup("General Options"); joachim99@8: config->writeEntry("Geometry", m_pKDiff3Shell->size()); joachim99@8: config->writeEntry("Position", m_pKDiff3Shell->pos()); joachim99@8: config->writeEntry("Show Toolbar", viewToolBar->isChecked()); joachim99@8: config->writeEntry("Show Statusbar",viewStatusBar->isChecked()); joachim99@8: if(toolBar("mainToolBar")!=0) joachim99@8: config->writeEntry("ToolBarPos", (int) toolBar("mainToolBar")->barPos()); joachim99@8: } joachim99@8: m_pOptionDialog->m_bAutoAdvance = autoAdvance->isChecked(); joachim99@8: m_pOptionDialog->m_bShowWhiteSpace = showWhiteSpace->isChecked(); joachim99@8: m_pOptionDialog->m_bShowLineNumbers = showLineNumbers->isChecked(); joachim99@8: joachim99@8: if ( m_pDiffWindowSplitter!=0 ) joachim99@8: { joachim99@8: m_pOptionDialog->m_bHorizDiffWindowSplitting = m_pDiffWindowSplitter->orientation()==Horizontal; joachim99@8: } joachim99@8: joachim99@8: m_pOptionDialog->saveOptions( config ); joachim99@8: } joachim99@8: joachim99@8: joachim99@8: void KDiff3App::readOptions( KConfig* config ) joachim99@8: { joachim99@8: if( !isPart() ) joachim99@8: { joachim99@8: config->setGroup("General Options"); joachim99@8: joachim99@8: // bar status settings joachim99@8: bool bViewToolbar = config->readBoolEntry("Show Toolbar", true); joachim99@8: viewToolBar->setChecked(bViewToolbar); joachim99@8: slotViewToolBar(); joachim99@8: joachim99@8: bool bViewStatusbar = config->readBoolEntry("Show Statusbar", true); joachim99@8: viewStatusBar->setChecked(bViewStatusbar); joachim99@8: slotViewStatusBar(); joachim99@8: joachim99@8: joachim99@8: // bar position settings joachim99@8: KToolBar::BarPosition toolBarPos; joachim99@8: toolBarPos=(KToolBar::BarPosition) config->readNumEntry("ToolBarPos", KToolBar::Top); joachim99@8: if( toolBar("mainToolBar")!=0 ) joachim99@8: toolBar("mainToolBar")->setBarPos(toolBarPos); joachim99@8: joachim99@8: QSize size=config->readSizeEntry("Geometry"); joachim99@8: QPoint pos=config->readPointEntry("Position"); joachim99@8: if(!size.isEmpty()) joachim99@8: { joachim99@8: m_pKDiff3Shell->resize( size ); joachim99@8: m_pKDiff3Shell->move( pos ); joachim99@8: } joachim99@8: } joachim99@8: m_pOptionDialog->readOptions( config ); joachim99@8: joachim99@8: slotRefresh(); joachim99@8: } joachim99@8: joachim99@8: joachim99@8: bool KDiff3App::queryClose() joachim99@8: { joachim99@8: saveOptions( isPart() ? m_pKDiff3Part->instance()->config() : kapp->config() ); joachim99@8: joachim99@8: if(m_bOutputModified) joachim99@8: { joachim99@8: int result = KMessageBox::warningYesNoCancel(this, joachim99@8: i18n("The merge result hasn't been saved."), joachim99@8: i18n("Warning"), i18n("Save and quit"), i18n("Quit without saving") ); joachim99@8: if ( result==KMessageBox::Cancel ) joachim99@8: return false; joachim99@8: else if ( result==KMessageBox::Yes ) joachim99@8: { joachim99@8: slotFileSave(); joachim99@8: if ( m_bOutputModified ) joachim99@8: { joachim99@8: KMessageBox::sorry(this, i18n("Saving the merge result failed."), i18n("Warning") ); joachim99@8: return false; joachim99@8: } joachim99@8: } joachim99@8: } joachim99@8: joachim99@8: m_bOutputModified = false; joachim99@8: joachim99@8: if ( m_pDirectoryMergeWindow->isDirectoryMergeInProgress() ) joachim99@8: { joachim99@8: int result = KMessageBox::warningYesNo(this, joachim99@8: i18n("You are currently doing a directory merge. Are you sure, you want to abort?"), joachim99@8: i18n("Warning"), i18n("Yes - Quit"), i18n("No - Continue merging") ); joachim99@8: if ( result!=KMessageBox::Yes ) joachim99@8: return false; joachim99@8: } joachim99@8: joachim99@8: return true; joachim99@8: } joachim99@8: joachim99@8: joachim99@8: ///////////////////////////////////////////////////////////////////// joachim99@8: // SLOT IMPLEMENTATION joachim99@8: ///////////////////////////////////////////////////////////////////// joachim99@8: joachim99@8: joachim99@8: void KDiff3App::slotFileSave() joachim99@8: { joachim99@8: if ( m_bDefaultFilename ) joachim99@8: { joachim99@8: slotFileSaveAs(); joachim99@8: } joachim99@8: else joachim99@8: { joachim99@8: slotStatusMsg(i18n("Saving file...")); joachim99@8: joachim99@8: bool bSuccess = m_pMergeResultWindow->saveDocument( m_outputFilename ); joachim99@8: if ( bSuccess ) joachim99@8: { joachim99@8: m_bOutputModified = false; joachim99@8: if ( m_bDirCompare ) joachim99@8: m_pDirectoryMergeWindow->mergeResultSaved(m_outputFilename); joachim99@8: } joachim99@8: joachim99@8: slotStatusMsg(i18n("Ready.")); joachim99@8: } joachim99@8: } joachim99@8: joachim99@8: void KDiff3App::slotFileSaveAs() joachim99@8: { joachim99@8: slotStatusMsg(i18n("Saving file with a new filename...")); joachim99@8: joachim99@8: QString s = KFileDialog::getSaveURL( QDir::currentDirPath(), 0, this, i18n("Save as...") ).url(); joachim99@8: if(!s.isEmpty()) joachim99@8: { joachim99@8: m_outputFilename = s; joachim99@8: bool bSuccess = m_pMergeResultWindow->saveDocument( m_outputFilename ); joachim99@8: if ( bSuccess ) joachim99@8: { joachim99@8: m_bOutputModified = false; joachim99@8: if ( m_bDirCompare ) joachim99@8: m_pDirectoryMergeWindow->mergeResultSaved(m_outputFilename); joachim99@8: } joachim99@8: //setCaption(url.fileName(),doc->isModified()); joachim99@8: joachim99@8: m_bDefaultFilename = false; joachim99@8: } joachim99@8: joachim99@8: slotStatusMsg(i18n("Ready.")); joachim99@8: } joachim99@8: joachim99@8: joachim99@8: void KDiff3App::slotFileQuit() joachim99@8: { joachim99@8: slotStatusMsg(i18n("Exiting...")); joachim99@8: joachim99@8: if( !queryClose() ) joachim99@8: return; // Don't quit joachim99@8: joachim99@8: KApplication::exit(0); joachim99@8: } joachim99@8: joachim99@8: joachim99@8: joachim99@8: void KDiff3App::slotViewToolBar() joachim99@8: { joachim99@8: slotStatusMsg(i18n("Toggling toolbar...")); joachim99@8: /////////////////////////////////////////////////////////////////// joachim99@8: // turn Toolbar on or off joachim99@8: if ( toolBar("mainToolBar") !=0 ) joachim99@8: { joachim99@8: if(!viewToolBar->isChecked()) joachim99@8: { joachim99@8: toolBar("mainToolBar")->hide(); joachim99@8: } joachim99@8: else joachim99@8: { joachim99@8: toolBar("mainToolBar")->show(); joachim99@8: } joachim99@8: } joachim99@8: joachim99@8: slotStatusMsg(i18n("Ready.")); joachim99@8: } joachim99@8: joachim99@8: void KDiff3App::slotViewStatusBar() joachim99@8: { joachim99@8: slotStatusMsg(i18n("Toggle the statusbar...")); joachim99@8: /////////////////////////////////////////////////////////////////// joachim99@8: //turn Statusbar on or off joachim99@8: if (statusBar() !=0 ) joachim99@8: { joachim99@8: if(!viewStatusBar->isChecked()) joachim99@8: { joachim99@8: statusBar()->hide(); joachim99@8: } joachim99@8: else joachim99@8: { joachim99@8: statusBar()->show(); joachim99@8: } joachim99@8: } joachim99@8: joachim99@8: slotStatusMsg(i18n("Ready.")); joachim99@8: } joachim99@8: joachim99@8: joachim99@8: void KDiff3App::slotStatusMsg(const QString &text) joachim99@8: { joachim99@8: /////////////////////////////////////////////////////////////////// joachim99@8: // change status message permanently joachim99@8: if (statusBar() !=0 ) joachim99@8: { joachim99@8: statusBar()->clear(); joachim99@8: statusBar()->message( text ); joachim99@8: } joachim99@8: } joachim99@8: joachim99@8: joachim99@8: joachim99@8: FindDialog::FindDialog(QWidget* pParent) joachim99@8: : QDialog( pParent ) joachim99@8: { joachim99@8: QGridLayout* layout = new QGridLayout( this ); joachim99@8: layout->setMargin(5); joachim99@8: layout->setSpacing(5); joachim99@8: joachim99@8: int line=0; joachim99@8: layout->addMultiCellWidget( new QLabel(i18n("Searchtext:"),this), line,line,0,1 ); joachim99@8: ++line; joachim99@8: joachim99@8: m_pSearchString = new QLineEdit( this ); joachim99@8: layout->addMultiCellWidget( m_pSearchString, line,line,0,1 ); joachim99@8: ++line; joachim99@8: joachim99@8: m_pCaseSensitive = new QCheckBox(i18n("Case Sensitive"),this); joachim99@8: layout->addWidget( m_pCaseSensitive, line, 1 ); joachim99@8: joachim99@8: m_pSearchInA = new QCheckBox(i18n("Search A"),this); joachim99@8: layout->addWidget( m_pSearchInA, line, 0 ); joachim99@8: m_pSearchInA->setChecked( true ); joachim99@8: ++line; joachim99@8: joachim99@8: m_pSearchInB = new QCheckBox(i18n("Search B"),this); joachim99@8: layout->addWidget( m_pSearchInB, line, 0 ); joachim99@8: m_pSearchInB->setChecked( true ); joachim99@8: ++line; joachim99@8: joachim99@8: m_pSearchInC = new QCheckBox(i18n("Search C"),this); joachim99@8: layout->addWidget( m_pSearchInC, line, 0 ); joachim99@8: m_pSearchInC->setChecked( true ); joachim99@8: ++line; joachim99@8: joachim99@8: m_pSearchInOutput = new QCheckBox(i18n("Search Output"),this); joachim99@8: layout->addWidget( m_pSearchInOutput, line, 0 ); joachim99@8: m_pSearchInOutput->setChecked( true ); joachim99@8: ++line; joachim99@8: joachim99@8: QPushButton* pButton = new QPushButton( i18n("Search"), this ); joachim99@8: layout->addWidget( pButton, line, 0 ); joachim99@8: connect( pButton, SIGNAL(clicked()), this, SLOT(accept())); joachim99@8: joachim99@8: pButton = new QPushButton( i18n("Cancel"), this ); joachim99@8: layout->addWidget( pButton, line, 1 ); joachim99@8: connect( pButton, SIGNAL(clicked()), this, SLOT(reject())); joachim99@8: joachim99@8: hide(); joachim99@8: } joachim99@8: joachim99@8: #include "kdiff3.moc"