1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - 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"
27 #include "MessageBox.h"
30 // CSubmoduleAddDlg dialog
32 IMPLEMENT_DYNAMIC(CSubmoduleAddDlg
, CHorizontalResizableStandAloneDialog
)
34 CSubmoduleAddDlg::CSubmoduleAddDlg(CWnd
* pParent
/*=NULL*/)
35 : CHorizontalResizableStandAloneDialog(CSubmoduleAddDlg::IDD
, pParent
)
40 m_bAutoloadPuttyKeyFile
= CAppUtils::IsSSHPutty();
43 CSubmoduleAddDlg::~CSubmoduleAddDlg()
47 void CSubmoduleAddDlg::DoDataExchange(CDataExchange
* pDX
)
49 CDialog::DoDataExchange(pDX
);
50 DDX_Control(pDX
, IDC_COMBOBOXEX_REPOSITORY
, m_Repository
);
51 DDX_Control(pDX
, IDC_COMBOBOXEX_PATH
, m_PathCtrl
);
52 DDX_Check(pDX
, IDC_BRANCH_CHECK
, m_bBranch
);
53 DDX_Text(pDX
, IDC_SUBMODULE_BRANCH
, m_strBranch
);
54 DDX_Check(pDX
, IDC_FORCE
, m_bForce
);
55 DDX_Check(pDX
,IDC_PUTTYKEY_AUTOLOAD
, m_bAutoloadPuttyKeyFile
);
56 DDX_Control(pDX
, IDC_PUTTYKEYFILE
, m_PuttyKeyCombo
);
60 BEGIN_MESSAGE_MAP(CSubmoduleAddDlg
, CHorizontalResizableStandAloneDialog
)
61 ON_COMMAND(IDC_REP_BROWSE
, OnRepBrowse
)
62 ON_COMMAND(IDC_BUTTON_PATH_BROWSE
, OnPathBrowse
)
63 ON_COMMAND(IDC_BRANCH_CHECK
, OnBranchCheck
)
64 ON_BN_CLICKED(IDC_PUTTYKEYFILE_BROWSE
, OnBnClickedPuttykeyfileBrowse
)
65 ON_BN_CLICKED(IDC_PUTTYKEY_AUTOLOAD
, OnBnClickedPuttykeyAutoload
)
69 // CSubmoduleAddDlg message handlers
71 BOOL
CSubmoduleAddDlg::OnInitDialog()
73 CHorizontalResizableStandAloneDialog::OnInitDialog();
74 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
76 AddAnchor(IDOK
,BOTTOM_RIGHT
);
77 AddAnchor(IDCANCEL
,BOTTOM_RIGHT
);
78 AddAnchor(IDC_GROUP_SUBMODULE
,TOP_LEFT
,BOTTOM_RIGHT
);
79 AddAnchor(IDC_COMBOBOXEX_REPOSITORY
,TOP_LEFT
,TOP_RIGHT
);
80 AddAnchor(IDC_COMBOBOXEX_PATH
,TOP_LEFT
,TOP_RIGHT
);
81 AddAnchor(IDC_REP_BROWSE
,TOP_RIGHT
);
82 AddAnchor(IDC_BUTTON_PATH_BROWSE
,TOP_RIGHT
);
83 AddAnchor(IDC_BRANCH_CHECK
,BOTTOM_LEFT
);
84 AddAnchor(IDC_SUBMODULE_BRANCH
,BOTTOM_LEFT
,BOTTOM_RIGHT
);
85 AddAnchor(IDC_FORCE
,BOTTOM_LEFT
);
86 AddAnchor(IDC_PUTTYKEYFILE_BROWSE
,TOP_RIGHT
);
87 AddAnchor(IDC_PUTTYKEY_AUTOLOAD
,TOP_LEFT
);
88 AddAnchor(IDC_PUTTYKEYFILE
,TOP_LEFT
,TOP_RIGHT
);
89 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
92 AdjustControlSize(IDC_BRANCH_CHECK
);
93 AdjustControlSize(IDC_FORCE
);
94 AdjustControlSize(IDC_PUTTYKEY_AUTOLOAD
);
96 EnableSaveRestore(_T("SubmoduleAddDlg"));
99 GetWindowText(sWindowTitle
);
100 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.CombinePath(m_strPath
).TrimRight('\\'), sWindowTitle
);
102 m_Repository
.SetURLHistory(true);
103 m_Repository
.SetCaseSensitive(TRUE
);
104 m_PathCtrl
.SetPathHistory(true);
106 m_Repository
.LoadHistory(_T("Software\\TortoiseGit\\History\\SubModuleRepoURLS"), _T("url"));
107 m_PathCtrl
.LoadHistory(_T("Software\\TortoiseGit\\History\\SubModulePath"), _T("url"));
108 m_PathCtrl
.SetWindowText(m_strPath
);
109 m_Repository
.SetCurSel(0);
111 m_PuttyKeyCombo
.SetPathHistory(TRUE
);
112 m_PuttyKeyCombo
.LoadHistory(_T("Software\\TortoiseGit\\History\\puttykey"), _T("key"));
113 m_PuttyKeyCombo
.SetCurSel(0);
115 GetDlgItem(IDC_PUTTYKEY_AUTOLOAD
)->EnableWindow(CAppUtils::IsSSHPutty());
116 GetDlgItem(IDC_PUTTYKEYFILE
)->EnableWindow(m_bAutoloadPuttyKeyFile
);
117 GetDlgItem(IDC_PUTTYKEYFILE_BROWSE
)->EnableWindow(m_bAutoloadPuttyKeyFile
);
119 GetDlgItem(IDC_GROUP_SUBMODULE
)->SetWindowText(CString(_T("Submodule of Project: "))+m_strProject
);
121 m_tooltips
.Create(this);
126 void CSubmoduleAddDlg::OnRepBrowse()
128 CBrowseFolder browseFolder
;
129 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
130 CString strDirectory
;
131 this->m_Repository
.GetWindowTextW(strDirectory
);
132 if (browseFolder
.Show(GetSafeHwnd(), strDirectory
) == CBrowseFolder::OK
)
134 this->m_Repository
.SetWindowTextW(strDirectory
);
137 void CSubmoduleAddDlg::OnPathBrowse()
139 CBrowseFolder browseFolder
;
140 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
141 CString strDirectory
;
142 this->m_PathCtrl
.GetWindowTextW(strDirectory
);
143 if (browseFolder
.Show(GetSafeHwnd(), strDirectory
,g_Git
.m_CurrentDir
) == CBrowseFolder::OK
)
145 this->m_PathCtrl
.SetWindowTextW(strDirectory
);
148 void CSubmoduleAddDlg::OnBranchCheck()
153 this->GetDlgItem(IDC_SUBMODULE_BRANCH
)->ShowWindow(TRUE
);
157 this->GetDlgItem(IDC_SUBMODULE_BRANCH
)->ShowWindow(FALSE
);
161 void CSubmoduleAddDlg::OnOK()
167 if(m_strBranch
.IsEmpty())
169 m_tooltips
.ShowBalloon(IDC_SUBMODULE_BRANCH
, IDS_ERR_MISSINGVALUE
, IDS_ERR_ERROR
, TTI_ERROR
);
173 m_Repository
.SaveHistory();
174 m_PathCtrl
.SaveHistory();
176 this->m_strPath
=m_PathCtrl
.GetString();
177 this->m_strRepos
=m_Repository
.GetString();
181 if(m_strPath
.IsEmpty())
183 m_tooltips
.ShowBalloon(IDC_COMBOBOXEX_PATH
, IDS_ERR_MISSINGVALUE
, IDS_ERR_ERROR
, TTI_ERROR
);
186 if(m_strRepos
.IsEmpty())
188 m_tooltips
.ShowBalloon(IDC_COMBOBOXEX_REPOSITORY
, IDS_ERR_MISSINGVALUE
, IDS_ERR_ERROR
, TTI_ERROR
);
192 m_PuttyKeyCombo
.SaveHistory();
193 m_PuttyKeyCombo
.GetWindowText(m_strPuttyKeyFile
);
197 void CSubmoduleAddDlg::OnBnClickedPuttykeyfileBrowse()
200 CFileDialog
dlg(TRUE
, NULL
, NULL
, OFN_HIDEREADONLY
| OFN_OVERWRITEPROMPT
, CString(MAKEINTRESOURCE(IDS_PUTTYKEYFILEFILTER
)));
201 if (dlg
.DoModal()==IDOK
)
203 m_PuttyKeyCombo
.SetWindowText(dlg
.GetPathName());
207 void CSubmoduleAddDlg::OnBnClickedPuttykeyAutoload()
210 GetDlgItem(IDC_PUTTYKEYFILE
)->EnableWindow(m_bAutoloadPuttyKeyFile
);
211 GetDlgItem(IDC_PUTTYKEYFILE_BROWSE
)->EnableWindow(m_bAutoloadPuttyKeyFile
);