Fixed issue #1741: Push / Pull Dialog URL combo box should not be filled unless enabled
[TortoiseGit.git] / src / Utils / MiscUI / HistoryCombo.h
blob5f54ab03a3ffa0c079952601b2abfaa490a27ccb
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.
19 #pragma once
21 /**
22 * \ingroup Utils
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
31 * CHistoryCombo
32 * -# in your OnInitDialog() call SetURLHistory(TRUE) if your ComboBox
33 * contains URLs
34 * -# in your OnInitDialog() call the LoadHistory() method
35 * -# in your OnOK() or somewhere similar call the SaveHistory() method
37 * thats it.
39 #include "git.h"
40 class CHistoryCombo : public CComboBoxEx
42 // Construction
43 public:
44 CHistoryCombo(BOOL bAllowSortStyle = FALSE);
45 virtual ~CHistoryCombo();
47 bool m_bWantReturn;
48 // Operations
49 public:
50 /**
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
58 protected:
59 DECLARE_MESSAGE_MAP()
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);
68 void CreateToolTip();
70 // Implementation
71 public:
72 /**
73 * Clears the history in the registry/inifile and the ComboBox.
74 * \param bDeleteRegistryEntries if this value is true then the registry key
75 * itself is deleted.
77 void ClearHistory(BOOL bDeleteRegistryEntries = TRUE);
79 void Reset(){ ResetContent(); m_arEntries.RemoveAll(); };
80 /**
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);
87 /**
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);
94 /**
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
103 * does nothing!
105 void SaveHistory();
107 * Loads the history from the registry/inifile and fills in the
108 * ComboBox.
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();
128 * Disables trimming of strings in the combobox. Useful if the combo box is
129 * used e.g. for searching.
131 void DisableTrimming() { m_bTrim = false; }
133 protected:
135 * Will be called whenever the return key is pressed while the
136 * history combo has the input focus. A derived class may implement
137 * a special behavior for the return key by overriding this method.
138 * It must return true to prevent the default processing for the
139 * return key. The default implementation returns false.
141 virtual bool OnReturnKeyPressed() { return m_bWantReturn; }
143 protected:
144 CStringArray m_arEntries;
145 CString m_sSection;
146 CString m_sKeyPrefix;
147 int m_nMaxHistoryItems;
148 BOOL m_bAllowSortStyle;
149 BOOL m_bURLHistory;
150 BOOL m_bPathHistory;
151 HWND m_hWndToolTip;
152 TOOLINFO m_ToolInfo;
153 BOOL m_ttShown;
154 BOOL m_bDyn;
155 BOOL m_bTrim;