1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2012-2013 - 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_LIST_TAGS
, TOP_LEFT
, BOTTOM_RIGHT
);
60 AddAnchor(IDC_SELECTALL
, BOTTOM_RIGHT
);
61 AddAnchor(IDOK
, BOTTOM_RIGHT
);
62 AddAnchor(IDCANCEL
, BOTTOM_RIGHT
);
64 this->AddOthersToAnchor();
66 AdjustControlSize((UINT
)IDC_STATIC
);
69 temp
.LoadString(IDS_PROC_TAG
);
70 m_ctrlTags
.InsertColumn(0, temp
, 0, -1);
71 m_ctrlTags
.SetColumnWidth(0, LVSCW_AUTOSIZE_USEHEADER
);
72 m_ctrlTags
.SetExtendedStyle(LVS_EX_DOUBLEBUFFER
);
76 EnableSaveRestore(_T("DeleteRemoteTagDlg"));
81 void CDeleteRemoteTagDlg::Refresh()
83 m_ctrlTags
.DeleteAllItems();
84 m_SelectAll
.SetCheck(BST_UNCHECKED
);
87 CSysProgressDlg sysProgressDlg
;
88 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
89 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_LOADING
)));
90 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
91 sysProgressDlg
.SetShowProgressBar(false);
92 sysProgressDlg
.ShowModal(this, true);
93 g_Git
.GetRemoteTags(m_sRemote
, m_taglist
);
94 sysProgressDlg
.Stop();
96 for (int i
= 0; i
< (int)m_taglist
.size(); ++i
)
98 m_ctrlTags
.InsertItem(i
, m_taglist
[i
]);
101 DialogEnableWindow(IDOK
, FALSE
);
104 void CDeleteRemoteTagDlg::OnBnClickedSelectall()
106 UINT state
= (m_SelectAll
.GetState() & 0x0003);
107 if (state
== BST_INDETERMINATE
)
109 // It is not at all useful to manually place the checkbox into the indeterminate state...
110 // We will force this on to the unchecked state
111 state
= BST_UNCHECKED
;
112 m_SelectAll
.SetCheck(state
);
114 if (state
== BST_UNCHECKED
)
116 m_ctrlTags
.SetItemState(-1, 0, LVIS_SELECTED
);
120 for (int i
= 0; i
< m_ctrlTags
.GetItemCount(); ++i
)
121 m_ctrlTags
.SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
125 void CDeleteRemoteTagDlg::OnBnClickedOk()
127 if (m_ctrlTags
.GetSelectedCount() > 1)
130 msg
.Format(IDS_PROC_DELETENREFS
, m_ctrlTags
.GetSelectedCount());
131 if (CMessageBox::Show(m_hWnd
, msg
, _T("TortoiseGit"), 2, IDI_QUESTION
, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 2)
134 else // GetSelectedCount() is 1, otherwise the button is disabled
136 POSITION pos
= m_ctrlTags
.GetFirstSelectedItemPosition();
138 msg
.Format(IDS_PROC_DELETEBRANCHTAG
, m_taglist
[(m_ctrlTags
.GetNextSelectedItem(pos
))]);
139 if (CMessageBox::Show(m_hWnd
, msg
, _T("TortoiseGit"), 2, IDI_QUESTION
, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 2)
143 CMassiveGitTask
mgtPush(_T("push ") + m_sRemote
, FALSE
);
145 POSITION pos
= m_ctrlTags
.GetFirstSelectedItemPosition();
147 while ((index
= m_ctrlTags
.GetNextSelectedItem(pos
)) >= 0)
149 mgtPush
.AddFile(_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);
159 mgtPush
.Execute(cancel
);
160 sysProgressDlg
.Stop();
164 void CDeleteRemoteTagDlg::OnSelchangeTags(NMHDR
* /*pNMHDR*/, LRESULT
* /*pResult*/)
166 DialogEnableWindow(IDOK
, m_ctrlTags
.GetSelectedCount() > 0);
167 if (m_ctrlTags
.GetSelectedCount() == 0)
168 m_SelectAll
.SetCheck(BST_UNCHECKED
);
169 else if ((int)m_ctrlTags
.GetSelectedCount() < m_ctrlTags
.GetItemCount())
170 m_SelectAll
.SetCheck(BST_INDETERMINATE
);
172 m_SelectAll
.SetCheck(BST_CHECKED
);
175 BOOL
CDeleteRemoteTagDlg::PreTranslateMessage(MSG
* pMsg
)
177 if (pMsg
->message
== WM_KEYDOWN
)
179 switch (pMsg
->wParam
)
189 return CHorizontalResizableStandAloneDialog::PreTranslateMessage(pMsg
);