Don't import ogdf namespace
[TortoiseGit.git] / src / TortoiseProc / DeleteRemoteTagDlg.cpp
blobf8c5f30d7d2efdbb736e020f0aebe065dda0092c
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2012-2017 - TortoiseGit
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.
20 #include "stdafx.h"
22 #include "Git.h"
23 #include "AppUtils.h"
24 #include "TortoiseProc.h"
25 #include "DeleteRemoteTagDlg.h"
26 #include "MessageBox.h"
27 #include "MassiveGitTask.h"
28 #include "SysProgressDlg.h"
30 IMPLEMENT_DYNAMIC(CDeleteRemoteTagDlg, CHorizontalResizableStandAloneDialog)
32 CDeleteRemoteTagDlg::CDeleteRemoteTagDlg(CWnd* pParent /*=nullptr*/)
33 : CHorizontalResizableStandAloneDialog(CDeleteRemoteTagDlg::IDD, pParent)
37 CDeleteRemoteTagDlg::~CDeleteRemoteTagDlg()
41 void CDeleteRemoteTagDlg::DoDataExchange(CDataExchange* pDX)
43 CDialog::DoDataExchange(pDX);
44 DDX_Control(pDX, IDC_SELECTALL, m_SelectAll);
45 DDX_Control(pDX, IDC_LIST_TAGS, m_ctrlTags);
48 BEGIN_MESSAGE_MAP(CDeleteRemoteTagDlg, CHorizontalResizableStandAloneDialog)
49 ON_BN_CLICKED(IDC_SELECTALL, OnBnClickedSelectall)
50 ON_BN_CLICKED(IDOK, OnBnClickedOk)
51 ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_TAGS, OnSelchangeTags)
52 END_MESSAGE_MAP()
54 BOOL CDeleteRemoteTagDlg::OnInitDialog()
56 CHorizontalResizableStandAloneDialog::OnInitDialog();
57 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
59 AdjustControlSize((UINT)IDC_STATIC);
61 AddAnchor(IDC_EDIT_REMOTE, TOP_LEFT, TOP_RIGHT);
62 AddAnchor(IDC_LIST_TAGS, TOP_LEFT, BOTTOM_RIGHT);
63 AddAnchor(IDC_SELECTALL, BOTTOM_RIGHT);
64 AddAnchor(IDOK, BOTTOM_RIGHT);
65 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
67 this->AddOthersToAnchor();
69 CString temp;
70 temp.LoadString(IDS_PROC_TAG);
71 m_ctrlTags.InsertColumn(0, temp, 0, -1);
72 m_ctrlTags.SetColumnWidth(0, LVSCW_AUTOSIZE_USEHEADER);
73 m_ctrlTags.SetExtendedStyle(LVS_EX_DOUBLEBUFFER);
75 GetDlgItem(IDC_EDIT_REMOTE)->SetWindowText(m_sRemote);
77 Refresh();
79 EnableSaveRestore(L"DeleteRemoteTagDlg");
81 return TRUE;
84 void CDeleteRemoteTagDlg::Refresh()
86 m_ctrlTags.DeleteAllItems();
87 m_SelectAll.SetCheck(BST_UNCHECKED);
89 CSysProgressDlg sysProgressDlg;
90 sysProgressDlg.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME)));
91 sysProgressDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_LOADING)));
92 sysProgressDlg.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT)));
93 sysProgressDlg.SetShowProgressBar(false);
94 sysProgressDlg.ShowModal(this, true);
95 REF_VECTOR tags;
96 if (g_Git.GetRemoteTags(m_sRemote, tags))
98 sysProgressDlg.Stop();
99 MessageBox(g_Git.GetGitLastErr(L"Could not retrieve remote tags.", CGit::GIT_CMD_FETCH), L"TortoiseGit", MB_ICONERROR);
101 sysProgressDlg.Stop();
102 BringWindowToTop();
104 for (int i = 0; i < (int)tags.size(); ++i)
106 if (CStringUtils::EndsWith(tags[i].name, L"^{}"))
107 continue;
108 m_ctrlTags.InsertItem(i, tags[i].name);
111 DialogEnableWindow(IDOK, FALSE);
114 void CDeleteRemoteTagDlg::OnBnClickedSelectall()
116 UINT state = (m_SelectAll.GetState() & 0x0003);
117 if (state == BST_INDETERMINATE)
119 // It is not at all useful to manually place the checkbox into the indeterminate state...
120 // We will force this on to the unchecked state
121 state = BST_UNCHECKED;
122 m_SelectAll.SetCheck(state);
124 if (state == BST_UNCHECKED)
125 m_ctrlTags.SetItemState(-1, 0, LVIS_SELECTED);
126 else
128 for (int i = 0; i < m_ctrlTags.GetItemCount(); ++i)
129 m_ctrlTags.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
133 void CDeleteRemoteTagDlg::OnBnClickedOk()
135 if (m_ctrlTags.GetSelectedCount() > 1)
137 CString msg;
138 msg.Format(IDS_PROC_DELETENREFS, m_ctrlTags.GetSelectedCount());
139 if (CMessageBox::Show(GetSafeHwnd(), msg, L"TortoiseGit", 2, IDI_QUESTION, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON))) == 2)
140 return;
142 else // GetSelectedCount() is 1, otherwise the button is disabled
144 POSITION pos = m_ctrlTags.GetFirstSelectedItemPosition();
145 CString msg;
146 msg.Format(IDS_PROC_DELETEBRANCHTAG, (LPCTSTR)m_ctrlTags.GetItemText(m_ctrlTags.GetNextSelectedItem(pos), 0));
147 if (CMessageBox::Show(GetSafeHwnd(), msg, L"TortoiseGit", 2, IDI_QUESTION, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON))) == 2)
148 return;
151 STRING_VECTOR list;
152 POSITION pos = m_ctrlTags.GetFirstSelectedItemPosition();
153 int index;
154 while ((index = m_ctrlTags.GetNextSelectedItem(pos)) >= 0)
155 list.push_back(L"refs/tags/" + m_ctrlTags.GetItemText(index, 0));
156 CSysProgressDlg sysProgressDlg;
157 sysProgressDlg.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME)));
158 sysProgressDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_DELETING_REMOTE_REFS)));
159 sysProgressDlg.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT)));
160 sysProgressDlg.SetShowProgressBar(false);
161 sysProgressDlg.ShowModal(this, true);
162 if (g_Git.DeleteRemoteRefs(m_sRemote, list))
163 CMessageBox::Show(GetSafeHwnd(), g_Git.GetGitLastErr(L"Could not delete remote ref.", CGit::GIT_CMD_PUSH), L"TortoiseGit", MB_OK | MB_ICONERROR);
164 sysProgressDlg.Stop();
165 BringWindowToTop();
166 Refresh();
169 void CDeleteRemoteTagDlg::OnSelchangeTags(NMHDR* /*pNMHDR*/, LRESULT* /*pResult*/)
171 DialogEnableWindow(IDOK, m_ctrlTags.GetSelectedCount() > 0);
172 if (m_ctrlTags.GetSelectedCount() == 0)
173 m_SelectAll.SetCheck(BST_UNCHECKED);
174 else if ((int)m_ctrlTags.GetSelectedCount() < m_ctrlTags.GetItemCount())
175 m_SelectAll.SetCheck(BST_INDETERMINATE);
176 else
177 m_SelectAll.SetCheck(BST_CHECKED);
180 BOOL CDeleteRemoteTagDlg::PreTranslateMessage(MSG* pMsg)
182 if (pMsg->message == WM_KEYDOWN)
184 switch (pMsg->wParam)
186 case VK_F5:
188 Refresh();
190 break;
194 return CHorizontalResizableStandAloneDialog::PreTranslateMessage(pMsg);