From 133f692ee7e203abbf4649903c6691a0a9ff23c2 Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Sun, 22 Jan 2017 20:52:42 +0100 Subject: [PATCH] Fixed issue #2082: RebaseDlg: Reorder commits via drag'n'drop Signed-off-by: Sven Strickroth --- src/Changelog.txt | 1 + src/TortoiseProc/GitLogListBase.cpp | 118 +++++++++++++++++++++++++++++++++++- src/TortoiseProc/GitLogListBase.h | 16 ++++- src/TortoiseProc/RebaseDlg.cpp | 38 +++++++++++- src/TortoiseProc/RebaseDlg.h | 3 +- 5 files changed, 172 insertions(+), 4 deletions(-) diff --git a/src/Changelog.txt b/src/Changelog.txt index 40ce0e09c..61fdf6b74 100644 --- a/src/Changelog.txt +++ b/src/Changelog.txt @@ -42,6 +42,7 @@ Released: unreleased * Enable/disable check boxes for bugtraq plugins * Fixed issue #2283: Improve symbols for "Symbolize ref names" * Fixed issue #2746: SubWCRev equivalent required: GitWCRev added + * Fixed issue #2082: RebaseDlg: Reorder commits via drag'n'drop == Bug Fixes == * Fixed issue #2837: Layout of overlapping icons settings dialog diff --git a/src/TortoiseProc/GitLogListBase.cpp b/src/TortoiseProc/GitLogListBase.cpp index 78134f144..a014c8a9c 100644 --- a/src/TortoiseProc/GitLogListBase.cpp +++ b/src/TortoiseProc/GitLogListBase.cpp @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2008-2016 - TortoiseGit +// Copyright (C) 2008-2017 - TortoiseGit // Copyright (C) 2005-2007 Marco Costalba // This program is free software; you can redistribute it and/or @@ -88,6 +88,11 @@ CGitLogListBase::CGitLogListBase() : CHintCtrl= first && m_nDropIndex - 1 <= last)) + { + SetCursor(LoadCursor(nullptr, IDC_NO)); + m_nDropIndex = -1; + } + DrawDropInsertMarker(m_nDropIndex); +} + +void CGitLogListBase::OnLButtonUp(UINT nFlags, CPoint point) +{ + if (m_bDragging) + { + ::ReleaseCapture(); + SetCursor(LoadCursor(nullptr, IDC_HAND)); + m_bDragging = FALSE; + + CRect rect; + GetItemRect(m_nDropMarkerLast, &rect, 0); + rect.bottom = rect.top + 2; + rect.top -= 2; + InvalidateRect(&rect, 0); + + CPoint pt(point); + ClientToScreen(&pt); + if (WindowFromPoint(pt) == this && m_nDropIndex != -1) + GetParent()->PostMessage(MSG_COMMITS_REORDERED, m_nDropIndex, 0); + } + + __super::OnLButtonUp(nFlags, point); +} + +void CGitLogListBase::DrawDropInsertMarker(int nIndex) +{ + if (m_nDropMarkerLast != nIndex) + { + CRect rect; + GetItemRect(m_nDropMarkerLast, &rect, 0); + rect.bottom = rect.top + 2; + rect.top -= 2; + InvalidateRect(&rect, 0); + m_nDropMarkerLast = nIndex; + + if (nIndex < 0) + return; + + CBrush* pBrush = CDC::GetHalftoneBrush(); + CDC* pDC = GetDC(); + + GetItemRect(nIndex, &rect, 0); + rect.bottom = rect.top + 2; + rect.top -= 2; + + CBrush* pBrushOld = pDC->SelectObject(pBrush); + pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), PATINVERT); + pDC->SelectObject(pBrushOld); + + ReleaseDC(pDC); + } + else if (m_nDropMarkerLastHot != GetHotItem()) + { + m_nDropMarkerLastHot = GetHotItem(); + m_nDropMarkerLast = -1; + } +} diff --git a/src/TortoiseProc/GitLogListBase.h b/src/TortoiseProc/GitLogListBase.h index 92e98c816..0c60fee0e 100644 --- a/src/TortoiseProc/GitLogListBase.h +++ b/src/TortoiseProc/GitLogListBase.h @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2008-2016 - TortoiseGit +// Copyright (C) 2008-2017 - TortoiseGit // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -71,6 +71,7 @@ #define MSG_LOAD_PERCENTAGE (WM_USER+111) #define MSG_REFLOG_CHANGED (WM_USER+112) #define MSG_FETCHED_DIFF (WM_USER+113) +#define MSG_COMMITS_REORDERED (WM_USER+114) class SelectionHistory { @@ -742,4 +743,17 @@ protected: int m_OldTopIndex; GIT_MAILMAP m_pMailmap; + + bool m_bDragndropEnabled; + BOOL m_bDragging; + int m_nDropIndex; + int m_nDropMarkerLast; + int m_nDropMarkerLastHot; + afx_msg void OnMouseMove(UINT nFlags, CPoint point); + afx_msg void OnLButtonUp(UINT nFlags, CPoint point); + afx_msg void OnBeginDrag(NMHDR* pNMHDR, LRESULT* pResult); + void DrawDropInsertMarker(int nIndex); + +public: + void EnableDragnDrop(bool enable) { m_bDragndropEnabled = enable; } }; diff --git a/src/TortoiseProc/RebaseDlg.cpp b/src/TortoiseProc/RebaseDlg.cpp index fae6dd219..b9fc2f3c4 100644 --- a/src/TortoiseProc/RebaseDlg.cpp +++ b/src/TortoiseProc/RebaseDlg.cpp @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2008-2016 - TortoiseGit +// Copyright (C) 2008-2017 - TortoiseGit // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -113,6 +113,7 @@ BEGIN_MESSAGE_MAP(CRebaseDlg, CResizableStandAloneDialog) ON_BN_CLICKED(IDC_BUTTON_ONTO, &CRebaseDlg::OnBnClickedButtonOnto) ON_BN_CLICKED(IDHELP, OnHelp) ON_BN_CLICKED(IDC_BUTTON_ADD, &CRebaseDlg::OnBnClickedButtonAdd) + ON_MESSAGE(MSG_COMMITS_REORDERED, OnCommitsReordered) END_MESSAGE_MAP() void CRebaseDlg::CleanUpRebaseActiveFolder() @@ -1673,6 +1674,7 @@ void CRebaseDlg::SetControlEnable() this->GetDlgItem(IDC_BUTTON_UP)->EnableWindow(TRUE); this->GetDlgItem(IDC_BUTTON_DOWN)->EnableWindow(TRUE); this->GetDlgItem(IDC_BUTTON_ADD)->EnableWindow(!m_bPreserveMerges); + m_CommitList.EnableDragnDrop(true); if(!m_IsCherryPick) { @@ -1706,6 +1708,7 @@ void CRebaseDlg::SetControlEnable() this->GetDlgItem(IDC_REBASE_CHECK_PRESERVEMERGES)->EnableWindow(FALSE); this->GetDlgItem(IDC_BUTTON_UP)->EnableWindow(FALSE); this->GetDlgItem(IDC_BUTTON_DOWN)->EnableWindow(FALSE); + m_CommitList.EnableDragnDrop(false); this->GetDlgItem(IDC_BUTTON_ADD)->EnableWindow(FALSE); if( m_RebaseStage == REBASE_DONE && (this->m_PostButtonTexts.GetCount() != 0) ) @@ -2576,6 +2579,39 @@ void CRebaseDlg::OnBnClickedButtonDown() } } +LRESULT CRebaseDlg::OnCommitsReordered(WPARAM wParam, LPARAM /*lParam*/) +{ + POSITION pos = m_CommitList.GetFirstSelectedItemPosition(); + int first = m_CommitList.GetNextSelectedItem(pos); + int last = first; + while (pos) + last = m_CommitList.GetNextSelectedItem(pos); + ++last; + + for (int i = first; i < last; ++i) + m_CommitList.SetItemState(i, 0, LVIS_SELECTED); + + int dest = (int)wParam; + if (dest > first) + { + std::rotate(m_CommitList.m_logEntries.begin() + first, m_CommitList.m_logEntries.begin() + last, m_CommitList.m_logEntries.begin() + dest); + m_CommitList.RecalculateShownList(&m_CommitList.m_arShownList); + for (int i = first + dest - last; i < dest; ++i) + m_CommitList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED); + } + else + { + std::rotate(m_CommitList.m_logEntries.begin() + dest, m_CommitList.m_logEntries.begin() + first, m_CommitList.m_logEntries.begin() + last); + m_CommitList.RecalculateShownList(&m_CommitList.m_arShownList); + for (int i = dest; i < dest + (last - first); ++i) + m_CommitList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED); + } + + m_CommitList.Invalidate(); + + return 0; +} + LRESULT CRebaseDlg::OnTaskbarBtnCreated(WPARAM wParam, LPARAM lParam) { m_pTaskbarList.Release(); diff --git a/src/TortoiseProc/RebaseDlg.h b/src/TortoiseProc/RebaseDlg.h index 3f87ec1c1..1afec863f 100644 --- a/src/TortoiseProc/RebaseDlg.h +++ b/src/TortoiseProc/RebaseDlg.h @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2008-2016 - TortoiseGit +// Copyright (C) 2008-2017 - TortoiseGit // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -265,6 +265,7 @@ protected: CComPtr m_pTaskbarList; afx_msg LRESULT OnRebaseActionMessage(WPARAM wParam, LPARAM lParam); + afx_msg LRESULT OnCommitsReordered(WPARAM wParam, LPARAM lParam); afx_msg void OnBnClickedRebaseSplitCommit(); afx_msg void OnBnClickedButtonOnto(); afx_msg void OnBnClickedButtonAdd(); -- 2.11.4.GIT