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
This commit is contained in:
Philippe Saint-Pierre
2010-01-31 02:49:10 +00:00
parent 83c03b5698
commit 481a903a81
5 changed files with 64 additions and 41 deletions
+25
View File
@@ -199,6 +199,9 @@ TBarApp::SaveSettings()
fSettingsFile->Write(&fSettings.superExpando, sizeof(bool)); fSettingsFile->Write(&fSettings.superExpando, sizeof(bool));
fSettingsFile->Write(&fSettings.expandNewTeams, sizeof(bool)); fSettingsFile->Write(&fSettings.expandNewTeams, sizeof(bool));
fSettingsFile->Write(&fSettings.autoRaise, 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.superExpando = false;
settings.expandNewTeams = false; settings.expandNewTeams = false;
settings.autoRaise = false; settings.autoRaise = false;
settings.recentAppsEnabled = true;
settings.recentDocsEnabled = true;
settings.recentFoldersEnabled = true;
BPath dirPath; BPath dirPath;
const char* settingsFileName = "Deskbar_settings"; const char* settingsFileName = "Deskbar_settings";
@@ -288,6 +294,16 @@ TBarApp::InitSettings()
} }
if (size >= kValidSettingsSize10) if (size >= kValidSettingsSize10)
fSettingsFile->Read(&settings.autoRaise, sizeof(bool)); 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) TBarApp::MessageReceived(BMessage* message)
{ {
int32 count; int32 count;
bool enabled;
switch (message->what) { switch (message->what) {
case 'gloc': case 'gloc':
case 'sloc': case 'sloc':
@@ -335,10 +352,18 @@ TBarApp::MessageReceived(BMessage* message)
case kUpdateRecentCounts: case kUpdateRecentCounts:
if (message->FindInt32("applications", &count) == B_OK) if (message->FindInt32("applications", &count) == B_OK)
fSettings.recentAppsCount = count; fSettings.recentAppsCount = count;
if (message->FindBool("applicationsEnabled", &enabled) == B_OK)
fSettings.recentAppsEnabled = enabled && count > 0;
if (message->FindInt32("folders", &count) == B_OK) if (message->FindInt32("folders", &count) == B_OK)
fSettings.recentFoldersCount = count; fSettings.recentFoldersCount = count;
if (message->FindBool("foldersEnabled", &enabled) == B_OK)
fSettings.recentFoldersEnabled = enabled && count > 0;
if (message->FindInt32("documents", &count) == B_OK) if (message->FindInt32("documents", &count) == B_OK)
fSettings.recentDocsCount = count; fSettings.recentDocsCount = count;
if (message->FindBool("documentsEnabled", &enabled) == B_OK)
fSettings.recentDocsEnabled = enabled && count > 0;
break; break;
case kConfigClose: case kConfigClose:
+4
View File
@@ -112,6 +112,9 @@ struct desk_settings {
bool superExpando; // version 9 bool superExpando; // version 9
bool expandNewTeams; bool expandNewTeams;
bool autoRaise; // version 10 bool autoRaise; // version 10
bool recentAppsEnabled; // version 11
bool recentDocsEnabled;
bool recentFoldersEnabled;
}; };
// the following structures are defined to compute // 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 kValidSettingsSize8 = 2 * sizeof(bool) + kValidSettingsSize7;
const uint32 kValidSettingsSize9 = 2 * sizeof(bool) + kValidSettingsSize8; const uint32 kValidSettingsSize9 = 2 * sizeof(bool) + kValidSettingsSize8;
const uint32 kValidSettingsSize10 = sizeof(bool) + kValidSettingsSize9; const uint32 kValidSettingsSize10 = sizeof(bool) + kValidSettingsSize9;
const uint32 kValidSettingsSize11 = 3 * sizeof(bool) + kValidSettingsSize10;
class TBarView; class TBarView;
class BFile; class BFile;
+12 -6
View File
@@ -155,23 +155,24 @@ TBeMenu::AddNextItem()
kRecentApplications}; kRecentApplications};
const int recentTypes = 3; const int recentTypes = 3;
TRecentsMenu* recentItem[recentTypes]; TRecentsMenu* recentItem[recentTypes];
int count = 0;
bool enabled = false;
for (int i = 0; i < recentTypes; i++) { for (int i = 0; i < recentTypes; i++) {
recentItem[i] = new TRecentsMenu(recentTitle[i], fBarView, recentItem[i] = new TRecentsMenu(recentTitle[i], fBarView,
recentType[i]); recentType[i]);
if (recentItem[i]) if (recentItem[i])
count += recentItem[i]->RecentsCount(); enabled |= recentItem[i]->RecentsEnabled();
} }
if (count > 0) { if (enabled) {
AddSeparatorItem(); AddSeparatorItem();
for (int i = 0;i < recentTypes;i++) { for (int i = 0; i < recentTypes; i++) {
if (!recentItem[i]) if (!recentItem[i])
continue; continue;
if (recentItem[i]->RecentsCount() > 0) { if (recentItem[i]->RecentsEnabled()) {
recentItem[i]->SetTypesList(TypesList()); recentItem[i]->SetTypesList(TypesList());
recentItem[i]->SetTarget(Target()); recentItem[i]->SetTarget(Target());
AddItem(recentItem[i]); AddItem(recentItem[i]);
@@ -391,6 +392,7 @@ TRecentsMenu::TRecentsMenu(const char* name, TBarView* bar, int32 which,
fAppRef(NULL), fAppRef(NULL),
fSignature(NULL), fSignature(NULL),
fRecentsCount(0), fRecentsCount(0),
fRecentsEnabled(false),
fItemIndex(0), fItemIndex(0),
fBarView(bar) fBarView(bar)
{ {
@@ -401,12 +403,15 @@ TRecentsMenu::TRecentsMenu(const char* name, TBarView* bar, int32 which,
switch (which) { switch (which) {
case kRecentDocuments: case kRecentDocuments:
fRecentsCount = app->Settings()->recentDocsCount; fRecentsCount = app->Settings()->recentDocsCount;
fRecentsEnabled = app->Settings()->recentDocsEnabled;
break; break;
case kRecentApplications: case kRecentApplications:
fRecentsCount = app->Settings()->recentAppsCount; fRecentsCount = app->Settings()->recentAppsCount;
fRecentsEnabled = app->Settings()->recentAppsEnabled;
break; break;
case kRecentAppDocuments: case kRecentAppDocuments:
fRecentsCount = app->Settings()->recentDocsCount; fRecentsCount = app->Settings()->recentDocsCount;
fRecentsEnabled = app->Settings()->recentDocsEnabled;
if (signature != NULL) if (signature != NULL)
fSignature = strdup(signature); fSignature = strdup(signature);
if (appRef != NULL) if (appRef != NULL)
@@ -414,6 +419,7 @@ TRecentsMenu::TRecentsMenu(const char* name, TBarView* bar, int32 which,
break; break;
case kRecentFolders: case kRecentFolders:
fRecentsCount = app->Settings()->recentFoldersCount; fRecentsCount = app->Settings()->recentFoldersCount;
fRecentsEnabled = app->Settings()->recentFoldersEnabled;
break; break;
} }
} }
@@ -454,7 +460,7 @@ TRecentsMenu::StartBuildingItemList()
bool bool
TRecentsMenu::AddNextItem() TRecentsMenu::AddNextItem()
{ {
if (fRecentsCount > 0 && AddRecents(fRecentsCount)) if (fRecentsCount > 0 && fRecentsEnabled && AddRecents(fRecentsCount))
return true; return true;
fItemIndex = 0; fItemIndex = 0;
+9
View File
@@ -58,6 +58,7 @@ class TRecentsMenu : public BNavMenu {
void ResetTargets(); void ResetTargets();
int32 RecentsCount(); int32 RecentsCount();
bool RecentsEnabled();
private: private:
virtual bool StartBuildingItemList(); virtual bool StartBuildingItemList();
@@ -71,6 +72,7 @@ class TRecentsMenu : public BNavMenu {
entry_ref *fAppRef; entry_ref *fAppRef;
char *fSignature; char *fSignature;
int32 fRecentsCount; int32 fRecentsCount;
bool fRecentsEnabled;
int32 fItemIndex; int32 fItemIndex;
BMessage fRecentList; BMessage fRecentList;
@@ -86,6 +88,13 @@ TRecentsMenu::RecentsCount()
} }
inline bool
TRecentsMenu::RecentsEnabled()
{
return fRecentsEnabled;
}
class TBeMenu : public BNavMenu { class TBeMenu : public BNavMenu {
public: public:
TBeMenu(TBarView* bar); TBeMenu(TBarView* bar);
+14 -35
View File
@@ -87,32 +87,18 @@ PreferencesWindow::PreferencesWindow(BRect frame)
fAppsShowExpanders->SetValue(appSettings->superExpando); fAppsShowExpanders->SetValue(appSettings->superExpando);
fAppsExpandNew->SetValue(appSettings->expandNewTeams); 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 docCount = appSettings->recentDocsCount;
int32 appCount = appSettings->recentAppsCount; int32 appCount = appSettings->recentAppsCount;
int32 folderCount = appSettings->recentFoldersCount; int32 folderCount = appSettings->recentFoldersCount;
if (docCount > 0) { fMenuRecentDocuments->SetValue(appSettings->recentDocsEnabled);
fMenuRecentDocuments->SetValue(true); fMenuRecentDocumentCount->SetEnabled(appSettings->recentDocsEnabled);
fMenuRecentDocumentCount->SetEnabled(true);
} fMenuRecentApplications->SetValue(appSettings->recentAppsEnabled);
fMenuRecentApplicationCount->SetEnabled(appSettings->recentAppsEnabled);
if (appCount > 0) {
fMenuRecentApplications->SetValue(true); fMenuRecentFolders->SetValue(appSettings->recentFoldersEnabled);
fMenuRecentApplicationCount->SetEnabled(true); fMenuRecentFolderCount->SetEnabled(appSettings->recentFoldersEnabled);
}
if (folderCount > 0) {
fMenuRecentFolders->SetValue(true);
fMenuRecentFolderCount->SetEnabled(true);
}
BString docString; BString docString;
BString appString; BString appString;
@@ -281,20 +267,13 @@ PreferencesWindow::_UpdateRecentCounts()
int32 appCount = atoi(fMenuRecentApplicationCount->Text()); int32 appCount = atoi(fMenuRecentApplicationCount->Text());
int32 folderCount = atoi(fMenuRecentFolderCount->Text()); int32 folderCount = atoi(fMenuRecentFolderCount->Text());
if (docCount <= 0 || fMenuRecentDocuments->Value() == false) message.AddInt32("documents", max_c(0, docCount));
message.AddInt32("documents", 0); message.AddInt32("applications", max_c(0, appCount));
else message.AddInt32("folders", max_c(0, folderCount));
message.AddInt32("documents", docCount);
if (appCount <= 0 || fMenuRecentApplications->Value() == false) message.AddBool("documentsEnabled", fMenuRecentDocuments->Value());
message.AddInt32("applications", 0); message.AddBool("applicationsEnabled", fMenuRecentApplications->Value());
else message.AddBool("foldersEnabled", fMenuRecentFolders->Value());
message.AddInt32("applications", appCount);
if (folderCount <= 0 || fMenuRecentFolders->Value() == false)
message.AddInt32("folders", 0);
else
message.AddInt32("folders", folderCount);
be_app->PostMessage(&message); be_app->PostMessage(&message);