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.
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
)
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
);
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
);
79 EnableSaveRestore(_T("DeleteRemoteTagDlg"));
84 void CDeleteRemoteTagDlg::Refresh()
86 m_ctrlTags
.DeleteAllItems();
87 m_SelectAll
.SetCheck(BST_UNCHECKED
);
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 g_Git
.GetRemoteTags(m_sRemote
, m_taglist
);
97 sysProgressDlg
.Stop();
100 for (int i
= 0; i
< (int)m_taglist
.size(); ++i
)
102 m_ctrlTags
.InsertItem(i
, m_taglist
[i
]);
105 DialogEnableWindow(IDOK
, FALSE
);
108 void CDeleteRemoteTagDlg::OnBnClickedSelectall()
110 UINT state
= (m_SelectAll
.GetState() & 0x0003);
111 if (state
== BST_INDETERMINATE
)
113 // It is not at all useful to manually place the checkbox into the indeterminate state...
114 // We will force this on to the unchecked state
115 state
= BST_UNCHECKED
;
116 m_SelectAll
.SetCheck(state
);
118 if (state
== BST_UNCHECKED
)
120 m_ctrlTags
.SetItemState(-1, 0, LVIS_SELECTED
);
124 for (int i
= 0; i
< m_ctrlTags
.GetItemCount(); ++i
)
125 m_ctrlTags
.SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
129 void CDeleteRemoteTagDlg::OnBnClickedOk()
131 if (m_ctrlTags
.GetSelectedCount() > 1)
134 msg
.Format(IDS_PROC_DELETENREFS
, m_ctrlTags
.GetSelectedCount());
135 if (CMessageBox::Show(m_hWnd
, msg
, _T("TortoiseGit"), 2, IDI_QUESTION
, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 2)
138 else // GetSelectedCount() is 1, otherwise the button is disabled
140 POSITION pos
= m_ctrlTags
.GetFirstSelectedItemPosition();
142 msg
.Format(IDS_PROC_DELETEBRANCHTAG
, m_taglist
[(m_ctrlTags
.GetNextSelectedItem(pos
))]);
143 if (CMessageBox::Show(m_hWnd
, msg
, _T("TortoiseGit"), 2, IDI_QUESTION
, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 2)
148 POSITION pos
= m_ctrlTags
.GetFirstSelectedItemPosition();
150 while ((index
= m_ctrlTags
.GetNextSelectedItem(pos
)) >= 0)
151 list
.push_back(_T("refs/tags/") + m_taglist
[index
]);
152 CSysProgressDlg sysProgressDlg
;
153 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
154 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_DELETING_REMOTE_REFS
)));
155 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
156 sysProgressDlg
.SetShowProgressBar(false);
157 sysProgressDlg
.ShowModal(this, true);
158 if (g_Git
.DeleteRemoteRefs(m_sRemote
, list
))
159 CMessageBox::Show(m_hWnd
, g_Git
.GetGitLastErr(_T("Could not delete remote ref."), CGit::GIT_CMD_PUSH
), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
160 sysProgressDlg
.Stop();
165 void CDeleteRemoteTagDlg::OnSelchangeTags(NMHDR
* /*pNMHDR*/, LRESULT
* /*pResult*/)
167 DialogEnableWindow(IDOK
, m_ctrlTags
.GetSelectedCount() > 0);
168 if (m_ctrlTags
.GetSelectedCount() == 0)
169 m_SelectAll
.SetCheck(BST_UNCHECKED
);
170 else if ((int)m_ctrlTags
.GetSelectedCount() < m_ctrlTags
.GetItemCount())
171 m_SelectAll
.SetCheck(BST_INDETERMINATE
);
173 m_SelectAll
.SetCheck(BST_CHECKED
);
176 BOOL
CDeleteRemoteTagDlg::PreTranslateMessage(MSG
* pMsg
)
178 if (pMsg
->message
== WM_KEYDOWN
)
180 switch (pMsg
->wParam
)
190 return CHorizontalResizableStandAloneDialog::PreTranslateMessage(pMsg
);