OSDN Git Service

Toolbar: Add drop down menu beside Options icon
authorsdottaka <sdottaka@sourceforge.net>
Sun, 9 Mar 2014 02:25:21 +0000 (11:25 +0900)
committersdottaka <sdottaka@sourceforge.net>
Sun, 9 Mar 2014 02:25:21 +0000 (11:25 +0900)
         Add "Folder Compare Method" combobox

--HG--
branch : stable

Src/MainFrm.cpp
Src/MainFrm.h
Src/Merge.rc
Src/Merge2.rc
Src/resource.h

index 6675430..47c17cb 100644 (file)
@@ -239,6 +239,14 @@ BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
        ON_COMMAND(ID_FILE_OPENCONFLICT, OnFileOpenConflict)
        ON_COMMAND(ID_PLUGINS_LIST, OnPluginsList)
        ON_UPDATE_COMMAND_UI(ID_STATUS_PLUGIN, OnUpdatePluginName)
+       ON_NOTIFY(TBN_DROPDOWN, AFX_IDW_TOOLBAR, OnDiffOptionsDropDown)
+       ON_COMMAND_RANGE(IDC_DIFF_WHITESPACE_COMPARE, IDC_DIFF_WHITESPACE_IGNOREALL, OnDiffWhitespace)
+       ON_UPDATE_COMMAND_UI_RANGE(IDC_DIFF_WHITESPACE_COMPARE, IDC_DIFF_WHITESPACE_IGNOREALL, OnUpdateDiffWhitespace)
+       ON_COMMAND(IDC_DIFF_CASESENSITIVE, OnDiffCaseSensitive)
+       ON_UPDATE_COMMAND_UI(IDC_DIFF_CASESENSITIVE, OnUpdateDiffCaseSensitive)
+       ON_COMMAND(IDC_DIFF_IGNOREEOL, OnDiffIgnoreEOL)
+       ON_UPDATE_COMMAND_UI(IDC_DIFF_IGNOREEOL, OnUpdateDiffIgnoreEOL)
+       ON_CBN_SELENDOK(IDC_COMPAREMETHODCOMBO, OnSelectCompareMethod)
        //}}AFX_MSG_MAP
 END_MESSAGE_MAP()
 
@@ -348,7 +356,7 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
        m_lfDiff = Options::Font::Load(OPT_FONT_FILECMP);
        m_lfDir = Options::Font::Load(OPT_FONT_DIRCMP);
        
-       if (!CreateToobar())
+       if (!CreateToolbar())
        {
                TRACE0("Failed to create toolbar\n");
                return -1;      // fail to create
@@ -873,21 +881,11 @@ void CMainFrame::OnOptions()
                sd_SetBreakChars(GetOptionsMgr()->GetString(OPT_BREAK_SEPARATORS).c_str());
 
                // make an attempt at rescanning any open diff sessions
-               const MergeDocList &docs = GetAllMergeDocs();
-               POSITION pos = docs.GetHeadPosition();
-               while (pos)
-               {
-                       CMergeDoc * pMergeDoc = docs.GetNext(pos);
-
-                       // Re-read MergeDoc settings (also updates view settings)
-                       // and rescan using new options
-                       pMergeDoc->RefreshOptions();
-                       pMergeDoc->FlushAndRescan(TRUE);
-               }
+               ApplyDiffOptions();
 
                // Update all dirdoc settings
                const DirDocList &dirDocs = GetAllDirDocs();
-               pos = dirDocs.GetHeadPosition();
+               POSITION pos = dirDocs.GetHeadPosition();
                while (pos)
                {
                        CDirDoc * pDirDoc = dirDocs.GetNext(pos);
@@ -1496,6 +1494,20 @@ void CMainFrame::addToMru(LPCTSTR szItem, LPCTSTR szRegSubKey, UINT nMaxItems)
        AfxGetApp()->WriteProfileInt(szRegSubKey, _T("Count"), cnt);
 }
 
+void CMainFrame::ApplyDiffOptions() 
+{
+       const MergeDocList &docs = GetAllMergeDocs();
+       POSITION pos = docs.GetHeadPosition();
+       while (pos)
+       {
+               CMergeDoc * pMergeDoc = docs.GetNext(pos);
+               // Re-read MergeDoc settings (also updates view settings)
+               // and rescan using new options
+               pMergeDoc->RefreshOptions();
+               pMergeDoc->FlushAndRescan(TRUE);
+       }
+}
+
 /**
  * @brief Apply tabs and eols settings to all merge documents
  */
@@ -2489,7 +2501,32 @@ void CMainFrame::OnActivateApp(BOOL bActive, HTASK hTask)
        }
 }
 
-BOOL CMainFrame::CreateToobar()
+BOOL CMainFrame::CreateComboBoxOnToolbar()
+{
+       const int methods[] =
+               {IDS_COMPMETHOD_FULL_CONTENTS, IDS_COMPMETHOD_QUICK_CONTENTS, IDS_COMPMETHOD_MODDATE, IDS_COMPMETHOD_DATESIZE, IDS_COMPMETHOD_SIZE};
+       CRect rcComboBox;
+       int index = m_wndToolBar.CommandToIndex(IDC_COMPAREMETHODCOMBO);
+       m_wndToolBar.SetButtonInfo(index, IDC_COMPAREMETHODCOMBO, TBBS_SEPARATOR, 128);
+       m_wndToolBar.GetItemRect(index, &rcComboBox);
+       rcComboBox.left += 6;
+       if (rcComboBox.Height() > 24)
+               rcComboBox.top += rcComboBox.Height() / 4;
+       rcComboBox.bottom = rcComboBox.top + 128;
+       if (!m_ctlCompareMethod.Create(
+                               CBS_DROPDOWNLIST | WS_VSCROLL | WS_VISIBLE,
+                               rcComboBox, &m_wndToolBar, IDC_COMPAREMETHODCOMBO ) )
+       {
+               return FALSE;
+       }
+       m_ctlCompareMethod.SetFont(CFont::FromHandle((HFONT)GetStockObject(DEFAULT_GUI_FONT)));
+       for (int i = 0; i < sizeof(methods)/sizeof(methods[0]); ++i)
+               m_ctlCompareMethod.AddString(theApp.LoadString(methods[i]).c_str());
+       m_ctlCompareMethod.SetCurSel(GetOptionsMgr()->GetInt(OPT_CMP_METHOD));
+       return TRUE;
+}
+
+BOOL CMainFrame::CreateToolbar()
 {
        if (!m_wndToolBar.CreateEx(this) ||
                !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
@@ -2507,11 +2544,23 @@ BOOL CMainFrame::CreateToobar()
        // Remove this if you don't want tool tips or a resizable toolbar
        m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
                CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
+       m_wndToolBar.GetToolBarCtrl().SetExtendedStyle(TBSTYLE_EX_DRAWDDARROWS);
 
        m_wndReBar.AddBar(&m_wndToolBar);
 
        LoadToolbarImages();
 
+       UINT nID, nStyle;
+       int iImage;
+       int index = m_wndToolBar.GetToolBarCtrl().CommandToIndex(ID_OPTIONS);
+       m_wndToolBar.GetButtonInfo(index, nID, nStyle, iImage);
+       nStyle |= TBSTYLE_DROPDOWN;
+       m_wndToolBar.SetButtonInfo(index, nID, nStyle, iImage);
+
+       // Create "Folder Compare Method" ComboBox on toolbar
+       if (!CreateComboBoxOnToolbar())
+               return FALSE;
+
        if (GetOptionsMgr()->GetBool(OPT_SHOW_TOOLBAR) == false)
        {
                CMDIFrameWnd::ShowControlBar(&m_wndToolBar, false, 0);
@@ -2631,6 +2680,14 @@ void CMainFrame::OnToolbarSmall()
 
        LoadToolbarImages();
 
+       CRect rcComboBox;
+       int index = m_wndToolBar.CommandToIndex(IDC_COMPAREMETHODCOMBO);
+       m_wndToolBar.GetItemRect(index, &rcComboBox);
+       rcComboBox.left += 6;
+       if (rcComboBox.Height() > 24)
+               rcComboBox.top += rcComboBox.Height() / 4;
+       m_ctlCompareMethod.MoveWindow(&rcComboBox);
+
        CMDIFrameWnd::ShowControlBar(&m_wndToolBar, TRUE, 0);
 }
 
@@ -2650,6 +2707,14 @@ void CMainFrame::OnToolbarBig()
 
        LoadToolbarImages();
 
+       CRect rcComboBox;
+       int index = m_wndToolBar.CommandToIndex(IDC_COMPAREMETHODCOMBO);
+       m_wndToolBar.GetItemRect(index, &rcComboBox);
+       rcComboBox.left += 6;
+       if (rcComboBox.Height() > 24)
+               rcComboBox.top += rcComboBox.Height() / 4;
+       m_ctlCompareMethod.MoveWindow(&rcComboBox);
+
        CMDIFrameWnd::ShowControlBar(&m_wndToolBar, TRUE, 0);
 }
 
@@ -2860,6 +2925,62 @@ void CMainFrame::OnPluginsList()
        dlg.DoModal();
 }
 
+void CMainFrame::OnDiffOptionsDropDown(NMHDR* pNMHDR, LRESULT* pResult)
+{
+       LPNMTOOLBAR pToolBar = reinterpret_cast<LPNMTOOLBAR>(pNMHDR);
+       ClientToScreen(&(pToolBar->rcButton));
+       CMenu menu;
+       VERIFY(menu.LoadMenu(IDR_POPUP_DIFF_OPTIONS));
+       theApp.TranslateMenu(menu.m_hMenu);
+       CMenu* pPopup = menu.GetSubMenu(0);
+       if (NULL != pPopup)
+       {
+               pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, 
+                       pToolBar->rcButton.left, pToolBar->rcButton.bottom, this);
+       }
+       *pResult = 0;
+}
+void CMainFrame::OnDiffWhitespace(UINT nID)
+{
+       GetOptionsMgr()->SaveOption(OPT_CMP_IGNORE_WHITESPACE, nID - IDC_DIFF_WHITESPACE_COMPARE);
+       ApplyDiffOptions();
+}
+
+void CMainFrame::OnUpdateDiffWhitespace(CCmdUI* pCmdUI)
+{
+       pCmdUI->SetRadio(pCmdUI->m_nID - IDC_DIFF_WHITESPACE_COMPARE == GetOptionsMgr()->GetInt(OPT_CMP_IGNORE_WHITESPACE));
+       pCmdUI->Enable();
+}
+
+void CMainFrame::OnDiffCaseSensitive()
+{
+       GetOptionsMgr()->SaveOption(OPT_CMP_IGNORE_CASE, !GetOptionsMgr()->GetBool(OPT_CMP_IGNORE_CASE));
+       ApplyDiffOptions();
+}
+
+void CMainFrame::OnUpdateDiffCaseSensitive(CCmdUI* pCmdUI)
+{
+       pCmdUI->SetCheck(!GetOptionsMgr()->GetBool(OPT_CMP_IGNORE_CASE));
+       pCmdUI->Enable();
+}
+
+void CMainFrame::OnDiffIgnoreEOL()
+{
+       GetOptionsMgr()->SaveOption(OPT_CMP_IGNORE_EOL, !GetOptionsMgr()->GetBool(OPT_CMP_IGNORE_EOL));
+       ApplyDiffOptions();
+}
+
+void CMainFrame::OnUpdateDiffIgnoreEOL(CCmdUI* pCmdUI)
+{
+       pCmdUI->SetCheck(GetOptionsMgr()->GetBool(OPT_CMP_IGNORE_EOL));
+       pCmdUI->Enable();
+}
+
+void CMainFrame::OnSelectCompareMethod()
+{ 
+       GetOptionsMgr()->SaveOption(OPT_CMP_METHOD, m_ctlCompareMethod.GetCurSel());
+}
+
 /**
  * @brief Update plugin name
  * @param [in] pCmdUI UI component to update.
index 23fe693..2b838ce 100644 (file)
@@ -108,6 +108,7 @@ public:
        void UpdateResources();
        CString SetStatus(LPCTSTR status);
        void ClearStatusbarItemCount();
+       void ApplyDiffOptions();
        void ApplyViewWhitespace();
        void SetEOLMixed(BOOL bAllow);
        void SelectFilter();
@@ -151,6 +152,7 @@ protected:
        CStatusBar  m_wndStatusBar;
        CReBar m_wndReBar;
        ToolBarXPThemes m_wndToolBar;
+       CComboBox m_ctlCompareMethod;
        CMDITabBar m_wndTabBar;
 
        /** @brief Toolbar image table indexes. */
@@ -276,6 +278,15 @@ protected:
        afx_msg void OnFileOpenConflict();
        afx_msg void OnPluginsList();
        afx_msg void OnUpdatePluginName(CCmdUI* pCmdUI);
+       afx_msg void OnDiffOptionsDropDown(NMHDR* pNMHDR, LRESULT* pResult);
+       afx_msg void OnUpdateDiffOptions(CCmdUI* pCmdUI);
+       afx_msg void OnDiffWhitespace(UINT nID);
+       afx_msg void OnUpdateDiffWhitespace(CCmdUI* pCmdUI);
+       afx_msg void OnDiffCaseSensitive();
+       afx_msg void OnUpdateDiffCaseSensitive(CCmdUI* pCmdUI);
+       afx_msg void OnDiffIgnoreEOL();
+       afx_msg void OnUpdateDiffIgnoreEOL(CCmdUI* pCmdUI);
+       afx_msg void OnSelectCompareMethod();
        //}}AFX_MSG
        DECLARE_MESSAGE_MAP()
 
@@ -291,7 +302,8 @@ private:
        CHexMergeDoc * GetHexMergeDocToShow(int nDirs, CDirDoc * pDirDoc, BOOL * pNew);
        CDirDoc * GetDirDocToShow(int nDirs, BOOL * pNew);
        void UpdateFont(FRAMETYPE frame);
-       BOOL CreateToobar();
+       BOOL CreateToolbar();
+       BOOL CreateComboBoxOnToolbar();
        CMergeEditView * GetActiveMergeEditView();
        void LoadToolbarImages();
        HMENU NewMenu( int view, int ID );
index 209b835..6063796 100644 (file)
@@ -648,6 +648,21 @@ BEGIN
     END
 END
 
+IDR_POPUP_DIFF_OPTIONS MENU
+BEGIN
+    POPUP "_POPUP_"
+    BEGIN
+        POPUP "W&hitespaces"
+        BEGIN
+            MENUITEM "Com&pare",            IDC_DIFF_WHITESPACE_COMPARE
+            MENUITEM "I&gnore changes",     IDC_DIFF_WHITESPACE_IGNORE
+            MENUITEM "Ig&nore all",         IDC_DIFF_WHITESPACE_IGNOREALL
+        END
+       MENUITEM "Case sensi&tive", IDC_DIFF_CASESENSITIVE
+       MENUITEM "Igno&re carriage return differences (Windows/Unix/Mac)", IDC_DIFF_IGNOREEOL
+    END
+END
+
 
 /////////////////////////////////////////////////////////////////////////////
 //
index 2debb5c..21c9d50 100644 (file)
@@ -97,6 +97,7 @@ BEGIN
     BUTTON      ID_AUTO_MERGE
     SEPARATOR
     BUTTON      ID_REFRESH
+    BUTTON      IDC_COMPAREMETHODCOMBO
 END
 
 
index 3669c16..984d6bc 100644 (file)
@@ -17,6 +17,7 @@
 #define IDR_DIRDOCTYPE                  110
 #define IDR_DIRVIEWMENU                 110 // = IDR_DIRDOCTYPE
 #define IDR_MERGEHAND                   112
+#define IDR_POPUP_DIFF_OPTIONS          113
 #define IDD_ABOUTBOX                    200
 #define IDD_PROP_VSS                    201
 #define IDD_OPEN                        202
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_3D_CONTROLS                     1
 #define _APS_NEXT_RESOURCE_VALUE        239
-#define _APS_NEXT_COMMAND_VALUE         33204
+#define _APS_NEXT_COMMAND_VALUE         33208
 #define _APS_NEXT_CONTROL_VALUE         1356
-#define _APS_NEXT_SYMED_VALUE           113
+#define _APS_NEXT_SYMED_VALUE           114
 #endif
 #endif