Use libgit2 to list remote tags
[TortoiseGit.git] / src / TortoiseProc / DeleteRemoteTagDlg.cpp
blob9db8f0f9d45e04859aee080c4116d5e9b4beb12e
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2012-2014 - 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 /*=NULL*/)
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 AddAnchor(IDC_EDIT_REMOTE, TOP_LEFT, TOP_RIGHT);
60 AddAnchor(IDC_LIST_TAGS, TOP_LEFT, BOTTOM_RIGHT);
61 AddAnchor(IDC_SELECTALL, BOTTOM_RIGHT);
62 AddAnchor(IDOK, BOTTOM_RIGHT);
63 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
65 this->AddOthersToAnchor();
67 AdjustControlSize((UINT)IDC_STATIC);
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(_T("DeleteRemoteTagDlg"));
81 return TRUE;
84 void CDeleteRemoteTagDlg::Refresh()
86 m_ctrlTags.DeleteAllItems();
87 m_SelectAll.SetCheck(BST_UNCHECKED);
88 m_taglist.clear();
90 CSysProgressDlg sysProgressDlg;
91 sysProgressDlg.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME)));
92 sysProgressDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_LOADING)));
93 sysProgressDlg.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT)));
94 sysProgressDlg.SetShowProgressBar(false);
95 sysProgressDlg.ShowModal(this, true);
96 git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
97 callbacks.credentials = CAppUtils::Git2GetUserPassword;
98 g_Git.GetRemoteTags(m_sRemote, m_taglist, &callbacks);
99 sysProgressDlg.Stop();
100 BringWindowToTop();
102 for (int i = 0; i < (int)m_taglist.size(); ++i)
104 m_ctrlTags.InsertItem(i, m_taglist[i]);
107 DialogEnableWindow(IDOK, FALSE);
110 void CDeleteRemoteTagDlg::OnBnClickedSelectall()
112 UINT state = (m_SelectAll.GetState() & 0x0003);
113 if (state == BST_INDETERMINATE)
115 // It is not at all useful to manually place the checkbox into the indeterminate state...
116 // We will force this on to the unchecked state
117 state = BST_UNCHECKED;
118 m_SelectAll.SetCheck(state);
120 if (state == BST_UNCHECKED)
122 m_ctrlTags.SetItemState(-1, 0, LVIS_SELECTED);
124 else
126 for (int i = 0; i < m_ctrlTags.GetItemCount(); ++i)
127 m_ctrlTags.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
131 void CDeleteRemoteTagDlg::OnBnClickedOk()
133 if (m_ctrlTags.GetSelectedCount() > 1)
135 CString msg;
136 msg.Format(IDS_PROC_DELETENREFS, m_ctrlTags.GetSelectedCount());
137 if (CMessageBox::Show(m_hWnd, msg, _T("TortoiseGit"), 2, IDI_QUESTION, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON))) == 2)
138 return;
140 else // GetSelectedCount() is 1, otherwise the button is disabled
142 POSITION pos = m_ctrlTags.GetFirstSelectedItemPosition();
143 CString msg;
144 msg.Format(IDS_PROC_DELETEBRANCHTAG, m_taglist[(m_ctrlTags.GetNextSelectedItem(pos))]);
145 if (CMessageBox::Show(m_hWnd, msg, _T("TortoiseGit"), 2, IDI_QUESTION, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON))) == 2)
146 return;
149 CMassiveGitTask mgtPush(_T("push ") + m_sRemote, FALSE);
151 POSITION pos = m_ctrlTags.GetFirstSelectedItemPosition();
152 int index;
153 while ((index = m_ctrlTags.GetNextSelectedItem(pos)) >= 0)
155 mgtPush.AddFile(_T(":refs/tags/") + m_taglist[index]);
158 CSysProgressDlg sysProgressDlg;
159 sysProgressDlg.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME)));
160 sysProgressDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_DELETING_REMOTE_REFS)));
161 sysProgressDlg.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT)));
162 sysProgressDlg.SetShowProgressBar(false);
163 sysProgressDlg.ShowModal(this, true);
164 BOOL cancel = FALSE;
165 mgtPush.Execute(cancel);
166 sysProgressDlg.Stop();
167 BringWindowToTop();
168 Refresh();
171 void CDeleteRemoteTagDlg::OnSelchangeTags(NMHDR* /*pNMHDR*/, LRESULT* /*pResult*/)
173 DialogEnableWindow(IDOK, m_ctrlTags.GetSelectedCount() > 0);
174 if (m_ctrlTags.GetSelectedCount() == 0)
175 m_SelectAll.SetCheck(BST_UNCHECKED);
176 else if ((int)m_ctrlTags.GetSelectedCount() < m_ctrlTags.GetItemCount())
177 m_SelectAll.SetCheck(BST_INDETERMINATE);
178 else
179 m_SelectAll.SetCheck(BST_CHECKED);
182 BOOL CDeleteRemoteTagDlg::PreTranslateMessage(MSG* pMsg)
184 if (pMsg->message == WM_KEYDOWN)
186 switch (pMsg->wParam)
188 case VK_F5:
190 Refresh();
192 break;
196 return CHorizontalResizableStandAloneDialog::PreTranslateMessage(pMsg);