OSDN Git Service

"Open Dialog Auto-Completion" == "From MRU list" now fixed
authorGreyMerlin <GreyMerlin@gmail.com>
Tue, 4 Sep 2018 22:58:18 +0000 (15:58 -0700)
committerGreyMerlin <GreyMerlin@gmail.com>
Tue, 4 Sep 2018 22:58:18 +0000 (15:58 -0700)
 - The option "Open Dialog Auto-Completion" (on the "Options
(General)" setting page) failed to work correctly when set to the value
"From MRU list".  This appears to have been true since the
`2.13.11+-jp-8` commit on 04/18/2010 when the ComboBoxes for
file/folder selection were changed to use the the "ComboBoxEx32" common
control.  The failure occurs because `FindString()`, which is used in
`CSuperComboBox::OnEditchange()`, is only valid for CComboBox but not
CComboBoxEx.

 - This patch restores the "From MRU list" functionality, but
necessarily builds it upon the recent "Improvements to CSuperComboBox"
changes.

- It should also be noted that "From MRU list" provides a very limited
functionality when compared to the "From file system".  This was
true even with WinMerge versions 2.13.10 and earlier.

Src/Common/SuperComboBox.cpp
Src/Common/SuperComboBox.h

index 43dccc5..6cf3983 100644 (file)
@@ -152,6 +152,31 @@ int CSuperComboBox::InsertString(int nIndex, LPCTSTR lpszItem)
        }
 }
 
+int CSuperComboBox::FindString(int nStartAfter, LPCTSTR lpszString) const
+{
+       
+       if (m_bComboBoxEx)
+       {
+               ASSERT(m_bExtendedFileNames);
+               CString sSearchString = lpszString;
+               int nSearchStringLen = sSearchString.GetLength();
+               if (nSearchStringLen <= 0)
+                       return CB_ERR;
+               for (int i = nStartAfter+1; i < m_sFullStateText.size(); i++)
+               {
+                       CString sListString = m_sFullStateText[i];
+                       int nListStringLen = sListString.GetLength();
+                       if (nSearchStringLen <= nListStringLen && sSearchString.CompareNoCase(sListString.Left(nSearchStringLen))==0)
+                               return i;
+               }
+               return CB_ERR;
+       }
+       else
+       {
+               return CComboBox::FindString(nStartAfter, lpszString);
+       }
+}
+
 /**
  * @brief Gets the system image list and attaches the image list to a combo box control.
  */
@@ -300,7 +325,7 @@ BOOL CSuperComboBox::OnEditchange()
        
        // get the current selection
        DWORD sel = GetEditSel();
-       WORD start=LOWORD(sel), end=HIWORD(sel);
+       int start = (short)LOWORD(sel), end = (short)HIWORD(sel);
        
        // look for the string that is prefixed by the typed text
        int idx = FindString(-1, s);
@@ -309,20 +334,21 @@ BOOL CSuperComboBox::OnEditchange()
                // set the new string
                CString strNew;
                GetLBText(idx, strNew);
-               SetWindowText(strNew);         
-               
-               // get the caret back in the right spot
-               if (sel != CB_ERR)
-                       SetEditSel(start, end);  
+               SetWindowText(strNew);
        }
        
        // select the text after our typing
-       if (sel == CB_ERR
-               || end >= length)
-               SetEditSel(length, -1);
-       // restore the selection
+       if (sel == CB_ERR || end >= length)
+       {
+               start = length;
+               end = -1;
+       }
+
+       // get the caret back in the right spot
+       if (m_bComboBoxEx)
+               GetEditCtrl()->SetSel(start, end);
        else
-               SetEditSel(start, end);
+               CComboBox::SetEditSel(start, end);  
 
        return FALSE;
 }
index 940f7b5..cf81039 100644 (file)
@@ -67,6 +67,7 @@ public:
        bool AttachSystemImageList();
        int AddString(LPCTSTR lpszItem);
        int InsertString(int nIndex, LPCTSTR lpszItem);
+       int FindString(int nStartAfter, LPCTSTR lpszString) const;
        int GetLBTextLen(int nIndex) const;
        void GetLBText(int nIndex, CString &rString) const;