1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2010, 2013-2019, 2023 - TortoiseGit
4 // Copyright (C) 2003-2008,2010 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "TortoiseProc.h"
22 #include "SetHooksAdv.h"
23 #include "BrowseFolder.h"
26 #include "GitAdminDir.h"
28 IMPLEMENT_DYNAMIC(CSetHooksAdv
, CResizableStandAloneDialog
)
30 CSetHooksAdv::CSetHooksAdv(CWnd
* pParent
/*=nullptr*/)
31 : CResizableStandAloneDialog(CSetHooksAdv::IDD
, pParent
)
39 CSetHooksAdv::~CSetHooksAdv()
43 void CSetHooksAdv::DoDataExchange(CDataExchange
* pDX
)
45 CResizableStandAloneDialog::DoDataExchange(pDX
);
46 DDX_Text(pDX
, IDC_HOOKPATH
, m_sPath
);
47 DDX_Text(pDX
, IDC_HOOKCOMMANDLINE
, m_sCommandLine
);
48 DDX_Check(pDX
, IDC_ENABLE
, m_bEnabled
);
49 DDX_Check(pDX
, IDC_LOCALCHECK
, m_bLocal
);
50 DDX_Check(pDX
, IDC_WAITCHECK
, m_bWait
);
51 DDX_Check(pDX
, IDC_HIDECHECK
, m_bHide
);
52 DDX_Control(pDX
, IDC_HOOKTYPECOMBO
, m_cHookTypeCombo
);
56 BEGIN_MESSAGE_MAP(CSetHooksAdv
, CResizableStandAloneDialog
)
57 ON_BN_CLICKED(IDC_HOOKBROWSE
, &CSetHooksAdv::OnBnClickedHookbrowse
)
58 ON_BN_CLICKED(IDC_HOOKCOMMANDBROWSE
, &CSetHooksAdv::OnBnClickedHookcommandbrowse
)
59 ON_BN_CLICKED(IDC_LOCALCHECK
, &CSetHooksAdv::OnBnClickedLocalcheck
)
62 BOOL
CSetHooksAdv::OnInitDialog()
64 CResizableStandAloneDialog::OnInitDialog();
66 AdjustControlSize(IDC_ENABLE
);
67 AdjustControlSize(IDC_WAITCHECK
);
68 AdjustControlSize(IDC_HIDECHECK
);
69 AdjustControlSize(IDC_LOCALCHECK
);
71 // initialize the combo box with all the hook types we have
73 index
= m_cHookTypeCombo
.AddString(CString(MAKEINTRESOURCE(IDS_HOOKTYPE_STARTCOMMIT
)));
74 m_cHookTypeCombo
.SetItemData(index
, static_cast<int>(HookType::start_commit_hook
));
75 index
= m_cHookTypeCombo
.AddString(CString(MAKEINTRESOURCE(IDS_HOOKTYPE_PRECOMMIT
)));
76 m_cHookTypeCombo
.SetItemData(index
, static_cast<int>(HookType::pre_commit_hook
));
77 index
= m_cHookTypeCombo
.AddString(CString(MAKEINTRESOURCE(IDS_HOOKTYPE_POSTCOMMIT
)));
78 m_cHookTypeCombo
.SetItemData(index
, static_cast<int>(HookType::post_commit_hook
));
79 index
= m_cHookTypeCombo
.AddString(CString(MAKEINTRESOURCE(IDS_HOOKTYPE_PREPUSH
)));
80 m_cHookTypeCombo
.SetItemData(index
, static_cast<int>(HookType::pre_push_hook
));
81 index
= m_cHookTypeCombo
.AddString(CString(MAKEINTRESOURCE(IDS_HOOKTYPE_POSTPUSH
)));
82 m_cHookTypeCombo
.SetItemData(index
, static_cast<int>(HookType::post_push_hook
));
83 index
= m_cHookTypeCombo
.AddString(CString(MAKEINTRESOURCE(IDS_HOOKTYPE_PREREBASE
)));
84 m_cHookTypeCombo
.SetItemData(index
, static_cast<int>(HookType::pre_rebase_hook
));
86 // preselect the right hook type in the combobox
87 for (int i
=0; i
<m_cHookTypeCombo
.GetCount(); ++i
)
89 HookType ht
= static_cast<HookType
>(m_cHookTypeCombo
.GetItemData(i
));
93 m_cHookTypeCombo
.GetLBText(i
, str
);
94 m_cHookTypeCombo
.SelectString(i
, str
);
99 m_sPath
= key
.path
.GetWinPathString();
100 m_sCommandLine
= cmd
.commandline
;
102 m_bHide
= !cmd
.bShow
;
103 m_bLocal
= cmd
.bLocal
;
104 m_bEnabled
= cmd
.bEnabled
? BST_CHECKED
: BST_UNCHECKED
;
107 OnBnClickedLocalcheck();
109 DialogEnableWindow(IDC_LOCALCHECK
, GitAdminDir::HasAdminDir(g_Git
.m_CurrentDir
));
111 AddAnchor(IDC_ENABLE
, TOP_LEFT
);
112 AddAnchor(IDC_HOOKTYPELABEL
, TOP_LEFT
, TOP_RIGHT
);
113 AddAnchor(IDC_HOOKTYPECOMBO
, TOP_RIGHT
);
114 AddAnchor(IDC_HOOKWCPATHLABEL
, TOP_LEFT
, TOP_RIGHT
);
115 AddAnchor(IDC_LOCALCHECK
, TOP_LEFT
, TOP_RIGHT
);
116 AddAnchor(IDC_HOOKPATH
, TOP_LEFT
, TOP_RIGHT
);
117 AddAnchor(IDC_HOOKBROWSE
, TOP_RIGHT
);
118 AddAnchor(IDC_HOOKCMLABEL
, TOP_LEFT
, TOP_RIGHT
);
119 AddAnchor(IDC_HOOKCOMMANDLINE
, TOP_LEFT
, TOP_RIGHT
);
120 AddAnchor(IDC_HOOKCOMMANDBROWSE
, TOP_RIGHT
);
121 AddAnchor(IDC_WAITCHECK
, BOTTOM_LEFT
, BOTTOM_RIGHT
);
122 AddAnchor(IDC_HIDECHECK
, BOTTOM_LEFT
, BOTTOM_RIGHT
);
123 AddAnchor(IDOK
, BOTTOM_RIGHT
);
124 AddAnchor(IDCANCEL
, BOTTOM_RIGHT
);
125 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
126 EnableSaveRestore(L
"SetHooksAdvDlg");
130 void CSetHooksAdv::OnOK()
133 int cursel
= m_cHookTypeCombo
.GetCurSel();
134 key
.htype
= HookType::unknown_hook
;
135 if (cursel
!= CB_ERR
)
137 key
.htype
= static_cast<HookType
>(m_cHookTypeCombo
.GetItemData(cursel
));
138 key
.path
= CTGitPath(m_sPath
);
139 cmd
.commandline
= m_sCommandLine
;
140 cmd
.bEnabled
= m_bEnabled
== BST_CHECKED
;
141 cmd
.bWait
= !!m_bWait
;
142 cmd
.bShow
= !m_bHide
;
143 cmd
.bLocal
= !!m_bLocal
;
145 if (key
.htype
== HookType::unknown_hook
)
147 m_tooltips
.ShowBalloon(IDC_HOOKTYPECOMBO
, IDS_ERR_NOHOOKTYPESPECIFIED
, IDS_ERR_ERROR
, TTI_ERROR
);
152 if (key
.path
.IsEmpty())
154 ShowEditBalloon(IDC_HOOKPATH
, IDS_ERR_NOHOOKPATHSPECIFIED
, IDS_ERR_ERROR
, TTI_ERROR
);
157 if (key
.path
.GetWinPathString() != L
"*" && (!PathIsDirectory(key
.path
.GetWinPathString()) || PathIsRelative(key
.path
.GetWinPathString())))
159 ShowEditBalloon(IDC_HOOKPATH
, static_cast<LPCWSTR
>(CFormatMessageWrapper(ERROR_PATH_NOT_FOUND
)), CString(MAKEINTRESOURCE(IDS_ERR_ERROR
)), TTI_ERROR
);
163 if (cmd
.commandline
.IsEmpty())
165 ShowEditBalloon(IDC_HOOKCOMMANDLINE
, IDS_ERR_NOHOOKCOMMANDPECIFIED
, IDS_ERR_ERROR
, TTI_ERROR
);
169 CResizableStandAloneDialog::OnOK();
172 void CSetHooksAdv::OnBnClickedHookbrowse()
175 CBrowseFolder browser
;
177 browser
.SetInfo(CString(MAKEINTRESOURCE(IDS_SETTINGS_HOOKS_SELECTFOLDERPATH
)));
178 browser
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
179 if (browser
.Show(m_hWnd
, sPath
) == CBrowseFolder::OK
)
186 void CSetHooksAdv::OnBnClickedHookcommandbrowse()
189 CString sCmdLine
= m_sCommandLine
;
190 if (!PathFileExists(sCmdLine
))
192 // Display the Open dialog box.
193 if (CAppUtils::FileOpenSave(sCmdLine
, nullptr, IDS_SETTINGS_HOOKS_SELECTSCRIPTFILE
, IDS_COMMONFILEFILTER
, true, m_hWnd
))
195 m_sCommandLine
= sCmdLine
;
200 void CSetHooksAdv::OnBnClickedLocalcheck()
203 DialogEnableWindow(IDC_HOOKPATH
, !m_bLocal
);
204 DialogEnableWindow(IDC_HOOKBROWSE
, !m_bLocal
);