Fixed issue #2507: Support keyboard shortcuts in yes/no prompts
[TortoiseGit.git] / src / Utils / MiscUI / HistoryCombo.h
blob3ad0fc7c3a0b9a02df70a277103e6bdc11e0cfe5
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2014 - 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.
20 #pragma once
22 /**
23 * \ingroup Utils
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
32 * CHistoryCombo
33 * -# in your OnInitDialog() call SetURLHistory(TRUE) if your ComboBox
34 * contains URLs
35 * -# in your OnInitDialog() call the LoadHistory() method
36 * -# in your OnOK() or somewhere similar call the SaveHistory() method
38 * thats it.
40 #include "Git.h"
41 class CHistoryCombo : public CComboBoxEx
43 // Construction
44 public:
45 CHistoryCombo(BOOL bAllowSortStyle = FALSE);
46 virtual ~CHistoryCombo();
48 bool m_bWantReturn;
49 // Operations
50 public:
51 /**
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
59 protected:
60 DECLARE_MESSAGE_MAP()
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);
69 void CreateToolTip();
71 private:
72 /**
73 * Inserts an entry into the combobox
75 int InsertEntry(const CString& combostring, INT_PTR pos);
77 // Implementation
78 public:
79 /**
80 * Clears the history in the registry/inifile and the ComboBox.
81 * \param bDeleteRegistryEntries if this value is true then the registry key
82 * itself is deleted.
84 void ClearHistory(BOOL bDeleteRegistryEntries = TRUE);
86 void Reset(){ ResetContent(); m_arEntries.RemoveAll(); };
87 /**
88 * When \a bURLHistory is TRUE, treat the combo box entries
89 * as URLs. This activates Shell URL auto completion and
90 * the display of special icons in front of the combobox
91 * entries. Default is FALSE.
93 void SetURLHistory(BOOL bURLHistory);
94 /**
95 * When \a bPathHistory is TRUE, treat the combo box entries
96 * as Paths. This activates Shell Path auto completion and
97 * the display of special icons in front of the combobox
98 * entries. Default is FALSE.
100 void SetPathHistory(BOOL bPathHistory);
102 * Sets the maximum numbers of entries in the history list.
103 * If the history is larger as \em nMaxItems then the last
104 * items in the history are deleted.
106 void SetMaxHistoryItems(int nMaxItems);
108 * Saves the history to the registry/inifile.
109 * \remark if you haven't called LoadHistory() before this method
110 * does nothing!
112 void SaveHistory();
114 * Loads the history from the registry/inifile and fills in the
115 * ComboBox.
116 * \param lpszSection a section name where to put the entries, e.g. "lastloadedfiles"
117 * \param lpszKeyPrefix a prefix to use for the history entries in registry/inifiles. E.g. "file" or "entry"
119 CString LoadHistory(LPCTSTR lpszSection, LPCTSTR lpszKeyPrefix);
122 * Goes through the stored history in registry and removes a specific entry
124 static void RemoveEntryFromHistory(LPCTSTR lpszSection, LPCTSTR lpszKeyPrefix, const CString& entryToRemove);
127 * Returns the string in the combobox which is either selected or the user has entered.
129 CString GetString() const;
132 * Populates the combobox with the items provided in the list, existing
133 * items will be removed.
134 * No checks for duplicates are performed!
136 void SetList(const STRING_VECTOR& list);
139 * Removes the selected item from the combo box and updates
140 * the registry settings. Returns TRUE if successful.
142 BOOL RemoveSelectedItem();
145 * Disables trimming of strings in the combobox. Useful if the combo box is
146 * used e.g. for searching.
148 void DisableTrimming() { m_bTrim = false; }
150 void SetCaseSensitive(BOOL bCaseSensitive) { m_bCaseSensitive = bCaseSensitive; }
152 int FindStringExactCaseSensitive(int nIndexStart, LPCTSTR lpszFind);
154 static int m_nGitIconIndex;
156 protected:
158 * Will be called whenever the return key is pressed while the
159 * history combo has the input focus. A derived class may implement
160 * a special behavior for the return key by overriding this method.
161 * It must return true to prevent the default processing for the
162 * return key. The default implementation returns false.
164 virtual bool OnReturnKeyPressed() { return m_bWantReturn; }
166 protected:
167 CStringArray m_arEntries;
168 CString m_sSection;
169 CString m_sKeyPrefix;
170 int m_nMaxHistoryItems;
171 BOOL m_bAllowSortStyle;
172 BOOL m_bURLHistory;
173 BOOL m_bPathHistory;
174 HWND m_hWndToolTip;
175 TOOLINFO m_ToolInfo;
176 CString m_ToolText;
177 BOOL m_ttShown;
178 BOOL m_bDyn;
179 BOOL m_bTrim;
180 BOOL m_bCaseSensitive;