1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - 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();
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(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 virtual BOOL
PreCreateWindow(CREATESTRUCT
& cs
);
62 virtual BOOL
PreTranslateMessage(MSG
* pMsg
);
63 virtual void PreSubclassWindow();
65 afx_msg
void OnMouseMove(UINT nFlags
, CPoint point
);
66 afx_msg
void OnTimer(UINT_PTR nIDEvent
);
67 afx_msg
int OnCreate(LPCREATESTRUCT lpCreateStruct
);
74 * Clears the history in the registry/inifile and the ComboBox.
75 * \param bDeleteRegistryEntries if this value is true then the registry key
78 void ClearHistory(BOOL bDeleteRegistryEntries
= TRUE
);
80 void Reset(){ ResetContent(); m_arEntries
.RemoveAll(); };
82 * When \a bURLHistory is TRUE, treat the combo box entries
83 * as URLs. This activates Shell URL auto completion and
84 * the display of special icons in front of the combobox
85 * entries. Default is FALSE.
87 void SetURLHistory(BOOL bURLHistory
);
89 * When \a bPathHistory is TRUE, treat the combo box entries
90 * as Paths. This activates Shell Path auto completion and
91 * the display of special icons in front of the combobox
92 * entries. Default is FALSE.
94 void SetPathHistory(BOOL bPathHistory
);
96 * Sets the maximum numbers of entries in the history list.
97 * If the history is larger as \em nMaxItems then the last
98 * items in the history are deleted.
100 void SetMaxHistoryItems(int nMaxItems
);
102 * Saves the history to the registry/inifile.
103 * \remark if you haven't called LoadHistory() before this method
108 * Loads the history from the registry/inifile and fills in the
110 * \param lpszSection a section name where to put the entries, e.g. "lastloadedfiles"
111 * \param lpszKeyPrefix a prefix to use for the history entries in registry/inifiles. E.g. "file" or "entry"
113 CString
LoadHistory(LPCTSTR lpszSection
, LPCTSTR lpszKeyPrefix
);
116 * Returns the string in the combobox which is either selected or the user has entered.
118 CString
GetString() const;
120 void AddString(STRING_VECTOR
&list
,BOOL isSel
=true);
123 * Removes the selected item from the combo box and updates
124 * the registry settings. Returns TRUE if successful.
126 BOOL
RemoveSelectedItem();
129 * Disables trimming of strings in the combobox. Useful if the combo box is
130 * used e.g. for searching.
132 void DisableTrimming() { m_bTrim
= false; }
134 void SetCaseSensitive(BOOL bCaseSensitive
) { m_bCaseSensitive
= bCaseSensitive
; }
136 int FindStringExactCaseSensitive(int nIndexStart
, LPCTSTR lpszFind
);
140 * Will be called whenever the return key is pressed while the
141 * history combo has the input focus. A derived class may implement
142 * a special behavior for the return key by overriding this method.
143 * It must return true to prevent the default processing for the
144 * return key. The default implementation returns false.
146 virtual bool OnReturnKeyPressed() { return m_bWantReturn
; }
149 CStringArray m_arEntries
;
151 CString m_sKeyPrefix
;
152 int m_nMaxHistoryItems
;
153 BOOL m_bAllowSortStyle
;
162 BOOL m_bCaseSensitive
;