HistoryCombo show icon for git and ssh protocol
[TortoiseGit.git] / src / Utils / MiscUI / HistoryCombo.h
blob2a320687f0deea5415908d79cf084fe47b2005e8
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.
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(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 // Implementation
72 public:
73 /**
74 * Clears the history in the registry/inifile and the ComboBox.
75 * \param bDeleteRegistryEntries if this value is true then the registry key
76 * itself is deleted.
78 void ClearHistory(BOOL bDeleteRegistryEntries = TRUE);
80 void Reset(){ ResetContent(); m_arEntries.RemoveAll(); };
81 /**
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);
88 /**
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);
95 /**
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
104 * does nothing!
106 void SaveHistory();
108 * Loads the history from the registry/inifile and fills in the
109 * ComboBox.
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);
138 static int m_nGitIconIndex;
140 protected:
142 * Will be called whenever the return key is pressed while the
143 * history combo has the input focus. A derived class may implement
144 * a special behavior for the return key by overriding this method.
145 * It must return true to prevent the default processing for the
146 * return key. The default implementation returns false.
148 virtual bool OnReturnKeyPressed() { return m_bWantReturn; }
150 protected:
151 CStringArray m_arEntries;
152 CString m_sSection;
153 CString m_sKeyPrefix;
154 int m_nMaxHistoryItems;
155 BOOL m_bAllowSortStyle;
156 BOOL m_bURLHistory;
157 BOOL m_bPathHistory;
158 HWND m_hWndToolTip;
159 TOOLINFO m_ToolInfo;
160 CString m_ToolText;
161 BOOL m_ttShown;
162 BOOL m_bDyn;
163 BOOL m_bTrim;
164 BOOL m_bCaseSensitive;