OSDN Git Service

igit added as submodule
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / HistoryDlg.cpp
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2003-2008 - TortoiseSVN\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 \r
20 #include "stdafx.h"\r
21 #include "TortoiseProc.h"\r
22 #include "Registry.h"\r
23 #include "HistoryDlg.h"\r
24 \r
25 \r
26 IMPLEMENT_DYNAMIC(CHistoryDlg, CResizableStandAloneDialog)\r
27 CHistoryDlg::CHistoryDlg(CWnd* pParent /*=NULL*/)\r
28         : CResizableStandAloneDialog(CHistoryDlg::IDD, pParent)\r
29 {\r
30 }\r
31 \r
32 CHistoryDlg::~CHistoryDlg()\r
33 {\r
34 }\r
35 \r
36 void CHistoryDlg::DoDataExchange(CDataExchange* pDX)\r
37 {\r
38         CResizableStandAloneDialog::DoDataExchange(pDX);\r
39         DDX_Control(pDX, IDC_HISTORYLIST, m_List);\r
40 }\r
41 \r
42 \r
43 BEGIN_MESSAGE_MAP(CHistoryDlg, CResizableStandAloneDialog)\r
44         ON_BN_CLICKED(IDOK, OnBnClickedOk)\r
45         ON_LBN_DBLCLK(IDC_HISTORYLIST, OnLbnDblclkHistorylist)\r
46         ON_WM_KEYDOWN()\r
47 END_MESSAGE_MAP()\r
48 \r
49 \r
50 void CHistoryDlg::OnBnClickedOk()\r
51 {\r
52         int pos = m_List.GetCurSel();\r
53         if (pos != LB_ERR)\r
54         {\r
55                 m_SelectedText = m_history->GetEntry(pos);\r
56         }\r
57         else\r
58                 m_SelectedText.Empty();\r
59         OnOK();\r
60 }\r
61 \r
62 BOOL CHistoryDlg::OnInitDialog()\r
63 {\r
64         CResizableStandAloneDialog::OnInitDialog();\r
65 \r
66         // calculate and set listbox width\r
67         CDC* pDC=m_List.GetDC();\r
68         CSize itemExtent;\r
69         int horizExtent = 1;\r
70         for (size_t i = 0; i < m_history->GetCount(); ++i)\r
71         {\r
72                 CString sEntry = m_history->GetEntry(i);\r
73                 sEntry.Replace(_T("\r"), _T(""));\r
74                 sEntry.Replace('\n', ' ');\r
75                 m_List.AddString(sEntry);\r
76                 itemExtent = pDC->GetTextExtent(sEntry);\r
77                 horizExtent = max(horizExtent, itemExtent.cx+5);\r
78         }\r
79         m_List.SetHorizontalExtent(horizExtent);\r
80         ReleaseDC(pDC); \r
81 \r
82         AddAnchor(IDC_HISTORYLIST, TOP_LEFT, BOTTOM_RIGHT);\r
83         AddAnchor(IDOK, BOTTOM_RIGHT);\r
84         AddAnchor(IDCANCEL, BOTTOM_RIGHT);\r
85         EnableSaveRestore(_T("HistoryDlg"));\r
86         m_List.SetFocus();\r
87         return FALSE;\r
88 }\r
89 \r
90 void CHistoryDlg::OnLbnDblclkHistorylist()\r
91 {\r
92         int pos = m_List.GetCurSel();\r
93         if (pos != LB_ERR)\r
94         {\r
95                 m_SelectedText = m_history->GetEntry(pos);\r
96                 OnOK();\r
97         }\r
98         else\r
99                 m_SelectedText.Empty();\r
100 }\r
101 \r
102 BOOL CHistoryDlg::PreTranslateMessage(MSG* pMsg)\r
103 {\r
104         if ((pMsg->message == WM_KEYDOWN) && (pMsg->wParam == VK_DELETE))\r
105         {\r
106                 int pos = m_List.GetCurSel();\r
107                 if (pos != LB_ERR)\r
108                 {\r
109                         m_List.DeleteString(pos);\r
110                         m_List.SetCurSel(min(pos, m_List.GetCount() - 1));\r
111                         m_history->RemoveEntry(pos);\r
112                         m_history->Save();\r
113                         return TRUE;\r
114                 }\r
115         }\r
116 \r
117         return CResizableStandAloneDialog::PreTranslateMessage(pMsg);\r
118 }\r