1 // TortoiseMerge - a Diff/Patch program
\r
3 // Copyright (C) 2004-2009 - TortoiseSVN
\r
5 // This program is free software; you can redistribute it and/or
\r
6 // modify it under the terms of the GNU General Public License
\r
7 // as published by the Free Software Foundation; either version 2
\r
8 // of the License, or (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, write to the Free Software Foundation,
\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
20 #include "TortoiseMerge.h"
\r
21 #include "OpenDlg.h"
\r
23 #include "SysProgressDlg.h"
\r
24 #include "Settings.h"
\r
25 #include "MessageBox.h"
\r
26 #include "AppUtils.h"
\r
27 #include "PathUtils.h"
\r
28 #include "MainFrm.h"
\r
29 #include "LeftView.h"
\r
30 #include "RightView.h"
\r
31 #include "BottomView.h"
\r
32 #include "DiffColors.h"
\r
33 #include ".\mainfrm.h"
\r
36 #define new DEBUG_NEW
\r
41 const UINT CMainFrame::m_FindDialogMessage = RegisterWindowMessage(FINDMSGSTRING);
\r
43 IMPLEMENT_DYNCREATE(CMainFrame, CFrameWndEx)
\r
45 BEGIN_MESSAGE_MAP(CMainFrame, CFrameWndEx)
\r
47 ON_COMMAND_RANGE(ID_VIEW_APPLOOK_WIN_2000, ID_VIEW_APPLOOK_OFF_2007_AQUA, &CMainFrame::OnApplicationLook)
\r
48 ON_UPDATE_COMMAND_UI_RANGE(ID_VIEW_APPLOOK_WIN_2000, ID_VIEW_APPLOOK_OFF_2007_AQUA, &CMainFrame::OnUpdateApplicationLook)
\r
49 // Global help commands
\r
50 ON_COMMAND(ID_HELP_FINDER, CFrameWndEx::OnHelpFinder)
\r
51 ON_COMMAND(ID_HELP, CFrameWndEx::OnHelp)
\r
52 ON_COMMAND(ID_CONTEXT_HELP, CFrameWndEx::OnContextHelp)
\r
53 ON_COMMAND(ID_DEFAULT_HELP, CFrameWndEx::OnHelpFinder)
\r
54 ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
\r
55 ON_COMMAND(ID_VIEW_WHITESPACES, OnViewWhitespaces)
\r
57 ON_COMMAND(ID_FILE_SAVE, OnFileSave)
\r
58 ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
\r
59 ON_UPDATE_COMMAND_UI(ID_FILE_SAVE, OnUpdateFileSave)
\r
60 ON_UPDATE_COMMAND_UI(ID_FILE_SAVE_AS, OnUpdateFileSaveAs)
\r
61 ON_COMMAND(ID_VIEW_ONEWAYDIFF, OnViewOnewaydiff)
\r
62 ON_UPDATE_COMMAND_UI(ID_VIEW_ONEWAYDIFF, OnUpdateViewOnewaydiff)
\r
63 ON_UPDATE_COMMAND_UI(ID_VIEW_WHITESPACES, OnUpdateViewWhitespaces)
\r
64 ON_COMMAND(ID_VIEW_OPTIONS, OnViewOptions)
\r
66 ON_COMMAND(ID_EDIT_FIND, OnEditFind)
\r
67 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
\r
68 ON_COMMAND(ID_EDIT_FINDNEXT, OnEditFindnext)
\r
69 ON_COMMAND(ID_EDIT_FINDPREV, OnEditFindprev)
\r
70 ON_COMMAND(ID_FILE_RELOAD, OnFileReload)
\r
71 ON_COMMAND(ID_VIEW_LINEDOWN, OnViewLinedown)
\r
72 ON_COMMAND(ID_VIEW_LINEUP, OnViewLineup)
\r
73 ON_UPDATE_COMMAND_UI(ID_EDIT_MARKASRESOLVED, OnUpdateMergeMarkasresolved)
\r
74 ON_COMMAND(ID_EDIT_MARKASRESOLVED, OnMergeMarkasresolved)
\r
75 ON_UPDATE_COMMAND_UI(ID_NAVIGATE_NEXTCONFLICT, OnUpdateMergeNextconflict)
\r
76 ON_UPDATE_COMMAND_UI(ID_NAVIGATE_PREVIOUSCONFLICT, OnUpdateMergePreviousconflict)
\r
79 ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateEditCopy)
\r
80 ON_COMMAND(ID_VIEW_SWITCHLEFT, OnViewSwitchleft)
\r
81 ON_UPDATE_COMMAND_UI(ID_VIEW_SWITCHLEFT, OnUpdateViewSwitchleft)
\r
82 ON_COMMAND(ID_VIEW_LINELEFT, &CMainFrame::OnViewLineleft)
\r
83 ON_COMMAND(ID_VIEW_LINERIGHT, &CMainFrame::OnViewLineright)
\r
84 ON_UPDATE_COMMAND_UI(ID_VIEW_SHOWFILELIST, &CMainFrame::OnUpdateViewShowfilelist)
\r
85 ON_COMMAND(ID_VIEW_SHOWFILELIST, &CMainFrame::OnViewShowfilelist)
\r
86 ON_COMMAND(ID_EDIT_USETHEIRBLOCK, &CMainFrame::OnEditUseTheirs)
\r
87 ON_COMMAND(ID_EDIT_USEMYBLOCK, &CMainFrame::OnEditUseMine)
\r
88 ON_COMMAND(ID_EDIT_USETHEIRTHENMYBLOCK, &CMainFrame::OnEditUseTheirsThenMine)
\r
89 ON_COMMAND(ID_EDIT_USEMINETHENTHEIRBLOCK, &CMainFrame::OnEditUseMineThenTheirs)
\r
90 ON_COMMAND(ID_EDIT_UNDO, &CMainFrame::OnEditUndo)
\r
91 ON_UPDATE_COMMAND_UI(ID_EDIT_UNDO, &CMainFrame::OnUpdateEditUndo)
\r
92 ON_UPDATE_COMMAND_UI(ID_EDIT_USEMINETHENTHEIRBLOCK, &CMainFrame::OnUpdateEditUseminethentheirblock)
\r
93 ON_UPDATE_COMMAND_UI(ID_EDIT_USEMYBLOCK, &CMainFrame::OnUpdateEditUsemyblock)
\r
94 ON_UPDATE_COMMAND_UI(ID_EDIT_USETHEIRBLOCK, &CMainFrame::OnUpdateEditUsetheirblock)
\r
95 ON_UPDATE_COMMAND_UI(ID_EDIT_USETHEIRTHENMYBLOCK, &CMainFrame::OnUpdateEditUsetheirthenmyblock)
\r
96 ON_COMMAND(ID_VIEW_INLINEDIFFWORD, &CMainFrame::OnViewInlinediffword)
\r
97 ON_UPDATE_COMMAND_UI(ID_VIEW_INLINEDIFFWORD, &CMainFrame::OnUpdateViewInlinediffword)
\r
98 ON_UPDATE_COMMAND_UI(ID_EDIT_CREATEUNIFIEDDIFFFILE, &CMainFrame::OnUpdateEditCreateunifieddifffile)
\r
99 ON_COMMAND(ID_EDIT_CREATEUNIFIEDDIFFFILE, &CMainFrame::OnEditCreateunifieddifffile)
\r
100 ON_UPDATE_COMMAND_UI(ID_VIEW_LINEDIFFBAR, &CMainFrame::OnUpdateViewLinediffbar)
\r
101 ON_COMMAND(ID_VIEW_LINEDIFFBAR, &CMainFrame::OnViewLinediffbar)
\r
102 ON_UPDATE_COMMAND_UI(ID_VIEW_LOCATORBAR, &CMainFrame::OnUpdateViewLocatorbar)
\r
103 ON_COMMAND(ID_VIEW_LOCATORBAR, &CMainFrame::OnViewLocatorbar)
\r
104 ON_COMMAND(ID_EDIT_USELEFTBLOCK, &CMainFrame::OnEditUseleftblock)
\r
105 ON_UPDATE_COMMAND_UI(ID_EDIT_USELEFTBLOCK, &CMainFrame::OnUpdateEditUseleftblock)
\r
106 ON_COMMAND(ID_EDIT_USELEFTFILE, &CMainFrame::OnEditUseleftfile)
\r
107 ON_UPDATE_COMMAND_UI(ID_EDIT_USELEFTFILE, &CMainFrame::OnUpdateEditUseleftfile)
\r
108 ON_COMMAND(ID_EDIT_USEBLOCKFROMLEFTBEFORERIGHT, &CMainFrame::OnEditUseblockfromleftbeforeright)
\r
109 ON_UPDATE_COMMAND_UI(ID_EDIT_USEBLOCKFROMLEFTBEFORERIGHT, &CMainFrame::OnUpdateEditUseblockfromleftbeforeright)
\r
110 ON_COMMAND(ID_EDIT_USEBLOCKFROMRIGHTBEFORELEFT, &CMainFrame::OnEditUseblockfromrightbeforeleft)
\r
111 ON_UPDATE_COMMAND_UI(ID_EDIT_USEBLOCKFROMRIGHTBEFORELEFT, &CMainFrame::OnUpdateEditUseblockfromrightbeforeleft)
\r
114 static UINT indicators[] =
\r
116 ID_SEPARATOR, // status line indicator
\r
117 ID_INDICATOR_LEFTVIEW,
\r
118 ID_INDICATOR_RIGHTVIEW,
\r
119 ID_INDICATOR_BOTTOMVIEW,
\r
126 // CMainFrame construction/destruction
\r
128 CMainFrame::CMainFrame()
\r
130 m_pFindDialog = NULL;
\r
131 m_nSearchIndex = 0;
\r
132 m_bInitSplitter = FALSE;
\r
133 m_bOneWay = (0 != ((DWORD)CRegDWORD(_T("Software\\TortoiseMerge\\OnePane"))));
\r
134 m_bReversedPatch = FALSE;
\r
135 m_bHasConflicts = false;
\r
136 m_bInlineWordDiff = true;
\r
137 m_bLineDiff = true;
\r
138 m_bLocatorBar = true;
\r
139 m_nMoveMovesToIgnore = 0;
\r
140 theApp.m_nAppLook = theApp.GetInt(_T("ApplicationLook"), ID_VIEW_APPLOOK_VS_2005);
\r
143 CMainFrame::~CMainFrame()
\r
147 int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
\r
149 if (CFrameWndEx::OnCreate(lpCreateStruct) == -1)
\r
152 OnApplicationLook(theApp.m_nAppLook);
\r
154 if (!m_wndMenuBar.Create(this))
\r
156 TRACE0("Failed to create menubar\n");
\r
157 return -1; // fail to create
\r
160 m_wndMenuBar.SetPaneStyle(m_wndMenuBar.GetPaneStyle() | CBRS_SIZE_DYNAMIC | CBRS_TOOLTIPS | CBRS_FLYBY);
\r
162 // prevent the menu bar from taking the focus on activation
\r
163 CMFCPopupMenu::SetForceMenuFocus(FALSE);
\r
165 if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_ALIGN_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY) ||
\r
166 !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
\r
168 TRACE0("Failed to create toolbar\n");
\r
169 return -1; // fail to create
\r
171 m_wndToolBar.SetWindowText(_T("Main"));
\r
173 if (!m_wndStatusBar.Create(this) ||
\r
174 !m_wndStatusBar.SetIndicators(indicators,
\r
175 sizeof(indicators)/sizeof(UINT)))
\r
177 TRACE0("Failed to create status bar\n");
\r
178 return -1; // fail to create
\r
181 if (!m_wndLocatorBar.Create(this, IDD_DIFFLOCATOR,
\r
182 CBRS_ALIGN_LEFT | CBRS_SIZE_FIXED, ID_VIEW_LOCATORBAR))
\r
184 TRACE0("Failed to create dialogbar\n");
\r
185 return -1; // fail to create
\r
187 if (!m_wndLineDiffBar.Create(this, IDD_LINEDIFF,
\r
188 CBRS_ALIGN_BOTTOM | CBRS_SIZE_FIXED, ID_VIEW_LINEDIFFBAR))
\r
190 TRACE0("Failed to create dialogbar\n");
\r
191 return -1; // fail to create
\r
193 m_wndLocatorBar.m_pMainFrm = this;
\r
194 m_wndLineDiffBar.m_pMainFrm = this;
\r
196 EnableDocking(CBRS_ALIGN_ANY);
\r
197 m_wndMenuBar.EnableDocking(CBRS_ALIGN_TOP);
\r
198 m_wndToolBar.EnableDocking(CBRS_ALIGN_TOP);
\r
199 DockPane(&m_wndMenuBar);
\r
200 DockPane(&m_wndToolBar);
\r
201 DockPane(&m_wndLocatorBar);
\r
202 DockPane(&m_wndLineDiffBar);
\r
203 ShowPane(&m_wndLocatorBar, true, false, true);
\r
204 ShowPane(&m_wndLineDiffBar, true, false, true);
\r
206 m_wndLocatorBar.EnableGripper(FALSE);
\r
207 m_wndLineDiffBar.EnableGripper(FALSE);
\r
212 BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
\r
214 if( !CFrameWndEx::PreCreateWindow(cs) )
\r
219 void CMainFrame::OnApplicationLook(UINT id)
\r
223 theApp.m_nAppLook = id;
\r
225 switch (theApp.m_nAppLook)
\r
227 case ID_VIEW_APPLOOK_WIN_2000:
\r
228 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManager));
\r
231 case ID_VIEW_APPLOOK_OFF_XP:
\r
232 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOfficeXP));
\r
235 case ID_VIEW_APPLOOK_WIN_XP:
\r
236 CMFCVisualManagerWindows::m_b3DTabsXPTheme = TRUE;
\r
237 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
\r
240 case ID_VIEW_APPLOOK_OFF_2003:
\r
241 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2003));
\r
242 CDockingManager::SetDockingMode(DT_SMART);
\r
245 case ID_VIEW_APPLOOK_VS_2005:
\r
246 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerVS2005));
\r
247 CDockingManager::SetDockingMode(DT_SMART);
\r
251 switch (theApp.m_nAppLook)
\r
253 case ID_VIEW_APPLOOK_OFF_2007_BLUE:
\r
254 CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_LunaBlue);
\r
257 case ID_VIEW_APPLOOK_OFF_2007_BLACK:
\r
258 CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_ObsidianBlack);
\r
261 case ID_VIEW_APPLOOK_OFF_2007_SILVER:
\r
262 CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_Silver);
\r
265 case ID_VIEW_APPLOOK_OFF_2007_AQUA:
\r
266 CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_Aqua);
\r
270 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2007));
\r
271 CDockingManager::SetDockingMode(DT_SMART);
\r
274 RedrawWindow(NULL, NULL, RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_UPDATENOW | RDW_FRAME | RDW_ERASE);
\r
276 theApp.WriteInt(_T("ApplicationLook"), theApp.m_nAppLook);
\r
279 void CMainFrame::OnUpdateApplicationLook(CCmdUI* pCmdUI)
\r
281 pCmdUI->SetRadio(theApp.m_nAppLook == pCmdUI->m_nID);
\r
285 // CMainFrame diagnostics
\r
288 void CMainFrame::AssertValid() const
\r
290 CFrameWndEx::AssertValid();
\r
293 void CMainFrame::Dump(CDumpContext& dc) const
\r
295 CFrameWndEx::Dump(dc);
\r
301 // CMainFrame message handlers
\r
304 BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/, CCreateContext* pContext)
\r
307 GetClientRect( &cr);
\r
310 // split into three panes:
\r
319 // create a splitter with 2 rows, 1 column
\r
320 if (!m_wndSplitter.CreateStatic(this, 2, 1))
\r
322 TRACE0("Failed to CreateStaticSplitter\n");
\r
326 // add the second splitter pane - which is a nested splitter with 2 columns
\r
327 if (!m_wndSplitter2.CreateStatic(
\r
328 &m_wndSplitter, // our parent window is the first splitter
\r
329 1, 2, // the new splitter is 1 row, 2 columns
\r
330 WS_CHILD | WS_VISIBLE | WS_BORDER, // style, WS_BORDER is needed
\r
331 m_wndSplitter.IdFromRowCol(0, 0)
\r
332 // new splitter is in the first row, 1st column of first splitter
\r
335 TRACE0("Failed to create nested splitter\n");
\r
338 // add the first splitter pane - the default view in row 0
\r
339 if (!m_wndSplitter.CreateView(1, 0,
\r
340 RUNTIME_CLASS(CBottomView), CSize(cr.Width(), cr.Height()), pContext))
\r
342 TRACE0("Failed to create first pane\n");
\r
345 m_pwndBottomView = (CBottomView *)m_wndSplitter.GetPane(1,0);
\r
346 m_pwndBottomView->m_pwndLocator = &m_wndLocatorBar;
\r
347 m_pwndBottomView->m_pwndLineDiffBar = &m_wndLineDiffBar;
\r
348 m_pwndBottomView->m_pwndStatusBar = &m_wndStatusBar;
\r
349 m_pwndBottomView->m_pMainFrame = this;
\r
351 // now create the two views inside the nested splitter
\r
353 if (!m_wndSplitter2.CreateView(0, 0,
\r
354 RUNTIME_CLASS(CLeftView), CSize(cr.Width()/2, cr.Height()/2), pContext))
\r
356 TRACE0("Failed to create second pane\n");
\r
359 m_pwndLeftView = (CLeftView *)m_wndSplitter2.GetPane(0,0);
\r
360 m_pwndLeftView->m_pwndLocator = &m_wndLocatorBar;
\r
361 m_pwndLeftView->m_pwndLineDiffBar = &m_wndLineDiffBar;
\r
362 m_pwndLeftView->m_pwndStatusBar = &m_wndStatusBar;
\r
363 m_pwndLeftView->m_pMainFrame = this;
\r
365 if (!m_wndSplitter2.CreateView(0, 1,
\r
366 RUNTIME_CLASS(CRightView), CSize(cr.Width()/2, cr.Height()/2), pContext))
\r
368 TRACE0("Failed to create third pane\n");
\r
371 m_pwndRightView = (CRightView *)m_wndSplitter2.GetPane(0,1);
\r
372 m_pwndRightView->m_pwndLocator = &m_wndLocatorBar;
\r
373 m_pwndRightView->m_pwndLineDiffBar = &m_wndLineDiffBar;
\r
374 m_pwndRightView->m_pwndStatusBar = &m_wndStatusBar;
\r
375 m_pwndRightView->m_pMainFrame = this;
\r
376 m_bInitSplitter = TRUE;
\r
378 m_dlgFilePatches.Create(IDD_FILEPATCHES, this);
\r
383 // Callback function
\r
384 BOOL CMainFrame::PatchFile(CString sFilePath, CString sVersion, BOOL bAutoPatch)
\r
386 //first, do a "dry run" of patching...
\r
387 if (!m_Patch.PatchFile(sFilePath))
\r
389 //patching not successful, so retrieve the
\r
390 //base file from version control and try
\r
393 CSysProgressDlg progDlg;
\r
394 sTemp.Format(IDS_GETVERSIONOFFILE, (LPCTSTR)sVersion);
\r
395 progDlg.SetLine(1, sTemp, true);
\r
396 progDlg.SetLine(2, sFilePath, true);
\r
397 sTemp.LoadString(IDS_GETVERSIONOFFILETITLE);
\r
398 progDlg.SetTitle(sTemp);
\r
399 progDlg.SetShowProgressBar(false);
\r
400 progDlg.SetAnimation(IDR_DOWNLOAD);
\r
401 progDlg.SetTime(FALSE);
\r
402 progDlg.ShowModeless(this);
\r
403 CString sBaseFile = m_TempFiles.GetTempFilePath();
\r
404 if (!CAppUtils::GetVersionedFile(sFilePath, sVersion, sBaseFile, &progDlg, m_hWnd))
\r
408 sErrMsg.Format(IDS_ERR_MAINFRAME_FILEVERSIONNOTFOUND, (LPCTSTR)sVersion, (LPCTSTR)sFilePath);
\r
409 MessageBox(sErrMsg, NULL, MB_ICONERROR);
\r
413 CString sTempFile = m_TempFiles.GetTempFilePath();
\r
414 if (!m_Patch.PatchFile(sFilePath, sTempFile, sBaseFile))
\r
416 MessageBox(m_Patch.GetErrorMessage(), NULL, MB_ICONERROR);
\r
420 temp.Format(_T("%s Revision %s"), (LPCTSTR)CPathUtils::GetFileNameFromPath(sFilePath), (LPCTSTR)sVersion);
\r
421 m_Data.m_baseFile.SetFileName(sBaseFile);
\r
422 m_Data.m_baseFile.SetDescriptiveName(temp);
\r
423 temp.Format(_T("%s %s"), (LPCTSTR)CPathUtils::GetFileNameFromPath(sFilePath), (LPCTSTR)m_Data.m_sPatchPatched);
\r
424 m_Data.m_theirFile.SetFileName(sTempFile);
\r
425 m_Data.m_theirFile.SetDescriptiveName(temp);
\r
426 m_Data.m_yourFile.SetFileName(sFilePath);
\r
427 m_Data.m_yourFile.SetDescriptiveName(CPathUtils::GetFileNameFromPath(sFilePath));
\r
428 m_Data.m_mergedFile.SetFileName(sFilePath);
\r
429 m_Data.m_mergedFile.SetDescriptiveName(CPathUtils::GetFileNameFromPath(sFilePath));
\r
430 TRACE(_T("comparing %s and %s\nagainst the base file %s\n"), (LPCTSTR)sTempFile, (LPCTSTR)sFilePath, (LPCTSTR)sBaseFile);
\r
434 //"dry run" was successful, so save the patched file somewhere...
\r
435 CString sTempFile = m_TempFiles.GetTempFilePath();
\r
436 if (!m_Patch.PatchFile(sFilePath, sTempFile))
\r
438 MessageBox(m_Patch.GetErrorMessage(), NULL, MB_ICONERROR);
\r
441 if (m_bReversedPatch)
\r
443 m_Data.m_baseFile.SetFileName(sTempFile);
\r
445 temp.Format(_T("%s %s"), (LPCTSTR)CPathUtils::GetFileNameFromPath(sFilePath), (LPCTSTR)m_Data.m_sPatchPatched);
\r
446 m_Data.m_baseFile.SetDescriptiveName(temp);
\r
447 m_Data.m_yourFile.SetFileName(sFilePath);
\r
448 temp.Format(_T("%s %s"), (LPCTSTR)CPathUtils::GetFileNameFromPath(sFilePath), (LPCTSTR)m_Data.m_sPatchOriginal);
\r
449 m_Data.m_yourFile.SetDescriptiveName(temp);
\r
450 m_Data.m_theirFile.SetOutOfUse();
\r
451 m_Data.m_mergedFile.SetOutOfUse();
\r
455 if (!PathFileExists(sFilePath))
\r
457 m_Data.m_baseFile.SetFileName(m_TempFiles.GetTempFilePath());
\r
458 m_Data.m_baseFile.CreateEmptyFile();
\r
462 m_Data.m_baseFile.SetFileName(sFilePath);
\r
464 CString sDescription;
\r
465 sDescription.Format(_T("%s %s"), (LPCTSTR)CPathUtils::GetFileNameFromPath(sFilePath), (LPCTSTR)m_Data.m_sPatchOriginal);
\r
466 m_Data.m_baseFile.SetDescriptiveName(sDescription);
\r
467 m_Data.m_yourFile.SetFileName(sTempFile);
\r
469 temp.Format(_T("%s %s"), (LPCTSTR)CPathUtils::GetFileNameFromPath(sFilePath), (LPCTSTR)m_Data.m_sPatchPatched);
\r
470 m_Data.m_yourFile.SetDescriptiveName(temp);
\r
471 m_Data.m_theirFile.SetOutOfUse();
\r
472 m_Data.m_mergedFile.SetFileName(sFilePath);
\r
474 TRACE(_T("comparing %s\nwith the patched result %s\n"), (LPCTSTR)sFilePath, (LPCTSTR)sTempFile);
\r
484 // Callback function
\r
485 BOOL CMainFrame::DiffFiles(CString sURL1, CString sRev1, CString sURL2, CString sRev2)
\r
487 CString tempfile1 = m_TempFiles.GetTempFilePath();
\r
488 CString tempfile2 = m_TempFiles.GetTempFilePath();
\r
490 ASSERT(tempfile1.Compare(tempfile2));
\r
493 CSysProgressDlg progDlg;
\r
494 sTemp.Format(IDS_GETVERSIONOFFILE, (LPCTSTR)sRev1);
\r
495 progDlg.SetLine(1, sTemp, true);
\r
496 progDlg.SetLine(2, sURL1, true);
\r
497 sTemp.LoadString(IDS_GETVERSIONOFFILETITLE);
\r
498 progDlg.SetTitle(sTemp);
\r
499 progDlg.SetShowProgressBar(true);
\r
500 progDlg.SetAnimation(IDR_DOWNLOAD);
\r
501 progDlg.SetTime(FALSE);
\r
502 progDlg.SetProgress(1,100);
\r
503 progDlg.ShowModeless(this);
\r
504 if (!CAppUtils::GetVersionedFile(sURL1, sRev1, tempfile1, &progDlg, m_hWnd))
\r
508 sErrMsg.Format(IDS_ERR_MAINFRAME_FILEVERSIONNOTFOUND, (LPCTSTR)sRev1, (LPCTSTR)sURL1);
\r
509 MessageBox(sErrMsg, NULL, MB_ICONERROR);
\r
512 sTemp.Format(IDS_GETVERSIONOFFILE, (LPCTSTR)sRev2);
\r
513 progDlg.SetLine(1, sTemp, true);
\r
514 progDlg.SetLine(2, sURL2, true);
\r
515 progDlg.SetProgress(50, 100);
\r
516 if (!CAppUtils::GetVersionedFile(sURL2, sRev2, tempfile2, &progDlg, m_hWnd))
\r
520 sErrMsg.Format(IDS_ERR_MAINFRAME_FILEVERSIONNOTFOUND, (LPCTSTR)sRev2, (LPCTSTR)sURL2);
\r
521 MessageBox(sErrMsg, NULL, MB_ICONERROR);
\r
524 progDlg.SetProgress(100,100);
\r
527 temp.Format(_T("%s Revision %s"), (LPCTSTR)CPathUtils::GetFileNameFromPath(sURL1), (LPCTSTR)sRev1);
\r
528 m_Data.m_baseFile.SetFileName(tempfile1);
\r
529 m_Data.m_baseFile.SetDescriptiveName(temp);
\r
530 temp.Format(_T("%s Revision %s"), (LPCTSTR)CPathUtils::GetFileNameFromPath(sURL2), (LPCTSTR)sRev2);
\r
531 m_Data.m_yourFile.SetFileName(tempfile2);
\r
532 m_Data.m_yourFile.SetDescriptiveName(temp);
\r
539 void CMainFrame::OnFileOpen()
\r
541 if (CheckForSave()==IDCANCEL)
\r
544 if (dlg.DoModal()!=IDOK)
\r
548 m_dlgFilePatches.ShowWindow(SW_HIDE);
\r
549 m_dlgFilePatches.Init(NULL, NULL, CString(), NULL);
\r
550 TRACE(_T("got the files:\n %s\n %s\n %s\n %s\n %s\n"), (LPCTSTR)dlg.m_sBaseFile, (LPCTSTR)dlg.m_sTheirFile, (LPCTSTR)dlg.m_sYourFile,
\r
551 (LPCTSTR)dlg.m_sUnifiedDiffFile, (LPCTSTR)dlg.m_sPatchDirectory);
\r
552 m_Data.m_baseFile.SetFileName(dlg.m_sBaseFile);
\r
553 m_Data.m_theirFile.SetFileName(dlg.m_sTheirFile);
\r
554 m_Data.m_yourFile.SetFileName(dlg.m_sYourFile);
\r
555 m_Data.m_sDiffFile = dlg.m_sUnifiedDiffFile;
\r
556 m_Data.m_sPatchPath = dlg.m_sPatchDirectory;
\r
557 m_Data.m_mergedFile.SetOutOfUse();
\r
558 g_crasher.AddFile((LPCSTR)(LPCTSTR)dlg.m_sBaseFile, (LPCSTR)(LPCTSTR)_T("Basefile"));
\r
559 g_crasher.AddFile((LPCSTR)(LPCTSTR)dlg.m_sTheirFile, (LPCSTR)(LPCTSTR)_T("Theirfile"));
\r
560 g_crasher.AddFile((LPCSTR)(LPCTSTR)dlg.m_sYourFile, (LPCSTR)(LPCTSTR)_T("Yourfile"));
\r
561 g_crasher.AddFile((LPCSTR)(LPCTSTR)dlg.m_sUnifiedDiffFile, (LPCSTR)(LPCTSTR)_T("Difffile"));
\r
563 if (!m_Data.IsBaseFileInUse() && m_Data.IsTheirFileInUse() && m_Data.IsYourFileInUse())
\r
565 // a diff between two files means "Yours" against "Base", not "Theirs" against "Yours"
\r
566 m_Data.m_baseFile.TransferDetailsFrom(m_Data.m_theirFile);
\r
568 if (m_Data.IsBaseFileInUse() && m_Data.IsTheirFileInUse() && !m_Data.IsYourFileInUse())
\r
570 // a diff between two files means "Yours" against "Base", not "Theirs" against "Base"
\r
571 m_Data.m_yourFile.TransferDetailsFrom(m_Data.m_theirFile);
\r
577 void CMainFrame::ClearViewNamesAndPaths() {
\r
578 m_pwndLeftView->m_sWindowName.Empty();
\r
579 m_pwndLeftView->m_sFullFilePath.Empty();
\r
580 m_pwndRightView->m_sWindowName.Empty();
\r
581 m_pwndRightView->m_sFullFilePath.Empty();
\r
582 m_pwndBottomView->m_sWindowName.Empty();
\r
583 m_pwndBottomView->m_sFullFilePath.Empty();
\r
586 bool CMainFrame::LoadViews(bool bRetainPosition)
\r
588 m_Data.SetBlame(m_bBlame);
\r
589 m_bHasConflicts = false;
\r
590 CBaseView* pwndActiveView = m_pwndLeftView;
\r
591 int nOldLine = m_pwndLeftView ? m_pwndLeftView->m_nTopLine : -1;
\r
592 int nOldLineNumber =
\r
593 m_pwndLeftView && m_pwndLeftView->m_pViewData ?
\r
594 m_pwndLeftView->m_pViewData->GetLineNumber(m_pwndLeftView->m_nTopLine) : -1;
\r
595 if (!m_Data.Load())
\r
597 ::MessageBox(NULL, m_Data.GetError(), _T("TortoiseMerge"), MB_ICONERROR);
\r
598 m_Data.m_mergedFile.SetOutOfUse();
\r
602 m_pwndRightView->UseCaret(false);
\r
603 m_pwndBottomView->UseCaret(false);
\r
605 if (!m_Data.IsBaseFileInUse())
\r
607 if (m_Data.IsYourFileInUse() && m_Data.IsTheirFileInUse())
\r
609 m_Data.m_baseFile.TransferDetailsFrom(m_Data.m_theirFile);
\r
611 else if ((!m_Data.m_sDiffFile.IsEmpty())&&(!m_Patch.OpenUnifiedDiffFile(m_Data.m_sDiffFile)))
\r
613 ClearViewNamesAndPaths();
\r
614 MessageBox(m_Patch.GetErrorMessage(), NULL, MB_ICONERROR);
\r
617 if (m_Patch.GetNumberOfFiles() > 0)
\r
619 CString firstpath = m_Patch.GetFilename(0);
\r
620 CString path=firstpath;
\r
621 path.Replace('/','\\');
\r
622 if ( !PathIsRelative(path) && !PathFileExists(path) )
\r
624 // The absolute path mentioned in the patch does not exist. Lets
\r
625 // try to find the correct relative path by stripping prefixes.
\r
626 BOOL bFound = m_Patch.StripPrefixes(m_Data.m_sPatchPath);
\r
627 CString strippedpath = m_Patch.GetFilename(0);
\r
631 msg.Format(IDS_WARNABSOLUTEPATHFOUND, (LPCTSTR)firstpath, (LPCTSTR)strippedpath);
\r
632 if (CMessageBox::Show(m_hWnd, msg, _T("TortoiseMerge"), MB_ICONQUESTION | MB_YESNO)==IDNO)
\r
638 msg.Format(IDS_WARNABSOLUTEPATHNOTFOUND, (LPCTSTR)firstpath);
\r
639 CMessageBox::Show(m_hWnd, msg, _T("TortoiseMerge"), MB_ICONEXCLAMATION);
\r
643 CString betterpatchpath = m_Patch.CheckPatchPath(m_Data.m_sPatchPath);
\r
644 if (betterpatchpath.CompareNoCase(m_Data.m_sPatchPath)!=0)
\r
647 msg.Format(IDS_WARNBETTERPATCHPATHFOUND, (LPCTSTR)m_Data.m_sPatchPath, (LPCTSTR)betterpatchpath);
\r
648 if (CMessageBox::Show(m_hWnd, msg, _T("TortoiseMerge"), MB_ICONQUESTION | MB_YESNO)==IDYES)
\r
649 m_Data.m_sPatchPath = betterpatchpath;
\r
651 m_dlgFilePatches.Init(&m_Patch, this, m_Data.m_sPatchPath, this);
\r
652 m_dlgFilePatches.ShowWindow(SW_SHOW);
\r
653 ClearViewNamesAndPaths();
\r
654 if (!m_wndSplitter.IsRowHidden(1))
\r
655 m_wndSplitter.HideRow(1);
\r
656 m_pwndLeftView->SetHidden(FALSE);
\r
657 m_pwndRightView->SetHidden(FALSE);
\r
658 m_pwndBottomView->SetHidden(TRUE);
\r
661 if (m_Data.IsBaseFileInUse() && !m_Data.IsYourFileInUse() && m_Data.IsTheirFileInUse())
\r
663 m_Data.m_yourFile.TransferDetailsFrom(m_Data.m_theirFile);
\r
665 if (m_Data.IsBaseFileInUse() && m_Data.IsYourFileInUse() && !m_Data.IsTheirFileInUse())
\r
667 //diff between YOUR and BASE
\r
668 m_pwndRightView->UseCaret();
\r
671 if (!m_wndSplitter2.IsColumnHidden(1))
\r
672 m_wndSplitter2.HideColumn(1);
\r
674 m_pwndLeftView->m_pViewData = &m_Data.m_YourBaseBoth;
\r
675 m_pwndLeftView->texttype = m_Data.m_arYourFile.GetUnicodeType();
\r
676 m_pwndLeftView->lineendings = m_Data.m_arYourFile.GetLineEndings();
\r
677 m_pwndLeftView->m_sWindowName = m_Data.m_baseFile.GetWindowName() + _T(" - ") + m_Data.m_yourFile.GetWindowName();
\r
678 m_pwndLeftView->m_sFullFilePath = m_Data.m_baseFile.GetFilename() + _T(" - ") + m_Data.m_yourFile.GetFilename();
\r
680 m_pwndRightView->m_pViewData = NULL;
\r
681 m_pwndBottomView->m_pViewData = NULL;
\r
683 if (!m_wndSplitter.IsRowHidden(1))
\r
684 m_wndSplitter.HideRow(1);
\r
685 m_pwndLeftView->SetHidden(FALSE);
\r
686 m_pwndRightView->SetHidden(TRUE);
\r
687 m_pwndBottomView->SetHidden(TRUE);
\r
688 ::SetWindowPos(m_pwndLeftView->m_hWnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
\r
692 pwndActiveView = m_pwndRightView;
\r
693 if (m_wndSplitter2.IsColumnHidden(1))
\r
694 m_wndSplitter2.ShowColumn();
\r
696 m_pwndLeftView->m_pViewData = &m_Data.m_YourBaseLeft;
\r
697 m_pwndLeftView->texttype = m_Data.m_arBaseFile.GetUnicodeType();
\r
698 m_pwndLeftView->lineendings = m_Data.m_arBaseFile.GetLineEndings();
\r
699 m_pwndLeftView->m_sWindowName = m_Data.m_baseFile.GetWindowName();
\r
700 m_pwndLeftView->m_sFullFilePath = m_Data.m_baseFile.GetFilename();
\r
702 m_pwndRightView->m_pViewData = &m_Data.m_YourBaseRight;
\r
703 m_pwndRightView->texttype = m_Data.m_arYourFile.GetUnicodeType();
\r
704 m_pwndRightView->lineendings = m_Data.m_arYourFile.GetLineEndings();
\r
705 m_pwndRightView->m_sWindowName = m_Data.m_yourFile.GetWindowName();
\r
706 m_pwndRightView->m_sFullFilePath = m_Data.m_yourFile.GetFilename();
\r
708 m_pwndBottomView->m_pViewData = NULL;
\r
710 if (!m_wndSplitter.IsRowHidden(1))
\r
711 m_wndSplitter.HideRow(1);
\r
712 m_pwndLeftView->SetHidden(FALSE);
\r
713 m_pwndRightView->SetHidden(FALSE);
\r
714 m_pwndBottomView->SetHidden(TRUE);
\r
717 else if (m_Data.IsBaseFileInUse() && m_Data.IsYourFileInUse() && m_Data.IsTheirFileInUse())
\r
719 //diff between THEIR, YOUR and BASE
\r
720 m_pwndBottomView->UseCaret();
\r
721 pwndActiveView = m_pwndBottomView;
\r
723 m_pwndLeftView->m_pViewData = &m_Data.m_TheirBaseBoth;
\r
724 m_pwndLeftView->texttype = m_Data.m_arTheirFile.GetUnicodeType();
\r
725 m_pwndLeftView->lineendings = m_Data.m_arTheirFile.GetLineEndings();
\r
726 m_pwndLeftView->m_sWindowName.LoadString(IDS_VIEWTITLE_THEIRS);
\r
727 m_pwndLeftView->m_sWindowName += _T(" - ") + m_Data.m_theirFile.GetWindowName();
\r
728 m_pwndLeftView->m_sFullFilePath = m_Data.m_theirFile.GetFilename();
\r
730 m_pwndRightView->m_pViewData = &m_Data.m_YourBaseBoth;
\r
731 m_pwndRightView->texttype = m_Data.m_arYourFile.GetUnicodeType();
\r
732 m_pwndRightView->lineendings = m_Data.m_arYourFile.GetLineEndings();
\r
733 m_pwndRightView->m_sWindowName.LoadString(IDS_VIEWTITLE_MINE);
\r
734 m_pwndRightView->m_sWindowName += _T(" - ") + m_Data.m_yourFile.GetWindowName();
\r
735 m_pwndRightView->m_sFullFilePath = m_Data.m_yourFile.GetFilename();
\r
737 m_pwndBottomView->m_pViewData = &m_Data.m_Diff3;
\r
738 m_pwndBottomView->texttype = m_Data.m_arTheirFile.GetUnicodeType();
\r
739 m_pwndBottomView->lineendings = m_Data.m_arTheirFile.GetLineEndings();
\r
740 m_pwndBottomView->m_sWindowName.LoadString(IDS_VIEWTITLE_MERGED);
\r
741 m_pwndBottomView->m_sWindowName += _T(" - ") + m_Data.m_mergedFile.GetWindowName();
\r
742 m_pwndBottomView->m_sFullFilePath = m_Data.m_mergedFile.GetFilename();
\r
744 if (m_wndSplitter2.IsColumnHidden(1))
\r
745 m_wndSplitter2.ShowColumn();
\r
746 if (m_wndSplitter.IsRowHidden(1))
\r
747 m_wndSplitter.ShowRow();
\r
748 m_pwndLeftView->SetHidden(FALSE);
\r
749 m_pwndRightView->SetHidden(FALSE);
\r
750 m_pwndBottomView->SetHidden(FALSE);
\r
751 // in three pane view, hide the line diff bar
\r
752 m_wndLineDiffBar.ShowPane(false, false, true);
\r
753 m_wndLineDiffBar.DocumentUpdated();
\r
755 if (!m_Data.m_mergedFile.InUse())
\r
757 m_Data.m_mergedFile.SetFileName(m_Data.m_yourFile.GetFilename());
\r
759 m_pwndLeftView->DocumentUpdated();
\r
760 m_pwndRightView->DocumentUpdated();
\r
761 m_pwndBottomView->DocumentUpdated();
\r
762 m_wndLocatorBar.DocumentUpdated();
\r
763 m_wndLineDiffBar.DocumentUpdated();
\r
765 SetActiveView(pwndActiveView);
\r
767 if (bRetainPosition && m_pwndLeftView->m_pViewData)
\r
769 int n = nOldLineNumber;
\r
771 n = m_pwndLeftView->m_pViewData->FindLineNumber(n);
\r
775 m_pwndLeftView->ScrollAllToLine(n);
\r
779 m_pwndLeftView->SetCaretPosition(p);
\r
783 bool bGoFirstDiff = (0 != (DWORD)CRegDWORD(_T("Software\\TortoiseMerge\\FirstDiffOnLoad"), TRUE));
\r
784 if (bGoFirstDiff) {
\r
785 pwndActiveView->GoToFirstDifference();
\r
786 // Ignore the first few Mouse Move messages, so that the line diff stays on
\r
787 // the first diff line until the user actually moves the mouse
\r
788 m_nMoveMovesToIgnore = 3;
\r
792 // Avoid incorrect rendering of active pane.
\r
793 m_pwndBottomView->ScrollToChar(0);
\r
794 m_pwndLeftView->ScrollToChar(0);
\r
795 m_pwndRightView->ScrollToChar(0);
\r
797 CUndo::GetInstance().Clear();
\r
801 void CMainFrame::UpdateLayout()
\r
803 if (m_bInitSplitter)
\r
805 CRect cr, rclocbar;
\r
806 GetWindowRect(&cr);
\r
807 int width = cr.Width();
\r
808 if (::IsWindow(m_wndLocatorBar) && m_wndLocatorBar.IsWindowVisible())
\r
810 m_wndLocatorBar.GetWindowRect(&rclocbar);
\r
811 width -= rclocbar.Width();
\r
813 m_wndSplitter.SetRowInfo(0, cr.Height()/2, 0);
\r
814 m_wndSplitter.SetRowInfo(1, cr.Height()/2, 0);
\r
815 m_wndSplitter.SetColumnInfo(0, width / 2, 50);
\r
816 m_wndSplitter2.SetRowInfo(0, cr.Height()/2, 0);
\r
817 m_wndSplitter2.SetColumnInfo(0, width / 2, 50);
\r
818 m_wndSplitter2.SetColumnInfo(1, width / 2, 50);
\r
820 m_wndSplitter.RecalcLayout();
\r
824 void CMainFrame::OnSize(UINT nType, int cx, int cy)
\r
826 if (m_bInitSplitter && nType != SIZE_MINIMIZED)
\r
830 CFrameWndEx::OnSize(nType, cx, cy);
\r
833 void CMainFrame::OnViewWhitespaces()
\r
835 CRegDWORD regViewWhitespaces = CRegDWORD(_T("Software\\TortoiseMerge\\ViewWhitespaces"), 1);
\r
836 BOOL bViewWhitespaces = regViewWhitespaces;
\r
837 if (m_pwndLeftView)
\r
838 bViewWhitespaces = m_pwndLeftView->m_bViewWhitespace;
\r
840 bViewWhitespaces = !bViewWhitespaces;
\r
841 regViewWhitespaces = bViewWhitespaces;
\r
842 if (m_pwndLeftView)
\r
844 m_pwndLeftView->m_bViewWhitespace = bViewWhitespaces;
\r
845 m_pwndLeftView->Invalidate();
\r
847 if (m_pwndRightView)
\r
849 m_pwndRightView->m_bViewWhitespace = bViewWhitespaces;
\r
850 m_pwndRightView->Invalidate();
\r
852 if (m_pwndBottomView)
\r
854 m_pwndBottomView->m_bViewWhitespace = bViewWhitespaces;
\r
855 m_pwndBottomView->Invalidate();
\r
859 void CMainFrame::OnUpdateViewWhitespaces(CCmdUI *pCmdUI)
\r
861 if (m_pwndLeftView)
\r
862 pCmdUI->SetCheck(m_pwndLeftView->m_bViewWhitespace);
\r
865 void CMainFrame::OnViewOnewaydiff()
\r
867 if (CheckForSave()==IDCANCEL)
\r
869 m_bOneWay = !m_bOneWay;
\r
872 // in one way view, hide the line diff bar
\r
873 m_wndLineDiffBar.ShowPane(false, false, true);
\r
874 m_wndLineDiffBar.DocumentUpdated();
\r
878 // restore the line diff bar
\r
879 m_wndLineDiffBar.ShowPane(m_bLineDiff, false, true);
\r
880 m_wndLineDiffBar.DocumentUpdated();
\r
881 m_wndLocatorBar.ShowPane(m_bLocatorBar, false, true);
\r
882 m_wndLocatorBar.DocumentUpdated();
\r
887 void CMainFrame::ShowDiffBar(bool bShow)
\r
891 // restore the line diff bar
\r
892 m_wndLineDiffBar.ShowPane(m_bLineDiff, false, true);
\r
893 m_wndLineDiffBar.DocumentUpdated();
\r
894 m_wndLocatorBar.ShowPane(m_bLocatorBar, false, true);
\r
895 m_wndLocatorBar.DocumentUpdated();
\r
899 // in one way view, hide the line diff bar
\r
900 m_wndLineDiffBar.ShowPane(false, false, true);
\r
901 m_wndLineDiffBar.DocumentUpdated();
\r
905 int CMainFrame::CheckResolved()
\r
907 //only in three way diffs can be conflicts!
\r
908 m_bHasConflicts = true;
\r
909 if (m_pwndBottomView->IsWindowVisible())
\r
911 if (m_pwndBottomView->m_pViewData)
\r
913 for (int i=0; i<m_pwndBottomView->m_pViewData->GetCount(); i++)
\r
915 if ((DIFFSTATE_CONFLICTED == m_pwndBottomView->m_pViewData->GetState(i))||
\r
916 (DIFFSTATE_CONFLICTED_IGNORED == m_pwndBottomView->m_pViewData->GetState(i)))
\r
921 m_bHasConflicts = false;
\r
925 int CMainFrame::SaveFile(const CString& sFilePath)
\r
927 CViewData * pViewData = NULL;
\r
928 CFileTextLines * pOriginFile = &m_Data.m_arBaseFile;
\r
929 if ((m_pwndBottomView)&&(m_pwndBottomView->IsWindowVisible()))
\r
931 pViewData = m_pwndBottomView->m_pViewData;
\r
934 else if ((m_pwndRightView)&&(m_pwndRightView->IsWindowVisible()))
\r
936 pViewData = m_pwndRightView->m_pViewData;
\r
937 if (m_Data.IsYourFileInUse())
\r
938 pOriginFile = &m_Data.m_arYourFile;
\r
939 else if (m_Data.IsTheirFileInUse())
\r
940 pOriginFile = &m_Data.m_arTheirFile;
\r
945 // nothing to save!
\r
948 if ((pViewData)&&(pOriginFile))
\r
950 CFileTextLines file;
\r
951 pOriginFile->CopySettings(&file);
\r
952 for (int i=0; i<pViewData->GetCount(); i++)
\r
954 //only copy non-removed lines
\r
955 DiffStates state = pViewData->GetState(i);
\r
958 case DIFFSTATE_CONFLICTED:
\r
959 case DIFFSTATE_CONFLICTED_IGNORED:
\r
966 } while((last<pViewData->GetCount()) && ((pViewData->GetState(last)==DIFFSTATE_CONFLICTED)||(pViewData->GetState(last)==DIFFSTATE_CONFLICTED_IGNORED)));
\r
967 file.Add(_T("<<<<<<< .mine"), EOL_NOENDING);
\r
968 for (int j=first; j<last; j++)
\r
970 file.Add(m_pwndRightView->m_pViewData->GetLine(j), m_pwndRightView->m_pViewData->GetLineEnding(j));
\r
972 file.Add(_T("======="), EOL_NOENDING);
\r
973 for (int j=first; j<last; j++)
\r
975 file.Add(m_pwndLeftView->m_pViewData->GetLine(j), m_pwndLeftView->m_pViewData->GetLineEnding(j));
\r
977 file.Add(_T(">>>>>>> .theirs"), EOL_NOENDING);
\r
981 case DIFFSTATE_EMPTY:
\r
982 case DIFFSTATE_CONFLICTEMPTY:
\r
983 case DIFFSTATE_IDENTICALREMOVED:
\r
984 case DIFFSTATE_REMOVED:
\r
985 case DIFFSTATE_THEIRSREMOVED:
\r
986 case DIFFSTATE_YOURSREMOVED:
\r
987 case DIFFSTATE_CONFLICTRESOLVEDEMPTY:
\r
988 // do not save removed lines
\r
991 file.Add(pViewData->GetLine(i), pViewData->GetLineEnding(i));
\r
995 if (!file.Save(sFilePath, false))
\r
997 CMessageBox::Show(m_hWnd, file.GetErrorString(), _T("TortoiseMerge"), MB_ICONERROR);
\r
1000 m_dlgFilePatches.SetFileStatusAsPatched(sFilePath);
\r
1001 if (m_pwndBottomView)
\r
1002 m_pwndBottomView->SetModified(FALSE);
\r
1003 if (m_pwndRightView)
\r
1004 m_pwndRightView->SetModified(FALSE);
\r
1005 CUndo::GetInstance().MarkAsOriginalState();
\r
1006 return file.GetCount();
\r
1011 void CMainFrame::OnFileSave()
\r
1016 bool CMainFrame::FileSave(bool bCheckResolved /*=true*/)
\r
1018 if (!m_Data.m_mergedFile.InUse())
\r
1019 return FileSaveAs(bCheckResolved);
\r
1020 // check if the file has the readonly attribute set
\r
1021 bool bDoesNotExist = false;
\r
1022 DWORD fAttribs = GetFileAttributes(m_Data.m_mergedFile.GetFilename());
\r
1023 if ((fAttribs != INVALID_FILE_ATTRIBUTES)&&(fAttribs & FILE_ATTRIBUTE_READONLY))
\r
1024 return FileSaveAs(bCheckResolved);
\r
1025 if (fAttribs == INVALID_FILE_ATTRIBUTES)
\r
1027 bDoesNotExist = (GetLastError() == ERROR_FILE_NOT_FOUND);
\r
1029 if (bCheckResolved)
\r
1031 int nConflictLine = CheckResolved();
\r
1032 if (nConflictLine >= 0)
\r
1035 sTemp.Format(IDS_ERR_MAINFRAME_FILEHASCONFLICTS, m_pwndBottomView->m_pViewData->GetLineNumber(nConflictLine)+1);
\r
1036 if (MessageBox(sTemp, 0, MB_ICONERROR | MB_YESNO)!=IDYES)
\r
1038 if (m_pwndBottomView)
\r
1039 m_pwndBottomView->GoToLine(nConflictLine);
\r
1044 if (((DWORD)CRegDWORD(_T("Software\\TortoiseMerge\\Backup"))) != 0)
\r
1046 MoveFileEx(m_Data.m_mergedFile.GetFilename(), m_Data.m_mergedFile.GetFilename() + _T(".bak"), MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH);
\r
1048 if (SaveFile(m_Data.m_mergedFile.GetFilename())==0)
\r
1050 // file was saved with 0 lines!
\r
1051 // ask the user if the file should be deleted
\r
1053 sTemp.Format(IDS_DELETEWHENEMPTY, (LPCTSTR)m_Data.m_mergedFile.GetFilename());
\r
1054 if (CMessageBox::ShowCheck(m_hWnd, sTemp, _T("TortoiseMerge"), MB_YESNO, _T("DeleteFileWhenEmpty")) == IDYES)
\r
1056 DeleteFile(m_Data.m_mergedFile.GetFilename());
\r
1060 if (bDoesNotExist)
\r
1062 // call TortoiseProc to add the new file to version control
\r
1063 CString cmd = _T("\"") + CPathUtils::GetAppDirectory();
\r
1064 cmd += _T("TortoiseProc.exe\" /command:add /noui /path:\"");
\r
1065 cmd += m_Data.m_mergedFile.GetFilename() + _T("\"");
\r
1066 TCHAR * buf = new TCHAR[cmd.GetLength()+1];
\r
1067 _tcscpy_s(buf, cmd.GetLength()+1, cmd);
\r
1068 STARTUPINFO startup;
\r
1069 PROCESS_INFORMATION process;
\r
1070 memset(&startup, 0, sizeof(startup));
\r
1071 startup.cb = sizeof(startup);
\r
1072 memset(&process, 0, sizeof(process));
\r
1073 if (CreateProcess(NULL, buf, NULL, NULL, FALSE, 0, 0, 0, &startup, &process)==0)
\r
1077 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
\r
1078 FORMAT_MESSAGE_FROM_SYSTEM |
\r
1079 FORMAT_MESSAGE_IGNORE_INSERTS,
\r
1082 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
\r
1083 (LPTSTR) &lpMsgBuf,
\r
1087 MessageBox((LPCTSTR)lpMsgBuf, _T("TortoiseMerge"), MB_OK | MB_ICONINFORMATION);
\r
1088 LocalFree( lpMsgBuf );
\r
1092 CloseHandle(process.hThread);
\r
1093 CloseHandle(process.hProcess);
\r
1098 void CMainFrame::OnFileSaveAs()
\r
1103 bool CMainFrame::FileSaveAs(bool bCheckResolved /*=true*/)
\r
1105 if (bCheckResolved)
\r
1107 int nConflictLine = CheckResolved();
\r
1108 if (nConflictLine >= 0)
\r
1111 sTemp.Format(IDS_ERR_MAINFRAME_FILEHASCONFLICTS, m_pwndBottomView->m_pViewData->GetLineNumber(nConflictLine)+1);
\r
1112 if (MessageBox(sTemp, 0, MB_ICONERROR | MB_YESNO)!=IDYES)
\r
1114 if (m_pwndBottomView)
\r
1115 m_pwndBottomView->GoToLine(nConflictLine);
\r
1120 OPENFILENAME ofn = {0}; // common dialog box structure
\r
1121 TCHAR szFile[MAX_PATH] = {0}; // buffer for file name
\r
1122 ofn.lStructSize = sizeof(OPENFILENAME);
\r
1123 ofn.hwndOwner = m_hWnd;
\r
1124 ofn.lpstrFile = szFile;
\r
1125 ofn.nMaxFile = sizeof(szFile)/sizeof(TCHAR);
\r
1127 temp.LoadString(IDS_SAVEASTITLE);
\r
1128 if (!temp.IsEmpty())
\r
1129 ofn.lpstrTitle = temp;
\r
1130 ofn.Flags = OFN_OVERWRITEPROMPT;
\r
1132 sFilter.LoadString(IDS_COMMONFILEFILTER);
\r
1133 TCHAR * pszFilters = new TCHAR[sFilter.GetLength()+4];
\r
1134 _tcscpy_s (pszFilters, sFilter.GetLength()+4, sFilter);
\r
1135 // Replace '|' delimiters with '\0's
\r
1136 TCHAR *ptr = pszFilters + _tcslen(pszFilters); //set ptr at the NULL
\r
1137 while (ptr != pszFilters)
\r
1143 ofn.lpstrFilter = pszFilters;
\r
1144 ofn.nFilterIndex = 1;
\r
1146 // Display the Open dialog box.
\r
1148 if (GetSaveFileName(&ofn)==TRUE)
\r
1150 sFile = CString(ofn.lpstrFile);
\r
1152 delete [] pszFilters;
\r
1155 delete [] pszFilters;
\r
1159 void CMainFrame::OnUpdateFileSave(CCmdUI *pCmdUI)
\r
1161 BOOL bEnable = FALSE;
\r
1162 if (m_Data.m_mergedFile.InUse())
\r
1164 if (m_pwndBottomView)
\r
1166 if ((m_pwndBottomView->IsWindowVisible())&&(m_pwndBottomView->m_pViewData))
\r
1171 if (m_pwndRightView)
\r
1173 if ((m_pwndRightView->IsWindowVisible())&&(m_pwndRightView->m_pViewData))
\r
1175 if (m_pwndRightView->IsModified() || (m_Data.m_yourFile.GetWindowName().Right(9).Compare(_T(": patched"))==0))
\r
1180 pCmdUI->Enable(bEnable);
\r
1183 void CMainFrame::OnUpdateFileSaveAs(CCmdUI *pCmdUI)
\r
1185 BOOL bEnable = FALSE;
\r
1186 if (m_pwndBottomView)
\r
1188 if ((m_pwndBottomView->IsWindowVisible())&&(m_pwndBottomView->m_pViewData))
\r
1193 if (m_pwndRightView)
\r
1195 if ((m_pwndRightView->IsWindowVisible())&&(m_pwndRightView->m_pViewData))
\r
1200 pCmdUI->Enable(bEnable);
\r
1204 void CMainFrame::OnUpdateViewOnewaydiff(CCmdUI *pCmdUI)
\r
1206 pCmdUI->SetCheck(!m_bOneWay);
\r
1207 BOOL bEnable = TRUE;
\r
1208 if (m_pwndBottomView)
\r
1210 if (m_pwndBottomView->IsWindowVisible())
\r
1213 pCmdUI->Enable(bEnable);
\r
1216 void CMainFrame::OnViewOptions()
\r
1219 sTemp.LoadString(IDS_SETTINGSTITLE);
\r
1220 CSettings dlg(sTemp);
\r
1222 if (dlg.IsReloadNeeded())
\r
1224 if (CheckForSave()==IDCANCEL)
\r
1226 CDiffColors::GetInstance().LoadRegistry();
\r
1230 CDiffColors::GetInstance().LoadRegistry();
\r
1231 if (m_pwndBottomView)
\r
1232 m_pwndBottomView->Invalidate();
\r
1233 if (m_pwndLeftView)
\r
1234 m_pwndLeftView->Invalidate();
\r
1235 if (m_pwndRightView)
\r
1236 m_pwndRightView->Invalidate();
\r
1239 void CMainFrame::OnClose()
\r
1241 if ((m_pFindDialog)&&(!m_pFindDialog->IsTerminating()))
\r
1243 m_pFindDialog->SendMessage(WM_CLOSE);
\r
1247 if (((m_pwndBottomView)&&(m_pwndBottomView->IsModified())) ||
\r
1248 ((m_pwndRightView)&&(m_pwndRightView->IsModified())))
\r
1251 sTemp.LoadString(IDS_ASKFORSAVE);
\r
1252 ret = MessageBox(sTemp, 0, MB_YESNOCANCEL | MB_ICONQUESTION);
\r
1259 if ((ret == IDNO)||(ret == IDYES))
\r
1261 WINDOWPLACEMENT wp;
\r
1263 // before it is destroyed, save the position of the window
\r
1264 wp.length = sizeof wp;
\r
1266 if (GetWindowPlacement(&wp))
\r
1270 // never restore to Iconic state
\r
1271 wp.showCmd = SW_SHOW ;
\r
1273 if ((wp.flags & WPF_RESTORETOMAXIMIZED) != 0)
\r
1274 // if maximized and maybe iconic restore maximized state
\r
1275 wp.showCmd = SW_SHOWMAXIMIZED ;
\r
1277 // and write it to the .INI file
\r
1278 WriteWindowPlacement(&wp);
\r
1280 __super::OnClose();
\r
1284 void CMainFrame::OnEditFind()
\r
1286 if (m_pFindDialog)
\r
1292 // start searching from the start again
\r
1293 // if no line is selected, otherwise start from
\r
1294 // the selected line
\r
1295 m_nSearchIndex = FindSearchStart(0);
\r
1296 m_pFindDialog = new CFindDlg();
\r
1297 m_pFindDialog->Create(this);
\r
1301 LRESULT CMainFrame::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
\r
1303 ASSERT(m_pFindDialog != NULL);
\r
1305 if (m_pFindDialog->IsTerminating())
\r
1307 // invalidate the handle identifying the dialog box.
\r
1308 m_pFindDialog = NULL;
\r
1312 if(m_pFindDialog->FindNext())
\r
1314 //read data from dialog
\r
1315 m_sFindText = m_pFindDialog->GetFindString();
\r
1316 m_bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
\r
1317 m_bLimitToDiff = m_pFindDialog->LimitToDiffs();
\r
1318 m_bWholeWord = m_pFindDialog->WholeWord();
\r
1326 bool CharIsDelimiter(const CString& ch)
\r
1328 CString delimiters(_T(" .,:;=+-*/\\\n\t()[]<>@"));
\r
1329 return delimiters.Find(ch) >= 0;
\r
1332 bool CMainFrame::StringFound(const CString& str)const
\r
1334 int nSubStringStartIdx = str.Find(m_sFindText);
\r
1335 bool bStringFound = (nSubStringStartIdx >= 0);
\r
1336 if (bStringFound && m_bWholeWord)
\r
1338 if (nSubStringStartIdx)
\r
1339 bStringFound = CharIsDelimiter(str.Mid(nSubStringStartIdx-1,1));
\r
1343 int nEndIndex = nSubStringStartIdx + m_sFindText.GetLength();
\r
1344 if (str.GetLength() > nEndIndex)
\r
1345 bStringFound = CharIsDelimiter(str.Mid(nEndIndex, 1));
\r
1348 return bStringFound;
\r
1351 void CMainFrame::OnEditFindprev()
\r
1353 Search(SearchPrevious);
\r
1356 void CMainFrame::OnEditFindnext()
\r
1358 Search(SearchNext);
\r
1361 void CMainFrame::Search(SearchDirection srchDir)
\r
1363 if (m_sFindText.IsEmpty())
\r
1366 if ((m_pwndLeftView)&&(m_pwndLeftView->m_pViewData))
\r
1368 bool bFound = FALSE;
\r
1373 DiffStates leftstate = DIFFSTATE_NORMAL;
\r
1374 DiffStates rightstate = DIFFSTATE_NORMAL;
\r
1375 DiffStates bottomstate = DIFFSTATE_NORMAL;
\r
1378 m_nSearchIndex = FindSearchStart(m_nSearchIndex);
\r
1380 if (m_nSearchIndex >= m_pwndLeftView->m_pViewData->GetCount())
\r
1381 m_nSearchIndex = 0;
\r
1382 if (srchDir == SearchPrevious)
\r
1384 // SearchIndex points 1 past where we found the last match,
\r
1385 // so if we are searching backwards we need to adjust accordingly
\r
1386 m_nSearchIndex -= 2;
\r
1387 // if at the top, start again from the end
\r
1388 if (m_nSearchIndex < 0)
\r
1389 m_nSearchIndex += m_pwndLeftView->m_pViewData->GetCount();
\r
1391 const int idxLimits[2][2][2]={{{m_nSearchIndex, m_pwndLeftView->m_pViewData->GetCount()},
\r
1392 {0, m_nSearchIndex}},
\r
1393 {{m_nSearchIndex, -1},
\r
1394 {m_pwndLeftView->m_pViewData->GetCount()-1, m_nSearchIndex}}};
\r
1395 const int offsets[2]={+1, -1};
\r
1397 for (int j=0; j != 2 && !bFound; ++j)
\r
1399 for (i=idxLimits[srchDir][j][0]; i != idxLimits[srchDir][j][1]; i += offsets[srchDir])
\r
1401 left = m_pwndLeftView->m_pViewData->GetLine(i);
\r
1402 leftstate = m_pwndLeftView->m_pViewData->GetState(i);
\r
1403 if ((!m_bOneWay)&&(m_pwndRightView->m_pViewData))
\r
1405 right = m_pwndRightView->m_pViewData->GetLine(i);
\r
1406 rightstate = m_pwndRightView->m_pViewData->GetState(i);
\r
1408 if ((m_pwndBottomView)&&(m_pwndBottomView->m_pViewData))
\r
1410 bottom = m_pwndBottomView->m_pViewData->GetLine(i);
\r
1411 bottomstate = m_pwndBottomView->m_pViewData->GetState(i);
\r
1414 if (!m_bMatchCase)
\r
1416 left = left.MakeLower();
\r
1417 right = right.MakeLower();
\r
1418 bottom = bottom.MakeLower();
\r
1419 m_sFindText = m_sFindText.MakeLower();
\r
1421 if (StringFound(left))
\r
1423 if ((!m_bLimitToDiff)||(leftstate != DIFFSTATE_NORMAL))
\r
1429 else if (StringFound(right))
\r
1431 if ((!m_bLimitToDiff)||(rightstate != DIFFSTATE_NORMAL))
\r
1437 else if (StringFound(bottom))
\r
1439 if ((!m_bLimitToDiff)||(bottomstate != DIFFSTATE_NORMAL))
\r
1449 m_nSearchIndex = i;
\r
1450 m_pwndLeftView->GoToLine(m_nSearchIndex);
\r
1451 if (StringFound(left))
\r
1453 m_pwndLeftView->SetFocus();
\r
1454 m_pwndLeftView->HiglightLines(m_nSearchIndex);
\r
1456 else if (StringFound(right))
\r
1458 m_pwndRightView->SetFocus();
\r
1459 m_pwndRightView->HiglightLines(m_nSearchIndex);
\r
1461 else if (StringFound(bottom))
\r
1463 m_pwndBottomView->SetFocus();
\r
1464 m_pwndBottomView->HiglightLines(m_nSearchIndex);
\r
1469 m_nSearchIndex = 0;
\r
1474 int CMainFrame::FindSearchStart(int nDefault)
\r
1476 // TortoiseMerge doesn't have a cursor which we could use to
\r
1477 // anchor the search on.
\r
1478 // Instead we use a line that is selected.
\r
1479 // If however no line is selected, use the default line (which could
\r
1480 // be the top of the document for a new search, or the line where the
\r
1481 // search was successful on)
\r
1482 int nLine = nDefault;
\r
1483 int nSelStart = 0;
\r
1485 if (m_pwndLeftView)
\r
1487 if (m_pwndLeftView->GetSelection(nSelStart, nSelEnd))
\r
1489 if (nSelStart == nSelEnd)
\r
1490 nLine = nSelStart;
\r
1493 else if ((nLine == nDefault)&&(m_pwndRightView))
\r
1495 if (m_pwndRightView->GetSelection(nSelStart, nSelEnd))
\r
1497 if (nSelStart == nSelEnd)
\r
1498 nLine = nSelStart;
\r
1501 else if ((nLine == nDefault)&&(m_pwndBottomView))
\r
1503 if (m_pwndBottomView->GetSelection(nSelStart, nSelEnd))
\r
1505 if (nSelStart == nSelEnd)
\r
1506 nLine = nSelStart;
\r
1512 void CMainFrame::OnViewLinedown()
\r
1514 if (m_pwndLeftView)
\r
1515 m_pwndLeftView->ScrollToLine(m_pwndLeftView->m_nTopLine+1);
\r
1516 if (m_pwndRightView)
\r
1517 m_pwndRightView->ScrollToLine(m_pwndRightView->m_nTopLine+1);
\r
1518 if (m_pwndBottomView)
\r
1519 m_pwndBottomView->ScrollToLine(m_pwndBottomView->m_nTopLine+1);
\r
1520 m_wndLocatorBar.Invalidate();
\r
1523 void CMainFrame::OnViewLineup()
\r
1525 if (m_pwndLeftView)
\r
1526 m_pwndLeftView->ScrollToLine(m_pwndLeftView->m_nTopLine-1);
\r
1527 if (m_pwndRightView)
\r
1528 m_pwndRightView->ScrollToLine(m_pwndRightView->m_nTopLine-1);
\r
1529 if (m_pwndBottomView)
\r
1530 m_pwndBottomView->ScrollToLine(m_pwndBottomView->m_nTopLine-1);
\r
1531 m_wndLocatorBar.Invalidate();
\r
1534 void CMainFrame::OnViewLineleft()
\r
1536 if (m_pwndLeftView)
\r
1537 m_pwndLeftView->ScrollSide(-1);
\r
1538 if (m_pwndRightView)
\r
1539 m_pwndRightView->ScrollSide(-1);
\r
1540 if (m_pwndBottomView)
\r
1541 m_pwndBottomView->ScrollSide(-1);
\r
1544 void CMainFrame::OnViewLineright()
\r
1546 if (m_pwndLeftView)
\r
1547 m_pwndLeftView->ScrollSide(1);
\r
1548 if (m_pwndRightView)
\r
1549 m_pwndRightView->ScrollSide(1);
\r
1550 if (m_pwndBottomView)
\r
1551 m_pwndBottomView->ScrollSide(1);
\r
1554 void CMainFrame::OnEditUseTheirs()
\r
1556 if (m_pwndBottomView)
\r
1557 m_pwndBottomView->UseTheirTextBlock();
\r
1559 void CMainFrame::OnUpdateEditUsetheirblock(CCmdUI *pCmdUI)
\r
1561 int nSelBlockStart = -1;
\r
1562 int nSelBlockEnd = -1;
\r
1563 if (m_pwndBottomView)
\r
1564 m_pwndBottomView->GetSelection(nSelBlockStart, nSelBlockEnd);
\r
1565 pCmdUI->Enable((nSelBlockStart >= 0)&&(nSelBlockEnd >= 0));
\r
1569 void CMainFrame::OnEditUseMine()
\r
1571 if (m_pwndBottomView)
\r
1572 m_pwndBottomView->UseMyTextBlock();
\r
1574 void CMainFrame::OnUpdateEditUsemyblock(CCmdUI *pCmdUI)
\r
1576 int nSelBlockStart = -1;
\r
1577 int nSelBlockEnd = -1;
\r
1578 if (m_pwndBottomView)
\r
1579 m_pwndBottomView->GetSelection(nSelBlockStart, nSelBlockEnd);
\r
1580 pCmdUI->Enable((nSelBlockStart >= 0)&&(nSelBlockEnd >= 0));
\r
1584 void CMainFrame::OnEditUseTheirsThenMine()
\r
1586 if (m_pwndBottomView)
\r
1587 m_pwndBottomView->UseTheirThenMyTextBlock();
\r
1589 void CMainFrame::OnUpdateEditUsetheirthenmyblock(CCmdUI *pCmdUI)
\r
1591 int nSelBlockStart = -1;
\r
1592 int nSelBlockEnd = -1;
\r
1593 if (m_pwndBottomView)
\r
1594 m_pwndBottomView->GetSelection(nSelBlockStart, nSelBlockEnd);
\r
1595 pCmdUI->Enable((nSelBlockStart >= 0)&&(nSelBlockEnd >= 0));
\r
1599 void CMainFrame::OnEditUseMineThenTheirs()
\r
1601 if (m_pwndBottomView)
\r
1602 m_pwndBottomView->UseMyThenTheirTextBlock();
\r
1604 void CMainFrame::OnUpdateEditUseminethentheirblock(CCmdUI *pCmdUI)
\r
1606 int nSelBlockStart = -1;
\r
1607 int nSelBlockEnd = -1;
\r
1608 if (m_pwndBottomView)
\r
1609 m_pwndBottomView->GetSelection(nSelBlockStart, nSelBlockEnd);
\r
1610 pCmdUI->Enable((nSelBlockStart >= 0)&&(nSelBlockEnd >= 0));
\r
1613 void CMainFrame::OnEditUseleftblock()
\r
1615 if (m_pwndRightView)
\r
1616 m_pwndRightView->UseBlock();
\r
1619 void CMainFrame::OnUpdateEditUseleftblock(CCmdUI *pCmdUI)
\r
1621 pCmdUI->Enable(m_pwndRightView && m_pwndRightView->IsWindowVisible() && m_pwndRightView->HasCaret() && m_pwndRightView->HasSelection());
\r
1624 void CMainFrame::OnEditUseleftfile()
\r
1626 if (m_pwndRightView)
\r
1627 m_pwndRightView->UseFile();
\r
1630 void CMainFrame::OnUpdateEditUseleftfile(CCmdUI *pCmdUI)
\r
1632 pCmdUI->Enable(m_pwndRightView && m_pwndRightView->IsWindowVisible() && m_pwndRightView->HasCaret());
\r
1635 void CMainFrame::OnEditUseblockfromleftbeforeright()
\r
1637 if (m_pwndRightView)
\r
1638 m_pwndRightView->UseLeftBeforeRight();
\r
1641 void CMainFrame::OnUpdateEditUseblockfromleftbeforeright(CCmdUI *pCmdUI)
\r
1643 pCmdUI->Enable(m_pwndRightView && m_pwndRightView->IsWindowVisible() && m_pwndRightView->HasCaret() && m_pwndRightView->HasSelection());
\r
1646 void CMainFrame::OnEditUseblockfromrightbeforeleft()
\r
1648 if (m_pwndRightView)
\r
1649 m_pwndRightView->UseRightBeforeLeft();
\r
1652 void CMainFrame::OnUpdateEditUseblockfromrightbeforeleft(CCmdUI *pCmdUI)
\r
1654 pCmdUI->Enable(m_pwndRightView && m_pwndRightView->IsWindowVisible() && m_pwndRightView->HasCaret() && m_pwndRightView->HasSelection());
\r
1658 void CMainFrame::OnFileReload()
\r
1660 if (CheckForSave()==IDCANCEL)
\r
1662 CDiffColors::GetInstance().LoadRegistry();
\r
1666 void CMainFrame::ActivateFrame(int nCmdShow)
\r
1668 // nCmdShow is the normal show mode this frame should be in
\r
1669 // translate default nCmdShow (-1)
\r
1670 if (nCmdShow == -1)
\r
1672 if (!IsWindowVisible())
\r
1673 nCmdShow = SW_SHOWNORMAL;
\r
1674 else if (IsIconic())
\r
1675 nCmdShow = SW_RESTORE;
\r
1678 // bring to top before showing
\r
1679 BringToTop(nCmdShow);
\r
1681 if (nCmdShow != -1)
\r
1683 // show the window as specified
\r
1684 WINDOWPLACEMENT wp;
\r
1686 if ( !ReadWindowPlacement(&wp) )
\r
1688 ShowWindow(nCmdShow);
\r
1692 if ( nCmdShow != SW_SHOWNORMAL )
\r
1693 wp.showCmd = nCmdShow;
\r
1695 SetWindowPlacement(&wp);
\r
1698 // and finally, bring to top after showing
\r
1699 BringToTop(nCmdShow);
\r
1704 BOOL CMainFrame::ReadWindowPlacement(WINDOWPLACEMENT * pwp)
\r
1706 CRegString placement = CRegString(_T("Software\\TortoiseMerge\\WindowPos"));
\r
1707 CString sPlacement = placement;
\r
1708 if (sPlacement.IsEmpty())
\r
1710 int nRead = _stscanf_s(sPlacement, _T("%u,%u,%d,%d,%d,%d,%d,%d,%d,%d"),
\r
1711 &pwp->flags, &pwp->showCmd,
\r
1712 &pwp->ptMinPosition.x, &pwp->ptMinPosition.y,
\r
1713 &pwp->ptMaxPosition.x, &pwp->ptMaxPosition.y,
\r
1714 &pwp->rcNormalPosition.left, &pwp->rcNormalPosition.top,
\r
1715 &pwp->rcNormalPosition.right, &pwp->rcNormalPosition.bottom);
\r
1716 if ( nRead != 10 )
\r
1718 pwp->length = sizeof(WINDOWPLACEMENT);
\r
1723 void CMainFrame::WriteWindowPlacement(WINDOWPLACEMENT * pwp)
\r
1725 CRegString placement = CRegString(_T("Software\\TortoiseMerge\\WindowPos"));
\r
1726 TCHAR szBuffer[sizeof("-32767")*8 + sizeof("65535")*2];
\r
1729 _stprintf_s(szBuffer, sizeof("-32767")*8 + sizeof("65535")*2, _T("%u,%u,%d,%d,%d,%d,%d,%d,%d,%d"),
\r
1730 pwp->flags, pwp->showCmd,
\r
1731 pwp->ptMinPosition.x, pwp->ptMinPosition.y,
\r
1732 pwp->ptMaxPosition.x, pwp->ptMaxPosition.y,
\r
1733 pwp->rcNormalPosition.left, pwp->rcNormalPosition.top,
\r
1734 pwp->rcNormalPosition.right, pwp->rcNormalPosition.bottom);
\r
1735 placement = szBuffer;
\r
1738 void CMainFrame::OnUpdateMergeMarkasresolved(CCmdUI *pCmdUI)
\r
1740 if (pCmdUI == NULL)
\r
1742 BOOL bEnable = FALSE;
\r
1743 if ((!m_bReadOnly)&&(m_Data.m_mergedFile.InUse()))
\r
1745 if (m_pwndBottomView)
\r
1747 if ((m_pwndBottomView->IsWindowVisible())&&(m_pwndBottomView->m_pViewData))
\r
1753 pCmdUI->Enable(bEnable);
\r
1756 void CMainFrame::OnMergeMarkasresolved()
\r
1758 int nConflictLine = CheckResolved();
\r
1759 if (nConflictLine >= 0)
\r
1762 sTemp.Format(IDS_ERR_MAINFRAME_FILEHASCONFLICTS, m_pwndBottomView->m_pViewData->GetLineNumber(nConflictLine)+1);
\r
1763 if (MessageBox(sTemp, 0, MB_ICONERROR | MB_YESNO)!=IDYES)
\r
1765 if (m_pwndBottomView)
\r
1766 m_pwndBottomView->GoToLine(nConflictLine);
\r
1770 // now check if the file has already been saved and if not, save it.
\r
1771 if (m_Data.m_mergedFile.InUse())
\r
1773 if (m_pwndBottomView)
\r
1775 if ((m_pwndBottomView->IsWindowVisible())&&(m_pwndBottomView->m_pViewData))
\r
1784 BOOL CMainFrame::MarkAsResolved()
\r
1788 if ((m_pwndBottomView)&&(m_pwndBottomView->IsWindowVisible()))
\r
1790 TCHAR buf[MAX_PATH*3];
\r
1791 GetModuleFileName(NULL, buf, MAX_PATH);
\r
1792 TCHAR * end = _tcsrchr(buf, '\\');
\r
1795 _tcscat_s(buf, MAX_PATH*3, _T("TortoiseProc.exe /command:resolve /path:\""));
\r
1796 _tcscat_s(buf, MAX_PATH*3, m_Data.m_mergedFile.GetFilename());
\r
1797 _tcscat_s(buf, MAX_PATH*3, _T("\" /closeonend:1 /noquestion /skipcheck"));
\r
1798 STARTUPINFO startup;
\r
1799 PROCESS_INFORMATION process;
\r
1800 memset(&startup, 0, sizeof(startup));
\r
1801 startup.cb = sizeof(startup);
\r
1802 memset(&process, 0, sizeof(process));
\r
1803 if (CreateProcess(NULL, buf, NULL, NULL, FALSE, 0, 0, 0, &startup, &process)==0)
\r
1806 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
\r
1807 FORMAT_MESSAGE_FROM_SYSTEM |
\r
1808 FORMAT_MESSAGE_IGNORE_INSERTS,
\r
1811 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
\r
1812 (LPTSTR) &lpMsgBuf,
\r
1816 MessageBox((LPCTSTR)lpMsgBuf, _T("TortoiseMerge"), MB_OK | MB_ICONINFORMATION);
\r
1817 LocalFree( lpMsgBuf );
\r
1820 CloseHandle(process.hThread);
\r
1821 CloseHandle(process.hProcess);
\r
1828 void CMainFrame::OnUpdateMergeNextconflict(CCmdUI *pCmdUI)
\r
1830 pCmdUI->Enable(m_bHasConflicts);
\r
1833 void CMainFrame::OnUpdateMergePreviousconflict(CCmdUI *pCmdUI)
\r
1835 pCmdUI->Enable(m_bHasConflicts);
\r
1838 void CMainFrame::OnMoving(UINT fwSide, LPRECT pRect)
\r
1840 // if the pathfilelist dialog is attached to the mainframe,
\r
1841 // move it along with the mainframe
\r
1842 if (::IsWindow(m_dlgFilePatches.m_hWnd))
\r
1845 m_dlgFilePatches.GetWindowRect(&patchrect);
\r
1846 if (::IsWindow(m_hWnd))
\r
1849 GetWindowRect(&thisrect);
\r
1850 if (patchrect.right == thisrect.left)
\r
1852 m_dlgFilePatches.SetWindowPos(NULL, patchrect.left - (thisrect.left - pRect->left), patchrect.top - (thisrect.top - pRect->top),
\r
1853 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
\r
1857 __super::OnMoving(fwSide, pRect);
\r
1860 void CMainFrame::OnUpdateEditCopy(CCmdUI *pCmdUI)
\r
1862 BOOL bShow = FALSE;
\r
1863 if ((m_pwndBottomView)&&(m_pwndBottomView->HasSelection()))
\r
1865 if ((m_pwndRightView)&&(m_pwndRightView->HasSelection()))
\r
1867 if ((m_pwndLeftView)&&(m_pwndLeftView->HasSelection()))
\r
1869 pCmdUI->Enable(bShow);
\r
1872 void CMainFrame::OnViewSwitchleft()
\r
1875 if (((m_pwndBottomView)&&(m_pwndBottomView->IsModified())) ||
\r
1876 ((m_pwndRightView)&&(m_pwndRightView->IsModified())))
\r
1879 sTemp.LoadString(IDS_ASKFORSAVE);
\r
1880 ret = MessageBox(sTemp, 0, MB_YESNOCANCEL | MB_ICONQUESTION);
\r
1887 if ((ret == IDNO)||(ret == IDYES))
\r
1889 CWorkingFile file = m_Data.m_baseFile;
\r
1890 m_Data.m_baseFile = m_Data.m_yourFile;
\r
1891 m_Data.m_yourFile = file;
\r
1892 if (m_Data.m_mergedFile.GetFilename().CompareNoCase(m_Data.m_yourFile.GetFilename())==0)
\r
1894 m_Data.m_mergedFile = m_Data.m_baseFile;
\r
1896 else if (m_Data.m_mergedFile.GetFilename().CompareNoCase(m_Data.m_baseFile.GetFilename())==0)
\r
1898 m_Data.m_mergedFile = m_Data.m_yourFile;
\r
1904 void CMainFrame::OnUpdateViewSwitchleft(CCmdUI *pCmdUI)
\r
1906 BOOL bEnable = TRUE;
\r
1907 if (m_pwndBottomView)
\r
1909 if (m_pwndBottomView->IsWindowVisible())
\r
1912 pCmdUI->Enable(bEnable);
\r
1916 void CMainFrame::OnUpdateViewShowfilelist(CCmdUI *pCmdUI)
\r
1918 if (m_dlgFilePatches.HasFiles())
\r
1920 pCmdUI->Enable(true);
\r
1923 pCmdUI->Enable(false);
\r
1924 pCmdUI->SetCheck(m_dlgFilePatches.IsWindowVisible());
\r
1927 void CMainFrame::OnViewShowfilelist()
\r
1929 m_dlgFilePatches.ShowWindow(m_dlgFilePatches.IsWindowVisible() ? SW_HIDE : SW_SHOW);
\r
1932 void CMainFrame::OnEditUndo()
\r
1934 if (CUndo::GetInstance().CanUndo())
\r
1936 CUndo::GetInstance().Undo(m_pwndLeftView, m_pwndRightView, m_pwndBottomView);
\r
1941 void CMainFrame::OnUpdateEditUndo(CCmdUI *pCmdUI)
\r
1943 pCmdUI->Enable(CUndo::GetInstance().CanUndo());
\r
1946 int CMainFrame::CheckForSave()
\r
1949 if (((m_pwndBottomView)&&(m_pwndBottomView->IsModified())) ||
\r
1950 ((m_pwndRightView)&&(m_pwndRightView->IsModified())))
\r
1953 sTemp.LoadString(IDS_WARNMODIFIEDLOOSECHANGES);
\r
1954 ret = MessageBox(sTemp, 0, MB_YESNOCANCEL | MB_ICONQUESTION);
\r
1964 void CMainFrame::OnViewInlinediffword()
\r
1966 m_bInlineWordDiff = !m_bInlineWordDiff;
\r
1967 if (m_pwndLeftView)
\r
1969 m_pwndLeftView->SetInlineWordDiff(m_bInlineWordDiff);
\r
1970 m_pwndLeftView->Invalidate();
\r
1972 if (m_pwndRightView)
\r
1974 m_pwndRightView->SetInlineWordDiff(m_bInlineWordDiff);
\r
1975 m_pwndRightView->Invalidate();
\r
1977 if (m_pwndBottomView)
\r
1979 m_pwndBottomView->SetInlineWordDiff(m_bInlineWordDiff);
\r
1980 m_pwndBottomView->Invalidate();
\r
1982 m_wndLineDiffBar.Invalidate();
\r
1985 void CMainFrame::OnUpdateViewInlinediffword(CCmdUI *pCmdUI)
\r
1987 pCmdUI->Enable(m_pwndLeftView && m_pwndLeftView->IsWindowVisible() &&
\r
1988 m_pwndRightView && m_pwndRightView->IsWindowVisible());
\r
1989 pCmdUI->SetCheck(m_bInlineWordDiff);
\r
1992 void CMainFrame::OnUpdateEditCreateunifieddifffile(CCmdUI *pCmdUI)
\r
1994 // "create unified diff file" is only available if two files
\r
1995 // are diffed, not three.
\r
1996 bool bEnabled = true;
\r
1997 if ((m_pwndLeftView == NULL)||(!m_pwndLeftView->IsWindowVisible()))
\r
1999 if ((m_pwndRightView == NULL)||(!m_pwndRightView->IsWindowVisible()))
\r
2001 if ((m_pwndBottomView)&&(m_pwndBottomView->IsWindowVisible()))
\r
2003 pCmdUI->Enable(bEnabled);
\r
2006 void CMainFrame::OnEditCreateunifieddifffile()
\r
2008 CString origFile, modifiedFile, outputFile;
\r
2009 // the original file is the one on the left
\r
2010 if (m_pwndLeftView)
\r
2011 origFile = m_pwndLeftView->m_sFullFilePath;
\r
2012 if (m_pwndRightView)
\r
2013 modifiedFile = m_pwndRightView->m_sFullFilePath;
\r
2014 if (!origFile.IsEmpty() && !modifiedFile.IsEmpty())
\r
2016 // ask for the path to save the unified diff file to
\r
2017 OPENFILENAME ofn = {0}; // common dialog box structure
\r
2018 TCHAR szFile[MAX_PATH] = {0}; // buffer for file name
\r
2019 ofn.lStructSize = sizeof(OPENFILENAME);
\r
2020 ofn.lpstrFile = szFile;
\r
2021 ofn.nMaxFile = sizeof(szFile)/sizeof(TCHAR);
\r
2023 temp.LoadString(IDS_SAVEASTITLE);
\r
2024 if (!temp.IsEmpty())
\r
2025 ofn.lpstrTitle = temp;
\r
2026 ofn.Flags = OFN_OVERWRITEPROMPT;
\r
2028 sFilter.LoadString(IDS_COMMONFILEFILTER);
\r
2029 TCHAR * pszFilters = new TCHAR[sFilter.GetLength()+4];
\r
2030 _tcscpy_s (pszFilters, sFilter.GetLength()+4, sFilter);
\r
2031 // Replace '|' delimiters with '\0's
\r
2032 TCHAR *ptr = pszFilters + _tcslen(pszFilters); //set ptr at the NULL
\r
2033 while (ptr != pszFilters)
\r
2039 ofn.lpstrFilter = pszFilters;
\r
2040 ofn.nFilterIndex = 1;
\r
2042 // Display the Save dialog box.
\r
2044 if (GetSaveFileName(&ofn)==TRUE)
\r
2046 outputFile = CString(ofn.lpstrFile);
\r
2047 CAppUtils::CreateUnifiedDiff(origFile, modifiedFile, outputFile, true);
\r
2049 delete [] pszFilters;
\r
2053 void CMainFrame::OnUpdateViewLinediffbar(CCmdUI *pCmdUI)
\r
2055 pCmdUI->SetCheck(m_bLineDiff);
\r
2059 void CMainFrame::OnViewLinediffbar()
\r
2061 m_bLineDiff = !m_bLineDiff;
\r
2062 m_wndLineDiffBar.ShowPane(m_bLineDiff, false, true);
\r
2063 m_wndLineDiffBar.DocumentUpdated();
\r
2064 m_wndLocatorBar.ShowPane(m_bLocatorBar, false, true);
\r
2065 m_wndLocatorBar.DocumentUpdated();
\r
2068 void CMainFrame::OnUpdateViewLocatorbar(CCmdUI *pCmdUI)
\r
2070 pCmdUI->SetCheck(m_bLocatorBar);
\r
2074 void CMainFrame::OnViewLocatorbar()
\r
2076 m_bLocatorBar = !m_bLocatorBar;
\r
2077 m_wndLocatorBar.ShowPane(m_bLocatorBar, false, true);
\r
2078 m_wndLocatorBar.DocumentUpdated();
\r
2079 m_wndLineDiffBar.ShowPane(m_bLineDiff, false, true);
\r
2080 m_wndLineDiffBar.DocumentUpdated();
\r