LogList Search Dialog: Do not double sort refs
[TortoiseGit.git] / src / TortoiseProc / HistoryDlg.cpp
blobbd53c9636e0a4a7bfddc9f238a1742b9fe8a9c10
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008,2011 - TortoiseSVN
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.
20 #include "stdafx.h"
21 #include "TortoiseProc.h"
22 #include "registry.h"
23 #include "HistoryDlg.h"
26 IMPLEMENT_DYNAMIC(CHistoryDlg, CResizableStandAloneDialog)
27 CHistoryDlg::CHistoryDlg(CWnd* pParent /*=NULL*/)
28 : CResizableStandAloneDialog(CHistoryDlg::IDD, pParent)
30 m_history = NULL;
33 CHistoryDlg::~CHistoryDlg()
37 void CHistoryDlg::DoDataExchange(CDataExchange* pDX)
39 CResizableStandAloneDialog::DoDataExchange(pDX);
40 DDX_Control(pDX, IDC_HISTORYLIST, m_List);
44 BEGIN_MESSAGE_MAP(CHistoryDlg, CResizableStandAloneDialog)
45 ON_BN_CLICKED(IDOK, OnBnClickedOk)
46 ON_LBN_DBLCLK(IDC_HISTORYLIST, OnLbnDblclkHistorylist)
47 ON_WM_KEYDOWN()
48 END_MESSAGE_MAP()
51 void CHistoryDlg::OnBnClickedOk()
53 int pos = m_List.GetCurSel();
54 if (pos != LB_ERR)
56 m_SelectedText = m_history->GetEntry(pos);
58 else
59 m_SelectedText.Empty();
60 OnOK();
63 BOOL CHistoryDlg::OnInitDialog()
65 CResizableStandAloneDialog::OnInitDialog();
67 // calculate and set listbox width
68 CDC* pDC=m_List.GetDC();
69 CSize itemExtent;
70 int horizExtent = 1;
71 for (size_t i = 0; i < m_history->GetCount(); ++i)
73 CString sEntry = m_history->GetEntry(i);
74 sEntry.Remove('\r');
75 sEntry.Replace('\n', ' ');
76 m_List.AddString(sEntry);
77 itemExtent = pDC->GetTextExtent(sEntry);
78 horizExtent = max(horizExtent, itemExtent.cx+5);
80 m_List.SetHorizontalExtent(horizExtent);
81 ReleaseDC(pDC);
83 AddAnchor(IDC_HISTORYLIST, TOP_LEFT, BOTTOM_RIGHT);
84 AddAnchor(IDOK, BOTTOM_RIGHT);
85 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
86 EnableSaveRestore(_T("HistoryDlg"));
87 m_List.SetFocus();
88 return FALSE;
91 void CHistoryDlg::OnLbnDblclkHistorylist()
93 int pos = m_List.GetCurSel();
94 if (pos != LB_ERR)
96 m_SelectedText = m_history->GetEntry(pos);
97 OnOK();
99 else
100 m_SelectedText.Empty();
103 BOOL CHistoryDlg::PreTranslateMessage(MSG* pMsg)
105 if ((pMsg->message == WM_KEYDOWN) && (pMsg->wParam == VK_DELETE))
107 int pos = m_List.GetCurSel();
108 if (pos != LB_ERR)
110 m_List.DeleteString(pos);
111 m_List.SetCurSel(min(pos, m_List.GetCount() - 1));
112 m_history->RemoveEntry(pos);
113 m_history->Save();
114 return TRUE;
118 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);