Add retry button when fetch failed
[TortoiseGit.git] / src / TortoiseProc / RenameDlg.cpp
blob9d159f3c0661a604a6af928e73dd978dcd34b857
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2009,2011-2013 - 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 "MessageBox.h"
23 #include "TGitPath.h"
24 #include "RenameDlg.h"
25 #include "AppUtils.h"
26 #include "ControlsBridge.h"
28 IMPLEMENT_DYNAMIC(CRenameDlg, CHorizontalResizableStandAloneDialog)
29 CRenameDlg::CRenameDlg(CWnd* pParent /*=NULL*/)
30 : CHorizontalResizableStandAloneDialog(CRenameDlg::IDD, pParent)
31 , m_name(_T(""))
32 , m_renameRequired(true)
33 , m_pInputValidator(NULL)
34 , m_bBalloonVisible(false)
38 CRenameDlg::~CRenameDlg()
42 void CRenameDlg::DoDataExchange(CDataExchange* pDX)
44 CHorizontalResizableStandAloneDialog::DoDataExchange(pDX);
45 DDX_Text(pDX, IDC_NAME, m_name);
49 BEGIN_MESSAGE_MAP(CRenameDlg, CHorizontalResizableStandAloneDialog)
50 ON_EN_SETFOCUS(IDC_NAME, &CRenameDlg::OnEnSetfocusName)
51 END_MESSAGE_MAP()
53 BOOL CRenameDlg::OnInitDialog()
55 CHorizontalResizableStandAloneDialog::OnInitDialog();
56 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
58 SHAutoComplete(GetDlgItem(IDC_NAME)->m_hWnd, SHACF_DEFAULT);
60 if (!m_windowtitle.IsEmpty())
61 this->SetWindowText(m_windowtitle);
62 if (!m_label.IsEmpty())
63 SetDlgItemText(IDC_LABEL, m_label);
65 if (!m_name.IsEmpty())
67 CString sTmp;
68 sTmp.Format(IDS_RENAME_INFO, (LPCWSTR)m_name);
69 SetDlgItemText(IDC_RENINFOLABEL, sTmp);
72 AddAnchor(IDC_RENINFOLABEL, TOP_LEFT, TOP_RIGHT);
73 AddAnchor(IDC_LABEL, TOP_LEFT);
74 AddAnchor(IDC_NAME, TOP_LEFT, TOP_RIGHT);
75 AddAnchor(IDOK, BOTTOM_RIGHT);
76 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
78 CControlsBridge::AlignHorizontally(this, IDC_LABEL, IDC_NAME);
79 if (hWndExplorer)
80 CenterWindow(CWnd::FromHandle(hWndExplorer));
81 EnableSaveRestore(_T("RenameDlg"));
82 m_originalName = m_name;
83 return TRUE;
86 void CRenameDlg::OnOK()
88 UpdateData();
89 m_name.Trim();
90 if (m_pInputValidator)
92 CString sError = m_pInputValidator->Validate(IDC_NAME, m_name);
93 if (!sError.IsEmpty())
95 m_bBalloonVisible = true;
96 ShowEditBalloon(IDC_NAME, sError, CString(MAKEINTRESOURCE(IDS_ERR_ERROR)), TTI_ERROR);
97 return;
100 bool nameAllowed = ((m_originalName != m_name) || !m_renameRequired) && !m_name.IsEmpty();
101 if (!nameAllowed)
103 m_bBalloonVisible = true;
104 ShowEditBalloon(IDC_NAME, IDS_WARN_RENAMEREQUIRED, IDS_ERR_ERROR, TTI_ERROR);
105 return;
108 CTGitPath path(m_name);
109 if (!path.IsValidOnWindows())
111 m_bBalloonVisible = true;
112 ShowEditBalloon(IDC_NAME, IDS_WARN_NOVALIDPATH, IDS_ERR_ERROR, TTI_ERROR);
113 return;
115 CHorizontalResizableStandAloneDialog::OnOK();
118 void CRenameDlg::OnCancel()
120 // find out if there's a balloon tip showing and if there is,
121 // hide that tooltip but do NOT exit the dialog.
122 if (m_bBalloonVisible)
124 Edit_HideBalloonTip(GetDlgItem(IDC_NAME)->GetSafeHwnd());
125 return;
128 CHorizontalResizableStandAloneDialog::OnCancel();
131 void CRenameDlg::OnEnSetfocusName()
133 m_bBalloonVisible = false;