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

Re: SV: Re: TortoiseMerge Patch to Improve Searching

From: Jeremy Whitby <jeremy.whitby_at_googlemail.com>
Date: 2006-09-02 09:23:09 CEST

Jeremy Whitby wrote:
> Stefan Küng wrote:
>> I like the hotkeys, but not the idea of providing two buttons for
>> searching. One button should be enough (only search forward). If
>> someone wants to search backwards, just use shift-hotkey (shift-F3).
>>
>> Stefan
>>
> Please find attached a patch that implements (shift-F3) to search
> backwards.
>
> I hope the patch is of use
>
> Regards
>
> Jeremy Whitby
>

Oops, the original patch contained an off by 1 error that caused search
previous to ignore the top lines in files, please find attached a
slightly modified patch that does not.

I hope the patch is of use

Regards

Jeremy Whitby

Index: src/Resources/TortoiseMergeENG.rc
===================================================================
--- src/Resources/TortoiseMergeENG.rc (revision 7382)
+++ src/Resources/TortoiseMergeENG.rc (working copy)
@@ -402,6 +402,7 @@
     "T", ID_VIEW_WHITESPACES, VIRTKEY, CONTROL, NOINVERT
     VK_F8, ID_MERGE_NEXTCONFLICT, VIRTKEY, NOINVERT
     VK_F8, ID_MERGE_PREVIOUSCONFLICT, VIRTKEY, SHIFT, NOINVERT
+ VK_F3, ID_EDIT_FINDPREV, VIRTKEY, SHIFT, NOINVERT
 END
 
 
Index: src/TortoiseMerge/MainFrm.cpp
===================================================================
--- src/TortoiseMerge/MainFrm.cpp (revision 7382)
+++ src/TortoiseMerge/MainFrm.cpp (working copy)
@@ -63,6 +63,7 @@
         ON_COMMAND(ID_EDIT_FIND, OnEditFind)
         ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
         ON_COMMAND(ID_EDIT_FINDNEXT, OnEditFindnext)
+ ON_COMMAND(ID_EDIT_FINDPREV, OnEditFindprev)
         ON_COMMAND(ID_FILE_RELOAD, OnFileReload)
         ON_COMMAND(ID_VIEW_LINEDOWN, OnViewLinedown)
         ON_COMMAND(ID_VIEW_LINEUP, OnViewLineup)
@@ -1086,8 +1087,18 @@
         return bStringFound;
 }
 
+void CMainFrame::OnEditFindprev()
+{
+ Search(SearchPrevious);
+}
+
 void CMainFrame::OnEditFindnext()
 {
+ Search(SearchNext);
+}
+
+void CMainFrame::Search(SearchDirection srchDir)
+{
         if (m_sFindText.IsEmpty())
                 return;
 
@@ -1102,11 +1113,22 @@
                 CDiffData::DiffStates rightstate = CDiffData::DIFFSTATE_NORMAL;
                 CDiffData::DiffStates bottomstate = CDiffData::DIFFSTATE_NORMAL;
                 int i = 0;
- const int idxLimits[2][2]={{m_nSearchIndex, m_pwndLeftView->m_arDiffLines->GetCount()},
- {0, m_nSearchIndex}};
+
+ if (srchDir == SearchPrevious)
+ {
+ m_nSearchIndex -= 2; // SearchIndex points 1 past where we found the last match, so if we are searching backwards we need to adjust accordingly
+ if (m_nSearchIndex < 0)
+ m_nSearchIndex += m_pwndLeftView->m_arDiffLines->GetCount();
+ }
+ const int idxLimits[2][2][2]={{{m_nSearchIndex, m_pwndLeftView->m_arDiffLines->GetCount()},
+ {0, m_nSearchIndex}},
+ {{m_nSearchIndex, -1},
+ {m_pwndLeftView->m_arDiffLines->GetCount()-1, m_nSearchIndex}}};
+ const int offsets[2]={+1, -1};
+
                 for (int j=0; j != 2 && !bFound; ++j)
                 {
- for (i=idxLimits[j][0]; i != idxLimits[j][1]; i++)
+ for (i=idxLimits[srchDir][j][0]; i != idxLimits[srchDir][j][1]; i += offsets[srchDir])
                         {
                                 left = m_pwndLeftView->m_arDiffLines->GetAt(i);
                                 leftstate = (CDiffData::DiffStates)m_pwndLeftView->m_arLineStates->GetAt(i);
Index: src/TortoiseMerge/MainFrm.h
===================================================================
--- src/TortoiseMerge/MainFrm.h (revision 7382)
+++ src/TortoiseMerge/MainFrm.h (working copy)
@@ -59,6 +59,7 @@
         afx_msg void OnClose();
         afx_msg void OnEditFind();
         afx_msg void OnEditFindnext();
+ afx_msg void OnEditFindprev();
         afx_msg void OnViewWhitespaces();
         afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
         afx_msg void OnSize(UINT nType, int cx, int cy);
@@ -96,6 +97,9 @@
         bool FileSave();
         bool FileSaveAs();
         bool StringFound(const CString&)const;
+ enum SearchDirection{SearchNext=0, SearchPrevious=1};
+ void Search(SearchDirection);
+
 protected:
         CStatusBar m_wndStatusBar;
         CNewToolBar m_wndToolBar;
Index: src/TortoiseMerge/resource.h
===================================================================
--- src/TortoiseMerge/resource.h (revision 7382)
+++ src/TortoiseMerge/resource.h (working copy)
@@ -194,13 +194,14 @@
 #define ID_VIEW_LINERIGHT 32814
 #define ID_BUTTON32816 32816
 #define ID_VIEW_SHOWFILELIST 32817
+#define ID_EDIT_FINDPREV 32818
 
 // Next default values for new objects
 //
 #ifdef APSTUDIO_INVOKED
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_NEXT_RESOURCE_VALUE 141
-#define _APS_NEXT_COMMAND_VALUE 32818
+#define _APS_NEXT_COMMAND_VALUE 32819
 #define _APS_NEXT_CONTROL_VALUE 1071
 #define _APS_NEXT_SYMED_VALUE 101
 #endif

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tortoisesvn.tigris.org
For additional commands, e-mail: dev-help@tortoisesvn.tigris.org
Received on Sat Sep 2 09:23:22 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.