return true;
}
-void CSuperComboBox::LoadState(LPCTSTR szRegSubKey, bool bCanBeEmpty /*=false */, int nMaxItems /*=20 */)
+void CSuperComboBox::LoadState(LPCTSTR szRegSubKey, bool bCanBeEmpty /*= false*/, int nMaxItems /*= 20*/)
{
- CString s,s2;
bool bIsEmpty = false;
if( bCanBeEmpty )
bIsEmpty = (AfxGetApp()->GetProfileInt(szRegSubKey, _T("Empty"), FALSE) == TRUE);
int cnt = AfxGetApp()->GetProfileInt(szRegSubKey, _T("Count"), 0);
- for (int i=0; i < cnt && i < nMaxItems; i++)
+ int idx = 0;
+ for (int i=0; i < cnt && idx < nMaxItems; i++)
{
- s2.Format(_T("Item_%u"), i);
+ CString s,s2;
+ s2.Format(_T("Item_%d"), i);
s = AfxGetApp()->GetProfileString(szRegSubKey, s2);
if (FindStringExact(-1, s) == CB_ERR && !s.IsEmpty())
+ {
AddString(s);
+ idx++;
+ }
}
- if (cnt > 0)
+ if (idx > 0)
if( bIsEmpty )
{
SetCurSel(-1);
void CSuperComboBox::GetLBText(int nIndex, CString &rString) const
{
ASSERT(::IsWindow(m_hWnd));
+
+ if (nIndex==0 && IsComboBoxEx())
+ {
+ GetEditCtrl()->GetWindowText(rString);
+ if (!rString.IsEmpty())
+ return;
+ }
CComboBoxEx::GetLBText(nIndex, rString.GetBufferSetLength(GetLBTextLen(nIndex)));
rString.ReleaseBuffer();
}
* before saving. Empty strings are not saved. So strings which have only
* whitespace characters aren't save either.
* @param [in] szRegSubKey Registry subkey where to save strings.
+ * @param [in] bCanBeEmpty
* @param [in] nMaxItems Max number of strings to save.
*/
-void CSuperComboBox::SaveState(LPCTSTR szRegSubKey, bool bCanBeEmpty /*=false */, int nMaxItems /*=20 */)
+void CSuperComboBox::SaveState(LPCTSTR szRegSubKey, bool bCanBeEmpty /*= false*/, int nMaxItems /*= 20*/)
{
- CString strItem,s,s2;
- int idx = 0;
-
+ CString strItem;
if (IsComboBoxEx())
GetEditCtrl()->GetWindowText(strItem);
else
GetWindowText(strItem);
+ strItem.TrimLeft();
+ strItem.TrimRight();
+
+ int idx = 0;
if (!strItem.IsEmpty())
{
AfxGetApp()->WriteProfileString(szRegSubKey, _T("Item_0"), strItem);
idx=1;
}
+
int cnt = GetCount();
- for (int i=idx; i < cnt && i < nMaxItems; i++)
- {
+ for (int i=0; i < cnt && idx < nMaxItems; i++)
+ {
+ CString s;
GetLBText(i, s);
s.TrimLeft();
s.TrimRight();
if (s != strItem && !s.IsEmpty())
{
+ CString s2;
s2.Format(_T("Item_%d"), idx);
AfxGetApp()->WriteProfileString(szRegSubKey, s2, s);
idx++;
AfxGetApp()->WriteProfileInt(szRegSubKey, _T("Count"), idx);
if (bCanBeEmpty)
- AfxGetApp()->WriteProfileInt(_T("Files\\Option"), _T("Empty"), strItem.IsEmpty());
+ AfxGetApp()->WriteProfileInt(szRegSubKey, _T("Empty"), strItem.IsEmpty());
}
BOOL CSuperComboBox::OnSelchange()
{
- m_bEditChanged=FALSE;
+ m_bEditChanged = false;
CString strCurSel;
GetWindowText(strCurSel);
m_bDoComplete = true;
if (nVirtKey == VK_DELETE || nVirtKey == VK_BACK)
- m_bDoComplete = FALSE;
+ m_bDoComplete = false;
}
}
/**
* @brief Called when dialog is closed via Cancel.
*
- * Open-dialog is closed when 'Cancel' button is selected or
- * Esc-key is pressed. It is *not* called when the program is
- * terminated, even if the dialog is visible at the time.
+ * Open-dialog is closed when `Cancel` button is selected or the
+ * `Esc` key is pressed. Save combobox states, since user may have
+ * removed items from them (with `shift-del`) and doesn't want them
+ * to re-appear.
+ * This is *not* called when the program is terminated, even if the
+ * dialog is visible at the time.
*/
void COpenView::OnCancel()
{
+ SaveComboboxStates();
AfxGetMainWnd()->PostMessage(WM_COMMAND, ID_FILE_CLOSE);
}