From 7eb3210e8f56c924148b23f129dbdc3f2670d828 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Sun, 6 Nov 2011 03:19:15 +0000 Subject: [PATCH] Sort application windows in Deskbar in 'natural' order yielding this: window 1 window 2 window 3 window 4 window 5 window 6 window 7 window 8 window 9 window 10 window 11 Instead of this: window 1 window 10 window 11 window 2 window 3 window 4 window 5 window 6 window 7 window 8 window 9 The natural order comparison method used in Deskbar is the same method used to sort file names in natural order in Tracker. Also when comparing window titles to their corresponding window menu item labels use the FullTitle() method instead of the Label() method because the label might get truncated. Fixes #7774 git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43195 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/deskbar/ExpandoMenuBar.cpp | 3 ++- src/apps/deskbar/ExpandoMenuBar.h | 2 +- src/apps/deskbar/TeamMenu.cpp | 3 ++- src/apps/deskbar/TeamMenu.h | 2 +- src/apps/deskbar/WindowMenu.cpp | 29 ++++++++++++++--------------- src/apps/deskbar/WindowMenuItem.cpp | 14 ++++++++++---- 6 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/apps/deskbar/ExpandoMenuBar.cpp b/src/apps/deskbar/ExpandoMenuBar.cpp index 739f0761bd..c07818be18 100644 --- a/src/apps/deskbar/ExpandoMenuBar.cpp +++ b/src/apps/deskbar/ExpandoMenuBar.cpp @@ -787,7 +787,8 @@ TExpandoMenuBar::monitor_team_windows(void* arg) ((1 << current_workspace()) & wInfo->workspaces) != 0); - if (strcmp(wInfo->name, item->Label()) != 0) + if (strcasecmp(wInfo->name, + item->FullTitle()) != 0) item->SetLabel(wInfo->name); if (item->ChangedState()) diff --git a/src/apps/deskbar/ExpandoMenuBar.h b/src/apps/deskbar/ExpandoMenuBar.h index 6a96559e02..d0d624a43f 100644 --- a/src/apps/deskbar/ExpandoMenuBar.h +++ b/src/apps/deskbar/ExpandoMenuBar.h @@ -84,7 +84,7 @@ class TExpandoMenuBar : public BMenuBar { void CheckForSizeOverrun(); private: - static int CompareByName( const void* first, const void* second); + static int CompareByName(const void* first, const void* second); static int32 monitor_team_windows(void* arg); void AddTeam(BList* team, BBitmap* icon, char* name, char* signature); diff --git a/src/apps/deskbar/TeamMenu.cpp b/src/apps/deskbar/TeamMenu.cpp index 3053969821..d0342786e3 100644 --- a/src/apps/deskbar/TeamMenu.cpp +++ b/src/apps/deskbar/TeamMenu.cpp @@ -33,9 +33,10 @@ holders. All rights reserved. */ -#include #include + #include +#include #include #include "BarApp.h" diff --git a/src/apps/deskbar/TeamMenu.h b/src/apps/deskbar/TeamMenu.h index a012a5e92d..b4239c945f 100644 --- a/src/apps/deskbar/TeamMenu.h +++ b/src/apps/deskbar/TeamMenu.h @@ -53,7 +53,7 @@ class TTeamMenu : public BMenu { void DrawBackground(BRect update); private: - static int CompareByName( const void* first, const void* second); + static int CompareByName(const void* first, const void* second); }; #endif /* TEAMMENU_H */ diff --git a/src/apps/deskbar/WindowMenu.cpp b/src/apps/deskbar/WindowMenu.cpp index 59e31fc7f1..5ad07ea14a 100644 --- a/src/apps/deskbar/WindowMenu.cpp +++ b/src/apps/deskbar/WindowMenu.cpp @@ -116,13 +116,12 @@ TWindowMenu::AttachedToWindow() int32 parentMenuItems = 0; - int32 numTeams = fTeam->CountItems(); - for (int32 i = 0; i < numTeams; i++) { - team_id theTeam = (team_id)fTeam->ItemAt(i); - int32 count = 0; - int32* tokens = get_token_list(theTeam, &count); + for (int32 i = 0; i < fTeam->CountItems(); i++) { + team_id theTeam = (team_id)fTeam->ItemAt(i); + int32 tokenCount = 0; + int32* tokens = get_token_list(theTeam, &tokenCount); - for (int32 j = 0; j < count; j++) { + for (int32 j = 0; j < tokenCount; j++) { client_window_info* wInfo = get_window_info(tokens[j]); if (wInfo == NULL) continue; @@ -131,11 +130,13 @@ TWindowMenu::AttachedToWindow() && (wInfo->show_hide_level <= 0 || wInfo->is_mini)) { // Don't add new items if we're expanded. We've already done // this, they've just been moved. - int32 numItems = CountItems(); - int32 addIndex = 0; - for (; addIndex < numItems; addIndex++) - if (strcasecmp(ItemAt(addIndex)->Label(), wInfo->name) > 0) + for (int32 addIndex = 0; addIndex < CountItems(); addIndex++) { + TWindowMenuItem* item + = static_cast(ItemAt(addIndex)); + if (item != NULL + && strcasecmp(item->FullTitle(), wInfo->name) > 0) break; + } if (!fExpanded) { TWindowMenuItem* item = new TWindowMenuItem(wInfo->name, @@ -180,19 +181,17 @@ TWindowMenu::AttachedToWindow() = new TWindowMenuItem(B_TRANSLATE("No windows"), -1, false, false); noWindowsItem->SetEnabled(false); - AddItem(noWindowsItem); - // if an application has no windows, this feature makes it easy to quit - // it. (but we only add this option if the application is not Tracker.) + // Add a 'Quit application' item if no windows are open + // unless the application is Tracker if (fApplicationSignature.ICompare(kTrackerSignature) != 0) { AddSeparatorItem(); AddItem(new TShowHideMenuItem(B_TRANSLATE("Quit application"), fTeam, B_QUIT_REQUESTED)); } } else { - // if we are in drag mode, then don't add the window controls - // to the menu + // Only add the window controls to the menu if we are in drag mode if (!dragging) { TShowHideMenuItem* hide = new TShowHideMenuItem(B_TRANSLATE("Hide all"), fTeam, diff --git a/src/apps/deskbar/WindowMenuItem.cpp b/src/apps/deskbar/WindowMenuItem.cpp index 3e2358521c..61e0ad0e03 100644 --- a/src/apps/deskbar/WindowMenuItem.cpp +++ b/src/apps/deskbar/WindowMenuItem.cpp @@ -39,6 +39,7 @@ All rights reserved. #include #include +#include #include "BarApp.h" #include "BarMenuBar.h" @@ -132,7 +133,7 @@ TWindowMenuItem::SetLabel(const char* string) Frame().Width() - contLoc.x - 3.0f); } - if (strcmp(Label(), truncatedTitle.String()) != 0) + if (strcasecmp(Label(), truncatedTitle.String()) != 0) BMenuItem::SetLabel(truncatedTitle.String()); } @@ -148,13 +149,18 @@ TWindowMenuItem::FullTitle() const TWindowMenuItem::InsertIndexFor(BMenu* menu, int32 startIndex, TWindowMenuItem* newItem) { - for (int32 index = startIndex;; index++) { + int32 index = 0; + + for (index = startIndex;; index++) { TWindowMenuItem* item = dynamic_cast(menu->ItemAt(index)); - if (item == NULL - || strcasecmp(item->FullTitle(), newItem->FullTitle()) > 0) + if (item == NULL || NaturalCompare(item->FullTitle(), + newItem->FullTitle()) > 0) return index; } + + // we should never get here + return index; }