1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - TortoiseGit
4 // Copyright (C) 2011-2012 Sven Strickroth <email@cs-ware.de>
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.
22 #include "GitBlameLogList.h"
24 #include "TortoiseGitBlameDoc.h"
25 #include "TortoiseGitBlameView.h"
27 #include "CommonAppUtils.h"
29 IMPLEMENT_DYNAMIC(CGitBlameLogList
, CHintListCtrl
)
31 void CGitBlameLogList::hideUnimplementedCommands()
34 GetContextMenuBit(ID_COMPAREWITHPREVIOUS
) |
35 GetContextMenuBit(ID_COPYCLIPBOARD
) |
36 GetContextMenuBit(ID_COPYHASH
) |
37 GetContextMenuBit(ID_EXPORT
) |
38 GetContextMenuBit(ID_CREATE_BRANCH
) |
39 GetContextMenuBit(ID_CREATE_TAG
) |
40 GetContextMenuBit(ID_SWITCHTOREV
)
42 m_ContextMenuMask
|= GetContextMenuBit(ID_LOG
) | GetContextMenuBit(ID_BLAME
) | GetContextMenuBit(ID_REPOBROWSE
);
45 void CGitBlameLogList::ContextMenuAction(int cmd
,int FirstSelect
, int LastSelect
,CMenu
* menu
)
47 POSITION pos
= GetFirstSelectedItemPosition();
48 int indexNext
= GetNextSelectedItem(pos
);
54 GitRev
* pSelLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(indexNext
));
56 bool bOpenWith
= false;
58 procCmd
+= _T("/path:\"");
59 procCmd
+= ((CMainFrame
*)::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName();
61 procCmd
+= _T(" /rev:")+this->m_logEntries
.GetGitRevAt(indexNext
).m_CommitHash
.ToString();
63 procCmd
+= _T(" /command:");
68 procCmd
+= _T("diff /udiff");
74 CString tempfile
=GetTempFile();
76 GitRev
* r1
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(FirstSelect
));
77 GitRev
* r2
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(LastSelect
));
78 cmd
.Format(_T("git.exe diff-tree -r -p --stat %s %s"),r1
->m_CommitHash
,r2
->m_CommitHash
);
79 g_Git
.RunLogFile(cmd
,tempfile
);
80 CAppUtils::StartUnifiedDiffViewer(tempfile
, r1
->m_CommitHash
.Left(g_Git
.GetShortHASHLength()) + _T(":") + r2
->m_CommitHash
.Left(g_Git
.GetShortHASHLength()));
88 GitRev
* r1
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(FirstSelect
));
89 GitRev
* r2
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(LastSelect
));
91 dlg
.SetDiff(NULL
,*r1
,*r2
);
100 GitRev
* r1
= &m_wcRev
;
101 GitRev
* r2
= pSelLogEntry
;
103 dlg
.SetDiff(NULL
,*r1
,*r2
);
106 //user clicked on the menu item "compare with working copy"
109 // GitDiff diff(this, m_hWnd, true);
110 // diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
111 // diff.SetHEADPeg(m_LogRevision);
112 // diff.ShowCompare(m_path, GitRev::REV_WC, m_path, revSelected);
115 // CAppUtils::StartShowCompare(m_hWnd, m_path, GitRev::REV_WC, m_path, revSelected, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
119 procCmd
+=CString(_T("diff \rev1:"))+CString(GIT_REV_ZERO
)+CString(_T(" \rev2:"))+this->m_logEntries
.GetGitRevAt(indexNext
).m_CommitHash
.ToString();
122 case ID_COMPAREWITHPREVIOUS
:
123 if (indexNext
+ 1 < m_logEntries
.size()) // cannot diff previous revision in first revision
125 procCmd
+=CString(_T("diff /startrev:"))+this->m_logEntries
.GetGitRevAt(indexNext
).m_CommitHash
.ToString()+CString(_T(" /endrev:"))+this->m_logEntries
.GetGitRevAt(indexNext
+1).m_CommitHash
.ToString();
132 case ID_COPYCLIPBOARD
:
134 CopySelectionToClipBoard();
139 CopySelectionToClipBoard(TRUE
);
143 procCmd
+= _T("export");
145 case ID_CREATE_BRANCH
:
146 procCmd
+= _T("branch");
149 procCmd
+= _T("tag");
152 procCmd
+= _T("switch");
155 procCmd
+= _T("blame");
156 procCmd
+= _T(" /endrev:") + this->m_logEntries
.GetGitRevAt(indexNext
).m_CommitHash
.ToString();
159 procCmd
+= _T("log");
162 procCmd
.Format(_T("/command:repobrowser /path:\"%s\" /rev:%s"), g_Git
.m_CurrentDir
, this->m_logEntries
.GetGitRevAt(indexNext
).m_CommitHash
.ToString());
165 //CMessageBox::Show(NULL,_T("Have not implemented"),_T("TortoiseGit"),MB_OK);
172 // we need an URL to complete this command, so error out if we can't get an URL
173 if (pathURL
.IsEmpty())
176 strMessage
.Format(IDS_ERR_NOURLOFFILE
, (LPCTSTR
)(m_path
.GetUIPathString()));
177 CMessageBox::Show(this->m_hWnd
, strMessage
, _T("TortoiseGit"), MB_ICONERROR
);
178 TRACE(_T("could not retrieve the URL of the folder!\n"));
182 msg
.Format(IDS_LOG_REVERT_CONFIRM
, m_path
.GetWinPath());
183 if (CMessageBox::Show(this->m_hWnd
, msg
, _T("TortoiseGit"), MB_YESNO
| MB_ICONQUESTION
) == IDYES
)
186 dlg
.SetCommand(CGitProgressDlg::GitProgress_Merge
);
187 dlg
.SetPathList(CTGitPathList(m_path
));
189 dlg
.SetSecondUrl(pathURL
);
190 revisionRanges
.AdjustForMerge(true);
191 dlg
.SetRevisionRanges(revisionRanges
);
192 dlg
.SetPegRevision(m_LogRevision
);
199 m_nSearchIndex
= GetSelectionMark();
200 if (m_nSearchIndex
< 0)
208 m_pFindDialog
= new CFindReplaceDialog();
209 m_pFindDialog
->Create(TRUE
, NULL
, NULL
, FR_HIDEUPDOWN
| FR_HIDEWHOLEWORD
, this);
217 CCommonAppUtils::RunTortoiseProc(procCmd
);