From 395214304922be6666a6a0ada2c8237c1a098bd9 Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Fri, 31 Jul 2015 20:41:05 +0200 Subject: [PATCH] Add the "Regex Filter" commands to the plain manu in non-ribbon mode Based on TortoiseSVN revision 26633. Signed-off-by: Sven Strickroth --- src/Resources/TortoiseMergeENG.rc | 5 ++ src/TortoiseMerge/MainFrm.cpp | 105 ++++++++++++++++++++++++++------------ src/TortoiseMerge/MainFrm.h | 3 +- src/TortoiseMerge/resource.h | 4 +- 4 files changed, 82 insertions(+), 35 deletions(-) diff --git a/src/Resources/TortoiseMergeENG.rc b/src/Resources/TortoiseMergeENG.rc index a779659f8..e303f155f 100644 --- a/src/Resources/TortoiseMergeENG.rc +++ b/src/Resources/TortoiseMergeENG.rc @@ -539,6 +539,11 @@ BEGIN MENUITEM SEPARATOR MENUITEM "Find", ID_EDIT_FIND MENUITEM "Goto Line", ID_EDIT_GOTOLINE + MENUITEM SEPARATOR + POPUP "Regex Filter" + BEGIN + MENUITEM "Configure Filter Regexes", ID_REGEXFILTER + END END POPUP "&Navigate" BEGIN diff --git a/src/TortoiseMerge/MainFrm.cpp b/src/TortoiseMerge/MainFrm.cpp index 17c66746e..57e4b00ea 100644 --- a/src/TortoiseMerge/MainFrm.cpp +++ b/src/TortoiseMerge/MainFrm.cpp @@ -3338,53 +3338,73 @@ void CMainFrame::OnUpdateViewRegexFilter( CCmdUI *pCmdUI ) pCmdUI->SetCheck(pCmdUI->m_nID == (UINT)m_regexIndex); } -void CMainFrame::BuildRegexSubitems() +void CMainFrame::BuildRegexSubitems(CMFCPopupMenu* pMenuPopup) { - CArray arButtons; - m_wndRibbonBar.GetElementsByID(ID_REGEXFILTER, arButtons); - if (arButtons.GetCount() == 1) + CString sIniPath = CPathUtils::GetAppDataDirectory() + L"regexfilters.ini"; + if (!PathFileExists(sIniPath)) { - CMFCRibbonButton * pButton = (CMFCRibbonButton*)arButtons.GetAt(0); - if (pButton) + // ini file does not exist (yet), so create a default one + HRSRC hRes = FindResource(NULL, MAKEINTRESOURCE(IDR_REGEXFILTERINI), L"config"); + if (hRes) { - pButton->RemoveAllSubItems(); - pButton->AddSubItem(new CMFCRibbonButton(ID_REGEXFILTER+1, CString(MAKEINTRESOURCE(IDS_CONFIGUREREGEXES)), 47)); - - CString sIniPath = CPathUtils::GetAppDataDirectory() + L"regexfilters.ini"; - if (!PathFileExists(sIniPath)) + HGLOBAL hResourceLoaded = LoadResource(NULL, hRes); + if (hResourceLoaded) { - // ini file does not exist (yet), so create a default one - HRSRC hRes = FindResource(NULL, MAKEINTRESOURCE(IDR_REGEXFILTERINI), L"config"); - if (hRes) + char * lpResLock = (char *)LockResource(hResourceLoaded); + DWORD dwSizeRes = SizeofResource(NULL, hRes); + if (lpResLock) { - HGLOBAL hResourceLoaded = LoadResource(NULL, hRes); - if (hResourceLoaded) + HANDLE hFile = CreateFile(sIniPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + if (hFile != INVALID_HANDLE_VALUE) { - char * lpResLock = (char *) LockResource(hResourceLoaded); - DWORD dwSizeRes = SizeofResource(NULL, hRes); - if (lpResLock) - { - HANDLE hFile = CreateFile(sIniPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); - if (hFile != INVALID_HANDLE_VALUE) - { - DWORD dwWritten = 0; - WriteFile(hFile, lpResLock, dwSizeRes, &dwWritten, NULL); - CloseHandle(hFile); - } - } + DWORD dwWritten = 0; + WriteFile(hFile, lpResLock, dwSizeRes, &dwWritten, NULL); + CloseHandle(hFile); } } } + } + } - m_regexIni.LoadFile(sIniPath); - CSimpleIni::TNamesDepend sections; - m_regexIni.GetAllSections(sections); + m_regexIni.LoadFile(sIniPath); + CSimpleIni::TNamesDepend sections; + m_regexIni.GetAllSections(sections); + + if (m_bUseRibbons) + { + CArray arButtons; + m_wndRibbonBar.GetElementsByID(ID_REGEXFILTER, arButtons); + if (arButtons.GetCount() == 1) + { + CMFCRibbonButton * pButton = (CMFCRibbonButton*)arButtons.GetAt(0); + if (pButton) + { + pButton->RemoveAllSubItems(); + pButton->AddSubItem(new CMFCRibbonButton(ID_REGEXFILTER + 1, CString(MAKEINTRESOURCE(IDS_CONFIGUREREGEXES)), 47)); + + if (!sections.empty()) + pButton->AddSubItem(new CMFCRibbonSeparator(TRUE)); + int cmdIndex = 2; + for (const auto& section : sections) + { + pButton->AddSubItem(new CMFCRibbonButton(ID_REGEXFILTER + cmdIndex, section, 46)); + cmdIndex++; + } + } + } + } + else if (pMenuPopup) + { + int iIndex = -1; + if (!CMFCToolBar::IsCustomizeMode() && + (iIndex = pMenuPopup->GetMenuBar()->CommandToIndex(ID_REGEXFILTER)) >= 0) + { if (!sections.empty()) - pButton->AddSubItem(new CMFCRibbonSeparator(TRUE)); + pMenuPopup->InsertSeparator(iIndex + 1); // insert the separator at the end int cmdIndex = 2; for (const auto& section : sections) { - pButton->AddSubItem(new CMFCRibbonButton(ID_REGEXFILTER+cmdIndex, section, 46)); + pMenuPopup->InsertItem(CMFCToolBarMenuButton(ID_REGEXFILTER + cmdIndex, NULL, -1, (LPCWSTR)section), iIndex + cmdIndex); cmdIndex++; } } @@ -3636,3 +3656,22 @@ void CMainFrame::OnUpdateTabMode(CBaseView *view, CCmdUI *pCmdUI, int startid) else pCmdUI->Enable(FALSE); } + +BOOL CMainFrame::OnShowPopupMenu(CMFCPopupMenu* pMenuPopup) +{ + __super::OnShowPopupMenu(pMenuPopup); + + if (pMenuPopup == NULL) + { + return TRUE; + } + + int iIndex = -1; + if (!CMFCToolBar::IsCustomizeMode() && + (iIndex = pMenuPopup->GetMenuBar()->CommandToIndex(ID_REGEXFILTER)) >= 0) + { + BuildRegexSubitems(pMenuPopup); + } + + return TRUE; +} diff --git a/src/TortoiseMerge/MainFrm.h b/src/TortoiseMerge/MainFrm.h index c14f9a1df..bceb33a72 100644 --- a/src/TortoiseMerge/MainFrm.h +++ b/src/TortoiseMerge/MainFrm.h @@ -67,6 +67,7 @@ protected: virtual BOOL PreCreateWindow(CREATESTRUCT& cs); virtual BOOL OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext); virtual void ActivateFrame(int nCmdShow = -1); + virtual BOOL OnShowPopupMenu(CMFCPopupMenu* pMenuPopup); /// line = -1 means keep the current position, /// line >= 0 means scroll to that line, /// and line == -2 means do nothing or scroll to first diff depending on registry setting @@ -234,7 +235,7 @@ protected: static bool HasNextConflict(CBaseView* view); static bool HasPrevInlineDiff(CBaseView* view); static bool HasNextInlineDiff(CBaseView* view); - void BuildRegexSubitems(); + void BuildRegexSubitems(CMFCPopupMenu* pMenuPopup = nullptr); protected: CMFCStatusBar m_wndStatusBar; diff --git a/src/TortoiseMerge/resource.h b/src/TortoiseMerge/resource.h index 6cef875f8..1186f2eb6 100644 --- a/src/TortoiseMerge/resource.h +++ b/src/TortoiseMerge/resource.h @@ -378,13 +378,15 @@ #define ID_EDIT_ENABLE 32976 #define ID_FILE_ENABLEEDIT 32978 #define ID_BUTTON3 32981 +#define ID_EDIT_REGEXFILTER 32992 +#define ID_REGEXFILTER_REGEXFILTER 32993 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 171 -#define _APS_NEXT_COMMAND_VALUE 32982 +#define _APS_NEXT_COMMAND_VALUE 32994 #define _APS_NEXT_CONTROL_VALUE 1513 #define _APS_NEXT_SYMED_VALUE 101 #endif -- 2.11.4.GIT