[haiku-commits] Change in haiku[master]: Tracker: Fix popup MenuEnded() cleanup.

  • From: Gerrit <review@xxxxxxxxxxxxxxxxxxx>
  • To: waddlesplash <waddlesplash@xxxxxxxxx>, haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 9 Mar 2020 02:41:00 +0000

From John Scipione <jscipione@xxxxxxxxx>:

John Scipione has uploaded this change for review. ( 
https://review.haiku-os.org/c/haiku/+/2331 ;)


Change subject: Tracker: Fix popup MenuEnded() cleanup.
......................................................................

Tracker: Fix popup MenuEnded() cleanup.

Set fContextMenu to the right variable in ShowContextMenu() and call
fContextMenu->Go() at the end. The only time that we exit this method
without calling fContextMenu->Go() is if we are Dragging() a file or
if the context menu is already open. With fContextMenu set we can check
it in MenusEnded() and if set exit skipping all the code that is intended
for the menus in the menu bar like the File menu.

Create fInitStatus and check it instead of checking each variable in
SetupMoveCopyMenus() and also check fInitStatus in ShowContextMenu().
---
M src/kits/tracker/ContainerWindow.cpp
M src/kits/tracker/ContainerWindow.h
2 files changed, 77 insertions(+), 46 deletions(-)



  git pull ssh://git.haiku-os.org:22/haiku refs/changes/31/2331/1

diff --git a/src/kits/tracker/ContainerWindow.cpp 
b/src/kits/tracker/ContainerWindow.cpp
index f0fa081..4d9b8b8 100644
--- a/src/kits/tracker/ContainerWindow.cpp
+++ b/src/kits/tracker/ContainerWindow.cpp
@@ -573,6 +573,7 @@
        fMoveToItem(NULL),
        fCopyToItem(NULL),
        fCreateLinkItem(NULL),
+       fIdentifyItem(NULL),
        fOpenWithItem(NULL),
        fNavigationItem(NULL),
        fMenuBar(NULL),
@@ -592,6 +593,7 @@
        fIsDesktop(isDeskWindow),
        fContainerWindowFlags(containerWindowFlags),
        fBackgroundImage(NULL),
+       fInitStatus(B_NO_INIT),
        fSavedZoomRect(0, 0, -1, -1),
        fContextMenu(NULL),
        fDragMessage(NULL),
@@ -959,6 +961,9 @@
                kCopySelectionTo, this));
        fCreateLinkItem = new BMenuItem(new BNavMenu(B_TRANSLATE("Create link"),
                kCreateLink, this), new BMessage(kCreateLink));
+       fIdentifyItem = new BMenuItem(B_TRANSLATE("Identify"),
+               new BMessage(kIdentifyEntry));
+       fIdentifyItem->Message()->SetBool("force", false);

        TrackerSettings settings;

@@ -1042,6 +1047,8 @@
        // done showing, turn the B_NO_WORKSPACE_ACTIVATION flag off;
        // it was on to prevent workspace jerking during boot
        SetFlags(Flags() & ~B_NO_WORKSPACE_ACTIVATION);
+
+       fInitStatus = B_OK;
 }

 void
@@ -2256,6 +2263,10 @@
 void
 BContainerWindow::MenusBeginning()
 {
+       if (fContextMenu != NULL)
+               return;
+
+       // the rest is for non-context menus
        if (fMenuBar == NULL)
                return;

@@ -2596,8 +2607,8 @@
 void
 BContainerWindow::SetupMoveCopyMenus(const entry_ref* item_ref, BMenu* parent)
 {
-       if (IsTrash() || InTrash() || IsPrintersDir() || !fMoveToItem
-               || !fCopyToItem || !fCreateLinkItem || TargetModel()->IsRoot()) 
{
+       if (IsTrash() || InTrash() || IsPrintersDir() || TargetModel()->IsRoot()
+               || parent == NULL || fInitStatus != B_OK) {
                return;
        }

@@ -2623,7 +2634,7 @@
                if (fCreateLinkItem->Menu() != NULL)
                        fCreateLinkItem->Menu()->RemoveItem(fCreateLinkItem);

-               parent->AddItem(fCreateLinkItem, index);
+               parent->AddItem(fCreateLinkItem, index++);
        }
 
        // Set the "Create Link" item label here so it
@@ -2724,6 +2735,10 @@
 void
 BContainerWindow::ShowContextMenu(BPoint loc, const entry_ref* ref, BView*)
 {
+       // ensure that the context menus have already been created
+       if (fInitStatus != B_OK)
+               return;
+
        ASSERT(IsLocked());
        BPoint global(loc);
        PoseView()->ConvertToScreen(&global);
@@ -2745,7 +2760,8 @@
                                static_cast<TTracker*>(be_app)->TrashFull());

                        SetupNavigationMenu(ref, fTrashContextMenu);
-                       fTrashContextMenu->Go(global, true, true, true);
+
+                       fContextMenu = fTrashContextMenu;
                } else {
                        bool showAsVolume = false;
                        bool isFilePanel = PoseView()->IsFilePanel();
@@ -2807,67 +2823,79 @@
                        } else
                                fContextMenu = fFileContextMenu;

-                       // clean up items from last context menu
+                       if (fContextMenu == NULL)
+                               return;

-                       if (fContextMenu != NULL) {
-                               if (fContextMenu->Window())
-                                       return;
-                               else
-                                       MenusEnded();
-
-                               if (model.InitCheck() == B_OK) { // ??? Do I 
need this ???
-                                       if (showAsVolume) {
-                                               // non-volume enable/disable 
copy, move, identify
-                                               
EnableNamedMenuItem(fContextMenu, kDuplicateSelection,
-                                                       false);
-                                               
EnableNamedMenuItem(fContextMenu, kMoveToTrash, false);
-                                               
EnableNamedMenuItem(fContextMenu, kIdentifyEntry,
-                                                       false);
-
-                                               // volume model, enable/disable 
the Unmount item
-                                               bool ejectableVolumeSelected = 
false;
-
-                                               BVolume boot;
-                                               
BVolumeRoster().GetBootVolume(&boot);
-                                               BVolume volume;
-                                               
volume.SetTo(model.NodeRef()->device);
-                                               if (volume != boot)
-                                                       ejectableVolumeSelected 
= true;
-
-                                               
EnableNamedMenuItem(fContextMenu,
-                                                       B_TRANSLATE("Unmount"), 
ejectableVolumeSelected);
-                                       }
+                       if (fContextMenu == fFileContextMenu) {
+                               // Update "Identify" item
+                               if ((modifiers() & B_SHIFT_KEY) != 0) {
+                                       
fIdentifyItem->SetLabel(B_TRANSLATE("Force identify"));
+                                       
fIdentifyItem->Message()->ReplaceBool("force", true);
+                               } else {
+                                       
fIdentifyItem->SetLabel(B_TRANSLATE("Identify"));
+                                       
fIdentifyItem->Message()->ReplaceBool("force", false);
                                }

-                               SetupNavigationMenu(ref, fContextMenu);
-                               if (!showAsVolume && !isFilePanel) {
-                                       SetupMoveCopyMenus(ref, fContextMenu);
-                                       SetupOpenWithMenu(fContextMenu);
-                               }
+                               // Update "Create link" item
+                               if ((modifiers() & B_SHIFT_KEY) != 0) {
+                                       fCreateLinkItem->SetLabel(
+                                               B_TRANSLATE("Create relative 
link"));
+                               } else
+                                       
fCreateLinkItem->SetLabel(B_TRANSLATE("Create link"));

-                               UpdateMenu(fContextMenu, kPosePopUpContext);
+                               // Add all mounted volumes (except the one this 
item lives on.)
+                               BNavMenu* navMenu = dynamic_cast<BNavMenu*>(
+                                       fCreateLinkItem->Submenu());
+                               PopulateMoveCopyNavMenu(navMenu,
+                               fCreateLinkItem->Message()->what, ref, false);
+                       } else if (model.InitCheck() == B_OK // TODO do we need 
this?
+                               && showAsVolume) {
+                               // non-volume enable/disable copy, move, 
identify
+                               EnableNamedMenuItem(fContextMenu, 
kDuplicateSelection,
+                                       false);
+                               EnableNamedMenuItem(fContextMenu, kMoveToTrash, 
false);
+                               EnableNamedMenuItem(fContextMenu, 
kIdentifyEntry, false);

-                               fContextMenu->Go(global, true, true, true);
+                               // volume model, enable/disable the Unmount item
+                               bool ejectableVolumeSelected = false;
+
+                               BVolume boot;
+                               BVolumeRoster().GetBootVolume(&boot);
+                               BVolume volume;
+                               volume.SetTo(model.NodeRef()->device);
+                               if (volume != boot)
+                                       ejectableVolumeSelected = true;
+
+                               EnableNamedMenuItem(fContextMenu,
+                                       B_TRANSLATE("Unmount"), 
ejectableVolumeSelected);
                        }
+
+                       SetupNavigationMenu(ref, fContextMenu);
+                       if (!showAsVolume && !isFilePanel) {
+                               SetupMoveCopyMenus(ref, fContextMenu);
+                               SetupOpenWithMenu(fContextMenu);
+                       }
+
+                       UpdateMenu(fContextMenu, kPosePopUpContext);
                }
        } else if (fWindowContextMenu != NULL) {
-               if (fWindowContextMenu->Window())
-                       return;
-
                // Repopulate desktop menu if IsDesktop
                if (fIsDesktop)
                        RepopulateMenus();

-               MenusEnded();
-
                // clicked on a window, show window context menu

                SetupNavigationMenu(ref, fWindowContextMenu);
                UpdateMenu(fWindowContextMenu, kWindowPopUpContext);

-               fWindowContextMenu->Go(global, true, true, true);
+               fContextMenu = fWindowContextMenu;
        }

+       // context menu invalid or popup window is already open
+       if (fContextMenu == NULL || fContextMenu->Window() != NULL)
+               return;
+
+       fContextMenu->Go(global, true, true, true);
        fContextMenu = NULL;
 }

diff --git a/src/kits/tracker/ContainerWindow.h 
b/src/kits/tracker/ContainerWindow.h
index b556f8e..3a28370 100644
--- a/src/kits/tracker/ContainerWindow.h
+++ b/src/kits/tracker/ContainerWindow.h
@@ -297,6 +297,7 @@
        BMenuItem* fMoveToItem;
        BMenuItem* fCopyToItem;
        BMenuItem* fCreateLinkItem;
+       BMenuItem* fIdentifyItem;
        BMenuItem* fOpenWithItem;
        ModelMenuItem* fNavigationItem;
        BMenuBar* fMenuBar;
@@ -324,6 +325,8 @@
        static LockingList<struct AddonShortcut>* fAddonsList;

 private:
+       status_t fInitStatus;
+
        BRect fSavedZoomRect;
        BRect fPreviousBounds;


--
To view, visit https://review.haiku-os.org/c/haiku/+/2331
To unsubscribe, or for help writing mail filters, visit 
https://review.haiku-os.org/settings

Gerrit-Project: haiku
Gerrit-Branch: master
Gerrit-Change-Id: I483716e855afa5e670c2d9bd1f9d6ac682ec20bb
Gerrit-Change-Number: 2331
Gerrit-PatchSet: 1
Gerrit-Owner: John Scipione <jscipione@xxxxxxxxx>
Gerrit-MessageType: newchange

Other related posts: