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"
29 IMPLEMENT_DYNAMIC(CDeleteRemoteTagDlg
, CHorizontalResizableStandAloneDialog
)
31 CDeleteRemoteTagDlg::CDeleteRemoteTagDlg(CWnd
* pParent
/*=NULL*/)
32 : CHorizontalResizableStandAloneDialog(CDeleteRemoteTagDlg::IDD
, pParent
)
36 CDeleteRemoteTagDlg::~CDeleteRemoteTagDlg()
40 void CDeleteRemoteTagDlg::DoDataExchange(CDataExchange
* pDX
)
42 CDialog::DoDataExchange(pDX
);
43 DDX_Control(pDX
, IDC_SELECTALL
, m_SelectAll
);
44 DDX_Control(pDX
, IDC_LIST_TAGS
, m_ctrlTags
);
47 BEGIN_MESSAGE_MAP(CDeleteRemoteTagDlg
, CHorizontalResizableStandAloneDialog
)
48 ON_BN_CLICKED(IDC_SELECTALL
, OnBnClickedSelectall
)
49 ON_BN_CLICKED(IDOK
, OnBnClickedOk
)
50 ON_NOTIFY(LVN_ITEMCHANGED
, IDC_LIST_TAGS
, OnSelchangeTags
)
53 BOOL
CDeleteRemoteTagDlg::OnInitDialog()
55 CHorizontalResizableStandAloneDialog::OnInitDialog();
56 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
58 AddAnchor(IDC_LIST_TAGS
, TOP_LEFT
, BOTTOM_RIGHT
);
59 AddAnchor(IDC_SELECTALL
, BOTTOM_RIGHT
);
60 AddAnchor(IDOK
, BOTTOM_RIGHT
);
61 AddAnchor(IDCANCEL
, BOTTOM_RIGHT
);
63 this->AddOthersToAnchor();
65 AdjustControlSize((UINT
)IDC_STATIC
);
68 temp
.LoadString(IDS_PROC_TAG
);
69 m_ctrlTags
.InsertColumn(0, temp
, 0, -1);
70 m_ctrlTags
.SetColumnWidth(0, LVSCW_AUTOSIZE_USEHEADER
);
71 m_ctrlTags
.SetExtendedStyle(LVS_EX_DOUBLEBUFFER
);
75 EnableSaveRestore(_T("DeleteRemoteTagDlg"));
80 void CDeleteRemoteTagDlg::Refresh()
82 m_ctrlTags
.DeleteAllItems();
83 m_SelectAll
.SetCheck(BST_UNCHECKED
);
86 g_Git
.GetRemoteTags(m_sRemote
, m_taglist
);
88 for (int i
= 0; i
< (int)m_taglist
.size(); ++i
)
90 m_ctrlTags
.InsertItem(i
, m_taglist
[i
]);
93 DialogEnableWindow(IDOK
, FALSE
);
96 void CDeleteRemoteTagDlg::OnBnClickedSelectall()
98 UINT state
= (m_SelectAll
.GetState() & 0x0003);
99 if (state
== BST_INDETERMINATE
)
101 // It is not at all useful to manually place the checkbox into the indeterminate state...
102 // We will force this on to the unchecked state
103 state
= BST_UNCHECKED
;
104 m_SelectAll
.SetCheck(state
);
106 if (state
== BST_UNCHECKED
)
108 m_ctrlTags
.SetItemState(-1, 0, LVIS_SELECTED
);
112 for (int i
= 0; i
< m_ctrlTags
.GetItemCount(); ++i
)
113 m_ctrlTags
.SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
117 void CDeleteRemoteTagDlg::OnBnClickedOk()
119 if (m_ctrlTags
.GetSelectedCount() > 1)
122 msg
.Format(IDS_PROC_DELETENREFS
, m_ctrlTags
.GetSelectedCount());
123 if (CMessageBox::Show(m_hWnd
, msg
, _T("TortoiseGit"), 2, IDI_QUESTION
, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 2)
126 else // GetSelectedCount() is 1, otherwise the button is disabled
128 POSITION pos
= m_ctrlTags
.GetFirstSelectedItemPosition();
130 msg
.Format(IDS_PROC_DELETEBRANCHTAG
, m_taglist
[(m_ctrlTags
.GetNextSelectedItem(pos
))]);
131 if (CMessageBox::Show(m_hWnd
, msg
, _T("TortoiseGit"), 2, IDI_QUESTION
, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 2)
135 CMassiveGitTask
mgtPush(_T("push ") + m_sRemote
, FALSE
);
137 POSITION pos
= m_ctrlTags
.GetFirstSelectedItemPosition();
139 while ((index
= m_ctrlTags
.GetNextSelectedItem(pos
)) >= 0)
141 mgtPush
.AddFile(_T(":refs/tags/") + m_taglist
[index
]);
145 mgtPush
.Execute(cancel
);
149 void CDeleteRemoteTagDlg::OnSelchangeTags(NMHDR
* /*pNMHDR*/, LRESULT
* /*pResult*/)
151 DialogEnableWindow(IDOK
, m_ctrlTags
.GetSelectedCount() > 0);
152 if (m_ctrlTags
.GetSelectedCount() == 0)
153 m_SelectAll
.SetCheck(BST_UNCHECKED
);
154 else if ((int)m_ctrlTags
.GetSelectedCount() < m_ctrlTags
.GetItemCount())
155 m_SelectAll
.SetCheck(BST_INDETERMINATE
);
157 m_SelectAll
.SetCheck(BST_CHECKED
);
160 BOOL
CDeleteRemoteTagDlg::PreTranslateMessage(MSG
* pMsg
)
162 if (pMsg
->message
== WM_KEYDOWN
)
164 switch (pMsg
->wParam
)
174 return CHorizontalResizableStandAloneDialog::PreTranslateMessage(pMsg
);