drop gooffline
[TortoiseGit.git] / src / TortoiseProc / ImportDlg.cpp
blob7f89899746b43bb96fb873f7dde3c5de8faf7568
1 // TortoiseSVN - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
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.
19 #include "stdafx.h"
20 #include "TortoiseProc.h"
21 #include "ImportDlg.h"
22 #include "RepositoryBrowser.h"
23 #include "AppUtils.h"
24 #include "DirFileEnum.h"
25 #include "MessageBox.h"
26 #include "BrowseFolder.h"
27 #include "Registry.h"
28 #include "HistoryDlg.h"
30 IMPLEMENT_DYNAMIC(CImportDlg, CResizableStandAloneDialog)
31 CImportDlg::CImportDlg(CWnd* pParent /*=NULL*/)
32 : CResizableStandAloneDialog(CImportDlg::IDD, pParent)
33 , m_bIncludeIgnored(FALSE)
37 CImportDlg::~CImportDlg()
41 void CImportDlg::DoDataExchange(CDataExchange* pDX)
43 CResizableStandAloneDialog::DoDataExchange(pDX);
44 DDX_Control(pDX, IDC_URLCOMBO, m_URLCombo);
45 DDX_Control(pDX, IDC_BROWSE, m_butBrowse);
46 DDX_Control(pDX, IDC_MESSAGE, m_cMessage);
47 DDX_Check(pDX, IDC_IMPORTIGNORED, m_bIncludeIgnored);
50 BEGIN_MESSAGE_MAP(CImportDlg, CResizableStandAloneDialog)
51 ON_BN_CLICKED(IDC_BROWSE, OnBnClickedBrowse)
52 ON_BN_CLICKED(IDHELP, OnBnClickedHelp)
53 ON_EN_CHANGE(IDC_MESSAGE, OnEnChangeLogmessage)
54 ON_BN_CLICKED(IDC_HISTORY, OnBnClickedHistory)
55 END_MESSAGE_MAP()
57 BOOL CImportDlg::OnInitDialog()
59 CResizableStandAloneDialog::OnInitDialog();
61 m_History.SetMaxHistoryItems((LONG)CRegDWORD(_T("Software\\TortoiseGit\\MaxHistoryItems"), 25));
63 if (m_url.IsEmpty())
65 m_URLCombo.SetURLHistory(TRUE);
66 m_URLCombo.LoadHistory(_T("Software\\TortoiseGit\\History\\repoURLS"), _T("url"));
68 else
70 m_URLCombo.SetWindowText(m_url);
71 if (GetFocus() == &m_URLCombo)
72 SendMessage(WM_NEXTDLGCTL, 0, FALSE);
73 m_URLCombo.EnableWindow(FALSE);
75 m_URLCombo.SetCurSel(0);
77 m_tooltips.Create(this);
78 m_tooltips.AddTool(IDC_HISTORY, IDS_COMMITDLG_HISTORY_TT);
80 m_History.Load(_T("Software\\TortoiseGit\\History\\commit"), _T("logmsgs"));
81 m_ProjectProperties.ReadProps(m_path);
82 m_cMessage.Init(m_ProjectProperties);
83 m_cMessage.SetFont((CString)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));
85 AdjustControlSize(IDC_IMPORTIGNORED);
87 AddAnchor(IDC_STATIC1, TOP_LEFT, TOP_RIGHT);
88 AddAnchor(IDC_STATIC4, TOP_LEFT);
89 AddAnchor(IDC_URLCOMBO, TOP_LEFT, TOP_RIGHT);
90 AddAnchor(IDC_BROWSE, TOP_RIGHT);
91 AddAnchor(IDC_STATIC2, TOP_LEFT, BOTTOM_RIGHT);
92 AddAnchor(IDC_MESSAGE, TOP_LEFT, BOTTOM_RIGHT);
93 AddAnchor(IDC_HISTORY, TOP_LEFT);
94 AddAnchor(IDC_IMPORTIGNORED, BOTTOM_LEFT);
95 AddAnchor(IDOK, BOTTOM_RIGHT);
96 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
97 AddAnchor(IDHELP, BOTTOM_RIGHT);
99 if (hWndExplorer)
100 CenterWindow(CWnd::FromHandle(hWndExplorer));
101 EnableSaveRestore(_T("ImportDlg"));
102 return TRUE; // return TRUE unless you set the focus to a control
105 void CImportDlg::OnOK()
107 if (m_URLCombo.IsWindowEnabled())
109 m_URLCombo.SaveHistory();
110 m_url = m_URLCombo.GetString();
111 UpdateData();
114 UpdateData();
115 m_sMessage = m_cMessage.GetText();
116 m_History.AddEntry(m_sMessage);
117 m_History.Save();
119 CResizableStandAloneDialog::OnOK();
122 void CImportDlg::OnBnClickedBrowse()
124 m_tooltips.Pop(); // hide the tooltips
125 SVNRev rev(SVNRev::REV_HEAD);
126 CAppUtils::BrowseRepository(m_URLCombo, this, rev);
129 BOOL CImportDlg::PreTranslateMessage(MSG* pMsg)
131 m_tooltips.RelayEvent(pMsg);
132 if (pMsg->message == WM_KEYDOWN)
134 switch (pMsg->wParam)
136 case VK_RETURN:
138 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
140 if ( GetDlgItem(IDOK)->IsWindowEnabled() )
142 PostMessage(WM_COMMAND, IDOK);
146 break;
149 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
152 void CImportDlg::OnBnClickedHelp()
154 OnHelp();
157 void CImportDlg::OnEnChangeLogmessage()
159 CString sTemp = m_cMessage.GetText();
160 DialogEnableWindow(IDOK, sTemp.GetLength() >= m_ProjectProperties.nMinLogSize);
163 void CImportDlg::OnCancel()
165 UpdateData();
166 if (m_ProjectProperties.sLogTemplate.Compare(m_cMessage.GetText()) != 0)
167 m_History.AddEntry(m_cMessage.GetText());
168 m_History.Save();
169 CResizableStandAloneDialog::OnCancel();
172 void CImportDlg::OnBnClickedHistory()
174 m_tooltips.Pop(); // hide the tooltips
175 SVN svn;
176 CHistoryDlg historyDlg;
177 historyDlg.SetHistory(m_History);
178 if (historyDlg.DoModal()==IDOK)
180 if (historyDlg.GetSelectedText().Compare(m_cMessage.GetText().Left(historyDlg.GetSelectedText().GetLength()))!=0)
182 if (m_ProjectProperties.sLogTemplate.Compare(m_cMessage.GetText())!=0)
183 m_cMessage.InsertText(historyDlg.GetSelectedText(), !m_cMessage.GetText().IsEmpty());
184 else
185 m_cMessage.SetText(historyDlg.GetSelectedText());
187 DialogEnableWindow(IDOK, m_ProjectProperties.nMinLogSize <= m_cMessage.GetText().GetLength());