Fix wrong xdg config string
[TortoiseGit.git] / src / TortoiseProc / SubmoduleDiffDlg.cpp
blob792f09c368f35f6c833277deba8703057ef9fd67
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2012 - 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.
19 #include "stdafx.h"
20 #include "TortoiseProc.h"
21 #include "AppUtils.h"
22 #include "SubmoduleDiffDlg.h"
23 #include "LoglistCommonResource.h"
25 IMPLEMENT_DYNAMIC(CSubmoduleDiffDlg, CHorizontalResizableStandAloneDialog)
26 CSubmoduleDiffDlg::CSubmoduleDiffDlg(CWnd* pParent /*=NULL*/)
27 : CHorizontalResizableStandAloneDialog(CSubmoduleDiffDlg::IDD, pParent)
28 , m_bToIsWorkingCopy(false)
29 , m_bFromOK(false)
30 , m_bToOK(false)
31 , m_bDirty(false)
32 , m_nChangeType(Unknown)
33 , m_bRefresh(false)
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)
55 ON_WM_CTLCOLOR()
56 ON_BN_CLICKED(IDC_BUTTON_UPDATE, &CSubmoduleDiffDlg::OnBnClickedButtonUpdate)
57 END_MESSAGE_MAP()
59 BOOL CSubmoduleDiffDlg::OnInitDialog()
61 CHorizontalResizableStandAloneDialog::OnInitDialog();
63 CString sWindowTitle;
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(_T("SubmoduleDiffDlg"));
90 if (m_bToIsWorkingCopy)
92 CString toGroup;
93 GetDlgItem(IDC_TOGROUP)->GetWindowText(toGroup);
94 toGroup += _T(" (") + CString(MAKEINTRESOURCE(IDS_git_DEPTH_WORKING)) + _T(")");
95 GetDlgItem(IDC_TOGROUP)->SetWindowText(toGroup);
98 CString fsPath = m_sPath;
99 fsPath.Replace('\\', '/');
100 CString title = _T("Submodule \"") + fsPath + _T("\"");
101 GetDlgItem(IDC_SUBMODULEDIFFTITLE)->SetWindowText(title);
103 UpdateData(FALSE);
104 if (m_bDirty)
105 GetDlgItem(IDC_TOHASH)->SetWindowText(m_sToHash + _T("-dirty"));
107 CString changeTypeTable[] =
109 CString(MAKEINTRESOURCE(IDS_SUBMODULEDIFF_UNKNOWN)),
110 CString(MAKEINTRESOURCE(IDS_SUBMODULEDIFF_NEWSUBMODULE)),
111 CString(MAKEINTRESOURCE(IDS_SUBMODULEDIFF_DELETESUBMODULE)),
112 CString(MAKEINTRESOURCE(IDS_SUBMODULEDIFF_FASTFORWARD)),
113 CString(MAKEINTRESOURCE(IDS_SUBMODULEDIFF_REWIND)),
114 CString(MAKEINTRESOURCE(IDS_SUBMODULEDIFF_NEWERTIME)),
115 CString(MAKEINTRESOURCE(IDS_SUBMODULEDIFF_OLDERTIME)),
116 CString(MAKEINTRESOURCE(IDS_SUBMODULEDIFF_SAMETIME))
118 GetDlgItem(IDC_CHANGETYPE)->SetWindowText(changeTypeTable[m_nChangeType]);
120 DialogEnableWindow(IDC_SHOW_DIFF, m_bFromOK && m_bToOK);
121 if (m_bDirty && m_nChangeType != Unknown)
123 m_ctrlShowDiffBtn.AddEntry(MAKEINTRESOURCE(IDS_PROC_SHOWDIFF));
124 m_ctrlShowDiffBtn.AddEntry(MAKEINTRESOURCE(IDS_LOG_POPUP_COMPARE));
127 GetDlgItem(IDC_BUTTON_UPDATE)->ShowWindow(!m_bFromOK || !m_bToOK || m_bToIsWorkingCopy ? SW_SHOW : SW_HIDE);
129 return FALSE;
132 HBRUSH CSubmoduleDiffDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
134 if (pWnd->GetDlgCtrlID() == IDC_FROMSUBJECT && nCtlColor == CTLCOLOR_STATIC && !m_bFromOK)
136 pDC->SetBkColor(RGB(255, 0, 0));
137 pDC->SetTextColor(RGB(255, 255, 255));
138 return CreateSolidBrush(RGB(255, 0, 0));
141 if (pWnd->GetDlgCtrlID() == IDC_TOSUBJECT && nCtlColor == CTLCOLOR_STATIC && !m_bToOK)
143 pDC->SetBkColor(RGB(255, 0, 0));
144 pDC->SetTextColor(RGB(255, 255, 255));
145 return CreateSolidBrush(RGB(255, 0, 0));
148 if (pWnd->GetDlgCtrlID() == IDC_TOHASH && nCtlColor == CTLCOLOR_STATIC && m_bDirty)
150 pDC->SetBkColor(RGB(255, 255, 0));
151 pDC->SetTextColor(RGB(255, 0, 0));
152 return CreateSolidBrush(RGB(255, 255, 0));
155 if (pWnd->GetDlgCtrlID() == IDC_CHANGETYPE && nCtlColor == CTLCOLOR_STATIC)
157 if (m_nChangeType == FastForward)
159 // light green
160 pDC->SetBkColor(RGB(211, 249, 154));
161 pDC->SetTextColor(RGB(0, 0, 0));
162 return CreateSolidBrush(RGB(211, 249, 154));
164 else if (m_nChangeType == Rewind)
166 // pink
167 pDC->SetBkColor(RGB(249, 199, 229));
168 pDC->SetTextColor(RGB(0, 0, 0));
169 return CreateSolidBrush(RGB(249, 199, 229));
171 else if (m_nChangeType == NewerTime)
173 // light blue
174 pDC->SetBkColor(RGB(176, 223, 244));
175 pDC->SetTextColor(RGB(0, 0, 0));
176 return CreateSolidBrush(RGB(176, 223, 244));
178 else if (m_nChangeType == OlderTime)
180 // light orange
181 pDC->SetBkColor(RGB(244, 207, 159));
182 pDC->SetTextColor(RGB(0, 0, 0));
183 return CreateSolidBrush(RGB(244, 207, 159));
185 else
187 // light gray
188 pDC->SetBkColor(RGB(222, 222, 222));
189 pDC->SetTextColor(RGB(0, 0, 0));
190 return CreateSolidBrush(RGB(222, 222, 222));
194 return CHorizontalResizableStandAloneDialog::OnCtlColor(pDC, pWnd, nCtlColor);
197 BOOL CSubmoduleDiffDlg::PreTranslateMessage(MSG* pMsg)
199 if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_F5)
201 m_bRefresh = true;
202 EndDialog(0);
205 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
208 void CSubmoduleDiffDlg::SetDiff(CString path, bool toIsWorkingCopy, CString fromHash, CString fromSubject, bool fromOK, CString toHash, CString toSubject, bool toOK, bool dirty, ChangeType changeType)
210 m_bToIsWorkingCopy = toIsWorkingCopy;
212 m_sPath = path;
214 m_sFromHash = fromHash;
215 m_sFromSubject = fromSubject;
216 m_bFromOK = fromOK;
217 m_sToHash = toHash;
218 m_sToSubject = toSubject;
219 m_bToOK = toOK;
220 m_bDirty = dirty;
221 m_nChangeType = changeType;
224 void CSubmoduleDiffDlg::ShowLog(CString hash)
226 CString sCmd;
227 sCmd.Format(_T("/command:log /path:\"%s\" /endrev:%s"), g_Git.CombinePath(m_sPath), hash);
228 CAppUtils::RunTortoiseGitProc(sCmd, false, false);
231 void CSubmoduleDiffDlg::OnBnClickedLog()
233 ShowLog(m_sFromHash);
236 void CSubmoduleDiffDlg::OnBnClickedLog2()
238 ShowLog(m_sToHash);
241 void CSubmoduleDiffDlg::OnBnClickedShowDiff()
243 CString sCmd;
244 sCmd.Format(_T("/command:showcompare /path:\"%s\" /revision1:%s /revision2:%s"), g_Git.CombinePath(m_sPath), m_sFromHash, ((m_bDirty && m_nChangeType == Unknown) || m_ctrlShowDiffBtn.GetCurrentEntry() == 1) ? GIT_REV_ZERO : m_sToHash);
245 CAppUtils::RunTortoiseGitProc(sCmd, false, false);
248 void CSubmoduleDiffDlg::OnBnClickedButtonUpdate()
250 CString sCmd;
251 sCmd.Format(_T("/command:subupdate /bkpath:\"%s\" /selectedpath:\"%s\""), g_Git.m_CurrentDir, m_sPath);
252 CAppUtils::RunTortoiseGitProc(sCmd);