SyncDlg: Make check if local branch fast-fowards to remote branch work again
[TortoiseGit.git] / src / TortoiseProc / DeleteRemoteTagDlg.cpp
blob1dec39c64fbf3faba46be20753994a6cfbc20626
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_LIST_TAGS, m_ctrlTags);
45 BEGIN_MESSAGE_MAP(CDeleteRemoteTagDlg, CHorizontalResizableStandAloneDialog)
46 ON_BN_CLICKED(IDOK, OnBnClickedOk)
47 ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_TAGS, OnSelchangeTags)
48 END_MESSAGE_MAP()
50 BOOL CDeleteRemoteTagDlg::OnInitDialog()
52 CHorizontalResizableStandAloneDialog::OnInitDialog();
53 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
55 AddAnchor(IDC_LIST_TAGS, TOP_LEFT, BOTTOM_RIGHT);
56 AddAnchor(IDOK, BOTTOM_RIGHT);
57 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
59 this->AddOthersToAnchor();
61 AdjustControlSize((UINT)IDC_STATIC);
63 CString temp;
64 temp.LoadString(IDS_PROC_TAG);
65 m_ctrlTags.InsertColumn(0, temp, 0, -1);
66 m_ctrlTags.SetColumnWidth(0, LVSCW_AUTOSIZE_USEHEADER);
67 m_ctrlTags.SetExtendedStyle(LVS_EX_DOUBLEBUFFER);
69 Refresh();
71 EnableSaveRestore(_T("DeleteRemoteTagDlg"));
73 return TRUE;
76 void CDeleteRemoteTagDlg::Refresh()
78 m_ctrlTags.DeleteAllItems();
79 m_taglist.clear();
81 g_Git.GetRemoteTags(m_sRemote, m_taglist);
83 for (int i = 0; i < (int)m_taglist.size(); i++)
85 m_ctrlTags.InsertItem(i, m_taglist[i]);
88 DialogEnableWindow(IDOK, FALSE);
91 void CDeleteRemoteTagDlg::OnBnClickedOk()
93 if (m_ctrlTags.GetSelectedCount() > 1)
95 CString msg;
96 msg.Format(IDS_PROC_DELETENREFS, m_ctrlTags.GetSelectedCount());
97 if (CMessageBox::Show(m_hWnd, msg, _T("TortoiseGit"), 2, IDI_QUESTION, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON))) == 2)
98 return;
100 else // GetSelectedCount() is 1, otherwise the button is disabled
102 POSITION pos = m_ctrlTags.GetFirstSelectedItemPosition();
103 CString msg;
104 msg.Format(IDS_PROC_DELETEBRANCHTAG, m_taglist[(m_ctrlTags.GetNextSelectedItem(pos))]);
105 if (CMessageBox::Show(m_hWnd, msg, _T("TortoiseGit"), 2, IDI_QUESTION, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON))) == 2)
106 return;
109 CString cmd, out;
110 cmd.Format(_T("git.exe push %s"), m_sRemote);
112 POSITION pos = m_ctrlTags.GetFirstSelectedItemPosition();
113 int index;
114 while ((index = m_ctrlTags.GetNextSelectedItem(pos)) >= 0)
116 cmd += _T(" :refs/tags/") + m_taglist[index];
119 if (g_Git.Run(cmd, &out, CP_UTF8))
121 MessageBox(out, _T("TortoiseGit"), MB_ICONERROR);
123 Refresh();
126 void CDeleteRemoteTagDlg::OnSelchangeTags(NMHDR* /*pNMHDR*/, LRESULT* /*pResult*/)
128 DialogEnableWindow(IDOK, m_ctrlTags.GetSelectedCount() > 0);
131 BOOL CDeleteRemoteTagDlg::PreTranslateMessage(MSG* pMsg)
133 if (pMsg->message == WM_KEYDOWN)
135 switch (pMsg->wParam)
137 case VK_F5:
139 Refresh();
141 break;
145 return CHorizontalResizableStandAloneDialog::PreTranslateMessage(pMsg);