From 3bcd2487d37cd9de8d9651a3812bc48c3a091619 Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Fri, 13 Jul 2018 17:54:34 +0200 Subject: [PATCH] Pass HWND to CGitDiff Signed-off-by: Sven Strickroth --- src/Git/GitStatusListCtrl.cpp | 24 +++---- src/TortoiseProc/Commands/DiffCommand.cpp | 12 ++-- src/TortoiseProc/Commands/PrevDiffCommand.cpp | 2 +- src/TortoiseProc/Commands/ShowCompareCommand.cpp | 4 +- src/TortoiseProc/FileDiffDlg.cpp | 10 +-- src/TortoiseProc/GitDiff.cpp | 79 ++++++++++++------------ src/TortoiseProc/GitDiff.h | 18 +++--- src/TortoiseProc/GitLogListAction.cpp | 12 ++-- src/TortoiseProc/RepositoryBrowser.cpp | 6 +- 9 files changed, 84 insertions(+), 83 deletions(-) diff --git a/src/Git/GitStatusListCtrl.cpp b/src/Git/GitStatusListCtrl.cpp index 781f9661a..154fbfa6f 100644 --- a/src/Git/GitStatusListCtrl.cpp +++ b/src/Git/GitStatusListCtrl.cpp @@ -1923,7 +1923,7 @@ void CGitStatusListCtrl::OnContextMenuList(CWnd * pWnd, CPoint point) case IDGITLC_PREPAREDIFF_COMPARE: { CTGitPath savedFile(m_sMarkForDiffFilename); - CGitDiff::Diff(filepath, &savedFile, m_CurrentVersion, m_sMarkForDiffVersion, false, false, 0, bShift); + CGitDiff::Diff(GetParentHWND(), filepath, &savedFile, m_CurrentVersion, m_sMarkForDiffVersion, false, false, 0, bShift); } break; @@ -2619,11 +2619,11 @@ void CGitStatusListCtrl::StartDiffTwo(int fileindex) CTGitPath file1 = *ptr; if (file1.m_Action & CTGitPath::LOGACTIONS_ADDED) - CGitDiff::DiffNull(&file1, m_Rev1, true, 0, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)); + CGitDiff::DiffNull(GetParentHWND(), &file1, m_Rev1, true, 0, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)); else if (file1.m_Action & CTGitPath::LOGACTIONS_DELETED) - CGitDiff::DiffNull(&file1, m_Rev2, false, 0, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)); + CGitDiff::DiffNull(GetParentHWND(), &file1, m_Rev2, false, 0, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)); else - CGitDiff::Diff(&file1, &file1, m_Rev1, m_Rev2, false, false, 0, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)); + CGitDiff::Diff(GetParentHWND(), &file1, &file1, m_Rev1, m_Rev2, false, false, 0, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)); } void CGitStatusListCtrl::StartDiffWC(int fileindex) @@ -2641,7 +2641,7 @@ void CGitStatusListCtrl::StartDiffWC(int fileindex) CTGitPath file1 = *ptr; file1.m_Action = 0; // reset action, so that diff is not started as added/deleted file; see issue #1757 - CGitDiff::Diff(&file1, &file1, GIT_REV_ZERO, m_CurrentVersion, false, false, 0, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)); + CGitDiff::Diff(GetParentHWND(), &file1, &file1, GIT_REV_ZERO, m_CurrentVersion, false, false, 0, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)); } void CGitStatusListCtrl::StartDiff(int fileindex) @@ -2666,16 +2666,16 @@ void CGitStatusListCtrl::StartDiff(int fileindex) if(m_amend && (file1.m_Action & CTGitPath::LOGACTIONS_ADDED) == 0) fromwhere = L"~1"; if( g_Git.IsInitRepos()) - CGitDiff::DiffNull(GetListEntry(fileindex), + CGitDiff::DiffNull(GetParentHWND(), GetListEntry(fileindex), GIT_REV_ZERO, true, 0, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)); else if( file1.m_Action&CTGitPath::LOGACTIONS_ADDED ) - CGitDiff::DiffNull(GetListEntry(fileindex), + CGitDiff::DiffNull(GetParentHWND(), GetListEntry(fileindex), m_CurrentVersion + fromwhere, true, 0, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)); else if( file1.m_Action&CTGitPath::LOGACTIONS_DELETED ) - CGitDiff::DiffNull(GetListEntry(fileindex), + CGitDiff::DiffNull(GetParentHWND(), GetListEntry(fileindex), GitRev::GetHead() + fromwhere, false, 0, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)); else - CGitDiff::Diff(&file1,&file2, + CGitDiff::Diff(GetParentHWND(), &file1,&file2, CString(GIT_REV_ZERO), GitRev::GetHead() + fromwhere, false, false, 0, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)); } @@ -2687,13 +2687,13 @@ void CGitStatusListCtrl::StartDiff(int fileindex) fromwhere = m_CurrentVersion + L"~2"; bool revfail = !!g_Git.GetHash(hash, fromwhere); if (revfail || (file1.m_Action & file1.LOGACTIONS_ADDED)) - CGitDiff::DiffNull(&file1, m_CurrentVersion, true, 0, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)); + CGitDiff::DiffNull(GetParentHWND(), &file1, m_CurrentVersion, true, 0, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)); else if (file1.m_Action & file1.LOGACTIONS_DELETED) { if (file1.m_ParentNo > 0) fromwhere.Format(L"%s^%d", (LPCTSTR)m_CurrentVersion, file1.m_ParentNo + 1); - CGitDiff::DiffNull(&file1, fromwhere, false, 0, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)); + CGitDiff::DiffNull(GetParentHWND(), &file1, fromwhere, false, 0, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)); } else { @@ -2780,7 +2780,7 @@ void CGitStatusListCtrl::StartDiff(int fileindex) str = L"~1"; else str.Format(L"^%d", (file1.m_ParentNo & PARENT_MASK) + 1); - CGitDiff::Diff(&file1,&file2, + CGitDiff::Diff(GetParentHWND(), &file1,&file2, m_CurrentVersion, m_CurrentVersion + str, false, false, 0, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)); } diff --git a/src/TortoiseProc/Commands/DiffCommand.cpp b/src/TortoiseProc/Commands/DiffCommand.cpp index 1bd5689ff..9a95b6e69 100644 --- a/src/TortoiseProc/Commands/DiffCommand.cpp +++ b/src/TortoiseProc/Commands/DiffCommand.cpp @@ -1,7 +1,7 @@ // TortoiseGit - a Windows shell extension for easy version control // Copyright (C) 2007-2008 - TortoiseSVN -// Copyright (C) 2008-2017 - TortoiseGit +// Copyright (C) 2008-2018 - TortoiseGit // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -51,7 +51,7 @@ bool DiffCommand::Execute() if (parser.HasKey(L"unified")) bRet = !!CAppUtils::StartShowUnifiedDiff(nullptr, cmdLinePath, parser.GetVal(L"startrev"), cmdLinePath, parser.GetVal(L"endrev"), bAlternativeTool); else - bRet = !!CGitDiff::Diff(&cmdLinePath, &cmdLinePath, parser.GetVal(L"endrev"), parser.GetVal(L"startrev"), false, parser.HasKey(L"unified") == TRUE, parser.GetLongVal(L"line"), bAlternativeTool, false); + bRet = !!CGitDiff::Diff(GetExplorerHWND(), &cmdLinePath, &cmdLinePath, parser.GetVal(L"endrev"), parser.GetVal(L"startrev"), false, parser.HasKey(L"unified") == TRUE, parser.GetLongVal(L"line"), bAlternativeTool, false); } else { @@ -78,7 +78,7 @@ bool DiffCommand::Execute() CTGitPath oldPath(changedFiles[i].GetGitOldPathString()); if (parser.HasKey(L"unified")) return !!CAppUtils::StartShowUnifiedDiff(nullptr, cmdLinePath, L"HEAD", cmdLinePath, GIT_REV_ZERO, bAlternativeTool); - return !!CGitDiff::Diff(&cmdLinePath, &oldPath, GIT_REV_ZERO, L"HEAD", false, parser.HasKey(L"unified") == TRUE, parser.GetLongVal(L"line"), bAlternativeTool); + return !!CGitDiff::Diff(GetExplorerHWND(), &cmdLinePath, &oldPath, GIT_REV_ZERO, L"HEAD", false, parser.HasKey(L"unified") == TRUE, parser.GetLongVal(L"line"), bAlternativeTool); } break; } @@ -90,13 +90,13 @@ bool DiffCommand::Execute() return !!CAppUtils::StartShowUnifiedDiff(nullptr, cmdLinePath, L"HEAD", cmdLinePath, GIT_REV_ZERO, bAlternativeTool); } else - return !!CGitDiff::DiffNull(&cmdLinePath, GIT_REV_ZERO, true, parser.GetLongVal(L"line"), bAlternativeTool); + return !!CGitDiff::DiffNull(GetExplorerHWND(), &cmdLinePath, GIT_REV_ZERO, true, parser.GetLongVal(L"line"), bAlternativeTool); } if (parser.HasKey(L"unified")) bRet = !!CAppUtils::StartShowUnifiedDiff(nullptr, cmdLinePath, L"HEAD", cmdLinePath, GIT_REV_ZERO, bAlternativeTool); else - bRet = !!CGitDiff::Diff(&cmdLinePath, &cmdLinePath, GIT_REV_ZERO, L"HEAD", false, parser.HasKey(L"unified") == TRUE, parser.GetLongVal(L"line"), bAlternativeTool); + bRet = !!CGitDiff::Diff(GetExplorerHWND(), &cmdLinePath, &cmdLinePath, GIT_REV_ZERO, L"HEAD", false, parser.HasKey(L"unified") == TRUE, parser.GetLongVal(L"line"), bAlternativeTool); } } } @@ -105,7 +105,7 @@ bool DiffCommand::Execute() if (parser.HasKey(L"startrev") && parser.HasKey(L"endrev") && CStringUtils::StartsWith(path2, g_Git.m_CurrentDir + L"\\")) { CTGitPath tgitPath2 = path2.Mid(g_Git.m_CurrentDir.GetLength() + 1); - bRet = !!CGitDiff::Diff(&tgitPath2, &cmdLinePath, parser.GetVal(L"endrev"), parser.GetVal(L"startrev"), false, parser.HasKey(L"unified") == TRUE, parser.GetLongVal(L"line"), bAlternativeTool); + bRet = !!CGitDiff::Diff(GetExplorerHWND(), &tgitPath2, &cmdLinePath, parser.GetVal(L"endrev"), parser.GetVal(L"startrev"), false, parser.HasKey(L"unified") == TRUE, parser.GetLongVal(L"line"), bAlternativeTool); } else { diff --git a/src/TortoiseProc/Commands/PrevDiffCommand.cpp b/src/TortoiseProc/Commands/PrevDiffCommand.cpp index 3b5597177..4063b742f 100644 --- a/src/TortoiseProc/Commands/PrevDiffCommand.cpp +++ b/src/TortoiseProc/Commands/PrevDiffCommand.cpp @@ -52,5 +52,5 @@ bool PrevDiffCommand::Execute() return false; } - return !!CGitDiff::Diff(&cmdLinePath, &cmdLinePath, GIT_REV_ZERO, revs.GetGitRevAt(1).m_CommitHash.ToString(), false, bUnified, 0, bAlternativeTool); + return !!CGitDiff::Diff(GetExplorerHWND(), &cmdLinePath, &cmdLinePath, GIT_REV_ZERO, revs.GetGitRevAt(1).m_CommitHash.ToString(), false, bUnified, 0, bAlternativeTool); } diff --git a/src/TortoiseProc/Commands/ShowCompareCommand.cpp b/src/TortoiseProc/Commands/ShowCompareCommand.cpp index f5389e123..bd9dcde9a 100644 --- a/src/TortoiseProc/Commands/ShowCompareCommand.cpp +++ b/src/TortoiseProc/Commands/ShowCompareCommand.cpp @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2012-2013, 2016 - TortoiseGit +// Copyright (C) 2012-2013, 2016, 2018 - TortoiseGit // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -38,5 +38,5 @@ bool ShowCompareCommand::Execute() if (unified) return !!CAppUtils::StartShowUnifiedDiff(nullptr, cmdLinePath, rev1, CTGitPath(), rev2, bAlternativeTool); else - return !!CGitDiff::DiffCommit(cmdLinePath, rev2, rev1, bAlternativeTool); + return !!CGitDiff::DiffCommit(GetExplorerHWND(), cmdLinePath, rev2, rev1, bAlternativeTool); } diff --git a/src/TortoiseProc/FileDiffDlg.cpp b/src/TortoiseProc/FileDiffDlg.cpp index bb327e1b4..d3949f9f7 100644 --- a/src/TortoiseProc/FileDiffDlg.cpp +++ b/src/TortoiseProc/FileDiffDlg.cpp @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2008-2017 - TortoiseGit +// Copyright (C) 2008-2018 - TortoiseGit // Copyright (C) 2003-2008 - TortoiseSVN // This program is free software; you can redistribute it and/or @@ -425,22 +425,22 @@ void CFileDiffDlg::DoDiff(int selIndex, bool blame) CTGitPath* fd1 = fd2; if (m_rev2.m_CommitHash.IsEmpty() && g_Git.IsInitRepos()) { - CGitDiff::DiffNull(fd2, GIT_REV_ZERO, true, 0, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)); + CGitDiff::DiffNull(GetSafeHwnd(), fd2, GIT_REV_ZERO, true, 0, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)); return; } if (fd1->m_Action & CTGitPath::LOGACTIONS_ADDED) { - CGitDiff::DiffNull(fd1, m_rev2.m_CommitHash.ToString(), true, 0, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)); + CGitDiff::DiffNull(GetSafeHwnd(), fd1, m_rev2.m_CommitHash.ToString(), true, 0, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)); return; } if (fd1->m_Action & CTGitPath::LOGACTIONS_DELETED) { - CGitDiff::DiffNull(fd1, m_rev1.m_CommitHash.ToString(), false, 0, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)); + CGitDiff::DiffNull(GetSafeHwnd(), fd1, m_rev1.m_CommitHash.ToString(), false, 0, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)); return; } if (fd1->m_Action & CTGitPath::LOGACTIONS_REPLACED) fd2 = new CTGitPath(fd1->GetGitOldPathString()); - CGitDiff::Diff(fd1, fd2, m_rev2.m_CommitHash.ToString(), m_rev1.m_CommitHash.ToString(), blame, FALSE, 0, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)); + CGitDiff::Diff(GetSafeHwnd(), fd1, fd2, m_rev2.m_CommitHash.ToString(), m_rev1.m_CommitHash.ToString(), blame, FALSE, 0, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)); if (fd1 != fd2) delete fd2; } diff --git a/src/TortoiseProc/GitDiff.cpp b/src/TortoiseProc/GitDiff.cpp index 110f40e2a..b7d20fa61 100644 --- a/src/TortoiseProc/GitDiff.cpp +++ b/src/TortoiseProc/GitDiff.cpp @@ -1,7 +1,7 @@ // TortoiseGit - a Windows shell extension for easy version control // Copyright (C) 2003-2008 - TortoiseSVN -// Copyright (C) 2008-2017 - TortoiseGit +// Copyright (C) 2008-2018 - TortoiseGit // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -19,6 +19,7 @@ #include "stdafx.h" #include "GitDiff.h" +#include "TortoiseProc.h" #include "AppUtils.h" #include "gittype.h" #include "resource.h" @@ -27,7 +28,7 @@ #include "SubmoduleDiffDlg.h" #include "TempFile.h" -int CGitDiff::SubmoduleDiffNull(const CTGitPath* pPath, const CString& rev1) +int CGitDiff::SubmoduleDiffNull(HWND hWnd, const CTGitPath* pPath, const CString& rev1) { CString newsub; CString newhash; @@ -41,7 +42,7 @@ int CGitDiff::SubmoduleDiffNull(const CTGitPath* pPath, const CString& rev1) CString output, err; if (g_Git.Run(cmd, &output, &err, CP_UTF8)) { - CMessageBox::Show(nullptr, output + L'\n' + err, L"TortoiseGit", MB_OK | MB_ICONERROR); + CMessageBox::Show(hWnd, output + L'\n' + err, L"TortoiseGit", MB_OK | MB_ICONERROR); return -1; } @@ -68,7 +69,7 @@ int CGitDiff::SubmoduleDiffNull(const CTGitPath* pPath, const CString& rev1) dirty = !dirtyList.IsEmpty(); } - CSubmoduleDiffDlg submoduleDiffDlg; + CSubmoduleDiffDlg submoduleDiffDlg(GetExplorerHWND() == hWnd ? nullptr : CWnd::FromHandle(hWnd)); if (pPath->m_Action & CTGitPath::LOGACTIONS_DELETED) submoduleDiffDlg.SetDiff(pPath->GetWinPath(), false, newhash, newsub, toOK, GIT_REV_ZERO, L"", false, dirty, DeleteSubmodule); else @@ -81,20 +82,20 @@ int CGitDiff::SubmoduleDiffNull(const CTGitPath* pPath, const CString& rev1) } if (rev1 != GIT_REV_ZERO) - CMessageBox::Show(nullptr, L"ls-tree output format error", L"TortoiseGit", MB_OK | MB_ICONERROR); + CMessageBox::Show(hWnd, L"ls-tree output format error", L"TortoiseGit", MB_OK | MB_ICONERROR); else - CMessageBox::Show(nullptr, L"ls-files output format error", L"TortoiseGit", MB_OK | MB_ICONERROR); + CMessageBox::Show(hWnd, L"ls-files output format error", L"TortoiseGit", MB_OK | MB_ICONERROR); return -1; } -int CGitDiff::DiffNull(const CTGitPath* pPath, CString rev1, bool bIsAdd, int jumpToLine, bool bAlternative) +int CGitDiff::DiffNull(HWND hWnd, const CTGitPath* pPath, CString rev1, bool bIsAdd, int jumpToLine, bool bAlternative) { if (rev1 != GIT_REV_ZERO) { CGitHash rev1Hash; if (g_Git.GetHash(rev1Hash, rev1)) // make sure we have a HASH here, otherwise filenames might be invalid { - MessageBox(nullptr, g_Git.GetGitLastErr(L"Could not get hash of \"" + rev1 + L"\"."), L"TortoiseGit", MB_ICONERROR); + MessageBox(hWnd, g_Git.GetGitLastErr(L"Could not get hash of \"" + rev1 + L"\"."), L"TortoiseGit", MB_ICONERROR); return -1; } rev1 = rev1Hash.ToString(); @@ -108,7 +109,7 @@ int CGitDiff::DiffNull(const CTGitPath* pPath, CString rev1, bool bIsAdd, int ju int result; // refresh if result = 1 CTGitPath path = *pPath; - while ((result = SubmoduleDiffNull(&path, rev1)) == 1) + while ((result = SubmoduleDiffNull(hWnd, &path, rev1)) == 1) path.SetFromGit(pPath->GetGitPathString()); return result; } @@ -120,7 +121,7 @@ int CGitDiff::DiffNull(const CTGitPath* pPath, CString rev1, bool bIsAdd, int ju { CString out; out.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED, (LPCTSTR)pPath->GetGitPathString(), (LPCTSTR)rev1, (LPCTSTR)file1); - CMessageBox::Show(nullptr, g_Git.GetGitLastErr(out, CGit::GIT_CMD_GETONEFILE), L"TortoiseGit", MB_OK); + CMessageBox::Show(hWnd, g_Git.GetGitLastErr(out, CGit::GIT_CMD_GETONEFILE), L"TortoiseGit", MB_OK); return -1; } ::SetFileAttributes(file1, FILE_ATTRIBUTE_READONLY); @@ -151,7 +152,7 @@ int CGitDiff::DiffNull(const CTGitPath* pPath, CString rev1, bool bIsAdd, int ju return 0; } -int CGitDiff::SubmoduleDiff(const CTGitPath* pPath, const CTGitPath* /*pPath2*/, const CString& rev1, const CString& rev2, bool /*blame*/, bool /*unified*/) +int CGitDiff::SubmoduleDiff(HWND hWnd, const CTGitPath* pPath, const CTGitPath* /*pPath2*/, const CString& rev1, const CString& rev2, bool /*blame*/, bool /*unified*/) { CString oldhash; CString newhash; @@ -177,7 +178,7 @@ int CGitDiff::SubmoduleDiff(const CTGitPath* pPath, const CTGitPath* /*pPath2*/, CString output, err; if (g_Git.Run(cmd, &output, &err, CP_UTF8)) { - CMessageBox::Show(nullptr, output + L'\n' + err, L"TortoiseGit", MB_OK | MB_ICONERROR); + CMessageBox::Show(hWnd, output + L'\n' + err, L"TortoiseGit", MB_OK | MB_ICONERROR); return -1; } @@ -189,16 +190,16 @@ int CGitDiff::SubmoduleDiff(const CTGitPath* pPath, const CTGitPath* /*pPath2*/, cmd.Format(L"git.exe diff -- \"%s\"", (LPCTSTR)pPath->GetGitPathString()); if (g_Git.Run(cmd, &output, &err, CP_UTF8)) { - CMessageBox::Show(nullptr, output + L'\n' + err, L"TortoiseGit", MB_OK | MB_ICONERROR); + CMessageBox::Show(hWnd, output + L'\n' + err, L"TortoiseGit", MB_OK | MB_ICONERROR); return -1; } if (output.IsEmpty()) { - CMessageBox::Show(nullptr, IDS_ERR_EMPTYDIFF, IDS_APPNAME, MB_OK | MB_ICONERROR); + CMessageBox::Show(hWnd, IDS_ERR_EMPTYDIFF, IDS_APPNAME, MB_OK | MB_ICONERROR); return -1; } - else if (CMessageBox::Show(nullptr, IDS_SUBMODULE_EMPTYDIFF, IDS_APPNAME, 1, IDI_QUESTION, IDS_MSGBOX_YES, IDS_MSGBOX_NO) == 1) + else if (CMessageBox::Show(hWnd, IDS_SUBMODULE_EMPTYDIFF, IDS_APPNAME, 1, IDI_QUESTION, IDS_MSGBOX_YES, IDS_MSGBOX_NO) == 1) { CString sCmd; sCmd.Format(L"/command:subupdate /bkpath:\"%s\"", (LPCTSTR)g_Git.m_CurrentDir); @@ -211,7 +212,7 @@ int CGitDiff::SubmoduleDiff(const CTGitPath* pPath, const CTGitPath* /*pPath2*/, int oldstart = output.Find(L"-Subproject commit", start); if(oldstart<0) { - CMessageBox::Show(nullptr, L"Subproject Diff Format error", L"TortoiseGit", MB_OK | MB_ICONERROR); + CMessageBox::Show(hWnd, L"Subproject Diff Format error", L"TortoiseGit", MB_OK | MB_ICONERROR); return -1; } oldhash = output.Mid(oldstart + (int)wcslen(L"-Subproject commit") + 1, GIT_HASH_SIZE * 2); @@ -219,7 +220,7 @@ int CGitDiff::SubmoduleDiff(const CTGitPath* pPath, const CTGitPath* /*pPath2*/, int newstart = output.Find(L"+Subproject commit",start); if (newstart < 0) { - CMessageBox::Show(nullptr, L"Subproject Diff Format error", L"TortoiseGit", MB_OK | MB_ICONERROR); + CMessageBox::Show(hWnd, L"Subproject Diff Format error", L"TortoiseGit", MB_OK | MB_ICONERROR); return -1; } newhash = output.Mid(newstart + (int)wcslen(L"+Subproject commit") + 1, GIT_HASH_SIZE * 2); @@ -235,13 +236,13 @@ int CGitDiff::SubmoduleDiff(const CTGitPath* pPath, const CTGitPath* /*pPath2*/, { CString err; CGit::StringAppend(&err, &errBytes[0], CP_UTF8); - CMessageBox::Show(nullptr, err, L"TortoiseGit", MB_OK | MB_ICONERROR); + CMessageBox::Show(hWnd, err, L"TortoiseGit", MB_OK | MB_ICONERROR); return -1; } if (bytes.size() < 15 + 2 * GIT_HASH_SIZE + 1 + 2 * GIT_HASH_SIZE) { - CMessageBox::Show(nullptr, L"git diff-tree gives invalid output", L"TortoiseGit", MB_OK | MB_ICONERROR); + CMessageBox::Show(hWnd, L"git diff-tree gives invalid output", L"TortoiseGit", MB_OK | MB_ICONERROR); return -1; } CGit::StringAppend(&oldhash, &bytes[15], CP_UTF8, 2 * GIT_HASH_SIZE); @@ -260,7 +261,7 @@ int CGitDiff::SubmoduleDiff(const CTGitPath* pPath, const CTGitPath* /*pPath2*/, if (pPath->HasAdminDir()) GetSubmoduleChangeType(subgit, oldhash, newhash, oldOK, newOK, changeType, oldsub, newsub); - CSubmoduleDiffDlg submoduleDiffDlg; + CSubmoduleDiffDlg submoduleDiffDlg(GetExplorerHWND() == hWnd ? nullptr : CWnd::FromHandle(hWnd)); submoduleDiffDlg.SetDiff(pPath->GetWinPath(), isWorkingCopy, oldhash, oldsub, oldOK, newhash, newsub, newOK, dirty, changeType); submoduleDiffDlg.DoModal(); if (submoduleDiffDlg.IsRefresh()) @@ -342,7 +343,7 @@ void CGitDiff::GetSubmoduleChangeType(CGit& subgit, const CGitHash& oldhash, con changeType = Unknown; } -int CGitDiff::Diff(const CTGitPath* pPath, const CTGitPath* pPath2, CString rev1, CString rev2, bool /*blame*/, bool /*unified*/, int jumpToLine, bool bAlternativeTool, bool mustExist) +int CGitDiff::Diff(HWND hWnd, const CTGitPath* pPath, const CTGitPath* pPath2, CString rev1, CString rev2, bool /*blame*/, bool /*unified*/, int jumpToLine, bool bAlternativeTool, bool mustExist) { // make sure we have HASHes here, otherwise filenames might be invalid if (rev1 != GIT_REV_ZERO) @@ -350,7 +351,7 @@ int CGitDiff::Diff(const CTGitPath* pPath, const CTGitPath* pPath2, CString rev1 CGitHash rev1Hash; if (g_Git.GetHash(rev1Hash, rev1)) { - MessageBox(nullptr, g_Git.GetGitLastErr(L"Could not get hash of \"" + rev1 + L"\"."), L"TortoiseGit", MB_ICONERROR); + MessageBox(hWnd, g_Git.GetGitLastErr(L"Could not get hash of \"" + rev1 + L"\"."), L"TortoiseGit", MB_ICONERROR); return -1; } rev1 = rev1Hash.ToString(); @@ -360,7 +361,7 @@ int CGitDiff::Diff(const CTGitPath* pPath, const CTGitPath* pPath2, CString rev1 CGitHash rev2Hash; if (g_Git.GetHash(rev2Hash, rev2)) { - MessageBox(nullptr, g_Git.GetGitLastErr(L"Could not get hash of \"" + rev2 + L"\"."), L"TortoiseGit", MB_ICONERROR); + MessageBox(hWnd, g_Git.GetGitLastErr(L"Could not get hash of \"" + rev2 + L"\"."), L"TortoiseGit", MB_ICONERROR); return -1; } rev2 = rev2Hash.ToString(); @@ -376,7 +377,7 @@ int CGitDiff::Diff(const CTGitPath* pPath, const CTGitPath* pPath2, CString rev1 // refresh if result = 1 CTGitPath path = *pPath; CTGitPath path2 = *pPath2; - while ((result = SubmoduleDiff(&path, &path2, rev1, rev2)) == 1) + while ((result = SubmoduleDiff(hWnd, &path, &path2, rev1, rev2)) == 1) { path.SetFromGit(pPath->GetGitPathString()); path2.SetFromGit(pPath2->GetGitPathString()); @@ -394,7 +395,7 @@ int CGitDiff::Diff(const CTGitPath* pPath, const CTGitPath* pPath2, CString rev1 { CString out; out.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED, (LPCTSTR)pPath->GetGitPathString(), (LPCTSTR)rev1, (LPCTSTR)file1); - CMessageBox::Show(nullptr, g_Git.GetGitLastErr(out, CGit::GIT_CMD_GETONEFILE), L"TortoiseGit", MB_OK); + CMessageBox::Show(hWnd, g_Git.GetGitLastErr(out, CGit::GIT_CMD_GETONEFILE), L"TortoiseGit", MB_OK); return -1; } ::SetFileAttributes(file1, FILE_ATTRIBUTE_READONLY); @@ -407,7 +408,7 @@ int CGitDiff::Diff(const CTGitPath* pPath, const CTGitPath* pPath2, CString rev1 { CString sMsg; sMsg.Format(IDS_PROC_DIFFERROR_FILENOTINWORKINGTREE, (LPCTSTR)file1); - if (MessageBox(nullptr, sMsg, L"TortoiseGit", MB_ICONEXCLAMATION | MB_YESNO) != IDYES) + if (MessageBox(hWnd, sMsg, L"TortoiseGit", MB_ICONEXCLAMATION | MB_YESNO) != IDYES) return 1; if (!CCommonAppUtils::FileOpenSave(file1, nullptr, IDS_SELECTFILE, IDS_COMMONFILEFILTER, true)) return 1; @@ -430,7 +431,7 @@ int CGitDiff::Diff(const CTGitPath* pPath, const CTGitPath* pPath2, CString rev1 { CString out; out.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED, (LPCTSTR)pPath2->GetGitPathString(), (LPCTSTR)rev2, (LPCTSTR)file2); - CMessageBox::Show(nullptr, g_Git.GetGitLastErr(out, CGit::GIT_CMD_GETONEFILE), L"TortoiseGit", MB_OK); + CMessageBox::Show(hWnd, g_Git.GetGitLastErr(out, CGit::GIT_CMD_GETONEFILE), L"TortoiseGit", MB_OK); return -1; } ::SetFileAttributes(file2, FILE_ATTRIBUTE_READONLY); @@ -455,50 +456,50 @@ int CGitDiff::Diff(const CTGitPath* pPath, const CTGitPath* pPath2, CString rev1 return 0; } -int CGitDiff::DiffCommit(const CTGitPath& path, const GitRev* r1, const GitRev* r2, bool bAlternative) +int CGitDiff::DiffCommit(HWND hWnd, const CTGitPath& path, const GitRev* r1, const GitRev* r2, bool bAlternative) { - return DiffCommit(path, path, r1, r2, bAlternative); + return DiffCommit(hWnd, path, path, r1, r2, bAlternative); } -int CGitDiff::DiffCommit(const CTGitPath& path1, const CTGitPath& path2, const GitRev* r1, const GitRev* r2, bool bAlternative) +int CGitDiff::DiffCommit(HWND hWnd, const CTGitPath& path1, const CTGitPath& path2, const GitRev* r1, const GitRev* r2, bool bAlternative) { if (path1.GetWinPathString().IsEmpty()) { - CFileDiffDlg dlg; + CFileDiffDlg dlg(GetExplorerHWND() == hWnd ? nullptr : CWnd::FromHandle(hWnd)); dlg.SetDiff(nullptr, *r2, *r1); dlg.DoModal(); } else if (path1.IsDirectory()) { - CFileDiffDlg dlg; + CFileDiffDlg dlg(GetExplorerHWND() == hWnd ? nullptr : CWnd::FromHandle(hWnd)); dlg.SetDiff(&path1, *r2, *r1); dlg.DoModal(); } else - Diff(&path1, &path2, r1->m_CommitHash.ToString(), r2->m_CommitHash.ToString(), false, false, 0, bAlternative); + Diff(hWnd, &path1, &path2, r1->m_CommitHash.ToString(), r2->m_CommitHash.ToString(), false, false, 0, bAlternative); return 0; } -int CGitDiff::DiffCommit(const CTGitPath& path, const CString& r1, const CString& r2, bool bAlternative) +int CGitDiff::DiffCommit(HWND hWnd, const CTGitPath& path, const CString& r1, const CString& r2, bool bAlternative) { - return DiffCommit(path, path, r1, r2, bAlternative); + return DiffCommit(hWnd, path, path, r1, r2, bAlternative); } -int CGitDiff::DiffCommit(const CTGitPath& path1, const CTGitPath& path2, const CString& r1, const CString& r2, bool bAlternative) +int CGitDiff::DiffCommit(HWND hWnd, const CTGitPath& path1, const CTGitPath& path2, const CString& r1, const CString& r2, bool bAlternative) { if (path1.GetWinPathString().IsEmpty()) { - CFileDiffDlg dlg; + CFileDiffDlg dlg(GetExplorerHWND() == hWnd ? nullptr : CWnd::FromHandle(hWnd)); dlg.SetDiff(nullptr, r2, r1); dlg.DoModal(); } else if (path1.IsDirectory()) { - CFileDiffDlg dlg; + CFileDiffDlg dlg(GetExplorerHWND() == hWnd ? nullptr : CWnd::FromHandle(hWnd)); dlg.SetDiff(&path1, r2, r1); dlg.DoModal(); } else - Diff(&path1, &path2, r1, r2, false, false, 0, bAlternative); + Diff(hWnd, &path1, &path2, r1, r2, false, false, 0, bAlternative); return 0; } diff --git a/src/TortoiseProc/GitDiff.h b/src/TortoiseProc/GitDiff.h index 624895181..3cee7371d 100644 --- a/src/TortoiseProc/GitDiff.h +++ b/src/TortoiseProc/GitDiff.h @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2008-2014, 2016-2017 - TortoiseGit +// Copyright (C) 2008-2014, 2016-2018 - TortoiseGit // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -43,12 +43,12 @@ public: static void GetSubmoduleChangeType(CGit& subgit, const CGitHash& oldhash, const CGitHash& newhash, bool& oldOK, bool& newOK, ChangeType& changeType, CString& oldsub, CString& newsub); // Use two path to handle rename cases - static int Diff(const CTGitPath* pPath1, const CTGitPath* pPath2, CString rev1, CString rev2, bool blame = false, bool unified = false, int jumpToLine = 0, bool bAlternativeTool = false, bool mustExist = true); - static int SubmoduleDiff(const CTGitPath* pPath1, const CTGitPath* pPath2, const CString& rev1, const CString& rev2, bool blame = false, bool unified = false); - static int DiffNull(const CTGitPath* pPath, CString rev1, bool bIsAdd = true, int jumpToLine = 0, bool bAlternative = false); - static int DiffCommit(const CTGitPath& path, const GitRev* r1, const GitRev* r2, bool bAlternative = false); - static int DiffCommit(const CTGitPath& path1, const CTGitPath& path2, const GitRev* r1, const GitRev* r2, bool bAlternative = false); - static int DiffCommit(const CTGitPath& path, const CString& r1, const CString& r2, bool bAlternative = false); - static int DiffCommit(const CTGitPath& path1, const CTGitPath& path2, const CString& r1, const CString& r2, bool bAlternative = false); - static int SubmoduleDiffNull(const CTGitPath* pPath1, const CString& rev1); + static int Diff(HWND hWnd, const CTGitPath* pPath1, const CTGitPath* pPath2, CString rev1, CString rev2, bool blame = false, bool unified = false, int jumpToLine = 0, bool bAlternativeTool = false, bool mustExist = true); + static int SubmoduleDiff(HWND hWnd, const CTGitPath* pPath1, const CTGitPath* pPath2, const CString& rev1, const CString& rev2, bool blame = false, bool unified = false); + static int DiffNull(HWND hWnd, const CTGitPath* pPath, CString rev1, bool bIsAdd = true, int jumpToLine = 0, bool bAlternative = false); + static int DiffCommit(HWND hWnd, const CTGitPath& path, const GitRev* r1, const GitRev* r2, bool bAlternative = false); + static int DiffCommit(HWND hWnd, const CTGitPath& path1, const CTGitPath& path2, const GitRev* r1, const GitRev* r2, bool bAlternative = false); + static int DiffCommit(HWND hWnd, const CTGitPath& path, const CString& r1, const CString& r2, bool bAlternative = false); + static int DiffCommit(HWND hWnd, const CTGitPath& path1, const CTGitPath& path2, const CString& r1, const CString& r2, bool bAlternative = false); + static int SubmoduleDiffNull(HWND hWnd, const CTGitPath* pPath1, const CString& rev1); }; diff --git a/src/TortoiseProc/GitLogListAction.cpp b/src/TortoiseProc/GitLogListAction.cpp index a7a729361..456b8a2b4 100644 --- a/src/TortoiseProc/GitLogListAction.cpp +++ b/src/TortoiseProc/GitLogListAction.cpp @@ -287,7 +287,7 @@ void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMe GitRev* r1 = m_arShownList.SafeGetAt(FirstSelect); GitRev* r2 = m_arShownList.SafeGetAt(LastSelect); if (m_Path.IsDirectory() || !(m_ShowMask & CGit::LOG_INFO_FOLLOW)) - CGitDiff::DiffCommit(m_Path, r1, r2, bShiftPressed); + CGitDiff::DiffCommit(GetParentHWND(), m_Path, r1, r2, bShiftPressed); else { CString path1 = m_Path.GetGitPathString(); @@ -309,7 +309,7 @@ void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMe if (file && !file->GetGitOldPathString().IsEmpty()) path2 = file->GetGitOldPathString(); } - CGitDiff::DiffCommit(CTGitPath(path1), CTGitPath(path2), r1, r2, bShiftPressed); + CGitDiff::DiffCommit(GetParentHWND(), CTGitPath(path1), CTGitPath(path2), r1, r2, bShiftPressed); } } @@ -321,7 +321,7 @@ void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMe GitRevLoglist* r2 = pSelLogEntry; if (m_Path.IsDirectory() || !(m_ShowMask & CGit::LOG_INFO_FOLLOW)) - CGitDiff::DiffCommit(m_Path, r1, r2, bShiftPressed); + CGitDiff::DiffCommit(GetParentHWND(), m_Path, r1, r2, bShiftPressed); else { CString path1 = m_Path.GetGitPathString(); @@ -334,7 +334,7 @@ void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMe if (file && !file->GetGitOldPathString().IsEmpty()) path1 = file->GetGitOldPathString(); } - CGitDiff::DiffCommit(m_Path, CTGitPath(path1), r1, r2, bShiftPressed); + CGitDiff::DiffCommit(GetParentHWND(), m_Path, CTGitPath(path1), r1, r2, bShiftPressed); } //user clicked on the menu item "compare with working copy" @@ -368,7 +368,7 @@ void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMe cmd=1; if (m_Path.IsDirectory() || !(m_ShowMask & CGit::LOG_INFO_FOLLOW)) - CGitDiff::DiffCommit(m_Path, pSelLogEntry->m_CommitHash.ToString(), pSelLogEntry->m_ParentHash[cmd - 1].ToString(), bShiftPressed); + CGitDiff::DiffCommit(GetParentHWND(), m_Path, pSelLogEntry->m_CommitHash.ToString(), pSelLogEntry->m_ParentHash[cmd - 1].ToString(), bShiftPressed); else { CString path1 = m_Path.GetGitPathString(); @@ -388,7 +388,7 @@ void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMe if (file && !file->GetGitOldPathString().IsEmpty()) path2 = file->GetGitOldPathString(); - CGitDiff::DiffCommit(CTGitPath(path1), CTGitPath(path2), pSelLogEntry->m_CommitHash.ToString(), pSelLogEntry->m_ParentHash[cmd - 1].ToString(), bShiftPressed); + CGitDiff::DiffCommit(GetParentHWND(), CTGitPath(path1), CTGitPath(path2), pSelLogEntry->m_CommitHash.ToString(), pSelLogEntry->m_ParentHash[cmd - 1].ToString(), bShiftPressed); } } else diff --git a/src/TortoiseProc/RepositoryBrowser.cpp b/src/TortoiseProc/RepositoryBrowser.cpp index fc7f00ad2..618edb681 100644 --- a/src/TortoiseProc/RepositoryBrowser.cpp +++ b/src/TortoiseProc/RepositoryBrowser.cpp @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2009-2017 - TortoiseGit +// Copyright (C) 2009-2018 - TortoiseGit // Copyright (C) 2003-2013 - TortoiseSVN // This program is free software; you can redistribute it and/or @@ -854,7 +854,7 @@ void CRepositoryBrowser::ShowContextMenu(CPoint point, TShadowFilesTreeList &sel case eCmd_CompareWC: { CTGitPath file(selectedLeafs.at(0)->GetFullName()); - CGitDiff::Diff(&file, &file, GIT_REV_ZERO, m_sRevision); + CGitDiff::Diff(GetSafeHwnd(), &file, &file, GIT_REV_ZERO, m_sRevision); } break; case eCmd_Revert: @@ -908,7 +908,7 @@ void CRepositoryBrowser::ShowContextMenu(CPoint point, TShadowFilesTreeList &sel MessageBox(g_Git.GetGitLastErr(L"Could not get SHA-1 for " + m_sRevision), L"TortoiseGit", MB_ICONERROR); return; } - CGitDiff::Diff(&selectedFile, &savedFile, currentHash, m_sMarkForDiffVersion); + CGitDiff::Diff(GetSafeHwnd(), &selectedFile, &savedFile, currentHash, m_sMarkForDiffVersion); } break; } -- 2.11.4.GIT