OSDN Git Service

Change to disable some menu items that should not be executed for directories, when...
authorJun Tajima <56220423+tjmprm77@users.noreply.github.com>
Sat, 27 Jun 2020 16:52:26 +0000 (01:52 +0900)
committerJun Tajima <56220423+tjmprm77@users.noreply.github.com>
Sat, 27 Jun 2020 16:52:26 +0000 (01:52 +0900)
Target menu items are the following:
- Context menu
  - "Compare As" > "XML"
  - "Compare As" > "Binary"
  - "Compare As" > "Image"
- Menu Bar
  - "Plugins" > "Edit with Unpacker..."

Also, as a precaution, change to do not perform processing when the above menu items are selected with selecting directories.
(Note that in normal case we cannot select these menu items because they are disabled.)

Src/DirActions.cpp
Src/DirActions.h
Src/DirView.cpp
Src/DirView.h

index 57dabd5..0a64d8c 100644 (file)
@@ -389,7 +389,7 @@ bool IsItemDeletableOnBoth(const CDiffContext& ctxt, const DIFFITEM &di)
 }
 
 /// is it possible to compare these two items?
-bool AreItemsOpenable(const CDiffContext& ctxt, SELECTIONTYPE selectionType, const DIFFITEM &di1, const DIFFITEM &di2)
+bool AreItemsOpenable(const CDiffContext& ctxt, SELECTIONTYPE selectionType, const DIFFITEM &di1, const DIFFITEM &di2, bool openableForDir /*= true*/)
 {
        String sLeftBasePath = ctxt.GetPath(0);
        String sRightBasePath = ctxt.GetPath(1);
@@ -397,6 +397,8 @@ bool AreItemsOpenable(const CDiffContext& ctxt, SELECTIONTYPE selectionType, con
        // Must be both directory or neither
        if (di1.diffcode.isDirectory() != di2.diffcode.isDirectory()) return false;
 
+       if (!openableForDir && di1.diffcode.isDirectory()) return false;
+
        switch (selectionType)
        {
        case SELECTIONTYPE_NORMAL:
@@ -438,7 +440,7 @@ bool AreItemsOpenable(const CDiffContext& ctxt, SELECTIONTYPE selectionType, con
        return false;
 }
 /// is it possible to compare these three items?
-bool AreItemsOpenable(const CDiffContext& ctxt, const DIFFITEM &di1, const DIFFITEM &di2, const DIFFITEM &di3)
+bool AreItemsOpenable(const CDiffContext& ctxt, const DIFFITEM &di1, const DIFFITEM &di2, const DIFFITEM &di3, bool openableForDir /*= true*/)
 {
        String sLeftBasePath = ctxt.GetPath(0);
        String sMiddleBasePath = ctxt.GetPath(1);
@@ -473,6 +475,8 @@ bool AreItemsOpenable(const CDiffContext& ctxt, const DIFFITEM &di1, const DIFFI
        // Must be both directory or neither
        if (di1.diffcode.isDirectory() != di2.diffcode.isDirectory() && di1.diffcode.isDirectory() != di3.diffcode.isDirectory()) return false;
 
+       if (!openableForDir && di1.diffcode.isDirectory()) return false;
+
        // Must be on different sides, or one on one side & one on both
        if (di1.diffcode.exists(0) && di2.diffcode.exists(1) && di3.diffcode.exists(2))
                return true;
@@ -713,15 +717,18 @@ bool IsShowable(const CDiffContext& ctxt, const DIFFITEM &di, const DirViewFilte
  * @param [out] paths First/Second/Third paths.
  * @param [out] sel1 Item's selection index in listview.
  * @param [in,out] isDir Is item folder?
+ * @param [in] openableForDir Are items openable if the items are directories?
  * return false if there was error or item was completely processed.
  */
 bool GetOpenOneItem(const CDiffContext& ctxt, DIFFITEM *pos1, const DIFFITEM *pdi[3],
-               PathContext & paths, int & sel1, bool & isdir, int nPane[3], String& errmsg)
+               PathContext & paths, int & sel1, bool & isdir, int nPane[3], String& errmsg, bool openableForDir /*= true*/)
 {
        pdi[0] = &ctxt.GetDiffAt(pos1);
        pdi[1] = pdi[0];
        pdi[2] = pdi[0];
 
+       if (!openableForDir && pdi[0]->diffcode.isDirectory()) return false;
+
        paths = GetItemFileNames(ctxt, *pdi[0]);
 
        for (int nIndex = 0; nIndex < paths.GetSize(); ++nIndex)
@@ -760,10 +767,11 @@ bool GetOpenOneItem(const CDiffContext& ctxt, DIFFITEM *pos1, const DIFFITEM *pd
  * @param [out] sel1 First item's selection index in listview.
  * @param [out] sel2 Second item's selection index in listview.
  * @param [in,out] isDir Is item folder?
+ * @param [in] openableForDir Are items openable if the items are directories?
  * return false if there was error or item was completely processed.
  */
 bool GetOpenTwoItems(const CDiffContext& ctxt, SELECTIONTYPE selectionType, DIFFITEM *pos1, DIFFITEM *pos2, const DIFFITEM *pdi[3],
-               PathContext & paths, int & sel1, int & sel2, bool & isDir, int nPane[3], String& errmsg)
+               PathContext & paths, int & sel1, int & sel2, bool & isDir, int nPane[3], String& errmsg, bool openableForDir /*= true*/)
 {
        // Two items selected, get their info
        pdi[0] = &ctxt.GetDiffAt(pos1);
@@ -772,7 +780,7 @@ bool GetOpenTwoItems(const CDiffContext& ctxt, SELECTIONTYPE selectionType, DIFF
        nPane[1] = 1;
 
        // Check for binary & side compatibility & file/dir compatibility
-       if (!AreItemsOpenable(ctxt, selectionType, *pdi[0], *pdi[1]))
+       if (!AreItemsOpenable(ctxt, selectionType, *pdi[0], *pdi[1], openableForDir))
        {
                return false;
        }
@@ -834,10 +842,11 @@ bool GetOpenTwoItems(const CDiffContext& ctxt, SELECTIONTYPE selectionType, DIFF
  * @param [out] sel2 Second item's selection index in listview.
  * @param [out] sel3 Third item's selection index in listview.
  * @param [in,out] isDir Is item folder?
+ * @param [in] openableForDir Are items openable if the items are directories?
  * return false if there was error or item was completely processed.
  */
 bool GetOpenThreeItems(const CDiffContext& ctxt, DIFFITEM *pos1, DIFFITEM *pos2, DIFFITEM *pos3, const DIFFITEM *pdi[3],
-       PathContext & paths, int & sel1, int & sel2, int & sel3, bool & isDir, int nPane[3], String& errmsg)
+       PathContext & paths, int & sel1, int & sel2, int & sel3, bool & isDir, int nPane[3], String& errmsg, bool openableForDir /*= true*/)
 {
        String pathLeft, pathMiddle, pathRight;
 
@@ -851,8 +860,8 @@ bool GetOpenThreeItems(const CDiffContext& ctxt, DIFFITEM *pos1, DIFFITEM *pos2,
                pdi[1] = &ctxt.GetDiffAt(pos2);
 
                // Check for binary & side compatibility & file/dir compatibility
-               if (!::AreItemsOpenable(ctxt, *pdi[0], *pdi[1], *pdi[1]) && 
-                       !::AreItemsOpenable(ctxt, *pdi[0], *pdi[0], *pdi[1]))
+               if (!::AreItemsOpenable(ctxt, *pdi[0], *pdi[1], *pdi[1], openableForDir) &&
+                       !::AreItemsOpenable(ctxt, *pdi[0], *pdi[0], *pdi[1], openableForDir))
                {
                        return false;
                }
@@ -906,7 +915,7 @@ bool GetOpenThreeItems(const CDiffContext& ctxt, DIFFITEM *pos1, DIFFITEM *pos2,
                pdi[2] = &ctxt.GetDiffAt(pos3);
 
                // Check for binary & side compatibility & file/dir compatibility
-               if (!::AreItemsOpenable(ctxt, *pdi[0], *pdi[1], *pdi[2]))
+               if (!::AreItemsOpenable(ctxt, *pdi[0], *pdi[1], *pdi[2], openableForDir))
                {
                        return false;
                }
index 4bf5bb9..7089ad4 100644 (file)
@@ -142,8 +142,8 @@ DIFFITEM *FindItemFromPaths(const CDiffContext& ctxt, const PathContext& paths);
 bool IsItemCopyable(const DIFFITEM &di, int index);
 bool IsItemDeletable(const DIFFITEM &di, int index);
 bool IsItemDeletableOnBoth(const CDiffContext& ctxt, const DIFFITEM &di);
-bool AreItemsOpenable(const CDiffContext& ctxt, SELECTIONTYPE selectionType, const DIFFITEM &di1, const DIFFITEM &di2);
-bool AreItemsOpenable(const CDiffContext& ctxt, const DIFFITEM &di1, const DIFFITEM &di2, const DIFFITEM &di3);
+bool AreItemsOpenable(const CDiffContext& ctxt, SELECTIONTYPE selectionType, const DIFFITEM &di1, const DIFFITEM &di2, bool openableForDir = true);
+bool AreItemsOpenable(const CDiffContext& ctxt, const DIFFITEM &di1, const DIFFITEM &di2, const DIFFITEM &di3, bool openableForDir = true);
 bool IsItemOpenableOn(const DIFFITEM &di, int index);
 bool IsItemOpenableOnWith(const DIFFITEM &di, int index);
 bool IsItemCopyableToOn(const DIFFITEM &di, int index);
@@ -152,11 +152,11 @@ bool IsItemExistAll(const CDiffContext& ctxt, const DIFFITEM &di);
 bool IsShowable(const CDiffContext& ctxt, const DIFFITEM &di, const DirViewFilterSettings& filter);
 
 bool GetOpenOneItem(const CDiffContext& ctxt, DIFFITEM *pos1, const DIFFITEM *pdi[3],
-               PathContext &paths, int & sel1, bool & isDir, int nPane[3], String& errmsg);
+               PathContext &paths, int & sel1, bool & isDir, int nPane[3], String& errmsg, bool openableForDir = true);
 bool GetOpenTwoItems(const CDiffContext& ctxt, SELECTIONTYPE selectionType, DIFFITEM *pos1, DIFFITEM *pos2, const DIFFITEM *pdi[3],
-               PathContext &paths, int & sel1, int & sel2, bool & isDir, int nPane[3], String& errmsg);
+               PathContext &paths, int & sel1, int & sel2, bool & isDir, int nPane[3], String& errmsg, bool openableForDir = true);
 bool GetOpenThreeItems(const CDiffContext& ctxt, DIFFITEM *pos1, DIFFITEM *pos2, DIFFITEM *pos3, const DIFFITEM *pdi[3],
-               PathContext &paths, int & sel1, int & sel2, int & sel3, bool & isDir, int nPane[3], String& errmsg);
+               PathContext &paths, int & sel1, int & sel2, int & sel3, bool & isDir, int nPane[3], String& errmsg, bool openableForDir = true);
 
 void GetItemFileNames(const CDiffContext& ctxt, const DIFFITEM& di, String& strLeft, String& strRight);
 PathContext GetItemFileNames(const CDiffContext& ctxt, const DIFFITEM& di);
index ed1807b..f92da3c 100644 (file)
@@ -1377,7 +1377,7 @@ void CDirView::Open(const PathContext& paths, DWORD dwFlags[3], PackingInfo * in
  * This handles the case that one item is selected
  * and the case that two items are selected (one on each side)
  */
-void CDirView::OpenSelection(SELECTIONTYPE selectionType /*= SELECTIONTYPE_NORMAL*/, PackingInfo * infoUnpacker /*= nullptr*/)
+void CDirView::OpenSelection(SELECTIONTYPE selectionType /*= SELECTIONTYPE_NORMAL*/, PackingInfo * infoUnpacker /*= nullptr*/, bool openableForDir /*= true*/)
 {
        Merge7zFormatMergePluginScope scope(infoUnpacker);
        CDirDoc * pDoc = GetDocument();
@@ -1420,15 +1420,15 @@ void CDirView::OpenSelection(SELECTIONTYPE selectionType /*= SELECTIONTYPE_NORMA
        bool success;
        if (pos2 && !pos3)
                success = GetOpenTwoItems(ctxt, selectionType, pos1, pos2, pdi,
-                               paths, sel1, sel2, isdir, nPane, errmsg);
+                               paths, sel1, sel2, isdir, nPane, errmsg, openableForDir);
        else if (pos2 && pos3)
                success = GetOpenThreeItems(ctxt, pos1, pos2, pos3, pdi,
-                               paths, sel1, sel2, sel3, isdir, nPane, errmsg);
+                               paths, sel1, sel2, sel3, isdir, nPane, errmsg, openableForDir);
        else
        {
                // Only one item selected, so perform diff on its sides
                success = GetOpenOneItem(ctxt, pos1, pdi, 
-                               paths, sel1, isdir, nPane, errmsg);
+                               paths, sel1, isdir, nPane, errmsg, openableForDir);
                if (isdir)
                        CreateFoldersPair(paths);
        }
@@ -1486,12 +1486,12 @@ void CDirView::OpenSelectionAs(UINT id)
        bool success;
        if (pos2)
                success = GetOpenTwoItems(ctxt, SELECTIONTYPE_NORMAL, pos1, pos2, pdi,
-                               paths, sel1, sel2, isdir, nPane, errmsg);
+                               paths, sel1, sel2, isdir, nPane, errmsg, false);
        else
        {
                // Only one item selected, so perform diff on its sides
                success = GetOpenOneItem(ctxt, pos1, pdi,
-                               paths, sel1, isdir, nPane, errmsg);
+                               paths, sel1, isdir, nPane, errmsg, false);
        }
        if (!success)
        {
@@ -1826,7 +1826,7 @@ void CDirView::OnUpdateCtxtDirOpenParentFolder(CCmdUI* pCmdUI)
 }
 
 // Used for Open
-void CDirView::DoUpdateOpen(SELECTIONTYPE selectionType, CCmdUI* pCmdUI)
+void CDirView::DoUpdateOpen(SELECTIONTYPE selectionType, CCmdUI* pCmdUI, bool openableForDir /*= true*/)
 {
        int sel1 = -1, sel2 = -1, sel3 = -1;
        if (!GetSelectedItems(&sel1, &sel2, &sel3))
@@ -1843,13 +1843,22 @@ void CDirView::DoUpdateOpen(SELECTIONTYPE selectionType, CCmdUI* pCmdUI)
                        pCmdUI->Enable(FALSE);
                        return;
                }
+               if (!openableForDir)
+               {
+                       const DIFFITEM& di1 = GetDiffItem(sel1);
+                       if (di1.diffcode.isDirectory())
+                       {
+                               pCmdUI->Enable(FALSE);
+                               return;
+                       }
+               }
        }
        else if (sel3 == -1)
        {
                // Two items selected
                const DIFFITEM& di1 = GetDiffItem(sel1);
                const DIFFITEM& di2 = GetDiffItem(sel2);
-               if (!AreItemsOpenable(GetDiffContext(), selectionType, di1, di2))
+               if (!AreItemsOpenable(GetDiffContext(), selectionType, di1, di2, openableForDir))
                {
                        pCmdUI->Enable(FALSE);
                        return;
@@ -1861,7 +1870,7 @@ void CDirView::DoUpdateOpen(SELECTIONTYPE selectionType, CCmdUI* pCmdUI)
                const DIFFITEM& di1 = GetDiffItem(sel1);
                const DIFFITEM& di2 = GetDiffItem(sel2);
                const DIFFITEM& di3 = GetDiffItem(sel3);
-               if (selectionType != SELECTIONTYPE_NORMAL || !::AreItemsOpenable(GetDiffContext(), di1, di2, di3))
+               if (selectionType != SELECTIONTYPE_NORMAL || !::AreItemsOpenable(GetDiffContext(), di1, di2, di3, openableForDir))
                {
                        pCmdUI->Enable(FALSE);
                        return;
@@ -2524,7 +2533,7 @@ void CDirView::OnCtxtOpenWithUnpacker()
                if (dlg.DoModal() == IDOK)
                {
                        infoUnpacker = dlg.GetInfoHandler();
-                       OpenSelection(SELECTIONTYPE_NORMAL, &infoUnpacker);
+                       OpenSelection(SELECTIONTYPE_NORMAL, &infoUnpacker, false);
                }
        }
 
@@ -2546,6 +2555,11 @@ void CDirView::OnUpdateCtxtOpenWithUnpacker(CCmdUI* pCmdUI)
                int sel = -1;
                sel = m_pList->GetNextItem(sel, LVNI_SELECTED);
                const DIFFITEM& di = GetDiffItem(sel);
+               if (di.diffcode.isDirectory())
+               {
+                       pCmdUI->Enable(FALSE);
+                       return;
+               }
                pCmdUI->Enable(IsItemDeletableOnBoth(GetDiffContext(), di));
        }
 }
@@ -3526,7 +3540,7 @@ void CDirView::OnMergeCompareXML()
 {
        CWaitCursor waitstatus;
        PackingInfo packingInfo(PLUGIN_BUILTIN_XML);
-       OpenSelection(SELECTIONTYPE_NORMAL, &packingInfo);
+       OpenSelection(SELECTIONTYPE_NORMAL, &packingInfo, false);
 }
 
 void CDirView::OnMergeCompareAs(UINT nID)
@@ -3537,7 +3551,11 @@ void CDirView::OnMergeCompareAs(UINT nID)
 
 void CDirView::OnUpdateMergeCompare(CCmdUI *pCmdUI)
 {
-       DoUpdateOpen(SELECTIONTYPE_NORMAL, pCmdUI);
+       bool openableForDir = (pCmdUI->m_nID != ID_MERGE_COMPARE_XML &&
+                                                  pCmdUI->m_nID != ID_MERGE_COMPARE_HEX &&
+                                                  pCmdUI->m_nID != ID_MERGE_COMPARE_IMAGE);
+
+       DoUpdateOpen(SELECTIONTYPE_NORMAL, pCmdUI, openableForDir);
 }
 
 template<SELECTIONTYPE seltype>
index 923227f..7f038d0 100644 (file)
@@ -123,7 +123,7 @@ private:
        void DoOpenWith(SIDE_TYPE stype);
        void DoOpenWithEditor(SIDE_TYPE stype);
        void DoOpenParentFolder(SIDE_TYPE stype);
-       void DoUpdateOpen(SELECTIONTYPE selectionType, CCmdUI* pCmdUI);
+       void DoUpdateOpen(SELECTIONTYPE selectionType, CCmdUI* pCmdUI, bool openableForDir = true);
        void ConfirmAndPerformActions(FileActionScript & actions);
        void PerformActionList(FileActionScript & actions);
        void UpdateAfterFileScript(FileActionScript & actionList);
@@ -380,7 +380,7 @@ protected:
 
 private:
        void Open(const PathContext& paths, DWORD dwFlags[3], PackingInfo * infoUnpacker = nullptr);
-       void OpenSelection(SELECTIONTYPE selectionType = SELECTIONTYPE_NORMAL, PackingInfo * infoUnpacker = nullptr);
+       void OpenSelection(SELECTIONTYPE selectionType = SELECTIONTYPE_NORMAL, PackingInfo * infoUnpacker = nullptr, bool openableForDir = true);
        void OpenSelectionAs(UINT id);
        bool GetSelectedItems(int * sel1, int * sel2, int * sel3);
        void OpenParentDirectory();