Call CGit::DeleteRemoteRefs() to delete remote tags
[TortoiseGit.git] / src / TortoiseProc / ResolveDlg.cpp
blobf6e5aba92c51f8f0cab80cf8d2969e963b7f6152
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-2013 - TortoiseGit
4 // Copyright (C) 2003-2008 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "stdafx.h"
21 #include "TortoiseProc.h"
22 #include "messagebox.h"
23 #include "ResolveDlg.h"
24 #include "AppUtils.h"
26 #define REFRESHTIMER 100
28 IMPLEMENT_DYNAMIC(CResolveDlg, CResizableStandAloneDialog)
29 CResolveDlg::CResolveDlg(CWnd* pParent /*=NULL*/)
30 : CResizableStandAloneDialog(CResolveDlg::IDD, pParent)
31 , m_bThreadRunning(FALSE)
32 , m_bCancelled(false)
36 CResolveDlg::~CResolveDlg()
40 void CResolveDlg::DoDataExchange(CDataExchange* pDX)
42 CResizableStandAloneDialog::DoDataExchange(pDX);
43 DDX_Control(pDX, IDC_RESOLVELIST, m_resolveListCtrl);
44 DDX_Control(pDX, IDC_SELECTALL, m_SelectAll);
48 BEGIN_MESSAGE_MAP(CResolveDlg, CResizableStandAloneDialog)
49 ON_BN_CLICKED(IDC_SELECTALL, OnBnClickedSelectall)
50 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_NEEDSREFRESH, OnSVNStatusListCtrlNeedsRefresh)
51 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ADDFILE, OnFileDropped)
52 ON_WM_TIMER()
53 END_MESSAGE_MAP()
55 BOOL CResolveDlg::OnInitDialog()
57 CResizableStandAloneDialog::OnInitDialog();
58 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
60 m_resolveListCtrl.Init(GITSLC_COLEXT, _T("ResolveDlg"), GITSLC_POPALL ^ (GITSLC_POPIGNORE|GITSLC_POPADD|GITSLC_POPCOMMIT|GITSLC_POPEXPORT|GITSLC_POPRESTORE|GITSLC_POPSAVEAS));
61 m_resolveListCtrl.SetConfirmButton((CButton*)GetDlgItem(IDOK));
62 m_resolveListCtrl.SetSelectButton(&m_SelectAll);
63 m_resolveListCtrl.SetCancelBool(&m_bCancelled);
64 m_resolveListCtrl.SetBackgroundImage(IDI_RESOLVE_BKG);
65 m_resolveListCtrl.EnableFileDrop();
67 CString sWindowTitle;
68 GetWindowText(sWindowTitle);
69 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
71 AdjustControlSize(IDC_SELECTALL);
73 AddAnchor(IDC_RESOLVELIST, TOP_LEFT, BOTTOM_RIGHT);
74 AddAnchor(IDC_SELECTALL, BOTTOM_LEFT);
75 AddAnchor(IDOK, BOTTOM_RIGHT);
76 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
77 AddAnchor(IDHELP, BOTTOM_RIGHT);
78 AddAnchor(IDC_STATIC_REMINDER, BOTTOM_RIGHT);
79 if (hWndExplorer)
80 CenterWindow(CWnd::FromHandle(hWndExplorer));
81 EnableSaveRestore(_T("ResolveDlg"));
83 // first start a thread to obtain the file list with the status without
84 // blocking the dialog
85 if(AfxBeginThread(ResolveThreadEntry, this) == NULL)
87 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
89 InterlockedExchange(&m_bThreadRunning, TRUE);
91 return TRUE;
94 void CResolveDlg::OnOK()
96 if (m_bThreadRunning)
97 return;
99 //save only the files the user has selected into the path list
100 m_resolveListCtrl.WriteCheckedNamesToPathList(m_pathList);
102 CResizableStandAloneDialog::OnOK();
105 void CResolveDlg::OnCancel()
107 m_bCancelled = true;
108 if (m_bThreadRunning)
109 return;
111 CResizableStandAloneDialog::OnCancel();
114 void CResolveDlg::OnBnClickedSelectall()
116 UINT state = (m_SelectAll.GetState() & 0x0003);
117 if (state == BST_INDETERMINATE)
119 // It is not at all useful to manually place the checkbox into the indeterminate state...
120 // We will force this on to the unchecked state
121 state = BST_UNCHECKED;
122 m_SelectAll.SetCheck(state);
124 theApp.DoWaitCursor(1);
125 m_resolveListCtrl.SelectAll(state == BST_CHECKED);
126 theApp.DoWaitCursor(-1);
129 UINT CResolveDlg::ResolveThreadEntry(LPVOID pVoid)
131 return ((CResolveDlg*)pVoid)->ResolveThread();
133 UINT CResolveDlg::ResolveThread()
135 // get the status of all selected file/folders recursively
136 // and show the ones which are in conflict
137 DialogEnableWindow(IDOK, false);
139 m_bCancelled = false;
141 m_resolveListCtrl.Clear();
142 if (!m_resolveListCtrl.GetStatus(&m_pathList))
144 m_resolveListCtrl.SetEmptyString(m_resolveListCtrl.GetLastErrorMessage());
146 m_resolveListCtrl.Show(GITSLC_SHOWCONFLICTED|GITSLC_SHOWINEXTERNALS, GITSLC_SHOWCONFLICTED);
148 InterlockedExchange(&m_bThreadRunning, FALSE);
149 return 0;
152 BOOL CResolveDlg::PreTranslateMessage(MSG* pMsg)
154 if (pMsg->message == WM_KEYDOWN)
156 switch (pMsg->wParam)
158 case VK_RETURN:
160 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
162 if ( GetDlgItem(IDOK)->IsWindowEnabled() )
164 PostMessage(WM_COMMAND, IDOK);
166 return TRUE;
169 break;
170 case VK_F5:
172 if (!m_bThreadRunning)
174 if(AfxBeginThread(ResolveThreadEntry, this) == NULL)
176 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
178 else
179 InterlockedExchange(&m_bThreadRunning, TRUE);
182 break;
186 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
189 LRESULT CResolveDlg::OnSVNStatusListCtrlNeedsRefresh(WPARAM, LPARAM)
191 if(AfxBeginThread(ResolveThreadEntry, this) == NULL)
193 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
195 return 0;
198 LRESULT CResolveDlg::OnFileDropped(WPARAM, LPARAM lParam)
200 BringWindowToTop();
201 SetForegroundWindow();
202 SetActiveWindow();
203 // if multiple files/folders are dropped
204 // this handler is called for every single item
205 // separately.
206 // To avoid creating multiple refresh threads and
207 // causing crashes, we only add the items to the
208 // list control and start a timer.
209 // When the timer expires, we start the refresh thread,
210 // but only if it isn't already running - otherwise we
211 // restart the timer.
212 CTGitPath path;
213 path.SetFromWin((LPCTSTR)lParam);
215 if (!m_resolveListCtrl.HasPath(path))
217 if (m_pathList.AreAllPathsFiles())
219 m_pathList.AddPath(path);
220 m_pathList.RemoveDuplicates();
222 else
224 // if the path list contains folders, we have to check whether
225 // our just (maybe) added path is a child of one of those. If it is
226 // a child of a folder already in the list, we must not add it. Otherwise
227 // that path could show up twice in the list.
228 bool bHasParentInList = false;
229 for (int i=0; i<m_pathList.GetCount(); ++i)
231 if (m_pathList[i].IsAncestorOf(path))
233 bHasParentInList = true;
234 break;
237 if (!bHasParentInList)
239 m_pathList.AddPath(path);
240 m_pathList.RemoveDuplicates();
245 // Always start the timer, since the status of an existing item might have changed
246 SetTimer(REFRESHTIMER, 200, NULL);
247 CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) _T(": Item %s dropped, timer started\n"), path.GetWinPath());
248 return 0;
251 void CResolveDlg::OnTimer(UINT_PTR nIDEvent)
253 switch (nIDEvent)
255 case REFRESHTIMER:
256 if (m_bThreadRunning)
258 SetTimer(REFRESHTIMER, 200, NULL);
259 CTraceToOutputDebugString::Instance()(__FUNCTION__ ": Wait some more before refreshing\n");
261 else
263 KillTimer(REFRESHTIMER);
264 CTraceToOutputDebugString::Instance()(__FUNCTION__ ": Refreshing after items dropped\n");
265 OnSVNStatusListCtrlNeedsRefresh(0, 0);
267 break;
269 __super::OnTimer(nIDEvent);