Refactor settings so that defaults get set in 1 place.
* Move desk_settings and clock_settings struct to a new header entitled 'BarSettings.h' so it can be included in BarApp.h and PreferencesWindow.h. * Refactor desk_settings to only include used, or at least relevant settings, some cruft had built up over time. * Refactor the InitSettings() method, all the B_OK checking wasn't working so I removed it. Defaults get set up to and if the corresponding setting is found in the settings file it is replaced, else, it is not. * Reorder the struct and code so it goes in the order that the settings appear: applications, then recent items, then window settings. * Simplify the preferences window revert and defaults code based on using the prebuild desk_settings structs in BarApp instead of creating our own and copying. All initial setup is in the constructor.
This commit is contained in:
parent
cb42238603
commit
43917ef2e0
@ -192,20 +192,15 @@ TBarApp::SaveSettings()
|
||||
if (fSettingsFile->InitCheck() == B_OK) {
|
||||
fSettingsFile->Seek(0, SEEK_SET);
|
||||
BMessage storedSettings;
|
||||
|
||||
storedSettings.AddBool("vertical", fSettings.vertical);
|
||||
storedSettings.AddBool("left", fSettings.left);
|
||||
storedSettings.AddBool("top", fSettings.top);
|
||||
storedSettings.AddInt32("state", fSettings.state);
|
||||
storedSettings.AddUInt32("state", fSettings.state);
|
||||
storedSettings.AddFloat("width", fSettings.width);
|
||||
storedSettings.AddBool("showClock", fSettings.showClock);
|
||||
storedSettings.AddPoint("switcherLoc", fSettings.switcherLoc);
|
||||
storedSettings.AddInt32("recentAppsCount", fSettings.recentAppsCount);
|
||||
storedSettings.AddInt32("recentDocsCount", fSettings.recentDocsCount);
|
||||
storedSettings.AddBool("timeShowSeconds", fSettings.timeShowSeconds);
|
||||
storedSettings.AddInt32("recentFoldersCount",
|
||||
fSettings.recentFoldersCount);
|
||||
storedSettings.AddBool("alwaysOnTop", fSettings.alwaysOnTop);
|
||||
storedSettings.AddBool("timeFullDate", fSettings.timeFullDate);
|
||||
storedSettings.AddBool("showClock", fSettings.showClock);
|
||||
// applications
|
||||
storedSettings.AddBool("trackerAlwaysFirst",
|
||||
fSettings.trackerAlwaysFirst);
|
||||
storedSettings.AddBool("sortRunningApps", fSettings.sortRunningApps);
|
||||
@ -213,14 +208,23 @@ TBarApp::SaveSettings()
|
||||
storedSettings.AddBool("expandNewTeams", fSettings.expandNewTeams);
|
||||
storedSettings.AddBool("hideLabels", fSettings.hideLabels);
|
||||
storedSettings.AddInt32("iconSize", fSettings.iconSize);
|
||||
storedSettings.AddBool("autoRaise", fSettings.autoRaise);
|
||||
storedSettings.AddBool("autoHide", fSettings.autoHide);
|
||||
storedSettings.AddBool("recentAppsEnabled",
|
||||
fSettings.recentAppsEnabled);
|
||||
// recent items
|
||||
storedSettings.AddBool("recentDocsEnabled",
|
||||
fSettings.recentDocsEnabled);
|
||||
storedSettings.AddBool("recentFoldersEnabled",
|
||||
fSettings.recentFoldersEnabled);
|
||||
storedSettings.AddBool("recentAppsEnabled",
|
||||
fSettings.recentAppsEnabled);
|
||||
storedSettings.AddInt32("recentDocsCount",
|
||||
fSettings.recentDocsCount);
|
||||
storedSettings.AddInt32("recentFoldersCount",
|
||||
fSettings.recentFoldersCount);
|
||||
storedSettings.AddInt32("recentAppsCount",
|
||||
fSettings.recentAppsCount);
|
||||
// window
|
||||
storedSettings.AddBool("alwaysOnTop", fSettings.alwaysOnTop);
|
||||
storedSettings.AddBool("autoRaise", fSettings.autoRaise);
|
||||
storedSettings.AddBool("autoHide", fSettings.autoHide);
|
||||
|
||||
storedSettings.Flatten(fSettingsFile);
|
||||
}
|
||||
@ -245,30 +249,32 @@ void
|
||||
TBarApp::InitSettings()
|
||||
{
|
||||
desk_settings settings;
|
||||
settings.vertical = true;
|
||||
settings.left = false;
|
||||
settings.top = true;
|
||||
settings.state = kExpandoState;
|
||||
settings.width = 0;
|
||||
settings.showClock = true;
|
||||
settings.switcherLoc = BPoint(5000, 5000);
|
||||
settings.recentAppsCount = 10;
|
||||
settings.recentDocsCount = 10;
|
||||
settings.timeShowSeconds = false;
|
||||
settings.recentFoldersCount = 10;
|
||||
settings.alwaysOnTop = false;
|
||||
settings.timeFullDate = false;
|
||||
settings.trackerAlwaysFirst = false;
|
||||
settings.sortRunningApps = false;
|
||||
settings.superExpando = false;
|
||||
settings.expandNewTeams = false;
|
||||
settings.hideLabels = false;
|
||||
settings.iconSize = kMinimumIconSize;
|
||||
settings.autoRaise = false;
|
||||
settings.autoHide = false;
|
||||
settings.recentAppsEnabled = true;
|
||||
settings.recentDocsEnabled = true;
|
||||
settings.recentFoldersEnabled = true;
|
||||
settings.vertical = fDefaultSettings.vertical = true;
|
||||
settings.left = fDefaultSettings.left = false;
|
||||
settings.top = fDefaultSettings.top = true;
|
||||
settings.state = fDefaultSettings.state = kExpandoState;
|
||||
settings.width = fDefaultSettings.width = 0;
|
||||
settings.switcherLoc = fDefaultSettings.switcherLoc = BPoint(5000, 5000);
|
||||
settings.showClock = fDefaultSettings.showClock = true;
|
||||
// applications
|
||||
settings.trackerAlwaysFirst = fDefaultSettings.trackerAlwaysFirst = false;
|
||||
settings.sortRunningApps = fDefaultSettings.sortRunningApps = false;
|
||||
settings.superExpando = fDefaultSettings.superExpando = false;
|
||||
settings.expandNewTeams = fDefaultSettings.expandNewTeams = false;
|
||||
settings.hideLabels = fDefaultSettings.hideLabels = false;
|
||||
settings.iconSize = fDefaultSettings.iconSize = kMinimumIconSize;
|
||||
// recent items
|
||||
settings.recentDocsEnabled = fDefaultSettings.recentDocsEnabled = true;
|
||||
settings.recentFoldersEnabled
|
||||
= fDefaultSettings.recentFoldersEnabled = true;
|
||||
settings.recentAppsEnabled = fDefaultSettings.recentAppsEnabled = true;
|
||||
settings.recentDocsCount = fDefaultSettings.recentDocsCount = 10;
|
||||
settings.recentFoldersCount = fDefaultSettings.recentFoldersCount = 10;
|
||||
settings.recentAppsCount = fDefaultSettings.recentAppsCount = 10;
|
||||
// window
|
||||
settings.alwaysOnTop = fDefaultSettings.alwaysOnTop = false;
|
||||
settings.autoRaise = fDefaultSettings.autoRaise = false;
|
||||
settings.autoHide = fDefaultSettings.autoHide = false;
|
||||
|
||||
clock_settings clock;
|
||||
clock.showSeconds = false;
|
||||
@ -292,6 +298,45 @@ TBarApp::InitSettings()
|
||||
theDir.CreateFile(settingsFileName, fSettingsFile);
|
||||
}
|
||||
|
||||
BMessage storedSettings;
|
||||
if (fSettingsFile->InitCheck() == B_OK
|
||||
&& storedSettings.Unflatten(fSettingsFile) == B_OK) {
|
||||
storedSettings.FindBool("vertical", &settings.vertical);
|
||||
storedSettings.FindBool("left", &settings.left);
|
||||
storedSettings.FindBool("top", &settings.top);
|
||||
storedSettings.FindUInt32("state", &settings.state);
|
||||
storedSettings.FindFloat("width", &settings.width);
|
||||
storedSettings.FindPoint("switcherLoc", &settings.switcherLoc);
|
||||
storedSettings.FindBool("showClock", &settings.showClock);
|
||||
// applications
|
||||
storedSettings.FindBool("trackerAlwaysFirst",
|
||||
&settings.trackerAlwaysFirst);
|
||||
storedSettings.FindBool("sortRunningApps",
|
||||
&settings.sortRunningApps);
|
||||
storedSettings.FindBool("superExpando", &settings.superExpando);
|
||||
storedSettings.FindBool("expandNewTeams",
|
||||
&settings.expandNewTeams);
|
||||
storedSettings.FindBool("hideLabels", &settings.hideLabels);
|
||||
storedSettings.FindInt32("iconSize", &settings.iconSize);
|
||||
// recent items
|
||||
storedSettings.FindBool("recentDocsEnabled",
|
||||
&settings.recentDocsEnabled);
|
||||
storedSettings.FindBool("recentFoldersEnabled",
|
||||
&settings.recentFoldersEnabled);
|
||||
storedSettings.FindBool("recentAppsEnabled",
|
||||
&settings.recentAppsEnabled);
|
||||
storedSettings.FindInt32("recentDocsCount",
|
||||
&settings.recentDocsCount);
|
||||
storedSettings.FindInt32("recentFoldersCount",
|
||||
&settings.recentFoldersCount);
|
||||
storedSettings.FindInt32("recentAppsCount",
|
||||
&settings.recentAppsCount);
|
||||
// window
|
||||
storedSettings.FindBool("alwaysOnTop", &settings.alwaysOnTop);
|
||||
storedSettings.FindBool("autoRaise", &settings.autoRaise);
|
||||
storedSettings.FindBool("autoHide", &settings.autoHide);
|
||||
}
|
||||
|
||||
filePath = dirPath;
|
||||
filePath.Append(clockSettingsFileName);
|
||||
fClockSettingsFile = new BFile(filePath.Path(), O_RDWR);
|
||||
@ -301,113 +346,11 @@ TBarApp::InitSettings()
|
||||
theDir.CreateFile(clockSettingsFileName, fClockSettingsFile);
|
||||
}
|
||||
|
||||
BMessage storedSettings;
|
||||
if (fSettingsFile->InitCheck() == B_OK
|
||||
&& storedSettings.Unflatten(fSettingsFile) == B_OK) {
|
||||
if (storedSettings.FindBool("vertical", &settings.vertical)
|
||||
!= B_OK) {
|
||||
settings.vertical = true;
|
||||
}
|
||||
if (storedSettings.FindBool("left", &settings.left) != B_OK)
|
||||
settings.left = false;
|
||||
if (storedSettings.FindBool("top", &settings.top) != B_OK)
|
||||
settings.top = true;
|
||||
if (storedSettings.FindInt32("state", (int32*)&settings.state)
|
||||
!= B_OK) {
|
||||
settings.state = kExpandoState;
|
||||
}
|
||||
if (storedSettings.FindFloat("width", &settings.width) != B_OK)
|
||||
settings.width = 0;
|
||||
if (storedSettings.FindBool("showClock", &settings.showClock)
|
||||
!= B_OK) {
|
||||
settings.showClock = true;
|
||||
}
|
||||
if (storedSettings.FindPoint("switcherLoc", &settings.switcherLoc)
|
||||
!= B_OK) {
|
||||
settings.switcherLoc = BPoint(5000, 5000);
|
||||
}
|
||||
if (storedSettings.FindInt32("recentAppsCount",
|
||||
&settings.recentAppsCount) != B_OK) {
|
||||
settings.recentAppsCount = 10;
|
||||
}
|
||||
if (storedSettings.FindInt32("recentDocsCount",
|
||||
&settings.recentDocsCount) != B_OK) {
|
||||
settings.recentDocsCount = 10;
|
||||
}
|
||||
if (storedSettings.FindBool("timeShowSeconds",
|
||||
&settings.timeShowSeconds) != B_OK) {
|
||||
settings.timeShowSeconds = false;
|
||||
}
|
||||
if (storedSettings.FindInt32("recentFoldersCount",
|
||||
&settings.recentFoldersCount) != B_OK) {
|
||||
settings.recentFoldersCount = 10;
|
||||
}
|
||||
if (storedSettings.FindBool("alwaysOnTop", &settings.alwaysOnTop)
|
||||
!= B_OK) {
|
||||
settings.alwaysOnTop = false;
|
||||
}
|
||||
if (storedSettings.FindBool("timeFullDate", &settings.timeFullDate)
|
||||
!= B_OK) {
|
||||
settings.timeFullDate = false;
|
||||
}
|
||||
if (storedSettings.FindBool("trackerAlwaysFirst",
|
||||
&settings.trackerAlwaysFirst) != B_OK) {
|
||||
settings.trackerAlwaysFirst = false;
|
||||
}
|
||||
if (storedSettings.FindBool("sortRunningApps",
|
||||
&settings.sortRunningApps) != B_OK) {
|
||||
settings.sortRunningApps = false;
|
||||
}
|
||||
if (storedSettings.FindBool("superExpando", &settings.superExpando)
|
||||
!= B_OK) {
|
||||
settings.superExpando = false;
|
||||
}
|
||||
if (storedSettings.FindBool("expandNewTeams",
|
||||
&settings.expandNewTeams) != B_OK) {
|
||||
settings.expandNewTeams = false;
|
||||
}
|
||||
if (storedSettings.FindBool("hideLabels", &settings.hideLabels)
|
||||
!= B_OK) {
|
||||
settings.hideLabels = false;
|
||||
}
|
||||
if (storedSettings.FindInt32("iconSize", (int32*)&settings.iconSize)
|
||||
!= B_OK) {
|
||||
settings.iconSize = kMinimumIconSize;
|
||||
}
|
||||
if (storedSettings.FindBool("autoRaise", &settings.autoRaise)
|
||||
!= B_OK) {
|
||||
settings.autoRaise = false;
|
||||
}
|
||||
if (storedSettings.FindBool("autoHide", &settings.autoHide) != B_OK)
|
||||
settings.autoHide = false;
|
||||
if (storedSettings.FindBool("recentAppsEnabled",
|
||||
&settings.recentAppsEnabled) != B_OK) {
|
||||
settings.recentAppsEnabled = true;
|
||||
}
|
||||
if (storedSettings.FindBool("recentDocsEnabled",
|
||||
&settings.recentDocsEnabled) != B_OK) {
|
||||
settings.recentDocsEnabled = true;
|
||||
}
|
||||
if (storedSettings.FindBool("recentFoldersEnabled",
|
||||
&settings.recentFoldersEnabled) != B_OK) {
|
||||
settings.recentFoldersEnabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (fClockSettingsFile->InitCheck() == B_OK
|
||||
&& storedSettings.Unflatten(fClockSettingsFile) == B_OK) {
|
||||
if (storedSettings.FindBool("showSeconds", &clock.showSeconds)
|
||||
!= B_OK) {
|
||||
clock.showSeconds = false;
|
||||
}
|
||||
if (storedSettings.FindBool("showDayOfWeek",
|
||||
&clock.showDayOfWeek) != B_OK) {
|
||||
clock.showDayOfWeek = false;
|
||||
}
|
||||
if (storedSettings.FindBool("showTimeZone",
|
||||
&clock.showTimeZone) != B_OK) {
|
||||
clock.showDayOfWeek = false;
|
||||
}
|
||||
storedSettings.FindBool("showSeconds", &clock.showSeconds);
|
||||
storedSettings.FindBool("showDayOfWeek", &clock.showDayOfWeek);
|
||||
storedSettings.FindBool("showTimeZone", &clock.showTimeZone);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,6 +38,9 @@ All rights reserved.
|
||||
|
||||
#include <Application.h>
|
||||
|
||||
#include "BarSettings.h"
|
||||
|
||||
|
||||
/* ------------------------------------ */
|
||||
// Private app_server defines that I need to use
|
||||
|
||||
@ -74,40 +77,6 @@ const uint32 kUpdatePreferences = 'Pref';
|
||||
|
||||
/* --------------------------------------------- */
|
||||
|
||||
struct desk_settings {
|
||||
bool vertical;
|
||||
bool left;
|
||||
bool top;
|
||||
uint32 state;
|
||||
float width;
|
||||
bool showClock;
|
||||
BPoint switcherLoc;
|
||||
int32 recentAppsCount;
|
||||
int32 recentDocsCount;
|
||||
bool timeShowSeconds;
|
||||
int32 recentFoldersCount;
|
||||
bool alwaysOnTop;
|
||||
bool timeFullDate;
|
||||
bool trackerAlwaysFirst;
|
||||
bool sortRunningApps;
|
||||
bool superExpando;
|
||||
bool expandNewTeams;
|
||||
bool hideLabels;
|
||||
int32 iconSize;
|
||||
bool autoRaise;
|
||||
bool autoHide;
|
||||
bool recentAppsEnabled;
|
||||
bool recentDocsEnabled;
|
||||
bool recentFoldersEnabled;
|
||||
};
|
||||
|
||||
struct clock_settings {
|
||||
bool showSeconds;
|
||||
bool showDayOfWeek;
|
||||
bool showTimeZone;
|
||||
};
|
||||
|
||||
|
||||
class BFile;
|
||||
class BList;
|
||||
class BBitmap;
|
||||
@ -139,6 +108,8 @@ public:
|
||||
virtual void RefsReceived(BMessage* refs);
|
||||
|
||||
desk_settings* Settings() { return &fSettings; }
|
||||
desk_settings* DefaultSettings()
|
||||
{ return &fDefaultSettings; }
|
||||
clock_settings* ClockSettings() { return &fClockSettings; }
|
||||
|
||||
TBarView* BarView() const { return fBarView; }
|
||||
@ -166,6 +137,8 @@ private:
|
||||
BBitmap* icon);
|
||||
|
||||
BRect IconRect();
|
||||
|
||||
private:
|
||||
TBarWindow* fBarWindow;
|
||||
TBarView* fBarView;
|
||||
BMessenger fSwitcherMessenger;
|
||||
@ -173,6 +146,7 @@ private:
|
||||
BFile* fSettingsFile;
|
||||
BFile* fClockSettingsFile;
|
||||
desk_settings fSettings;
|
||||
desk_settings fDefaultSettings;
|
||||
clock_settings fClockSettings;
|
||||
PreferencesWindow* fPreferencesWindow;
|
||||
|
||||
@ -182,4 +156,4 @@ private:
|
||||
};
|
||||
|
||||
|
||||
#endif /* BAR_APP_H */
|
||||
#endif // BAR_APP_H
|
||||
|
74
src/apps/deskbar/BarSettings.h
Normal file
74
src/apps/deskbar/BarSettings.h
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
Open Tracker License
|
||||
|
||||
Terms and Conditions
|
||||
|
||||
Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice applies to all licensees
|
||||
and shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the name of Be Incorporated shall not be
|
||||
used in advertising or otherwise to promote the sale, use or other dealings in
|
||||
this Software without prior written authorization from Be Incorporated.
|
||||
|
||||
Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered
|
||||
trademarks of Be Incorporated in the United States and other countries. Other
|
||||
brand product names are registered trademarks or trademarks of their respective
|
||||
holders.
|
||||
All rights reserved.
|
||||
*/
|
||||
#ifndef BAR_SETTINGS_H
|
||||
#define BAR_SETTINGS_H
|
||||
|
||||
|
||||
struct desk_settings {
|
||||
bool vertical;
|
||||
bool left;
|
||||
bool top;
|
||||
uint32 state;
|
||||
float width;
|
||||
BPoint switcherLoc;
|
||||
bool showClock;
|
||||
// applications
|
||||
bool trackerAlwaysFirst;
|
||||
bool sortRunningApps;
|
||||
bool superExpando;
|
||||
bool expandNewTeams;
|
||||
bool hideLabels;
|
||||
int32 iconSize;
|
||||
// recent items
|
||||
bool recentDocsEnabled;
|
||||
bool recentFoldersEnabled;
|
||||
bool recentAppsEnabled;
|
||||
int32 recentDocsCount;
|
||||
int32 recentFoldersCount;
|
||||
int32 recentAppsCount;
|
||||
// window
|
||||
bool alwaysOnTop;
|
||||
bool autoRaise;
|
||||
bool autoHide;
|
||||
};
|
||||
|
||||
struct clock_settings {
|
||||
bool showSeconds;
|
||||
bool showDayOfWeek;
|
||||
bool showTimeZone;
|
||||
};
|
||||
|
||||
|
||||
#endif // BAR_SETTINGS_H
|
@ -11,6 +11,7 @@
|
||||
#include "PreferencesWindow.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <Box.h>
|
||||
#include <Button.h>
|
||||
@ -48,9 +49,9 @@ PreferencesWindow::PreferencesWindow(BRect frame)
|
||||
BWindow(frame, B_TRANSLATE("Deskbar preferences"), B_TITLED_WINDOW,
|
||||
B_NOT_RESIZABLE | B_AUTO_UPDATE_SIZE_LIMITS | B_NOT_ZOOMABLE)
|
||||
{
|
||||
// Set the default and intial settings used by default and revert buttons
|
||||
_SetDefaultSettings();
|
||||
_SetInitialSettings();
|
||||
// Initial settings (used by revert button)
|
||||
memcpy(&fSettings, static_cast<TBarApp*>(be_app)->Settings(),
|
||||
sizeof(desk_settings));
|
||||
|
||||
// Menu controls
|
||||
fMenuRecentDocuments = new BCheckBox(B_TRANSLATE("Recent documents:"),
|
||||
@ -113,18 +114,18 @@ PreferencesWindow::PreferencesWindow(BRect frame)
|
||||
appTextView->SetMaxBytes(4);
|
||||
folderTextView->SetMaxBytes(4);
|
||||
|
||||
int32 docCount = fInitialSettings.recentDocsCount;
|
||||
int32 appCount = fInitialSettings.recentAppsCount;
|
||||
int32 folderCount = fInitialSettings.recentFoldersCount;
|
||||
int32 docCount = fSettings.recentDocsCount;
|
||||
int32 appCount = fSettings.recentAppsCount;
|
||||
int32 folderCount = fSettings.recentFoldersCount;
|
||||
|
||||
fMenuRecentDocuments->SetValue(fInitialSettings.recentDocsEnabled);
|
||||
fMenuRecentDocumentCount->SetEnabled(fInitialSettings.recentDocsEnabled);
|
||||
fMenuRecentDocuments->SetValue(fSettings.recentDocsEnabled);
|
||||
fMenuRecentDocumentCount->SetEnabled(fSettings.recentDocsEnabled);
|
||||
|
||||
fMenuRecentApplications->SetValue(fInitialSettings.recentAppsEnabled);
|
||||
fMenuRecentApplicationCount->SetEnabled(fInitialSettings.recentAppsEnabled);
|
||||
fMenuRecentApplications->SetValue(fSettings.recentAppsEnabled);
|
||||
fMenuRecentApplicationCount->SetEnabled(fSettings.recentAppsEnabled);
|
||||
|
||||
fMenuRecentFolders->SetValue(fInitialSettings.recentFoldersEnabled);
|
||||
fMenuRecentFolderCount->SetEnabled(fInitialSettings.recentFoldersEnabled);
|
||||
fMenuRecentFolders->SetValue(fSettings.recentFoldersEnabled);
|
||||
fMenuRecentFolderCount->SetEnabled(fSettings.recentFoldersEnabled);
|
||||
|
||||
BString docString;
|
||||
BString appString;
|
||||
@ -139,18 +140,18 @@ PreferencesWindow::PreferencesWindow(BRect frame)
|
||||
fMenuRecentFolderCount->SetText(folderString.String());
|
||||
|
||||
// Applications settings
|
||||
fAppsSort->SetValue(fInitialSettings.sortRunningApps);
|
||||
fAppsSortTrackerFirst->SetValue(fInitialSettings.trackerAlwaysFirst);
|
||||
fAppsShowExpanders->SetValue(fInitialSettings.superExpando);
|
||||
fAppsExpandNew->SetValue(fInitialSettings.expandNewTeams);
|
||||
fAppsHideLabels->SetValue(fInitialSettings.hideLabels);
|
||||
fAppsIconSizeSlider->SetValue(fInitialSettings.iconSize
|
||||
fAppsSort->SetValue(fSettings.sortRunningApps);
|
||||
fAppsSortTrackerFirst->SetValue(fSettings.trackerAlwaysFirst);
|
||||
fAppsShowExpanders->SetValue(fSettings.superExpando);
|
||||
fAppsExpandNew->SetValue(fSettings.expandNewTeams);
|
||||
fAppsHideLabels->SetValue(fSettings.hideLabels);
|
||||
fAppsIconSizeSlider->SetValue(fSettings.iconSize
|
||||
/ kIconSizeInterval);
|
||||
|
||||
// Window settings
|
||||
fWindowAlwaysOnTop->SetValue(fInitialSettings.alwaysOnTop);
|
||||
fWindowAutoRaise->SetValue(fInitialSettings.autoRaise);
|
||||
fWindowAutoHide->SetValue(fInitialSettings.autoHide);
|
||||
fWindowAlwaysOnTop->SetValue(fSettings.alwaysOnTop);
|
||||
fWindowAutoRaise->SetValue(fSettings.autoRaise);
|
||||
fWindowAutoHide->SetValue(fSettings.autoHide);
|
||||
|
||||
_EnableDisableDependentItems();
|
||||
|
||||
@ -284,11 +285,12 @@ PreferencesWindow::MessageReceived(BMessage* message)
|
||||
break;
|
||||
|
||||
case kRevert:
|
||||
_UpdatePreferences(fInitialSettings);
|
||||
_UpdatePreferences(&fSettings);
|
||||
break;
|
||||
|
||||
case kDefaults:
|
||||
_UpdatePreferences(fDefaultSettings);
|
||||
_UpdatePreferences(
|
||||
static_cast<TBarApp*>(be_app)->DefaultSettings());
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -351,23 +353,24 @@ bool
|
||||
PreferencesWindow::_IsDefaultable()
|
||||
{
|
||||
desk_settings* settings = static_cast<TBarApp*>(be_app)->Settings();
|
||||
desk_settings* defaults = static_cast<TBarApp*>(be_app)->DefaultSettings();
|
||||
|
||||
return fDefaultSettings.sortRunningApps != settings->sortRunningApps
|
||||
|| fDefaultSettings.trackerAlwaysFirst != settings->trackerAlwaysFirst
|
||||
|| fDefaultSettings.superExpando != settings->superExpando
|
||||
|| fDefaultSettings.expandNewTeams != settings->expandNewTeams
|
||||
|| fDefaultSettings.hideLabels != settings->hideLabels
|
||||
|| fDefaultSettings.iconSize != settings->iconSize
|
||||
|| fDefaultSettings.recentAppsEnabled != settings->recentAppsEnabled
|
||||
|| fDefaultSettings.recentDocsEnabled != settings->recentDocsEnabled
|
||||
|| fDefaultSettings.recentFoldersEnabled
|
||||
return defaults->sortRunningApps != settings->sortRunningApps
|
||||
|| defaults->trackerAlwaysFirst != settings->trackerAlwaysFirst
|
||||
|| defaults->superExpando != settings->superExpando
|
||||
|| defaults->expandNewTeams != settings->expandNewTeams
|
||||
|| defaults->hideLabels != settings->hideLabels
|
||||
|| defaults->iconSize != settings->iconSize
|
||||
|| defaults->recentAppsEnabled != settings->recentAppsEnabled
|
||||
|| defaults->recentDocsEnabled != settings->recentDocsEnabled
|
||||
|| defaults->recentFoldersEnabled
|
||||
!= settings->recentFoldersEnabled
|
||||
|| fDefaultSettings.recentAppsCount != settings->recentAppsCount
|
||||
|| fDefaultSettings.recentDocsCount != settings->recentDocsCount
|
||||
|| fDefaultSettings.recentFoldersCount != settings->recentFoldersCount
|
||||
|| fDefaultSettings.alwaysOnTop != settings->alwaysOnTop
|
||||
|| fDefaultSettings.autoRaise != settings->autoRaise
|
||||
|| fDefaultSettings.autoHide != settings->autoHide;
|
||||
|| defaults->recentAppsCount != settings->recentAppsCount
|
||||
|| defaults->recentDocsCount != settings->recentDocsCount
|
||||
|| defaults->recentFoldersCount != settings->recentFoldersCount
|
||||
|| defaults->alwaysOnTop != settings->alwaysOnTop
|
||||
|| defaults->autoRaise != settings->autoRaise
|
||||
|| defaults->autoHide != settings->autoHide;
|
||||
}
|
||||
|
||||
|
||||
@ -376,76 +379,22 @@ PreferencesWindow::_IsRevertable()
|
||||
{
|
||||
desk_settings* settings = static_cast<TBarApp*>(be_app)->Settings();
|
||||
|
||||
return fInitialSettings.sortRunningApps != settings->sortRunningApps
|
||||
|| fInitialSettings.trackerAlwaysFirst != settings->trackerAlwaysFirst
|
||||
|| fInitialSettings.superExpando != settings->superExpando
|
||||
|| fInitialSettings.expandNewTeams != settings->expandNewTeams
|
||||
|| fInitialSettings.hideLabels != settings->hideLabels
|
||||
|| fInitialSettings.iconSize != settings->iconSize
|
||||
|| fInitialSettings.recentAppsEnabled != settings->recentAppsEnabled
|
||||
|| fInitialSettings.recentDocsEnabled != settings->recentDocsEnabled
|
||||
|| fInitialSettings.recentFoldersEnabled
|
||||
return fSettings.sortRunningApps != settings->sortRunningApps
|
||||
|| fSettings.trackerAlwaysFirst != settings->trackerAlwaysFirst
|
||||
|| fSettings.superExpando != settings->superExpando
|
||||
|| fSettings.expandNewTeams != settings->expandNewTeams
|
||||
|| fSettings.hideLabels != settings->hideLabels
|
||||
|| fSettings.iconSize != settings->iconSize
|
||||
|| fSettings.recentAppsEnabled != settings->recentAppsEnabled
|
||||
|| fSettings.recentDocsEnabled != settings->recentDocsEnabled
|
||||
|| fSettings.recentFoldersEnabled
|
||||
!= settings->recentFoldersEnabled
|
||||
|| fInitialSettings.recentAppsCount != settings->recentAppsCount
|
||||
|| fInitialSettings.recentDocsCount != settings->recentDocsCount
|
||||
|| fInitialSettings.recentFoldersCount != settings->recentFoldersCount
|
||||
|| fInitialSettings.alwaysOnTop != settings->alwaysOnTop
|
||||
|| fInitialSettings.autoRaise != settings->autoRaise
|
||||
|| fInitialSettings.autoHide != settings->autoHide;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PreferencesWindow::_SetDefaultSettings()
|
||||
{
|
||||
// applications
|
||||
fDefaultSettings.sortRunningApps = false;
|
||||
fDefaultSettings.trackerAlwaysFirst = false;
|
||||
fDefaultSettings.superExpando = false;
|
||||
fDefaultSettings.expandNewTeams = false;
|
||||
fDefaultSettings.hideLabels = false;
|
||||
fDefaultSettings.iconSize = kMinimumIconSize;
|
||||
|
||||
// recent items
|
||||
fDefaultSettings.recentAppsEnabled = true;
|
||||
fDefaultSettings.recentDocsEnabled = true;
|
||||
fDefaultSettings.recentFoldersEnabled = true;
|
||||
fDefaultSettings.recentAppsCount = 10;
|
||||
fDefaultSettings.recentDocsCount = 10;
|
||||
fDefaultSettings.recentFoldersCount = 10;
|
||||
|
||||
// window
|
||||
fDefaultSettings.alwaysOnTop = false;
|
||||
fDefaultSettings.autoRaise = false;
|
||||
fDefaultSettings.autoHide = false;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PreferencesWindow::_SetInitialSettings()
|
||||
{
|
||||
desk_settings* settings = static_cast<TBarApp*>(be_app)->Settings();
|
||||
|
||||
// applications
|
||||
fInitialSettings.sortRunningApps = settings->sortRunningApps;
|
||||
fInitialSettings.trackerAlwaysFirst = settings->trackerAlwaysFirst;
|
||||
fInitialSettings.superExpando = settings->superExpando;
|
||||
fInitialSettings.expandNewTeams = settings->expandNewTeams;
|
||||
fInitialSettings.hideLabels = settings->hideLabels;
|
||||
fInitialSettings.iconSize = settings->iconSize;
|
||||
|
||||
// recent items
|
||||
fInitialSettings.recentAppsEnabled = settings->recentAppsEnabled;
|
||||
fInitialSettings.recentDocsEnabled = settings->recentDocsEnabled;
|
||||
fInitialSettings.recentFoldersEnabled = settings->recentFoldersEnabled;
|
||||
fInitialSettings.recentAppsCount = settings->recentAppsCount;
|
||||
fInitialSettings.recentDocsCount = settings->recentDocsCount;
|
||||
fInitialSettings.recentFoldersCount = settings->recentFoldersCount;
|
||||
|
||||
// window
|
||||
fInitialSettings.alwaysOnTop = settings->alwaysOnTop;
|
||||
fInitialSettings.autoRaise = settings->autoRaise;
|
||||
fInitialSettings.autoHide = settings->autoHide;
|
||||
|| fSettings.recentAppsCount != settings->recentAppsCount
|
||||
|| fSettings.recentDocsCount != settings->recentDocsCount
|
||||
|| fSettings.recentFoldersCount != settings->recentFoldersCount
|
||||
|| fSettings.alwaysOnTop != settings->alwaysOnTop
|
||||
|| fSettings.autoRaise != settings->autoRaise
|
||||
|| fSettings.autoHide != settings->autoHide;
|
||||
}
|
||||
|
||||
|
||||
@ -458,78 +407,78 @@ PreferencesWindow::_UpdateButtons()
|
||||
|
||||
|
||||
void
|
||||
PreferencesWindow::_UpdatePreferences(pref_settings prefs)
|
||||
PreferencesWindow::_UpdatePreferences(desk_settings* settings)
|
||||
{
|
||||
desk_settings* settings = static_cast<TBarApp*>(be_app)->Settings();
|
||||
desk_settings* current = static_cast<TBarApp*>(be_app)->Settings();
|
||||
bool updateRecentCounts = false;
|
||||
|
||||
if (settings->sortRunningApps != prefs.sortRunningApps) {
|
||||
fAppsSort->SetValue(prefs.sortRunningApps);
|
||||
if (current->sortRunningApps != settings->sortRunningApps) {
|
||||
fAppsSort->SetValue(settings->sortRunningApps);
|
||||
fAppsSort->Invoke();
|
||||
}
|
||||
if (settings->trackerAlwaysFirst != prefs.trackerAlwaysFirst) {
|
||||
fAppsSortTrackerFirst->SetValue(prefs.trackerAlwaysFirst);
|
||||
if (current->trackerAlwaysFirst != settings->trackerAlwaysFirst) {
|
||||
fAppsSortTrackerFirst->SetValue(settings->trackerAlwaysFirst);
|
||||
fAppsSortTrackerFirst->Invoke();
|
||||
}
|
||||
if (settings->superExpando != prefs.superExpando) {
|
||||
fAppsShowExpanders->SetValue(prefs.superExpando);
|
||||
if (current->superExpando != settings->superExpando) {
|
||||
fAppsShowExpanders->SetValue(settings->superExpando);
|
||||
fAppsShowExpanders->Invoke();
|
||||
}
|
||||
if (settings->expandNewTeams != prefs.expandNewTeams) {
|
||||
fAppsExpandNew->SetValue(prefs.expandNewTeams);
|
||||
if (current->expandNewTeams != settings->expandNewTeams) {
|
||||
fAppsExpandNew->SetValue(settings->expandNewTeams);
|
||||
fAppsExpandNew->Invoke();
|
||||
}
|
||||
if (settings->hideLabels != prefs.hideLabels) {
|
||||
fAppsHideLabels->SetValue(prefs.hideLabels);
|
||||
if (current->hideLabels != settings->hideLabels) {
|
||||
fAppsHideLabels->SetValue(settings->hideLabels);
|
||||
fAppsHideLabels->Invoke();
|
||||
}
|
||||
if (settings->iconSize != prefs.iconSize) {
|
||||
fAppsIconSizeSlider->SetValue(prefs.iconSize / kIconSizeInterval);
|
||||
if (current->iconSize != settings->iconSize) {
|
||||
fAppsIconSizeSlider->SetValue(settings->iconSize / kIconSizeInterval);
|
||||
fAppsIconSizeSlider->Invoke();
|
||||
}
|
||||
if (settings->recentDocsEnabled != prefs.recentDocsEnabled) {
|
||||
fMenuRecentDocuments->SetValue(prefs.recentDocsEnabled
|
||||
if (current->recentDocsEnabled != settings->recentDocsEnabled) {
|
||||
fMenuRecentDocuments->SetValue(settings->recentDocsEnabled
|
||||
? B_CONTROL_ON : B_CONTROL_OFF);
|
||||
updateRecentCounts = true;
|
||||
}
|
||||
if (settings->recentFoldersEnabled != prefs.recentFoldersEnabled) {
|
||||
fMenuRecentFolders->SetValue(prefs.recentFoldersEnabled
|
||||
if (current->recentFoldersEnabled != settings->recentFoldersEnabled) {
|
||||
fMenuRecentFolders->SetValue(settings->recentFoldersEnabled
|
||||
? B_CONTROL_ON : B_CONTROL_OFF);
|
||||
updateRecentCounts = true;
|
||||
}
|
||||
if (settings->recentAppsEnabled != fDefaultSettings.recentAppsEnabled) {
|
||||
fMenuRecentApplications->SetValue(prefs.recentAppsEnabled
|
||||
if (current->recentAppsEnabled != settings->recentAppsEnabled) {
|
||||
fMenuRecentApplications->SetValue(settings->recentAppsEnabled
|
||||
? B_CONTROL_ON : B_CONTROL_OFF);
|
||||
updateRecentCounts = true;
|
||||
}
|
||||
if (settings->recentDocsCount != prefs.recentDocsCount) {
|
||||
if (current->recentDocsCount != settings->recentDocsCount) {
|
||||
BString docString;
|
||||
docString << prefs.recentDocsCount;
|
||||
docString << settings->recentDocsCount;
|
||||
fMenuRecentDocumentCount->SetText(docString.String());
|
||||
updateRecentCounts = true;
|
||||
}
|
||||
if (settings->recentFoldersCount != prefs.recentFoldersCount) {
|
||||
if (current->recentFoldersCount != settings->recentFoldersCount) {
|
||||
BString folderString;
|
||||
folderString << prefs.recentFoldersCount;
|
||||
folderString << settings->recentFoldersCount;
|
||||
fMenuRecentFolderCount->SetText(folderString.String());
|
||||
updateRecentCounts = true;
|
||||
}
|
||||
if (settings->recentAppsCount != prefs.recentAppsCount) {
|
||||
if (current->recentAppsCount != settings->recentAppsCount) {
|
||||
BString appString;
|
||||
appString << prefs.recentAppsCount;
|
||||
appString << settings->recentAppsCount;
|
||||
fMenuRecentApplicationCount->SetText(appString.String());
|
||||
updateRecentCounts = true;
|
||||
}
|
||||
if (settings->alwaysOnTop != prefs.alwaysOnTop) {
|
||||
fWindowAlwaysOnTop->SetValue(prefs.alwaysOnTop);
|
||||
if (current->alwaysOnTop != settings->alwaysOnTop) {
|
||||
fWindowAlwaysOnTop->SetValue(settings->alwaysOnTop);
|
||||
fWindowAlwaysOnTop->Invoke();
|
||||
}
|
||||
if (settings->autoRaise != prefs.autoRaise) {
|
||||
fWindowAutoRaise->SetValue(prefs.autoRaise);
|
||||
if (current->autoRaise != settings->autoRaise) {
|
||||
fWindowAutoRaise->SetValue(settings->autoRaise);
|
||||
fWindowAutoRaise->Invoke();
|
||||
}
|
||||
if (settings->autoHide != prefs.autoHide) {
|
||||
fWindowAutoHide->SetValue(prefs.autoHide);
|
||||
if (current->autoHide != settings->autoHide) {
|
||||
fWindowAutoHide->SetValue(settings->autoHide);
|
||||
fWindowAutoHide->Invoke();
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,8 @@
|
||||
|
||||
#include <Window.h>
|
||||
|
||||
#include "BarSettings.h"
|
||||
|
||||
|
||||
const uint32 kConfigShow = 'PrSh';
|
||||
const uint32 kConfigQuit = 'PrQt';
|
||||
@ -27,28 +29,6 @@ const uint32 kDefaults = 'dflt';
|
||||
const uint32 kRevert = 'rvrt';
|
||||
|
||||
|
||||
struct pref_settings {
|
||||
// applications
|
||||
bool trackerAlwaysFirst;
|
||||
bool sortRunningApps;
|
||||
bool superExpando;
|
||||
bool expandNewTeams;
|
||||
bool hideLabels;
|
||||
int32 iconSize;
|
||||
// recent items
|
||||
int32 recentAppsCount;
|
||||
int32 recentDocsCount;
|
||||
int32 recentFoldersCount;
|
||||
bool recentAppsEnabled;
|
||||
bool recentDocsEnabled;
|
||||
bool recentFoldersEnabled;
|
||||
// window
|
||||
bool alwaysOnTop;
|
||||
bool autoRaise;
|
||||
bool autoHide;
|
||||
};
|
||||
|
||||
|
||||
class BCheckBox;
|
||||
class BRadioButton;
|
||||
class BSlider;
|
||||
@ -70,11 +50,10 @@ private:
|
||||
bool _IsDefaultable();
|
||||
bool _IsRevertable();
|
||||
|
||||
void _SetDefaultSettings();
|
||||
void _SetInitialSettings();
|
||||
|
||||
void _UpdateButtons();
|
||||
void _UpdatePreferences(pref_settings prefs);
|
||||
void _UpdatePreferences(desk_settings* settings);
|
||||
void _UpdateRecentCounts();
|
||||
|
||||
private:
|
||||
@ -101,9 +80,8 @@ private:
|
||||
BButton* fDefaultsButton;
|
||||
|
||||
private:
|
||||
pref_settings fDefaultSettings;
|
||||
pref_settings fInitialSettings;
|
||||
desk_settings fSettings;
|
||||
};
|
||||
|
||||
|
||||
#endif /* _PREFERENCES_WINDOW_H */
|
||||
#endif // _PREFERENCES_WINDOW_H
|
||||
|
Loading…
Reference in New Issue
Block a user