Allow to use libgit2 for unified diff
[TortoiseGit.git] / src / TortoiseProc / ExportDlg.cpp
blob7ad1c8bb25ce94ec81ce3a548b51ff58f8bf593c
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
4 // Copyright (C) 2008-2012 - TortoiseGit
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.
20 #include "stdafx.h"
21 #include "TortoiseProc.h"
22 #include "ExportDlg.h"
24 #include "Messagebox.h"
25 #include "PathUtils.h"
26 #include "BrowseFolder.h"
27 #include "AppUtils.h"
30 IMPLEMENT_DYNAMIC(CExportDlg, CHorizontalResizableStandAloneDialog)
31 CExportDlg::CExportDlg(CWnd* pParent /*=NULL*/)
32 : CHorizontalResizableStandAloneDialog(CExportDlg::IDD, pParent)
33 , CChooseVersion(this)
34 , m_Revision(_T("HEAD"))
35 , m_strExportDirectory(_T(""))
36 , m_sExportDirOrig(_T(""))
37 , m_bNoExternals(FALSE)
38 , m_pLogDlg(NULL)
39 , m_bAutoCreateTargetName(false)
43 CExportDlg::~CExportDlg()
45 if (m_pLogDlg)
46 delete m_pLogDlg;
49 void CExportDlg::DoDataExchange(CDataExchange* pDX)
51 CHorizontalResizableStandAloneDialog::DoDataExchange(pDX);
52 DDX_Text(pDX, IDC_CHECKOUTDIRECTORY, m_strExportDirectory);
53 DDX_Control(pDX, IDC_CHECKOUTDIRECTORY, m_cCheckoutEdit);
55 CHOOSE_VERSION_DDX;
60 BEGIN_MESSAGE_MAP(CExportDlg, CHorizontalResizableStandAloneDialog)
61 ON_BN_CLICKED(IDC_CHECKOUTDIRECTORY_BROWSE, OnBnClickedCheckoutdirectoryBrowse)
62 ON_EN_CHANGE(IDC_CHECKOUTDIRECTORY, OnEnChangeCheckoutdirectory)
63 ON_BN_CLICKED(IDHELP, OnBnClickedHelp)
65 CHOOSE_VERSION_EVENT
66 ON_WM_DESTROY()
67 END_MESSAGE_MAP()
69 BOOL CExportDlg::OnInitDialog()
71 CHorizontalResizableStandAloneDialog::OnInitDialog();
72 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
74 m_sExportDirOrig = m_strExportDirectory;
75 m_bAutoCreateTargetName = !PathIsDirectoryEmpty(m_sExportDirOrig);
77 AddAnchor(IDC_REPOGROUP, TOP_LEFT, TOP_RIGHT);
78 AddAnchor(IDC_EXPORT_CHECKOUTDIR, TOP_LEFT);
79 AddAnchor(IDC_CHECKOUTDIRECTORY_BROWSE, TOP_RIGHT);
80 AddAnchor(IDC_CHECKOUTDIRECTORY, TOP_LEFT, TOP_RIGHT);
82 AddAnchor(IDOK, BOTTOM_RIGHT);
83 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
84 AddAnchor(IDHELP, BOTTOM_RIGHT);
86 AdjustControlSize(IDC_RADIO_HEAD);
87 AdjustControlSize(IDC_RADIO_BRANCH);
88 AdjustControlSize(IDC_RADIO_TAGS);
89 AdjustControlSize(IDC_RADIO_VERSION);
91 CString sWindowTitle;
92 GetWindowText(sWindowTitle);
93 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
95 CHOOSE_VERSION_ADDANCHOR;
96 this->AddOthersToAnchor();
97 Init();
98 if(this->m_Revision.IsEmpty())
100 SetDefaultChoose(IDC_RADIO_HEAD);
102 else
104 SetDefaultChoose(IDC_RADIO_VERSION);
105 this->GetDlgItem(IDC_COMBOBOXEX_VERSION)->SetWindowTextW(m_Revision);
108 m_tooltips.Create(this);
109 m_tooltips.AddTool(IDC_CHECKOUTDIRECTORY, IDS_CHECKOUT_TT_DIR);
111 SHAutoComplete(GetDlgItem(IDC_CHECKOUTDIRECTORY)->m_hWnd, SHACF_FILESYSTEM);
113 if ((m_pParentWnd==NULL)&&(hWndExplorer))
114 CenterWindow(CWnd::FromHandle(hWndExplorer));
115 EnableSaveRestore(_T("ExportDlg"));
116 return TRUE;
119 void CExportDlg::OnOK()
121 if (!UpdateData(TRUE))
122 return; // don't dismiss dialog (error message already shown by MFC framework)
124 // check it the export path is a valid windows path
125 UpdateRevsionName();
127 if (m_VersionName.IsEmpty())
129 m_tooltips.ShowBalloon(IDC_COMBOBOXEX_VERSION, IDS_ERR_INVALIDREV, IDS_ERR_ERROR, TTI_ERROR);
130 return;
133 m_bAutoCreateTargetName = false;
135 // m_URLCombo.SaveHistory();
136 // m_URL = m_URLCombo.GetString();
139 if(::PathFileExists(this->m_strExportDirectory))
141 if(::PathIsDirectory(m_strExportDirectory))
143 CMessageBox::Show(NULL, IDS_PROCEXPORTERRFOLDER, IDS_APPNAME, MB_OK | MB_ICONERROR);
144 return;
146 CString sMessage;
147 sMessage.Format(IDS_PROC_OVERWRITE_CONFIRM, m_strExportDirectory);
148 if (CMessageBox::Show(NULL, sMessage, _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2) != IDYES)
150 return ;
153 else if (m_strExportDirectory.IsEmpty())
155 CMessageBox::Show(NULL, IDS_PROC_NOZIPFILE, IDS_APPNAME, MB_OK | MB_ICONERROR);
156 return;
159 UpdateData(FALSE);
160 CHorizontalResizableStandAloneDialog::OnOK();
163 void CExportDlg::OnBnClickedBrowse()
165 m_tooltips.Pop(); // hide the tooltips
169 void CExportDlg::OnBnClickedCheckoutdirectoryBrowse()
171 m_tooltips.Pop(); // hide the tooltips
173 // Create a folder browser dialog. If the user selects OK, we should update
174 // the local data members with values from the controls, copy the checkout
175 // directory from the browse folder, then restore the local values into the
176 // dialog controls.
178 this->UpdateRevsionName();
179 CFileDialog dlg(FALSE, _T("zip"), this->m_VersionName, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("*.zip"));
181 INT_PTR ret = dlg.DoModal();
182 SetCurrentDirectory(g_Git.m_CurrentDir);
183 if (ret == IDOK)
185 UpdateData(TRUE);
186 m_strExportDirectory = dlg.GetPathName();
187 UpdateData(FALSE);
191 BOOL CExportDlg::PreTranslateMessage(MSG* pMsg)
193 m_tooltips.RelayEvent(pMsg);
194 return CHorizontalResizableStandAloneDialog::PreTranslateMessage(pMsg);
197 void CExportDlg::OnEnChangeCheckoutdirectory()
199 UpdateData(TRUE);
200 DialogEnableWindow(IDOK, !m_strExportDirectory.IsEmpty());
203 void CExportDlg::OnBnClickedHelp()
205 OnHelp();
208 void CExportDlg::OnBnClickedShowlog()
210 m_tooltips.Pop(); // hide the tooltips
214 void CExportDlg::OnCbnSelchangeEolcombo()
218 void CExportDlg::OnCbnEditchangeUrlcombo()
220 if (!m_bAutoCreateTargetName)
221 return;
222 if (m_sExportDirOrig.IsEmpty())
223 return;
224 // find out what to use as the checkout directory name
225 UpdateData();
226 m_URLCombo.GetWindowText(m_URL);
227 if (m_URL.IsEmpty())
228 return;
229 CString name = CAppUtils::GetProjectNameFromURL(m_URL);
230 m_strExportDirectory = m_sExportDirOrig+_T('\\')+name;
231 UpdateData(FALSE);
234 void CExportDlg::OnDestroy()
236 WaitForFinishLoading();
237 __super::OnDestroy();