Sort items in the Go menu into submenus per base URL. This further reduces the
clutter there. I'm quite happy now, but one issue could be that the Go menu is not stable: Any URL will always appear only once, somewhere in the hierarchy, depending on when you last visited it. The BrowsingHistory could be changed, though, feedback welcome. git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@330 94f232f2-1747-11df-bad5-a5bfde151594
This commit is contained in:
parent
7cbf0e1d7e
commit
f1dcf19d1d
@ -131,6 +131,17 @@ private:
|
||||
};
|
||||
|
||||
|
||||
static BString
|
||||
baseURL(const BString string)
|
||||
{
|
||||
int32 baseURLStart = string.FindFirst("://") + 3;
|
||||
int32 baseURLEnd = string.FindFirst("/", baseURLStart + 1);
|
||||
BString result;
|
||||
result.SetTo(string.String() + baseURLStart, baseURLEnd - baseURLStart);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
class BrowsingHistoryChoiceModel : public BAutoCompleter::ChoiceModel {
|
||||
virtual void FetchChoicesFor(const BString& pattern)
|
||||
{
|
||||
@ -161,10 +172,7 @@ class BrowsingHistoryChoiceModel : public BAutoCompleter::ChoiceModel {
|
||||
priority--;
|
||||
} else
|
||||
priority = INT_MAX;
|
||||
int32 baseURLStart = choiceText.FindFirst("://") + 3;
|
||||
int32 baseURLEnd = choiceText.FindFirst("/", baseURLStart + 1);
|
||||
lastBaseURL.SetTo(choiceText.String() + baseURLStart,
|
||||
baseURLEnd - baseURLStart);
|
||||
lastBaseURL = baseURL(choiceText);
|
||||
fChoices.AddItem(new URLChoice(choiceText,
|
||||
choiceText, matchPos, pattern.Length(), priority));
|
||||
}
|
||||
@ -683,6 +691,35 @@ BrowserWindow::QuitRequested()
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
addItemToMenuOrSubmenu(BMenu* menu, BMenuItem* newItem)
|
||||
{
|
||||
BString baseURLLabel = baseURL(BString(newItem->Label()));
|
||||
for (int32 i = menu->CountItems() - 1; i >= 0; i--) {
|
||||
BMenuItem* item = menu->ItemAt(i);
|
||||
BString label = item->Label();
|
||||
if (label.FindFirst(baseURLLabel) >= 0) {
|
||||
if (item->Submenu()) {
|
||||
// Submenu was already added in previous iteration.
|
||||
item->Submenu()->AddItem(newItem);
|
||||
return;
|
||||
} else {
|
||||
menu->RemoveItem(item);
|
||||
BMenu* subMenu = new BMenu(baseURLLabel.String());
|
||||
subMenu->AddItem(item);
|
||||
subMenu->AddItem(newItem);
|
||||
// Add common submenu for this base URL, clickable.
|
||||
BMessage* message = new BMessage(GOTO_URL);
|
||||
message->AddString("url", baseURLLabel.String());
|
||||
menu->AddItem(new BMenuItem(subMenu, message));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
menu->AddItem(newItem);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
addOrDeleteMenu(BMenu* menu, BMenu* toMenu)
|
||||
{
|
||||
@ -755,19 +792,19 @@ BrowserWindow::MenusBeginning()
|
||||
menuItem = new BMenuItem(truncatedUrl, message);
|
||||
|
||||
if (historyItem.dateTime() < fiveDaysAgoStart)
|
||||
earlierMenu->AddItem(menuItem);
|
||||
addItemToMenuOrSubmenu(earlierMenu, menuItem);
|
||||
else if (historyItem.dateTime() < fourDaysAgoStart)
|
||||
fiveDaysAgoMenu->AddItem(menuItem);
|
||||
addItemToMenuOrSubmenu(fiveDaysAgoMenu, menuItem);
|
||||
else if (historyItem.dateTime() < threeDaysAgoStart)
|
||||
fourDaysAgoMenu->AddItem(menuItem);
|
||||
addItemToMenuOrSubmenu(fourDaysAgoMenu, menuItem);
|
||||
else if (historyItem.dateTime() < twoDaysAgoStart)
|
||||
threeDaysAgoMenu->AddItem(menuItem);
|
||||
addItemToMenuOrSubmenu(threeDaysAgoMenu, menuItem);
|
||||
else if (historyItem.dateTime() < oneDayAgoStart)
|
||||
twoDaysAgoMenu->AddItem(menuItem);
|
||||
addItemToMenuOrSubmenu(twoDaysAgoMenu, menuItem);
|
||||
else if (historyItem.dateTime() < todayStart)
|
||||
yesterdayMenu->AddItem(menuItem);
|
||||
addItemToMenuOrSubmenu(yesterdayMenu, menuItem);
|
||||
else
|
||||
todayMenu->AddItem(menuItem);
|
||||
addItemToMenuOrSubmenu(todayMenu, menuItem);
|
||||
}
|
||||
history->Unlock();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user