From 481a903a81b32b77e6cc60c31c6b0e13b065c3fc Mon Sep 17 00:00:00 2001 From: Philippe Saint-Pierre Date: Sun, 31 Jan 2010 02:49:10 +0000 Subject: [PATCH] DeskBar: Adds a new setting (called ...Enabled) to determine if we show a particular Recent Menu. * the previous behaviour was to consider it enabled if the count was above 0, and disabled otherwise. * the new behaviour is to consider it disabled if the count is 0, but also allows to disable it by unchecking the box in the pref window, without setting the count to 0 (losing its value). Fixes ticket #5007. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35355 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/deskbar/BarApp.cpp | 25 +++++++++++++ src/apps/deskbar/BarApp.h | 4 +++ src/apps/deskbar/BeMenu.cpp | 18 ++++++---- src/apps/deskbar/BeMenu.h | 9 +++++ src/apps/deskbar/PreferencesWindow.cpp | 49 ++++++++------------------ 5 files changed, 64 insertions(+), 41 deletions(-) diff --git a/src/apps/deskbar/BarApp.cpp b/src/apps/deskbar/BarApp.cpp index 7890bf9dd1..0a0ad002dc 100644 --- a/src/apps/deskbar/BarApp.cpp +++ b/src/apps/deskbar/BarApp.cpp @@ -199,6 +199,9 @@ TBarApp::SaveSettings() fSettingsFile->Write(&fSettings.superExpando, sizeof(bool)); fSettingsFile->Write(&fSettings.expandNewTeams, sizeof(bool)); fSettingsFile->Write(&fSettings.autoRaise, sizeof(bool)); + fSettingsFile->Write(&fSettings.recentAppsEnabled, sizeof(bool)); + fSettingsFile->Write(&fSettings.recentDocsEnabled, sizeof(bool)); + fSettingsFile->Write(&fSettings.recentFoldersEnabled, sizeof(bool)); } } @@ -228,6 +231,9 @@ TBarApp::InitSettings() settings.superExpando = false; settings.expandNewTeams = false; settings.autoRaise = false; + settings.recentAppsEnabled = true; + settings.recentDocsEnabled = true; + settings.recentFoldersEnabled = true; BPath dirPath; const char* settingsFileName = "Deskbar_settings"; @@ -288,6 +294,16 @@ TBarApp::InitSettings() } if (size >= kValidSettingsSize10) fSettingsFile->Read(&settings.autoRaise, sizeof(bool)); + + if (size >= kValidSettingsSize11) { + fSettingsFile->Read(&settings.recentAppsEnabled, sizeof(bool)); + fSettingsFile->Read(&settings.recentDocsEnabled, sizeof(bool)); + fSettingsFile->Read(&settings.recentFoldersEnabled, sizeof(bool)); + } else { + settings.recentAppsEnabled = settings.recentAppsCount > 0; + settings.recentDocsEnabled = settings.recentDocsCount > 0; + settings.recentFoldersEnabled = settings.recentFoldersCount > 0; + } } } @@ -299,6 +315,7 @@ void TBarApp::MessageReceived(BMessage* message) { int32 count; + bool enabled; switch (message->what) { case 'gloc': case 'sloc': @@ -335,10 +352,18 @@ TBarApp::MessageReceived(BMessage* message) case kUpdateRecentCounts: if (message->FindInt32("applications", &count) == B_OK) fSettings.recentAppsCount = count; + if (message->FindBool("applicationsEnabled", &enabled) == B_OK) + fSettings.recentAppsEnabled = enabled && count > 0; + if (message->FindInt32("folders", &count) == B_OK) fSettings.recentFoldersCount = count; + if (message->FindBool("foldersEnabled", &enabled) == B_OK) + fSettings.recentFoldersEnabled = enabled && count > 0; + if (message->FindInt32("documents", &count) == B_OK) fSettings.recentDocsCount = count; + if (message->FindBool("documentsEnabled", &enabled) == B_OK) + fSettings.recentDocsEnabled = enabled && count > 0; break; case kConfigClose: diff --git a/src/apps/deskbar/BarApp.h b/src/apps/deskbar/BarApp.h index 577a5023b9..59650e4cce 100644 --- a/src/apps/deskbar/BarApp.h +++ b/src/apps/deskbar/BarApp.h @@ -112,6 +112,9 @@ struct desk_settings { bool superExpando; // version 9 bool expandNewTeams; bool autoRaise; // version 10 + bool recentAppsEnabled; // version 11 + bool recentDocsEnabled; + bool recentFoldersEnabled; }; // the following structures are defined to compute @@ -128,6 +131,7 @@ const uint32 kValidSettingsSize7 = sizeof(bool) + kValidSettingsSize6; const uint32 kValidSettingsSize8 = 2 * sizeof(bool) + kValidSettingsSize7; const uint32 kValidSettingsSize9 = 2 * sizeof(bool) + kValidSettingsSize8; const uint32 kValidSettingsSize10 = sizeof(bool) + kValidSettingsSize9; +const uint32 kValidSettingsSize11 = 3 * sizeof(bool) + kValidSettingsSize10; class TBarView; class BFile; diff --git a/src/apps/deskbar/BeMenu.cpp b/src/apps/deskbar/BeMenu.cpp index 703e1792e1..82f84efcc0 100644 --- a/src/apps/deskbar/BeMenu.cpp +++ b/src/apps/deskbar/BeMenu.cpp @@ -155,23 +155,24 @@ TBeMenu::AddNextItem() kRecentApplications}; const int recentTypes = 3; TRecentsMenu* recentItem[recentTypes]; - int count = 0; + + bool enabled = false; for (int i = 0; i < recentTypes; i++) { recentItem[i] = new TRecentsMenu(recentTitle[i], fBarView, recentType[i]); if (recentItem[i]) - count += recentItem[i]->RecentsCount(); + enabled |= recentItem[i]->RecentsEnabled(); } - if (count > 0) { + if (enabled) { AddSeparatorItem(); - for (int i = 0;i < recentTypes;i++) { + for (int i = 0; i < recentTypes; i++) { if (!recentItem[i]) continue; - if (recentItem[i]->RecentsCount() > 0) { + if (recentItem[i]->RecentsEnabled()) { recentItem[i]->SetTypesList(TypesList()); recentItem[i]->SetTarget(Target()); AddItem(recentItem[i]); @@ -391,6 +392,7 @@ TRecentsMenu::TRecentsMenu(const char* name, TBarView* bar, int32 which, fAppRef(NULL), fSignature(NULL), fRecentsCount(0), + fRecentsEnabled(false), fItemIndex(0), fBarView(bar) { @@ -401,12 +403,15 @@ TRecentsMenu::TRecentsMenu(const char* name, TBarView* bar, int32 which, switch (which) { case kRecentDocuments: fRecentsCount = app->Settings()->recentDocsCount; + fRecentsEnabled = app->Settings()->recentDocsEnabled; break; case kRecentApplications: fRecentsCount = app->Settings()->recentAppsCount; + fRecentsEnabled = app->Settings()->recentAppsEnabled; break; case kRecentAppDocuments: fRecentsCount = app->Settings()->recentDocsCount; + fRecentsEnabled = app->Settings()->recentDocsEnabled; if (signature != NULL) fSignature = strdup(signature); if (appRef != NULL) @@ -414,6 +419,7 @@ TRecentsMenu::TRecentsMenu(const char* name, TBarView* bar, int32 which, break; case kRecentFolders: fRecentsCount = app->Settings()->recentFoldersCount; + fRecentsEnabled = app->Settings()->recentFoldersEnabled; break; } } @@ -454,7 +460,7 @@ TRecentsMenu::StartBuildingItemList() bool TRecentsMenu::AddNextItem() { - if (fRecentsCount > 0 && AddRecents(fRecentsCount)) + if (fRecentsCount > 0 && fRecentsEnabled && AddRecents(fRecentsCount)) return true; fItemIndex = 0; diff --git a/src/apps/deskbar/BeMenu.h b/src/apps/deskbar/BeMenu.h index 26cc059c2e..276275d709 100644 --- a/src/apps/deskbar/BeMenu.h +++ b/src/apps/deskbar/BeMenu.h @@ -58,6 +58,7 @@ class TRecentsMenu : public BNavMenu { void ResetTargets(); int32 RecentsCount(); + bool RecentsEnabled(); private: virtual bool StartBuildingItemList(); @@ -71,6 +72,7 @@ class TRecentsMenu : public BNavMenu { entry_ref *fAppRef; char *fSignature; int32 fRecentsCount; + bool fRecentsEnabled; int32 fItemIndex; BMessage fRecentList; @@ -86,6 +88,13 @@ TRecentsMenu::RecentsCount() } +inline bool +TRecentsMenu::RecentsEnabled() +{ + return fRecentsEnabled; +} + + class TBeMenu : public BNavMenu { public: TBeMenu(TBarView* bar); diff --git a/src/apps/deskbar/PreferencesWindow.cpp b/src/apps/deskbar/PreferencesWindow.cpp index c291445f57..e6e89b2390 100644 --- a/src/apps/deskbar/PreferencesWindow.cpp +++ b/src/apps/deskbar/PreferencesWindow.cpp @@ -87,32 +87,18 @@ PreferencesWindow::PreferencesWindow(BRect frame) fAppsShowExpanders->SetValue(appSettings->superExpando); fAppsExpandNew->SetValue(appSettings->expandNewTeams); - fMenuRecentDocuments->SetValue(false); - fMenuRecentApplications->SetValue(false); - fMenuRecentFolders->SetValue(false); - - fMenuRecentDocumentCount->SetEnabled(false); - fMenuRecentApplicationCount->SetEnabled(false); - fMenuRecentFolderCount->SetEnabled(false); - int32 docCount = appSettings->recentDocsCount; int32 appCount = appSettings->recentAppsCount; int32 folderCount = appSettings->recentFoldersCount; - if (docCount > 0) { - fMenuRecentDocuments->SetValue(true); - fMenuRecentDocumentCount->SetEnabled(true); - } - - if (appCount > 0) { - fMenuRecentApplications->SetValue(true); - fMenuRecentApplicationCount->SetEnabled(true); - } - - if (folderCount > 0) { - fMenuRecentFolders->SetValue(true); - fMenuRecentFolderCount->SetEnabled(true); - } + fMenuRecentDocuments->SetValue(appSettings->recentDocsEnabled); + fMenuRecentDocumentCount->SetEnabled(appSettings->recentDocsEnabled); + + fMenuRecentApplications->SetValue(appSettings->recentAppsEnabled); + fMenuRecentApplicationCount->SetEnabled(appSettings->recentAppsEnabled); + + fMenuRecentFolders->SetValue(appSettings->recentFoldersEnabled); + fMenuRecentFolderCount->SetEnabled(appSettings->recentFoldersEnabled); BString docString; BString appString; @@ -281,20 +267,13 @@ PreferencesWindow::_UpdateRecentCounts() int32 appCount = atoi(fMenuRecentApplicationCount->Text()); int32 folderCount = atoi(fMenuRecentFolderCount->Text()); - if (docCount <= 0 || fMenuRecentDocuments->Value() == false) - message.AddInt32("documents", 0); - else - message.AddInt32("documents", docCount); + message.AddInt32("documents", max_c(0, docCount)); + message.AddInt32("applications", max_c(0, appCount)); + message.AddInt32("folders", max_c(0, folderCount)); - if (appCount <= 0 || fMenuRecentApplications->Value() == false) - message.AddInt32("applications", 0); - else - message.AddInt32("applications", appCount); - - if (folderCount <= 0 || fMenuRecentFolders->Value() == false) - message.AddInt32("folders", 0); - else - message.AddInt32("folders", folderCount); + message.AddBool("documentsEnabled", fMenuRecentDocuments->Value()); + message.AddBool("applicationsEnabled", fMenuRecentApplications->Value()); + message.AddBool("foldersEnabled", fMenuRecentFolders->Value()); be_app->PostMessage(&message);