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
This commit is contained in:
John Scipione 2011-11-06 03:19:15 +00:00
parent fdb0863fbe
commit 7eb3210e8f
6 changed files with 30 additions and 23 deletions

View File

@ -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())

View File

@ -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);

View File

@ -33,9 +33,10 @@ holders.
All rights reserved.
*/
#include <Debug.h>
#include <string.h>
#include <Application.h>
#include <Debug.h>
#include <Roster.h>
#include "BarApp.h"

View File

@ -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 */

View File

@ -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<TWindowMenuItem*>(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,

View File

@ -39,6 +39,7 @@ All rights reserved.
#include <Bitmap.h>
#include <Debug.h>
#include <NaturalCompare.h>
#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<TWindowMenuItem*>(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;
}