Merge branch 'scintilla-405'
[TortoiseGit.git] / src / TortoiseProc / SubmoduleAddDlg.cpp
blob1ca3d72da344515c530ebc2b6a659b2bafd4d382
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
23 #include "stdafx.h"
24 #include "resource.h"
25 #include "SubmoduleAddDlg.h"
26 #include "BrowseFolder.h"
27 #include "AppUtils.h"
29 // CSubmoduleAddDlg dialog
31 IMPLEMENT_DYNAMIC(CSubmoduleAddDlg, CHorizontalResizableStandAloneDialog)
33 CSubmoduleAddDlg::CSubmoduleAddDlg(CWnd* pParent /*=nullptr*/)
34 : CHorizontalResizableStandAloneDialog(CSubmoduleAddDlg::IDD, pParent)
35 , m_bBranch(FALSE)
36 , m_bForce(FALSE)
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)
64 END_MESSAGE_MAP()
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);
92 AddOthersToAnchor();
94 EnableSaveRestore(L"SubmoduleAddDlg");
96 CString sWindowTitle;
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);
117 CString text;
118 GetDlgItem(IDC_GROUP_SUBMODULE)->GetWindowText(text);
119 text += m_strProject;
120 GetDlgItem(IDC_GROUP_SUBMODULE)->SetWindowText(text);
122 return TRUE;
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()
149 this->UpdateData();
150 if(this->m_bBranch)
152 this->GetDlgItem(IDC_SUBMODULE_BRANCH)->ShowWindow(TRUE);
154 else
156 this->GetDlgItem(IDC_SUBMODULE_BRANCH)->ShowWindow(FALSE);
160 void CSubmoduleAddDlg::OnOK()
162 this->UpdateData();
163 if(m_bBranch)
165 m_strBranch.Trim();
166 if(m_strBranch.IsEmpty())
168 m_tooltips.ShowBalloon(IDC_SUBMODULE_BRANCH, IDS_ERR_MISSINGVALUE, IDS_ERR_ERROR, TTI_ERROR);
169 return;
172 m_Repository.SaveHistory();
173 m_PathCtrl.SaveHistory();
175 this->m_strPath=m_PathCtrl.GetString();
176 this->m_strRepos=m_Repository.GetString();
178 m_strPath.Trim();
179 m_strRepos.Trim();
180 if(m_strPath.IsEmpty())
182 m_tooltips.ShowBalloon(IDC_COMBOBOXEX_PATH, IDS_ERR_MISSINGVALUE, IDS_ERR_ERROR, TTI_ERROR);
183 return;
185 if(m_strRepos.IsEmpty())
187 m_tooltips.ShowBalloon(IDC_COMBOBOXEX_REPOSITORY, IDS_ERR_MISSINGVALUE, IDS_ERR_ERROR, TTI_ERROR);
188 return;
191 m_PuttyKeyCombo.SaveHistory();
192 m_PuttyKeyCombo.GetWindowText(m_strPuttyKeyFile);
193 __super::OnOK();
196 void CSubmoduleAddDlg::OnBnClickedPuttykeyfileBrowse()
198 UpdateData();
199 CString filename;
200 m_PuttyKeyCombo.GetWindowText(filename);
201 if (!PathFileExists(filename))
202 filename.Empty();
203 if (!CAppUtils::FileOpenSave(filename, nullptr, 0, IDS_PUTTYKEYFILEFILTER, true, GetSafeHwnd()))
204 return;
205 m_PuttyKeyCombo.SetWindowText(filename);
208 void CSubmoduleAddDlg::OnBnClickedPuttykeyAutoload()
210 UpdateData();
211 GetDlgItem(IDC_PUTTYKEYFILE)->EnableWindow(m_bAutoloadPuttyKeyFile);
212 GetDlgItem(IDC_PUTTYKEYFILE_BROWSE)->EnableWindow(m_bAutoloadPuttyKeyFile);