1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013, 2015-2017 - TortoiseGit
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 // SubmoduleAddDlg.cpp : implementation file
25 #include "SubmoduleAddDlg.h"
26 #include "BrowseFolder.h"
29 // CSubmoduleAddDlg dialog
31 IMPLEMENT_DYNAMIC(CSubmoduleAddDlg
, CHorizontalResizableStandAloneDialog
)
33 CSubmoduleAddDlg::CSubmoduleAddDlg(CWnd
* pParent
/*=nullptr*/)
34 : CHorizontalResizableStandAloneDialog(CSubmoduleAddDlg::IDD
, pParent
)
37 , m_bAutoloadPuttyKeyFile(CAppUtils::IsSSHPutty())
41 CSubmoduleAddDlg::~CSubmoduleAddDlg()
45 void CSubmoduleAddDlg::DoDataExchange(CDataExchange
* pDX
)
47 CDialog::DoDataExchange(pDX
);
48 DDX_Control(pDX
, IDC_COMBOBOXEX_REPOSITORY
, m_Repository
);
49 DDX_Control(pDX
, IDC_COMBOBOXEX_PATH
, m_PathCtrl
);
50 DDX_Check(pDX
, IDC_BRANCH_CHECK
, m_bBranch
);
51 DDX_Text(pDX
, IDC_SUBMODULE_BRANCH
, m_strBranch
);
52 DDX_Check(pDX
, IDC_FORCE
, m_bForce
);
53 DDX_Check(pDX
,IDC_PUTTYKEY_AUTOLOAD
, m_bAutoloadPuttyKeyFile
);
54 DDX_Control(pDX
, IDC_PUTTYKEYFILE
, m_PuttyKeyCombo
);
58 BEGIN_MESSAGE_MAP(CSubmoduleAddDlg
, CHorizontalResizableStandAloneDialog
)
59 ON_COMMAND(IDC_REP_BROWSE
, OnRepBrowse
)
60 ON_COMMAND(IDC_BUTTON_PATH_BROWSE
, OnPathBrowse
)
61 ON_COMMAND(IDC_BRANCH_CHECK
, OnBranchCheck
)
62 ON_BN_CLICKED(IDC_PUTTYKEYFILE_BROWSE
, OnBnClickedPuttykeyfileBrowse
)
63 ON_BN_CLICKED(IDC_PUTTYKEY_AUTOLOAD
, OnBnClickedPuttykeyAutoload
)
67 // CSubmoduleAddDlg message handlers
69 BOOL
CSubmoduleAddDlg::OnInitDialog()
71 CHorizontalResizableStandAloneDialog::OnInitDialog();
72 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
74 AdjustControlSize(IDC_BRANCH_CHECK
);
75 AdjustControlSize(IDC_FORCE
);
76 AdjustControlSize(IDC_PUTTYKEY_AUTOLOAD
);
78 AddAnchor(IDOK
,BOTTOM_RIGHT
);
79 AddAnchor(IDCANCEL
,BOTTOM_RIGHT
);
80 AddAnchor(IDC_GROUP_SUBMODULE
,TOP_LEFT
,BOTTOM_RIGHT
);
81 AddAnchor(IDC_COMBOBOXEX_REPOSITORY
,TOP_LEFT
,TOP_RIGHT
);
82 AddAnchor(IDC_COMBOBOXEX_PATH
,TOP_LEFT
,TOP_RIGHT
);
83 AddAnchor(IDC_REP_BROWSE
,TOP_RIGHT
);
84 AddAnchor(IDC_BUTTON_PATH_BROWSE
,TOP_RIGHT
);
85 AddAnchor(IDC_BRANCH_CHECK
,BOTTOM_LEFT
);
86 AddAnchor(IDC_SUBMODULE_BRANCH
,BOTTOM_LEFT
,BOTTOM_RIGHT
);
87 AddAnchor(IDC_FORCE
,BOTTOM_LEFT
);
88 AddAnchor(IDC_PUTTYKEYFILE_BROWSE
,TOP_RIGHT
);
89 AddAnchor(IDC_PUTTYKEY_AUTOLOAD
,TOP_LEFT
);
90 AddAnchor(IDC_PUTTYKEYFILE
,TOP_LEFT
,TOP_RIGHT
);
91 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
94 EnableSaveRestore(L
"SubmoduleAddDlg");
97 GetWindowText(sWindowTitle
);
98 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.CombinePath(m_strPath
).TrimRight('\\'), sWindowTitle
);
100 m_Repository
.SetURLHistory(true);
101 m_Repository
.SetCaseSensitive(TRUE
);
102 m_PathCtrl
.SetPathHistory(true);
104 m_Repository
.LoadHistory(L
"Software\\TortoiseGit\\History\\SubModuleRepoURLS", L
"url");
105 m_PathCtrl
.LoadHistory(L
"Software\\TortoiseGit\\History\\SubModulePath", L
"url");
106 m_PathCtrl
.SetWindowText(m_strPath
);
107 m_Repository
.SetCurSel(0);
109 m_PuttyKeyCombo
.SetPathHistory(TRUE
);
110 m_PuttyKeyCombo
.LoadHistory(L
"Software\\TortoiseGit\\History\\puttykey", L
"key");
111 m_PuttyKeyCombo
.SetCurSel(0);
113 GetDlgItem(IDC_PUTTYKEY_AUTOLOAD
)->EnableWindow(CAppUtils::IsSSHPutty());
114 GetDlgItem(IDC_PUTTYKEYFILE
)->EnableWindow(m_bAutoloadPuttyKeyFile
);
115 GetDlgItem(IDC_PUTTYKEYFILE_BROWSE
)->EnableWindow(m_bAutoloadPuttyKeyFile
);
118 GetDlgItem(IDC_GROUP_SUBMODULE
)->GetWindowText(text
);
119 text
+= m_strProject
;
120 GetDlgItem(IDC_GROUP_SUBMODULE
)->SetWindowText(text
);
125 void CSubmoduleAddDlg::OnRepBrowse()
127 CBrowseFolder browseFolder
;
128 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
129 CString strDirectory
;
130 this->m_Repository
.GetWindowTextW(strDirectory
);
131 if (browseFolder
.Show(GetSafeHwnd(), strDirectory
) == CBrowseFolder::OK
)
133 this->m_Repository
.SetWindowTextW(strDirectory
);
136 void CSubmoduleAddDlg::OnPathBrowse()
138 CBrowseFolder browseFolder
;
139 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
140 CString strDirectory
;
141 this->m_PathCtrl
.GetWindowTextW(strDirectory
);
142 if (browseFolder
.Show(GetSafeHwnd(), strDirectory
,g_Git
.m_CurrentDir
) == CBrowseFolder::OK
)
144 this->m_PathCtrl
.SetWindowTextW(strDirectory
);
147 void CSubmoduleAddDlg::OnBranchCheck()
152 this->GetDlgItem(IDC_SUBMODULE_BRANCH
)->ShowWindow(TRUE
);
156 this->GetDlgItem(IDC_SUBMODULE_BRANCH
)->ShowWindow(FALSE
);
160 void CSubmoduleAddDlg::OnOK()
166 if(m_strBranch
.IsEmpty())
168 m_tooltips
.ShowBalloon(IDC_SUBMODULE_BRANCH
, IDS_ERR_MISSINGVALUE
, IDS_ERR_ERROR
, TTI_ERROR
);
172 m_Repository
.SaveHistory();
173 m_PathCtrl
.SaveHistory();
175 this->m_strPath
=m_PathCtrl
.GetString();
176 this->m_strRepos
=m_Repository
.GetString();
180 if(m_strPath
.IsEmpty())
182 m_tooltips
.ShowBalloon(IDC_COMBOBOXEX_PATH
, IDS_ERR_MISSINGVALUE
, IDS_ERR_ERROR
, TTI_ERROR
);
185 if(m_strRepos
.IsEmpty())
187 m_tooltips
.ShowBalloon(IDC_COMBOBOXEX_REPOSITORY
, IDS_ERR_MISSINGVALUE
, IDS_ERR_ERROR
, TTI_ERROR
);
191 m_PuttyKeyCombo
.SaveHistory();
192 m_PuttyKeyCombo
.GetWindowText(m_strPuttyKeyFile
);
196 void CSubmoduleAddDlg::OnBnClickedPuttykeyfileBrowse()
200 m_PuttyKeyCombo
.GetWindowText(filename
);
201 if (!PathFileExists(filename
))
203 if (!CAppUtils::FileOpenSave(filename
, nullptr, 0, IDS_PUTTYKEYFILEFILTER
, true, GetSafeHwnd()))
205 m_PuttyKeyCombo
.SetWindowText(filename
);
208 void CSubmoduleAddDlg::OnBnClickedPuttykeyAutoload()
211 GetDlgItem(IDC_PUTTYKEYFILE
)->EnableWindow(m_bAutoloadPuttyKeyFile
);
212 GetDlgItem(IDC_PUTTYKEYFILE_BROWSE
)->EnableWindow(m_bAutoloadPuttyKeyFile
);