1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2012, 2014-2016 - 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"
22 #include "SubmoduleDiffDlg.h"
23 #include "LoglistCommonResource.h"
25 IMPLEMENT_DYNAMIC(CSubmoduleDiffDlg
, CHorizontalResizableStandAloneDialog
)
26 CSubmoduleDiffDlg::CSubmoduleDiffDlg(CWnd
* pParent
/*=nullptr*/)
27 : CHorizontalResizableStandAloneDialog(CSubmoduleDiffDlg::IDD
, pParent
)
28 , m_bToIsWorkingCopy(false)
32 , m_nChangeType(CGitDiff::Unknown
)
37 CSubmoduleDiffDlg::~CSubmoduleDiffDlg()
41 void CSubmoduleDiffDlg::DoDataExchange(CDataExchange
* pDX
)
43 CHorizontalResizableStandAloneDialog::DoDataExchange(pDX
);
44 DDX_Text(pDX
, IDC_FROMHASH
, m_sFromHash
);
45 DDX_Text(pDX
, IDC_FROMSUBJECT
, m_sFromSubject
);
46 DDX_Text(pDX
, IDC_TOHASH
, m_sToHash
);
47 DDX_Text(pDX
, IDC_TOSUBJECT
, m_sToSubject
);
48 DDX_Control(pDX
, IDC_SHOW_DIFF
, m_ctrlShowDiffBtn
);
51 BEGIN_MESSAGE_MAP(CSubmoduleDiffDlg
, CHorizontalResizableStandAloneDialog
)
52 ON_BN_CLICKED(IDC_LOG
, &CSubmoduleDiffDlg::OnBnClickedLog
)
53 ON_BN_CLICKED(IDC_LOG2
, &CSubmoduleDiffDlg::OnBnClickedLog2
)
54 ON_BN_CLICKED(IDC_SHOW_DIFF
, &CSubmoduleDiffDlg::OnBnClickedShowDiff
)
56 ON_BN_CLICKED(IDC_BUTTON_UPDATE
, &CSubmoduleDiffDlg::OnBnClickedButtonUpdate
)
59 BOOL
CSubmoduleDiffDlg::OnInitDialog()
61 CHorizontalResizableStandAloneDialog::OnInitDialog();
64 GetWindowText(sWindowTitle
);
65 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
67 AddAnchor(IDC_SUBMODULEDIFFTITLE
, TOP_LEFT
, TOP_RIGHT
);
68 AddAnchor(IDC_STATIC_REVISION
, TOP_LEFT
);
69 AddAnchor(IDC_STATIC_REVISION2
, TOP_LEFT
);
70 AddAnchor(IDC_STATIC_SUBJECT
, TOP_LEFT
);
71 AddAnchor(IDC_STATIC_SUBJECT2
, TOP_LEFT
);
72 AddAnchor(IDC_STATIC_CHANGETYPE
, TOP_LEFT
);
74 AddAnchor(IDC_FROMGROUP
, TOP_LEFT
, TOP_RIGHT
);
75 AddAnchor(IDC_TOGROUP
, TOP_LEFT
, TOP_RIGHT
);
77 AddAnchor(IDC_LOG
, TOP_RIGHT
);
78 AddAnchor(IDC_LOG2
, TOP_RIGHT
);
79 AddAnchor(IDC_BUTTON_UPDATE
, TOP_RIGHT
);
80 AddAnchor(IDC_SHOW_DIFF
, TOP_RIGHT
);
82 AddAnchor(IDC_FROMHASH
, TOP_LEFT
, TOP_RIGHT
);
83 AddAnchor(IDC_FROMSUBJECT
, TOP_LEFT
, TOP_RIGHT
);
84 AddAnchor(IDC_CHANGETYPE
, TOP_LEFT
, TOP_RIGHT
);
85 AddAnchor(IDC_TOHASH
, TOP_LEFT
, TOP_RIGHT
);
86 AddAnchor(IDC_TOSUBJECT
, TOP_LEFT
, TOP_RIGHT
);
88 EnableSaveRestore(L
"SubmoduleDiffDlg");
90 if (m_bToIsWorkingCopy
)
93 GetDlgItem(IDC_TOGROUP
)->GetWindowText(toGroup
);
94 toGroup
+= L
" (" + CString(MAKEINTRESOURCE(IDS_git_DEPTH_WORKING
)) + L
')';
95 GetDlgItem(IDC_TOGROUP
)->SetWindowText(toGroup
);
98 CString fsPath
= m_sPath
;
99 fsPath
.Replace(L
'\\', L
'/');
100 CString title
= L
"Submodule \"" + fsPath
+ L
'"';
101 GetDlgItem(IDC_SUBMODULEDIFFTITLE
)->SetWindowText(title
);
105 GetDlgItem(IDC_TOHASH
)->SetWindowText(m_sToHash
+ L
"-dirty");
107 CString changeTypeTable
[] =
109 CString(MAKEINTRESOURCE(IDS_SUBMODULEDIFF_UNKNOWN
)),
110 CString(MAKEINTRESOURCE(IDS_SUBMODULEDIFF_IDENTICAL
)),
111 CString(MAKEINTRESOURCE(IDS_SUBMODULEDIFF_NEWSUBMODULE
)),
112 CString(MAKEINTRESOURCE(IDS_SUBMODULEDIFF_DELETESUBMODULE
)),
113 CString(MAKEINTRESOURCE(IDS_SUBMODULEDIFF_FASTFORWARD
)),
114 CString(MAKEINTRESOURCE(IDS_SUBMODULEDIFF_REWIND
)),
115 CString(MAKEINTRESOURCE(IDS_SUBMODULEDIFF_NEWERTIME
)),
116 CString(MAKEINTRESOURCE(IDS_SUBMODULEDIFF_OLDERTIME
)),
117 CString(MAKEINTRESOURCE(IDS_SUBMODULEDIFF_SAMETIME
))
119 GetDlgItem(IDC_CHANGETYPE
)->SetWindowText(changeTypeTable
[m_nChangeType
]);
121 DialogEnableWindow(IDC_SHOW_DIFF
, m_bFromOK
&& m_bToOK
);
122 if (m_bDirty
&& m_nChangeType
!= CGitDiff::Unknown
)
124 m_ctrlShowDiffBtn
.AddEntry(MAKEINTRESOURCE(IDS_PROC_SHOWDIFF
));
125 m_ctrlShowDiffBtn
.AddEntry(MAKEINTRESOURCE(IDS_LOG_POPUP_COMPARE
));
128 GetDlgItem(IDC_BUTTON_UPDATE
)->ShowWindow(!m_bFromOK
|| !m_bToOK
|| m_bToIsWorkingCopy
? SW_SHOW
: SW_HIDE
);
134 HBRUSH
CSubmoduleDiffDlg::GetInvalidBrush(CDC
* pDC
)
136 pDC
->SetBkColor(RGB(255, 0, 0));
137 pDC
->SetTextColor(RGB(255, 255, 255));
138 return CreateSolidBrush(RGB(255, 0, 0));
141 HBRUSH
CSubmoduleDiffDlg::GetChangeTypeBrush(CDC
* pDC
, const CGitDiff::ChangeType
& changeType
)
143 if (changeType
== CGitDiff::FastForward
)
146 pDC
->SetBkColor(RGB(211, 249, 154));
147 pDC
->SetTextColor(RGB(0, 0, 0));
148 return CreateSolidBrush(RGB(211, 249, 154));
150 if (changeType
== CGitDiff::Rewind
)
153 pDC
->SetBkColor(RGB(249, 199, 229));
154 pDC
->SetTextColor(RGB(0, 0, 0));
155 return CreateSolidBrush(RGB(249, 199, 229));
157 if (changeType
== CGitDiff::NewerTime
)
160 pDC
->SetBkColor(RGB(176, 223, 244));
161 pDC
->SetTextColor(RGB(0, 0, 0));
162 return CreateSolidBrush(RGB(176, 223, 244));
164 if (changeType
== CGitDiff::OlderTime
)
167 pDC
->SetBkColor(RGB(244, 207, 159));
168 pDC
->SetTextColor(RGB(0, 0, 0));
169 return CreateSolidBrush(RGB(244, 207, 159));
173 pDC
->SetBkColor(RGB(222, 222, 222));
174 pDC
->SetTextColor(RGB(0, 0, 0));
175 return CreateSolidBrush(RGB(222, 222, 222));
178 HBRUSH
CSubmoduleDiffDlg::OnCtlColor(CDC
* pDC
, CWnd
* pWnd
, UINT nCtlColor
)
180 if (nCtlColor
== CTLCOLOR_STATIC
)
182 if (pWnd
->GetDlgCtrlID() == IDC_FROMSUBJECT
&& !m_bFromOK
)
183 return GetInvalidBrush(pDC
);
185 if (pWnd
->GetDlgCtrlID() == IDC_TOSUBJECT
&& !m_bToOK
)
186 return GetInvalidBrush(pDC
);
188 if (pWnd
->GetDlgCtrlID() == IDC_TOHASH
&& m_bDirty
)
190 pDC
->SetBkColor(RGB(255, 255, 0));
191 pDC
->SetTextColor(RGB(255, 0, 0));
192 return CreateSolidBrush(RGB(255, 255, 0));
195 if (pWnd
->GetDlgCtrlID() == IDC_CHANGETYPE
&& m_nChangeType
!= CGitDiff::Identical
)
196 return GetChangeTypeBrush(pDC
, m_nChangeType
);
199 return CHorizontalResizableStandAloneDialog::OnCtlColor(pDC
, pWnd
, nCtlColor
);
202 BOOL
CSubmoduleDiffDlg::PreTranslateMessage(MSG
* pMsg
)
204 if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
== VK_F5
)
210 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
213 void CSubmoduleDiffDlg::SetDiff(CString path
, bool toIsWorkingCopy
, CString fromHash
, CString fromSubject
, bool fromOK
, CString toHash
, CString toSubject
, bool toOK
, bool dirty
, CGitDiff::ChangeType changeType
)
215 m_bToIsWorkingCopy
= toIsWorkingCopy
;
219 m_sFromHash
= fromHash
;
220 m_sFromSubject
= fromSubject
;
223 m_sToSubject
= toSubject
;
226 m_nChangeType
= changeType
;
229 void CSubmoduleDiffDlg::ShowLog(CString hash
)
232 sCmd
.Format(L
"/command:log /path:\"%s\" /endrev:%s", (LPCTSTR
)g_Git
.CombinePath(m_sPath
), (LPCTSTR
)hash
);
233 CAppUtils::RunTortoiseGitProc(sCmd
, false, false);
236 void CSubmoduleDiffDlg::OnBnClickedLog()
238 ShowLog(m_sFromHash
);
241 void CSubmoduleDiffDlg::OnBnClickedLog2()
246 void CSubmoduleDiffDlg::OnBnClickedShowDiff()
249 sCmd
.Format(L
"/command:showcompare /path:\"%s\" /revision1:%s /revision2:%s", (LPCTSTR
)g_Git
.CombinePath(m_sPath
), (LPCTSTR
)m_sFromHash
, ((m_bDirty
&& m_nChangeType
== CGitDiff::Unknown
) || m_ctrlShowDiffBtn
.GetCurrentEntry() == 1) ? GIT_REV_ZERO
: (LPCTSTR
)m_sToHash
);
251 if (!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000))
252 sCmd
+= L
" /alternative";
254 CAppUtils::RunTortoiseGitProc(sCmd
, false, false);
257 void CSubmoduleDiffDlg::OnBnClickedButtonUpdate()
260 sCmd
.Format(L
"/command:subupdate /bkpath:\"%s\" /selectedpath:\"%s\"", (LPCTSTR
)g_Git
.m_CurrentDir
, (LPCTSTR
)m_sPath
);
261 CAppUtils::RunTortoiseGitProc(sCmd
);