1 /* 2 Open Tracker License 3 4 Terms and Conditions 5 6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved. 7 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: 14 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. 17 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. 24 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. 28 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. 33 */ 34 35 36 #include "SettingsViews.h" 37 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> 51 52 #include "Commands.h" 53 #include "DeskWindow.h" 54 #include "Model.h" 55 #include "Tracker.h" 56 #include "WidgetAttributeText.h" 57 58 59 static const uint32 kSpaceBarSwitchColor = 'SBsc'; 60 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 }; 71 72 73 static void 74 send_bool_notices(uint32 what, const char* name, bool value) 75 { 76 TTracker* tracker = dynamic_cast<TTracker*>(be_app); 77 if (tracker == NULL) 78 return; 79 80 BMessage message; 81 message.AddBool(name, value); 82 tracker->SendNotices(what, &message); 83 } 84 85 86 #undef B_TRANSLATION_CONTEXT 87 #define B_TRANSLATION_CONTEXT "SettingsView" 88 89 90 // #pragma mark - SettingsView 91 92 93 SettingsView::SettingsView(const char* name) 94 : 95 BGroupView(name) 96 { 97 } 98 99 100 SettingsView::~SettingsView() 101 { 102 } 103 104 105 /*! 106 The inherited functions should set the default values 107 and update the UI gadgets. The latter can by done by 108 calling ShowCurrentSettings(). 109 */ 110 void 111 SettingsView::SetDefaults() 112 { 113 } 114 115 116 /*! 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. 121 */ 122 bool 123 SettingsView::IsDefaultable() const 124 { 125 return true; 126 } 127 128 129 /*! 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(). 134 */ 135 void 136 SettingsView::Revert() 137 { 138 } 139 140 141 /*! 142 This function is called when the window is shown to let 143 the settings views record the state to revert to. 144 */ 145 void 146 SettingsView::RecordRevertSettings() 147 { 148 } 149 150 151 /*! 152 This function is used by the window to tell the view 153 to display the current settings in the tracker. 154 */ 155 void 156 SettingsView::ShowCurrentSettings() 157 { 158 } 159 160 161 /*! 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. 165 */ 166 bool 167 SettingsView::IsRevertable() const 168 { 169 return true; 170 } 171 172 173 // #pragma mark - DesktopSettingsView 174 175 176 DesktopSettingsView::DesktopSettingsView() 177 : 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) 187 { 188 fShowDisksIconRadioButton = new BRadioButton("", 189 B_TRANSLATE("Show Disks icon"), 190 new BMessage(kShowDisksIconChanged)); 191 192 fMountVolumesOntoDesktopRadioButton = new BRadioButton("", 193 B_TRANSLATE("Show volumes on Desktop"), 194 new BMessage(kVolumesOnDesktopChanged)); 195 196 fMountSharedVolumesOntoDesktopCheckBox = new BCheckBox("", 197 B_TRANSLATE("Show shared volumes on Desktop"), 198 new BMessage(kVolumesOnDesktopChanged)); 199 200 const float spacing = be_control_look->DefaultItemSpacing(); 201 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); 211 } 212 213 214 void 215 DesktopSettingsView::AttachedToWindow() 216 { 217 fShowDisksIconRadioButton->SetTarget(this); 218 fMountVolumesOntoDesktopRadioButton->SetTarget(this); 219 fMountSharedVolumesOntoDesktopCheckBox->SetTarget(this); 220 } 221 222 223 void 224 DesktopSettingsView::MessageReceived(BMessage* message) 225 { 226 TTracker* tracker = dynamic_cast<TTracker*>(be_app); 227 if (tracker == NULL) 228 return; 229 230 TrackerSettings settings; 231 232 switch (message->what) { 233 case kShowDisksIconChanged: 234 { 235 // Turn on and off related settings: 236 fMountVolumesOntoDesktopRadioButton->SetValue( 237 !fShowDisksIconRadioButton->Value() == 1); 238 fMountSharedVolumesOntoDesktopCheckBox->SetEnabled( 239 fMountVolumesOntoDesktopRadioButton->Value() == 1); 240 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); 247 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); 256 257 // Send the notification message: 258 tracker->SendNotices(kVolumesOnDesktopChanged, 259 ¬ificationMessage); 260 261 // Tell the settings window the contents have changed: 262 Window()->PostMessage(kSettingsContentsModified); 263 break; 264 } 265 266 case kVolumesOnDesktopChanged: 267 { 268 // Turn on and off related settings: 269 fShowDisksIconRadioButton->SetValue( 270 !fMountVolumesOntoDesktopRadioButton->Value() == 1); 271 fMountSharedVolumesOntoDesktopCheckBox->SetEnabled( 272 fMountVolumesOntoDesktopRadioButton->Value() == 1); 273 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); 280 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); 289 290 // Send the notification message: 291 tracker->SendNotices(kVolumesOnDesktopChanged,\ 292 ¬ificationMessage); 293 294 // Tell the settings window the contents have changed: 295 Window()->PostMessage(kSettingsContentsModified); 296 break; 297 } 298 299 default: 300 _inherited::MessageReceived(message); 301 break; 302 } 303 } 304 305 306 void 307 DesktopSettingsView::SetDefaults() 308 { 309 // ToDo: Avoid the duplication of the default values. 310 TrackerSettings settings; 311 312 settings.SetShowDisksIcon(false); 313 settings.SetMountVolumesOntoDesktop(true); 314 settings.SetMountSharedVolumesOntoDesktop(true); 315 settings.SetEjectWhenUnmounting(true); 316 317 ShowCurrentSettings(); 318 _SendNotices(); 319 } 320 321 322 bool 323 DesktopSettingsView::IsDefaultable() const 324 { 325 TrackerSettings settings; 326 327 return settings.ShowDisksIcon() != false 328 || settings.MountVolumesOntoDesktop() != true 329 || settings.MountSharedVolumesOntoDesktop() != true 330 || settings.EjectWhenUnmounting() != true; 331 } 332 333 334 void 335 DesktopSettingsView::Revert() 336 { 337 TrackerSettings settings; 338 339 settings.SetShowDisksIcon(fShowDisksIcon); 340 settings.SetMountVolumesOntoDesktop(fMountVolumesOntoDesktop); 341 settings.SetMountSharedVolumesOntoDesktop(fMountSharedVolumesOntoDesktop); 342 settings.SetEjectWhenUnmounting(fEjectWhenUnmounting); 343 344 ShowCurrentSettings(); 345 _SendNotices(); 346 } 347 348 349 void 350 DesktopSettingsView::_SendNotices() 351 { 352 TTracker* tracker = dynamic_cast<TTracker*>(be_app); 353 if (tracker == NULL) 354 return; 355 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); 364 365 // Send notices to the tracker about the change: 366 tracker->SendNotices(kVolumesOnDesktopChanged, ¬ificationMessage); 367 tracker->SendNotices(kDesktopIntegrationChanged, ¬ificationMessage); 368 } 369 370 371 void 372 DesktopSettingsView::ShowCurrentSettings() 373 { 374 TrackerSettings settings; 375 376 fShowDisksIconRadioButton->SetValue(settings.ShowDisksIcon()); 377 fMountVolumesOntoDesktopRadioButton->SetValue( 378 settings.MountVolumesOntoDesktop()); 379 380 fMountSharedVolumesOntoDesktopCheckBox->SetValue( 381 settings.MountSharedVolumesOntoDesktop()); 382 fMountSharedVolumesOntoDesktopCheckBox->SetEnabled( 383 settings.MountVolumesOntoDesktop()); 384 } 385 386 387 void 388 DesktopSettingsView::RecordRevertSettings() 389 { 390 TrackerSettings settings; 391 392 fShowDisksIcon = settings.ShowDisksIcon(); 393 fMountVolumesOntoDesktop = settings.MountVolumesOntoDesktop(); 394 fMountSharedVolumesOntoDesktop = settings.MountSharedVolumesOntoDesktop(); 395 fEjectWhenUnmounting = settings.EjectWhenUnmounting(); 396 } 397 398 399 bool 400 DesktopSettingsView::IsRevertable() const 401 { 402 return fShowDisksIcon != (fShowDisksIconRadioButton->Value() > 0) 403 || fMountVolumesOntoDesktop != 404 (fMountVolumesOntoDesktopRadioButton->Value() > 0) 405 || fMountSharedVolumesOntoDesktop != 406 (fMountSharedVolumesOntoDesktopCheckBox->Value() > 0); 407 } 408 409 410 // #pragma mark - WindowsSettingsView 411 412 413 WindowsSettingsView::WindowsSettingsView() 414 : 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) 430 { 431 fShowFullPathInTitleBarCheckBox = new BCheckBox("", 432 B_TRANSLATE("Show folder location in title tab"), 433 new BMessage(kWindowsShowFullPathChanged)); 434 435 fSingleWindowBrowseCheckBox = new BCheckBox("", 436 B_TRANSLATE("Single window navigation"), 437 new BMessage(kSingleWindowBrowseChanged)); 438 439 fShowNavigatorCheckBox = new BCheckBox("", 440 B_TRANSLATE("Show navigator"), 441 new BMessage(kShowNavigatorChanged)); 442 443 fOutlineSelectionCheckBox = new BCheckBox("", 444 B_TRANSLATE("Outline selection rectangle only"), 445 new BMessage(kTransparentSelectionChanged)); 446 447 fSortFolderNamesFirstCheckBox = new BCheckBox("", 448 B_TRANSLATE("List folders first"), 449 new BMessage(kSortFolderNamesFirstChanged)); 450 451 fHideDotFilesCheckBox = new BCheckBox("", 452 B_TRANSLATE("Hide dotfiles"), 453 new BMessage(kHideDotFilesChanged)); 454 455 fTypeAheadFilteringCheckBox = new BCheckBox("", 456 B_TRANSLATE("Enable type-ahead filtering"), 457 new BMessage(kTypeAheadFilteringChanged)); 458 459 const float spacing = be_control_look->DefaultItemSpacing(); 460 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); 478 } 479 480 481 void 482 WindowsSettingsView::AttachedToWindow() 483 { 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); 491 } 492 493 494 void 495 WindowsSettingsView::MessageReceived(BMessage* message) 496 { 497 TTracker* tracker = dynamic_cast<TTracker*>(be_app); 498 if (tracker == NULL) 499 return; 500 501 TrackerSettings settings; 502 503 switch (message->what) { 504 case kWindowsShowFullPathChanged: 505 settings.SetShowFullPathInTitleBar( 506 fShowFullPathInTitleBarCheckBox->Value() == 1); 507 tracker->SendNotices(kWindowsShowFullPathChanged); 508 Window()->PostMessage(kSettingsContentsModified); 509 break; 510 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); 521 } 522 tracker->SendNotices(kShowNavigatorChanged); 523 tracker->SendNotices(kSingleWindowBrowseChanged); 524 Window()->PostMessage(kSettingsContentsModified); 525 break; 526 527 case kShowNavigatorChanged: 528 settings.SetShowNavigator(fShowNavigatorCheckBox->Value() == 1); 529 tracker->SendNotices(kShowNavigatorChanged); 530 Window()->PostMessage(kSettingsContentsModified); 531 break; 532 533 case kTransparentSelectionChanged: 534 { 535 settings.SetTransparentSelection( 536 fOutlineSelectionCheckBox->Value() == B_CONTROL_OFF); 537 538 // Make the notification message and send it to the tracker: 539 send_bool_notices(kTransparentSelectionChanged, 540 "TransparentSelection", settings.TransparentSelection()); 541 542 Window()->PostMessage(kSettingsContentsModified); 543 break; 544 } 545 546 case kSortFolderNamesFirstChanged: 547 { 548 settings.SetSortFolderNamesFirst( 549 fSortFolderNamesFirstCheckBox->Value() == 1); 550 551 // Make the notification message and send it to the tracker: 552 send_bool_notices(kSortFolderNamesFirstChanged, 553 "SortFolderNamesFirst", 554 fSortFolderNamesFirstCheckBox->Value() == 1); 555 556 Window()->PostMessage(kSettingsContentsModified); 557 break; 558 } 559 560 case kHideDotFilesChanged: 561 { 562 settings.SetHideDotFiles( 563 fHideDotFilesCheckBox->Value() == 1); 564 565 // Make the notification message and send it to the tracker: 566 send_bool_notices(kHideDotFilesChanged, 567 "HideDotFiles", 568 fHideDotFilesCheckBox->Value() == 1); 569 570 Window()->PostMessage(kSettingsContentsModified); 571 break; 572 } 573 574 case kTypeAheadFilteringChanged: 575 { 576 settings.SetTypeAheadFiltering( 577 fTypeAheadFilteringCheckBox->Value() == 1); 578 send_bool_notices(kTypeAheadFilteringChanged, 579 "TypeAheadFiltering", 580 fTypeAheadFilteringCheckBox->Value() == 1); 581 Window()->PostMessage(kSettingsContentsModified); 582 break; 583 } 584 585 default: 586 _inherited::MessageReceived(message); 587 break; 588 } 589 } 590 591 592 void 593 WindowsSettingsView::SetDefaults() 594 { 595 TTracker* tracker = dynamic_cast<TTracker*>(be_app); 596 if (tracker == NULL) 597 return; 598 599 TrackerSettings settings; 600 601 if (settings.ShowFullPathInTitleBar()) { 602 settings.SetShowFullPathInTitleBar(false); 603 tracker->SendNotices(kWindowsShowFullPathChanged); 604 } 605 606 if (settings.SingleWindowBrowse()) { 607 settings.SetSingleWindowBrowse(false); 608 tracker->SendNotices(kSingleWindowBrowseChanged); 609 } 610 611 if (settings.ShowNavigator()) { 612 settings.SetShowNavigator(false); 613 tracker->SendNotices(kShowNavigatorChanged); 614 } 615 616 if (!settings.TransparentSelection()) { 617 settings.SetTransparentSelection(true); 618 send_bool_notices(kTransparentSelectionChanged, 619 "TransparentSelection", true); 620 } 621 622 if (!settings.SortFolderNamesFirst()) { 623 settings.SetSortFolderNamesFirst(true); 624 send_bool_notices(kSortFolderNamesFirstChanged, 625 "SortFolderNamesFirst", true); 626 } 627 628 if (!settings.HideDotFiles()) { 629 settings.SetHideDotFiles(true); 630 send_bool_notices(kHideDotFilesChanged, 631 "HideDotFiles", true); 632 } 633 634 if (settings.TypeAheadFiltering()) { 635 settings.SetTypeAheadFiltering(false); 636 send_bool_notices(kTypeAheadFilteringChanged, 637 "TypeAheadFiltering", true); 638 } 639 640 ShowCurrentSettings(); 641 } 642 643 644 bool 645 WindowsSettingsView::IsDefaultable() const 646 { 647 TrackerSettings settings; 648 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; 655 } 656 657 658 void 659 WindowsSettingsView::Revert() 660 { 661 TTracker* tracker = dynamic_cast<TTracker*>(be_app); 662 if (tracker == NULL) 663 return; 664 665 TrackerSettings settings; 666 667 if (settings.ShowFullPathInTitleBar() != fShowFullPathInTitleBar) { 668 settings.SetShowFullPathInTitleBar(fShowFullPathInTitleBar); 669 tracker->SendNotices(kWindowsShowFullPathChanged); 670 } 671 672 if (settings.SingleWindowBrowse() != fSingleWindowBrowse) { 673 settings.SetSingleWindowBrowse(fSingleWindowBrowse); 674 tracker->SendNotices(kSingleWindowBrowseChanged); 675 } 676 677 if (settings.ShowNavigator() != fShowNavigator) { 678 settings.SetShowNavigator(fShowNavigator); 679 tracker->SendNotices(kShowNavigatorChanged); 680 } 681 682 if (settings.TransparentSelection() != fTransparentSelection) { 683 settings.SetTransparentSelection(fTransparentSelection); 684 send_bool_notices(kTransparentSelectionChanged, 685 "TransparentSelection", fTransparentSelection); 686 } 687 688 if (settings.SortFolderNamesFirst() != fSortFolderNamesFirst) { 689 settings.SetSortFolderNamesFirst(fSortFolderNamesFirst); 690 send_bool_notices(kSortFolderNamesFirstChanged, 691 "SortFolderNamesFirst", fSortFolderNamesFirst); 692 } 693 694 if (settings.HideDotFiles() != fHideDotFiles) { 695 settings.SetSortFolderNamesFirst(fHideDotFiles); 696 send_bool_notices(kHideDotFilesChanged, 697 "HideDotFiles", fHideDotFiles); 698 } 699 700 if (settings.TypeAheadFiltering() != fTypeAheadFiltering) { 701 settings.SetTypeAheadFiltering(fTypeAheadFiltering); 702 send_bool_notices(kTypeAheadFilteringChanged, 703 "TypeAheadFiltering", fTypeAheadFiltering); 704 } 705 706 ShowCurrentSettings(); 707 } 708 709 710 void 711 WindowsSettingsView::ShowCurrentSettings() 712 { 713 TrackerSettings settings; 714 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()); 725 } 726 727 728 void 729 WindowsSettingsView::RecordRevertSettings() 730 { 731 TrackerSettings settings; 732 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(); 740 } 741 742 743 bool 744 WindowsSettingsView::IsRevertable() const 745 { 746 TrackerSettings settings; 747 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(); 755 } 756 757 758 // #pragma mark - SpaceBarSettingsView 759 760 761 SpaceBarSettingsView::SpaceBarSettingsView() 762 : 763 SettingsView("SpaceBarSettingsView") 764 { 765 fSpaceBarShowCheckBox = new BCheckBox("", 766 B_TRANSLATE("Show space bars on volumes"), 767 new BMessage(kUpdateVolumeSpaceBar)); 768 769 BPopUpMenu* menu = new BPopUpMenu(B_EMPTY_STRING); 770 menu->SetFont(be_plain_font); 771 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))); 784 785 fColorPicker = new BMenuField("menu", NULL, menu); 786 787 fColorControl = new BColorControl(BPoint(0, 0), 788 B_CELLS_16x16, 1, "SpaceColorControl", 789 new BMessage(kSpaceBarColorChanged)); 790 fColorControl->SetValue(TrackerSettings().UsedSpaceColor()); 791 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()); 798 799 BLayoutBuilder::Group<>(this, B_VERTICAL) 800 .Add(fSpaceBarShowCheckBox) 801 .Add(box) 802 .AddGlue() 803 .SetInsets(B_USE_DEFAULT_SPACING); 804 } 805 806 807 SpaceBarSettingsView::~SpaceBarSettingsView() 808 { 809 } 810 811 812 void 813 SpaceBarSettingsView::AttachedToWindow() 814 { 815 fSpaceBarShowCheckBox->SetTarget(this); 816 fColorControl->SetTarget(this); 817 fColorPicker->Menu()->SetTargetForItems(this); 818 } 819 820 821 void 822 SpaceBarSettingsView::MessageReceived(BMessage* message) 823 { 824 TTracker* tracker = dynamic_cast<TTracker*>(be_app); 825 if (tracker == NULL) 826 return; 827 828 TrackerSettings settings; 829 830 switch (message->what) { 831 case kUpdateVolumeSpaceBar: 832 { 833 settings.SetShowVolumeSpaceBar( 834 fSpaceBarShowCheckBox->Value() == 1); 835 Window()->PostMessage(kSettingsContentsModified); 836 tracker->PostMessage(kShowVolumeSpaceBar); 837 break; 838 } 839 840 case kSpaceBarSwitchColor: 841 { 842 fCurrentColor = message->FindInt32("index"); 843 switch (fCurrentColor) { 844 case 0: 845 fColorControl->SetValue(settings.UsedSpaceColor()); 846 break; 847 848 case 1: 849 fColorControl->SetValue(settings.FreeSpaceColor()); 850 break; 851 852 case 2: 853 fColorControl->SetValue(settings.WarningSpaceColor()); 854 break; 855 } 856 break; 857 } 858 859 case kSpaceBarColorChanged: 860 { 861 rgb_color color = fColorControl->ValueAsColor(); 862 color.alpha = kSpaceBarAlpha; 863 // alpha is ignored by BColorControl but is checked 864 // in equalities 865 866 switch (fCurrentColor) { 867 case 0: 868 settings.SetUsedSpaceColor(color); 869 break; 870 871 case 1: 872 settings.SetFreeSpaceColor(color); 873 break; 874 875 case 2: 876 settings.SetWarningSpaceColor(color); 877 break; 878 } 879 880 BWindow* window = Window(); 881 if (window != NULL) 882 window->PostMessage(kSettingsContentsModified); 883 884 tracker->PostMessage(kSpaceBarColorChanged); 885 break; 886 } 887 888 default: 889 _inherited::MessageReceived(message); 890 break; 891 } 892 } 893 894 895 void 896 SpaceBarSettingsView::SetDefaults() 897 { 898 TTracker* tracker = dynamic_cast<TTracker*>(be_app); 899 if (tracker == NULL) 900 return; 901 902 TrackerSettings settings; 903 904 if (!settings.ShowVolumeSpaceBar()) { 905 settings.SetShowVolumeSpaceBar(true); 906 send_bool_notices(kShowVolumeSpaceBar, "ShowVolumeSpaceBar", true); 907 } 908 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); 916 } 917 918 ShowCurrentSettings(); 919 } 920 921 922 bool 923 SpaceBarSettingsView::IsDefaultable() const 924 { 925 TrackerSettings settings; 926 927 return settings.ShowVolumeSpaceBar() != true 928 || settings.UsedSpaceColor() != kDefaultUsedSpaceColor 929 || settings.FreeSpaceColor() != kDefaultFreeSpaceColor 930 || settings.WarningSpaceColor() != kDefaultWarningSpaceColor; 931 } 932 933 934 void 935 SpaceBarSettingsView::Revert() 936 { 937 TTracker* tracker = dynamic_cast<TTracker*>(be_app); 938 if (tracker == NULL) 939 return; 940 941 TrackerSettings settings; 942 943 if (settings.ShowVolumeSpaceBar() != fSpaceBarShow) { 944 settings.SetShowVolumeSpaceBar(fSpaceBarShow); 945 send_bool_notices(kShowVolumeSpaceBar, "ShowVolumeSpaceBar", 946 fSpaceBarShow); 947 } 948 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); 956 } 957 958 ShowCurrentSettings(); 959 } 960 961 962 void 963 SpaceBarSettingsView::ShowCurrentSettings() 964 { 965 TrackerSettings settings; 966 967 fSpaceBarShowCheckBox->SetValue(settings.ShowVolumeSpaceBar()); 968 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; 979 } 980 } 981 982 983 void 984 SpaceBarSettingsView::RecordRevertSettings() 985 { 986 TrackerSettings settings; 987 988 fSpaceBarShow = settings.ShowVolumeSpaceBar(); 989 fUsedSpaceColor = settings.UsedSpaceColor(); 990 fFreeSpaceColor = settings.FreeSpaceColor(); 991 fWarningSpaceColor = settings.WarningSpaceColor(); 992 } 993 994 995 bool 996 SpaceBarSettingsView::IsRevertable() const 997 { 998 TrackerSettings settings; 999 1000 return fSpaceBarShow != settings.ShowVolumeSpaceBar() 1001 || fUsedSpaceColor != settings.UsedSpaceColor() 1002 || fFreeSpaceColor != settings.FreeSpaceColor() 1003 || fWarningSpaceColor != settings.WarningSpaceColor(); 1004 } 1005