Skip to content

Commit

Permalink
Rearrange Deskbar preferences to use a list view like Tracker
Browse files Browse the repository at this point in the history
Instead of showing all Deskbar preferences at once, show them one
at a time using a list view to switch between them like Tracker
preferences.
  • Loading branch information
jscipione committed Dec 20, 2012
1 parent 31c0024 commit c5b556a
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 25 deletions.
120 changes: 98 additions & 22 deletions src/apps/deskbar/PreferencesWindow.cpp
Expand Up @@ -19,23 +19,49 @@
#include <ControlLook.h>
#include <FormattingConventions.h>
#include <GroupLayout.h>
#include <ListView.h>
#include <Locale.h>
#include <LayoutBuilder.h>
#include <OpenWithTracker.h>
#include <RadioButton.h>
#include <Roster.h>
#include <ScrollView.h>
#include <SeparatorView.h>
#include <Slider.h>
#include <StringView.h>
#include <StringItem.h>
#include <TextControl.h>
#include <View.h>

#include "BarApp.h"
#include "StatusView.h"


namespace BPrivate {

class SettingsItem : public BStringItem {
public:
SettingsItem(const char* label, BView* view)
:
BStringItem(label),
fSettingsView(view)
{
}

BView* View()
{
return fSettingsView;
}

private:
BView* fSettingsView;
};

} // namespace BPrivate


static const float kIndentSpacing
= be_control_look->DefaultItemSpacing() * 2.3;
static const uint32 kSettingsViewChanged = 'Svch';


#undef B_TRANSLATION_CONTEXT
Expand All @@ -47,6 +73,15 @@ PreferencesWindow::PreferencesWindow(BRect frame)
BWindow(frame, B_TRANSLATE("Deskbar preferences"), B_TITLED_WINDOW,
B_NOT_RESIZABLE | B_AUTO_UPDATE_SIZE_LIMITS | B_NOT_ZOOMABLE)
{
// Main view controls
fSettingsTypeListView = new BListView("List View",
B_SINGLE_SELECTION_LIST);

BScrollView* scrollView = new BScrollView("scrollview",
fSettingsTypeListView, 0, false, true);

fSettingsContainerBox = new BBox("SettingsContainerBox");

// Menu controls
fMenuRecentDocuments = new BCheckBox(B_TRANSLATE("Recent documents:"),
new BMessage(kUpdateRecentCounts));
Expand Down Expand Up @@ -164,16 +199,7 @@ PreferencesWindow::PreferencesWindow(BRect frame)
fWindowAutoHide->SetTarget(be_app);

// Layout
fMenuBox = new BBox("fMenuBox");
fAppsBox = new BBox("fAppsBox");
fWindowBox = new BBox("fWindowBox");

fMenuBox->SetLabel(B_TRANSLATE("Menu"));
fAppsBox->SetLabel(B_TRANSLATE("Applications"));
fWindowBox->SetLabel(B_TRANSLATE("Window"));

BView* view;
view = BLayoutBuilder::Group<>()
BView* menuSettingsView = BLayoutBuilder::Group<>()
.AddGroup(B_VERTICAL, 0)
.AddGroup(B_HORIZONTAL, 0)
.AddGroup(B_VERTICAL, 0)
Expand All @@ -196,9 +222,8 @@ PreferencesWindow::PreferencesWindow(BRect frame)
B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING)
.End()
.View();
fMenuBox->AddChild(view);

view = BLayoutBuilder::Group<>()
BView* applicationSettingsView = BLayoutBuilder::Group<>()
.AddGroup(B_VERTICAL, 0)
.Add(fAppsSort)
.Add(fAppsSortTrackerFirst)
Expand All @@ -217,9 +242,8 @@ PreferencesWindow::PreferencesWindow(BRect frame)
B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING)
.End()
.View();
fAppsBox->AddChild(view);

view = BLayoutBuilder::Group<>()
BView* windowSettingsView = BLayoutBuilder::Group<>()
.AddGroup(B_VERTICAL, 0)
.Add(fWindowAlwaysOnTop)
.Add(fWindowAutoRaise)
Expand All @@ -229,17 +253,33 @@ PreferencesWindow::PreferencesWindow(BRect frame)
B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING)
.End()
.View();
fWindowBox->AddChild(view);

BLayoutBuilder::Group<>(this)
.AddGroup(B_VERTICAL, B_USE_SMALL_SPACING)
.Add(fMenuBox)
.Add(fAppsBox)
.Add(fWindowBox)
.SetInsets(B_USE_DEFAULT_SPACING)
.End()
.AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING)
.Add(scrollView)
.Add(fSettingsContainerBox)
.SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING,
B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING)
.End();

fSettingsTypeListView->AddItem(new SettingsItem(B_TRANSLATE("Menu"),
menuSettingsView));
fSettingsTypeListView->AddItem(new SettingsItem(B_TRANSLATE("Application"),
applicationSettingsView));
fSettingsTypeListView->AddItem(new SettingsItem(B_TRANSLATE("Window"),
windowSettingsView));

// constraint the listview width so that the longest item fits
float width = 0;
fSettingsTypeListView->GetPreferredSize(&width, NULL);
width += B_V_SCROLL_BAR_WIDTH;
fSettingsTypeListView->SetExplicitMinSize(BSize(width, 0));
fSettingsTypeListView->SetExplicitMaxSize(BSize(width, B_SIZE_UNLIMITED));

fSettingsTypeListView->SetSelectionMessage(
new BMessage(kSettingsViewChanged));
fSettingsTypeListView->Select(0);

CenterOnScreen();
}

Expand Down Expand Up @@ -272,6 +312,10 @@ PreferencesWindow::MessageReceived(BMessage* message)
EnableDisableDependentItems();
break;

case kSettingsViewChanged:
_HandleChangedSettingsView();
break;

default:
BWindow::MessageReceived(message);
break;
Expand Down Expand Up @@ -333,3 +377,35 @@ PreferencesWindow::EnableDisableDependentItems()
fWindowAutoRaise->SetEnabled(
fWindowAlwaysOnTop->Value() == B_CONTROL_OFF);
}


// #pragma mark -


void
PreferencesWindow::_HandleChangedSettingsView()
{
int32 currentSelection = fSettingsTypeListView->CurrentSelection();
if (currentSelection < 0)
return;

BView* oldView = fSettingsContainerBox->ChildAt(0);

if (oldView)
oldView->RemoveSelf();

SettingsItem* selectedItem =
dynamic_cast<SettingsItem*>
(fSettingsTypeListView->ItemAt(currentSelection));

if (selectedItem) {
fSettingsContainerBox->SetLabel(selectedItem->Text());

BView* view = selectedItem->View();
view->SetViewColor(fSettingsContainerBox->ViewColor());
view->Hide();
fSettingsContainerBox->AddChild(view);

view->Show();
}
}
8 changes: 5 additions & 3 deletions src/apps/deskbar/PreferencesWindow.h
Expand Up @@ -26,6 +26,7 @@ const uint32 kAutoHide = 'AtHd';
class BBox;
class BButton;
class BCheckBox;
class BListView;
class BRadioButton;
class BSlider;
class BStringView;
Expand All @@ -44,9 +45,10 @@ class PreferencesWindow : public BWindow
void EnableDisableDependentItems();

private:
BBox* fMenuBox;
BBox* fAppsBox;
BBox* fWindowBox;
void _HandleChangedSettingsView();

BListView* fSettingsTypeListView;
BBox* fSettingsContainerBox;

BCheckBox* fMenuRecentDocuments;
BCheckBox* fMenuRecentApplications;
Expand Down

0 comments on commit c5b556a

Please sign in to comment.