comparison kdiff3/src/kdiff3.cpp @ 58:8af4bb9d9a5a

Version 0.9.83
author joachim99
date Sun, 07 Mar 2004 09:59:09 +0000
parents c59d5a3a8ff3
children efe33e938730
comparison
equal deleted inserted replaced
57:023fbd76c1e3 58:8af4bb9d9a5a
1 /*************************************************************************** 1 /***************************************************************************
2 kdiff3.cpp - description 2 kdiff3.cpp - description
3 ------------------- 3 -------------------
4 begin : Don Jul 11 12:31:29 CEST 2002 4 begin : Don Jul 11 12:31:29 CEST 2002
5 copyright : (C) 2002 by Joachim Eibl 5 copyright : (C) 2002-2004 by Joachim Eibl
6 email : joachim.eibl@gmx.de 6 email : joachim.eibl@gmx.de
7 ***************************************************************************/ 7 ***************************************************************************/
8 8
9 /*************************************************************************** 9 /***************************************************************************
10 * * 10 * *
106 m_bTimerBlock = false; 106 m_bTimerBlock = false;
107 107
108 // Needed before any file operations via FileAccess happen. 108 // Needed before any file operations via FileAccess happen.
109 g_pProgressDialog = new ProgressDialog(this); 109 g_pProgressDialog = new ProgressDialog(this);
110 110
111 // All default values must be set before calling readOptions().
112 m_pOptionDialog = new OptionDialog( m_pKDiff3Shell!=0, this );
113 connect( m_pOptionDialog, SIGNAL(applyClicked()), this, SLOT(slotRefresh()) );
114
115 m_pOptionDialog->readOptions( isPart() ? m_pKDiff3Part->instance()->config() : kapp->config() );
116
117 m_sd1.setOptionDialog(m_pOptionDialog);
118 m_sd2.setOptionDialog(m_pOptionDialog);
119 m_sd3.setOptionDialog(m_pOptionDialog);
120
111 // Option handling: Only when pParent==0 (no parent) 121 // Option handling: Only when pParent==0 (no parent)
112 KCmdLineArgs *args = isPart() ? 0 : KCmdLineArgs::parsedArgs(); 122 KCmdLineArgs *args = isPart() ? 0 : KCmdLineArgs::parsedArgs();
113 123
114 if (args!=0) 124 if (args!=0)
115 { 125 {
163 initStatusBar(); 173 initStatusBar();
164 174
165 m_pFindDialog = new FindDialog( this ); 175 m_pFindDialog = new FindDialog( this );
166 connect( m_pFindDialog, SIGNAL(findNext()), this, SLOT(slotEditFindNext())); 176 connect( m_pFindDialog, SIGNAL(findNext()), this, SLOT(slotEditFindNext()));
167 177
168 // All default values must be set before calling readOptions().
169 m_pOptionDialog = new OptionDialog( m_pKDiff3Shell!=0, this );
170 connect( m_pOptionDialog, SIGNAL(applyClicked()), this, SLOT(slotRefresh()) );
171
172 readOptions( isPart() ? m_pKDiff3Part->instance()->config() : kapp->config() ); 178 readOptions( isPart() ? m_pKDiff3Part->instance()->config() : kapp->config() );
173 179
174 autoAdvance->setChecked( m_pOptionDialog->m_bAutoAdvance ); 180 autoAdvance->setChecked( m_pOptionDialog->m_bAutoAdvance );
175 showWhiteSpaceCharacters->setChecked( m_pOptionDialog->m_bShowWhiteSpaceCharacters ); 181 showWhiteSpaceCharacters->setChecked( m_pOptionDialog->m_bShowWhiteSpaceCharacters );
176 showWhiteSpace->setChecked( m_pOptionDialog->m_bShowWhiteSpace ); 182 showWhiteSpace->setChecked( m_pOptionDialog->m_bShowWhiteSpace );
177 showWhiteSpaceCharacters->setEnabled( m_pOptionDialog->m_bShowWhiteSpace ); 183 showWhiteSpaceCharacters->setEnabled( m_pOptionDialog->m_bShowWhiteSpace );
178 showLineNumbers->setChecked( m_pOptionDialog->m_bShowLineNumbers ); 184 showLineNumbers->setChecked( m_pOptionDialog->m_bShowLineNumbers );
228 m_pDirectoryMergeSplitter->hide(); 234 m_pDirectoryMergeSplitter->hide();
229 235
230 init( m_bAuto ); 236 init( m_bAuto );
231 if ( m_bAuto ) 237 if ( m_bAuto )
232 { 238 {
233 const char* pBuf = 0; 239 SourceData* pSD=0;
234 unsigned int size = 0;
235 if ( m_sd3.isEmpty() ) 240 if ( m_sd3.isEmpty() )
236 { 241 {
237 if ( m_totalDiffStatus.bBinaryAEqB ){ pBuf=m_sd1.m_pBuf; size=m_sd1.m_size; } 242 if ( m_totalDiffStatus.bBinaryAEqB ){ pSD = &m_sd1; }
238 } 243 }
239 else 244 else
240 { 245 {
241 if ( m_totalDiffStatus.bBinaryBEqC ){ pBuf=m_sd3.m_pBuf; size=m_sd3.m_size; } 246 if ( m_totalDiffStatus.bBinaryBEqC ){ pSD = &m_sd3; } // B==C (assume A is old)
242 else if ( m_totalDiffStatus.bBinaryAEqB ){ pBuf=m_sd3.m_pBuf; size=m_sd3.m_size; } 247 else if ( m_totalDiffStatus.bBinaryAEqB ){ pSD = &m_sd3; } // assuming C has changed
243 else if ( m_totalDiffStatus.bBinaryAEqC ){ pBuf=m_sd2.m_pBuf; size=m_sd2.m_size; } 248 else if ( m_totalDiffStatus.bBinaryAEqC ){ pSD = &m_sd2; } // assuming B has changed
244 } 249 }
245 250
246 if ( pBuf!=0 ) 251 if ( pSD!=0 )
247 { 252 {
248 // Save this file directly, not via the merge result window. 253 // Save this file directly, not via the merge result window.
249 bool bSuccess = false; 254 bool bSuccess = false;
250 if ( m_pOptionDialog->m_bDmCreateBakFiles && QDir().exists( m_outputFilename ) ) 255 FileAccess fa( m_outputFilename );
256 if ( m_pOptionDialog->m_bDmCreateBakFiles && fa.exists() )
251 { 257 {
252 QString newName = m_outputFilename + ".orig"; 258 QString newName = m_outputFilename + ".orig";
253 if ( QDir().exists( newName ) ) QFile::remove(newName); 259 if ( FileAccess::exists( newName ) ) FileAccess::removeFile( newName );
254 if ( !QDir().exists( newName ) ) QDir().rename( m_outputFilename, newName ); 260 if ( !FileAccess::exists( newName ) ) fa.rename( newName );
255 } 261 }
256 QFile file( m_outputFilename ); 262
257 if ( file.open( IO_WriteOnly ) ) 263 bSuccess = pSD->saveNormalDataAs( m_outputFilename );
258 {
259 bSuccess = (long)size == file.writeBlock ( pBuf, size );
260 file.close();
261 }
262 if ( bSuccess ) ::exit(0); 264 if ( bSuccess ) ::exit(0);
263 else KMessageBox::error( this, i18n("Saving failed.") ); 265 else KMessageBox::error( this, i18n("Saving failed.") );
264 } 266 }
265 else if ( m_pMergeResultWindow->getNrOfUnsolvedConflicts() == 0 ) 267 else if ( m_pMergeResultWindow->getNrOfUnsolvedConflicts() == 0 )
266 { 268 {
278 slotUpdateAvailabilities(); 280 slotUpdateAvailabilities();
279 281
280 if ( ! m_bDirCompare && m_pKDiff3Shell!=0 ) 282 if ( ! m_bDirCompare && m_pKDiff3Shell!=0 )
281 { 283 {
282 bool bFileOpenError = false; 284 bool bFileOpenError = false;
283 if ( ! m_sd1.isEmpty() && m_sd1.m_pBuf==0 || 285 if ( ! m_sd1.isEmpty() && !m_sd1.hasData() ||
284 ! m_sd2.isEmpty() && m_sd2.m_pBuf==0 || 286 ! m_sd2.isEmpty() && !m_sd2.hasData() ||
285 ! m_sd3.isEmpty() && m_sd3.m_pBuf==0 ) 287 ! m_sd3.isEmpty() && !m_sd3.hasData() )
286 { 288 {
287 QString text( i18n("Opening of these files failed:") ); 289 QString text( i18n("Opening of these files failed:") );
288 text += "\n\n"; 290 text += "\n\n";
289 if ( ! m_sd1.isEmpty() && m_sd1.m_pBuf==0 ) 291 if ( ! m_sd1.isEmpty() && !m_sd1.hasData() )
290 text += " - " + m_sd1.getAliasName() + "\n"; 292 text += " - " + m_sd1.getAliasName() + "\n";
291 if ( ! m_sd2.isEmpty() && m_sd2.m_pBuf==0 ) 293 if ( ! m_sd2.isEmpty() && !m_sd2.hasData() )
292 text += " - " + m_sd2.getAliasName() + "\n"; 294 text += " - " + m_sd2.getAliasName() + "\n";
293 if ( ! m_sd3.isEmpty() && m_sd3.m_pBuf==0 ) 295 if ( ! m_sd3.isEmpty() && !m_sd3.hasData() )
294 text += " - " + m_sd3.getAliasName() + "\n"; 296 text += " - " + m_sd3.getAliasName() + "\n";
295 297
296 KMessageBox::sorry( this, text, i18n("File Open Error") ); 298 KMessageBox::sorry( this, text, i18n("File Open Error") );
297 bFileOpenError = true; 299 bFileOpenError = true;
298 } 300 }
351 #include "xpm/iconA.xpm" 353 #include "xpm/iconA.xpm"
352 #include "xpm/iconB.xpm" 354 #include "xpm/iconB.xpm"
353 #include "xpm/iconC.xpm" 355 #include "xpm/iconC.xpm"
354 #include "xpm/autoadvance.xpm" 356 #include "xpm/autoadvance.xpm"
355 #include "xpm/showwhitespace.xpm" 357 #include "xpm/showwhitespace.xpm"
358 #include "xpm/showwhitespacechars.xpm"
356 #include "xpm/showlinenumbers.xpm" 359 #include "xpm/showlinenumbers.xpm"
357 //#include "reload.xpm" 360 //#include "reload.xpm"
358 361
359 goCurrent = new KAction(i18n("Go to Current Delta"), QIconSet(QPixmap(currentpos)), CTRL+Key_Space, this, SLOT(slotGoCurrent()), ac, "go_current"); 362 goCurrent = new KAction(i18n("Go to Current Delta"), QIconSet(QPixmap(currentpos)), CTRL+Key_Space, this, SLOT(slotGoCurrent()), ac, "go_current");
360 goTop = new KAction(i18n("Go to First Delta"), QIconSet(QPixmap(upend)), 0, this, SLOT(slotGoTop()), ac, "go_top"); 363 goTop = new KAction(i18n("Go to First Delta"), QIconSet(QPixmap(upend)), 0, this, SLOT(slotGoTop()), ac, "go_top");
368 chooseA = new KToggleAction(i18n("Select Line(s) From A"), QIconSet(QPixmap(iconA)), CTRL+Key_1, this, SLOT(slotChooseA()), ac, "merge_choose_a"); 371 chooseA = new KToggleAction(i18n("Select Line(s) From A"), QIconSet(QPixmap(iconA)), CTRL+Key_1, this, SLOT(slotChooseA()), ac, "merge_choose_a");
369 chooseB = new KToggleAction(i18n("Select Line(s) From B"), QIconSet(QPixmap(iconB)), CTRL+Key_2, this, SLOT(slotChooseB()), ac, "merge_choose_b"); 372 chooseB = new KToggleAction(i18n("Select Line(s) From B"), QIconSet(QPixmap(iconB)), CTRL+Key_2, this, SLOT(slotChooseB()), ac, "merge_choose_b");
370 chooseC = new KToggleAction(i18n("Select Line(s) From C"), QIconSet(QPixmap(iconC)), CTRL+Key_3, this, SLOT(slotChooseC()), ac, "merge_choose_c"); 373 chooseC = new KToggleAction(i18n("Select Line(s) From C"), QIconSet(QPixmap(iconC)), CTRL+Key_3, this, SLOT(slotChooseC()), ac, "merge_choose_c");
371 autoAdvance = new KToggleAction(i18n("Automatically Go to Next Unsolved Conflict After Source Selection"), QIconSet(QPixmap(autoadvance)), 0, this, SLOT(slotAutoAdvanceToggled()), ac, "merge_autoadvance"); 374 autoAdvance = new KToggleAction(i18n("Automatically Go to Next Unsolved Conflict After Source Selection"), QIconSet(QPixmap(autoadvance)), 0, this, SLOT(slotAutoAdvanceToggled()), ac, "merge_autoadvance");
372 375
373 showWhiteSpaceCharacters = new KToggleAction(i18n("Show Space && Tabulator Characters for Differences"), QIconSet(QPixmap(showwhitespace)), 0, this, SLOT(slotShowWhiteSpaceToggled()), ac, "merge_show_whitespace_characters"); 376 showWhiteSpaceCharacters = new KToggleAction(i18n("Show Space && Tabulator Characters for Differences"), QIconSet(QPixmap(showwhitespacechars)), 0, this, SLOT(slotShowWhiteSpaceToggled()), ac, "merge_show_whitespace_characters");
374 showWhiteSpace = new KToggleAction(i18n("Show White Space"), 0, this, SLOT(slotShowWhiteSpaceToggled()), ac, "merge_show_whitespace"); 377 showWhiteSpace = new KToggleAction(i18n("Show White Space"), QIconSet(QPixmap(showwhitespace)), 0, this, SLOT(slotShowWhiteSpaceToggled()), ac, "merge_show_whitespace");
375 378
376 showLineNumbers = new KToggleAction(i18n("Show Line Numbers"), QIconSet(QPixmap(showlinenumbers)), 0, this, SLOT(slotShowLineNumbersToggled()), ac, "merge_showlinenumbers"); 379 showLineNumbers = new KToggleAction(i18n("Show Line Numbers"), QIconSet(QPixmap(showlinenumbers)), 0, this, SLOT(slotShowLineNumbersToggled()), ac, "merge_showlinenumbers");
377 chooseAEverywhere = new KAction(i18n("Choose A Everywhere"), CTRL+SHIFT+Key_1, this, SLOT(slotChooseAEverywhere()), ac, "merge_choose_a_everywhere"); 380 chooseAEverywhere = new KAction(i18n("Choose A Everywhere"), CTRL+SHIFT+Key_1, this, SLOT(slotChooseAEverywhere()), ac, "merge_choose_a_everywhere");
378 chooseBEverywhere = new KAction(i18n("Choose B Everywhere"), CTRL+SHIFT+Key_2, this, SLOT(slotChooseBEverywhere()), ac, "merge_choose_b_everywhere"); 381 chooseBEverywhere = new KAction(i18n("Choose B Everywhere"), CTRL+SHIFT+Key_2, this, SLOT(slotChooseBEverywhere()), ac, "merge_choose_b_everywhere");
379 chooseCEverywhere = new KAction(i18n("Choose C Everywhere"), CTRL+SHIFT+Key_3, this, SLOT(slotChooseCEverywhere()), ac, "merge_choose_c_everywhere"); 382 chooseCEverywhere = new KAction(i18n("Choose C Everywhere"), CTRL+SHIFT+Key_3, this, SLOT(slotChooseCEverywhere()), ac, "merge_choose_c_everywhere");
465 { 468 {
466 m_pKDiff3Shell->resize( size ); 469 m_pKDiff3Shell->resize( size );
467 m_pKDiff3Shell->move( pos ); 470 m_pKDiff3Shell->move( pos );
468 } 471 }
469 } 472 }
470 m_pOptionDialog->readOptions( config );
471 473
472 slotRefresh(); 474 slotRefresh();
473 } 475 }
474 476
475 477