[haiku-commits] Change in haiku[master]: Tracker: Live update identify and create link menu items

  • From: Gerrit <review@xxxxxxxxxxxxxxxxxxx>
  • To: waddlesplash <waddlesplash@xxxxxxxxx>, haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 29 Feb 2020 00:43:13 +0000

From John Scipione <jscipione@xxxxxxxxx>:

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


Change subject: Tracker: Live update identify and create link menu items
......................................................................

Tracker: Live update identify and create link menu items

when you press and release the shift key with the File menu or a
file's context menu open.

Identify => Force identify
Create link => Create relative link

Forward B_MODIFIERS_CHANGED message from MenuWindow::DispatchMessage()
to be_app_messenger to so that Tracker can then forward the message onto
its windows.
---
M src/kits/interface/MenuWindow.cpp
M src/kits/tracker/ContainerWindow.cpp
M src/kits/tracker/ContainerWindow.h
M src/kits/tracker/Tracker.cpp
M src/kits/tracker/Tracker.h
5 files changed, 135 insertions(+), 39 deletions(-)



  git pull ssh://git.haiku-os.org:22/haiku refs/changes/93/2293/1

diff --git a/src/kits/interface/MenuWindow.cpp 
b/src/kits/interface/MenuWindow.cpp
index e8e5eeb..b30140c 100644
--- a/src/kits/interface/MenuWindow.cpp
+++ b/src/kits/interface/MenuWindow.cpp
@@ -11,6 +11,7 @@

 #include <MenuWindow.h>

+#include <Application.h>
 #include <ControlLook.h>
 #include <Debug.h>
 #include <Menu.h>
@@ -256,6 +257,9 @@
 void
 BMenuWindow::DispatchMessage(BMessage *message, BHandler *handler)
 {
+       if (message->what == B_MODIFIERS_CHANGED)
+               be_app_messenger.SendMessage(message);
+
        BWindow::DispatchMessage(message, handler);
 }

diff --git a/src/kits/tracker/ContainerWindow.cpp 
b/src/kits/tracker/ContainerWindow.cpp
index 65d61b5..2d377bb 100644
--- a/src/kits/tracker/ContainerWindow.cpp
+++ b/src/kits/tracker/ContainerWindow.cpp
@@ -1514,6 +1514,10 @@
                        break;
                }

+               case B_MODIFIERS_CHANGED:
+                       UpdateMenuItemsForModifiersChanged();
+                       break;
+
                case kNewFolder:
                        PostMessage(message, PoseView());
                        break;
@@ -1573,6 +1577,7 @@
                case kCreateLink:
                case kCreateRelativeLink:
                {
+                       bool relative = message->what == kCreateRelativeLink;
                        entry_ref ref;
                        if (message->FindRef("refs", &ref) == B_OK) {
                                BRoster().AddToRecentFolders(&ref);
@@ -1582,14 +1587,12 @@
                                        break;

                                PoseView()->MoveSelectionInto(&model, this, 
false, false,
-                                       message->what == kCreateLink,
-                                       message->what == kCreateRelativeLink);
+                                       relative, relative);
                        } else if (!TargetModel()->IsQuery()
                                && !TargetModel()->IsVirtualDirectory()) {
                                // no destination specified, create link in 
same dir as item
-                               PoseView()->MoveSelectionInto(TargetModel(), 
this, false, false,
-                                       message->what == kCreateLink,
-                                       message->what == kCreateRelativeLink);
+                               PoseView()->MoveSelectionInto(TargetModel(), 
this, false,
+                                       false, relative, relative);
                        }
                        break;
                }
@@ -2600,9 +2603,6 @@
                return;
        }

-       // Grab the modifiers state since we use it twice
-       uint32 modifierKeys = modifiers();
-
        // re-parent items to this menu since they're shared
        int32 index;
        BMenuItem* trash = parent->FindItem(kMoveToTrash);
@@ -2632,13 +2632,6 @@
                parent->AddItem(fCreateLinkItem, index);
        }

-       // Set the "Create Link" item label here so it
-       // appears correctly when menus are disabled, too.
-       if (modifierKeys & B_SHIFT_KEY)
-               fCreateLinkItem->SetLabel(B_TRANSLATE("Create relative link"));
-       else
-               fCreateLinkItem->SetLabel(B_TRANSLATE("Create link"));
-
        // only enable once the menus are built
        fMoveToItem->SetEnabled(false);
        fCopyToItem->SetEnabled(false);
@@ -2667,33 +2660,14 @@

        // Set "Create Link" menu item message and
        // add all mounted volumes (except the one this item lives on)
-       if (modifierKeys & B_SHIFT_KEY) {
-               fCreateLinkItem->SetMessage(new BMessage(kCreateRelativeLink));
-               PopulateMoveCopyNavMenu(dynamic_cast<BNavMenu*>
-                               (fCreateLinkItem->Submenu()),
-                       kCreateRelativeLink, item_ref, false);
-       } else {
-               fCreateLinkItem->SetMessage(new BMessage(kCreateLink));
-               PopulateMoveCopyNavMenu(dynamic_cast<BNavMenu*>
-                       (fCreateLinkItem->Submenu()),
-               kCreateLink, item_ref, false);
-       }
+       UpdateCreateLinkMenuItem(fCreateLinkItem, item_ref);

        fMoveToItem->SetEnabled(true);
        fCopyToItem->SetEnabled(true);
        fCreateLinkItem->SetEnabled(true);

        // Set the "Identify" item label
-       BMenuItem* identifyItem = parent->FindItem(kIdentifyEntry);
-       if (identifyItem != NULL) {
-               if (modifierKeys & B_SHIFT_KEY) {
-                       identifyItem->SetLabel(B_TRANSLATE("Force identify"));
-                       identifyItem->Message()->ReplaceBool("force", true);
-               } else {
-                       identifyItem->SetLabel(B_TRANSLATE("Identify"));
-                       identifyItem->Message()->ReplaceBool("force", false);
-               }
-       }
+       UpdateIdentifyMenuItem(parent->FindItem(kIdentifyEntry));
 }


@@ -2710,16 +2684,16 @@
        BMenuItem* item = fDropContextMenu->FindItem(kCreateLink);
        if (item == NULL)
                item = fDropContextMenu->FindItem(kCreateRelativeLink);
-       if (item && (modifiers() & B_SHIFT_KEY)) {
+       if (item != NULL && (modifiers() & B_SHIFT_KEY)) {
                item->SetLabel(B_TRANSLATE("Create relative link here"));
                item->SetMessage(new BMessage(kCreateRelativeLink));
-       } else if (item) {
+       } else if (item != NULL) {
                item->SetLabel(B_TRANSLATE("Create link here"));
                item->SetMessage(new BMessage(kCreateLink));
        }

        item = fDropContextMenu->Go(global, true, true);
-       if (item)
+       if (item != NULL)
                return item->Command();
 
        return 0;
@@ -2918,9 +2892,11 @@
 #endif

        menu->AddSeparatorItem();
+
        BMessage* message = new BMessage(kIdentifyEntry);
        message->AddBool("force", false);
        menu->AddItem(new BMenuItem(B_TRANSLATE("Identify"), message));
+
        BMenu* addOnMenuItem = new BMenu(B_TRANSLATE("Add-ons"));
        addOnMenuItem->SetFont(be_plain_font);
        menu->AddItem(addOnMenuItem);
@@ -4361,6 +4337,101 @@
 }


+void
+BContainerWindow::UpdateMenuItemsForModifiersChanged()
+{
+       BMenuItem* item = NULL;
+
+       // File menu
+       if (fFileMenu != NULL) {
+               // Identify/Force identify
+               item = fFileMenu->FindItem(kIdentifyEntry);
+               UpdateIdentifyMenuItem(item);
+
+               // Create link/Create relative link
+               item = fFileMenu->FindItem(kCreateLink);
+               UpdateCreateLinkMenuItem(item);
+               item = fFileMenu->FindItem(kCreateRelativeLink);
+               UpdateCreateLinkMenuItem(item);
+
+       }
+
+       // File context menu
+       if (fFileContextMenu != NULL) {
+               // Identify/Force identify
+               item = fFileContextMenu->FindItem(kIdentifyEntry);
+               UpdateIdentifyMenuItem(item);
+
+               // Create link/Create relative link
+               item = fFileContextMenu->FindItem(kCreateLink);
+               UpdateCreateLinkMenuItem(item);
+               item = fFileContextMenu->FindItem(kCreateRelativeLink);
+               UpdateCreateLinkMenuItem(item);
+       }
+}
+
+
+void
+BContainerWindow::UpdateIdentifyMenuItem(BMenuItem* item)
+{
+       if (item == NULL || item->Menu() == NULL)
+               return;
+
+       if ((modifiers() & B_SHIFT_KEY) != 0) {
+               item->Message()->ReplaceBool("force", true);
+               item->SetLabel(B_TRANSLATE("Force identify"));
+       } else {
+               item->Message()->ReplaceBool("force", false);
+               // add some room for the label to grow
+               BString label(B_TRANSLATE("Identify"));
+               float shortLabel = item->Menu()->StringWidth(
+                       B_TRANSLATE("Identify"));
+               float longLabel = item->Menu()->StringWidth(
+                       B_TRANSLATE("Force identify"));
+               while (longLabel > shortLabel) {
+                       label << " ";
+                       longLabel -= item->Menu()->StringWidth(" ");
+               }
+               item->SetLabel(label.String());
+       }
+}
+
+
+void
+BContainerWindow::UpdateCreateLinkMenuItem(BMenuItem* item,
+       const entry_ref* ref)
+{
+       if (item == NULL || item->Menu() == NULL)
+               return;
+
+       if ((modifiers() & B_SHIFT_KEY) != 0) {
+               item->Message()->what = kCreateRelativeLink;
+               if (strcmp(item->Label(), B_TRANSLATE("Current folder")) != 0)
+                       item->SetLabel(B_TRANSLATE("Create relative link"));
+       } else {
+               item->Message()->what = kCreateLink;
+               if (strcmp(item->Label(), B_TRANSLATE("Current folder")) != 0) {
+                       // add some room for the label to grow
+                       BString label(B_TRANSLATE("Create link"));
+                       float shortLabel = item->Menu()->StringWidth(
+                               B_TRANSLATE("Create link"));
+                       float longLabel = item->Menu()->StringWidth(
+                               B_TRANSLATE("Create relative link"));
+                       while (longLabel > shortLabel) {
+                               label << " ";
+                               longLabel -= item->Menu()->StringWidth(" ");
+                       }
+                       item->SetLabel(label.String());
+               }
+       }
+
+       if (ref != NULL) {
+               BNavMenu* navMenu = dynamic_cast<BNavMenu*>(item->Submenu());
+               PopulateMoveCopyNavMenu(navMenu, item->Message()->what, ref, 
false);
+       }
+}
+
+
 //     #pragma mark - WindowStateNodeOpener


diff --git a/src/kits/tracker/ContainerWindow.h 
b/src/kits/tracker/ContainerWindow.h
index b556f8e..5602a2a 100644
--- a/src/kits/tracker/ContainerWindow.h
+++ b/src/kits/tracker/ContainerWindow.h
@@ -244,6 +244,10 @@
        virtual void RepopulateMenus();
        void PopulateArrangeByMenu(BMenu*);

+       void UpdateMenuItemsForModifiersChanged();
+       void UpdateIdentifyMenuItem(BMenuItem* item);
+       void UpdateCreateLinkMenuItem(BMenuItem* item, const entry_ref* ref = 
NULL);
+
        virtual void SetCutItem(BMenu*);
        virtual void SetCopyItem(BMenu*);
        virtual void SetPasteItem(BMenu*);
diff --git a/src/kits/tracker/Tracker.cpp b/src/kits/tracker/Tracker.cpp
index 93390c3..c59165b 100644
--- a/src/kits/tracker/Tracker.cpp
+++ b/src/kits/tracker/Tracker.cpp
@@ -1026,6 +1026,22 @@


 void
+TTracker::DispatchMessage(BMessage* message, BHandler* handler)
+{
+       if (message->what == B_MODIFIERS_CHANGED) {
+               for (int32 i = 0; i < fWindowList.CountItems(); i++) {
+                       BContainerWindow* window = 
dynamic_cast<BContainerWindow*>(
+                               fWindowList.ItemAt(i));
+                       if (window != NULL)
+                               window->PostMessage(message);
+               }
+       }
+
+       BApplication::DispatchMessage(message, handler);
+}
+
+
+void
 TTracker::OpenContainerWindow(Model* model, BMessage* originalRefsList,
        OpenSelector openSelector, uint32 openFlags, bool checkAlreadyOpen,
        const BMessage* stateMessage)
diff --git a/src/kits/tracker/Tracker.h b/src/kits/tracker/Tracker.h
index efda7ae..34680bd 100644
--- a/src/kits/tracker/Tracker.h
+++ b/src/kits/tracker/Tracker.h
@@ -89,6 +89,7 @@
        virtual void Pulse();
        virtual void RefsReceived(BMessage* message);
        virtual void ArgvReceived(int32 argc, char** argv);
+       virtual void DispatchMessage(BMessage* message, BHandler* handler);

        MimeTypeList* MimeTypes() const;
                // list of mime types that have a description and do not have

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

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

Other related posts:

  • » [haiku-commits] Change in haiku[master]: Tracker: Live update identify and create link menu items - Gerrit