Add checkbox to select all tags in Delete Remote Tag Dialog
[TortoiseGit.git] / src / TortoiseProc / DeleteRemoteTagDlg.cpp
blob37294ec6a26609f4d9dc181202b1e780048041a2
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2012 - 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"
28 IMPLEMENT_DYNAMIC(CDeleteRemoteTagDlg, CHorizontalResizableStandAloneDialog)
30 CDeleteRemoteTagDlg::CDeleteRemoteTagDlg(CWnd* pParent /*=NULL*/)
31 : CHorizontalResizableStandAloneDialog(CDeleteRemoteTagDlg::IDD, pParent)
35 CDeleteRemoteTagDlg::~CDeleteRemoteTagDlg()
39 void CDeleteRemoteTagDlg::DoDataExchange(CDataExchange* pDX)
41 CDialog::DoDataExchange(pDX);
42 DDX_Control(pDX, IDC_SELECTALL, m_SelectAll);
43 DDX_Control(pDX, IDC_LIST_TAGS, m_ctrlTags);
46 BEGIN_MESSAGE_MAP(CDeleteRemoteTagDlg, CHorizontalResizableStandAloneDialog)
47 ON_BN_CLICKED(IDC_SELECTALL, OnBnClickedSelectall)
48 ON_BN_CLICKED(IDOK, OnBnClickedOk)
49 ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_TAGS, OnSelchangeTags)
50 END_MESSAGE_MAP()
52 BOOL CDeleteRemoteTagDlg::OnInitDialog()
54 CHorizontalResizableStandAloneDialog::OnInitDialog();
55 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
57 AddAnchor(IDC_LIST_TAGS, TOP_LEFT, BOTTOM_RIGHT);
58 AddAnchor(IDC_SELECTALL, BOTTOM_RIGHT);
59 AddAnchor(IDOK, BOTTOM_RIGHT);
60 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
62 this->AddOthersToAnchor();
64 AdjustControlSize((UINT)IDC_STATIC);
66 CString temp;
67 temp.LoadString(IDS_PROC_TAG);
68 m_ctrlTags.InsertColumn(0, temp, 0, -1);
69 m_ctrlTags.SetColumnWidth(0, LVSCW_AUTOSIZE_USEHEADER);
70 m_ctrlTags.SetExtendedStyle(LVS_EX_DOUBLEBUFFER);
72 Refresh();
74 EnableSaveRestore(_T("DeleteRemoteTagDlg"));
76 return TRUE;
79 void CDeleteRemoteTagDlg::Refresh()
81 m_ctrlTags.DeleteAllItems();
82 m_taglist.clear();
84 g_Git.GetRemoteTags(m_sRemote, m_taglist);
86 for (int i = 0; i < (int)m_taglist.size(); i++)
88 m_ctrlTags.InsertItem(i, m_taglist[i]);
91 DialogEnableWindow(IDOK, FALSE);
94 void CDeleteRemoteTagDlg::OnBnClickedSelectall()
96 UINT state = (m_SelectAll.GetState() & 0x0003);
97 if (state == BST_INDETERMINATE)
99 // It is not at all useful to manually place the checkbox into the indeterminate state...
100 // We will force this on to the unchecked state
101 state = BST_UNCHECKED;
102 m_SelectAll.SetCheck(state);
104 if (state == BST_UNCHECKED)
106 m_ctrlTags.SetItemState(-1, 0, LVIS_SELECTED);
108 else
110 for (int i = 0; i < m_ctrlTags.GetItemCount(); i++)
111 m_ctrlTags.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
115 void CDeleteRemoteTagDlg::OnBnClickedOk()
117 if (m_ctrlTags.GetSelectedCount() > 1)
119 CString msg;
120 msg.Format(IDS_PROC_DELETENREFS, m_ctrlTags.GetSelectedCount());
121 if (CMessageBox::Show(m_hWnd, msg, _T("TortoiseGit"), 2, IDI_QUESTION, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON))) == 2)
122 return;
124 else // GetSelectedCount() is 1, otherwise the button is disabled
126 POSITION pos = m_ctrlTags.GetFirstSelectedItemPosition();
127 CString msg;
128 msg.Format(IDS_PROC_DELETEBRANCHTAG, m_taglist[(m_ctrlTags.GetNextSelectedItem(pos))]);
129 if (CMessageBox::Show(m_hWnd, msg, _T("TortoiseGit"), 2, IDI_QUESTION, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON))) == 2)
130 return;
133 CString cmd, out;
134 cmd.Format(_T("git.exe push %s"), m_sRemote);
136 POSITION pos = m_ctrlTags.GetFirstSelectedItemPosition();
137 int index;
138 while ((index = m_ctrlTags.GetNextSelectedItem(pos)) >= 0)
140 cmd += _T(" :refs/tags/") + m_taglist[index];
143 if (g_Git.Run(cmd, &out, CP_UTF8))
145 MessageBox(out, _T("TortoiseGit"), MB_ICONERROR);
147 Refresh();
150 void CDeleteRemoteTagDlg::OnSelchangeTags(NMHDR* /*pNMHDR*/, LRESULT* /*pResult*/)
152 DialogEnableWindow(IDOK, m_ctrlTags.GetSelectedCount() > 0);
153 if (m_ctrlTags.GetSelectedCount() == 0)
154 m_SelectAll.SetCheck(BST_UNCHECKED);
155 else if ((int)m_ctrlTags.GetSelectedCount() < m_ctrlTags.GetItemCount())
156 m_SelectAll.SetCheck(BST_INDETERMINATE);
157 else
158 m_SelectAll.SetCheck(BST_CHECKED);
161 BOOL CDeleteRemoteTagDlg::PreTranslateMessage(MSG* pMsg)
163 if (pMsg->message == WM_KEYDOWN)
165 switch (pMsg->wParam)
167 case VK_F5:
169 Refresh();
171 break;
175 return CHorizontalResizableStandAloneDialog::PreTranslateMessage(pMsg);