1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008,2010 - 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"
21 #include "SetHooksAdv.h"
22 #include "BrowseFolder.h"
26 IMPLEMENT_DYNAMIC(CSetHooksAdv
, CResizableStandAloneDialog
)
28 CSetHooksAdv::CSetHooksAdv(CWnd
* pParent
/*=NULL*/)
29 : CResizableStandAloneDialog(CSetHooksAdv::IDD
, pParent
)
31 , m_sCommandLine(_T(""))
37 CSetHooksAdv::~CSetHooksAdv()
41 void CSetHooksAdv::DoDataExchange(CDataExchange
* pDX
)
43 CResizableStandAloneDialog::DoDataExchange(pDX
);
44 DDX_Text(pDX
, IDC_HOOKPATH
, m_sPath
);
45 DDX_Text(pDX
, IDC_HOOKCOMMANDLINE
, m_sCommandLine
);
46 DDX_Check(pDX
, IDC_WAITCHECK
, m_bWait
);
47 DDX_Check(pDX
, IDC_HIDECHECK
, m_bHide
);
48 DDX_Control(pDX
, IDC_HOOKTYPECOMBO
, m_cHookTypeCombo
);
52 BEGIN_MESSAGE_MAP(CSetHooksAdv
, CResizableStandAloneDialog
)
53 ON_BN_CLICKED(IDC_HOOKBROWSE
, &CSetHooksAdv::OnBnClickedHookbrowse
)
54 ON_BN_CLICKED(IDC_HOOKCOMMANDBROWSE
, &CSetHooksAdv::OnBnClickedHookcommandbrowse
)
55 ON_BN_CLICKED(IDHELP
, &CSetHooksAdv::OnBnClickedHelp
)
58 BOOL
CSetHooksAdv::OnInitDialog()
60 CResizableStandAloneDialog::OnInitDialog();
62 // initialize the combo box with all the hook types we have
65 index = m_cHookTypeCombo.AddString(CString(MAKEINTRESOURCE(IDS_HOOKTYPE_STARTCOMMIT)));
66 m_cHookTypeCombo.SetItemData(index, start_commit_hook);
67 index = m_cHookTypeCombo.AddString(CString(MAKEINTRESOURCE(IDS_HOOKTYPE_PRECOMMIT)));
68 m_cHookTypeCombo.SetItemData(index, pre_commit_hook);
69 index = m_cHookTypeCombo.AddString(CString(MAKEINTRESOURCE(IDS_HOOKTYPE_POSTCOMMIT)));
70 m_cHookTypeCombo.SetItemData(index, post_commit_hook);
71 index = m_cHookTypeCombo.AddString(CString(MAKEINTRESOURCE(IDS_HOOKTYPE_STARTUPDATE)));
72 m_cHookTypeCombo.SetItemData(index, start_update_hook);
73 index = m_cHookTypeCombo.AddString(CString(MAKEINTRESOURCE(IDS_HOOKTYPE_PREUPDATE)));
74 m_cHookTypeCombo.SetItemData(index, pre_update_hook);
75 index = m_cHookTypeCombo.AddString(CString(MAKEINTRESOURCE(IDS_HOOKTYPE_POSTUPDATE)));
76 m_cHookTypeCombo.SetItemData(index, post_update_hook);
78 index
= m_cHookTypeCombo
.AddString(CString(MAKEINTRESOURCE(IDS_HOOKTYPE_PREPUSH
)));
79 m_cHookTypeCombo
.SetItemData(index
, pre_push_hook
);
80 index
= m_cHookTypeCombo
.AddString(CString(MAKEINTRESOURCE(IDS_HOOKTYPE_POSTPUSH
)));
81 m_cHookTypeCombo
.SetItemData(index
, post_push_hook
);
83 // preselect the right hook type in the combobox
84 for (int i
=0; i
<m_cHookTypeCombo
.GetCount(); ++i
)
86 hooktype ht
= (hooktype
)m_cHookTypeCombo
.GetItemData(i
);
90 m_cHookTypeCombo
.GetLBText(i
, str
);
91 m_cHookTypeCombo
.SelectString(i
, str
);
96 m_sPath
= key
.path
.GetWinPathString();
97 m_sCommandLine
= cmd
.commandline
;
100 m_tooltips
.Create(this);
103 AddAnchor(IDC_HOOKTYPELABEL
, TOP_LEFT
, TOP_RIGHT
);
104 AddAnchor(IDC_HOOKTYPECOMBO
, TOP_RIGHT
);
105 AddAnchor(IDC_HOOKWCPATHLABEL
, TOP_LEFT
, TOP_RIGHT
);
106 AddAnchor(IDC_HOOKPATH
, TOP_LEFT
, TOP_RIGHT
);
107 AddAnchor(IDC_HOOKBROWSE
, TOP_RIGHT
);
108 AddAnchor(IDC_HOOKCMLABEL
, TOP_LEFT
, TOP_RIGHT
);
109 AddAnchor(IDC_HOOKCOMMANDLINE
, TOP_LEFT
, TOP_RIGHT
);
110 AddAnchor(IDC_HOOKCOMMANDBROWSE
, TOP_RIGHT
);
111 AddAnchor(IDC_WAITCHECK
, BOTTOM_LEFT
, BOTTOM_RIGHT
);
112 AddAnchor(IDC_HIDECHECK
, BOTTOM_LEFT
, BOTTOM_RIGHT
);
113 AddAnchor(IDOK
, BOTTOM_RIGHT
);
114 AddAnchor(IDCANCEL
, BOTTOM_RIGHT
);
115 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
116 EnableSaveRestore(_T("SetHooksAdvDlg"));
120 void CSetHooksAdv::OnOK()
124 int cursel
= m_cHookTypeCombo
.GetCurSel();
125 key
.htype
= unknown_hook
;
126 if (cursel
!= CB_ERR
)
128 key
.htype
= (hooktype
)m_cHookTypeCombo
.GetItemData(cursel
);
129 key
.path
= CTGitPath(m_sPath
);
130 cmd
.commandline
= m_sCommandLine
;
131 cmd
.bWait
= !!m_bWait
;
132 cmd
.bShow
= !m_bHide
;
134 if (key
.htype
== unknown_hook
)
136 m_tooltips
.ShowBalloon(IDC_HOOKTYPECOMBO
, IDS_ERR_NOHOOKTYPESPECIFIED
, IDS_ERR_ERROR
, TTI_ERROR
);
139 if (key
.path
.IsEmpty())
141 ShowEditBalloon(IDC_HOOKPATH
, IDS_ERR_NOHOOKPATHSPECIFIED
, IDS_ERR_ERROR
, TTI_ERROR
);
144 if (cmd
.commandline
.IsEmpty())
146 ShowEditBalloon(IDC_HOOKCOMMANDLINE
, IDS_ERR_NOHOOKCOMMANDPECIFIED
, IDS_ERR_ERROR
, TTI_ERROR
);
150 CResizableStandAloneDialog::OnOK();
153 void CSetHooksAdv::OnBnClickedHookbrowse()
157 CBrowseFolder browser
;
159 browser
.SetInfo(CString(MAKEINTRESOURCE(IDS_SETTINGS_HOOKS_SELECTFOLDERPATH
)));
160 browser
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
161 if (browser
.Show(m_hWnd
, sPath
) == CBrowseFolder::OK
)
169 void CSetHooksAdv::OnBnClickedHookcommandbrowse()
172 CString sCmdLine
= m_sCommandLine
;
173 if (!PathFileExists(sCmdLine
))
175 // Display the Open dialog box.
176 if (CAppUtils::FileOpenSave(sCmdLine
, NULL
, IDS_SETTINGS_HOOKS_SELECTSCRIPTFILE
, IDS_COMMONFILEFILTER
, true, m_hWnd
))
178 m_sCommandLine
= sCmdLine
;
183 void CSetHooksAdv::OnBnClickedHelp()
188 BOOL
CSetHooksAdv::PreTranslateMessage(MSG
* pMsg
)
190 m_tooltips
.RelayEvent(pMsg
);
191 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);