1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoioseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 * Extends the CComboBoxEx class with a history of entered
24 * values. An example of such a combobox is the Start/Run
25 * dialog which lists the programs you used last in a combobox.
26 * To use this class do the following:
27 * -# add both files HistoryCombo.h and HistoryCombo.cpp to your project.
28 * -# add a ComboBoxEx to your dialog
29 * -# create a variable for the ComboBox of type control
30 * -# change the type of the created variable from CComboBoxEx to
32 * -# in your OnInitDialog() call SetURLHistory(TRUE) if your ComboBox
34 * -# in your OnInitDialog() call the LoadHistory() method
35 * -# in your OnOK() or somewhere similar call the SaveHistory() method
40 class CHistoryCombo
: public CComboBoxEx
44 CHistoryCombo(BOOL bAllowSortStyle
= FALSE
);
45 virtual ~CHistoryCombo();
51 * Adds the string \a str to both the combobox and the history.
52 * If \a pos is specified, insert the string at the specified
53 * position, otherwise add it to the end of the list.
55 int AddString(CString str
, INT_PTR pos
= -1, BOOL isSel
= true);
57 void DisableTooltip(){m_bDyn
= FALSE
;} //because rebase need disable combox tooltip to show version info
60 virtual BOOL
PreCreateWindow(CREATESTRUCT
& cs
);
61 virtual BOOL
PreTranslateMessage(MSG
* pMsg
);
62 virtual void PreSubclassWindow();
64 afx_msg
void OnMouseMove(UINT nFlags
, CPoint point
);
65 afx_msg
void OnTimer(UINT_PTR nIDEvent
);
66 afx_msg
int OnCreate(LPCREATESTRUCT lpCreateStruct
);
73 * Clears the history in the registry/inifile and the ComboBox.
74 * \param bDeleteRegistryEntries if this value is true then the registry key
77 void ClearHistory(BOOL bDeleteRegistryEntries
= TRUE
);
79 void Reset(){ ResetContent(); m_arEntries
.RemoveAll(); };
81 * When \a bURLHistory is TRUE, treat the combo box entries
82 * as URLs. This activates Shell URL auto completion and
83 * the display of special icons in front of the combobox
84 * entries. Default is FALSE.
86 void SetURLHistory(BOOL bURLHistory
);
88 * When \a bPathHistory is TRUE, treat the combo box entries
89 * as Paths. This activates Shell Path auto completion and
90 * the display of special icons in front of the combobox
91 * entries. Default is FALSE.
93 void SetPathHistory(BOOL bPathHistory
);
95 * Sets the maximum numbers of entries in the history list.
96 * If the history is larger as \em nMaxItems then the last
97 * items in the history are deleted.
99 void SetMaxHistoryItems(int nMaxItems
);
101 * Saves the history to the registry/inifile.
102 * \remark if you haven't called LoadHistory() before this method
107 * Loads the history from the registry/inifile and fills in the
109 * \param lpszSection a section name where to put the entries, e.g. "lastloadedfiles"
110 * \param lpszKeyPrefix a prefix to use for the history entries in registry/inifiles. E.g. "file" or "entry"
112 CString
LoadHistory(LPCTSTR lpszSection
, LPCTSTR lpszKeyPrefix
);
115 * Returns the string in the combobox which is either selected or the user has entered.
117 CString
GetString() const;
119 void AddString(STRING_VECTOR
&list
,BOOL isSel
=true);
122 * Removes the selected item from the combo box and updates
123 * the registry settings. Returns TRUE if successful.
125 BOOL
RemoveSelectedItem();
129 * Will be called whenever the return key is pressed while the
130 * history combo has the input focus. A derived class may implement
131 * a special behavior for the return key by overriding this method.
132 * It must return true to prevent the default processing for the
133 * return key. The default implementation returns false.
135 virtual bool OnReturnKeyPressed() { return m_bWantReturn
; }
138 CStringArray m_arEntries
;
140 CString m_sKeyPrefix
;
141 int m_nMaxHistoryItems
;
142 BOOL m_bAllowSortStyle
;