From a647def6f3bf080841c59ac8c40574ae87d23e25 Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Sat, 23 Jul 2016 23:53:39 +0200 Subject: [PATCH] Refactor out CResizableColumnsListCtrl (fixes issue #2799: Column sizes in "Browse references" dialog are not remembered) Signed-off-by: Sven Strickroth --- src/Changelog.txt | 1 + src/Git/GitStatusListCtrl.cpp | 107 +++------------------- src/Git/GitStatusListCtrl.h | 15 +--- src/TortoiseProc/BrowseRefsDlg.cpp | 24 ++--- src/TortoiseProc/BrowseRefsDlg.h | 6 +- src/TortoiseProc/GitLogListBase.cpp | 60 +++---------- src/TortoiseProc/GitLogListBase.h | 9 +- src/TortoiseProc/ResizableColumnsListCtrl.h | 124 ++++++++++++++++++++++++++ src/TortoiseProc/TortoiseProc.vcxproj | 1 + src/TortoiseProc/TortoiseProc.vcxproj.filters | 3 + 10 files changed, 165 insertions(+), 185 deletions(-) create mode 100644 src/TortoiseProc/ResizableColumnsListCtrl.h diff --git a/src/Changelog.txt b/src/Changelog.txt index a32d453cd..319ac53bf 100644 --- a/src/Changelog.txt +++ b/src/Changelog.txt @@ -11,6 +11,7 @@ Released: unreleased * Fixed issue #2798: Commit message autocompletion doesn't work with UTF-8 encoded files * Fixed issue #2797: RebaseDlg: Make branch selectors adjust with resized dialog * Autocompletion of filenames with umlauts in the commit dialog did not work + * Fixed issue #2799: Column sizes in "Browse references" dialog are not remembered = Release 2.2.0 = Released: 2016-07-02 diff --git a/src/Git/GitStatusListCtrl.cpp b/src/Git/GitStatusListCtrl.cpp index d7e212ba8..3fce65f4b 100644 --- a/src/Git/GitStatusListCtrl.cpp +++ b/src/Git/GitStatusListCtrl.cpp @@ -193,12 +193,9 @@ HRESULT CALLBACK dfmCallback(IShellFolder * /*psf*/, HWND /*hwnd*/, IDataObject return E_NOTIMPL; } -BEGIN_MESSAGE_MAP(CGitStatusListCtrl, CListCtrl) +BEGIN_MESSAGE_MAP(CGitStatusListCtrl, CResizableColumnsListCtrl) ON_NOTIFY(HDN_ITEMCLICKA, 0, OnHdnItemclick) ON_NOTIFY(HDN_ITEMCLICKW, 0, OnHdnItemclick) - ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized) - ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved) - ON_NOTIFY(HDN_DIVIDERDBLCLICK, 0, OnHeaderDblClick) ON_NOTIFY_REFLECT_EX(LVN_ITEMCHANGED, OnLvnItemchanged) ON_WM_CONTEXTMENU() ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclk) @@ -209,18 +206,11 @@ BEGIN_MESSAGE_MAP(CGitStatusListCtrl, CListCtrl) ON_NOTIFY_REFLECT(NM_RETURN, OnNMReturn) ON_WM_KEYDOWN() ON_WM_PAINT() - ON_NOTIFY(HDN_BEGINTRACKA, 0, &CGitStatusListCtrl::OnHdnBegintrack) - ON_NOTIFY(HDN_BEGINTRACKW, 0, &CGitStatusListCtrl::OnHdnBegintrack) - ON_NOTIFY(HDN_ITEMCHANGINGA, 0, &CGitStatusListCtrl::OnHdnItemchanging) - ON_NOTIFY(HDN_ITEMCHANGINGW, 0, &CGitStatusListCtrl::OnHdnItemchanging) - ON_WM_DESTROY() ON_NOTIFY_REFLECT(LVN_BEGINDRAG, OnBeginDrag) ON_NOTIFY_REFLECT(LVN_ITEMCHANGING, &CGitStatusListCtrl::OnLvnItemchanging) END_MESSAGE_MAP() - - -CGitStatusListCtrl::CGitStatusListCtrl() : CListCtrl() +CGitStatusListCtrl::CGitStatusListCtrl() : CResizableColumnsListCtrl() //, m_HeadRev(GitRev::REV_HEAD) , m_pbCanceled(nullptr) , m_pStatLabel(nullptr) @@ -242,7 +232,6 @@ CGitStatusListCtrl::CGitStatusListCtrl() : CListCtrl() , m_bFileDropsEnabled(false) , m_bOwnDrag(false) , m_dwDefaultColumns(0) - , m_ColumnManager(this) , m_bAscending(false) , m_nSortedColumn(-1) , m_bHasExternalsFromDifferentRepos(false) @@ -318,14 +307,11 @@ void CGitStatusListCtrl::Init(DWORD dwColumns, const CString& sColumnInfoContain m_bHasWC = bHasWC; // set the extended style of the listcontrol - // the style LVS_EX_FULLROWSELECT interferes with the background watermark image but it's more important to be able to select in the whole row. - CRegDWORD regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE); - DWORD exStyle = LVS_EX_HEADERDRAGDROP | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES; - if (DWORD(regFullRowSelect)) - exStyle |= LVS_EX_FULLROWSELECT; + DWORD exStyle = LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES; exStyle |= (bHasCheckboxes ? LVS_EX_CHECKBOXES : 0); SetRedraw(false); SetExtendedStyle(exStyle); + CResizableColumnsListCtrl::Init(); SetWindowTheme(m_hWnd, L"Explorer", nullptr); @@ -680,9 +666,7 @@ void CGitStatusListCtrl::Show(unsigned int dwShow, unsigned int dwCheck /*=0*/, } } - int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1; - for (int col = 0; col <= maxcol; col++) - SetColumnWidth (col, m_ColumnManager.GetWidth (col, true)); + AdjustColumnWidths(); SetRedraw(TRUE); GetStatisticsString(); @@ -820,9 +804,7 @@ void CGitStatusListCtrl::Show(unsigned int dwShow, unsigned int dwCheck /*=0*/, m_ColumnManager.UpdateRelevance (m_arStatusArray, m_arListArray); - int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1; - for (int col = 0; col <= maxcol; col++) - SetColumnWidth (col, m_ColumnManager.GetWidth (col, true)); + AdjustColumnWidths(); SetRedraw(TRUE); GetStatisticsString(); @@ -872,9 +854,7 @@ void CGitStatusListCtrl::Show(unsigned int /*dwShow*/, const CTGitPathList& chec for (int i = 0; i < checkedList.GetCount(); ++i) this->AddEntry((CTGitPath *)&checkedList[i],0,i); - int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1; - for (int col = 0; col <= maxcol; col++) - SetColumnWidth (col, m_ColumnManager.GetWidth (col, true)); + AdjustColumnWidths(); return ; #if 0 @@ -960,9 +940,7 @@ void CGitStatusListCtrl::Show(unsigned int /*dwShow*/, const CTGitPathList& chec SetItemCount(listIndex); - int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1; - for (int col = 0; col <= maxcol; col++) - SetColumnWidth (col, m_ColumnManager.GetWidth (col, true)); + AdjustColumnWidths(); SetRedraw(TRUE); GetStatisticsString(); @@ -1233,27 +1211,6 @@ BOOL CGitStatusListCtrl::OnLvnItemchanged(NMHDR *pNMHDR, LRESULT *pResult) return FALSE; } -void CGitStatusListCtrl::OnHeaderDblClick(NMHDR* pNMHDR, LRESULT* pResult) -{ - m_ColumnManager.OnHeaderDblClick(pNMHDR, pResult); - - *pResult = FALSE; -} - -void CGitStatusListCtrl::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult) -{ - m_ColumnManager.OnColumnResized(pNMHDR,pResult); - - *pResult = FALSE; -} - -void CGitStatusListCtrl::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult) -{ - m_ColumnManager.OnColumnMoved(pNMHDR, pResult); - - Invalidate(FALSE); -} - void CGitStatusListCtrl::CheckEntry(int index, int /*nListItems*/) { Locker lock(m_critSec); @@ -2437,7 +2394,6 @@ void CGitStatusListCtrl::OnContextMenuList(CWnd * pWnd, CPoint point) } } SetRedraw(TRUE); - SaveColumnWidths(); #if 0 // revert an added file and some entry will be cloned (part 2/2) Show(m_dwShow, 0, m_bShowFolders,updateStatusList,true); NotifyCheck(); @@ -2628,20 +2584,11 @@ void CGitStatusListCtrl::SetGitIndexFlagsForSelectedFiles(UINT message, BOOL ass SetRedraw(TRUE); } -void CGitStatusListCtrl::OnContextMenuHeader(CWnd * pWnd, CPoint point) -{ - Locker lock(m_critSec); - m_ColumnManager.OnContextMenuHeader(pWnd,point,!!IsGroupViewEnabled()); -} - void CGitStatusListCtrl::OnContextMenu(CWnd* pWnd, CPoint point) { + __super::OnContextMenu(pWnd, point); if (pWnd == this) - { OnContextMenuList(pWnd, point); - } // if (pWnd == this) - else if (pWnd == GetHeaderCtrl()) - OnContextMenuHeader(pWnd, point); } void CGitStatusListCtrl::OnNMDblclk(NMHDR *pNMHDR, LRESULT *pResult) @@ -3274,7 +3221,7 @@ void CGitStatusListCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) void CGitStatusListCtrl::PreSubclassWindow() { - CListCtrl::PreSubclassWindow(); + __super::PreSubclassWindow(); EnableToolTips(TRUE); SetWindowTheme(GetSafeHwnd(), L"Explorer", nullptr); } @@ -3342,25 +3289,6 @@ void CGitStatusListCtrl::OnPaint() } } -// prevent users from extending our hidden (size 0) columns -void CGitStatusListCtrl::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult) -{ - m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult); -} - -// prevent any function from extending our hidden (size 0) columns -void CGitStatusListCtrl::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult) -{ - if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult)) - Default(); -} - -void CGitStatusListCtrl::OnDestroy() -{ - SaveColumnWidths(true); - CListCtrl::OnDestroy(); -} - void CGitStatusListCtrl::OnBeginDrag(NMHDR* pNMHDR, LRESULT* pResult) { LPNMLISTVIEW pNMLV = reinterpret_cast(pNMHDR); @@ -3414,17 +3342,6 @@ void CGitStatusListCtrl::OnBeginDrag(NMHDR* pNMHDR, LRESULT* pResult) *pResult = 0; } -void CGitStatusListCtrl::SaveColumnWidths(bool bSaveToRegistry /* = false */) -{ - int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1; - for (int col = 0; col <= maxcol; col++) - if (m_ColumnManager.IsVisible (col)) - m_ColumnManager.ColumnResized (col); - - if (bSaveToRegistry) - m_ColumnManager.WriteSettings(); -} - bool CGitStatusListCtrl::EnableFileDrop() { m_bFileDropsEnabled = true; @@ -3488,7 +3405,7 @@ BOOL CGitStatusListCtrl::PreTranslateMessage(MSG* pMsg) } } - return CListCtrl::PreTranslateMessage(pMsg); + return __super::PreTranslateMessage(pMsg); } bool CGitStatusListCtrl::CopySelectedEntriesToClipboard(DWORD dwCols) @@ -4477,5 +4394,5 @@ BOOL CGitStatusListCtrl::OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LR break; } - return CListCtrl::OnWndMsg(message, wParam, lParam, pResult); + return __super::OnWndMsg(message, wParam, lParam, pResult); } diff --git a/src/Git/GitStatusListCtrl.h b/src/Git/GitStatusListCtrl.h index 744e11a24..5ecaf1eba 100644 --- a/src/Git/GitStatusListCtrl.h +++ b/src/Git/GitStatusListCtrl.h @@ -22,7 +22,7 @@ #include "GitStatus.h" #include "GitRev.h" #include "Colors.h" -#include "ColumnManager.h" +#include "ResizableColumnsListCtrl.h" #define GIT_WC_ENTRY_WORKING_SIZE_UNKNOWN (-1) @@ -172,7 +172,7 @@ private: * work on. */ class CGitStatusListCtrl : - public CListCtrl + public CResizableColumnsListCtrl { public: enum @@ -683,7 +683,6 @@ public: } private: - void SaveColumnWidths(bool bSaveToRegistry = false); //void AddEntry(FileEntry * entry, WORD langID, int listIndex); ///< add an entry to the control void RemoveListEntry(int index); ///< removes an entry from the listcontrol and both arrays bool BuildStatistics(); ///< build the statistics and correct the case of files/folders @@ -746,7 +745,6 @@ private: void OnContextMenuList(CWnd * pWnd, CPoint point); void OnContextMenuGroup(CWnd * pWnd, CPoint point); - void OnContextMenuHeader(CWnd * pWnd, CPoint point); bool CheckMultipleDiffs(); void DeleteSelectedFiles(); @@ -759,9 +757,6 @@ private: afx_msg void OnHdnItemclick(NMHDR *pNMHDR, LRESULT *pResult); afx_msg void OnLvnItemchanging(NMHDR *pNMHDR, LRESULT *pResult); afx_msg BOOL OnLvnItemchanged(NMHDR *pNMHDR, LRESULT *pResult); - afx_msg void OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult); - afx_msg void OnHeaderDblClick(NMHDR* pNMHDR, LRESULT* pResult); - afx_msg void OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult); afx_msg void OnContextMenu(CWnd* pWnd, CPoint point); void CreateChangeList(const CString& name); @@ -774,10 +769,6 @@ private: afx_msg void OnNMReturn(NMHDR *pNMHDR, LRESULT *pResult); afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags); afx_msg void OnPaint(); - afx_msg void OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult); - afx_msg void OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult); - afx_msg void OnDestroy(); - void FilesExport(); void FileSaveAs(CTGitPath *path); @@ -859,8 +850,6 @@ private: bool m_bCheckChildrenWithParent; CGitStatusListCtrlDropTarget * m_pDropTarget; - ColumnManager m_ColumnManager; - std::map m_mapFilenameToChecked; ///< Remember de-/selected items std::map m_mapDirectFiles; CComCriticalSection m_critSec; diff --git a/src/TortoiseProc/BrowseRefsDlg.cpp b/src/TortoiseProc/BrowseRefsDlg.cpp index 2e2869299..7edb8f2e8 100644 --- a/src/TortoiseProc/BrowseRefsDlg.cpp +++ b/src/TortoiseProc/BrowseRefsDlg.cpp @@ -163,7 +163,6 @@ CBrowseRefsDlg::CBrowseRefsDlg(CString cmdPath, CWnd* pParent /*=nullptr*/) m_pListCtrlRoot(nullptr), m_bHasWC(true), m_SelectedFilters(LOGFILTER_ALL), - m_ColumnManager(&m_ListRefLeafs), m_bPickOne(false), m_bIncludeNestedRefs(TRUE), m_bPickedRefSet(false) @@ -285,17 +284,15 @@ BOOL CBrowseRefsDlg::OnInitDialog() AddAnchor(IDC_INCLUDENESTEDREFS, BOTTOM_LEFT); AddAnchor(IDHELP, BOTTOM_RIGHT); - CRegDWORD regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE); - DWORD exStyle = LVS_EX_INFOTIP; - if (DWORD(regFullRowSelect)) - exStyle |= LVS_EX_FULLROWSELECT; - m_ListRefLeafs.SetExtendedStyle(m_ListRefLeafs.GetExtendedStyle() | exStyle); + m_ListRefLeafs.SetExtendedStyle(m_ListRefLeafs.GetExtendedStyle() | LVS_EX_INFOTIP); static UINT columnNames[] = { IDS_BRANCHNAME, IDS_TRACKEDBRANCH, IDS_DATELASTCOMMIT, IDS_LASTCOMMIT, IDS_LASTAUTHOR, IDS_HASH, IDS_DESCRIPTION }; - static int columnWidths[] = { 150, 100, 100, 300, 100, 80, 80 }; + static int columnWidths[] = { 0, 0, 0, 300, 0, 0, 80 }; DWORD dwDefaultColumns = (1 << eCol_Name) | (1 << eCol_Upstream ) | (1 << eCol_Date) | (1 << eCol_Msg) | (1 << eCol_LastAuthor) | (1 << eCol_Hash) | (1 << eCol_Description); - m_ColumnManager.SetNames(columnNames, _countof(columnNames)); - m_ColumnManager.ReadSettings(dwDefaultColumns, 0, _T("BrowseRefs"), _countof(columnNames), columnWidths); + m_ListRefLeafs.m_bAllowHiding = false; + m_ListRefLeafs.Init(); + m_ListRefLeafs.m_ColumnManager.SetNames(columnNames, _countof(columnNames)); + m_ListRefLeafs.m_ColumnManager.ReadSettings(dwDefaultColumns, 0, _T("BrowseRefs"), _countof(columnNames), columnWidths); m_bPickedRefSet = false; AddAnchor(IDOK,BOTTOM_RIGHT); @@ -576,7 +573,8 @@ void CBrowseRefsDlg::FillListCtrlForTreeNode(HTREEITEM treeNode) return; } FillListCtrlForShadowTree(pTree,L"",true); - m_ColumnManager.SetVisible(eCol_Upstream, pTree->IsFrom(L"refs/heads")); + m_ListRefLeafs.m_ColumnManager.SetVisible(eCol_Upstream, pTree->IsFrom(L"refs/heads")); + m_ListRefLeafs.AdjustColumnWidths(); } void CBrowseRefsDlg::FillListCtrlForShadowTree(CShadowTree* pTree, CString refNamePrefix, bool isFirstLevel) @@ -1349,12 +1347,6 @@ void CBrowseRefsDlg::OnDestroy() if (!m_bPickedRefSet) m_pickedRef = GetSelectedRef(true, false); - int maxcol = m_ColumnManager.GetColumnCount(); - for (int col = 0; col < maxcol; ++col) - if (m_ColumnManager.IsVisible(col)) - m_ColumnManager.ColumnResized(col); - m_ColumnManager.WriteSettings(); - CResizableStandAloneDialog::OnDestroy(); } diff --git a/src/TortoiseProc/BrowseRefsDlg.h b/src/TortoiseProc/BrowseRefsDlg.h index 47638217d..5361aad3a 100644 --- a/src/TortoiseProc/BrowseRefsDlg.h +++ b/src/TortoiseProc/BrowseRefsDlg.h @@ -18,10 +18,9 @@ // #pragma once -#include #include "StandAloneDlg.h" #include "FilterEdit.h" -#include "GitStatusListCtrl.h" +#include "ResizableColumnsListCtrl.h" #include "gittype.h" const int gPickRef_Head = 1; @@ -180,8 +179,7 @@ private: CShadowTree m_TreeRoot; CShadowTree* m_pListCtrlRoot; CTreeCtrl m_RefTreeCtrl; - CListCtrl m_ListRefLeafs; - ColumnManager m_ColumnManager; + CResizableColumnsListCtrl m_ListRefLeafs; CFilterEdit m_ctrlFilter; afx_msg void OnEnChangeEditFilter(); diff --git a/src/TortoiseProc/GitLogListBase.cpp b/src/TortoiseProc/GitLogListBase.cpp index 5db937e11..b500405a2 100644 --- a/src/TortoiseProc/GitLogListBase.cpp +++ b/src/TortoiseProc/GitLogListBase.cpp @@ -55,9 +55,9 @@ const UINT CGitLogListBase::m_FindDialogMessage = RegisterWindowMessage(FINDMSGS const UINT CGitLogListBase::m_ScrollToMessage = RegisterWindowMessage(_T("TORTOISEGIT_LOG_SCROLLTO")); const UINT CGitLogListBase::m_RebaseActionMessage = RegisterWindowMessage(_T("TORTOISEGIT_LOG_REBASEACTION")); -IMPLEMENT_DYNAMIC(CGitLogListBase, CHintCtrl) +IMPLEMENT_DYNAMIC(CGitLogListBase, CHintCtrl>) -CGitLogListBase::CGitLogListBase() : CHintCtrl() +CGitLogListBase::CGitLogListBase() : CHintCtrl>() ,m_regMaxBugIDColWidth(_T("Software\\TortoiseGit\\MaxBugIDColWidth"), 200) ,m_nSearchIndex(0) ,m_bNoDispUpdates(FALSE) @@ -68,7 +68,6 @@ CGitLogListBase::CGitLogListBase() : CHintCtrl() , m_bShowWC(false) , m_logEntries(&m_LogCache) , m_pFindDialog(nullptr) - , m_ColumnManager(this) , m_dwDefaultColumns(0) , m_arShownList(&m_critSec) , m_hasWC(true) @@ -282,7 +281,7 @@ CGitLogListBase::~CGitLogListBase() } -BEGIN_MESSAGE_MAP(CGitLogListBase, CHintCtrl) +BEGIN_MESSAGE_MAP(CGitLogListBase, CHintCtrl>) ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage) ON_REGISTERED_MESSAGE(m_ScrollToMessage, OnScrollToMessage) ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdrawLoglist) @@ -295,12 +294,6 @@ BEGIN_MESSAGE_MAP(CGitLogListBase, CHintCtrl) ON_MESSAGE(MSG_LOADED,OnLoad) ON_WM_MEASUREITEM() ON_WM_MEASUREITEM_REFLECT() - ON_NOTIFY(HDN_BEGINTRACKA, 0, OnHdnBegintrack) - ON_NOTIFY(HDN_BEGINTRACKW, 0, OnHdnBegintrack) - ON_NOTIFY(HDN_ITEMCHANGINGA, 0, OnHdnItemchanging) - ON_NOTIFY(HDN_ITEMCHANGINGW, 0, OnHdnItemchanging) - ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized) - ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved) ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, &OnToolTipText) ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, &OnToolTipText) END_MESSAGE_MAP() @@ -344,11 +337,7 @@ void CGitLogListBase::InsertGitColumn() { CString temp; - CRegDWORD regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE); - DWORD exStyle = GetExtendedStyle() | LVS_EX_HEADERDRAGDROP; - if (DWORD(regFullRowSelect)) - exStyle |= LVS_EX_FULLROWSELECT; - SetExtendedStyle(exStyle); + Init(); // only load properties if we have a repository if (GitAdminDir::IsWorkingTreeOrBareRepo(g_Git.m_CurrentDir)) @@ -1658,8 +1647,10 @@ void CGitLogListBase::GetParentHashes(GitRev *pRev, GIT_REV_LIST &parentHash) void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point) { - if (pWnd == GetHeaderCtrl()) - return m_ColumnManager.OnContextMenuHeader(pWnd,point,!!IsGroupViewEnabled()); + __super::OnContextMenu(pWnd, point); + + if (pWnd != this) + return; int selIndex = GetSelectionMark(); if (selIndex < 0) @@ -3755,9 +3746,6 @@ void CGitLogListBase::Clear() void CGitLogListBase::OnDestroy() { - // save the column widths to the registry - SaveColumnWidths(); - SafeTerminateThread(); SafeTerminateAsyncDiffThread(); @@ -3793,16 +3781,10 @@ LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM /*lParam*/) */ void CGitLogListBase::SaveColumnWidths() { - int maxcol = m_ColumnManager.GetColumnCount(); - // HACK that graph column is always shown SetColumnWidth(0, m_ColumnManager.GetWidth(0, false)); - for (int col = 0; col < maxcol; ++col) - if (m_ColumnManager.IsVisible (col)) - m_ColumnManager.ColumnResized (col); - - m_ColumnManager.WriteSettings(); + __super::SaveColumnWidths(); } int CGitLogListBase::GetHeadIndex() @@ -3829,15 +3811,7 @@ void CGitLogListBase::OnFind() m_pFindDialog->Create(this); } } -void CGitLogListBase::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult) -{ - m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult); -} -void CGitLogListBase::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult) -{ - if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult)) - Default(); -} + LRESULT CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect, LPARAM /*lParam*/) { if (GetSelectedCount() != 0) @@ -4047,20 +4021,6 @@ LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam* return 0; } -void CGitLogListBase::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult) -{ - m_ColumnManager.OnColumnResized(pNMHDR,pResult); - - *pResult = FALSE; -} - -void CGitLogListBase::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult) -{ - m_ColumnManager.OnColumnMoved(pNMHDR, pResult); - - Invalidate(FALSE); -} - INT_PTR CGitLogListBase::OnToolHitTest(CPoint point, TOOLINFO * pTI) const { LVHITTESTINFO lvhitTestInfo; diff --git a/src/TortoiseProc/GitLogListBase.h b/src/TortoiseProc/GitLogListBase.h index 4cb847f57..4f42ec4c0 100644 --- a/src/TortoiseProc/GitLogListBase.h +++ b/src/TortoiseProc/GitLogListBase.h @@ -21,7 +21,7 @@ #pragma once #include "HintCtrl.h" -#include "ColumnManager.h" +#include "ResizableColumnsListCtrl.h" #include "Git.h" #include "ProjectProperties.h" #include "TGitPath.h" @@ -200,7 +200,7 @@ public: } }; -class CGitLogListBase : public CHintCtrl +class CGitLogListBase : public CHintCtrl> { DECLARE_DYNAMIC(CGitLogListBase) @@ -513,10 +513,6 @@ protected: afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); afx_msg void OnContextMenu(CWnd* pWnd, CPoint point); afx_msg LRESULT OnLoad(WPARAM wParam, LPARAM lParam); - afx_msg void OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult); - afx_msg void OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult); - afx_msg void OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult); - afx_msg void OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult); void OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult); afx_msg void OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult); void PreSubclassWindow(); @@ -663,7 +659,6 @@ protected: bool m_bSymbolizeRefNames; bool m_bIncludeBoundaryCommits; - ColumnManager m_ColumnManager; DWORD m_dwDefaultColumns; TCHAR m_wszTip[8192]; char m_szTip[8192]; diff --git a/src/TortoiseProc/ResizableColumnsListCtrl.h b/src/TortoiseProc/ResizableColumnsListCtrl.h new file mode 100644 index 000000000..ace5ae708 --- /dev/null +++ b/src/TortoiseProc/ResizableColumnsListCtrl.h @@ -0,0 +1,124 @@ +// TortoiseGit - a Windows shell extension for easy version control + +// Copyright (C) 2016 - TortoiseGit + +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software Foundation, +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +#pragma once +#include "ColumnManager.h" + +template class CResizableColumnsListCtrl : public BaseType +{ +public: + CResizableColumnsListCtrl() + : BaseType() + , m_ColumnManager(this) + , m_bAllowHiding(true) + {} + + DECLARE_MESSAGE_MAP() + +protected: + void OnDestroy() + { + SaveColumnWidths(); + BaseType::OnDestroy(); + } + + void OnHeaderDblClick(NMHDR* pNMHDR, LRESULT* pResult) + { + m_ColumnManager.OnHeaderDblClick(pNMHDR, pResult); + + *pResult = FALSE; + } + + void OnColumnResized(NMHDR* pNMHDR, LRESULT* pResult) + { + m_ColumnManager.OnColumnResized(pNMHDR, pResult); + + *pResult = FALSE; + } + + void OnColumnMoved(NMHDR* pNMHDR, LRESULT* pResult) + { + m_ColumnManager.OnColumnMoved(pNMHDR, pResult); + + Invalidate(FALSE); + } + + void OnContextMenuHeader(CWnd* pWnd, CPoint point) + { + m_ColumnManager.OnContextMenuHeader(pWnd, point, !!IsGroupViewEnabled()); + } + + void OnContextMenu(CWnd* pWnd, CPoint point) + { + if (pWnd == GetHeaderCtrl() && m_bAllowHiding) + OnContextMenuHeader(pWnd, point); + } + + // prevent users from extending our hidden (size 0) columns + void OnHdnBegintrack(NMHDR* pNMHDR, LRESULT* pResult) + { + m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult); + } + + // prevent any function from extending our hidden (size 0) columns + void OnHdnItemchanging(NMHDR* pNMHDR, LRESULT* pResult) + { + if (!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult)) + Default(); + } + +public: + void Init() + { + CRegDWORD regFullRowSelect(L"Software\\TortoiseGit\\FullRowSelect", TRUE); + DWORD exStyle = LVS_EX_HEADERDRAGDROP; + if (DWORD(regFullRowSelect)) + exStyle |= LVS_EX_FULLROWSELECT; + SetExtendedStyle(GetExtendedStyle() | exStyle); + } + void AdjustColumnWidths() + { + int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount() - 1; + for (int col = 0; col <= maxcol; col++) + SetColumnWidth(col, m_ColumnManager.GetWidth(col, true)); + } + virtual void SaveColumnWidths() + { + int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount() - 1; + for (int col = 0; col <= maxcol; col++) + if (m_ColumnManager.IsVisible(col)) + m_ColumnManager.ColumnResized(col); + + m_ColumnManager.WriteSettings(); + } + + bool m_bAllowHiding; + ColumnManager m_ColumnManager; +}; + +BEGIN_TEMPLATE_MESSAGE_MAP(CResizableColumnsListCtrl, BaseType, BaseType) + ON_NOTIFY(HDN_BEGINTRACKA, 0, OnHdnBegintrack) + ON_NOTIFY(HDN_BEGINTRACKW, 0, OnHdnBegintrack) + ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized) + ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved) + ON_NOTIFY(HDN_DIVIDERDBLCLICK, 0, OnHeaderDblClick) + ON_NOTIFY(HDN_ITEMCHANGINGA, 0, OnHdnItemchanging) + ON_NOTIFY(HDN_ITEMCHANGINGW, 0, OnHdnItemchanging) + ON_WM_DESTROY() + ON_WM_CONTEXTMENU() +END_MESSAGE_MAP() diff --git a/src/TortoiseProc/TortoiseProc.vcxproj b/src/TortoiseProc/TortoiseProc.vcxproj index 220005718..499cef67e 100644 --- a/src/TortoiseProc/TortoiseProc.vcxproj +++ b/src/TortoiseProc/TortoiseProc.vcxproj @@ -402,6 +402,7 @@ + diff --git a/src/TortoiseProc/TortoiseProc.vcxproj.filters b/src/TortoiseProc/TortoiseProc.vcxproj.filters index afcdbf1c4..c1dc0b543 100644 --- a/src/TortoiseProc/TortoiseProc.vcxproj.filters +++ b/src/TortoiseProc/TortoiseProc.vcxproj.filters @@ -1702,6 +1702,9 @@ Utils\UI + + Utility Dialogs + Utility Dialogs -- 2.11.4.GIT