1 /////////////////////////////////////////////////////////////////////////////
2 // WinMerge: an interactive diff/merge utility
3 // Copyright (C) 1997-2000 Thingamahoochie Software
5 // SPDX-License-Identifier: GPL-2.0-or-later
6 /////////////////////////////////////////////////////////////////////////////
8 * @file MergeEditView.cpp
10 * @brief Implementation of the CMergeEditView class
14 #include "MergeEditView.h"
18 #include "LocationView.h"
21 #include "OptionsMgr.h"
22 #include "OptionsDiffColors.h"
23 #include "FileTransform.h"
25 #include "WMGotoDlg.h"
26 #include "OptionsDef.h"
27 #include "SyntaxColors.h"
28 #include "MergeEditFrm.h"
29 #include "MergeLineFlags.h"
31 #include "DropHandler.h"
33 #include "ShellContextMenu.h"
40 #ifndef WM_MOUSEHWHEEL
41 # define WM_MOUSEHWHEEL 0x20e
45 using CrystalLineParser::TEXTBLOCK;
47 /** @brief Timer ID for delayed rescan. */
48 const UINT IDT_RESCAN = 2;
49 /** @brief Timer timeout for delayed rescan. */
50 const UINT RESCAN_TIMEOUT = 1000;
52 /** @brief Location for file compare specific help to open. */
53 static TCHAR MergeViewHelpLocation[] = _T("::/htmlhelp/Compare_files.html");
55 /////////////////////////////////////////////////////////////////////////////
58 IMPLEMENT_DYNCREATE(CMergeEditView, CCrystalEditViewEx)
60 CMergeEditView::CMergeEditView()
61 : m_bCurrentLineIsDiff(false)
64 , m_bDetailView(false)
65 , m_piMergeEditStatus(nullptr)
66 , m_bAutomaticRescan(false)
67 , fTimerWaitingForIdle(0)
70 , m_CurrentPredifferID(0)
72 SetParser(&m_xParser);
74 Options::DiffColors::Load(GetOptionsMgr(), m_cachedColors);
77 CMergeEditView::~CMergeEditView()
82 BEGIN_MESSAGE_MAP(CMergeEditView, CCrystalEditViewEx)
83 //{{AFX_MSG_MAP(CMergeEditView)
84 ON_COMMAND(ID_CURDIFF, OnCurdiff)
85 ON_UPDATE_COMMAND_UI(ID_CURDIFF, OnUpdateCurdiff)
86 ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
87 ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateEditCopy)
88 ON_COMMAND(ID_EDIT_CUT, OnEditCut)
89 ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateEditCut)
90 ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
91 ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdateEditPaste)
92 ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
93 ON_COMMAND(ID_FIRSTDIFF, OnFirstdiff)
94 ON_UPDATE_COMMAND_UI(ID_FIRSTDIFF, OnUpdateFirstdiff)
95 ON_COMMAND(ID_LASTDIFF, OnLastdiff)
96 ON_UPDATE_COMMAND_UI(ID_LASTDIFF, OnUpdateLastdiff)
97 ON_COMMAND(ID_NEXTDIFF, OnNextdiff)
98 ON_UPDATE_COMMAND_UI(ID_NEXTDIFF, OnUpdateNextdiff)
99 ON_COMMAND(ID_PREVDIFF, OnPrevdiff)
100 ON_UPDATE_COMMAND_UI(ID_PREVDIFF, OnUpdatePrevdiff)
101 ON_COMMAND(ID_NEXTCONFLICT, OnNextConflict)
102 ON_UPDATE_COMMAND_UI(ID_NEXTCONFLICT, OnUpdateNextConflict)
103 ON_COMMAND(ID_PREVCONFLICT, OnPrevConflict)
104 ON_UPDATE_COMMAND_UI(ID_PREVCONFLICT, OnUpdatePrevConflict)
105 ON_COMMAND(ID_NEXTDIFFLM, OnNextdiffLM)
106 ON_UPDATE_COMMAND_UI(ID_NEXTDIFFLM, OnUpdateNextdiffLM)
107 ON_COMMAND(ID_PREVDIFFLM, OnPrevdiffLM)
108 ON_UPDATE_COMMAND_UI(ID_PREVDIFFLM, OnUpdatePrevdiffLM)
109 ON_COMMAND(ID_NEXTDIFFLR, OnNextdiffLR)
110 ON_UPDATE_COMMAND_UI(ID_NEXTDIFFLR, OnUpdateNextdiffLR)
111 ON_COMMAND(ID_PREVDIFFLR, OnPrevdiffLR)
112 ON_UPDATE_COMMAND_UI(ID_PREVDIFFLR, OnUpdatePrevdiffLR)
113 ON_COMMAND(ID_NEXTDIFFMR, OnNextdiffMR)
114 ON_UPDATE_COMMAND_UI(ID_NEXTDIFFMR, OnUpdateNextdiffMR)
115 ON_COMMAND(ID_PREVDIFFMR, OnPrevdiffMR)
116 ON_UPDATE_COMMAND_UI(ID_PREVDIFFMR, OnUpdatePrevdiffMR)
117 ON_COMMAND(ID_NEXTDIFFLO, OnNextdiffLO)
118 ON_UPDATE_COMMAND_UI(ID_NEXTDIFFLO, OnUpdateNextdiffLO)
119 ON_COMMAND(ID_PREVDIFFLO, OnPrevdiffLO)
120 ON_UPDATE_COMMAND_UI(ID_PREVDIFFLO, OnUpdatePrevdiffLO)
121 ON_COMMAND(ID_NEXTDIFFMO, OnNextdiffMO)
122 ON_UPDATE_COMMAND_UI(ID_NEXTDIFFMO, OnUpdateNextdiffMO)
123 ON_COMMAND(ID_PREVDIFFMO, OnPrevdiffMO)
124 ON_UPDATE_COMMAND_UI(ID_PREVDIFFMO, OnUpdatePrevdiffMO)
125 ON_COMMAND(ID_NEXTDIFFRO, OnNextdiffRO)
126 ON_UPDATE_COMMAND_UI(ID_NEXTDIFFRO, OnUpdateNextdiffRO)
127 ON_COMMAND(ID_PREVDIFFRO, OnPrevdiffRO)
128 ON_UPDATE_COMMAND_UI(ID_PREVDIFFRO, OnUpdatePrevdiffRO)
129 ON_WM_LBUTTONDBLCLK()
132 ON_COMMAND(ID_ALL_LEFT, OnAllLeft)
133 ON_UPDATE_COMMAND_UI(ID_ALL_LEFT, OnUpdateAllLeft)
134 ON_COMMAND(ID_ALL_RIGHT, OnAllRight)
135 ON_UPDATE_COMMAND_UI(ID_ALL_RIGHT, OnUpdateAllRight)
136 ON_COMMAND(ID_AUTO_MERGE, OnAutoMerge)
137 ON_UPDATE_COMMAND_UI(ID_AUTO_MERGE, OnUpdateAutoMerge)
138 ON_COMMAND(ID_L2R, OnL2r)
139 ON_UPDATE_COMMAND_UI(ID_L2R, OnUpdateL2r)
140 ON_COMMAND(ID_R2L, OnR2l)
141 ON_UPDATE_COMMAND_UI(ID_R2L, OnUpdateR2l)
142 ON_COMMAND(ID_COPY_FROM_LEFT, OnCopyFromLeft)
143 ON_UPDATE_COMMAND_UI(ID_COPY_FROM_LEFT, OnUpdateCopyFromLeft)
144 ON_COMMAND(ID_COPY_FROM_RIGHT, OnCopyFromRight)
145 ON_UPDATE_COMMAND_UI(ID_COPY_FROM_RIGHT, OnUpdateCopyFromRight)
146 ON_COMMAND(ID_ADD_SYNCPOINT, OnAddSyncPoint)
147 ON_COMMAND(ID_CLEAR_SYNCPOINTS, OnClearSyncPoints)
148 ON_UPDATE_COMMAND_UI(ID_CLEAR_SYNCPOINTS, OnUpdateClearSyncPoints)
149 ON_UPDATE_COMMAND_UI(ID_EDIT_UNDO, OnUpdateEditUndo)
150 ON_COMMAND(ID_EDIT_REDO, OnEditRedo)
151 ON_UPDATE_COMMAND_UI(ID_EDIT_REDO, OnUpdateEditRedo)
153 ON_UPDATE_COMMAND_UI(ID_FILE_SAVE_LEFT, OnUpdateFileSaveLeft)
154 ON_UPDATE_COMMAND_UI(ID_FILE_SAVE_MIDDLE, OnUpdateFileSaveMiddle)
155 ON_UPDATE_COMMAND_UI(ID_FILE_SAVE_RIGHT, OnUpdateFileSaveRight)
156 ON_COMMAND(ID_REFRESH, OnRefresh)
157 ON_UPDATE_COMMAND_UI(ID_FILE_SAVE, OnUpdateFileSave)
158 ON_COMMAND(ID_SELECTLINEDIFF, OnSelectLineDiff<false>)
159 ON_UPDATE_COMMAND_UI(ID_SELECTLINEDIFF, OnUpdateSelectLineDiff)
160 ON_COMMAND(ID_SELECTPREVLINEDIFF, OnSelectLineDiff<true>)
161 ON_UPDATE_COMMAND_UI(ID_SELECTPREVLINEDIFF, OnUpdateSelectLineDiff)
163 ON_UPDATE_COMMAND_UI(ID_EDIT_REPLACE, OnUpdateEditReplace)
164 ON_COMMAND(ID_FILE_LEFT_READONLY, OnLeftReadOnly)
165 ON_UPDATE_COMMAND_UI(ID_FILE_LEFT_READONLY, OnUpdateLeftReadOnly)
166 ON_COMMAND(ID_FILE_MIDDLE_READONLY, OnMiddleReadOnly)
167 ON_UPDATE_COMMAND_UI(ID_FILE_MIDDLE_READONLY, OnUpdateMiddleReadOnly)
168 ON_COMMAND(ID_FILE_RIGHT_READONLY, OnRightReadOnly)
169 ON_UPDATE_COMMAND_UI(ID_FILE_RIGHT_READONLY, OnUpdateRightReadOnly)
170 ON_UPDATE_COMMAND_UI(ID_STATUS_PANE0FILE_RO, OnUpdateStatusRO)
171 ON_UPDATE_COMMAND_UI(ID_STATUS_PANE1FILE_RO, OnUpdateStatusRO)
172 ON_UPDATE_COMMAND_UI(ID_STATUS_PANE2FILE_RO, OnUpdateStatusRO)
173 ON_COMMAND_RANGE(ID_EOL_TO_DOS, ID_EOL_TO_MAC, OnConvertEolTo)
174 ON_UPDATE_COMMAND_UI_RANGE(ID_EOL_TO_DOS, ID_EOL_TO_MAC, OnUpdateConvertEolTo)
175 ON_UPDATE_COMMAND_UI(ID_STATUS_PANE0FILE_EOL, OnUpdateStatusEOL)
176 ON_UPDATE_COMMAND_UI(ID_STATUS_PANE1FILE_EOL, OnUpdateStatusEOL)
177 ON_UPDATE_COMMAND_UI(ID_STATUS_PANE2FILE_EOL, OnUpdateStatusEOL)
178 ON_COMMAND(ID_L2RNEXT, OnL2RNext)
179 ON_UPDATE_COMMAND_UI(ID_L2RNEXT, OnUpdateL2RNext)
180 ON_COMMAND(ID_R2LNEXT, OnR2LNext)
181 ON_UPDATE_COMMAND_UI(ID_R2LNEXT, OnUpdateR2LNext)
182 ON_COMMAND(ID_WINDOW_CHANGE_PANE, OnChangePane)
183 ON_COMMAND(ID_NEXT_PANE, OnChangePane)
184 ON_COMMAND(ID_EDIT_WMGOTO, OnWMGoto)
185 ON_COMMAND(ID_FILE_SHELLMENU, OnShellMenu)
186 ON_UPDATE_COMMAND_UI(ID_FILE_SHELLMENU, OnUpdateShellMenu)
187 ON_COMMAND_RANGE(ID_SCRIPT_FIRST, ID_SCRIPT_LAST, OnScripts)
188 ON_COMMAND(ID_NO_PREDIFFER, OnNoPrediffer)
189 ON_UPDATE_COMMAND_UI(ID_NO_PREDIFFER, OnUpdateNoPrediffer)
190 ON_COMMAND_RANGE(ID_PREDIFFERS_FIRST, ID_PREDIFFERS_LAST, OnPrediffer)
191 ON_UPDATE_COMMAND_UI_RANGE(ID_PREDIFFERS_FIRST, ID_PREDIFFERS_LAST, OnUpdatePrediffer)
194 ON_COMMAND(ID_EDIT_COPY_LINENUMBERS, OnEditCopyLineNumbers)
195 ON_UPDATE_COMMAND_UI(ID_EDIT_COPY_LINENUMBERS, OnUpdateEditCopyLinenumbers)
196 ON_COMMAND(ID_VIEW_LINEDIFFS, OnViewLineDiffs)
197 ON_UPDATE_COMMAND_UI(ID_VIEW_LINEDIFFS, OnUpdateViewLineDiffs)
198 ON_COMMAND(ID_VIEW_WORDWRAP, OnViewWordWrap)
199 ON_UPDATE_COMMAND_UI(ID_VIEW_WORDWRAP, OnUpdateViewWordWrap)
200 ON_COMMAND(ID_VIEW_LINENUMBERS, OnViewLineNumbers)
201 ON_UPDATE_COMMAND_UI(ID_VIEW_LINENUMBERS, OnUpdateViewLineNumbers)
202 ON_COMMAND(ID_VIEW_WHITESPACE, OnViewWhitespace)
203 ON_UPDATE_COMMAND_UI(ID_VIEW_WHITESPACE, OnUpdateViewWhitespace)
204 ON_COMMAND(ID_VIEW_EOL, OnViewEOL)
205 ON_UPDATE_COMMAND_UI(ID_VIEW_EOL, OnUpdateViewEOL)
206 ON_COMMAND(ID_FILE_OPEN_REGISTERED, OnOpenFile)
207 ON_COMMAND(ID_FILE_OPEN_WITHEDITOR, OnOpenFileWithEditor)
208 ON_COMMAND(ID_FILE_OPEN_WITH, OnOpenFileWith)
209 ON_COMMAND(ID_VIEW_SWAPPANES, OnViewSwapPanes)
210 ON_UPDATE_COMMAND_UI(ID_NO_EDIT_SCRIPTS, OnUpdateNoEditScripts)
213 ON_COMMAND(ID_HELP, OnHelp)
214 ON_COMMAND(ID_VIEW_SELMARGIN, OnViewMargin)
215 ON_UPDATE_COMMAND_UI(ID_VIEW_SELMARGIN, OnUpdateViewMargin)
216 ON_UPDATE_COMMAND_UI(ID_VIEW_CHANGESCHEME, OnUpdateViewChangeScheme)
217 ON_COMMAND_RANGE(ID_COLORSCHEME_FIRST, ID_COLORSCHEME_LAST, OnChangeScheme)
218 ON_UPDATE_COMMAND_UI_RANGE(ID_COLORSCHEME_FIRST, ID_COLORSCHEME_LAST, OnUpdateChangeScheme)
221 ON_COMMAND(ID_VIEW_ZOOMIN, OnViewZoomIn)
222 ON_COMMAND(ID_VIEW_ZOOMOUT, OnViewZoomOut)
223 ON_COMMAND(ID_VIEW_ZOOMNORMAL, OnViewZoomNormal)
224 ON_COMMAND(ID_WINDOW_SPLIT, OnWindowSplit)
225 ON_UPDATE_COMMAND_UI(ID_WINDOW_SPLIT, OnUpdateWindowSplit)
226 ON_NOTIFY(NM_DBLCLK, AFX_IDW_STATUS_BAR, OnStatusBarDblClick)
231 /////////////////////////////////////////////////////////////////////////////
232 // CMergeEditView diagnostics
235 CMergeDoc* CMergeEditView::GetDocument() // non-debug version is inline
237 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMergeDoc)));
238 return (CMergeDoc*)m_pDocument;
243 /////////////////////////////////////////////////////////////////////////////
244 // CMergeEditView message handlers
247 * @brief Return text buffer for file in view
249 CCrystalTextBuffer *CMergeEditView::LocateTextBuffer()
251 return GetDocument()->m_ptBuf[m_nThisPane].get();
255 * @brief Update any resources necessary after a GUI language change
257 void CMergeEditView::UpdateResources()
261 CMergeEditView *CMergeEditView::GetGroupView(int nBuffer) const
263 return GetDocument()->GetView(m_nThisGroup, nBuffer);
266 void CMergeEditView::PrimeListWithFile()
268 // Set the tab size now, just in case the options change...
269 // We don't update it at the end of OnOptions,
270 // we can update it safely now
271 SetTabSize(GetOptionsMgr()->GetInt(OPT_TAB_SIZE));
274 * @brief Return text from line given
276 CString CMergeEditView::GetLineText(int idx)
278 return GetLineChars(idx);
282 * @brief Return text from selection
284 CString CMergeEditView::GetSelectedText()
286 CPoint ptStart, ptEnd;
288 GetSelection(ptStart, ptEnd);
289 if (ptStart != ptEnd)
290 GetTextWithoutEmptys(ptStart.y, ptStart.x, ptEnd.y, ptEnd.x, strText);
295 * @brief Get diffs inside selection.
296 * @param [out] firstDiff First diff inside selection
297 * @param [out] lastDiff Last diff inside selection
298 * @note -1 is returned in parameters if diffs cannot be determined
299 * @todo This shouldn't be called when there is no diffs, so replace
300 * first 'if' with ASSERT()?
302 void CMergeEditView::GetFullySelectedDiffs(int & firstDiff, int & lastDiff)
307 CMergeDoc *pd = GetDocument();
308 const int nDiffs = pd->m_diffList.GetSignificantDiffs();
312 int firstLine, lastLine;
313 GetFullySelectedLines(firstLine, lastLine);
314 if (lastLine < firstLine)
317 firstDiff = pd->m_diffList.NextSignificantDiffFromLine(firstLine);
318 lastDiff = pd->m_diffList.PrevSignificantDiffFromLine(lastLine);
319 if (firstDiff != -1 && lastDiff != -1)
323 // Check that first selected line is first diff's first line or above it
324 VERIFY(pd->m_diffList.GetDiff(firstDiff, di));
325 if ((int)di.dbegin < firstLine)
327 if (firstDiff < lastDiff)
331 // Check that last selected line is last diff's last line or below it
332 VERIFY(pd->m_diffList.GetDiff(lastDiff, di));
333 if ((int)di.dend > lastLine)
335 if (firstDiff < lastDiff)
339 // Special case: one-line diff is not selected if cursor is in it
340 if (firstLine == lastLine)
349 * @brief Get diffs inside selection.
350 * @param [out] firstDiff First diff inside selection
351 * @param [out] lastDiff Last diff inside selection
352 * @param [out] firstWordDiff First word level diff inside selection
353 * @param [out] lastWordDiff Last word level diff inside selection
354 * @note -1 is returned in parameters if diffs cannot be determined
355 * @todo This shouldn't be called when there is no diffs, so replace
356 * first 'if' with ASSERT()?
358 void CMergeEditView::GetFullySelectedDiffs(int & firstDiff, int & lastDiff, int & firstWordDiff, int & lastWordDiff, const CPoint *pptStart, const CPoint *pptEnd)
365 CMergeDoc *pd = GetDocument();
366 const int nDiffs = pd->m_diffList.GetSignificantDiffs();
370 int firstLine, lastLine;
371 CPoint ptStart, ptEnd;
372 GetSelection(ptStart, ptEnd);
373 if (pptStart != nullptr)
375 if (pptEnd != nullptr)
377 firstLine = ptStart.y;
380 firstDiff = pd->m_diffList.LineToDiff(firstLine);
381 bool firstLineIsNotInDiff = firstDiff == -1;
384 firstDiff = pd->m_diffList.NextSignificantDiffFromLine(firstLine);
389 lastDiff = pd->m_diffList.LineToDiff(lastLine);
390 bool lastLineIsNotInDiff = lastDiff == -1;
392 lastDiff = pd->m_diffList.PrevSignificantDiffFromLine(lastLine);
393 if (lastDiff < firstDiff)
400 if (firstDiff != -1 && lastDiff != -1)
404 if (pd->EqualCurrentWordDiff(m_nThisPane, ptStart, ptEnd))
406 firstWordDiff = lastWordDiff = static_cast<int>(pd->GetCurrentWordDiff().nWordDiff);
408 else if (ptStart != ptEnd)
410 VERIFY(pd->m_diffList.GetDiff(firstDiff, di));
411 if (lastLineIsNotInDiff && (firstLineIsNotInDiff || (di.dbegin == firstLine && ptStart.x == 0)))
417 if (firstWordDiff == -1)
419 vector<WordDiff> worddiffs = pd->GetWordDiffArrayInDiffBlock(firstDiff);
420 for (size_t i = 0; i < worddiffs.size(); ++i)
422 int worddiffLen = worddiffs[i].end[m_nThisPane] - worddiffs[i].begin[m_nThisPane];
423 if (worddiffs[i].endline[m_nThisPane] > firstLine ||
424 (firstLine == worddiffs[i].endline[m_nThisPane] &&
425 worddiffs[i].end[m_nThisPane] - (worddiffLen == 0 ? 0 : 1) >= ptStart.x))
427 firstWordDiff = static_cast<int>(i);
432 if (firstLine >= di.dbegin && firstWordDiff == -1)
439 VERIFY(pd->m_diffList.GetDiff(lastDiff, di));
440 vector<WordDiff> worddiffs = pd->GetWordDiffArrayInDiffBlock(lastDiff);
441 for (size_t i = worddiffs.size() - 1; i != (size_t)-1; --i)
443 if (worddiffs[i].beginline[m_nThisPane] < lastLine ||
444 (lastLine == worddiffs[i].beginline[m_nThisPane] && worddiffs[i].begin[m_nThisPane] + 1 <= ptEnd.x))
446 lastWordDiff = static_cast<int>(i);
451 if (lastLine <= di.dend && lastWordDiff == -1)
454 if (firstDiff == lastDiff && (lastWordDiff != -1 && lastWordDiff < firstWordDiff))
461 else if (lastDiff < firstDiff || (firstDiff == lastDiff && firstWordDiff == -1 && lastWordDiff == -1))
478 ASSERT(firstDiff == -1 ? (lastDiff == -1 && firstWordDiff == -1 && lastWordDiff == -1) : true);
479 ASSERT(lastDiff == -1 ? (firstDiff == -1 && firstWordDiff == -1 && lastWordDiff == -1) : true);
480 ASSERT(firstDiff != -1 ? firstWordDiff != -1 : true);
483 std::map<int, std::vector<int>> CMergeEditView::GetColumnSelectedWordDiffIndice()
485 CMergeDoc *pDoc = GetDocument();
486 std::map<int, std::vector<int>> ret;
487 std::map<int, std::vector<int> *> list;
488 CPoint ptStart, ptEnd;
489 GetSelection(ptStart, ptEnd);
490 for (int nLine = ptStart.y; nLine <= ptEnd.y; ++nLine)
492 if (pDoc->m_diffList.LineToDiff(nLine) != -1)
494 int firstDiff, lastDiff, firstWordDiff, lastWordDiff;
496 GetColumnSelection(nLine, nLeft, nRight);
497 CPoint ptStart2, ptEnd2;
500 ptStart2.y = ptEnd2.y = nLine;
501 GetFullySelectedDiffs(firstDiff, lastDiff, firstWordDiff, lastWordDiff, &ptStart2, &ptEnd2);
502 if (firstDiff != -1 && lastDiff != -1)
504 std::vector<int> *pWordDiffs;
505 if (list.find(firstDiff) == list.end())
506 list.insert(std::pair<int, std::vector<int> *>(firstDiff, new std::vector<int>()));
507 pWordDiffs = list[firstDiff];
508 for (int i = firstWordDiff; i <= lastWordDiff; ++i)
510 if (pWordDiffs->empty() || i != (*pWordDiffs)[pWordDiffs->size() - 1])
511 pWordDiffs->push_back(i);
516 for (auto& it : list)
517 ret.insert(std::pair<int, std::vector<int>>(it.first, *it.second));
521 void CMergeEditView::OnInitialUpdate()
524 CCrystalEditViewEx::OnInitialUpdate();
526 SetFont(dynamic_cast<CMainFrame*>(AfxGetMainWnd())->m_lfDiff);
527 SetAlternateDropTarget(new DropHandler(std::bind(&CMergeEditView::OnDropFiles, this, std::placeholders::_1)));
533 void CMergeEditView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
535 CCrystalEditViewEx::OnActivateView(bActivate, pActivateView, pDeactiveView);
537 CMergeDoc* pDoc = GetDocument();
538 pDoc->UpdateHeaderActivity(m_nThisPane, !!bActivate);
541 std::vector<CrystalLineParser::TEXTBLOCK> CMergeEditView::GetMarkerTextBlocks(int nLineIndex) const
545 if (nLineIndex < m_lineBegin || nLineIndex > m_lineEnd)
546 return std::vector<CrystalLineParser::TEXTBLOCK>();
548 return CCrystalTextView::GetMarkerTextBlocks(nLineIndex);
551 std::vector<TEXTBLOCK> CMergeEditView::GetAdditionalTextBlocks (int nLineIndex)
553 static const std::vector<TEXTBLOCK> emptyBlocks;
556 if (nLineIndex < m_lineBegin || nLineIndex > m_lineEnd)
560 DWORD dwLineFlags = GetLineFlags(nLineIndex);
561 if ((dwLineFlags & LF_SNP) == LF_SNP || (dwLineFlags & LF_DIFF) != LF_DIFF || (dwLineFlags & LF_MOVED) == LF_MOVED)
564 if (!GetOptionsMgr()->GetBool(OPT_WORDDIFF_HIGHLIGHT))
567 CMergeDoc *pDoc = GetDocument();
568 if (pDoc->IsEditedAfterRescan(m_nThisPane))
571 int nDiff = pDoc->m_diffList.LineToDiff(nLineIndex);
576 pDoc->m_diffList.GetDiff(nDiff, cd);
577 int unemptyLineCount = 0;
578 for (int nPane = 0; nPane < pDoc->m_nBuffers; nPane++)
580 if (cd.begin[nPane] != cd.end[nPane] + 1)
583 if (unemptyLineCount < 2)
586 vector<WordDiff> worddiffs = pDoc->GetWordDiffArray(nLineIndex);
587 size_t nWordDiffs = worddiffs.size();
589 bool lineInCurrentDiff = IsLineInCurrentDiff(nLineIndex);
591 std::vector<TEXTBLOCK> blocks(nWordDiffs * 2 + 1);
592 blocks[0].m_nCharPos = 0;
593 blocks[0].m_nColorIndex = COLORINDEX_NONE;
594 blocks[0].m_nBgColorIndex = COLORINDEX_NONE;
596 for (i = 0, j = 1; i < nWordDiffs; i++)
598 if (worddiffs[i].beginline[m_nThisPane] > nLineIndex || worddiffs[i].endline[m_nThisPane] < nLineIndex )
600 if (pDoc->m_nBuffers > 2)
602 if (m_nThisPane == 0 && worddiffs[i].op == OP_3RDONLY)
604 else if (m_nThisPane == 2 && worddiffs[i].op == OP_1STONLY)
607 int begin[3], end[3];
608 bool deleted = false;
609 for (int pane = 0; pane < pDoc->m_nBuffers; pane++)
611 begin[pane] = (worddiffs[i].beginline[pane] < nLineIndex) ? 0 : worddiffs[i].begin[pane];
612 end[pane] = (worddiffs[i].endline[pane] > nLineIndex) ? GetGroupView(pane)->GetLineLength(nLineIndex) : worddiffs[i].end[pane];
613 if (worddiffs[i].beginline[pane] == worddiffs[i].endline[pane] &&
614 worddiffs[i].begin[pane] == worddiffs[i].end[pane])
617 blocks[j].m_nCharPos = begin[m_nThisPane];
618 if (lineInCurrentDiff)
620 if (m_cachedColors.clrSelDiffText != CLR_NONE)
621 blocks[j].m_nColorIndex = COLORINDEX_HIGHLIGHTTEXT1 | COLORINDEX_APPLYFORCE;
623 blocks[j].m_nColorIndex = COLORINDEX_NONE;
624 blocks[j].m_nBgColorIndex = COLORINDEX_APPLYFORCE |
625 (deleted ? COLORINDEX_HIGHLIGHTBKGND4 : COLORINDEX_HIGHLIGHTBKGND1);
629 if (m_cachedColors.clrDiffText != CLR_NONE)
630 blocks[j].m_nColorIndex = COLORINDEX_HIGHLIGHTTEXT2 | COLORINDEX_APPLYFORCE;
632 blocks[j].m_nColorIndex = COLORINDEX_NONE;
633 blocks[j].m_nBgColorIndex = COLORINDEX_APPLYFORCE |
634 (deleted ? COLORINDEX_HIGHLIGHTBKGND3 : COLORINDEX_HIGHLIGHTBKGND2);
637 blocks[j].m_nCharPos = end[m_nThisPane];
638 blocks[j].m_nColorIndex = COLORINDEX_NONE;
639 blocks[j].m_nBgColorIndex = COLORINDEX_NONE;
648 COLORREF CMergeEditView::GetColor(int nColorIndex)
650 switch (nColorIndex & ~COLORINDEX_APPLYFORCE)
652 case COLORINDEX_HIGHLIGHTBKGND1:
653 return m_cachedColors.clrSelWordDiff;
654 case COLORINDEX_HIGHLIGHTTEXT1:
655 return m_cachedColors.clrSelWordDiffText;
656 case COLORINDEX_HIGHLIGHTBKGND2:
657 return m_cachedColors.clrWordDiff;
658 case COLORINDEX_HIGHLIGHTTEXT2:
659 return m_cachedColors.clrWordDiffText;
660 case COLORINDEX_HIGHLIGHTBKGND3:
661 return m_cachedColors.clrWordDiffDeleted;
662 case COLORINDEX_HIGHLIGHTBKGND4:
663 return m_cachedColors.clrSelWordDiffDeleted;
666 return CCrystalTextView::GetColor(nColorIndex);
671 * @brief Determine text and background color for line
672 * @param [in] nLineIndex Index of line in view (NOT line in file)
673 * @param [out] crBkgnd Backround color for line
674 * @param [out] crText Text color for line
676 void CMergeEditView::GetLineColors(int nLineIndex, COLORREF & crBkgnd,
677 COLORREF & crText, bool & bDrawWhitespace)
679 DWORD ignoreFlags = 0;
680 GetLineColors2(nLineIndex, ignoreFlags, crBkgnd, crText, bDrawWhitespace);
684 * @brief Determine text and background color for line
685 * @param [in] nLineIndex Index of line in view (NOT line in file)
686 * @param [in] ignoreFlags Flags that caller wishes ignored
687 * @param [out] crBkgnd Backround color for line
688 * @param [out] crText Text color for line
690 * This version allows caller to suppress particular flags
692 void CMergeEditView::GetLineColors2(int nLineIndex, DWORD ignoreFlags, COLORREF & crBkgnd,
693 COLORREF & crText, bool & bDrawWhitespace)
695 if (GetLineCount() <= nLineIndex)
698 DWORD dwLineFlags = GetLineFlags(nLineIndex);
700 if (dwLineFlags & ignoreFlags)
701 dwLineFlags &= (~ignoreFlags);
705 // Line with WinMerge flag,
706 // Lines with only the LF_DIFF/LF_TRIVIAL flags are not colored with Winmerge colors
707 if (dwLineFlags & (LF_WINMERGE_FLAGS & ~LF_DIFF & ~LF_TRIVIAL & ~LF_MOVED & ~LF_SNP))
709 crText = m_cachedColors.clrDiffText;
710 bDrawWhitespace = true;
712 if (dwLineFlags & LF_GHOST)
714 crBkgnd = m_cachedColors.clrDiffDeleted;
719 // If no syntax hilighting
720 if (!GetOptionsMgr()->GetBool(OPT_SYNTAX_HIGHLIGHT))
722 crBkgnd = GetColor (COLORINDEX_BKGND);
723 crText = GetColor (COLORINDEX_NORMALTEXT);
724 bDrawWhitespace = false;
727 // Line not inside diff, get colors from CrystalEditor
728 CCrystalEditViewEx::GetLineColors(nLineIndex, crBkgnd,
729 crText, bDrawWhitespace);
731 if (nLineIndex < m_lineBegin || nLineIndex > m_lineEnd)
733 crBkgnd = GetColor (COLORINDEX_WHITESPACE);
734 crText = GetColor (COLORINDEX_WHITESPACE);
735 bDrawWhitespace = false;
741 if (dwLineFlags & LF_WINMERGE_FLAGS)
743 crText = m_cachedColors.clrDiffText;
744 bDrawWhitespace = true;
745 bool lineInCurrentDiff = IsLineInCurrentDiff(nLineIndex);
747 if (dwLineFlags & LF_SNP)
749 if (lineInCurrentDiff)
751 if (dwLineFlags & LF_GHOST)
752 crBkgnd = m_cachedColors.clrSelSNPDeleted;
754 crBkgnd = m_cachedColors.clrSelSNP;
755 crText = m_cachedColors.clrSelSNPText;
759 if (dwLineFlags & LF_GHOST)
760 crBkgnd = m_cachedColors.clrSNPDeleted;
762 crBkgnd = m_cachedColors.clrSNP;
763 crText = m_cachedColors.clrSNPText;
767 else if (dwLineFlags & LF_DIFF)
769 if (lineInCurrentDiff)
771 if (dwLineFlags & LF_MOVED)
773 crBkgnd = m_cachedColors.clrSelMoved;
774 crText = m_cachedColors.clrSelMovedText;
778 crBkgnd = m_cachedColors.clrSelDiff;
779 crText = m_cachedColors.clrSelDiffText;
785 if (dwLineFlags & LF_MOVED)
787 crBkgnd = m_cachedColors.clrMoved;
788 crText = m_cachedColors.clrMovedText;
792 crBkgnd = m_cachedColors.clrDiff;
793 crText = m_cachedColors.clrDiffText;
798 else if (dwLineFlags & LF_TRIVIAL)
800 // trivial diff can not be selected
801 if (dwLineFlags & LF_GHOST)
802 // ghost lines in trivial diff has their own color
803 crBkgnd = m_cachedColors.clrTrivialDeleted;
805 crBkgnd = m_cachedColors.clrTrivial;
806 crText = m_cachedColors.clrTrivialText;
809 else if (dwLineFlags & LF_GHOST)
811 if (lineInCurrentDiff)
813 if (dwLineFlags & LF_MOVED)
814 crBkgnd = m_cachedColors.clrSelMovedDeleted;
816 crBkgnd = m_cachedColors.clrSelDiffDeleted;
820 if (dwLineFlags & LF_MOVED)
821 crBkgnd = m_cachedColors.clrMovedDeleted;
823 crBkgnd = m_cachedColors.clrDiffDeleted;
830 // Line not inside diff,
831 if (!GetOptionsMgr()->GetBool(OPT_SYNTAX_HIGHLIGHT))
833 // If no syntax hilighting, get windows default colors
834 crBkgnd = GetColor (COLORINDEX_BKGND);
835 crText = GetColor (COLORINDEX_NORMALTEXT);
836 bDrawWhitespace = false;
839 // Syntax highlighting, get colors from CrystalEditor
840 CCrystalEditViewEx::GetLineColors(nLineIndex, crBkgnd,
841 crText, bDrawWhitespace);
846 * @brief Sync other pane position
848 void CMergeEditView::UpdateSiblingScrollPos (bool bHorz)
850 CSplitterWnd *pSplitterWnd = GetParentSplitter (this, false);
851 if (pSplitterWnd != nullptr)
853 // See CSplitterWnd::IdFromRowCol() implementation for details
854 int nCurrentRow = (GetDlgCtrlID () - AFX_IDW_PANE_FIRST) / 16;
855 int nCurrentCol = (GetDlgCtrlID () - AFX_IDW_PANE_FIRST) % 16;
856 ASSERT (nCurrentRow >= 0 && nCurrentRow < pSplitterWnd->GetRowCount ());
857 ASSERT (nCurrentCol >= 0 && nCurrentCol < pSplitterWnd->GetColumnCount ());
859 // limit the TopLine : must be smaller than GetLineCount for all the panels
860 int newTopSubLine = m_nTopSubLine;
861 int nRows = pSplitterWnd->GetRowCount ();
862 int nCols = pSplitterWnd->GetColumnCount ();
864 // for (nRow = 0; nRow < nRows; nRow++)
866 // for (int nCol = 0; nCol < nCols; nCol++)
868 // CMergeEditView *pSiblingView = static_cast<CMergeEditView*>(GetSiblingView (nRow, nCol));
869 // if (pSiblingView != nullptr)
870 // if (pSiblingView->GetSubLineCount() <= newTopSubLine)
871 // newTopSubLine = pSiblingView->GetSubLineCount()-1;
874 if (m_nTopSubLine != newTopSubLine)
875 ScrollToSubLine(newTopSubLine);
877 for (nRow = 0; nRow < nRows; nRow++)
879 for (int nCol = 0; nCol < nCols; nCol++)
881 if (!(nRow == nCurrentRow && nCol == nCurrentCol)) // We don't need to update ourselves
883 CMergeEditView *pSiblingView = static_cast<CMergeEditView*>(GetSiblingView (nRow, nCol));
884 if (pSiblingView != nullptr && pSiblingView->m_nThisGroup == m_nThisGroup)
885 pSiblingView->OnUpdateSibling (this, bHorz);
893 * @brief Update other panes
895 void CMergeEditView::OnUpdateSibling (CCrystalTextView * pUpdateSource, bool bHorz)
897 if (pUpdateSource != this)
899 ASSERT (pUpdateSource != nullptr);
900 ASSERT_KINDOF (CCrystalTextView, pUpdateSource);
901 CMergeEditView *pSrcView = static_cast<CMergeEditView*>(pUpdateSource);
902 if (!bHorz) // changed this so bHorz works right
904 ASSERT (pSrcView->m_nTopSubLine >= 0);
906 // This ASSERT is wrong: panes have different files and
907 // different linecounts
908 // ASSERT (pSrcView->m_nTopLine < GetLineCount ());
909 if (pSrcView->m_nTopSubLine != m_nTopSubLine)
911 ScrollToSubLine (pSrcView->m_nTopSubLine, true, false);
913 RecalcVertScrollBar(true);
914 RecalcHorzScrollBar();
919 ASSERT (pSrcView->m_nOffsetChar >= 0);
921 // This ASSERT is wrong: panes have different files and
922 // different linelengths
923 // ASSERT (pSrcView->m_nOffsetChar < GetMaxLineLength ());
924 if (pSrcView->m_nOffsetChar != m_nOffsetChar)
926 ScrollToChar (pSrcView->m_nOffsetChar, true, false);
928 RecalcHorzScrollBar(true);
929 RecalcHorzScrollBar();
935 void CMergeEditView::OnDisplayDiff(int nDiff /*=0*/)
937 int newlineBegin, newlineEnd;
938 CMergeDoc *pd = GetDocument();
939 if (nDiff < 0 || nDiff >= pd->m_diffList.GetSize())
947 VERIFY(pd->m_diffList.GetDiff(nDiff, curDiff));
949 newlineBegin = curDiff.dbegin;
950 ASSERT (newlineBegin >= 0);
951 newlineEnd = curDiff.dend;
954 m_lineBegin = newlineBegin;
955 m_lineEnd = newlineEnd;
957 int nLineCount = GetLineCount();
958 if (m_lineBegin > nLineCount)
959 m_lineBegin = nLineCount - 1;
960 if (m_lineEnd > nLineCount)
961 m_lineEnd = nLineCount - 1;
963 if (m_nTopLine == newlineBegin)
966 // scroll to the first line of the diff
967 ScrollToLine(m_lineBegin);
969 // update the width of the horizontal scrollbar
970 RecalcHorzScrollBar();
974 * @brief Selects diff by number and syncs other file
975 * @param [in] nDiff Diff to select, must be >= 0
976 * @param [in] bScroll Scroll diff to view
977 * @param [in] bSelectText Select diff text
978 * @sa CMergeEditView::ShowDiff()
979 * @sa CMergeDoc::SetCurrentDiff()
980 * @todo Parameter bSelectText is never used?
982 void CMergeEditView::SelectDiff(int nDiff, bool bScroll /*= true*/, bool bSelectText /*= true*/)
984 CMergeDoc *pd = GetDocument();
986 // Check that nDiff is valid
988 _RPTF1(_CRT_ERROR, "Diffnumber negative (%d)", nDiff);
989 if (nDiff >= pd->m_diffList.GetSize())
990 _RPTF2(_CRT_ERROR, "Selected diff > diffcount (%d >= %d)",
991 nDiff, pd->m_diffList.GetSize());
994 pd->SetCurrentDiff(nDiff);
995 ShowDiff(bScroll, bSelectText);
996 pd->UpdateAllViews(this);
997 UpdateSiblingScrollPos(false);
999 // notify either side, as it will notify the other one
1000 pd->ForEachView ([&](auto& pView) { if (pView->m_bDetailView) pView->OnDisplayDiff(nDiff); });
1003 void CMergeEditView::DeselectDiffIfCursorNotInCurrentDiff()
1005 CMergeDoc *pd = GetDocument();
1006 // If we have a selected diff, deselect it
1007 int nCurrentDiff = pd->GetCurrentDiff();
1008 if (nCurrentDiff != -1)
1010 CPoint pos = GetCursorPos();
1011 if (!IsLineInCurrentDiff(pos.y))
1013 pd->SetCurrentDiff(-1);
1015 pd->UpdateAllViews(this);
1021 * @brief Called when user selects "Current Difference".
1022 * Goes to active diff. If no active diff, selects diff under cursor
1023 * @sa CMergeEditView::SelectDiff()
1024 * @sa CMergeDoc::GetCurrentDiff()
1025 * @sa CMergeDoc::LineToDiff()
1027 void CMergeEditView::OnCurdiff()
1029 CMergeDoc *pd = GetDocument();
1031 // If no diffs, nothing to select
1032 if (!pd->m_diffList.HasSignificantDiffs())
1035 // GetCurrentDiff() returns -1 if no diff selected
1036 int nDiff = pd->GetCurrentDiff();
1039 // Scroll to the first line of the currently selected diff
1040 SelectDiff(nDiff, true, false);
1044 // If cursor is inside diff, select that diff
1045 CPoint pos = GetCursorPos();
1046 nDiff = pd->m_diffList.LineToDiff(pos.y);
1047 if (nDiff != -1 && pd->m_diffList.IsDiffSignificant(nDiff))
1048 SelectDiff(nDiff, true, false);
1053 * @brief Called when "Current diff" item is updated
1055 void CMergeEditView::OnUpdateCurdiff(CCmdUI* pCmdUI)
1057 CMergeDoc *pd = GetDocument();
1058 CPoint pos = GetCursorPos();
1059 int nCurrentDiff = pd->GetCurrentDiff();
1060 if (nCurrentDiff == -1)
1062 int nNewDiff = pd->m_diffList.LineToDiff(pos.y);
1063 pCmdUI->Enable(nNewDiff != -1 && pd->m_diffList.IsDiffSignificant(nNewDiff));
1066 pCmdUI->Enable(true);
1070 * @brief Copy selected text to clipboard
1072 void CMergeEditView::OnEditCopy()
1074 CMergeDoc * pDoc = GetDocument();
1075 CPoint ptSelStart, ptSelEnd;
1076 GetSelection(ptSelStart, ptSelEnd);
1079 if (ptSelStart == ptSelEnd)
1084 if (!m_bRectangularSelection)
1086 CDiffTextBuffer * buffer = pDoc->m_ptBuf[m_nThisPane].get();
1088 buffer->GetTextWithoutEmptys(ptSelStart.y, ptSelStart.x,
1089 ptSelEnd.y, ptSelEnd.x, text);
1092 GetTextWithoutEmptysInColumnSelection(text);
1094 PutToClipboard(text, text.GetLength(), m_bRectangularSelection);
1098 * @brief Called when "Copy" item is updated
1100 void CMergeEditView::OnUpdateEditCopy(CCmdUI* pCmdUI)
1102 CCrystalEditViewEx::OnUpdateEditCopy(pCmdUI);
1106 * @brief Cut current selection to clipboard
1108 void CMergeEditView::OnEditCut()
1110 if (!QueryEditable())
1113 CPoint ptSelStart, ptSelEnd;
1114 CMergeDoc * pDoc = GetDocument();
1115 GetSelection(ptSelStart, ptSelEnd);
1118 if (ptSelStart == ptSelEnd)
1122 if (!m_bRectangularSelection)
1123 pDoc->m_ptBuf[m_nThisPane]->GetTextWithoutEmptys(ptSelStart.y, ptSelStart.x,
1124 ptSelEnd.y, ptSelEnd.x, text);
1126 GetTextWithoutEmptysInColumnSelection(text);
1128 PutToClipboard(text, text.GetLength(), m_bRectangularSelection);
1130 if (!m_bRectangularSelection)
1132 CPoint ptCursorPos = ptSelStart;
1133 ASSERT_VALIDTEXTPOS(ptCursorPos);
1134 SetAnchor(ptCursorPos);
1135 SetSelection(ptCursorPos, ptCursorPos);
1136 SetCursorPos(ptCursorPos);
1137 EnsureVisible(ptCursorPos);
1139 pDoc->m_ptBuf[m_nThisPane]->DeleteText(this, ptSelStart.y, ptSelStart.x, ptSelEnd.y,
1140 ptSelEnd.x, CE_ACTION_CUT);
1143 DeleteCurrentColumnSelection (CE_ACTION_CUT);
1145 m_pTextBuffer->SetModified(true);
1149 * @brief Called when "Cut" item is updated
1151 void CMergeEditView::OnUpdateEditCut(CCmdUI* pCmdUI)
1153 if (QueryEditable())
1154 CCrystalEditViewEx::OnUpdateEditCut(pCmdUI);
1156 pCmdUI->Enable(false);
1160 * @brief Paste text from clipboard
1162 void CMergeEditView::OnEditPaste()
1164 if (!QueryEditable())
1167 CCrystalEditViewEx::Paste();
1168 m_pTextBuffer->SetModified(true);
1172 * @brief Called when "Paste" item is updated
1174 void CMergeEditView::OnUpdateEditPaste(CCmdUI* pCmdUI)
1176 if (QueryEditable())
1177 CCrystalEditViewEx::OnUpdateEditPaste(pCmdUI);
1179 pCmdUI->Enable(false);
1183 * @brief Undo last action
1185 void CMergeEditView::OnEditUndo()
1187 CWaitCursor waitstatus;
1188 CMergeDoc* pDoc = GetDocument();
1189 CMergeEditView *tgt = pDoc->GetView(m_nThisGroup, *(pDoc->curUndo-1));
1192 if (!QueryEditable())
1195 GetParentFrame()->SetActiveView(this, true);
1196 if(CCrystalEditViewEx::DoEditUndo())
1199 pDoc->UpdateHeaderPath(m_nThisPane);
1200 pDoc->FlushAndRescan();
1203 m_pTextBuffer->GetRedoActionCode(nAction);
1204 if (nAction == CE_ACTION_MERGE)
1205 // select the diff so we may just merge it again
1211 tgt->SendMessage(WM_COMMAND, ID_EDIT_UNDO);
1213 if (!pDoc->CanUndo())
1214 pDoc->SetAutoMerged(false);
1218 * @brief Called when "Undo" item is updated
1220 void CMergeEditView::OnUpdateEditUndo(CCmdUI* pCmdUI)
1222 CMergeDoc* pDoc = GetDocument();
1223 if (pDoc->curUndo!=pDoc->undoTgt.begin())
1225 CMergeEditView *tgt = pDoc->GetView(m_nThisGroup, *(pDoc->curUndo-1));
1226 pCmdUI->Enable( !IsReadOnly(tgt->m_nThisPane));
1229 pCmdUI->Enable(false);
1233 * @brief Go to first diff
1235 * Called when user selects "First Difference"
1236 * @sa CMergeEditView::SelectDiff()
1238 void CMergeEditView::OnFirstdiff()
1240 CMergeDoc *pd = GetDocument();
1241 if (pd->m_diffList.HasSignificantDiffs())
1243 int nDiff = pd->m_diffList.FirstSignificantDiff();
1244 SelectDiff(nDiff, true, false);
1249 * @brief Update "First diff" UI items
1251 void CMergeEditView::OnUpdateFirstdiff(CCmdUI* pCmdUI)
1253 OnUpdatePrevdiff(pCmdUI);
1257 * @brief Go to last diff
1259 void CMergeEditView::OnLastdiff()
1261 CMergeDoc *pd = GetDocument();
1262 if (pd->m_diffList.HasSignificantDiffs())
1264 int nDiff = pd->m_diffList.LastSignificantDiff();
1265 SelectDiff(nDiff, true, false);
1270 * @brief Update "Last diff" UI items
1272 void CMergeEditView::OnUpdateLastdiff(CCmdUI* pCmdUI)
1274 OnUpdateNextdiff(pCmdUI);
1278 * @brief Go to next diff and select it.
1280 * Finds and selects next difference. There are several cases:
1281 * - if there is selected difference, and that difference is visible
1282 * on screen, next found difference is selected.
1283 * - if there is selected difference but it is not visible, next
1284 * difference from cursor position is selected. This is what user
1285 * expects to happen and is natural thing to do. Also reduces
1286 * needless scrolling.
1287 * - if there is no selected difference, next difference from cursor
1288 * position is selected.
1290 void CMergeEditView::OnNextdiff()
1292 CMergeDoc *pd = GetDocument();
1293 int cnt = pd->m_ptBuf[0]->GetLineCount();
1297 // Returns -1 if no diff selected
1299 int curDiff = pd->GetCurrentDiff();
1303 if (!IsDiffVisible(curDiff))
1305 // Selected difference not visible, select next from cursor
1306 int line = GetCursorPos().y;
1307 // Make sure we aren't in the first line of the diff
1309 if (!IsValidTextPosY(CPoint(0, line)))
1311 nextDiff = pd->m_diffList.NextSignificantDiffFromLine(line);
1315 // Find out if there is a following significant diff
1316 if (curDiff < pd->m_diffList.GetSize() - 1)
1318 nextDiff = pd->m_diffList.NextSignificantDiff(curDiff);
1324 // We don't have a selected difference,
1325 // but cursor can be inside inactive diff
1326 int line = GetCursorPos().y;
1327 if (!IsValidTextPosY(CPoint(0, line)))
1329 nextDiff = pd->m_diffList.NextSignificantDiffFromLine(line);
1332 int lastDiff = pd->m_diffList.LastSignificantDiff();
1333 if (nextDiff >= 0 && nextDiff <= lastDiff)
1334 SelectDiff(nextDiff, true, false);
1335 else if (CDirDoc *pDirDoc = pd->GetDirDoc())
1337 if (pDirDoc->MoveableToNextDiff())
1338 pDirDoc->MoveToNextDiff(pd);
1343 * @brief Update "Next diff" UI items
1345 void CMergeEditView::OnUpdateNextdiff(CCmdUI* pCmdUI)
1347 CMergeDoc *pd = GetDocument();
1348 const DIFFRANGE * dfi = pd->m_diffList.LastSignificantDiffRange();
1353 // There aren't any significant differences
1358 // Enable if the beginning of the last significant difference is after caret
1359 enabled = (GetCursorPos().y < (long)dfi->dbegin);
1362 if (!enabled && pd->GetDirDoc())
1363 enabled = pd->GetDirDoc()->MoveableToNextDiff();
1365 pCmdUI->Enable(enabled);
1369 * @brief Go to previous diff and select it.
1371 * Finds and selects previous difference. There are several cases:
1372 * - if there is selected difference, and that difference is visible
1373 * on screen, previous found difference is selected.
1374 * - if there is selected difference but it is not visible, previous
1375 * difference from cursor position is selected. This is what user
1376 * expects to happen and is natural thing to do. Also reduces
1377 * needless scrolling.
1378 * - if there is no selected difference, previous difference from cursor
1379 * position is selected.
1381 void CMergeEditView::OnPrevdiff()
1383 CMergeDoc *pd = GetDocument();
1384 int cnt = pd->m_ptBuf[0]->GetLineCount();
1388 // GetCurrentDiff() returns -1 if no diff selected
1390 int curDiff = pd->GetCurrentDiff();
1394 if (!IsDiffVisible(curDiff))
1396 // Selected difference not visible, select previous from cursor
1397 int line = GetCursorPos().y;
1398 // Make sure we aren't in the last line of the diff
1400 if (!IsValidTextPosY(CPoint(0, line)))
1402 prevDiff = pd->m_diffList.PrevSignificantDiffFromLine(line);
1406 // Find out if there is a preceding significant diff
1409 prevDiff = pd->m_diffList.PrevSignificantDiff(curDiff);
1415 // We don't have a selected difference,
1416 // but cursor can be inside inactive diff
1417 int line = GetCursorPos().y;
1418 if (!IsValidTextPosY(CPoint(0, line)))
1420 prevDiff = pd->m_diffList.PrevSignificantDiffFromLine(line);
1423 int firstDiff = pd->m_diffList.FirstSignificantDiff();
1424 if (prevDiff >= 0 && prevDiff >= firstDiff)
1425 SelectDiff(prevDiff, true, false);
1426 else if (CDirDoc *pDirDoc = pd->GetDirDoc())
1428 if (pDirDoc->MoveableToPrevDiff())
1429 pDirDoc->MoveToPrevDiff(pd);
1434 * @brief Update "Previous diff" UI items
1436 void CMergeEditView::OnUpdatePrevdiff(CCmdUI* pCmdUI)
1438 CMergeDoc *pd = GetDocument();
1439 const DIFFRANGE * dfi = pd->m_diffList.FirstSignificantDiffRange();
1444 // There aren't any significant differences
1449 // Enable if the end of the first significant difference is before caret
1450 enabled = (GetCursorPos().y > (long)dfi->dend);
1453 if (!enabled && pd->GetDirDoc())
1454 enabled = pd->GetDirDoc()->MoveableToPrevDiff();
1456 pCmdUI->Enable(enabled);
1459 void CMergeEditView::OnNextConflict()
1461 OnNext3wayDiff(THREEWAYDIFFTYPE_CONFLICT);
1465 * @brief Update "Next Conflict" UI items
1467 void CMergeEditView::OnUpdateNextConflict(CCmdUI* pCmdUI)
1469 OnUpdateNext3wayDiff(pCmdUI, THREEWAYDIFFTYPE_CONFLICT);
1472 void CMergeEditView::OnPrevConflict()
1474 OnPrev3wayDiff(THREEWAYDIFFTYPE_CONFLICT);
1478 * @brief Update "Prev Conflict" UI items
1480 void CMergeEditView::OnUpdatePrevConflict(CCmdUI* pCmdUI)
1482 OnUpdatePrev3wayDiff(pCmdUI, THREEWAYDIFFTYPE_CONFLICT);
1486 * @brief Go to next 3-way diff and select it.
1488 void CMergeEditView::OnNext3wayDiff(int nDiffType)
1490 CMergeDoc *pd = GetDocument();
1491 int cnt = pd->m_ptBuf[0]->GetLineCount();
1495 // Returns -1 if no diff selected
1496 int curDiff = pd->GetCurrentDiff();
1500 int nextDiff = curDiff;
1501 if (!IsDiffVisible(curDiff))
1503 // Selected difference not visible, select next from cursor
1504 int line = GetCursorPos().y;
1505 // Make sure we aren't in the first line of the diff
1507 if (!IsValidTextPosY(CPoint(0, line)))
1509 nextDiff = pd->m_diffList.NextSignificant3wayDiffFromLine(line, nDiffType);
1513 // Find out if there is a following significant diff
1514 if (curDiff < pd->m_diffList.GetSize() - 1)
1516 nextDiff = pd->m_diffList.NextSignificant3wayDiff(curDiff, nDiffType);
1522 // nextDiff is the next one if there is one, else it is the one we're on
1523 SelectDiff(nextDiff, true, false);
1527 // We don't have a selected difference,
1528 // but cursor can be inside inactive diff
1529 int line = GetCursorPos().y;
1530 if (!IsValidTextPosY(CPoint(0, line)))
1532 curDiff = pd->m_diffList.NextSignificant3wayDiffFromLine(line, nDiffType);
1534 SelectDiff(curDiff, true, false);
1539 * @brief Update "Next 3-way diff" UI items
1541 void CMergeEditView::OnUpdateNext3wayDiff(CCmdUI* pCmdUI, int nDiffType)
1543 CMergeDoc *pd = GetDocument();
1545 if (pd->m_nBuffers < 3)
1547 pCmdUI->Enable(false);
1551 const DIFFRANGE * dfi = pd->m_diffList.LastSignificant3wayDiffRange(nDiffType);
1555 // There aren't any significant differences
1556 pCmdUI->Enable(false);
1560 // Enable if the beginning of the last significant difference is after caret
1561 CPoint pos = GetCursorPos();
1562 pCmdUI->Enable(pos.y < (long)dfi->dbegin);
1567 * @brief Go to previous 3-way diff and select it.
1569 void CMergeEditView::OnPrev3wayDiff(int nDiffType)
1571 CMergeDoc *pd = GetDocument();
1573 int cnt = pd->m_ptBuf[0]->GetLineCount();
1577 // GetCurrentDiff() returns -1 if no diff selected
1578 int curDiff = pd->GetCurrentDiff();
1582 int prevDiff = curDiff;
1583 if (!IsDiffVisible(curDiff))
1585 // Selected difference not visible, select previous from cursor
1586 int line = GetCursorPos().y;
1587 // Make sure we aren't in the last line of the diff
1589 if (!IsValidTextPosY(CPoint(0, line)))
1591 prevDiff = pd->m_diffList.PrevSignificant3wayDiffFromLine(line, nDiffType);
1595 // Find out if there is a preceding significant diff
1598 prevDiff = pd->m_diffList.PrevSignificant3wayDiff(curDiff, nDiffType);
1604 // prevDiff is the preceding one if there is one, else it is the one we're on
1605 SelectDiff(prevDiff, true, false);
1609 // We don't have a selected difference,
1610 // but cursor can be inside inactive diff
1611 int line = GetCursorPos().y;
1612 if (!IsValidTextPosY(CPoint(0, line)))
1614 curDiff = pd->m_diffList.PrevSignificant3wayDiffFromLine(line, nDiffType);
1616 SelectDiff(curDiff, true, false);
1621 * @brief Update "Previous diff X and Y" UI items
1623 void CMergeEditView::OnUpdatePrev3wayDiff(CCmdUI* pCmdUI, int nDiffType)
1625 CMergeDoc *pd = GetDocument();
1627 if (pd->m_nBuffers < 3)
1629 pCmdUI->Enable(false);
1633 const DIFFRANGE * dfi = pd->m_diffList.FirstSignificant3wayDiffRange(nDiffType);
1637 // There aren't any significant differences
1638 pCmdUI->Enable(false);
1642 // Enable if the end of the first significant difference is before caret
1643 CPoint pos = GetCursorPos();
1644 pCmdUI->Enable(pos.y > (long)dfi->dend);
1648 void CMergeEditView::OnNextdiffLM()
1650 OnNext3wayDiff(THREEWAYDIFFTYPE_LEFTMIDDLE);
1653 void CMergeEditView::OnUpdateNextdiffLM(CCmdUI* pCmdUI)
1655 OnUpdateNext3wayDiff(pCmdUI, THREEWAYDIFFTYPE_LEFTMIDDLE);
1658 void CMergeEditView::OnNextdiffLR()
1660 OnNext3wayDiff(THREEWAYDIFFTYPE_LEFTRIGHT);
1663 void CMergeEditView::OnUpdateNextdiffLR(CCmdUI* pCmdUI)
1665 OnUpdateNext3wayDiff(pCmdUI, THREEWAYDIFFTYPE_LEFTRIGHT);
1668 void CMergeEditView::OnNextdiffMR()
1670 OnNext3wayDiff(THREEWAYDIFFTYPE_MIDDLERIGHT);
1673 void CMergeEditView::OnUpdateNextdiffMR(CCmdUI* pCmdUI)
1675 OnUpdateNext3wayDiff(pCmdUI, THREEWAYDIFFTYPE_MIDDLERIGHT);
1678 void CMergeEditView::OnNextdiffLO()
1680 OnNext3wayDiff(THREEWAYDIFFTYPE_LEFTONLY);
1683 void CMergeEditView::OnUpdateNextdiffLO(CCmdUI* pCmdUI)
1685 OnUpdateNext3wayDiff(pCmdUI, THREEWAYDIFFTYPE_LEFTONLY);
1688 void CMergeEditView::OnNextdiffMO()
1690 OnNext3wayDiff(THREEWAYDIFFTYPE_MIDDLEONLY);
1693 void CMergeEditView::OnUpdateNextdiffMO(CCmdUI* pCmdUI)
1695 OnUpdateNext3wayDiff(pCmdUI, THREEWAYDIFFTYPE_MIDDLEONLY);
1698 void CMergeEditView::OnNextdiffRO()
1700 OnNext3wayDiff(THREEWAYDIFFTYPE_RIGHTONLY);
1703 void CMergeEditView::OnUpdateNextdiffRO(CCmdUI* pCmdUI)
1705 OnUpdateNext3wayDiff(pCmdUI, THREEWAYDIFFTYPE_RIGHTONLY);
1708 void CMergeEditView::OnPrevdiffLM()
1710 OnPrev3wayDiff(THREEWAYDIFFTYPE_LEFTMIDDLE);
1713 void CMergeEditView::OnUpdatePrevdiffLM(CCmdUI* pCmdUI)
1715 OnUpdatePrev3wayDiff(pCmdUI, THREEWAYDIFFTYPE_LEFTMIDDLE);
1718 void CMergeEditView::OnPrevdiffLR()
1720 OnPrev3wayDiff(THREEWAYDIFFTYPE_LEFTRIGHT);
1723 void CMergeEditView::OnUpdatePrevdiffLR(CCmdUI* pCmdUI)
1725 OnUpdatePrev3wayDiff(pCmdUI, THREEWAYDIFFTYPE_LEFTRIGHT);
1728 void CMergeEditView::OnPrevdiffMR()
1730 OnPrev3wayDiff(THREEWAYDIFFTYPE_MIDDLERIGHT);
1733 void CMergeEditView::OnUpdatePrevdiffMR(CCmdUI* pCmdUI)
1735 OnUpdatePrev3wayDiff(pCmdUI, THREEWAYDIFFTYPE_MIDDLERIGHT);
1738 void CMergeEditView::OnPrevdiffLO()
1740 OnPrev3wayDiff(THREEWAYDIFFTYPE_LEFTONLY);
1743 void CMergeEditView::OnUpdatePrevdiffLO(CCmdUI* pCmdUI)
1745 OnUpdatePrev3wayDiff(pCmdUI, THREEWAYDIFFTYPE_LEFTONLY);
1748 void CMergeEditView::OnPrevdiffMO()
1750 OnPrev3wayDiff(THREEWAYDIFFTYPE_MIDDLEONLY);
1753 void CMergeEditView::OnUpdatePrevdiffMO(CCmdUI* pCmdUI)
1755 OnUpdatePrev3wayDiff(pCmdUI, THREEWAYDIFFTYPE_MIDDLEONLY);
1758 void CMergeEditView::OnPrevdiffRO()
1760 OnPrev3wayDiff(THREEWAYDIFFTYPE_RIGHTONLY);
1763 void CMergeEditView::OnUpdatePrevdiffRO(CCmdUI* pCmdUI)
1765 OnUpdatePrev3wayDiff(pCmdUI, THREEWAYDIFFTYPE_RIGHTONLY);
1769 * @brief Clear selection
1771 void CMergeEditView::SelectNone()
1773 SetSelection (GetCursorPos(), GetCursorPos());
1778 * @brief Check if line is inside currently selected diff
1779 * @param [in] nLine 0-based linenumber in view
1780 * @sa CMergeDoc::GetCurrentDiff()
1781 * @sa CMergeDoc::LineInDiff()
1783 bool CMergeEditView::IsLineInCurrentDiff(int nLine) const
1785 // Check validity of nLine
1788 _RPTF1(_CRT_ERROR, "Linenumber is negative (%d)!", nLine);
1789 int nLineCount = LocateTextBuffer()->GetLineCount();
1790 if (nLine >= nLineCount)
1791 _RPTF2(_CRT_ERROR, "Linenumber > linecount (%d>%d)!", nLine, nLineCount);
1794 const CMergeDoc *pd = GetDocument();
1795 int curDiff = pd->GetCurrentDiff();
1798 return pd->m_diffList.LineInDiff(nLine, curDiff);
1802 * @brief Called when mouse left-button double-clicked
1804 * Double-clicking mouse inside diff selects that diff
1806 void CMergeEditView::OnLButtonDblClk(UINT nFlags, CPoint point)
1808 CMergeDoc *pd = GetDocument();
1809 CPoint pos = GetCursorPos();
1811 int diff = pd->m_diffList.LineToDiff(pos.y);
1812 if (diff != -1 && pd->m_diffList.IsDiffSignificant(diff))
1813 SelectDiff(diff, false, false);
1815 CCrystalEditViewEx::OnLButtonDblClk(nFlags, point);
1819 * @brief Called when mouse left button is released.
1821 * If button is released outside diffs, current diff
1824 void CMergeEditView::OnLButtonUp(UINT nFlags, CPoint point)
1826 CCrystalEditViewEx::OnLButtonUp(nFlags, point);
1827 DeselectDiffIfCursorNotInCurrentDiff();
1831 * @brief Called when mouse right button is pressed.
1833 * If right button is pressed outside diffs, current diff
1836 void CMergeEditView::OnRButtonDown(UINT nFlags, CPoint point)
1838 CCrystalEditViewEx::OnRButtonDown(nFlags, point);
1839 DeselectDiffIfCursorNotInCurrentDiff();
1842 void CMergeEditView::OnX2Y(int srcPane, int dstPane)
1844 // Check that right side is not readonly
1845 if (IsReadOnly(dstPane))
1848 CMergeDoc *pDoc = GetDocument();
1849 int currentDiff = pDoc->GetCurrentDiff();
1851 if (currentDiff == -1)
1854 // If cursor is inside diff get number of that diff
1855 if (m_bCurrentLineIsDiff)
1857 CPoint pt = GetCursorPos();
1858 currentDiff = pDoc->m_diffList.LineToDiff(pt.y);
1862 CPoint ptStart, ptEnd;
1863 GetSelection(ptStart, ptEnd);
1864 if (IsSelection() || pDoc->EqualCurrentWordDiff(srcPane, ptStart, ptEnd))
1866 if (!m_bRectangularSelection)
1868 int firstDiff, lastDiff, firstWordDiff, lastWordDiff;
1869 GetFullySelectedDiffs(firstDiff, lastDiff, firstWordDiff, lastWordDiff);
1870 if (firstDiff != -1 && lastDiff != -1)
1872 CWaitCursor waitstatus;
1873 pDoc->CopyMultipleList(srcPane, dstPane, firstDiff, lastDiff, firstWordDiff, lastWordDiff);
1878 CWaitCursor waitstatus;
1879 auto wordDiffs = GetColumnSelectedWordDiffIndice();
1881 std::for_each(wordDiffs.rbegin(), wordDiffs.rend(), [&](auto& it) {
1882 pDoc->WordListCopy(srcPane, dstPane, it.first, it.second[0], it.second[it.second.size() - 1], &it.second, i != 0, i == 0);
1887 else if (currentDiff != -1 && pDoc->m_diffList.IsDiffSignificant(currentDiff))
1889 CWaitCursor waitstatus;
1890 pDoc->ListCopy(srcPane, dstPane, currentDiff);
1894 void CMergeEditView::OnUpdateX2Y(int dstPane, CCmdUI* pCmdUI)
1896 // Check that right side is not readonly
1897 if (!IsReadOnly(dstPane))
1899 // If one or more diffs inside selection OR
1900 // there is an active diff OR
1901 // cursor is inside diff
1902 CPoint ptStart, ptEnd;
1903 GetSelection(ptStart, ptEnd);
1904 if (IsSelection() || GetDocument()->EqualCurrentWordDiff(m_nThisPane, ptStart, ptEnd))
1906 if (m_bCurrentLineIsDiff || (m_pTextBuffer->GetLineFlags(m_ptSelStart.y) & LF_NONTRIVIAL_DIFF) != 0)
1908 pCmdUI->Enable(true);
1912 int firstDiff, lastDiff;
1913 GetFullySelectedDiffs(firstDiff, lastDiff);
1915 pCmdUI->Enable(firstDiff != -1 && lastDiff != -1 && (lastDiff >= firstDiff));
1920 const int currDiff = GetDocument()->GetCurrentDiff();
1921 pCmdUI->Enable(m_bCurrentLineIsDiff || (currDiff != -1 && GetDocument()->m_diffList.IsDiffSignificant(currDiff)));
1925 pCmdUI->Enable(false);
1929 * @brief Copy diff from left pane to right pane
1931 * Difference is copied from left to right when
1932 * - difference is selected
1933 * - difference is inside selection (allows merging multiple differences).
1934 * - cursor is inside diff
1936 * If there is selected diff outside selection, we copy selected
1939 void CMergeEditView::OnL2r()
1941 int dstPane = (m_nThisPane < GetDocument()->m_nBuffers - 1) ? m_nThisPane + 1 : GetDocument()->m_nBuffers - 1;
1942 int srcPane = dstPane - 1;
1943 OnX2Y(srcPane, dstPane);
1947 * @brief Called when "Copy to left" item is updated
1949 void CMergeEditView::OnUpdateL2r(CCmdUI* pCmdUI)
1951 OnUpdateX2Y(m_nThisPane < GetDocument()->m_nBuffers - 1 ? m_nThisPane + 1 : GetDocument()->m_nBuffers - 1, pCmdUI);
1955 * @brief Copy diff from right pane to left pane
1957 * Difference is copied from left to right when
1958 * - difference is selected
1959 * - difference is inside selection (allows merging multiple differences).
1960 * - cursor is inside diff
1962 * If there is selected diff outside selection, we copy selected
1965 void CMergeEditView::OnR2l()
1967 int dstPane = (m_nThisPane > 0) ? m_nThisPane - 1 : 0;
1968 int srcPane = dstPane + 1;
1969 OnX2Y(srcPane, dstPane);
1973 * @brief Called when "Copy to right" item is updated
1975 void CMergeEditView::OnUpdateR2l(CCmdUI* pCmdUI)
1977 OnUpdateX2Y(m_nThisPane > 0 ? m_nThisPane - 1 : 0, pCmdUI);
1980 void CMergeEditView::OnCopyFromLeft()
1982 int dstPane = m_nThisPane;
1983 int srcPane = dstPane - 1;
1986 OnX2Y(srcPane, dstPane);
1989 void CMergeEditView::OnUpdateCopyFromLeft(CCmdUI* pCmdUI)
1991 int dstPane = m_nThisPane;
1992 int srcPane = dstPane - 1;
1994 pCmdUI->Enable(false);
1996 OnUpdateX2Y(dstPane, pCmdUI);
1999 void CMergeEditView::OnCopyFromRight()
2001 int dstPane = m_nThisPane;
2002 int srcPane = dstPane + 1;
2003 if (srcPane >= GetDocument()->m_nBuffers)
2005 OnX2Y(srcPane, dstPane);
2008 void CMergeEditView::OnUpdateCopyFromRight(CCmdUI* pCmdUI)
2010 int dstPane = m_nThisPane;
2011 int srcPane = dstPane + 1;
2012 if (srcPane >= GetDocument()->m_nBuffers)
2013 pCmdUI->Enable(false);
2015 OnUpdateX2Y(dstPane, pCmdUI);
2019 * @brief Copy all diffs from right pane to left pane
2021 void CMergeEditView::OnAllLeft()
2023 // Check that left side is not readonly
2024 int srcPane = m_nThisPane > 0 ? m_nThisPane : 1;
2025 int dstPane = m_nThisPane > 0 ? m_nThisPane - 1 : 0;
2026 if (IsReadOnly(dstPane))
2028 CWaitCursor waitstatus;
2030 GetDocument()->CopyAllList(srcPane, dstPane);
2034 * @brief Called when "Copy all to left" item is updated
2036 void CMergeEditView::OnUpdateAllLeft(CCmdUI* pCmdUI)
2038 // Check that left side is not readonly
2039 int dstPane = m_nThisPane > 0 ? m_nThisPane - 1 : 0;
2040 if (!IsReadOnly(dstPane))
2041 pCmdUI->Enable(GetDocument()->m_diffList.HasSignificantDiffs());
2043 pCmdUI->Enable(false);
2047 * @brief Copy all diffs from left pane to right pane
2049 void CMergeEditView::OnAllRight()
2051 // Check that right side is not readonly
2052 int srcPane = m_nThisPane < GetDocument()->m_nBuffers - 1 ? m_nThisPane : m_nThisPane - 1;
2053 int dstPane = m_nThisPane < GetDocument()->m_nBuffers - 1 ? m_nThisPane + 1 : GetDocument()->m_nBuffers - 1;
2054 if (IsReadOnly(dstPane))
2057 CWaitCursor waitstatus;
2059 GetDocument()->CopyAllList(srcPane, dstPane);
2063 * @brief Called when "Copy all to right" item is updated
2065 void CMergeEditView::OnUpdateAllRight(CCmdUI* pCmdUI)
2067 // Check that right side is not readonly
2068 int dstPane = m_nThisPane < GetDocument()->m_nBuffers - 1 ? m_nThisPane + 1 : GetDocument()->m_nBuffers - 1;
2069 if (!IsReadOnly(dstPane))
2070 pCmdUI->Enable(GetDocument()->m_diffList.HasSignificantDiffs());
2072 pCmdUI->Enable(false);
2076 * @brief Do Auto merge
2078 void CMergeEditView::OnAutoMerge()
2080 // Check current pane is not readonly
2081 if (GetDocument()->IsModified() || GetDocument()->GetAutoMerged() || !QueryEditable())
2084 CWaitCursor waitstatus;
2086 GetDocument()->DoAutoMerge(m_nThisPane);
2090 * @brief Called when "Auto Merge" item is updated
2092 void CMergeEditView::OnUpdateAutoMerge(CCmdUI* pCmdUI)
2094 pCmdUI->Enable(GetDocument()->m_nBuffers == 3 &&
2095 !GetDocument()->IsModified() &&
2096 !GetDocument()->GetAutoMerged() &&
2101 * @brief Add synchronization point
2103 void CMergeEditView::OnAddSyncPoint()
2105 GetDocument()->AddSyncPoint();
2109 * @brief Clear synchronization points
2111 void CMergeEditView::OnClearSyncPoints()
2113 GetDocument()->ClearSyncPoints();
2117 * @brief Called when "Clear Synchronization Points" item is updated
2119 void CMergeEditView::OnUpdateClearSyncPoints(CCmdUI* pCmdUI)
2121 pCmdUI->Enable(GetDocument()->HasSyncPoints());
2125 * @brief This function is called before other edit events.
2126 * @param [in] nAction Edit operation to do
2127 * @param [in] pszText Text to insert, delete etc
2128 * @sa CCrystalEditView::OnEditOperation()
2129 * @todo More edit-events for rescan delaying?
2131 void CMergeEditView::OnEditOperation(int nAction, LPCTSTR pszText, size_t cchText)
2133 if (!QueryEditable())
2135 // We must not arrive here, and assert helps detect troubles
2140 CMergeDoc* pDoc = GetDocument();
2141 pDoc->SetEditedAfterRescan(m_nThisPane);
2143 // simple hook for multiplex undo operations
2144 // deleted by jtuc 2003-06-28
2145 // now AddUndoRecords does it (so we don't create entry for OnEditOperation with no Undo data in m_pTextBuffer)
2146 /*if(dynamic_cast<CMergeDoc::CDiffTextBuffer*>(m_pTextBuffer)->curUndoGroup())
2148 pDoc->undoTgt.erase(pDoc->curUndo, pDoc->undoTgt.end());
2149 pDoc->undoTgt.push_back(this);
2150 pDoc->curUndo = pDoc->undoTgt.end();
2153 // perform original function
2154 CCrystalEditViewEx::OnEditOperation(nAction, pszText, cchText);
2156 // augment with additional operations
2158 // Change header to inform about changed doc
2159 pDoc->UpdateHeaderPath(m_nThisPane);
2161 // If automatic rescan enabled, rescan after edit events
2162 if (m_bAutomaticRescan)
2164 // keep document up to date
2165 // (Re)start timer to rescan only when user edits text
2166 // If timer starting fails, rescan immediately
2167 if (nAction == CE_ACTION_TYPING ||
2168 nAction == CE_ACTION_REPLACE ||
2169 nAction == CE_ACTION_BACKSPACE ||
2170 nAction == CE_ACTION_INDENT ||
2171 nAction == CE_ACTION_PASTE ||
2172 nAction == CE_ACTION_DELSEL ||
2173 nAction == CE_ACTION_DELETE ||
2174 nAction == CE_ACTION_CUT)
2176 if (!SetTimer(IDT_RESCAN, RESCAN_TIMEOUT, nullptr))
2177 pDoc->FlushAndRescan();
2180 pDoc->FlushAndRescan();
2186 // Update other pane for sync line.
2187 for (int nPane = 0; nPane < pDoc->m_nBuffers; nPane++)
2189 if (nPane == m_nThisPane)
2191 CCrystalEditView *pView = GetGroupView(nPane);
2192 if (pView != nullptr)
2193 pView->Invalidate();
2200 * @brief Redo last action
2202 void CMergeEditView::OnEditRedo()
2204 CWaitCursor waitstatus;
2205 CMergeDoc* pDoc = GetDocument();
2206 CMergeEditView *tgt = pDoc->GetView(m_nThisGroup, *(pDoc->curUndo));
2209 if (!QueryEditable())
2212 GetParentFrame()->SetActiveView(this, true);
2213 if(CCrystalEditViewEx::DoEditRedo())
2216 pDoc->UpdateHeaderPath(m_nThisPane);
2217 pDoc->FlushAndRescan();
2222 tgt->SendMessage(WM_COMMAND, ID_EDIT_REDO);
2227 * @brief Called when "Redo" item is updated
2229 void CMergeEditView::OnUpdateEditRedo(CCmdUI* pCmdUI)
2231 CMergeDoc* pDoc = GetDocument();
2232 if (pDoc->curUndo!=pDoc->undoTgt.end())
2234 CMergeEditView *tgt = pDoc->GetView(m_nThisGroup, *(pDoc->curUndo));
2235 pCmdUI->Enable( !IsReadOnly(tgt->m_nThisPane));
2238 pCmdUI->Enable(false);
2241 void CMergeEditView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
2243 CCrystalEditViewEx::OnUpdate(pSender, lHint, pHint);
2247 * @brief Scrolls to current diff and/or selects diff text
2248 * @param [in] bScroll If true scroll diff to view
2249 * @param [in] bSelectText If true select diff text
2250 * @note If bScroll and bSelectText are false, this does nothing!
2251 * @todo This shouldn't be called when no diff is selected, so
2252 * somebody could try to ASSERT(nDiff > -1)...
2254 void CMergeEditView::ShowDiff(bool bScroll, bool bSelectText)
2256 CMergeDoc *pd = GetDocument();
2257 const int nDiff = pd->GetCurrentDiff();
2259 // Try to trap some errors
2260 if (nDiff >= pd->m_diffList.GetSize())
2261 _RPTF2(_CRT_ERROR, "Selected diff > diffcount (%d > %d)!",
2262 nDiff, pd->m_diffList.GetSize());
2264 if (nDiff >= 0 && nDiff < pd->m_diffList.GetSize())
2266 CPoint ptStart, ptEnd;
2268 pd->m_diffList.GetDiff(nDiff, curDiff);
2271 ptStart.y = curDiff.dbegin;
2273 ptEnd.y = curDiff.dend;
2275 if (bScroll && !m_bDetailView)
2277 if (!IsDiffVisible(curDiff, CONTEXT_LINES_BELOW))
2279 // Difference is not visible, scroll it so that max amount of
2280 // scrolling is done while keeping the diff in screen. So if
2281 // scrolling is downwards, scroll the diff to as up in screen
2282 // as possible. This usually brings next diff to the screen
2283 // and we don't need to scroll into it.
2284 int nLine = GetSubLineIndex(ptStart.y);
2285 if (nLine > CONTEXT_LINES_ABOVE)
2287 nLine -= CONTEXT_LINES_ABOVE;
2289 GetGroupView(m_nThisPane)->ScrollToSubLine(nLine);
2290 for (int nPane = 0; nPane < pd->m_nBuffers; nPane++)
2292 if (nPane != m_nThisPane)
2293 GetGroupView(nPane)->ScrollToSubLine(nLine);
2296 GetGroupView(m_nThisPane)->SetCursorPos(ptStart);
2297 GetGroupView(m_nThisPane)->SetAnchor(ptStart);
2298 GetGroupView(m_nThisPane)->SetSelection(ptStart, ptStart);
2299 for (int nPane = 0; nPane < pd->m_nBuffers; nPane++)
2301 if (nPane != m_nThisPane)
2303 GetGroupView(nPane)->SetCursorPos(ptStart);
2304 GetGroupView(nPane)->SetAnchor(ptStart);
2305 GetGroupView(nPane)->SetSelection(ptStart, ptStart);
2312 ptEnd.x = GetLineLength(ptEnd.y);
2313 SetSelection(ptStart, ptEnd);
2322 void CMergeEditView::OnTimer(UINT_PTR nIDEvent)
2324 // Maybe we want theApp::OnIdle to proceed before processing a timer message
2325 // ...but for this the queue must be empty
2326 // The timer message is a low priority message but the queue is maybe not yet empty
2327 // So we set a flag, wait for OnIdle to proceed, then come back here...
2328 // We come back here with a IDLE_TIMER OnTimer message (send with SendMessage
2329 // not with SetTimer so there is no delay)
2331 // IDT_RESCAN was posted because the app wanted to do a flushAndRescan with some delay
2333 // IDLE_TIMER is the false timer used to come back here after OnIdle
2334 // fTimerWaitingForIdle is a bool to store the commands waiting for idle
2335 // (one normal timer = one flag = one command)
2337 if (nIDEvent == IDT_RESCAN)
2339 KillTimer(IDT_RESCAN);
2340 fTimerWaitingForIdle |= FLAG_RESCAN_WAITS_FOR_IDLE;
2341 // notify the app to come back after OnIdle
2342 theApp.SetNeedIdleTimer();
2345 if (nIDEvent == IDLE_TIMER)
2347 // not a real timer, just come back after OnIdle
2348 // look to flags to know what to do
2349 if (fTimerWaitingForIdle & FLAG_RESCAN_WAITS_FOR_IDLE)
2350 GetDocument()->RescanIfNeeded(RESCAN_TIMEOUT/1000);
2351 fTimerWaitingForIdle = 0;
2354 CCrystalEditViewEx::OnTimer(nIDEvent);
2358 * @brief Returns if buffer is read-only
2359 * @note This has no any relation to file being read-only!
2361 bool CMergeEditView::IsReadOnly(int pane) const
2363 return m_bDetailView ? true : (GetDocument()->m_ptBuf[pane]->GetReadOnly() != false);
2367 * @brief Called when "Save left (as...)" item is updated
2369 void CMergeEditView::OnUpdateFileSaveLeft(CCmdUI* pCmdUI)
2371 CMergeDoc *pd = GetDocument();
2372 pCmdUI->Enable(!IsReadOnly(0) && pd->m_ptBuf[0]->IsModified());
2376 * @brief Called when "Save middle (as...)" item is updated
2378 void CMergeEditView::OnUpdateFileSaveMiddle(CCmdUI* pCmdUI)
2380 CMergeDoc *pd = GetDocument();
2381 pCmdUI->Enable(pd->m_nBuffers == 3 && !IsReadOnly(1) && pd->m_ptBuf[1]->IsModified());
2385 * @brief Called when "Save right (as...)" item is updated
2387 void CMergeEditView::OnUpdateFileSaveRight(CCmdUI* pCmdUI)
2389 CMergeDoc *pd = GetDocument();
2390 pCmdUI->Enable(!IsReadOnly(pd->m_nBuffers - 1) && pd->m_ptBuf[pd->m_nBuffers - 1]->IsModified());
2394 * @brief Refresh display using text-buffers
2395 * @note This DOES NOT reload files!
2397 void CMergeEditView::OnRefresh()
2399 CMergeDoc *pd = GetDocument();
2400 ASSERT(pd != nullptr);
2401 pd->FlushAndRescan(true);
2405 * @brief Handle some keys when in merging mode
2407 bool CMergeEditView::MergeModeKeyDown(MSG* pMsg)
2409 bool bHandled = false;
2411 // Allow default text selection when SHIFT pressed
2412 if (::GetAsyncKeyState(VK_SHIFT))
2415 // Allow default editor functions when CTRL pressed
2416 if (::GetAsyncKeyState(VK_CONTROL))
2419 // If we are in merging mode (merge with cursor keys)
2420 // handle some keys here
2421 switch (pMsg->wParam)
2448 * @brief Called before messages are translated.
2450 * Checks if ESC key was pressed, saves and closes doc.
2451 * Also if in merge mode traps cursor keys.
2453 BOOL CMergeEditView::PreTranslateMessage(MSG* pMsg)
2455 if (pMsg->message == WM_KEYDOWN)
2457 // If we are in merging mode (merge with cursor keys)
2458 // handle some keys here
2459 if (theApp.GetMergingMode())
2461 bool bHandled = MergeModeKeyDown(pMsg);
2466 // Close window if user has allowed it from options
2467 if (pMsg->wParam == VK_ESCAPE)
2469 int nCloseWithEsc = GetOptionsMgr()->GetInt(OPT_CLOSE_WITH_ESC);
2470 if (nCloseWithEsc != 0)
2471 GetParentFrame()->PostMessage(WM_CLOSE, 0, 0);
2476 return CCrystalEditViewEx::PreTranslateMessage(pMsg);
2480 * @brief Called when "Save" item is updated
2482 void CMergeEditView::OnUpdateFileSave(CCmdUI* pCmdUI)
2484 CMergeDoc *pd = GetDocument();
2486 bool bModified = false;
2487 for (int nPane = 0; nPane < pd->m_nBuffers; nPane++)
2489 if (pd->m_ptBuf[nPane]->IsModified())
2492 pCmdUI->Enable(bModified);
2496 * @brief Enable/disable left buffer read-only
2498 void CMergeEditView::OnLeftReadOnly()
2500 CMergeDoc *pd = GetDocument();
2501 bool bReadOnly = pd->m_ptBuf[0]->GetReadOnly();
2502 pd->m_ptBuf[0]->SetReadOnly(!bReadOnly);
2506 * @brief Called when "Left read-only" item is updated
2508 void CMergeEditView::OnUpdateLeftReadOnly(CCmdUI* pCmdUI)
2510 CMergeDoc *pd = GetDocument();
2511 bool bReadOnly = pd->m_ptBuf[0]->GetReadOnly();
2512 pCmdUI->Enable(true);
2513 pCmdUI->SetCheck(bReadOnly);
2517 * @brief Enable/disable middle buffer read-only
2519 void CMergeEditView::OnMiddleReadOnly()
2521 CMergeDoc *pd = GetDocument();
2522 if (pd->m_nBuffers == 3)
2524 bool bReadOnly = pd->m_ptBuf[1]->GetReadOnly();
2525 pd->m_ptBuf[1]->SetReadOnly(!bReadOnly);
2530 * @brief Called when "Middle read-only" item is updated
2532 void CMergeEditView::OnUpdateMiddleReadOnly(CCmdUI* pCmdUI)
2534 CMergeDoc *pd = GetDocument();
2535 if (pd->m_nBuffers < 3)
2537 pCmdUI->Enable(false);
2541 bool bReadOnly = pd->m_ptBuf[1]->GetReadOnly();
2542 pCmdUI->Enable(true);
2543 pCmdUI->SetCheck(bReadOnly);
2548 * @brief Enable/disable right buffer read-only
2550 void CMergeEditView::OnRightReadOnly()
2552 CMergeDoc *pd = GetDocument();
2553 bool bReadOnly = pd->m_ptBuf[pd->m_nBuffers - 1]->GetReadOnly();
2554 pd->m_ptBuf[pd->m_nBuffers - 1]->SetReadOnly(!bReadOnly);
2558 * @brief Called when "Left read-only" item is updated
2560 void CMergeEditView::OnUpdateRightReadOnly(CCmdUI* pCmdUI)
2562 CMergeDoc *pd = GetDocument();
2563 bool bReadOnly = pd->m_ptBuf[pd->m_nBuffers - 1]->GetReadOnly();
2564 pCmdUI->Enable(true);
2565 pCmdUI->SetCheck(bReadOnly);
2568 /// Store interface we use to display status line info
2569 void CMergeEditView::SetStatusInterface(IMergeEditStatus * piMergeEditStatus)
2571 ASSERT(m_piMergeEditStatus == nullptr);
2572 m_piMergeEditStatus = piMergeEditStatus;
2576 * @brief Update status bar contents.
2578 void CMergeEditView::UpdateStatusbar()
2584 * @brief Update statusbar info, Override from CCrystalTextView
2585 * @note we tab-expand column, but we don't tab-expand char count,
2586 * since we want to show how many chars there are and tab is just one
2587 * character although it expands to several spaces.
2589 void CMergeEditView::OnUpdateCaret()
2591 if (m_piMergeEditStatus == nullptr || !IsTextBufferInitialized())
2594 CPoint cursorPos = GetCursorPos();
2595 int nScreenLine = cursorPos.y;
2596 const int nRealLine = ComputeRealLine(nScreenLine);
2603 DWORD dwLineFlags = 0;
2605 dwLineFlags = m_pTextBuffer->GetLineFlags(nScreenLine);
2606 // Is this a ghost line ?
2607 if (dwLineFlags & LF_GHOST)
2609 // Ghost lines display eg "Line 12-13"
2610 sLine.Format(_T("%d-%d"), nRealLine, nRealLine+1);
2611 sEol = _T("hidden");
2615 // Regular lines display eg "Line 13 Characters: 25 EOL: CRLF"
2616 sLine.Format(_T("%d"), nRealLine+1);
2617 curChar = cursorPos.x + 1;
2618 chars = GetLineLength(nScreenLine);
2619 column = CalculateActualOffset(nScreenLine, cursorPos.x, true) + 1;
2620 columns = CalculateActualOffset(nScreenLine, chars, true) + 1;
2622 if (GetOptionsMgr()->GetBool(OPT_ALLOW_MIXED_EOL) ||
2623 GetDocument()->IsMixedEOL(m_nThisPane))
2625 sEol = GetTextBufferEol(nScreenLine);
2628 sEol = _T("hidden");
2630 m_piMergeEditStatus->SetLineInfo(sLine, column, columns,
2631 curChar, chars, sEol, GetDocument()->m_ptBuf[m_nThisPane]->getCodepage(), GetDocument()->m_ptBuf[m_nThisPane]->getHasBom());
2633 // Is cursor inside difference?
2634 if (dwLineFlags & LF_NONTRIVIAL_DIFF)
2635 m_bCurrentLineIsDiff = true;
2637 m_bCurrentLineIsDiff = false;
2639 CWnd* pWnd = GetFocus();
2640 if (!m_bDetailView || (pWnd && pWnd->m_hWnd == this->m_hWnd))
2641 UpdateLocationViewPosition(m_nTopSubLine, m_nTopSubLine + GetScreenLines());
2644 * @brief Select linedifference in the current line.
2646 * Select line difference in current line. Selection type
2647 * is choosed by highlight type.
2649 template<bool reversed>
2650 void CMergeEditView::OnSelectLineDiff()
2652 // Pass this to the document, to compare this file to other
2653 GetDocument()->Showlinediff(this, reversed);
2656 /// Enable select difference menuitem if current line is inside difference.
2657 void CMergeEditView::OnUpdateSelectLineDiff(CCmdUI* pCmdUI)
2659 pCmdUI->Enable(!GetDocument()->IsEditedAfterRescan());
2663 * @brief Enable/disable Replace-menuitem
2665 void CMergeEditView::OnUpdateEditReplace(CCmdUI* pCmdUI)
2667 CMergeDoc *pd = GetDocument();
2668 bool bReadOnly = pd->m_ptBuf[m_nThisPane]->GetReadOnly();
2670 pCmdUI->Enable(!bReadOnly);
2674 * @brief Update readonly statusbaritem
2676 void CMergeEditView::OnUpdateStatusRO(CCmdUI* pCmdUI)
2678 bool bRO = GetDocument()->m_ptBuf[pCmdUI->m_nID - ID_STATUS_PANE0FILE_RO]->GetReadOnly();
2679 pCmdUI->Enable(bRO);
2683 * @brief Create the dynamic submenu for scripts
2685 HMENU CMergeEditView::createScriptsSubmenu(HMENU hMenu)
2688 std::vector<String> functionNamesList = FileTransform::GetFreeFunctionsInScripts(L"EDITOR_SCRIPT");
2691 size_t i = GetMenuItemCount(hMenu);
2693 DeleteMenu(hMenu, 0, MF_BYPOSITION);
2695 if (functionNamesList.size() == 0)
2697 // no script : create a <empty> entry
2698 AppendMenu(hMenu, MF_STRING, ID_NO_EDIT_SCRIPTS, _("< Empty >").c_str());
2702 // or fill in the submenu with the scripts names
2703 int ID = ID_SCRIPT_FIRST; // first ID in menu
2704 for (i = 0 ; i < functionNamesList.size() ; i++, ID++)
2705 AppendMenu(hMenu, MF_STRING, ID, functionNamesList[i].c_str());
2707 functionNamesList.clear();
2710 if (!plugin::IsWindowsScriptThere())
2711 AppendMenu(hMenu, MF_STRING, ID_NO_SCT_SCRIPTS, _("WSH not found - .sct scripts disabled").c_str());
2717 * @brief Create the dynamic submenu for prediffers
2719 * @note The plugins are grouped in (suggested) and (not suggested)
2720 * The IDs follow the order of GetAvailableScripts
2722 * suggested 0 ID_1ST + 0
2723 * suggested 1 ID_1ST + 2
2724 * suggested 2 ID_1ST + 5
2725 * not suggested 0 ID_1ST + 1
2726 * not suggested 1 ID_1ST + 3
2727 * not suggested 2 ID_1ST + 4
2729 HMENU CMergeEditView::createPrediffersSubmenu(HMENU hMenu)
2732 int i = GetMenuItemCount(hMenu);
2734 DeleteMenu(hMenu, 0, MF_BYPOSITION);
2736 CMergeDoc *pd = GetDocument();
2737 ASSERT(pd != nullptr);
2740 AppendMenu(hMenu, MF_STRING, ID_NO_PREDIFFER, _("No prediffer (normal)").c_str());
2742 // get the scriptlet files
2743 PluginArray * piScriptArray =
2744 CAllThreadsScripts::GetActiveSet()->GetAvailableScripts(L"FILE_PREDIFF");
2745 PluginArray * piScriptArray2 =
2746 CAllThreadsScripts::GetActiveSet()->GetAvailableScripts(L"BUFFER_PREDIFF");
2748 // build the menu : first part, suggested plugins
2750 AppendMenu(hMenu, MF_SEPARATOR, 0, nullptr);
2751 AppendMenu(hMenu, MF_STRING, ID_SUGGESTED_PLUGINS, _("Suggested plugins").c_str());
2753 int ID = ID_PREDIFFERS_FIRST; // first ID in menu
2755 for (iScript = 0 ; iScript < piScriptArray->size() ; iScript++, ID ++)
2757 const PluginInfoPtr & plugin = piScriptArray->at(iScript);
2758 if (plugin->m_disabled || !plugin->TestAgainstRegList(pd->m_strBothFilenames))
2761 AppendMenu(hMenu, MF_STRING, ID, plugin->m_name.c_str());
2763 for (iScript = 0 ; iScript < piScriptArray2->size() ; iScript++, ID ++)
2765 const PluginInfoPtr & plugin = piScriptArray2->at(iScript);
2766 if (plugin->m_disabled || !plugin->TestAgainstRegList(pd->m_strBothFilenames))
2769 AppendMenu(hMenu, MF_STRING, ID, plugin->m_name.c_str());
2772 // build the menu : second part, others plugins
2774 AppendMenu(hMenu, MF_SEPARATOR, 0, nullptr);
2775 AppendMenu(hMenu, MF_STRING, ID_NOT_SUGGESTED_PLUGINS, _("Other plugins").c_str());
2777 ID = ID_PREDIFFERS_FIRST; // first ID in menu
2778 for (iScript = 0 ; iScript < piScriptArray->size() ; iScript++, ID ++)
2780 const PluginInfoPtr & plugin = piScriptArray->at(iScript);
2781 if (plugin->m_disabled || plugin->TestAgainstRegList(pd->m_strBothFilenames) != false)
2784 AppendMenu(hMenu, MF_STRING, ID, plugin->m_name.c_str());
2786 for (iScript = 0 ; iScript < piScriptArray2->size() ; iScript++, ID ++)
2788 const PluginInfoPtr & plugin = piScriptArray2->at(iScript);
2789 if (plugin->m_disabled || plugin->TestAgainstRegList(pd->m_strBothFilenames) != false)
2792 AppendMenu(hMenu, MF_STRING, ID, plugin->m_name.c_str());
2795 // compute the m_CurrentPredifferID (to set the radio button)
2796 PrediffingInfo prediffer;
2797 pd->GetPrediffer(&prediffer);
2799 if (prediffer.m_PluginOrPredifferMode != PLUGIN_MANUAL)
2800 m_CurrentPredifferID = 0;
2801 else if (prediffer.m_PluginName.empty())
2802 m_CurrentPredifferID = ID_NO_PREDIFFER;
2805 ID = ID_PREDIFFERS_FIRST; // first ID in menu
2806 for (iScript = 0 ; iScript < piScriptArray->size() ; iScript++, ID ++)
2808 const PluginInfoPtr & plugin = piScriptArray->at(iScript);
2809 if (prediffer.m_PluginName == plugin->m_name)
2810 m_CurrentPredifferID = ID;
2813 for (iScript = 0 ; iScript < piScriptArray2->size() ; iScript++, ID ++)
2815 const PluginInfoPtr & plugin = piScriptArray2->at(iScript);
2816 if (prediffer.m_PluginName == plugin->m_name)
2817 m_CurrentPredifferID = ID;
2825 * @brief Offer a context menu built with scriptlet/ActiveX functions
2827 void CMergeEditView::OnContextMenu(CWnd* pWnd, CPoint point)
2829 // Create the menu and populate it with the available functions
2831 VERIFY(menu.LoadMenu(IDR_POPUP_MERGEVIEW));
2833 // Remove copying item copying from active side
2834 if (m_nThisPane == 0) // left?
2836 menu.RemoveMenu(ID_COPY_FROM_RIGHT, MF_BYCOMMAND);
2837 menu.RemoveMenu(ID_COPY_FROM_LEFT, MF_BYCOMMAND);
2839 if (m_nThisPane == GetDocument()->m_nBuffers - 1)
2841 menu.RemoveMenu(ID_COPY_FROM_LEFT, MF_BYCOMMAND);
2842 menu.RemoveMenu(ID_COPY_FROM_RIGHT, MF_BYCOMMAND);
2845 VERIFY(menu.LoadToolbar(IDR_MAINFRAME));
2846 theApp.TranslateMenu(menu.m_hMenu);
2848 BCMenu *pSub = static_cast<BCMenu *>(menu.GetSubMenu(0));
2849 ASSERT(pSub != nullptr);
2851 // Context menu opened using keyboard has no coordinates
2852 if (point.x == -1 && point.y == -1)
2855 GetClientRect(rect);
2856 ClientToScreen(rect);
2858 point = rect.TopLeft();
2862 pSub->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,
2863 point.x, point.y, AfxGetMainWnd());
2868 * @brief Update EOL mode in status bar
2870 void CMergeEditView::OnUpdateStatusEOL(CCmdUI* pCmdUI)
2872 GetGroupView(pCmdUI->m_nID - ID_STATUS_PANE0FILE_EOL)->OnUpdateIndicatorCRLF(pCmdUI);
2876 * @brief Change EOL mode and unify all the lines EOL to this new mode
2878 void CMergeEditView::OnConvertEolTo(UINT nID )
2880 CRLFSTYLE nStyle = CRLF_STYLE_AUTOMATIC;;
2884 nStyle = CRLF_STYLE_DOS;
2886 case ID_EOL_TO_UNIX:
2887 nStyle = CRLF_STYLE_UNIX;
2890 nStyle = CRLF_STYLE_MAC;
2894 _RPTF0(_CRT_ERROR, "Unhandled EOL type conversion!");
2897 m_pTextBuffer->SetCRLFMode(nStyle);
2899 // we don't need a derived applyEOLMode for ghost lines as they have no EOL char
2900 if (m_pTextBuffer->applyEOLMode())
2902 CMergeDoc *pd = GetDocument();
2903 ASSERT(pd != nullptr);
2904 pd->UpdateHeaderPath(m_nThisPane);
2905 pd->FlushAndRescan(true);
2910 * @brief allow convert to entries in file submenu
2912 void CMergeEditView::OnUpdateConvertEolTo(CCmdUI* pCmdUI)
2914 int nStyle = CRLF_STYLE_AUTOMATIC;
2915 switch (pCmdUI->m_nID)
2918 nStyle = CRLF_STYLE_DOS;
2920 case ID_EOL_TO_UNIX:
2921 nStyle = CRLF_STYLE_UNIX;
2924 nStyle = CRLF_STYLE_MAC;
2928 _RPTF0(_CRT_ERROR, "Missing menuitem handler for EOL convert menu!");
2932 if (GetOptionsMgr()->GetBool(OPT_ALLOW_MIXED_EOL) ||
2933 GetDocument()->IsMixedEOL(m_nThisPane) ||
2934 nStyle != m_pTextBuffer->GetCRLFMode())
2936 pCmdUI->SetRadio(false);
2938 // Don't allow selecting other EOL style for protected pane
2939 if (!QueryEditable())
2940 pCmdUI->Enable(false);
2943 pCmdUI->SetRadio(true);
2947 * @brief Copy diff from left to right and advance to next diff
2949 void CMergeEditView::OnL2RNext()
2952 if (IsCursorInDiff()) // for 3-way file compare
2958 * @brief Update "Copy right and advance" UI item
2960 void CMergeEditView::OnUpdateL2RNext(CCmdUI* pCmdUI)
2962 OnUpdateL2r(pCmdUI);
2966 * @brief Copy diff from right to left and advance to next diff
2968 void CMergeEditView::OnR2LNext()
2971 if (IsCursorInDiff()) // for 3-way file compare
2977 * @brief Update "Copy left and advance" UI item
2979 void CMergeEditView::OnUpdateR2LNext(CCmdUI* pCmdUI)
2981 OnUpdateR2l(pCmdUI);
2985 * @brief Change active pane in MergeView.
2986 * Changes active pane and makes sure cursor position is kept in
2987 * screen. Currently we put cursor in same line than in original
2988 * active pane but we could be smarter too? Maybe update cursor
2989 * only when it is not visible in new pane?
2991 void CMergeEditView::OnChangePane()
2993 CSplitterWnd *pSplitterWnd = GetParentSplitter(this, false);
2994 CMergeEditView *pWnd = static_cast<CMergeEditView*>(pSplitterWnd->GetActivePane());
2995 CMergeDoc *pDoc = GetDocument();
2996 bool bFound = false;
2997 CMergeEditView *pNextActiveView = nullptr;
2998 std::vector<CMergeEditView *> list = pDoc->GetViewList();
2999 list.insert(list.end(), list.begin(), list.end());
3000 for (auto& pView : list)
3002 if (bFound && pView->m_bDetailView == pWnd->m_bDetailView)
3004 pNextActiveView = pView;
3010 GetParentFrame()->SetActiveView(pNextActiveView);
3011 CPoint ptCursor = pWnd->GetCursorPos();
3013 if (ptCursor.y >= pNextActiveView->GetLineCount())
3014 ptCursor.y = pNextActiveView->GetLineCount() - 1;
3015 pNextActiveView->SetCursorPos(ptCursor);
3016 pNextActiveView->SetAnchor(ptCursor);
3017 pNextActiveView->SetSelection(ptCursor, ptCursor);
3021 * @brief Show "Go To" dialog and scroll views to line or diff.
3023 * Before dialog is opened, current line and file is determined
3025 * @note Conversions needed between apparent and real lines
3027 void CMergeEditView::OnWMGoto()
3030 CMergeDoc *pDoc = GetDocument();
3031 CPoint pos = GetCursorPos();
3035 nRealLine = pDoc->m_ptBuf[m_nThisPane]->ComputeRealLine(pos.y);
3036 int nLineCount = pDoc->m_ptBuf[m_nThisPane]->GetLineCount();
3037 nLastLine = pDoc->m_ptBuf[m_nThisPane]->ComputeRealLine(nLineCount - 1);
3039 // Set active file and current line selected in dialog
3040 dlg.m_strParam = strutils::to_str(nRealLine + 1);
3041 dlg.m_nFile = (pDoc->m_nBuffers < 3) ? (m_nThisPane == 1 ? 2 : 0) : m_nThisPane;
3042 dlg.m_nGotoWhat = 0;
3044 if (dlg.DoModal() == IDOK)
3046 CMergeDoc * pDoc1 = GetDocument();
3047 CMergeEditView * pCurrentView = nullptr;
3050 pCurrentView = GetGroupView(m_nThisPane);
3053 try { num = std::stoi(dlg.m_strParam) - 1; } catch(...) {}
3055 if (dlg.m_nGotoWhat == 0)
3057 int nRealLine1 = num;
3060 if (nRealLine1 > nLastLine)
3061 nRealLine1 = nLastLine;
3063 GotoLine(nRealLine1, true, (pDoc1->m_nBuffers < 3) ? (dlg.m_nFile == 2 ? 1 : 0) : dlg.m_nFile);
3070 if (diff >= pDoc1->m_diffList.GetSize())
3071 diff = pDoc1->m_diffList.GetSize();
3073 pCurrentView->SelectDiff(diff, true, false);
3078 void CMergeEditView::OnShellMenu()
3080 CFrameWnd *pFrame = GetTopLevelFrame();
3081 ASSERT(pFrame != nullptr);
3082 BOOL bAutoMenuEnableOld = pFrame->m_bAutoMenuEnable;
3083 pFrame->m_bAutoMenuEnable = FALSE;
3085 String path = GetDocument()->m_filePaths[m_nThisPane];
3086 std::unique_ptr<CShellContextMenu> pContextMenu(new CShellContextMenu(0x9000, 0x9FFF));
3087 pContextMenu->Initialize();
3088 pContextMenu->AddItem(paths::GetParentPath(path), paths::FindFileName(path));
3089 pContextMenu->RequeryShellContextMenu();
3091 ::GetCursorPos(&point);
3092 HWND hWnd = GetSafeHwnd();
3093 BOOL nCmd = TrackPopupMenu(pContextMenu->GetHMENU(), TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD, point.x, point.y, 0, hWnd, nullptr);
3095 pContextMenu->InvokeCommand(nCmd, hWnd);
3096 pContextMenu->ReleaseShellContextMenu();
3098 pFrame->m_bAutoMenuEnable = bAutoMenuEnableOld;
3101 void CMergeEditView::OnUpdateShellMenu(CCmdUI* pCmdUI)
3103 pCmdUI->Enable(!GetDocument()->m_filePaths[m_nThisPane].empty());
3107 * @brief Reload options.
3109 void CMergeEditView::RefreshOptions()
3111 RENDERING_MODE nRenderingMode = static_cast<RENDERING_MODE>(GetOptionsMgr()->GetInt(OPT_RENDERING_MODE));
3112 SetRenderingMode(nRenderingMode);
3114 m_bAutomaticRescan = GetOptionsMgr()->GetBool(OPT_AUTOMATIC_RESCAN);
3116 if (GetOptionsMgr()->GetInt(OPT_TAB_TYPE) == 0)
3117 SetInsertTabs(true);
3119 SetInsertTabs(false);
3121 SetSelectionMargin(GetOptionsMgr()->GetBool(OPT_VIEW_FILEMARGIN));
3123 if (!GetOptionsMgr()->GetBool(OPT_SYNTAX_HIGHLIGHT))
3124 SetTextType(CrystalLineParser::SRC_PLAIN);
3126 SetWordWrapping(GetOptionsMgr()->GetBool(OPT_WORDWRAP));
3127 SetViewLineNumbers(GetOptionsMgr()->GetBool(OPT_VIEW_LINENUMBERS));
3129 SetViewTabs(GetOptionsMgr()->GetBool(OPT_VIEW_WHITESPACE));
3130 SetViewEols(GetOptionsMgr()->GetBool(OPT_VIEW_EOL),
3131 GetOptionsMgr()->GetBool(OPT_ALLOW_MIXED_EOL) ||
3132 GetDocument()->IsMixedEOL(m_nThisPane));
3134 Options::DiffColors::Load(GetOptionsMgr(), m_cachedColors);
3137 void CMergeEditView::OnScripts(UINT nID )
3139 // text is CHAR if compiled without UNICODE, WCHAR with UNICODE
3140 String text = GetSelectedText();
3142 // transform the text with a script/ActiveX function, event=EDITOR_SCRIPT
3143 bool bChanged = FileTransform::Interactive(text, L"EDITOR_SCRIPT", nID - ID_SCRIPT_FIRST);
3145 // now replace the text
3146 ReplaceSelection(text.c_str(), text.length(), 0);
3150 * @brief Called when an editor script item is updated
3152 void CMergeEditView::OnUpdateNoEditScripts(CCmdUI* pCmdUI)
3154 // append the scripts submenu
3155 HMENU scriptsSubmenu = dynamic_cast<CMainFrame*>(AfxGetMainWnd())->GetScriptsSubmenu(AfxGetMainWnd()->GetMenu()->m_hMenu);
3156 if (scriptsSubmenu != nullptr)
3157 createScriptsSubmenu(scriptsSubmenu);
3159 pCmdUI->Enable(true);
3163 * @brief Called when an editor script item is updated
3165 void CMergeEditView::OnUpdatePrediffer(CCmdUI* pCmdUI)
3167 pCmdUI->Enable(true);
3169 CMergeDoc *pd = GetDocument();
3170 ASSERT(pd != nullptr);
3171 PrediffingInfo prediffer;
3172 pd->GetPrediffer(&prediffer);
3174 if (prediffer.m_PluginOrPredifferMode != PLUGIN_MANUAL)
3176 pCmdUI->SetRadio(false);
3180 // Detect when CDiffWrapper::RunFileDiff has canceled a buggy prediffer
3181 if (prediffer.m_PluginName.empty())
3182 m_CurrentPredifferID = ID_NO_PREDIFFER;
3184 pCmdUI->SetRadio(pCmdUI->m_nID == static_cast<UINT>(m_CurrentPredifferID));
3188 * @brief Update "Prediffer" menuitem
3190 void CMergeEditView::OnUpdateNoPrediffer(CCmdUI* pCmdUI)
3192 // recreate the sub menu (to fill the "selected prediffers")
3193 GetMainFrame()->UpdatePrediffersMenu();
3197 void CMergeEditView::OnNoPrediffer()
3199 OnPrediffer(ID_NO_PREDIFFER);
3202 * @brief Handler for all prediffer choices, including ID_PREDIFF_MANUAL, ID_PREDIFF_AUTO, ID_NO_PREDIFFER, & specific prediffers
3204 void CMergeEditView::OnPrediffer(UINT nID )
3206 CMergeDoc *pd = GetDocument();
3207 ASSERT(pd != nullptr);
3209 SetPredifferByMenu(nID);
3210 pd->FlushAndRescan(true);
3214 * @brief Handler for all prediffer choices.
3215 * Prediffer choises include ID_PREDIFF_MANUAL, ID_PREDIFF_AUTO,
3216 * ID_NO_PREDIFFER, & specific prediffers.
3218 void CMergeEditView::SetPredifferByMenu(UINT nID )
3220 CMergeDoc *pd = GetDocument();
3221 ASSERT(pd != nullptr);
3223 if (nID == ID_NO_PREDIFFER)
3225 m_CurrentPredifferID = nID;
3226 // All flags are set correctly during the construction
3227 PrediffingInfo *infoPrediffer = new PrediffingInfo;
3228 infoPrediffer->m_PluginOrPredifferMode = PLUGIN_MANUAL;
3229 infoPrediffer->m_PluginName.clear();
3230 pd->SetPrediffer(infoPrediffer);
3231 pd->FlushAndRescan(true);
3235 // get the scriptlet files
3236 PluginArray * piScriptArray =
3237 CAllThreadsScripts::GetActiveSet()->GetAvailableScripts(L"FILE_PREDIFF");
3238 PluginArray * piScriptArray2 =
3239 CAllThreadsScripts::GetActiveSet()->GetAvailableScripts(L"BUFFER_PREDIFF");
3241 // build a PrediffingInfo structure fom the ID
3242 PrediffingInfo prediffer;
3243 prediffer.m_PluginOrPredifferMode = PLUGIN_MANUAL;
3245 size_t pluginNumber = nID - ID_PREDIFFERS_FIRST;
3246 if (pluginNumber < piScriptArray->size())
3248 const PluginInfoPtr & plugin = piScriptArray->at(pluginNumber);
3249 prediffer.m_PluginName = plugin->m_name;
3253 pluginNumber -= piScriptArray->size();
3254 if (pluginNumber >= piScriptArray2->size())
3256 const PluginInfoPtr & plugin = piScriptArray2->at(pluginNumber);
3257 prediffer.m_PluginName = plugin->m_name;
3260 // update data for the radio button
3261 m_CurrentPredifferID = nID;
3263 // update the prediffer and rescan
3264 pd->SetPrediffer(&prediffer);
3268 * @brief Look through available prediffers, and return ID of requested one, if found
3270 int CMergeEditView::FindPrediffer(LPCTSTR prediffer) const
3273 int ID = ID_PREDIFFERS_FIRST;
3275 // Search file prediffers
3276 PluginArray * piScriptArray =
3277 CAllThreadsScripts::GetActiveSet()->GetAvailableScripts(L"FILE_PREDIFF");
3278 for (i=0; i<piScriptArray->size(); ++i, ++ID)
3280 const PluginInfoPtr & plugin = piScriptArray->at(i);
3281 if (plugin->m_name == prediffer)
3285 // Search buffer prediffers
3286 PluginArray * piScriptArray2 =
3287 CAllThreadsScripts::GetActiveSet()->GetAvailableScripts(L"BUFFER_PREDIFF");
3288 for (i=0; i<piScriptArray2->size(); ++i, ++ID)
3290 const PluginInfoPtr & plugin = piScriptArray2->at(i);
3291 if (plugin->m_name == prediffer)
3299 * @brief Look through available prediffers, and return ID of requested one, if found
3301 bool CMergeEditView::SetPredifferByName(const CString & prediffer)
3303 int id = FindPrediffer(prediffer);
3304 if (id<0) return false;
3305 SetPredifferByMenu(id);
3310 * @brief Goto given line.
3311 * @param [in] nLine Destination linenumber
3312 * @param [in] bRealLine if true linenumber is real line, otherwise
3313 * it is apparent line (including deleted lines)
3314 * @param [in] pane Pane index of goto target pane (0 = left, 1 = right).
3316 void CMergeEditView::GotoLine(UINT nLine, bool bRealLine, int pane)
3318 CMergeDoc *pDoc = GetDocument();
3319 CSplitterWnd *pSplitterWnd = GetParentSplitter(this, false);
3320 CMergeEditView *pCurrentView = nullptr;
3321 if (pSplitterWnd != nullptr)
3322 pCurrentView = static_cast<CMergeEditView*>
3323 (pSplitterWnd->GetActivePane());
3325 int nRealLine = nLine;
3326 int nApparentLine = nLine;
3328 // Compute apparent (shown linenumber) line
3331 if (nRealLine > pDoc->m_ptBuf[pane]->GetLineCount() - 1)
3332 nRealLine = pDoc->m_ptBuf[pane]->GetLineCount() - 1;
3334 nApparentLine = pDoc->m_ptBuf[pane]->ComputeApparentLine(nRealLine);
3338 ptPos.y = nApparentLine;
3340 // Scroll line to center of view
3341 int nScrollLine = GetSubLineIndex(nApparentLine);
3342 nScrollLine -= GetScreenLines() / 2;
3343 if (nScrollLine < 0)
3346 for (int nPane = 0; nPane < pDoc->m_nBuffers; nPane++)
3348 CMergeEditView *pView = GetGroupView(nPane);
3349 pView->ScrollToSubLine(nScrollLine);
3350 if (ptPos.y < pView->GetLineCount())
3352 pView->SetCursorPos(ptPos);
3353 pView->SetAnchor(ptPos);
3357 CPoint ptPos1(0, pView->GetLineCount() - 1);
3358 pView->SetCursorPos(ptPos1);
3359 pView->SetAnchor(ptPos1);
3363 // If goto target is another view - activate another view.
3364 // This is done for user convenience as user probably wants to
3365 // work with goto target file.
3366 if (GetGroupView(pane) != pCurrentView)
3368 if (pSplitterWnd != nullptr)
3370 if (pSplitterWnd->GetColumnCount() > 1)
3371 pSplitterWnd->SetActivePane(0, pane);
3373 pSplitterWnd->SetActivePane(pane, 0);
3379 * @brief Check for horizontal scroll. Re-route to CSplitterEx if not from
3382 void CMergeEditView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar *pScrollBar)
3384 if (pScrollBar == nullptr)
3386 // Scroll did not come frome a scroll bar
3387 // Find the appropriate scroll bar
3388 // and send the message to the splitter window instead
3389 // The event should eventually come back here but with a valid scrollbar
3390 // Along the way it will be propagated to other windows that need it
3391 CSplitterWnd *pSplitterWnd = GetParentSplitter(this, false);
3392 CScrollBar* curBar = this->GetScrollBarCtrl(SB_HORZ);
3393 pSplitterWnd->SendMessage(WM_HSCROLL,
3394 MAKELONG(nSBCode, nPos), (LPARAM)curBar->m_hWnd);
3397 CCrystalTextView::OnHScroll (nSBCode, nPos, pScrollBar);
3401 * @brief When view is scrolled using scrollbars update location pane.
3403 void CMergeEditView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar *pScrollBar)
3405 if (pScrollBar == nullptr)
3407 // Scroll did not come frome a scroll bar
3408 // Find the appropriate scroll bar
3409 // and send the message to the splitter window instead
3410 // The event should eventually come back here but with a valid scrollbar
3411 // Along the way it will be propagated to other windows that need it
3412 CSplitterWnd *pSplitterWnd = GetParentSplitter(this, false);
3413 CScrollBar* curBar = this->GetScrollBarCtrl(SB_VERT);
3414 pSplitterWnd->SendMessage(WM_VSCROLL,
3415 MAKELONG(nSBCode, nPos), (LPARAM)curBar->m_hWnd);
3418 CCrystalTextView::OnVScroll (nSBCode, nPos, pScrollBar);
3420 if (nSBCode == SB_ENDSCROLL)
3423 // Note we cannot use nPos because of its 16-bit nature
3424 SCROLLINFO si = {0};
3425 si.cbSize = sizeof (si);
3426 si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_TRACKPOS;
3427 VERIFY (GetScrollInfo (SB_VERT, &si));
3429 // Get the current position of scroll box.
3430 int nCurPos = si.nPos;
3432 UpdateLocationViewPosition(nCurPos, nCurPos + GetScreenLines());
3436 * @brief Copy selected lines adding linenumbers.
3438 void CMergeEditView::OnEditCopyLineNumbers()
3446 CMergeDoc *pDoc = GetDocument();
3447 GetSelection(ptStart, ptEnd);
3449 // Get last selected line (having widest linenumber)
3450 int line = pDoc->m_ptBuf[m_nThisPane]->ComputeRealLine(ptEnd.y);
3451 size_t nNumWidth = strutils::to_str(line + 1).length();
3453 for (int i = ptStart.y; i <= ptEnd.y; i++)
3455 if (GetLineFlags(i) & LF_GHOST || (GetEnableHideLines() && (GetLineFlags(i) & LF_INVISIBLE)))
3458 // We need to convert to real linenumbers
3459 line = pDoc->m_ptBuf[m_nThisPane]->ComputeRealLine(i);
3461 // Insert spaces to align different width linenumbers (99, 100)
3462 strLine = GetLineText(i);
3463 CString sSpaces(' ', static_cast<int>(nNumWidth - strutils::to_str(line + 1).length()));
3466 strNumLine.Format(_T("%d: %s"), line + 1, (LPCTSTR)strLine);
3467 strText += strNumLine;
3469 PutToClipboard(strText, strText.GetLength(), m_bRectangularSelection);
3472 void CMergeEditView::OnUpdateEditCopyLinenumbers(CCmdUI* pCmdUI)
3474 CCrystalEditViewEx::OnUpdateEditCopy(pCmdUI);
3478 * @brief Open active file with associated application.
3480 * First tries to open file using shell 'Edit' action, since that
3481 * action open scripts etc. to editor instead of running them. If
3482 * edit-action is not registered, 'Open' action is used.
3484 void CMergeEditView::OnOpenFile()
3486 CMergeDoc * pDoc = GetDocument();
3487 ASSERT(pDoc != nullptr);
3489 String sFileName = pDoc->m_filePaths[m_nThisPane];
3490 if (sFileName.empty())
3492 HINSTANCE rtn = ShellExecute(::GetDesktopWindow(), _T("edit"), sFileName.c_str(),
3493 0, 0, SW_SHOWNORMAL);
3494 if (reinterpret_cast<uintptr_t>(rtn) == SE_ERR_NOASSOC)
3495 rtn = ShellExecute(::GetDesktopWindow(), _T("open"), sFileName.c_str(),
3496 0, 0, SW_SHOWNORMAL);
3497 if (reinterpret_cast<uintptr_t>(rtn) == SE_ERR_NOASSOC)
3502 * @brief Open active file with app selection dialog
3504 void CMergeEditView::OnOpenFileWith()
3506 CMergeDoc * pDoc = GetDocument();
3507 ASSERT(pDoc != nullptr);
3509 String sFileName = pDoc->m_filePaths[m_nThisPane];
3510 if (sFileName.empty())
3514 if (!GetSystemDirectory(sysdir.GetBuffer(MAX_PATH), MAX_PATH))
3516 sysdir.ReleaseBuffer();
3517 CString arg = (CString)_T("shell32.dll,OpenAs_RunDLL ") + sFileName.c_str();
3518 ShellExecute(::GetDesktopWindow(), 0, _T("RUNDLL32.EXE"), arg,
3519 sysdir, SW_SHOWNORMAL);
3523 * @brief Open active file with external editor
3525 void CMergeEditView::OnOpenFileWithEditor()
3527 CMergeDoc * pDoc = GetDocument();
3528 ASSERT(pDoc != nullptr);
3530 String sFileName = pDoc->m_filePaths[m_nThisPane];
3531 if (sFileName.empty())
3534 int nRealLine = ComputeRealLine(GetCursorPos().y) + 1;
3535 theApp.OpenFileToExternalEditor(sFileName, nRealLine);
3539 * @brief Force repaint of the location pane.
3541 void CMergeEditView::RepaintLocationPane()
3543 // Must force recalculation due to caching of data in location pane.
3544 CLocationView *pLocationView = GetDocument()->GetLocationView();
3545 if (pLocationView != nullptr)
3546 pLocationView->ForceRecalculate();
3550 * @brief Enables/disables linediff (different color for diffs)
3552 void CMergeEditView::OnViewLineDiffs()
3554 bool bWordDiffHighlight = GetOptionsMgr()->GetBool(OPT_WORDDIFF_HIGHLIGHT);
3555 GetOptionsMgr()->SaveOption(OPT_WORDDIFF_HIGHLIGHT, !bWordDiffHighlight);
3557 // Call CMergeDoc RefreshOptions() to refresh *both* views
3558 CMergeDoc *pDoc = GetDocument();
3559 pDoc->RefreshOptions();
3560 pDoc->FlushAndRescan(true);
3563 void CMergeEditView::OnUpdateViewLineDiffs(CCmdUI* pCmdUI)
3565 pCmdUI->Enable(true);
3566 pCmdUI->SetCheck(GetOptionsMgr()->GetBool(OPT_WORDDIFF_HIGHLIGHT));
3570 * @brief Enables/disables line number
3572 void CMergeEditView::OnViewLineNumbers()
3574 GetOptionsMgr()->SaveOption(OPT_VIEW_LINENUMBERS, !GetViewLineNumbers());
3576 // Call CMergeDoc RefreshOptions() to refresh *both* views
3577 CMergeDoc *pDoc = GetDocument();
3578 pDoc->RefreshOptions();
3581 void CMergeEditView::OnUpdateViewLineNumbers(CCmdUI* pCmdUI)
3583 pCmdUI->Enable(true);
3584 pCmdUI->SetCheck(GetViewLineNumbers());
3588 * @brief Enables/disables word wrap
3590 void CMergeEditView::OnViewWordWrap()
3592 GetOptionsMgr()->SaveOption(OPT_WORDWRAP, !m_bWordWrap);
3594 // Call CMergeDoc RefreshOptions() to refresh *both* views
3595 CMergeDoc *pDoc = GetDocument();
3596 pDoc->RefreshOptions();
3597 pDoc->UpdateAllViews(this);
3602 void CMergeEditView::OnUpdateViewWordWrap(CCmdUI* pCmdUI)
3604 pCmdUI->Enable(true);
3605 pCmdUI->SetCheck(m_bWordWrap);
3608 void CMergeEditView::OnViewWhitespace()
3610 GetOptionsMgr()->SaveOption(OPT_VIEW_WHITESPACE, !GetViewTabs());
3612 // Call CMergeDoc RefreshOptions() to refresh *both* views
3613 CMergeDoc *pDoc = GetDocument();
3614 pDoc->RefreshOptions();
3617 void CMergeEditView::OnUpdateViewWhitespace(CCmdUI* pCmdUI)
3619 pCmdUI->SetCheck(GetViewTabs());
3622 void CMergeEditView::OnViewEOL()
3624 GetOptionsMgr()->SaveOption(OPT_VIEW_EOL, !GetViewEols());
3625 GetDocument()->RefreshOptions();
3628 void CMergeEditView::OnUpdateViewEOL(CCmdUI* pCmdUI)
3630 pCmdUI->SetCheck(GetViewEols());
3633 void CMergeEditView::OnSize(UINT nType, int cx, int cy)
3635 if (!IsInitialized())
3638 CMergeDoc * pDoc = GetDocument();
3639 if (m_nThisPane < pDoc->m_nBuffers - 1)
3641 // To calculate subline index correctly
3642 // we have to invalidate line cache in all pane before calling the function related the subline.
3643 for (int nPane = 0; nPane < pDoc->m_nBuffers; nPane++)
3645 CMergeEditView *pView = GetGroupView(nPane);
3646 if (pView != nullptr)
3647 pView->InvalidateScreenRect(false);
3652 for (int nPane = 0; nPane < pDoc->m_nBuffers; nPane++)
3654 CMergeEditView *pView = GetGroupView(nPane);
3655 if (pView != nullptr)
3656 pView->Invalidate();
3659 // recalculate m_nTopSubLine
3660 m_nTopSubLine = GetSubLineIndex(m_nTopLine);
3664 RecalcVertScrollBar (false, false);
3665 RecalcHorzScrollBar (false, false);
3669 * @brief allocates GDI resources for printing
3670 * @param pDC [in] points to the printer device context
3671 * @param pInfo [in] points to a CPrintInfo structure that describes the current print job
3673 void CMergeEditView::OnBeginPrinting(CDC * pDC, CPrintInfo * pInfo)
3675 GetParentFrame()->PostMessage(WM_TIMER);
3677 for (int pane = 0; pane < GetDocument()->m_nBuffers; pane++)
3679 CMergeEditView *pView = GetDocument()->GetView(m_nThisGroup, pane);
3680 pView->m_bPrintHeader = true;
3681 pView->m_bPrintFooter = true;
3682 pView->CGhostTextView::OnBeginPrinting(pDC, pInfo);
3687 * @brief frees GDI resources for printing
3688 * @param pDC [in] points to the printer device context
3689 * @param pInfo [in] points to a CPrintInfo structure that describes the current print job
3691 void CMergeEditView::OnEndPrinting(CDC * pDC, CPrintInfo * pInfo)
3693 for (int pane = 0; pane < GetDocument()->m_nBuffers; pane++)
3694 GetDocument()->GetView(m_nThisGroup, pane)->CGhostTextView::OnEndPrinting(pDC, pInfo);
3696 GetParentFrame()->PostMessage(WM_TIMER);
3700 * @brief Gets header text to print
3701 * @param [in] nPageNum the page number to print
3702 * @param [out] header text to print
3704 void CMergeEditView::GetPrintHeaderText(int nPageNum, CString & text)
3706 text = GetDocument()->GetTitle();
3710 * @brief Prints header
3711 * @param [in] nPageNum the page number to print
3713 void CMergeEditView::PrintHeader(CDC * pdc, int nPageNum)
3715 if (m_nThisPane > 0)
3717 int oldRight = m_rcPrintArea.right;
3718 m_rcPrintArea.right += m_rcPrintArea.Width() * (GetDocument()->m_nBuffers - 1);
3719 CGhostTextView::PrintHeader(pdc, nPageNum);
3720 m_rcPrintArea.right = oldRight;
3724 * @brief Prints footer
3725 * @param [in] nPageNum the page number to print
3727 void CMergeEditView::PrintFooter(CDC * pdc, int nPageNum)
3729 if (m_nThisPane > 0)
3731 int oldRight = m_rcPrintArea.right;
3732 m_rcPrintArea.right += m_rcPrintArea.Width() * (GetDocument()->m_nBuffers - 1);
3733 CGhostTextView::PrintFooter(pdc, nPageNum);
3734 m_rcPrintArea.right = oldRight;
3737 void CMergeEditView::RecalcPageLayouts (CDC * pDC, CPrintInfo * pInfo)
3739 for (int pane = 0; pane < GetDocument()->m_nBuffers; pane++)
3740 GetDocument()->GetView(m_nThisGroup, pane)->CGhostTextView::RecalcPageLayouts(pDC, pInfo);
3744 * @brief Prints or previews both panes.
3745 * @param pDC [in] points to the printer device context
3746 * @param pInfo [in] points to a CPrintInfo structure that describes the current print job
3748 void CMergeEditView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
3750 CRect rDraw = pInfo->m_rectDraw;
3751 CSize sz = rDraw.Size();
3752 CMergeDoc *pDoc = GetDocument();
3754 SIZE szLeftTop, szRightBottom;
3755 GetPrintMargins(szLeftTop.cx, szLeftTop.cy, szRightBottom.cx, szRightBottom.cy);
3756 pDC->HIMETRICtoLP(&szLeftTop);
3757 pDC->HIMETRICtoLP(&szRightBottom);
3759 int midX = (sz.cx - szLeftTop.cx - szRightBottom.cx) / pDoc->m_nBuffers;
3762 for (int pane = 0; pane < pDoc->m_nBuffers; pane++)
3764 pInfo->m_rectDraw.left = rDraw.left + midX * pane;
3765 pInfo->m_rectDraw.right = pInfo->m_rectDraw.left + midX + szLeftTop.cx + szRightBottom.cx;
3766 CMergeEditView* pPane = pDoc->GetView(m_nThisGroup, pane);
3767 pPane->CGhostTextView::OnPrint(pDC, pInfo);
3771 bool CMergeEditView::IsInitialized() const
3773 CMergeEditView * pThis = const_cast<CMergeEditView *>(this);
3774 CDiffTextBuffer * pBuffer = dynamic_cast<CDiffTextBuffer *>(pThis->LocateTextBuffer());
3775 return pBuffer->IsInitialized();
3779 * @brief returns the number of empty lines which are added for synchronizing the line in two/three panes.
3781 int CMergeEditView::GetEmptySubLines( int nLineIndex )
3783 int nBreaks[3] = {0};
3784 int nMaxBreaks = -1;
3785 CMergeDoc * pDoc = GetDocument();
3786 for (int nPane = 0; nPane < pDoc->m_nBuffers; nPane++)
3788 CMergeEditView *pView = GetGroupView(nPane);
3789 if (pView != nullptr)
3791 if (nLineIndex >= pView->GetLineCount())
3793 pView->WrapLineCached( nLineIndex, pView->GetScreenChars(), nullptr, nBreaks[nPane] );
3795 nMaxBreaks = max(nMaxBreaks, nBreaks[nPane]);
3798 if (nBreaks[m_nThisPane] < nMaxBreaks)
3799 return nMaxBreaks - nBreaks[m_nThisPane];
3805 * @brief Invalidate sub line index cache from the specified index to the end of file.
3806 * @param [in] nLineIndex Index of the first line to invalidate
3808 void CMergeEditView::InvalidateSubLineIndexCache( int nLineIndex )
3810 CMergeDoc * pDoc = GetDocument();
3811 ASSERT(pDoc != nullptr);
3813 // We have to invalidate sub line index cache on both panes.
3814 for (int nPane = 0; nPane < pDoc->m_nBuffers; nPane++)
3816 CMergeEditView *pView = GetGroupView(nPane);
3817 if (pView != nullptr)
3818 pView->CCrystalTextView::InvalidateSubLineIndexCache( nLineIndex );
3822 void CMergeEditView::SetWordWrapping( bool bWordWrap )
3824 for (int pane = 0; pane < GetDocument()->m_nBuffers; pane++)
3825 GetGroupView(pane)->m_bWordWrap = bWordWrap;
3826 CCrystalTextView::SetWordWrapping(bWordWrap);
3830 * @brief Swap the positions of the two panes
3832 void CMergeEditView::OnViewSwapPanes()
3834 GetDocument()->SwapFiles();
3838 * @brief Determine if difference is visible on screen.
3839 * @param [in] nDiff Number of diff to check.
3840 * @return true if difference is visible.
3842 bool CMergeEditView::IsDiffVisible(int nDiff)
3844 const CMergeDoc *pd = GetDocument();
3847 pd->m_diffList.GetDiff(nDiff, diff);
3849 return IsDiffVisible(diff);
3853 * @brief Determine if difference is visible on screen.
3854 * @param [in] diff diff to check.
3855 * @param [in] nLinesBelow Allow "minimizing" the number of visible lines.
3856 * @return true if difference is visible, false otherwise.
3858 bool CMergeEditView::IsDiffVisible(const DIFFRANGE& diff, int nLinesBelow /*=0*/)
3860 const int nDiffStart = GetSubLineIndex(diff.dbegin);
3861 const int nDiffEnd = GetSubLineIndex(diff.dend);
3862 // Diff's height is last line - first line + last line's line count
3863 const int nDiffHeight = nDiffEnd - nDiffStart + GetSubLines(diff.dend) + 1;
3865 // If diff first line outside current view - context OR
3866 // if diff last line outside current view - context OR
3867 // if diff is bigger than screen
3868 if ((nDiffStart < m_nTopSubLine) ||
3869 (nDiffEnd >= m_nTopSubLine + GetScreenLines() - nLinesBelow) ||
3870 (nDiffHeight >= GetScreenLines()))
3880 /** @brief Open help from mainframe when user presses F1*/
3881 void CMergeEditView::OnHelp()
3883 theApp.ShowHelp(MergeViewHelpLocation);
3887 * @brief Called after document is loaded.
3888 * This function is called from CMergeDoc::OpenDocs() after documents are
3889 * loaded. So this is good place to set View's options etc.
3891 void CMergeEditView::DocumentsLoaded()
3893 if (GetDocument()->m_ptBuf[m_nThisPane]->GetTableEditing())
3896 if (m_nThisPane == GetDocument()->m_nBuffers - 1 && !m_bDetailView)
3901 SetTopMargin(false);
3904 // Enable/disable automatic rescan (rescanning after edit)
3905 EnableRescan(GetOptionsMgr()->GetBool(OPT_AUTOMATIC_RESCAN));
3907 // SetTextType will revert to language dependent defaults for tab
3908 SetTabSize(GetOptionsMgr()->GetInt(OPT_TAB_SIZE));
3909 SetViewTabs(GetOptionsMgr()->GetBool(OPT_VIEW_WHITESPACE));
3910 const bool mixedEOLs = GetOptionsMgr()->GetBool(OPT_ALLOW_MIXED_EOL) ||
3911 GetDocument()->IsMixedEOL(m_nThisPane);
3912 SetViewEols(GetOptionsMgr()->GetBool(OPT_VIEW_EOL), mixedEOLs);
3913 SetWordWrapping(GetOptionsMgr()->GetBool(OPT_WORDWRAP));
3914 SetViewLineNumbers(GetOptionsMgr()->GetBool(OPT_VIEW_LINENUMBERS));
3915 SetSelectionMargin(GetOptionsMgr()->GetBool(OPT_VIEW_FILEMARGIN));
3917 // Enable Backspace at beginning of line
3918 SetDisableBSAtSOL(false);
3920 // Set tab type (tabs/spaces)
3921 bool bInsertTabs = (GetOptionsMgr()->GetInt(OPT_TAB_TYPE) == 0);
3922 SetInsertTabs(bInsertTabs);
3924 // Sometimes WinMerge doesn't update scrollbars correctly (they remain
3925 // disabled) after docs are open in screen. So lets make sure they are
3926 // really updated, even though this is unnecessary in most cases.
3927 RecalcHorzScrollBar();
3928 RecalcVertScrollBar();
3932 * @brief Update LocationView position.
3933 * This function updates LocationView position to given lines.
3934 * Usually we want to lines in file compare view and area in
3935 * LocationView to match. Be extra carefull to not call non-existing
3937 * @param [in] nTopLine Top line of current view.
3938 * @param [in] nBottomLine Bottom line of current view.
3940 void CMergeEditView::UpdateLocationViewPosition(int nTopLine /*=-1*/,
3941 int nBottomLine /*= -1*/)
3943 CMergeDoc *pDoc = GetDocument();
3944 if (pDoc == nullptr)
3947 CLocationView *pLocationView = pDoc->GetLocationView();
3949 if (pLocationView != nullptr && IsWindow(pLocationView->GetSafeHwnd()))
3951 pLocationView->UpdateVisiblePos(nTopLine, nBottomLine);
3956 * @brief Enable/Disable view's selection margins.
3957 * Selection margins show bookmarks and word-wrap symbols, so they are pretty
3958 * useful. But it appears many users don't use/need those features and for them
3959 * selection margins are just wasted screen estate.
3961 void CMergeEditView::OnViewMargin()
3963 bool bViewMargin = GetOptionsMgr()->GetBool(OPT_VIEW_FILEMARGIN);
3964 GetOptionsMgr()->SaveOption(OPT_VIEW_FILEMARGIN, !bViewMargin);
3966 SetSelectionMargin(!bViewMargin);
3967 CMergeDoc *pDoc = GetDocument();
3968 pDoc->RefreshOptions();
3969 pDoc->UpdateAllViews(this);
3973 * @brief Update GUI for Enable/Disable view's selection margin.
3974 * @param [in] pCmdUI Pointer to UI item to update.
3976 void CMergeEditView::OnUpdateViewMargin(CCmdUI* pCmdUI)
3978 pCmdUI->Enable(true);
3979 pCmdUI->SetCheck(GetOptionsMgr()->GetBool(OPT_VIEW_FILEMARGIN));
3983 * @brief Create the "Change Scheme" sub menu.
3984 * @param [in] pCmdUI Pointer to UI item to update.
3986 void CMergeEditView::OnUpdateViewChangeScheme(CCmdUI *pCmdUI)
3988 // Delete the place holder menu.
3989 pCmdUI->m_pSubMenu->DeleteMenu(0, MF_BYPOSITION);
3991 const HMENU hSubMenu = pCmdUI->m_pSubMenu->m_hMenu;
3993 String name = theApp.LoadString(ID_COLORSCHEME_FIRST);
3994 AppendMenu(hSubMenu, MF_STRING, ID_COLORSCHEME_FIRST, name.c_str());
3995 AppendMenu(hSubMenu, MF_SEPARATOR, 0, nullptr);
3997 for (int i = ID_COLORSCHEME_FIRST + 1; i <= ID_COLORSCHEME_LAST; ++i)
3999 name = theApp.LoadString(i);
4000 AppendMenu(hSubMenu, MF_STRING, i, name.c_str());
4003 pCmdUI->Enable(true);
4007 * @brief Change the editor's syntax highlighting scheme.
4008 * @param [in] nID Selected color scheme sub menu id.
4010 void CMergeEditView::OnChangeScheme(UINT nID)
4012 CMergeDoc *pDoc = GetDocument();
4013 ASSERT(pDoc != nullptr);
4015 for (int nPane = 0; nPane < pDoc->m_nBuffers; nPane++)
4017 CMergeEditView *pView = GetGroupView(nPane);
4018 ASSERT(pView != nullptr);
4020 if (pView != nullptr)
4022 pView->SetTextType(CrystalLineParser::TextType(nID - ID_COLORSCHEME_FIRST));
4023 pView->SetDisableBSAtSOL(false);
4027 pDoc->UpdateAllViews(nullptr);
4031 * @brief Enable all color schemes sub menu items.
4032 * @param [in] pCmdUI Pointer to UI item to update.
4034 void CMergeEditView::OnUpdateChangeScheme(CCmdUI* pCmdUI)
4036 const bool bIsCurrentScheme = (static_cast<UINT>(m_CurSourceDef->type) == (pCmdUI->m_nID - ID_COLORSCHEME_FIRST));
4037 pCmdUI->SetRadio(bIsCurrentScheme);
4038 pCmdUI->Enable(GetOptionsMgr()->GetBool(OPT_SYNTAX_HIGHLIGHT));
4042 * @brief Called when mouse's wheel is scrolled.
4044 BOOL CMergeEditView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
4046 if ( nFlags == MK_CONTROL )
4048 short amount = zDelta < 0 ? -1: 1;
4051 // no default CCrystalTextView
4052 return CView::OnMouseWheel(nFlags, zDelta, pt);
4055 if (nFlags == MK_SHIFT)
4057 SCROLLINFO si = { sizeof SCROLLINFO };
4058 si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
4060 VERIFY(GetScrollInfo(SB_HORZ, &si));
4063 si.nPos -= zDelta / 40;
4064 if (si.nPos > si.nMax) si.nPos = si.nMax;
4065 if (si.nPos < si.nMin) si.nPos = si.nMin;
4067 SetScrollInfo(SB_HORZ, &si);
4070 SendMessage(WM_HSCROLL, MAKEWPARAM(SB_THUMBPOSITION, si.nPos) , NULL );
4072 // no default CCrystalTextView
4073 return CView::OnMouseWheel(nFlags, zDelta, pt);
4076 return CGhostTextView::OnMouseWheel(nFlags, zDelta, pt);
4080 * @brief Called when mouse's horizontal wheel is scrolled.
4082 void CMergeEditView::OnMouseHWheel(UINT nFlags, short zDelta, CPoint pt)
4084 SCROLLINFO si = { sizeof SCROLLINFO };
4085 si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
4087 VERIFY(GetScrollInfo(SB_HORZ, &si));
4090 si.nPos += zDelta / 40;
4091 if (si.nPos > si.nMax) si.nPos = si.nMax;
4092 if (si.nPos < si.nMin) si.nPos = si.nMin;
4094 SetScrollInfo(SB_HORZ, &si);
4097 SendMessage(WM_HSCROLL, MAKEWPARAM(SB_THUMBPOSITION, si.nPos) , NULL );
4099 // no default CCrystalTextView
4100 CView::OnMouseHWheel(nFlags, zDelta, pt);
4104 * @brief Change font size (zoom) in views.
4105 * @param [in] amount Amount of change/zoom, negative number makes
4106 * font smaller, positive number bigger and 0 reset the font size.
4108 void CMergeEditView::ZoomText(short amount)
4113 const int nLogPixelsY = CClientDC(this).GetDeviceCaps(LOGPIXELSY);
4114 int nPointSize = -MulDiv(lf.lfHeight, 72, nLogPixelsY);
4118 nPointSize = -MulDiv(GetOptionsMgr()->GetInt(OPT_FONT_FILECMP + OPT_FONT_HEIGHT), 72, nLogPixelsY);
4121 nPointSize += amount;
4125 lf.lfHeight = -MulDiv(nPointSize, nLogPixelsY, 72);
4127 CMergeDoc *pDoc = GetDocument();
4128 ASSERT(pDoc != nullptr);
4130 if (pDoc != nullptr)
4132 for (int nPane = 0; nPane < pDoc->m_nBuffers; nPane++)
4134 CMergeEditView *pView = GetGroupView(nPane);
4135 ASSERT(pView != nullptr);
4137 if (pView != nullptr)
4145 bool CMergeEditView::QueryEditable()
4147 return m_bDetailView ? false : !GetDocument()->m_ptBuf[m_nThisPane]->GetReadOnly();
4151 * @brief Adjust the point to remain in the displayed diff
4153 * @return Tells if the point has been changed
4155 bool CMergeEditView::EnsureInDiff(CPoint& pt)
4157 int nLineCount = GetLineCount();
4158 if (m_lineBegin >= nLineCount)
4159 m_lineBegin = nLineCount - 1;
4160 if (m_lineEnd >= nLineCount)
4161 m_lineEnd = nLineCount - 1;
4163 int diffLength = m_lineEnd - m_lineBegin + 1;
4164 // first get the degenerate case out of the way
4166 if (diffLength == 0)
4168 if (pt.y == m_lineBegin && pt.x == 0)
4176 if (pt.y < m_lineBegin)
4182 // diff is defined and not below diff
4183 if (m_lineEnd > -1 && pt.y > m_lineEnd)
4186 pt.x = GetLineLength(pt.y);
4192 void CMergeEditView::EnsureVisible(CPoint pt)
4197 // ensure we remain in diff
4198 if (EnsureInDiff(ptNew))
4199 SetCursorPos(ptNew);
4201 CCrystalTextView::EnsureVisible(ptNew);
4204 void CMergeEditView::EnsureVisible(CPoint ptStart, CPoint ptEnd)
4206 CCrystalTextView::EnsureVisible(ptStart, ptEnd);
4209 void CMergeEditView::SetSelection(const CPoint& ptStart, const CPoint& ptEnd, bool bUpdateView)
4211 CPoint ptStartNew = ptStart;
4212 CPoint ptEndNew = ptEnd;
4215 // ensure we remain in diff
4216 EnsureInDiff(ptStartNew);
4217 EnsureInDiff(ptEndNew);
4219 CCrystalTextView::SetSelection(ptStartNew, ptEndNew, bUpdateView);
4222 void CMergeEditView::ScrollToSubLine(int nNewTopLine, bool bNoSmoothScroll /*= FALSE*/, bool bTrackScrollBar /*= TRUE*/)
4226 int nLineCount = GetLineCount();
4227 if (m_lineBegin >= nLineCount)
4228 m_lineBegin = nLineCount - 1;
4229 if (m_lineEnd >= nLineCount)
4230 m_lineEnd = nLineCount - 1;
4232 // ensure we remain in diff
4233 int sublineBegin = GetSubLineIndex(m_lineBegin);
4234 int sublineEnd = m_lineEnd < 0 ? -1 : GetSubLineIndex(m_lineEnd) + GetSubLines(m_lineEnd) - 1;
4235 int diffLength = sublineEnd - sublineBegin + 1;
4236 int displayLength = GetScreenLines();
4237 if (diffLength <= displayLength)
4238 nNewTopLine = sublineBegin;
4241 if (nNewTopLine < sublineBegin)
4242 nNewTopLine = sublineBegin;
4243 if (nNewTopLine + displayLength - 1 > sublineEnd)
4244 nNewTopLine = GetSubLineIndex(sublineEnd - displayLength + 1);
4247 CPoint pt = GetCursorPos();
4248 if (EnsureInDiff(pt))
4251 CPoint ptSelStart, ptSelEnd;
4252 GetSelection(ptSelStart, ptSelEnd);
4253 if (EnsureInDiff(ptSelStart) || EnsureInDiff(ptSelEnd))
4254 SetSelection(ptSelStart, ptSelEnd);
4256 CCrystalTextView::ScrollToSubLine(nNewTopLine, bNoSmoothScroll, bTrackScrollBar);
4260 * @brief Called when user selects View/Zoom In from menu.
4262 void CMergeEditView::OnViewZoomIn()
4268 * @brief Called when user selects View/Zoom Out from menu.
4270 void CMergeEditView::OnViewZoomOut()
4276 * @brief Called when user selects View/Zoom Normal from menu.
4278 void CMergeEditView::OnViewZoomNormal()
4283 void CMergeEditView::OnDropFiles(const std::vector<String>& tFiles)
4285 if (tFiles.size() > 1 || paths::IsDirectory(tFiles[0]))
4287 GetMainFrame()->GetDropHandler()->GetCallback()(tFiles);
4291 GetDocument()->ChangeFile(m_nThisPane, tFiles[0]);
4294 void CMergeEditView::OnWindowSplit()
4297 auto& wndSplitter = dynamic_cast<CMergeEditFrame *>(GetParentFrame())->GetSplitter();
4298 CMergeDoc *pDoc = GetDocument();
4299 CMergeEditView *pView = pDoc->GetView(0, m_nThisPane);
4300 auto* pwndSplitterChild = pView->GetParentSplitter(pView, false);
4301 int nBuffer = m_nThisPane;
4302 if (pDoc->m_nGroups <= 2)
4304 wndSplitter.SplitRow(1);
4305 wndSplitter.EqualizeRows();
4309 wndSplitter.SetActivePane(0, 0);
4310 wndSplitter.DeleteRow(1);
4311 if (pwndSplitterChild->GetColumnCount() > 1)
4312 pwndSplitterChild->SetActivePane(0, nBuffer);
4314 pwndSplitterChild->SetActivePane(nBuffer, 0);
4318 void CMergeEditView::OnUpdateWindowSplit(CCmdUI* pCmdUI)
4320 pCmdUI->Enable(!m_bDetailView);
4321 pCmdUI->SetCheck(GetDocument()->m_nGroups > 2);
4324 void CMergeEditView::OnStatusBarDblClick(NMHDR* pNMHDR, LRESULT* pResult)
4327 LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
4328 const int pane = pNMItemActivate->iItem / 4;
4330 switch (pNMItemActivate->iItem % 4)
4333 GetDocument()->GetView(0, pane)->PostMessage(WM_COMMAND, ID_EDIT_WMGOTO);
4336 GetDocument()->GetView(0, pane)->PostMessage(WM_COMMAND, ID_FILE_ENCODING);
4341 ::GetCursorPos(&point);
4344 VERIFY(menu.LoadMenu(IDR_POPUP_MERGEEDITFRAME_STATUSBAR_EOL));
4345 theApp.TranslateMenu(menu.m_hMenu);
4346 menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, GetDocument()->GetView(0, pane));
4350 GetDocument()->m_ptBuf[pane]->SetReadOnly(!GetDocument()->m_ptBuf[pane]->GetReadOnly());