1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-2013, 2015-2020, 2023-2024 - 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.
21 #include "TortoiseProc.h"
22 #include "MessageBox.h"
23 #include "ResolveDlg.h"
24 #include "PathUtils.h"
28 #define REFRESHTIMER 100
30 IMPLEMENT_DYNAMIC(CResolveDlg
, CResizableStandAloneDialog
)
31 CResolveDlg::CResolveDlg(CWnd
* pParent
/*=nullptr*/)
32 : CResizableStandAloneDialog(CResolveDlg::IDD
, pParent
)
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
)
55 BOOL
CResolveDlg::OnInitDialog()
57 CResizableStandAloneDialog::OnInitDialog();
58 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
60 m_resolveListCtrl
.Init(GITSLC_COLEXT
, L
"ResolveDlg", GITSLC_POPALL
^ (GITSLC_POPIGNORE
| GITSLC_POPADD
| GITSLC_POPCOMMIT
| GITSLC_POPEXPORT
| GITSLC_POPRESTORE
| GITSLC_POPSAVEAS
| GITSLC_POPPREPAREDIFF
| GITSLC_POPCHANGELISTS
));
61 m_resolveListCtrl
.SetConfirmButton(static_cast<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 CAppUtils::SetWindowTitle(*this, g_Git
.m_CurrentDir
);
69 AdjustControlSize(IDC_SELECTALL
);
71 AddAnchor(IDC_RESOLVELIST
, TOP_LEFT
, BOTTOM_RIGHT
);
72 AddAnchor(IDC_SELECTALL
, BOTTOM_LEFT
);
73 AddAnchor(IDOK
, BOTTOM_RIGHT
);
74 AddAnchor(IDCANCEL
, BOTTOM_RIGHT
);
75 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
76 AddAnchor(IDC_STATIC_REMINDER
, BOTTOM_RIGHT
);
77 if (GetExplorerHWND())
78 CenterWindow(CWnd::FromHandle(GetExplorerHWND()));
79 EnableSaveRestore(L
"ResolveDlg");
81 // first start a thread to obtain the file list with the status without
82 // blocking the dialog
83 InterlockedExchange(&m_bThreadRunning
, TRUE
);
84 if (!AfxBeginThread(ResolveThreadEntry
, this))
86 InterlockedExchange(&m_bThreadRunning
, FALSE
);
87 CMessageBox::Show(this->m_hWnd
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
93 void CResolveDlg::OnOK()
98 //save only the files the user has selected into the path list
99 m_resolveListCtrl
.WriteCheckedNamesToPathList(m_pathList
);
101 CResizableStandAloneDialog::OnOK();
104 void CResolveDlg::OnCancel()
107 if (m_bThreadRunning
)
110 CResizableStandAloneDialog::OnCancel();
113 void CResolveDlg::OnBnClickedSelectall()
115 UINT state
= (m_SelectAll
.GetState() & 0x0003);
116 if (state
== BST_INDETERMINATE
)
118 // It is not at all useful to manually place the checkbox into the indeterminate state...
119 // We will force this on to the unchecked state
120 state
= BST_UNCHECKED
;
121 m_SelectAll
.SetCheck(state
);
123 theApp
.DoWaitCursor(1);
124 m_resolveListCtrl
.SelectAll(state
== BST_CHECKED
);
125 theApp
.DoWaitCursor(-1);
128 UINT
CResolveDlg::ResolveThreadEntry(LPVOID pVoid
)
130 return static_cast<CResolveDlg
*>(pVoid
)->ResolveThread();
132 UINT
CResolveDlg::ResolveThread()
134 // get the status of all selected file/folders recursively
135 // and show the ones which are in conflict
136 DialogEnableWindow(IDOK
, false);
138 m_bCancelled
= false;
140 m_resolveListCtrl
.StoreScrollPos();
141 m_resolveListCtrl
.Clear();
142 if (!m_resolveListCtrl
.GetStatus(&m_pathList
))
143 m_resolveListCtrl
.SetEmptyString(m_resolveListCtrl
.GetLastErrorMessage());
144 m_resolveListCtrl
.Show(GITSLC_SHOWCONFLICTED
|GITSLC_SHOWINEXTERNALS
, GITSLC_SHOWCONFLICTED
);
146 InterlockedExchange(&m_bThreadRunning
, FALSE
);
150 BOOL
CResolveDlg::PreTranslateMessage(MSG
* pMsg
)
152 if (pMsg
->message
== WM_KEYDOWN
)
154 switch (pMsg
->wParam
)
158 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
160 if ( GetDlgItem(IDOK
)->IsWindowEnabled() )
161 PostMessage(WM_COMMAND
, IDOK
);
168 if (!InterlockedExchange(&m_bThreadRunning
, TRUE
))
170 if (!AfxBeginThread(ResolveThreadEntry
, this))
172 InterlockedExchange(&m_bThreadRunning
, FALSE
);
173 CMessageBox::Show(this->m_hWnd
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
181 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
184 LRESULT
CResolveDlg::OnSVNStatusListCtrlNeedsRefresh(WPARAM
, LPARAM
)
186 if (InterlockedExchange(&m_bThreadRunning
, TRUE
))
188 if (!AfxBeginThread(ResolveThreadEntry
, this))
190 InterlockedExchange(&m_bThreadRunning
, FALSE
);
191 CMessageBox::Show(this->m_hWnd
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
196 LRESULT
CResolveDlg::OnFileDropped(WPARAM
, LPARAM lParam
)
199 SetForegroundWindow();
201 // if multiple files/folders are dropped
202 // this handler is called for every single item
204 // To avoid creating multiple refresh threads and
205 // causing crashes, we only add the items to the
206 // list control and start a timer.
207 // When the timer expires, we start the refresh thread,
208 // but only if it isn't already running - otherwise we
209 // restart the timer.
211 path
.SetFromWin(reinterpret_cast<LPCWSTR
>(lParam
));
213 // check whether the dropped file belongs to the very same repository
215 if (!path
.HasAdminDir(&projectDir
) || !CPathUtils::ArePathStringsEqual(g_Git
.m_CurrentDir
, projectDir
))
218 if (!m_resolveListCtrl
.HasPath(path
))
220 if (m_pathList
.AreAllPathsFiles())
222 m_pathList
.AddPath(path
);
223 m_pathList
.RemoveDuplicates();
227 // if the path list contains folders, we have to check whether
228 // our just (maybe) added path is a child of one of those. If it is
229 // a child of a folder already in the list, we must not add it. Otherwise
230 // that path could show up twice in the list.
231 if (!m_pathList
.IsAnyAncestorOf(path
))
233 m_pathList
.AddPath(path
);
234 m_pathList
.RemoveDuplicates();
238 m_resolveListCtrl
.ResetChecked(path
);
240 // Always start the timer, since the status of an existing item might have changed
241 SetTimer(REFRESHTIMER
, 200, nullptr);
242 CTraceToOutputDebugString::Instance()(_T(__FUNCTION__
) L
": Item %s dropped, timer started\n", path
.GetWinPath());
246 void CResolveDlg::OnTimer(UINT_PTR nIDEvent
)
251 if (m_bThreadRunning
)
253 SetTimer(REFRESHTIMER
, 200, nullptr);
254 CTraceToOutputDebugString::Instance()(__FUNCTION__
": Wait some more before refreshing\n");
258 KillTimer(REFRESHTIMER
);
259 CTraceToOutputDebugString::Instance()(__FUNCTION__
": Refreshing after items dropped\n");
260 OnSVNStatusListCtrlNeedsRefresh(0, 0);
264 __super::OnTimer(nIDEvent
);