Move overflowing items from bookmark bar to a menu.
Since the bookmark bar can now be resized smaller than the space needed for the items, move items that don't fit in it to a menu, which is always the last item in the BMenuBar.
This commit is contained in:
@@ -14,12 +14,19 @@
|
|||||||
|
|
||||||
#include "NavMenu.h"
|
#include "NavMenu.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
BookmarkBar::BookmarkBar(const char* title, BHandler* target,
|
BookmarkBar::BookmarkBar(const char* title, BHandler* target,
|
||||||
const entry_ref* navDir)
|
const entry_ref* navDir)
|
||||||
: BMenuBar(title)
|
: BMenuBar(title)
|
||||||
{
|
{
|
||||||
|
SetFlags(Flags() | B_FRAME_EVENTS);
|
||||||
BEntry(navDir).GetNodeRef(&fNodeRef);
|
BEntry(navDir).GetNodeRef(&fNodeRef);
|
||||||
|
|
||||||
|
fOverflowMenu = new BMenu(B_UTF8_ELLIPSIS);
|
||||||
|
|
||||||
|
AddItem(fOverflowMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -118,6 +125,59 @@ BookmarkBar::MessageReceived(BMessage* message)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BookmarkBar::FrameResized(float width, float height)
|
||||||
|
{
|
||||||
|
int32 count = CountItems() - 1;
|
||||||
|
// We don't touch the "more" menu
|
||||||
|
int32 i = 0;
|
||||||
|
float rightmost = 0.f;
|
||||||
|
while (i < count) {
|
||||||
|
BMenuItem* item = ItemAt(i);
|
||||||
|
BRect frame = item->Frame();
|
||||||
|
if (frame.right > width - 32)
|
||||||
|
break;
|
||||||
|
rightmost = frame.right;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i == count) {
|
||||||
|
// See if we can move some items from the "more" menu in the remaining
|
||||||
|
// space.
|
||||||
|
BMenuItem* extraItem = fOverflowMenu->ItemAt(0);
|
||||||
|
while (extraItem) {
|
||||||
|
BRect frame = extraItem->Frame();
|
||||||
|
if (frame.Width() + rightmost > width - 32)
|
||||||
|
break;
|
||||||
|
|
||||||
|
AddItem(fOverflowMenu->RemoveItem((int32)0), i);
|
||||||
|
i++;
|
||||||
|
|
||||||
|
extraItem = fOverflowMenu->ItemAt(0);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Remove any overflowing item and move them to the "more" menu.
|
||||||
|
for (int j = i; j < count; j++)
|
||||||
|
fOverflowMenu->AddItem(RemoveItem(j), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSize
|
||||||
|
BookmarkBar::MinSize()
|
||||||
|
{
|
||||||
|
BSize size = BMenuBar::MinSize();
|
||||||
|
|
||||||
|
// We only need space to show the "more" button.
|
||||||
|
size.width = 32;
|
||||||
|
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//#pragma mark - private methods
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BookmarkBar::_AddItem(ino_t inode, BEntry* entry)
|
BookmarkBar::_AddItem(ino_t inode, BEntry* entry)
|
||||||
{
|
{
|
||||||
@@ -149,6 +209,10 @@ BookmarkBar::_AddItem(ino_t inode, BEntry* entry)
|
|||||||
B_MINI_ICON);
|
B_MINI_ICON);
|
||||||
}
|
}
|
||||||
|
|
||||||
BMenuBar::AddItem(item);
|
BMenuBar::AddItem(item, CountItems() - 1);
|
||||||
fItemsMap[inode] = item;
|
fItemsMap[inode] = item;
|
||||||
|
|
||||||
|
// Move the item to the "more" menu if it overflows.
|
||||||
|
BRect r = Bounds();
|
||||||
|
FrameResized(r.width(), r.height());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include <MenuBar.h>
|
#include <MenuBar.h>
|
||||||
#include <Node.h>
|
#include <Node.h>
|
||||||
#include <NodeMonitor.h>
|
#include <NodeMonitor.h>
|
||||||
|
#include <Size.h>
|
||||||
|
|
||||||
|
|
||||||
class BEntry;
|
class BEntry;
|
||||||
@@ -30,12 +31,16 @@ public:
|
|||||||
void AttachedToWindow();
|
void AttachedToWindow();
|
||||||
void MessageReceived(BMessage* message);
|
void MessageReceived(BMessage* message);
|
||||||
|
|
||||||
|
void FrameResized(float width, float height);
|
||||||
|
BSize MinSize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _AddItem(ino_t inode, BEntry* entry);
|
void _AddItem(ino_t inode, BEntry* entry);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
node_ref fNodeRef;
|
node_ref fNodeRef;
|
||||||
std::map<ino_t, BPrivate::IconMenuItem*> fItemsMap;
|
std::map<ino_t, BPrivate::IconMenuItem*> fItemsMap;
|
||||||
|
BMenu* fOverflowMenu;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user