TortoiseSVN -> TortoiseGit
[TortoiseGit.git] / src / TortoiseProc / RenameDlg.cpp
blobc483aa82919f258db22889342866f374189a8968
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 "MessageBox.h"
22 #include "TGitPath.h"
23 #include "RenameDlg.h"
24 #include ".\renamedlg.h"
25 #include "CommonResource.h"
26 #include "AppUtils.h"
28 IMPLEMENT_DYNAMIC(CRenameDlg, CResizableStandAloneDialog)
29 CRenameDlg::CRenameDlg(CWnd* pParent /*=NULL*/)
30 : CResizableStandAloneDialog(CRenameDlg::IDD, pParent)
31 , m_name(_T(""))
35 CRenameDlg::~CRenameDlg()
39 void CRenameDlg::DoDataExchange(CDataExchange* pDX)
41 CResizableStandAloneDialog::DoDataExchange(pDX);
42 DDX_Text(pDX, IDC_NAME, m_name);
46 BEGIN_MESSAGE_MAP(CRenameDlg, CResizableStandAloneDialog)
47 ON_WM_SIZING()
48 ON_EN_CHANGE(IDC_NAME, OnEnChangeName)
49 END_MESSAGE_MAP()
51 BOOL CRenameDlg::OnInitDialog()
53 CResizableStandAloneDialog::OnInitDialog();
54 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
56 SHAutoComplete(GetDlgItem(IDC_NAME)->m_hWnd, SHACF_DEFAULT);
58 if (!m_windowtitle.IsEmpty())
59 this->SetWindowText(m_windowtitle);
60 if (!m_label.IsEmpty())
61 SetDlgItemText(IDC_LABEL, m_label);
62 AddAnchor(IDC_LABEL, TOP_LEFT);
63 AddAnchor(IDC_NAME, TOP_LEFT, TOP_RIGHT);
64 AddAnchor(IDOK, BOTTOM_RIGHT);
65 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
66 if (hWndExplorer)
67 CenterWindow(CWnd::FromHandle(hWndExplorer));
68 EnableSaveRestore(_T("RenameDlg"));
69 GetDlgItem(IDOK)->EnableWindow(FALSE);
70 return TRUE;
73 void CRenameDlg::OnOK()
75 UpdateData();
76 m_name.Trim();
77 CTGitPath path(m_name);
78 if (!path.IsValidOnWindows())
80 if (CMessageBox::Show(GetSafeHwnd(), IDS_WARN_NOVALIDPATH, IDS_APPNAME, MB_ICONWARNING | MB_OKCANCEL)==IDCANCEL)
81 return;
83 CResizableDialog::OnOK();
86 void CRenameDlg::OnSizing(UINT fwSide, LPRECT pRect)
88 // don't allow the dialog to be changed in height
89 CRect rcWindowRect;
90 GetWindowRect(&rcWindowRect);
91 switch (fwSide)
93 case WMSZ_BOTTOM:
94 case WMSZ_BOTTOMLEFT:
95 case WMSZ_BOTTOMRIGHT:
96 pRect->bottom = pRect->top + rcWindowRect.Height();
97 break;
98 case WMSZ_TOP:
99 case WMSZ_TOPLEFT:
100 case WMSZ_TOPRIGHT:
101 pRect->top = pRect->bottom - rcWindowRect.Height();
102 break;
104 CResizableStandAloneDialog::OnSizing(fwSide, pRect);
107 void CRenameDlg::OnEnChangeName()
109 UpdateData();
110 GetDlgItem(IDOK)->EnableWindow(!m_name.IsEmpty());