1 // TortoiseGit - 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"
25 IMPLEMENT_DYNAMIC(CSetHooks
, ISettingsPropPage
)
27 CSetHooks::CSetHooks()
28 : ISettingsPropPage(CSetHooks::IDD
)
33 CSetHooks::~CSetHooks()
37 void CSetHooks::DoDataExchange(CDataExchange
* pDX
)
39 ISettingsPropPage::DoDataExchange(pDX
);
40 DDX_Control(pDX
, IDC_HOOKLIST
, m_cHookList
);
44 BEGIN_MESSAGE_MAP(CSetHooks
, ISettingsPropPage
)
45 ON_BN_CLICKED(IDC_HOOKREMOVEBUTTON
, &CSetHooks::OnBnClickedRemovebutton
)
46 ON_BN_CLICKED(IDC_HOOKEDITBUTTON
, &CSetHooks::OnBnClickedEditbutton
)
47 ON_BN_CLICKED(IDC_HOOKADDBUTTON
, &CSetHooks::OnBnClickedAddbutton
)
48 ON_BN_CLICKED(IDC_HOOKCOPYBUTTON
, &CSetHooks::OnBnClickedHookcopybutton
)
49 ON_NOTIFY(LVN_ITEMCHANGED
, IDC_HOOKLIST
, &CSetHooks::OnLvnItemchangedHooklist
)
50 ON_NOTIFY(NM_DBLCLK
, IDC_HOOKLIST
, &CSetHooks::OnNMDblclkHooklist
)
53 BOOL
CSetHooks::OnInitDialog()
55 ISettingsPropPage::OnInitDialog();
57 m_cHookList
.SetExtendedStyle(LVS_EX_FULLROWSELECT
| LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
);
59 // clear all previously set header columns
60 m_cHookList
.DeleteAllItems();
61 int c
= ((CHeaderCtrl
*)(m_cHookList
.GetDlgItem(0)))->GetItemCount()-1;
63 m_cHookList
.DeleteColumn(c
--);
65 // now set up the requested columns
67 // the relative path is always visible
68 temp
.LoadString(IDS_SETTINGS_HOOKS_TYPECOL
);
69 m_cHookList
.InsertColumn(0, temp
);
70 temp
.LoadString(IDS_SETTINGS_HOOKS_PATHCOL
);
71 m_cHookList
.InsertColumn(1, temp
);
72 temp
.LoadString(IDS_SETTINGS_HOOKS_COMMANDLINECOL
);
73 m_cHookList
.InsertColumn(2, temp
);
74 temp
.LoadString(IDS_SETTINGS_HOOKS_WAITCOL
);
75 m_cHookList
.InsertColumn(3, temp
);
76 temp
.LoadString(IDS_SETTINGS_HOOKS_SHOWCOL
);
77 m_cHookList
.InsertColumn(4, temp
);
79 SetWindowTheme(m_hWnd
, L
"Explorer", NULL
);
86 void CSetHooks::RebuildHookList()
88 m_cHookList
.SetRedraw(false);
89 m_cHookList
.DeleteAllItems();
90 // fill the list control with all the hooks
91 if (CHooks::Instance().size())
93 for (hookiterator it
= CHooks::Instance().begin(); it
!= CHooks::Instance().end(); ++it
)
95 int pos
= m_cHookList
.InsertItem(m_cHookList
.GetItemCount(), CHooks::Instance().GetHookTypeString(it
->first
.htype
));
96 m_cHookList
.SetItemText(pos
, 1, it
->first
.path
.GetWinPathString());
97 m_cHookList
.SetItemText(pos
, 2, it
->second
.commandline
);
98 m_cHookList
.SetItemText(pos
, 3, (it
->second
.bWait
? _T("true") : _T("false")));
99 m_cHookList
.SetItemText(pos
, 4, (it
->second
.bShow
? _T("show") : _T("hide")));
103 int maxcol
= ((CHeaderCtrl
*)(m_cHookList
.GetDlgItem(0)))->GetItemCount()-1;
104 for (int col
= 0; col
<= maxcol
; col
++)
106 m_cHookList
.SetColumnWidth(col
, LVSCW_AUTOSIZE_USEHEADER
);
108 m_cHookList
.SetRedraw(true);
111 void CSetHooks::OnBnClickedRemovebutton()
114 // traversing from the end to the beginning so that the indices are not skipped
115 int index
= m_cHookList
.GetItemCount()-1;
118 if (m_cHookList
.GetItemState(index
, LVIS_SELECTED
) & LVIS_SELECTED
)
121 key
.htype
= CHooks::GetHookType((LPCTSTR
)m_cHookList
.GetItemText(index
, 0));
122 key
.path
= CTGitPath(m_cHookList
.GetItemText(index
, 1));
123 CHooks::Instance().Remove(key
);
124 m_cHookList
.DeleteItem(index
);
132 void CSetHooks::OnBnClickedEditbutton()
135 if (m_cHookList
.GetSelectedCount() > 1)
137 POSITION pos
= m_cHookList
.GetFirstSelectedItemPosition();
141 int index
= m_cHookList
.GetNextSelectedItem(pos
);
142 dlg
.key
.htype
= CHooks::GetHookType((LPCTSTR
)m_cHookList
.GetItemText(index
, 0));
143 dlg
.key
.path
= CTGitPath(m_cHookList
.GetItemText(index
, 1));
144 dlg
.cmd
.commandline
= m_cHookList
.GetItemText(index
, 2);
145 dlg
.cmd
.bWait
= (m_cHookList
.GetItemText(index
, 3).Compare(_T("true"))==0);
146 dlg
.cmd
.bShow
= (m_cHookList
.GetItemText(index
, 4).Compare(_T("show"))==0);
147 hookkey key
= dlg
.key
;
148 if (dlg
.DoModal() == IDOK
)
150 CHooks::Instance().Remove(key
);
151 CHooks::Instance().Add(dlg
.key
.htype
, dlg
.key
.path
, dlg
.cmd
.commandline
, dlg
.cmd
.bWait
, dlg
.cmd
.bShow
);
159 void CSetHooks::OnBnClickedAddbutton()
162 if (dlg
.DoModal() == IDOK
)
164 CHooks::Instance().Add(dlg
.key
.htype
, dlg
.key
.path
, dlg
.cmd
.commandline
, dlg
.cmd
.bWait
, dlg
.cmd
.bShow
);
170 void CSetHooks::OnLvnItemchangedHooklist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
172 UINT count
= m_cHookList
.GetSelectedCount();
173 GetDlgItem(IDC_HOOKREMOVEBUTTON
)->EnableWindow(count
> 0);
174 GetDlgItem(IDC_HOOKEDITBUTTON
)->EnableWindow(count
== 1);
175 GetDlgItem(IDC_HOOKCOPYBUTTON
)->EnableWindow(count
== 1);
179 void CSetHooks::OnNMDblclkHooklist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
181 OnBnClickedEditbutton();
185 BOOL
CSetHooks::OnApply()
188 CHooks::Instance().Save();
190 return ISettingsPropPage::OnApply();
193 void CSetHooks::OnBnClickedHookcopybutton()
195 if (m_cHookList
.GetSelectedCount() > 1)
197 POSITION pos
= m_cHookList
.GetFirstSelectedItemPosition();
201 int index
= m_cHookList
.GetNextSelectedItem(pos
);
202 dlg
.key
.htype
= CHooks::GetHookType((LPCTSTR
)m_cHookList
.GetItemText(index
, 0));
203 dlg
.cmd
.commandline
= m_cHookList
.GetItemText(index
, 2);
204 dlg
.cmd
.bWait
= (m_cHookList
.GetItemText(index
, 3).Compare(_T("true"))==0);
205 dlg
.cmd
.bShow
= (m_cHookList
.GetItemText(index
, 4).Compare(_T("show"))==0);
206 hookkey key
= dlg
.key
;
207 if (dlg
.DoModal() == IDOK
)
209 CHooks::Instance().Add(dlg
.key
.htype
, dlg
.key
.path
, dlg
.cmd
.commandline
, dlg
.cmd
.bWait
, dlg
.cmd
.bShow
);