1 // TortoiseSVN - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - 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 "TortoiseProc.h"
22 #include "SetHooksAdv.h"
26 IMPLEMENT_DYNAMIC(CSetHooks
, ISettingsPropPage
)
28 CSetHooks::CSetHooks()
29 : ISettingsPropPage(CSetHooks::IDD
)
34 CSetHooks::~CSetHooks()
38 void CSetHooks::DoDataExchange(CDataExchange
* pDX
)
40 ISettingsPropPage::DoDataExchange(pDX
);
41 DDX_Control(pDX
, IDC_HOOKLIST
, m_cHookList
);
45 BEGIN_MESSAGE_MAP(CSetHooks
, ISettingsPropPage
)
46 ON_BN_CLICKED(IDC_HOOKREMOVEBUTTON
, &CSetHooks::OnBnClickedRemovebutton
)
47 ON_BN_CLICKED(IDC_HOOKEDITBUTTON
, &CSetHooks::OnBnClickedEditbutton
)
48 ON_BN_CLICKED(IDC_HOOKADDBUTTON
, &CSetHooks::OnBnClickedAddbutton
)
49 ON_BN_CLICKED(IDC_HOOKCOPYBUTTON
, &CSetHooks::OnBnClickedHookcopybutton
)
50 ON_NOTIFY(LVN_ITEMCHANGED
, IDC_HOOKLIST
, &CSetHooks::OnLvnItemchangedHooklist
)
51 ON_NOTIFY(NM_DBLCLK
, IDC_HOOKLIST
, &CSetHooks::OnNMDblclkHooklist
)
54 BOOL
CSetHooks::OnInitDialog()
56 ISettingsPropPage::OnInitDialog();
58 m_cHookList
.SetExtendedStyle(LVS_EX_FULLROWSELECT
| LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
);
60 // clear all previously set header columns
61 m_cHookList
.DeleteAllItems();
62 int c
= ((CHeaderCtrl
*)(m_cHookList
.GetDlgItem(0)))->GetItemCount()-1;
64 m_cHookList
.DeleteColumn(c
--);
66 // now set up the requested columns
68 // the relative path is always visible
69 temp
.LoadString(IDS_SETTINGS_HOOKS_TYPECOL
);
70 m_cHookList
.InsertColumn(0, temp
);
71 temp
.LoadString(IDS_SETTINGS_HOOKS_PATHCOL
);
72 m_cHookList
.InsertColumn(1, temp
);
73 temp
.LoadString(IDS_SETTINGS_HOOKS_COMMANDLINECOL
);
74 m_cHookList
.InsertColumn(2, temp
);
75 temp
.LoadString(IDS_SETTINGS_HOOKS_WAITCOL
);
76 m_cHookList
.InsertColumn(3, temp
);
77 temp
.LoadString(IDS_SETTINGS_HOOKS_SHOWCOL
);
78 m_cHookList
.InsertColumn(4, temp
);
81 theme
.SetWindowTheme(m_cHookList
.GetSafeHwnd(), L
"Explorer", NULL
);
88 void CSetHooks::RebuildHookList()
90 m_cHookList
.SetRedraw(false);
91 m_cHookList
.DeleteAllItems();
92 // fill the list control with all the hooks
93 if (CHooks::Instance().size())
95 for (hookiterator it
= CHooks::Instance().begin(); it
!= CHooks::Instance().end(); ++it
)
97 int pos
= m_cHookList
.InsertItem(m_cHookList
.GetItemCount(), CHooks::Instance().GetHookTypeString(it
->first
.htype
));
98 m_cHookList
.SetItemText(pos
, 1, it
->first
.path
.GetWinPathString());
99 m_cHookList
.SetItemText(pos
, 2, it
->second
.commandline
);
100 m_cHookList
.SetItemText(pos
, 3, (it
->second
.bWait
? _T("true") : _T("false")));
101 m_cHookList
.SetItemText(pos
, 4, (it
->second
.bShow
? _T("show") : _T("hide")));
105 int maxcol
= ((CHeaderCtrl
*)(m_cHookList
.GetDlgItem(0)))->GetItemCount()-1;
106 for (int col
= 0; col
<= maxcol
; col
++)
108 m_cHookList
.SetColumnWidth(col
, LVSCW_AUTOSIZE_USEHEADER
);
110 m_cHookList
.SetRedraw(true);
113 void CSetHooks::OnBnClickedRemovebutton()
116 // traversing from the end to the beginning so that the indices are not skipped
117 int index
= m_cHookList
.GetItemCount()-1;
120 if (m_cHookList
.GetItemState(index
, LVIS_SELECTED
) & LVIS_SELECTED
)
123 key
.htype
= CHooks::GetHookType((LPCTSTR
)m_cHookList
.GetItemText(index
, 0));
124 key
.path
= CTGitPath(m_cHookList
.GetItemText(index
, 1));
125 CHooks::Instance().Remove(key
);
126 m_cHookList
.DeleteItem(index
);
134 void CSetHooks::OnBnClickedEditbutton()
137 if (m_cHookList
.GetSelectedCount() > 1)
139 POSITION pos
= m_cHookList
.GetFirstSelectedItemPosition();
143 int index
= m_cHookList
.GetNextSelectedItem(pos
);
144 dlg
.key
.htype
= CHooks::GetHookType((LPCTSTR
)m_cHookList
.GetItemText(index
, 0));
145 dlg
.key
.path
= CTGitPath(m_cHookList
.GetItemText(index
, 1));
146 dlg
.cmd
.commandline
= m_cHookList
.GetItemText(index
, 2);
147 dlg
.cmd
.bWait
= (m_cHookList
.GetItemText(index
, 3).Compare(_T("true"))==0);
148 dlg
.cmd
.bShow
= (m_cHookList
.GetItemText(index
, 4).Compare(_T("show"))==0);
149 hookkey key
= dlg
.key
;
150 if (dlg
.DoModal() == IDOK
)
152 CHooks::Instance().Remove(key
);
153 CHooks::Instance().Add(dlg
.key
.htype
, dlg
.key
.path
, dlg
.cmd
.commandline
, dlg
.cmd
.bWait
, dlg
.cmd
.bShow
);
161 void CSetHooks::OnBnClickedAddbutton()
164 if (dlg
.DoModal() == IDOK
)
166 CHooks::Instance().Add(dlg
.key
.htype
, dlg
.key
.path
, dlg
.cmd
.commandline
, dlg
.cmd
.bWait
, dlg
.cmd
.bShow
);
172 void CSetHooks::OnLvnItemchangedHooklist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
174 UINT count
= m_cHookList
.GetSelectedCount();
175 GetDlgItem(IDC_HOOKREMOVEBUTTON
)->EnableWindow(count
> 0);
176 GetDlgItem(IDC_HOOKEDITBUTTON
)->EnableWindow(count
== 1);
177 GetDlgItem(IDC_HOOKCOPYBUTTON
)->EnableWindow(count
== 1);
181 void CSetHooks::OnNMDblclkHooklist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
183 OnBnClickedEditbutton();
187 BOOL
CSetHooks::OnApply()
190 CHooks::Instance().Save();
192 return ISettingsPropPage::OnApply();
195 void CSetHooks::OnBnClickedHookcopybutton()
197 if (m_cHookList
.GetSelectedCount() > 1)
199 POSITION pos
= m_cHookList
.GetFirstSelectedItemPosition();
203 int index
= m_cHookList
.GetNextSelectedItem(pos
);
204 dlg
.key
.htype
= CHooks::GetHookType((LPCTSTR
)m_cHookList
.GetItemText(index
, 0));
205 dlg
.cmd
.commandline
= m_cHookList
.GetItemText(index
, 2);
206 dlg
.cmd
.bWait
= (m_cHookList
.GetItemText(index
, 3).Compare(_T("true"))==0);
207 dlg
.cmd
.bShow
= (m_cHookList
.GetItemText(index
, 4).Compare(_T("show"))==0);
208 hookkey key
= dlg
.key
;
209 if (dlg
.DoModal() == IDOK
)
211 CHooks::Instance().Add(dlg
.key
.htype
, dlg
.key
.path
, dlg
.cmd
.commandline
, dlg
.cmd
.bWait
, dlg
.cmd
.bShow
);