1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2012-2018 - 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 "TortoiseProc.h"
23 #include "SubmoduleResolveConflictDlg.h"
24 #include "LoglistCommonResource.h"
25 #include "SubmoduleDiffDlg.h"
26 #include "MessageBox.h"
28 IMPLEMENT_DYNAMIC(CSubmoduleResolveConflictDlg
, CHorizontalResizableStandAloneDialog
)
29 CSubmoduleResolveConflictDlg::CSubmoduleResolveConflictDlg(CWnd
* pParent
/*=nullptr*/)
30 : CHorizontalResizableStandAloneDialog(CSubmoduleResolveConflictDlg::IDD
, pParent
)
34 , m_nChangeTypeMine(CGitDiff::Unknown
)
35 , m_nChangeTypeTheirs(CGitDiff::Unknown
)
36 , m_bRevertTheirMy(false)
41 CSubmoduleResolveConflictDlg::~CSubmoduleResolveConflictDlg()
45 void CSubmoduleResolveConflictDlg::DoDataExchange(CDataExchange
* pDX
)
47 CHorizontalResizableStandAloneDialog::DoDataExchange(pDX
);
48 DDX_Text(pDX
, IDC_BASEHASH
, m_sBaseHash
);
49 DDX_Text(pDX
, IDC_BASESUBJECT
, m_sBaseSubject
);
50 DDX_Text(pDX
, IDC_MINEHASH
, m_sMineHash
);
51 DDX_Text(pDX
, IDC_MINESUBJECT
, m_sMineSubject
);
52 DDX_Text(pDX
, IDC_THEIRSHASH
, m_sTheirsHash
);
53 DDX_Text(pDX
, IDC_THEIRSSUBJECT
, m_sTheirsSubject
);
56 BEGIN_MESSAGE_MAP(CSubmoduleResolveConflictDlg
, CHorizontalResizableStandAloneDialog
)
57 ON_BN_CLICKED(IDC_LOG
, &OnBnClickedLog
)
58 ON_BN_CLICKED(IDC_LOG2
, &OnBnClickedLog2
)
59 ON_BN_CLICKED(IDC_LOG3
, &OnBnClickedLog3
)
61 ON_BN_CLICKED(IDC_BUTTON_UPDATE2
, &CSubmoduleResolveConflictDlg::OnBnClickedButtonUpdate2
)
62 ON_BN_CLICKED(IDC_BUTTON_UPDATE3
, &CSubmoduleResolveConflictDlg::OnBnClickedButtonUpdate3
)
65 BOOL
CSubmoduleResolveConflictDlg::OnInitDialog()
67 CHorizontalResizableStandAloneDialog::OnInitDialog();
70 GetWindowText(sWindowTitle
);
71 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
73 AddAnchor(IDC_SUBMODULEDIFFTITLE
, TOP_LEFT
, TOP_RIGHT
);
74 AddAnchor(IDC_STATIC_REVISION
, TOP_LEFT
);
75 AddAnchor(IDC_STATIC_REVISION2
, TOP_LEFT
);
76 AddAnchor(IDC_STATIC_REVISION3
, TOP_LEFT
);
77 AddAnchor(IDC_STATIC_SUBJECT
, TOP_LEFT
);
78 AddAnchor(IDC_STATIC_SUBJECT2
, TOP_LEFT
);
79 AddAnchor(IDC_STATIC_SUBJECT3
, TOP_LEFT
);
80 AddAnchor(IDC_STATIC_CHANGETYPE
, TOP_LEFT
);
81 AddAnchor(IDC_STATIC_CHANGETYPE2
, TOP_LEFT
);
83 AddAnchor(IDC_FROMGROUP
, TOP_LEFT
, TOP_RIGHT
);
84 AddAnchor(IDC_TOGROUP
, TOP_LEFT
, TOP_RIGHT
);
85 AddAnchor(IDC_TOGROUP2
, TOP_LEFT
, TOP_RIGHT
);
87 AddAnchor(IDC_LOG
, TOP_RIGHT
);
88 AddAnchor(IDC_LOG2
, TOP_RIGHT
);
89 AddAnchor(IDC_LOG3
, TOP_RIGHT
);
91 AddAnchor(IDC_BASEHASH
, TOP_LEFT
, TOP_RIGHT
);
92 AddAnchor(IDC_BASESUBJECT
, TOP_LEFT
, TOP_RIGHT
);
93 AddAnchor(IDC_MINECHANGETYPE
, TOP_LEFT
, TOP_RIGHT
);
94 AddAnchor(IDC_MINEHASH
, TOP_LEFT
, TOP_RIGHT
);
95 AddAnchor(IDC_MINESUBJECT
, TOP_LEFT
, TOP_RIGHT
);
96 AddAnchor(IDC_THEIRSCHANGETYPE
, TOP_LEFT
, TOP_RIGHT
);
97 AddAnchor(IDC_THEIRSHASH
, TOP_LEFT
, TOP_RIGHT
);
98 AddAnchor(IDC_THEIRSSUBJECT
, TOP_LEFT
, TOP_RIGHT
);
100 EnableSaveRestore(L
"SubmoduleResolveConflictDlg");
102 CString fsPath
= m_sPath
;
103 fsPath
.Replace(L
'\\', L
'/');
104 CString title
= L
"Submodule \"" + fsPath
+ L
'"';
105 GetDlgItem(IDC_SUBMODULEDIFFTITLE
)->SetWindowText(title
);
109 CString changeTypeTable
[] =
111 CString(MAKEINTRESOURCE(IDS_SUBMODULEDIFF_UNKNOWN
)),
112 CString(MAKEINTRESOURCE(IDS_SUBMODULEDIFF_IDENTICAL
)),
113 CString(MAKEINTRESOURCE(IDS_SUBMODULEDIFF_NEWSUBMODULE
)),
114 CString(MAKEINTRESOURCE(IDS_SUBMODULEDIFF_DELETESUBMODULE
)),
115 CString(MAKEINTRESOURCE(IDS_SUBMODULEDIFF_FASTFORWARD
)),
116 CString(MAKEINTRESOURCE(IDS_SUBMODULEDIFF_REWIND
)),
117 CString(MAKEINTRESOURCE(IDS_SUBMODULEDIFF_NEWERTIME
)),
118 CString(MAKEINTRESOURCE(IDS_SUBMODULEDIFF_OLDERTIME
)),
119 CString(MAKEINTRESOURCE(IDS_SUBMODULEDIFF_SAMETIME
))
121 GetDlgItem(IDC_MINECHANGETYPE
)->SetWindowText(changeTypeTable
[m_nChangeTypeMine
]);
122 GetDlgItem(IDC_THEIRSCHANGETYPE
)->SetWindowText(changeTypeTable
[m_nChangeTypeTheirs
]);
124 GetDlgItem(IDC_FROMGROUP
)->SetWindowText(m_sBaseTitle
);
125 GetDlgItem(IDC_TOGROUP
)->SetWindowText(m_sMineTitle
);
126 GetDlgItem(IDC_TOGROUP2
)->SetWindowText(m_sTheirsTitle
);
128 DialogEnableWindow(IDC_LOG
, m_bBaseOK
);
129 DialogEnableWindow(IDC_LOG2
, m_bMineOK
&& m_nChangeTypeMine
!= CGitDiff::DeleteSubmodule
);
130 DialogEnableWindow(IDC_LOG3
, m_bTheirsOK
&& m_nChangeTypeTheirs
!= CGitDiff::DeleteSubmodule
);
135 HBRUSH
CSubmoduleResolveConflictDlg::OnCtlColor(CDC
* pDC
, CWnd
* pWnd
, UINT nCtlColor
)
137 if (nCtlColor
== CTLCOLOR_STATIC
)
139 if (pWnd
->GetDlgCtrlID() == IDC_BASESUBJECT
&& !m_bBaseOK
)
140 return CSubmoduleDiffDlg::GetInvalidBrush(pDC
);
142 if (pWnd
->GetDlgCtrlID() == IDC_MINESUBJECT
&& !m_bMineOK
)
143 return CSubmoduleDiffDlg::GetInvalidBrush(pDC
);
145 if (pWnd
->GetDlgCtrlID() == IDC_THEIRSSUBJECT
&& !m_bTheirsOK
)
146 return CSubmoduleDiffDlg::GetInvalidBrush(pDC
);
148 if (pWnd
->GetDlgCtrlID() == IDC_MINECHANGETYPE
&& m_nChangeTypeMine
!= CGitDiff::Identical
)
149 return CSubmoduleDiffDlg::GetChangeTypeBrush(pDC
, m_nChangeTypeMine
);
151 if (pWnd
->GetDlgCtrlID() == IDC_THEIRSCHANGETYPE
&& m_nChangeTypeTheirs
!= CGitDiff::Identical
)
152 return CSubmoduleDiffDlg::GetChangeTypeBrush(pDC
, m_nChangeTypeTheirs
);
155 return CHorizontalResizableStandAloneDialog::OnCtlColor(pDC
, pWnd
, nCtlColor
);
158 void CSubmoduleResolveConflictDlg::SetDiff(const CString
& path
, bool revertTheirMy
, const CString
& baseTitle
, const CString
& mineTitle
, const CString
& theirsTitle
, const CString
& baseHash
, const CString
& baseSubject
, bool baseOK
, const CString
& mineHash
, const CString
& mineSubject
, bool mineOK
, CGitDiff::ChangeType mineChangeType
, const CString
& theirsHash
, const CString
& theirsSubject
, bool theirsOK
, CGitDiff::ChangeType theirsChangeType
)
162 m_sBaseTitle
= baseTitle
;
163 m_sBaseHash
= baseHash
;
164 m_sBaseSubject
= baseSubject
;
167 m_bRevertTheirMy
= revertTheirMy
;
169 if (!m_bRevertTheirMy
)
171 m_sMineTitle
= mineTitle
;
172 m_sMineHash
= mineHash
;
173 m_sMineSubject
= mineSubject
;
175 m_nChangeTypeMine
= mineChangeType
;
177 m_sTheirsTitle
= theirsTitle
;
178 m_sTheirsHash
= theirsHash
;
179 m_sTheirsSubject
= theirsSubject
;
180 m_bTheirsOK
= theirsOK
;
181 m_nChangeTypeTheirs
= theirsChangeType
;
185 m_sMineTitle
= theirsTitle
;
186 m_sMineHash
= theirsHash
;
187 m_sMineSubject
= theirsSubject
;
188 m_bMineOK
= theirsOK
;
189 m_nChangeTypeMine
= theirsChangeType
;
191 m_sTheirsTitle
= mineTitle
;
192 m_sTheirsHash
= mineHash
;
193 m_sTheirsSubject
= mineSubject
;
194 m_bTheirsOK
= mineOK
;
195 m_nChangeTypeTheirs
= mineChangeType
;
199 void CSubmoduleResolveConflictDlg::ShowLog(CString hash
)
202 sCmd
.Format(L
"/command:log /path:\"%s\" /endrev:%s", (LPCTSTR
)g_Git
.CombinePath(m_sPath
), (LPCTSTR
)hash
);
203 CAppUtils::RunTortoiseGitProc(sCmd
, false, false);
206 void CSubmoduleResolveConflictDlg::OnBnClickedLog()
208 ShowLog(m_sBaseHash
);
211 void CSubmoduleResolveConflictDlg::OnBnClickedLog2()
213 ShowLog(m_sMineHash
);
216 void CSubmoduleResolveConflictDlg::OnBnClickedLog3()
218 ShowLog(m_sTheirsHash
);
221 void CSubmoduleResolveConflictDlg::Resolve(const CString
& path
, bool useMine
)
223 if (CMessageBox::Show(GetSafeHwnd(), IDS_PROC_RESOLVE
, IDS_APPNAME
, MB_ICONQUESTION
| MB_YESNO
) != IDYES
)
226 CTGitPath
gitpath(path
);
227 gitpath
.m_Action
= CTGitPath::LOGACTIONS_UNMERGED
;
228 if (CAppUtils::ResolveConflict(GetSafeHwnd(), gitpath
, useMine
? CAppUtils::RESOLVE_WITH_MINE
: CAppUtils::RESOLVE_WITH_THEIRS
) == 0)
235 void CSubmoduleResolveConflictDlg::OnBnClickedButtonUpdate2()
237 Resolve(m_sPath
, !m_bRevertTheirMy
);
240 void CSubmoduleResolveConflictDlg::OnBnClickedButtonUpdate3()
242 Resolve(m_sPath
, m_bRevertTheirMy
);