btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / kits / tracker / SettingsViews.cpp
blob18be42255f6bfbe32d1ba17cdc6238a89e8b5b7c
1 /*
2 Open Tracker License
4 Terms and Conditions
6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30 of Be Incorporated in the United States and other countries. Other brand product
31 names are registered trademarks or trademarks of their respective holders.
32 All rights reserved.
36 #include "SettingsViews.h"
38 #include <Box.h>
39 #include <Button.h>
40 #include <Catalog.h>
41 #include <CheckBox.h>
42 #include <ColorControl.h>
43 #include <ControlLook.h>
44 #include <LayoutBuilder.h>
45 #include <Locale.h>
46 #include <MenuField.h>
47 #include <NodeMonitor.h>
48 #include <Point.h>
49 #include <RadioButton.h>
50 #include <StringView.h>
52 #include "Commands.h"
53 #include "DeskWindow.h"
54 #include "Model.h"
55 #include "Tracker.h"
56 #include "WidgetAttributeText.h"
59 static const uint32 kSpaceBarSwitchColor = 'SBsc';
61 //TODO: defaults should be set in one place only (TrackerSettings.cpp) while
62 // being accessible from here.
63 // What about adding DefaultValue(), IsDefault() etc... methods to
64 // xxxValueSetting ?
65 static const uint8 kSpaceBarAlpha = 192;
66 static const rgb_color kDefaultUsedSpaceColor = { 0, 203, 0, kSpaceBarAlpha };
67 static const rgb_color kDefaultFreeSpaceColor
68 = { 255, 255, 255, kSpaceBarAlpha };
69 static const rgb_color kDefaultWarningSpaceColor
70 = { 203, 0, 0, kSpaceBarAlpha };
73 static void
74 send_bool_notices(uint32 what, const char* name, bool value)
76 TTracker* tracker = dynamic_cast<TTracker*>(be_app);
77 if (tracker == NULL)
78 return;
80 BMessage message;
81 message.AddBool(name, value);
82 tracker->SendNotices(what, &message);
86 #undef B_TRANSLATION_CONTEXT
87 #define B_TRANSLATION_CONTEXT "SettingsView"
90 // #pragma mark - SettingsView
93 SettingsView::SettingsView(const char* name)
95 BGroupView(name)
100 SettingsView::~SettingsView()
106 The inherited functions should set the default values
107 and update the UI gadgets. The latter can by done by
108 calling ShowCurrentSettings().
110 void
111 SettingsView::SetDefaults()
117 This function is used by the window to tell whether
118 it can ghost the defaults button or not. It doesn't
119 shows the default settings, this function should
120 return true.
122 bool
123 SettingsView::IsDefaultable() const
125 return true;
130 The inherited functions should set the values that was
131 active when the settings window opened. It should also
132 update the UI widgets accordingly, preferrable by calling
133 ShowCurrentSettings().
135 void
136 SettingsView::Revert()
142 This function is called when the window is shown to let
143 the settings views record the state to revert to.
145 void
146 SettingsView::RecordRevertSettings()
152 This function is used by the window to tell the view
153 to display the current settings in the tracker.
155 void
156 SettingsView::ShowCurrentSettings()
162 This function is used by the window to tell whether
163 it can ghost the revert button or not. It it shows the
164 reverted settings, this function should return true.
166 bool
167 SettingsView::IsRevertable() const
169 return true;
173 // #pragma mark - DesktopSettingsView
176 DesktopSettingsView::DesktopSettingsView()
178 SettingsView("DesktopSettingsView"),
179 fShowDisksIconRadioButton(NULL),
180 fMountVolumesOntoDesktopRadioButton(NULL),
181 fMountSharedVolumesOntoDesktopCheckBox(NULL),
182 fShowDisksIcon(false),
183 fMountVolumesOntoDesktop(false),
184 fMountSharedVolumesOntoDesktop(false),
185 fIntegrateNonBootBeOSDesktops(false),
186 fEjectWhenUnmounting(false)
188 fShowDisksIconRadioButton = new BRadioButton("",
189 B_TRANSLATE("Show Disks icon"),
190 new BMessage(kShowDisksIconChanged));
192 fMountVolumesOntoDesktopRadioButton = new BRadioButton("",
193 B_TRANSLATE("Show volumes on Desktop"),
194 new BMessage(kVolumesOnDesktopChanged));
196 fMountSharedVolumesOntoDesktopCheckBox = new BCheckBox("",
197 B_TRANSLATE("Show shared volumes on Desktop"),
198 new BMessage(kVolumesOnDesktopChanged));
200 const float spacing = be_control_look->DefaultItemSpacing();
202 BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
203 .Add(fShowDisksIconRadioButton)
204 .Add(fMountVolumesOntoDesktopRadioButton)
205 .AddGroup(B_VERTICAL, 0)
206 .Add(fMountSharedVolumesOntoDesktopCheckBox)
207 .SetInsets(spacing * 2, 0, 0, 0)
208 .End()
209 .AddGlue()
210 .SetInsets(spacing);
214 void
215 DesktopSettingsView::AttachedToWindow()
217 fShowDisksIconRadioButton->SetTarget(this);
218 fMountVolumesOntoDesktopRadioButton->SetTarget(this);
219 fMountSharedVolumesOntoDesktopCheckBox->SetTarget(this);
223 void
224 DesktopSettingsView::MessageReceived(BMessage* message)
226 TTracker* tracker = dynamic_cast<TTracker*>(be_app);
227 if (tracker == NULL)
228 return;
230 TrackerSettings settings;
232 switch (message->what) {
233 case kShowDisksIconChanged:
235 // Turn on and off related settings:
236 fMountVolumesOntoDesktopRadioButton->SetValue(
237 !(fShowDisksIconRadioButton->Value() == 1));
238 fMountSharedVolumesOntoDesktopCheckBox->SetEnabled(
239 fMountVolumesOntoDesktopRadioButton->Value() == 1);
241 // Set the new settings in the tracker:
242 settings.SetShowDisksIcon(fShowDisksIconRadioButton->Value() == 1);
243 settings.SetMountVolumesOntoDesktop(
244 fMountVolumesOntoDesktopRadioButton->Value() == 1);
245 settings.SetMountSharedVolumesOntoDesktop(
246 fMountSharedVolumesOntoDesktopCheckBox->Value() == 1);
248 // Construct the notification message:
249 BMessage notificationMessage;
250 notificationMessage.AddBool("ShowDisksIcon",
251 fShowDisksIconRadioButton->Value() == 1);
252 notificationMessage.AddBool("MountVolumesOntoDesktop",
253 fMountVolumesOntoDesktopRadioButton->Value() == 1);
254 notificationMessage.AddBool("MountSharedVolumesOntoDesktop",
255 fMountSharedVolumesOntoDesktopCheckBox->Value() == 1);
257 // Send the notification message:
258 tracker->SendNotices(kVolumesOnDesktopChanged,
259 &notificationMessage);
261 // Tell the settings window the contents have changed:
262 Window()->PostMessage(kSettingsContentsModified);
263 break;
266 case kVolumesOnDesktopChanged:
268 // Turn on and off related settings:
269 fShowDisksIconRadioButton->SetValue(
270 !(fMountVolumesOntoDesktopRadioButton->Value() == 1));
271 fMountSharedVolumesOntoDesktopCheckBox->SetEnabled(
272 fMountVolumesOntoDesktopRadioButton->Value() == 1);
274 // Set the new settings in the tracker:
275 settings.SetShowDisksIcon(fShowDisksIconRadioButton->Value() == 1);
276 settings.SetMountVolumesOntoDesktop(
277 fMountVolumesOntoDesktopRadioButton->Value() == 1);
278 settings.SetMountSharedVolumesOntoDesktop(
279 fMountSharedVolumesOntoDesktopCheckBox->Value() == 1);
281 // Construct the notification message:
282 BMessage notificationMessage;
283 notificationMessage.AddBool("ShowDisksIcon",
284 fShowDisksIconRadioButton->Value() == 1);
285 notificationMessage.AddBool("MountVolumesOntoDesktop",
286 fMountVolumesOntoDesktopRadioButton->Value() == 1);
287 notificationMessage.AddBool("MountSharedVolumesOntoDesktop",
288 fMountSharedVolumesOntoDesktopCheckBox->Value() == 1);
290 // Send the notification message:
291 tracker->SendNotices(kVolumesOnDesktopChanged,\
292 &notificationMessage);
294 // Tell the settings window the contents have changed:
295 Window()->PostMessage(kSettingsContentsModified);
296 break;
299 default:
300 _inherited::MessageReceived(message);
301 break;
306 void
307 DesktopSettingsView::SetDefaults()
309 // ToDo: Avoid the duplication of the default values.
310 TrackerSettings settings;
312 settings.SetShowDisksIcon(false);
313 settings.SetMountVolumesOntoDesktop(true);
314 settings.SetMountSharedVolumesOntoDesktop(true);
315 settings.SetEjectWhenUnmounting(true);
317 ShowCurrentSettings();
318 _SendNotices();
322 bool
323 DesktopSettingsView::IsDefaultable() const
325 TrackerSettings settings;
327 return settings.ShowDisksIcon() != false
328 || settings.MountVolumesOntoDesktop() != true
329 || settings.MountSharedVolumesOntoDesktop() != true
330 || settings.EjectWhenUnmounting() != true;
334 void
335 DesktopSettingsView::Revert()
337 TrackerSettings settings;
339 settings.SetShowDisksIcon(fShowDisksIcon);
340 settings.SetMountVolumesOntoDesktop(fMountVolumesOntoDesktop);
341 settings.SetMountSharedVolumesOntoDesktop(fMountSharedVolumesOntoDesktop);
342 settings.SetEjectWhenUnmounting(fEjectWhenUnmounting);
344 ShowCurrentSettings();
345 _SendNotices();
349 void
350 DesktopSettingsView::_SendNotices()
352 TTracker* tracker = dynamic_cast<TTracker*>(be_app);
353 if (tracker == NULL)
354 return;
356 // Construct the notification message:
357 BMessage notificationMessage;
358 notificationMessage.AddBool("ShowDisksIcon",
359 fShowDisksIconRadioButton->Value() == 1);
360 notificationMessage.AddBool("MountVolumesOntoDesktop",
361 fMountVolumesOntoDesktopRadioButton->Value() == 1);
362 notificationMessage.AddBool("MountSharedVolumesOntoDesktop",
363 fMountSharedVolumesOntoDesktopCheckBox->Value() == 1);
365 // Send notices to the tracker about the change:
366 tracker->SendNotices(kVolumesOnDesktopChanged, &notificationMessage);
367 tracker->SendNotices(kDesktopIntegrationChanged, &notificationMessage);
371 void
372 DesktopSettingsView::ShowCurrentSettings()
374 TrackerSettings settings;
376 fShowDisksIconRadioButton->SetValue(settings.ShowDisksIcon());
377 fMountVolumesOntoDesktopRadioButton->SetValue(
378 settings.MountVolumesOntoDesktop());
380 fMountSharedVolumesOntoDesktopCheckBox->SetValue(
381 settings.MountSharedVolumesOntoDesktop());
382 fMountSharedVolumesOntoDesktopCheckBox->SetEnabled(
383 settings.MountVolumesOntoDesktop());
387 void
388 DesktopSettingsView::RecordRevertSettings()
390 TrackerSettings settings;
392 fShowDisksIcon = settings.ShowDisksIcon();
393 fMountVolumesOntoDesktop = settings.MountVolumesOntoDesktop();
394 fMountSharedVolumesOntoDesktop = settings.MountSharedVolumesOntoDesktop();
395 fEjectWhenUnmounting = settings.EjectWhenUnmounting();
399 bool
400 DesktopSettingsView::IsRevertable() const
402 return fShowDisksIcon != (fShowDisksIconRadioButton->Value() > 0)
403 || fMountVolumesOntoDesktop !=
404 (fMountVolumesOntoDesktopRadioButton->Value() > 0)
405 || fMountSharedVolumesOntoDesktop !=
406 (fMountSharedVolumesOntoDesktopCheckBox->Value() > 0);
410 // #pragma mark - WindowsSettingsView
413 WindowsSettingsView::WindowsSettingsView()
415 SettingsView("WindowsSettingsView"),
416 fShowFullPathInTitleBarCheckBox(NULL),
417 fSingleWindowBrowseCheckBox(NULL),
418 fShowNavigatorCheckBox(NULL),
419 fOutlineSelectionCheckBox(NULL),
420 fSortFolderNamesFirstCheckBox(NULL),
421 fHideDotFilesCheckBox(NULL),
422 fTypeAheadFilteringCheckBox(NULL),
423 fShowFullPathInTitleBar(false),
424 fSingleWindowBrowse(false),
425 fShowNavigator(false),
426 fTransparentSelection(false),
427 fSortFolderNamesFirst(false),
428 fHideDotFiles(false),
429 fTypeAheadFiltering(false)
431 fShowFullPathInTitleBarCheckBox = new BCheckBox("",
432 B_TRANSLATE("Show folder location in title tab"),
433 new BMessage(kWindowsShowFullPathChanged));
435 fSingleWindowBrowseCheckBox = new BCheckBox("",
436 B_TRANSLATE("Single window navigation"),
437 new BMessage(kSingleWindowBrowseChanged));
439 fShowNavigatorCheckBox = new BCheckBox("",
440 B_TRANSLATE("Show navigator"),
441 new BMessage(kShowNavigatorChanged));
443 fOutlineSelectionCheckBox = new BCheckBox("",
444 B_TRANSLATE("Outline selection rectangle only"),
445 new BMessage(kTransparentSelectionChanged));
447 fSortFolderNamesFirstCheckBox = new BCheckBox("",
448 B_TRANSLATE("List folders first"),
449 new BMessage(kSortFolderNamesFirstChanged));
451 fHideDotFilesCheckBox = new BCheckBox("",
452 B_TRANSLATE("Hide dotfiles"),
453 new BMessage(kHideDotFilesChanged));
455 fTypeAheadFilteringCheckBox = new BCheckBox("",
456 B_TRANSLATE("Enable type-ahead filtering"),
457 new BMessage(kTypeAheadFilteringChanged));
459 const float spacing = be_control_look->DefaultItemSpacing();
461 BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
462 .AddGroup(B_VERTICAL, 0)
463 .Add(fShowFullPathInTitleBarCheckBox)
464 .Add(fSingleWindowBrowseCheckBox)
465 .End()
466 .AddGroup(B_VERTICAL)
467 .Add(fShowNavigatorCheckBox)
468 .SetInsets(spacing * 2, 0, 0, 0)
469 .End()
470 .AddGroup(B_VERTICAL, 0)
471 .Add(fOutlineSelectionCheckBox)
472 .Add(fSortFolderNamesFirstCheckBox)
473 .Add(fHideDotFilesCheckBox)
474 .Add(fTypeAheadFilteringCheckBox)
475 .End()
476 .AddGlue()
477 .SetInsets(spacing);
481 void
482 WindowsSettingsView::AttachedToWindow()
484 fSingleWindowBrowseCheckBox->SetTarget(this);
485 fShowNavigatorCheckBox->SetTarget(this);
486 fShowFullPathInTitleBarCheckBox->SetTarget(this);
487 fOutlineSelectionCheckBox->SetTarget(this);
488 fSortFolderNamesFirstCheckBox->SetTarget(this);
489 fHideDotFilesCheckBox->SetTarget(this);
490 fTypeAheadFilteringCheckBox->SetTarget(this);
494 void
495 WindowsSettingsView::MessageReceived(BMessage* message)
497 TTracker* tracker = dynamic_cast<TTracker*>(be_app);
498 if (tracker == NULL)
499 return;
501 TrackerSettings settings;
503 switch (message->what) {
504 case kWindowsShowFullPathChanged:
505 settings.SetShowFullPathInTitleBar(
506 fShowFullPathInTitleBarCheckBox->Value() == 1);
507 tracker->SendNotices(kWindowsShowFullPathChanged);
508 Window()->PostMessage(kSettingsContentsModified);
509 break;
511 case kSingleWindowBrowseChanged:
512 settings.SetSingleWindowBrowse(
513 fSingleWindowBrowseCheckBox->Value() == 1);
514 if (fSingleWindowBrowseCheckBox->Value() == 0) {
515 fShowNavigatorCheckBox->SetEnabled(false);
516 settings.SetShowNavigator(0);
517 } else {
518 fShowNavigatorCheckBox->SetEnabled(true);
519 settings.SetShowNavigator(
520 fShowNavigatorCheckBox->Value() != 0);
522 tracker->SendNotices(kShowNavigatorChanged);
523 tracker->SendNotices(kSingleWindowBrowseChanged);
524 Window()->PostMessage(kSettingsContentsModified);
525 break;
527 case kShowNavigatorChanged:
528 settings.SetShowNavigator(fShowNavigatorCheckBox->Value() == 1);
529 tracker->SendNotices(kShowNavigatorChanged);
530 Window()->PostMessage(kSettingsContentsModified);
531 break;
533 case kTransparentSelectionChanged:
535 settings.SetTransparentSelection(
536 fOutlineSelectionCheckBox->Value() == B_CONTROL_OFF);
538 // Make the notification message and send it to the tracker:
539 send_bool_notices(kTransparentSelectionChanged,
540 "TransparentSelection", settings.TransparentSelection());
542 Window()->PostMessage(kSettingsContentsModified);
543 break;
546 case kSortFolderNamesFirstChanged:
548 settings.SetSortFolderNamesFirst(
549 fSortFolderNamesFirstCheckBox->Value() == 1);
551 // Make the notification message and send it to the tracker:
552 send_bool_notices(kSortFolderNamesFirstChanged,
553 "SortFolderNamesFirst",
554 fSortFolderNamesFirstCheckBox->Value() == 1);
556 Window()->PostMessage(kSettingsContentsModified);
557 break;
560 case kHideDotFilesChanged:
562 settings.SetHideDotFiles(
563 fHideDotFilesCheckBox->Value() == 1);
565 // Make the notification message and send it to the tracker:
566 send_bool_notices(kHideDotFilesChanged,
567 "HideDotFiles",
568 fHideDotFilesCheckBox->Value() == 1);
570 Window()->PostMessage(kSettingsContentsModified);
571 break;
574 case kTypeAheadFilteringChanged:
576 settings.SetTypeAheadFiltering(
577 fTypeAheadFilteringCheckBox->Value() == 1);
578 send_bool_notices(kTypeAheadFilteringChanged,
579 "TypeAheadFiltering",
580 fTypeAheadFilteringCheckBox->Value() == 1);
581 Window()->PostMessage(kSettingsContentsModified);
582 break;
585 default:
586 _inherited::MessageReceived(message);
587 break;
592 void
593 WindowsSettingsView::SetDefaults()
595 TTracker* tracker = dynamic_cast<TTracker*>(be_app);
596 if (tracker == NULL)
597 return;
599 TrackerSettings settings;
601 if (settings.ShowFullPathInTitleBar()) {
602 settings.SetShowFullPathInTitleBar(false);
603 tracker->SendNotices(kWindowsShowFullPathChanged);
606 if (settings.SingleWindowBrowse()) {
607 settings.SetSingleWindowBrowse(false);
608 tracker->SendNotices(kSingleWindowBrowseChanged);
611 if (settings.ShowNavigator()) {
612 settings.SetShowNavigator(false);
613 tracker->SendNotices(kShowNavigatorChanged);
616 if (!settings.TransparentSelection()) {
617 settings.SetTransparentSelection(true);
618 send_bool_notices(kTransparentSelectionChanged,
619 "TransparentSelection", true);
622 if (!settings.SortFolderNamesFirst()) {
623 settings.SetSortFolderNamesFirst(true);
624 send_bool_notices(kSortFolderNamesFirstChanged,
625 "SortFolderNamesFirst", true);
628 if (!settings.HideDotFiles()) {
629 settings.SetHideDotFiles(true);
630 send_bool_notices(kHideDotFilesChanged,
631 "HideDotFiles", true);
634 if (settings.TypeAheadFiltering()) {
635 settings.SetTypeAheadFiltering(false);
636 send_bool_notices(kTypeAheadFilteringChanged,
637 "TypeAheadFiltering", true);
640 ShowCurrentSettings();
644 bool
645 WindowsSettingsView::IsDefaultable() const
647 TrackerSettings settings;
649 return settings.ShowFullPathInTitleBar() != false
650 || settings.SingleWindowBrowse() != false
651 || settings.ShowNavigator() != false
652 || settings.TransparentSelection() != true
653 || settings.SortFolderNamesFirst() != true
654 || settings.TypeAheadFiltering() != false;
658 void
659 WindowsSettingsView::Revert()
661 TTracker* tracker = dynamic_cast<TTracker*>(be_app);
662 if (tracker == NULL)
663 return;
665 TrackerSettings settings;
667 if (settings.ShowFullPathInTitleBar() != fShowFullPathInTitleBar) {
668 settings.SetShowFullPathInTitleBar(fShowFullPathInTitleBar);
669 tracker->SendNotices(kWindowsShowFullPathChanged);
672 if (settings.SingleWindowBrowse() != fSingleWindowBrowse) {
673 settings.SetSingleWindowBrowse(fSingleWindowBrowse);
674 tracker->SendNotices(kSingleWindowBrowseChanged);
677 if (settings.ShowNavigator() != fShowNavigator) {
678 settings.SetShowNavigator(fShowNavigator);
679 tracker->SendNotices(kShowNavigatorChanged);
682 if (settings.TransparentSelection() != fTransparentSelection) {
683 settings.SetTransparentSelection(fTransparentSelection);
684 send_bool_notices(kTransparentSelectionChanged,
685 "TransparentSelection", fTransparentSelection);
688 if (settings.SortFolderNamesFirst() != fSortFolderNamesFirst) {
689 settings.SetSortFolderNamesFirst(fSortFolderNamesFirst);
690 send_bool_notices(kSortFolderNamesFirstChanged,
691 "SortFolderNamesFirst", fSortFolderNamesFirst);
694 if (settings.HideDotFiles() != fHideDotFiles) {
695 settings.SetSortFolderNamesFirst(fHideDotFiles);
696 send_bool_notices(kHideDotFilesChanged,
697 "HideDotFiles", fHideDotFiles);
700 if (settings.TypeAheadFiltering() != fTypeAheadFiltering) {
701 settings.SetTypeAheadFiltering(fTypeAheadFiltering);
702 send_bool_notices(kTypeAheadFilteringChanged,
703 "TypeAheadFiltering", fTypeAheadFiltering);
706 ShowCurrentSettings();
710 void
711 WindowsSettingsView::ShowCurrentSettings()
713 TrackerSettings settings;
715 fShowFullPathInTitleBarCheckBox->SetValue(
716 settings.ShowFullPathInTitleBar());
717 fSingleWindowBrowseCheckBox->SetValue(settings.SingleWindowBrowse());
718 fShowNavigatorCheckBox->SetEnabled(settings.SingleWindowBrowse());
719 fShowNavigatorCheckBox->SetValue(settings.ShowNavigator());
720 fOutlineSelectionCheckBox->SetValue(settings.TransparentSelection()
721 ? B_CONTROL_OFF : B_CONTROL_ON);
722 fSortFolderNamesFirstCheckBox->SetValue(settings.SortFolderNamesFirst());
723 fHideDotFilesCheckBox->SetValue(settings.HideDotFiles());
724 fTypeAheadFilteringCheckBox->SetValue(settings.TypeAheadFiltering());
728 void
729 WindowsSettingsView::RecordRevertSettings()
731 TrackerSettings settings;
733 fShowFullPathInTitleBar = settings.ShowFullPathInTitleBar();
734 fSingleWindowBrowse = settings.SingleWindowBrowse();
735 fShowNavigator = settings.ShowNavigator();
736 fTransparentSelection = settings.TransparentSelection();
737 fSortFolderNamesFirst = settings.SortFolderNamesFirst();
738 fHideDotFiles = settings.HideDotFiles();
739 fTypeAheadFiltering = settings.TypeAheadFiltering();
743 bool
744 WindowsSettingsView::IsRevertable() const
746 TrackerSettings settings;
748 return fShowFullPathInTitleBar != settings.ShowFullPathInTitleBar()
749 || fSingleWindowBrowse != settings.SingleWindowBrowse()
750 || fShowNavigator != settings.ShowNavigator()
751 || fTransparentSelection != settings.TransparentSelection()
752 || fSortFolderNamesFirst != settings.SortFolderNamesFirst()
753 || fHideDotFiles != settings.HideDotFiles()
754 || fTypeAheadFiltering != settings.TypeAheadFiltering();
758 // #pragma mark - SpaceBarSettingsView
761 SpaceBarSettingsView::SpaceBarSettingsView()
763 SettingsView("SpaceBarSettingsView")
765 fSpaceBarShowCheckBox = new BCheckBox("",
766 B_TRANSLATE("Show space bars on volumes"),
767 new BMessage(kUpdateVolumeSpaceBar));
769 BPopUpMenu* menu = new BPopUpMenu(B_EMPTY_STRING);
770 menu->SetFont(be_plain_font);
772 BMenuItem* item;
773 menu->AddItem(item = new BMenuItem(
774 B_TRANSLATE("Used space color"),
775 new BMessage(kSpaceBarSwitchColor)));
776 item->SetMarked(true);
777 fCurrentColor = 0;
778 menu->AddItem(new BMenuItem(
779 B_TRANSLATE("Free space color"),
780 new BMessage(kSpaceBarSwitchColor)));
781 menu->AddItem(new BMenuItem(
782 B_TRANSLATE("Warning space color"),
783 new BMessage(kSpaceBarSwitchColor)));
785 fColorPicker = new BMenuField("menu", NULL, menu);
787 fColorControl = new BColorControl(BPoint(0, 0),
788 B_CELLS_16x16, 1, "SpaceColorControl",
789 new BMessage(kSpaceBarColorChanged));
790 fColorControl->SetValue(TrackerSettings().UsedSpaceColor());
792 BBox* box = new BBox("box");
793 box->SetLabel(fColorPicker);
794 box->AddChild(BLayoutBuilder::Group<>(B_HORIZONTAL)
795 .Add(fColorControl)
796 .SetInsets(B_USE_DEFAULT_SPACING)
797 .View());
799 BLayoutBuilder::Group<>(this, B_VERTICAL)
800 .Add(fSpaceBarShowCheckBox)
801 .Add(box)
802 .AddGlue()
803 .SetInsets(B_USE_DEFAULT_SPACING);
807 SpaceBarSettingsView::~SpaceBarSettingsView()
812 void
813 SpaceBarSettingsView::AttachedToWindow()
815 fSpaceBarShowCheckBox->SetTarget(this);
816 fColorControl->SetTarget(this);
817 fColorPicker->Menu()->SetTargetForItems(this);
821 void
822 SpaceBarSettingsView::MessageReceived(BMessage* message)
824 TTracker* tracker = dynamic_cast<TTracker*>(be_app);
825 if (tracker == NULL)
826 return;
828 TrackerSettings settings;
830 switch (message->what) {
831 case kUpdateVolumeSpaceBar:
833 settings.SetShowVolumeSpaceBar(
834 fSpaceBarShowCheckBox->Value() == 1);
835 Window()->PostMessage(kSettingsContentsModified);
836 tracker->PostMessage(kShowVolumeSpaceBar);
837 break;
840 case kSpaceBarSwitchColor:
842 fCurrentColor = message->FindInt32("index");
843 switch (fCurrentColor) {
844 case 0:
845 fColorControl->SetValue(settings.UsedSpaceColor());
846 break;
848 case 1:
849 fColorControl->SetValue(settings.FreeSpaceColor());
850 break;
852 case 2:
853 fColorControl->SetValue(settings.WarningSpaceColor());
854 break;
856 break;
859 case kSpaceBarColorChanged:
861 rgb_color color = fColorControl->ValueAsColor();
862 color.alpha = kSpaceBarAlpha;
863 // alpha is ignored by BColorControl but is checked
864 // in equalities
866 switch (fCurrentColor) {
867 case 0:
868 settings.SetUsedSpaceColor(color);
869 break;
871 case 1:
872 settings.SetFreeSpaceColor(color);
873 break;
875 case 2:
876 settings.SetWarningSpaceColor(color);
877 break;
880 BWindow* window = Window();
881 if (window != NULL)
882 window->PostMessage(kSettingsContentsModified);
884 tracker->PostMessage(kSpaceBarColorChanged);
885 break;
888 default:
889 _inherited::MessageReceived(message);
890 break;
895 void
896 SpaceBarSettingsView::SetDefaults()
898 TTracker* tracker = dynamic_cast<TTracker*>(be_app);
899 if (tracker == NULL)
900 return;
902 TrackerSettings settings;
904 if (!settings.ShowVolumeSpaceBar()) {
905 settings.SetShowVolumeSpaceBar(true);
906 send_bool_notices(kShowVolumeSpaceBar, "ShowVolumeSpaceBar", true);
909 if (settings.UsedSpaceColor() != kDefaultUsedSpaceColor
910 || settings.FreeSpaceColor() != kDefaultFreeSpaceColor
911 || settings.WarningSpaceColor() != kDefaultWarningSpaceColor) {
912 settings.SetUsedSpaceColor(kDefaultUsedSpaceColor);
913 settings.SetFreeSpaceColor(kDefaultFreeSpaceColor);
914 settings.SetWarningSpaceColor(kDefaultWarningSpaceColor);
915 tracker->SendNotices(kSpaceBarColorChanged);
918 ShowCurrentSettings();
922 bool
923 SpaceBarSettingsView::IsDefaultable() const
925 TrackerSettings settings;
927 return settings.ShowVolumeSpaceBar() != true
928 || settings.UsedSpaceColor() != kDefaultUsedSpaceColor
929 || settings.FreeSpaceColor() != kDefaultFreeSpaceColor
930 || settings.WarningSpaceColor() != kDefaultWarningSpaceColor;
934 void
935 SpaceBarSettingsView::Revert()
937 TTracker* tracker = dynamic_cast<TTracker*>(be_app);
938 if (tracker == NULL)
939 return;
941 TrackerSettings settings;
943 if (settings.ShowVolumeSpaceBar() != fSpaceBarShow) {
944 settings.SetShowVolumeSpaceBar(fSpaceBarShow);
945 send_bool_notices(kShowVolumeSpaceBar, "ShowVolumeSpaceBar",
946 fSpaceBarShow);
949 if (settings.UsedSpaceColor() != fUsedSpaceColor
950 || settings.FreeSpaceColor() != fFreeSpaceColor
951 || settings.WarningSpaceColor() != fWarningSpaceColor) {
952 settings.SetUsedSpaceColor(fUsedSpaceColor);
953 settings.SetFreeSpaceColor(fFreeSpaceColor);
954 settings.SetWarningSpaceColor(fWarningSpaceColor);
955 tracker->SendNotices(kSpaceBarColorChanged);
958 ShowCurrentSettings();
962 void
963 SpaceBarSettingsView::ShowCurrentSettings()
965 TrackerSettings settings;
967 fSpaceBarShowCheckBox->SetValue(settings.ShowVolumeSpaceBar());
969 switch (fCurrentColor) {
970 case 0:
971 fColorControl->SetValue(settings.UsedSpaceColor());
972 break;
973 case 1:
974 fColorControl->SetValue(settings.FreeSpaceColor());
975 break;
976 case 2:
977 fColorControl->SetValue(settings.WarningSpaceColor());
978 break;
983 void
984 SpaceBarSettingsView::RecordRevertSettings()
986 TrackerSettings settings;
988 fSpaceBarShow = settings.ShowVolumeSpaceBar();
989 fUsedSpaceColor = settings.UsedSpaceColor();
990 fFreeSpaceColor = settings.FreeSpaceColor();
991 fWarningSpaceColor = settings.WarningSpaceColor();
995 bool
996 SpaceBarSettingsView::IsRevertable() const
998 TrackerSettings settings;
1000 return fSpaceBarShow != settings.ShowVolumeSpaceBar()
1001 || fUsedSpaceColor != settings.UsedSpaceColor()
1002 || fFreeSpaceColor != settings.FreeSpaceColor()
1003 || fWarningSpaceColor != settings.WarningSpaceColor();