[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

TortoiseMerge Patch to Improve Searching

From: Jeremy Whitby <jeremy.whitby_at_googlemail.com>
Date: 2006-08-28 23:53:03 CEST

Please find attached a patch that implements "Whole Word" searching and
"Wrap around" whilst searching. These are items 1 & 2 of issue tracker
issue 271.

I have not done anything with the status bar to indicate wrap around as I'm
not sure how. If you can provide help and are happy with the quality of the
patch then I'll continue working on this.

A further idea I had for searching was to provide two radio buttons for
search direction i.e. backwards/forwards. Again if you think that is a good
idea let me know and I'll try to put something together.

I hope this is of some use,

Regards

Jeremy Whitby

Patch below:
=========
Index: src/Resources/TortoiseMergeENG.rc
===================================================================
--- src/Resources/TortoiseMergeENG.rc (revision 7348)
+++ src/Resources/TortoiseMergeENG.rc (working copy)
@@ -693,7 +693,7 @@
 // Dialog
 //

-IDD_FIND DIALOGEX 0, 0, 311, 58
+IDD_FIND DIALOGEX 0, 0, 311, 89
 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION |
WS_SYSMENU
 CAPTION "Find"
 FONT 8, "MS Shell Dlg", 400, 0, 0x1
@@ -705,6 +705,8 @@
     CONTROL "Match &case",IDC_MATCHCASE,"Button",BS_AUTOCHECKBOX |
WS_TABSTOP,7,26,83,10
     CONTROL "&Limit search to modified lines",IDC_LIMITTODIFFS,
                     "Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,41,144,10
+ CONTROL "Wrap &around",IDC_WRAPAROUND,"Button",BS_AUTOCHECKBOX
| WS_TABSTOP,7,56,144,10
+ CONTROL "&Whole word",IDC_WHOLEWORD,"Button",BS_AUTOCHECKBOX |
WS_TABSTOP,7,71,144,10
 END

@@ -725,7 +727,7 @@
         VERTGUIDE, 244
         VERTGUIDE, 248
         TOPMARGIN, 7
- BOTTOMMARGIN, 51
+ BOTTOMMARGIN, 82
     END
 END
 #endif // APSTUDIO_INVOKED
Index: src/TortoiseMerge/FindDlg.cpp
===================================================================
--- src/TortoiseMerge/FindDlg.cpp (revision 7348)
+++ src/TortoiseMerge/FindDlg.cpp (working copy)
@@ -16,6 +16,8 @@
     , m_bFindNext(false)
     , m_bMatchCase(FALSE)
     , m_bLimitToDiffs(FALSE)
+ , m_bWholeWord(FALSE)
+ , m_bWrapAround(FALSE)
     , m_sFindText(_T(""))
 {
 }
@@ -29,6 +31,8 @@
     CDialog::DoDataExchange(pDX);
     DDX_Check(pDX, IDC_MATCHCASE, m_bMatchCase);
     DDX_Check(pDX, IDC_LIMITTODIFFS, m_bLimitToDiffs);
+ DDX_Check(pDX, IDC_WRAPAROUND, m_bWrapAround);
+ DDX_Check(pDX, IDC_WHOLEWORD, m_bWholeWord);
     DDX_Text(pDX, IDC_SEARCHTEXT, m_sFindText);
 }

Index: src/TortoiseMerge/FindDlg.h
===================================================================
--- src/TortoiseMerge/FindDlg.h (revision 7348)
+++ src/TortoiseMerge/FindDlg.h (working copy)
@@ -15,6 +15,8 @@
     bool FindNext() {return m_bFindNext;}
     bool MatchCase() {return !!m_bMatchCase;}
     bool LimitToDiffs() {return !!m_bLimitToDiffs;}
+ bool WholeWord() {return !!m_bWholeWord;}
+ bool WrapAround() {return !!m_bWrapAround;}
     CString GetFindString() {return m_sFindText;}
 // Dialog Data
     enum { IDD = IDD_FIND };
@@ -34,5 +36,7 @@
     bool m_bFindNext;
     BOOL m_bMatchCase;
     BOOL m_bLimitToDiffs;
+ BOOL m_bWholeWord;
+ BOOL m_bWrapAround;
     CString m_sFindText;
 };
Index: src/TortoiseMerge/MainFrm.cpp
===================================================================
--- src/TortoiseMerge/MainFrm.cpp (revision 7348)
+++ src/TortoiseMerge/MainFrm.cpp (working copy)
@@ -1053,13 +1053,39 @@
         m_sFindText = m_pFindDialog->GetFindString();
         m_bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
         m_bLimitToDiff = m_pFindDialog->LimitToDiffs();
-
+ m_bWholeWord = m_pFindDialog->WholeWord();
+ m_bWrapAround = m_pFindDialog->WrapAround();
         OnEditFindnext();
     } // if(m_pFindDialog->FindNext())

     return 0;
 }

+bool CharIsDelimiter(const CString& ch)
+{
+ CString delimiters(_T("., :;=+-*/\\\n\t()"));
+ return delimiters.Find(ch) >= 0;
+}
+
+bool CMainFrame::StringFound(const CString& str)const
+{
+ int nSubStringStartIdx = str.Find(m_sFindText);
+ bool bStringFound = (nSubStringStartIdx >= 0);
+ if (bStringFound && m_bWholeWord)
+ {
+ if (nSubStringStartIdx)
+ bStringFound = CharIsDelimiter(str.Mid
(nSubStringStartIdx-1,1));
+
+ if (bStringFound)
+ {
+ int nEndIndex = nSubStringStartIdx + m_sFindText.GetLength();
+ if (str.GetLength() > nEndIndex)
+ bStringFound = CharIsDelimiter(str.Mid(nEndIndex, 1));
+ }
+ }
+ return bStringFound;
+}
+
 void CMainFrame::OnEditFindnext()
 {
     if (m_sFindText.IsEmpty())
@@ -1068,7 +1094,8 @@
     if ((m_pwndLeftView)&&(m_pwndLeftView->m_arDiffLines))
     {
         bool bFound = FALSE;
-
+ bool bWrap = true;
+
         CString left;
         CString right;
         CString bottom;
@@ -1076,80 +1103,82 @@
         CDiffData::DiffStates rightstate = CDiffData::DIFFSTATE_NORMAL;
         CDiffData::DiffStates bottomstate = CDiffData::DIFFSTATE_NORMAL;
         int i = 0;
- for (i=m_nSearchIndex; i<m_pwndLeftView->m_arDiffLines->GetCount();
i++)
+ const int idxLimits[2][2]={{m_nSearchIndex,
m_pwndLeftView->m_arDiffLines->GetCount()},
+ {0, m_nSearchIndex}};
+ for (int j=0; j != 2 && !bFound && bWrap; ++j)
         {
- left = m_pwndLeftView->m_arDiffLines->GetAt(i);
- leftstate =
(CDiffData::DiffStates)m_pwndLeftView->m_arLineStates->GetAt(i);
- if ((!m_bOneWay)&&(m_pwndRightView->m_arDiffLines))
+ for (i=idxLimits[j][0]; i != idxLimits[j][1]; i++)
             {
- right = m_pwndRightView->m_arDiffLines->GetAt(i);
- rightstate =
(CDiffData::DiffStates)m_pwndRightView->m_arLineStates->GetAt(i);
- }
- if ((m_pwndBottomView)&&(m_pwndBottomView->m_arDiffLines))
- {
- bottom = m_pwndBottomView->m_arDiffLines->GetAt(i);
- bottomstate =
(CDiffData::DiffStates)m_pwndBottomView->m_arLineStates->GetAt(i);
- }
-
- if (!m_bMatchCase)
- {
- left = left.MakeLower();
- right = right.MakeLower();
- bottom = bottom.MakeLower();
- m_sFindText = m_sFindText.MakeLower();
- }
- if (left.Find(m_sFindText) >= 0)
- {
- if ((!m_bLimitToDiff)||(leftstate !=
CDiffData::DIFFSTATE_NORMAL))
+ left = m_pwndLeftView->m_arDiffLines->GetAt(i);
+ leftstate =
(CDiffData::DiffStates)m_pwndLeftView->m_arLineStates->GetAt(i);
+ if ((!m_bOneWay)&&(m_pwndRightView->m_arDiffLines))
                 {
- bFound = TRUE;
- break;
+ right = m_pwndRightView->m_arDiffLines->GetAt(i);
+ rightstate =
(CDiffData::DiffStates)m_pwndRightView->m_arLineStates->GetAt(i);
                 }
- }
- else if (right.Find(m_sFindText) >= 0)
- {
- if ((!m_bLimitToDiff)||(rightstate !=
CDiffData::DIFFSTATE_NORMAL))
+ if ((m_pwndBottomView)&&(m_pwndBottomView->m_arDiffLines))
                 {
- bFound = TRUE;
- break;
+ bottom = m_pwndBottomView->m_arDiffLines->GetAt(i);
+ bottomstate =
(CDiffData::DiffStates)m_pwndBottomView->m_arLineStates->GetAt(i);
                 }
- }
- else if (bottom.Find(m_sFindText) >= 0)
- {
- if ((!m_bLimitToDiff)||(bottomstate !=
CDiffData::DIFFSTATE_NORMAL))
+
+ if (!m_bMatchCase)
                 {
- bFound = TRUE;
- break;
+ left = left.MakeLower();
+ right = right.MakeLower();
+ bottom = bottom.MakeLower();
+ m_sFindText = m_sFindText.MakeLower();
                 }
- }
- }
+ if (StringFound(left))
+ {
+ if ((!m_bLimitToDiff)||(leftstate !=
CDiffData::DIFFSTATE_NORMAL))
+ {
+ bFound = TRUE;
+ break;
+ }
+ }
+ else if (StringFound(right))
+ {
+ if ((!m_bLimitToDiff)||(rightstate !=
CDiffData::DIFFSTATE_NORMAL))
+ {
+ bFound = TRUE;
+ break;
+ }
+ }
+ else if (StringFound(bottom))
+ {
+ if ((!m_bLimitToDiff)||(bottomstate !=
CDiffData::DIFFSTATE_NORMAL))
+ {
+ bFound = TRUE;
+ break;
+ }
+ }
+ }
+ bWrap = m_bWrapAround;
+ }
         if (bFound)
         {
             m_nSearchIndex = i;
             m_pwndLeftView->GoToLine(m_nSearchIndex);
- if (left.Find(m_sFindText) >= 0)
+ if (StringFound(left))
             {
                 m_pwndLeftView->SetFocus();
                 m_pwndLeftView->SelectLines(m_nSearchIndex);
             }
- else if (right.Find(m_sFindText) >= 0)
+ else if (StringFound(right))
             {
                 m_pwndRightView->SetFocus();
                 m_pwndRightView->SelectLines(m_nSearchIndex);
             }
- else if (bottom.Find(m_sFindText) >= 0)
+ else if (StringFound(bottom))
             {
                 m_pwndBottomView->SetFocus();
                 m_pwndBottomView->SelectLines(m_nSearchIndex);
             }
             m_nSearchIndex++;
             if (m_nSearchIndex >=
m_pwndLeftView->m_arDiffLines->GetCount())
- m_nSearchIndex = 0;
+ --m_nSearchIndex;
         } // if (bFound)
- else
- {
- m_nSearchIndex = 0;
- }
     } // if ((m_pwndLeftView)&&(m_pwndLeftView->m_arDiffLines))
 }

Index: src/TortoiseMerge/MainFrm.h
===================================================================
--- src/TortoiseMerge/MainFrm.h (revision 7348)
+++ src/TortoiseMerge/MainFrm.h (working copy)
@@ -95,6 +95,7 @@
     BOOL ReadWindowPlacement(WINDOWPLACEMENT * pwp);
     bool FileSave();
     bool FileSaveAs();
+ bool StringFound(const CString&)const;
 protected:
     CStatusBar m_wndStatusBar;
     CNewToolBar m_wndToolBar;
@@ -113,6 +114,8 @@
     CString m_sFindText;
     BOOL m_bMatchCase;
     bool m_bLimitToDiff;
+ bool m_bWrapAround;
+ bool m_bWholeWord;
     static const UINT m_FindDialogMessage;
     CFindDlg * m_pFindDialog;
     bool m_bHasConflicts;
Index: src/TortoiseMerge/resource.h
===================================================================
--- src/TortoiseMerge/resource.h (revision 7348)
+++ src/TortoiseMerge/resource.h (working copy)
@@ -111,6 +111,8 @@
 #define IDC_DIFFBAR 1065
 #define IDC_LIMITTODIFFS 1065
 #define IDC_STRIKEOUT 1066
+#define IDC_WRAPAROUND 1066
+#define IDC_WHOLEWORD 1067
 #define IDC_CHECK3 1067
 #define IDC_RESOLVE 1067
 #define IDC_CASEINSENSITIVE 1067
Received on Mon Aug 28 23:53:20 2006

This is an archived mail posted to the TortoiseSVN Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.