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

Re: TortoiseMerge Patch to Improve Searching

From: Jeremy Whitby <jeremy.whitby_at_googlemail.com>
Date: 2006-08-31 21:26:41 CEST

Stefan Küng wrote:
> Jeremy Whitby wrote:
>> 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.
>
> Can you please send the patch again, but this time as an attachment to
> the mail? The tabs/spaces got somehow mangled in the mail and I can't
> apply it as it is now.
> If in doubt, just zip it :)
Sorry for the delay, I've been away please find attached to this email a
patch.
>
>> 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.
>
> I'd say we just have 'wrap around' always enabled, without a checkbox.
> Most text editors I know do that too.
>
OK, the attached patch has no checkbox but always 'wraps around'
>> 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 think that would be overkill. I never really liked that feature
> anyway, no matter in what editor or other app it is present. I'm used
> to have the search always start over at the top again, so why should I
> want to specify the search direction?
>
> Stefan
>
Fair enough, it was just a thought.

Hope the patch can be applied this time,

Regards

Jeremy Whitby

Index: src/Resources/TortoiseMergeENG.rc
===================================================================
--- src/Resources/TortoiseMergeENG.rc (revision 7379)
+++ src/Resources/TortoiseMergeENG.rc (working copy)
@@ -695,7 +695,7 @@
 // Dialog
 //
 
-IDD_FIND DIALOGEX 0, 0, 311, 58
+IDD_FIND DIALOGEX 0, 0, 311, 73
 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
 CAPTION "Find"
 FONT 8, "MS Shell Dlg", 400, 0, 0x1
@@ -707,6 +707,7 @@
     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 "&Whole word",IDC_WHOLEWORD,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,56,144,10
 END
 
 
@@ -727,7 +728,7 @@
         VERTGUIDE, 244
         VERTGUIDE, 248
         TOPMARGIN, 7
- BOTTOMMARGIN, 51
+ BOTTOMMARGIN, 66
     END
 END
 #endif // APSTUDIO_INVOKED
Index: src/TortoiseMerge/FindDlg.cpp
===================================================================
--- src/TortoiseMerge/FindDlg.cpp (revision 7379)
+++ src/TortoiseMerge/FindDlg.cpp (working copy)
@@ -16,6 +16,7 @@
         , m_bFindNext(false)
         , m_bMatchCase(FALSE)
         , m_bLimitToDiffs(FALSE)
+ , m_bWholeWord(FALSE)
         , m_sFindText(_T(""))
 {
 }
@@ -29,6 +30,7 @@
         CDialog::DoDataExchange(pDX);
         DDX_Check(pDX, IDC_MATCHCASE, m_bMatchCase);
         DDX_Check(pDX, IDC_LIMITTODIFFS, m_bLimitToDiffs);
+ DDX_Check(pDX, IDC_WHOLEWORD, m_bWholeWord);
         DDX_Text(pDX, IDC_SEARCHTEXT, m_sFindText);
 }
 
Index: src/TortoiseMerge/FindDlg.h
===================================================================
--- src/TortoiseMerge/FindDlg.h (revision 7379)
+++ src/TortoiseMerge/FindDlg.h (working copy)
@@ -15,6 +15,7 @@
         bool FindNext() {return m_bFindNext;}
         bool MatchCase() {return !!m_bMatchCase;}
         bool LimitToDiffs() {return !!m_bLimitToDiffs;}
+ bool WholeWord() {return !!m_bWholeWord;}
         CString GetFindString() {return m_sFindText;}
 // Dialog Data
         enum { IDD = IDD_FIND };
@@ -34,5 +35,6 @@
         bool m_bFindNext;
         BOOL m_bMatchCase;
         BOOL m_bLimitToDiffs;
+ BOOL m_bWholeWord;
         CString m_sFindText;
 };
Index: src/TortoiseMerge/MainFrm.cpp
===================================================================
--- src/TortoiseMerge/MainFrm.cpp (revision 7379)
+++ src/TortoiseMerge/MainFrm.cpp (working copy)
@@ -1053,6 +1053,7 @@
         m_sFindText = m_pFindDialog->GetFindString();
         m_bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
                 m_bLimitToDiff = m_pFindDialog->LimitToDiffs();
+ m_bWholeWord = m_pFindDialog->WholeWord();
         
                 OnEditFindnext();
     } // if(m_pFindDialog->FindNext())
@@ -1060,6 +1061,31 @@
     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())
@@ -1076,68 +1102,73 @@
                 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; ++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;
+ }
+ }
+ }
+ }
                 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);
Index: src/TortoiseMerge/MainFrm.h
===================================================================
--- src/TortoiseMerge/MainFrm.h (revision 7379)
+++ 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,7 @@
         CString m_sFindText;
         BOOL m_bMatchCase;
         bool m_bLimitToDiff;
+ bool m_bWholeWord;
         static const UINT m_FindDialogMessage;
         CFindDlg * m_pFindDialog;
         bool m_bHasConflicts;
Index: src/TortoiseMerge/resource.h
===================================================================
--- src/TortoiseMerge/resource.h (revision 7379)
+++ src/TortoiseMerge/resource.h (working copy)
@@ -1,6 +1,6 @@
 //{{NO_DEPENDENCIES}}
 // Microsoft Visual C++ generated include file.
-// Used by d:\Development\SVN\TortoiseSVN\src\Resources\TortoiseMergeENG.rc
+// Used by c:\Dev\SVN\TortoiseSVN\src\Resources\TortoiseMergeENG.rc
 //
 #define IDR_MAINFRAME 100
 #define IDP_OLE_INIT_FAILED 101
@@ -111,6 +111,7 @@
 #define IDC_DIFFBAR 1065
 #define IDC_LIMITTODIFFS 1065
 #define IDC_STRIKEOUT 1066
+#define IDC_WHOLEWORD 1066
 #define IDC_CHECK3 1067
 #define IDC_RESOLVE 1067
 #define IDC_CASEINSENSITIVE 1067

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tortoisesvn.tigris.org
For additional commands, e-mail: dev-help@tortoisesvn.tigris.org
Received on Thu Aug 31 21:27:15 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.