1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2014, 2020-2023 - TortoiseGit
4 // Copyright (C) 2003-2008 - TortoioseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * Extends the CComboBoxEx class with a history of entered
25 * values. An example of such a combobox is the Start/Run
26 * dialog which lists the programs you used last in a combobox.
27 * To use this class do the following:
28 * -# add both files HistoryCombo.h and HistoryCombo.cpp to your project.
29 * -# add a ComboBoxEx to your dialog
30 * -# create a variable for the ComboBox of type control
31 * -# change the type of the created variable from CComboBoxEx to
33 * -# in your OnInitDialog() call SetURLHistory(TRUE) if your ComboBox
35 * -# in your OnInitDialog() call the LoadHistory() method
36 * -# in your OnOK() or somewhere similar call the SaveHistory() method
41 class CHistoryCombo
: public CComboBoxEx
45 CHistoryCombo(BOOL bAllowSortStyle
= FALSE
);
46 virtual ~CHistoryCombo();
48 bool m_bWantReturn
= false;
52 * Adds the string \a str to both the combobox and the history.
53 * If \a pos is specified, insert the string at the specified
54 * position, otherwise add it to the end of the list.
56 int AddString(const CString
& str
, INT_PTR pos
= -1, BOOL isSel
= true);
58 void DisableTooltip(){m_bDyn
= FALSE
;} //because rebase need disable combox tooltip to show version info
61 BOOL
PreCreateWindow(CREATESTRUCT
& cs
) override
;
62 BOOL
PreTranslateMessage(MSG
* pMsg
) override
;
63 void PreSubclassWindow() override
;
65 afx_msg
void OnMouseMove(UINT nFlags
, CPoint point
);
66 afx_msg
void OnTimer(UINT_PTR nIDEvent
);
67 afx_msg
int OnCreate(LPCREATESTRUCT lpCreateStruct
);
68 afx_msg LRESULT
OnPaste(WPARAM
, LPARAM
);
70 static WNDPROC lpfnEditWndProc
;
71 static LRESULT CALLBACK
SubClassProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
77 * Inserts an entry into the combobox
79 int InsertEntry(const CString
& combostring
, INT_PTR pos
);
80 void SetEditWndProc();
85 * Clears the history in the registry/inifile and the ComboBox.
86 * \param bDeleteRegistryEntries if this value is true then the registry key
89 void ClearHistory(BOOL bDeleteRegistryEntries
= TRUE
);
91 void Reset(){ ResetContent(); m_arEntries
.RemoveAll(); };
93 * When \a bURLHistory is TRUE, treat the combo box entries
94 * as URLs. This activates Shell URL auto completion and
95 * the display of special icons in front of the combobox
96 * entries. Default is FALSE.
98 void SetURLHistory(BOOL bURLHistory
);
100 * When \a bPathHistory is TRUE, treat the combo box entries
101 * as Paths. This activates Shell Path auto completion and
102 * the display of special icons in front of the combobox
103 * entries. Default is FALSE.
105 void SetPathHistory(BOOL bPathHistory
);
106 void SetCustomAutoSuggest(BOOL listEntries
, BOOL bPathHistory
, BOOL bURLHistory
);
108 * Sets the maximum numbers of entries in the history list.
109 * If the history is larger as \em nMaxItems then the last
110 * items in the history are deleted.
112 void SetMaxHistoryItems(int nMaxItems
);
114 * Allows to configure whether entries can be deleted by the user by opening the
115 * drop-down box, selecting an item by mouse over, and pressing SHIFT+DEL.
117 void SetAllowDelete(bool allowDelete
) { m_bAllowDelete
= allowDelete
; }
119 * Saves the history to the registry/inifile.
120 * \remark if you haven't called LoadHistory() before this method
125 * Loads the history from the registry/inifile and fills in the
127 * \param lpszSection a section name where to put the entries, e.g. "lastloadedfiles"
128 * \param lpszKeyPrefix a prefix to use for the history entries in registry/inifiles. E.g. "file" or "entry"
130 CString
LoadHistory(LPCWSTR lpszSection
, LPCWSTR lpszKeyPrefix
, bool allowUserDelete
= true);
133 * Goes through the stored history in registry and removes a specific entry
135 static void RemoveEntryFromHistory(LPCWSTR lpszSection
, LPCWSTR lpszKeyPrefix
, const CString
& entryToRemove
);
138 * Returns the string in the combobox which is either selected or the user has entered.
140 CString
GetString() const;
143 * Populates the combobox with the items provided in the list, existing
144 * items will be removed.
145 * No checks for duplicates are performed!
147 void SetList(const STRING_VECTOR
& list
);
150 * Removes the selected item from the combo box and updates
151 * the registry settings. Returns TRUE if successful.
153 BOOL
RemoveSelectedItem();
156 * Disables trimming of strings in the combobox. Useful if the combo box is
157 * used e.g. for searching.
159 void DisableTrimming() { m_bTrim
= false; }
161 void SetCaseSensitive(BOOL bCaseSensitive
) { m_bCaseSensitive
= bCaseSensitive
; }
162 void SetCheckDuplicate(BOOL bCheckDuplicate
) { m_bCheckDuplicate
= bCheckDuplicate
; }
164 int FindStringExactCaseSensitive(int nIndexStart
, LPCWSTR lpszFind
);
166 static int m_nGitIconIndex
;
170 * Will be called whenever the return key is pressed while the
171 * history combo has the input focus. A derived class may implement
172 * a special behavior for the return key by overriding this method.
173 * It must return true to prevent the default processing for the
174 * return key. The default implementation returns false.
176 virtual bool OnReturnKeyPressed() const { return m_bWantReturn
; }
179 CStringArray m_arEntries
;
181 CString m_sKeyPrefix
;
182 int m_nMaxHistoryItems
;
183 BOOL m_bAllowSortStyle
= FALSE
;
184 BOOL m_bURLHistory
= FALSE
;
185 BOOL m_bPathHistory
= FALSE
;
186 HWND m_hWndToolTip
= nullptr;
187 TOOLINFO m_ToolInfo
{};
189 BOOL m_ttShown
= FALSE
;
192 BOOL m_bCaseSensitive
= FALSE
;
193 BOOL m_bCheckDuplicate
= TRUE
;
194 bool m_bAllowDelete
= false;
197 class CCustomAutoCompleteSource
: public IEnumString
200 CCustomAutoCompleteSource(const CStringArray
& pData
);
203 HRESULT STDMETHODCALLTYPE
QueryInterface(REFIID riid
, void** ppvObject
) override
;
204 ULONG STDMETHODCALLTYPE
AddRef() override
;
205 ULONG STDMETHODCALLTYPE
Release() override
;
208 HRESULT STDMETHODCALLTYPE
Clone(IEnumString
** ppenum
) override
;
209 HRESULT STDMETHODCALLTYPE
Next(ULONG celt
, LPOLESTR
* rgelt
, ULONG
* pceltFetched
) override
;
210 HRESULT STDMETHODCALLTYPE
Reset() override
;
211 HRESULT STDMETHODCALLTYPE
Skip(ULONG celt
) override
;
214 volatile ULONG m_cRefCount
= 0;
216 const CStringArray
& m_pData
;