OSDN Git Service

merge original branch.
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / Settings / SetHooks.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 #include "stdafx.h"\r
20 #include "TortoiseProc.h"\r
21 #include "SetHooks.h"\r
22 #include "SetHooksAdv.h"\r
23 #include "Hooks.h"\r
24 #include "XPTheme.h"\r
25 \r
26 IMPLEMENT_DYNAMIC(CSetHooks, ISettingsPropPage)\r
27 \r
28 CSetHooks::CSetHooks()\r
29         : ISettingsPropPage(CSetHooks::IDD)\r
30 {\r
31 \r
32 }\r
33 \r
34 CSetHooks::~CSetHooks()\r
35 {\r
36 }\r
37 \r
38 void CSetHooks::DoDataExchange(CDataExchange* pDX)\r
39 {\r
40         ISettingsPropPage::DoDataExchange(pDX);\r
41         DDX_Control(pDX, IDC_HOOKLIST, m_cHookList);\r
42 }\r
43 \r
44 \r
45 BEGIN_MESSAGE_MAP(CSetHooks, ISettingsPropPage)\r
46         ON_BN_CLICKED(IDC_HOOKREMOVEBUTTON, &CSetHooks::OnBnClickedRemovebutton)\r
47         ON_BN_CLICKED(IDC_HOOKEDITBUTTON, &CSetHooks::OnBnClickedEditbutton)\r
48         ON_BN_CLICKED(IDC_HOOKADDBUTTON, &CSetHooks::OnBnClickedAddbutton)\r
49         ON_BN_CLICKED(IDC_HOOKCOPYBUTTON, &CSetHooks::OnBnClickedHookcopybutton)\r
50         ON_NOTIFY(LVN_ITEMCHANGED, IDC_HOOKLIST, &CSetHooks::OnLvnItemchangedHooklist)\r
51         ON_NOTIFY(NM_DBLCLK, IDC_HOOKLIST, &CSetHooks::OnNMDblclkHooklist)\r
52 END_MESSAGE_MAP()\r
53 \r
54 BOOL CSetHooks::OnInitDialog()\r
55 {\r
56         ISettingsPropPage::OnInitDialog();\r
57 \r
58         m_cHookList.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP);\r
59 \r
60         // clear all previously set header columns\r
61         m_cHookList.DeleteAllItems();\r
62         int c = ((CHeaderCtrl*)(m_cHookList.GetDlgItem(0)))->GetItemCount()-1;\r
63         while (c>=0)\r
64                 m_cHookList.DeleteColumn(c--);\r
65 \r
66         // now set up the requested columns\r
67         CString temp;\r
68         // the relative path is always visible\r
69         temp.LoadString(IDS_SETTINGS_HOOKS_TYPECOL);\r
70         m_cHookList.InsertColumn(0, temp);\r
71         temp.LoadString(IDS_SETTINGS_HOOKS_PATHCOL);\r
72         m_cHookList.InsertColumn(1, temp);\r
73         temp.LoadString(IDS_SETTINGS_HOOKS_COMMANDLINECOL);\r
74         m_cHookList.InsertColumn(2, temp);\r
75         temp.LoadString(IDS_SETTINGS_HOOKS_WAITCOL);\r
76         m_cHookList.InsertColumn(3, temp);\r
77         temp.LoadString(IDS_SETTINGS_HOOKS_SHOWCOL);\r
78         m_cHookList.InsertColumn(4, temp);\r
79 \r
80         CXPTheme theme;\r
81         theme.SetWindowTheme(m_cHookList.GetSafeHwnd(), L"Explorer", NULL);\r
82 \r
83         RebuildHookList();\r
84 \r
85         return TRUE;\r
86 }\r
87 \r
88 void CSetHooks::RebuildHookList()\r
89 {\r
90         m_cHookList.SetRedraw(false);\r
91         m_cHookList.DeleteAllItems();\r
92         // fill the list control with all the hooks\r
93         if (CHooks::Instance().size())\r
94         {\r
95                 for (hookiterator it = CHooks::Instance().begin(); it != CHooks::Instance().end(); ++it)\r
96                 {\r
97                         int pos = m_cHookList.InsertItem(m_cHookList.GetItemCount(), CHooks::Instance().GetHookTypeString(it->first.htype));\r
98                         m_cHookList.SetItemText(pos, 1, it->first.path.GetWinPathString());\r
99                         m_cHookList.SetItemText(pos, 2, it->second.commandline);\r
100                         m_cHookList.SetItemText(pos, 3, (it->second.bWait ? _T("true") : _T("false")));\r
101                         m_cHookList.SetItemText(pos, 4, (it->second.bShow ? _T("show") : _T("hide")));\r
102                 }\r
103         }\r
104 \r
105         int maxcol = ((CHeaderCtrl*)(m_cHookList.GetDlgItem(0)))->GetItemCount()-1;\r
106         for (int col = 0; col <= maxcol; col++)\r
107         {\r
108                 m_cHookList.SetColumnWidth(col, LVSCW_AUTOSIZE_USEHEADER);\r
109         }\r
110         m_cHookList.SetRedraw(true);\r
111 }\r
112 \r
113 void CSetHooks::OnBnClickedRemovebutton()\r
114 {\r
115 #if 0\r
116         // traversing from the end to the beginning so that the indices are not skipped\r
117         int index = m_cHookList.GetItemCount()-1;\r
118         while (index >= 0)\r
119         {\r
120                 if (m_cHookList.GetItemState(index, LVIS_SELECTED) & LVIS_SELECTED)\r
121                 {\r
122                         hookkey key;\r
123                         key.htype = CHooks::GetHookType((LPCTSTR)m_cHookList.GetItemText(index, 0));\r
124                         key.path = CTSVNPath(m_cHookList.GetItemText(index, 1));\r
125                         CHooks::Instance().Remove(key);         \r
126                         m_cHookList.DeleteItem(index);\r
127                         SetModified();\r
128                 }\r
129                 index--;\r
130         }\r
131 #endif\r
132 }\r
133 \r
134 void CSetHooks::OnBnClickedEditbutton()\r
135 {\r
136 #if 0\r
137         if (m_cHookList.GetSelectedCount() > 1)\r
138                 return;\r
139         POSITION pos = m_cHookList.GetFirstSelectedItemPosition();\r
140         if (pos)\r
141         {\r
142                 CSetHooksAdv dlg;\r
143                 int index = m_cHookList.GetNextSelectedItem(pos);\r
144                 dlg.key.htype = CHooks::GetHookType((LPCTSTR)m_cHookList.GetItemText(index, 0));\r
145                 dlg.key.path = CTSVNPath(m_cHookList.GetItemText(index, 1));\r
146                 dlg.cmd.commandline = m_cHookList.GetItemText(index, 2);\r
147                 dlg.cmd.bWait = (m_cHookList.GetItemText(index, 3).Compare(_T("true"))==0);\r
148                 dlg.cmd.bShow = (m_cHookList.GetItemText(index, 4).Compare(_T("show"))==0);\r
149                 hookkey key = dlg.key;\r
150                 if (dlg.DoModal() == IDOK)\r
151                 {\r
152                         CHooks::Instance().Remove(key);\r
153                         CHooks::Instance().Add(dlg.key.htype, dlg.key.path, dlg.cmd.commandline, dlg.cmd.bWait, dlg.cmd.bShow);\r
154                         RebuildHookList();\r
155                         SetModified();\r
156                 }\r
157         }\r
158 #endif\r
159 }\r
160 \r
161 void CSetHooks::OnBnClickedAddbutton()\r
162 {\r
163         CSetHooksAdv dlg;\r
164         if (dlg.DoModal() == IDOK)\r
165         {\r
166                 CHooks::Instance().Add(dlg.key.htype, dlg.key.path, dlg.cmd.commandline, dlg.cmd.bWait, dlg.cmd.bShow);\r
167                 RebuildHookList();\r
168                 SetModified();\r
169         }\r
170 }\r
171 \r
172 void CSetHooks::OnLvnItemchangedHooklist(NMHDR * /*pNMHDR*/, LRESULT *pResult)\r
173 {\r
174         UINT count = m_cHookList.GetSelectedCount();\r
175         GetDlgItem(IDC_HOOKREMOVEBUTTON)->EnableWindow(count > 0);\r
176         GetDlgItem(IDC_HOOKEDITBUTTON)->EnableWindow(count == 1);\r
177         GetDlgItem(IDC_HOOKCOPYBUTTON)->EnableWindow(count == 1);\r
178         *pResult = 0;\r
179 }\r
180 \r
181 void CSetHooks::OnNMDblclkHooklist(NMHDR * /*pNMHDR*/, LRESULT *pResult)\r
182 {\r
183         OnBnClickedEditbutton();\r
184         *pResult = 0;\r
185 }\r
186 \r
187 BOOL CSetHooks::OnApply()\r
188 {\r
189         UpdateData();\r
190         CHooks::Instance().Save();\r
191         SetModified(FALSE);\r
192         return ISettingsPropPage::OnApply();\r
193 }\r
194 \r
195 void CSetHooks::OnBnClickedHookcopybutton()\r
196 {\r
197         if (m_cHookList.GetSelectedCount() > 1)\r
198                 return;\r
199         POSITION pos = m_cHookList.GetFirstSelectedItemPosition();\r
200         if (pos)\r
201         {\r
202                 CSetHooksAdv dlg;\r
203                 int index = m_cHookList.GetNextSelectedItem(pos);\r
204                 dlg.key.htype = CHooks::GetHookType((LPCTSTR)m_cHookList.GetItemText(index, 0));\r
205                 dlg.cmd.commandline = m_cHookList.GetItemText(index, 2);\r
206                 dlg.cmd.bWait = (m_cHookList.GetItemText(index, 3).Compare(_T("true"))==0);\r
207                 dlg.cmd.bShow = (m_cHookList.GetItemText(index, 4).Compare(_T("show"))==0);\r
208                 hookkey key = dlg.key;\r
209                 if (dlg.DoModal() == IDOK)\r
210                 {\r
211                         CHooks::Instance().Add(dlg.key.htype, dlg.key.path, dlg.cmd.commandline, dlg.cmd.bWait, dlg.cmd.bShow);\r
212                         RebuildHookList();\r
213                         SetModified();\r
214                 }\r
215         }\r
216 }\r