No need to explicitly initialize CString and use Empty() for clearing CString
[TortoiseGit.git] / src / TortoiseProc / RenameDlg.cpp
blob4e1ee5ff387e851126805970b3fe6a6de9058385
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2009, 2011-2013, 2015 - TortoiseGit
4 // Copyright (C) 2003-2011, 2013 - TortoiseSVN
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 "TGitPath.h"
23 #include "RenameDlg.h"
24 #include "AppUtils.h"
25 #include "ControlsBridge.h"
27 IMPLEMENT_DYNAMIC(CRenameDlg, CHorizontalResizableStandAloneDialog)
28 CRenameDlg::CRenameDlg(CWnd* pParent /*=NULL*/)
29 : CHorizontalResizableStandAloneDialog(CRenameDlg::IDD, pParent)
30 , m_renameRequired(true)
31 , m_pInputValidator(NULL)
32 , m_bBalloonVisible(false)
36 CRenameDlg::~CRenameDlg()
40 void CRenameDlg::DoDataExchange(CDataExchange* pDX)
42 CHorizontalResizableStandAloneDialog::DoDataExchange(pDX);
43 DDX_Text(pDX, IDC_NAME, m_name);
47 BEGIN_MESSAGE_MAP(CRenameDlg, CHorizontalResizableStandAloneDialog)
48 ON_EN_SETFOCUS(IDC_NAME, &CRenameDlg::OnEnSetfocusName)
49 END_MESSAGE_MAP()
51 BOOL CRenameDlg::OnInitDialog()
53 CHorizontalResizableStandAloneDialog::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);
63 if (!m_name.IsEmpty())
65 CString sTmp;
66 sTmp.Format(IDS_RENAME_INFO, (LPCWSTR)m_name);
67 SetDlgItemText(IDC_RENINFOLABEL, sTmp);
70 AddAnchor(IDC_RENINFOLABEL, TOP_LEFT, TOP_RIGHT);
71 AddAnchor(IDC_LABEL, TOP_LEFT);
72 AddAnchor(IDC_NAME, TOP_LEFT, TOP_RIGHT);
73 AddAnchor(IDOK, BOTTOM_RIGHT);
74 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
76 CControlsBridge::AlignHorizontally(this, IDC_LABEL, IDC_NAME);
77 if (hWndExplorer)
78 CenterWindow(CWnd::FromHandle(hWndExplorer));
79 EnableSaveRestore(_T("RenameDlg"));
80 m_originalName = m_name;
81 return TRUE;
84 void CRenameDlg::OnOK()
86 UpdateData();
87 m_name.Trim();
88 if (m_pInputValidator)
90 CString sError = m_pInputValidator->Validate(IDC_NAME, m_name);
91 if (!sError.IsEmpty())
93 m_bBalloonVisible = true;
94 ShowEditBalloon(IDC_NAME, sError, CString(MAKEINTRESOURCE(IDS_ERR_ERROR)), TTI_ERROR);
95 return;
98 bool nameAllowed = ((m_originalName != m_name) || !m_renameRequired) && !m_name.IsEmpty();
99 if (!nameAllowed)
101 m_bBalloonVisible = true;
102 ShowEditBalloon(IDC_NAME, IDS_WARN_RENAMEREQUIRED, IDS_ERR_ERROR, TTI_ERROR);
103 return;
106 CTGitPath path(m_name);
107 if (!path.IsValidOnWindows())
109 m_bBalloonVisible = true;
110 ShowEditBalloon(IDC_NAME, IDS_WARN_NOVALIDPATH, IDS_ERR_ERROR, TTI_ERROR);
111 return;
113 CHorizontalResizableStandAloneDialog::OnOK();
116 void CRenameDlg::OnCancel()
118 // find out if there's a balloon tip showing and if there is,
119 // hide that tooltip but do NOT exit the dialog.
120 if (m_bBalloonVisible)
122 Edit_HideBalloonTip(GetDlgItem(IDC_NAME)->GetSafeHwnd());
123 return;
126 CHorizontalResizableStandAloneDialog::OnCancel();
129 void CRenameDlg::OnEnSetfocusName()
131 m_bBalloonVisible = false;