Initial version of BrowseRefsDlg
[TortoiseGit.git] / src / TortoiseProc / DeleteUnversionedDlg.cpp
blobb9a40ba243db127df2b43bee10f8eb749059211c
1 // TortoiseSVN - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
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.
19 #include "stdafx.h"
20 #include "TortoiseProc.h"
21 #include "messagebox.h"
22 #include "SVN.h"
23 #include "Registry.h"
24 #include "DeleteUnversionedDlg.h"
26 IMPLEMENT_DYNAMIC(CDeleteUnversionedDlg, CResizableStandAloneDialog)
27 CDeleteUnversionedDlg::CDeleteUnversionedDlg(CWnd* pParent /*=NULL*/)
28 : CResizableStandAloneDialog(CDeleteUnversionedDlg::IDD, pParent)
29 , m_bSelectAll(TRUE)
30 , m_bThreadRunning(FALSE)
31 , m_bCancelled(false)
35 CDeleteUnversionedDlg::~CDeleteUnversionedDlg()
39 void CDeleteUnversionedDlg::DoDataExchange(CDataExchange* pDX)
41 CResizableStandAloneDialog::DoDataExchange(pDX);
42 DDX_Control(pDX, IDC_ITEMLIST, m_StatusList);
43 DDX_Check(pDX, IDC_SELECTALL, m_bSelectAll);
44 DDX_Control(pDX, IDC_SELECTALL, m_SelectAll);
48 BEGIN_MESSAGE_MAP(CDeleteUnversionedDlg, CResizableStandAloneDialog)
49 ON_BN_CLICKED(IDC_SELECTALL, OnBnClickedSelectall)
50 ON_REGISTERED_MESSAGE(CSVNStatusListCtrl::SVNSLNM_NEEDSREFRESH, OnSVNStatusListCtrlNeedsRefresh)
51 END_MESSAGE_MAP()
55 BOOL CDeleteUnversionedDlg::OnInitDialog()
57 CResizableStandAloneDialog::OnInitDialog();
59 m_StatusList.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS, _T("DeleteUnversionedDlg"), 0, true);
60 m_StatusList.SetUnversionedRecurse(true);
61 m_StatusList.PutUnversionedLast(false);
62 m_StatusList.CheckChildrenWithParent(true);
63 m_StatusList.SetConfirmButton((CButton*)GetDlgItem(IDOK));
64 m_StatusList.SetSelectButton(&m_SelectAll);
65 m_StatusList.SetCancelBool(&m_bCancelled);
66 m_StatusList.SetBackgroundImage(IDI_DELUNVERSIONED_BKG);
68 GetWindowText(m_sWindowTitle);
70 AdjustControlSize(IDC_SELECTALL);
72 AddAnchor(IDC_ITEMLIST, TOP_LEFT, BOTTOM_RIGHT);
73 AddAnchor(IDC_SELECTALL, BOTTOM_LEFT);
74 AddAnchor(IDOK, BOTTOM_RIGHT);
75 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
76 if (hWndExplorer)
77 CenterWindow(CWnd::FromHandle(hWndExplorer));
78 EnableSaveRestore(_T("DeleteUnversionedDlg"));
80 // first start a thread to obtain the file list with the status without
81 // blocking the dialog
82 if (AfxBeginThread(StatusThreadEntry, this)==0)
84 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
86 InterlockedExchange(&m_bThreadRunning, TRUE);
88 return TRUE;
91 UINT CDeleteUnversionedDlg::StatusThreadEntry(LPVOID pVoid)
93 return ((CDeleteUnversionedDlg*)pVoid)->StatusThread();
96 UINT CDeleteUnversionedDlg::StatusThread()
98 // get the status of all selected file/folders recursively
99 // and show the ones which are unversioned/ignored to the user
100 // in a list control.
101 DialogEnableWindow(IDOK, false);
102 m_bCancelled = false;
104 if (!m_StatusList.GetStatus(m_pathList, false, true))
106 m_StatusList.SetEmptyString(m_StatusList.GetLastErrorMessage());
108 m_StatusList.Show(SVNSLC_SHOWUNVERSIONED | SVNSLC_SHOWIGNORED,
109 SVNSLC_SHOWUNVERSIONED | SVNSLC_SHOWIGNORED);
111 CTSVNPath commonDir = m_StatusList.GetCommonDirectory(false);
112 SetWindowText(m_sWindowTitle + _T(" - ") + commonDir.GetWinPathString());
114 InterlockedExchange(&m_bThreadRunning, FALSE);
115 RefreshCursor();
117 return 0;
120 void CDeleteUnversionedDlg::OnOK()
122 if (m_bThreadRunning)
123 return;
124 // save only the files the user has selected into the temporary file
125 m_StatusList.WriteCheckedNamesToPathList(m_pathList);
127 CResizableStandAloneDialog::OnOK();
130 void CDeleteUnversionedDlg::OnCancel()
132 m_bCancelled = true;
133 if (m_bThreadRunning)
134 return;
136 CResizableStandAloneDialog::OnCancel();
139 void CDeleteUnversionedDlg::OnBnClickedSelectall()
141 UINT state = (m_SelectAll.GetState() & 0x0003);
142 if (state == BST_INDETERMINATE)
144 // It is not at all useful to manually place the checkbox into the indeterminate state...
145 // We will force this on to the unchecked state
146 state = BST_UNCHECKED;
147 m_SelectAll.SetCheck(state);
149 theApp.DoWaitCursor(1);
150 m_StatusList.SelectAll(state == BST_CHECKED);
151 theApp.DoWaitCursor(-1);
154 BOOL CDeleteUnversionedDlg::PreTranslateMessage(MSG* pMsg)
156 if (pMsg->message == WM_KEYDOWN)
158 switch (pMsg->wParam)
160 case VK_RETURN:
162 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
164 if ( GetDlgItem(IDOK)->IsWindowEnabled() )
166 PostMessage(WM_COMMAND, IDOK);
168 return TRUE;
171 break;
172 case VK_F5:
174 if (!m_bThreadRunning)
176 if (AfxBeginThread(StatusThreadEntry, this)==0)
178 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
180 else
181 InterlockedExchange(&m_bThreadRunning, TRUE);
184 break;
188 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
191 LRESULT CDeleteUnversionedDlg::OnSVNStatusListCtrlNeedsRefresh(WPARAM, LPARAM)
193 if (AfxBeginThread(StatusThreadEntry, this)==0)
195 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
197 return 0;