Skip to content

Commit

Permalink
refactor Preferences->Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
augiedoggie committed Jul 7, 2024
1 parent 4259477 commit ee11e6c
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 62 deletions.
6 changes: 3 additions & 3 deletions Assets/UserGuide/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Tracker Context Menu
:align: center


The context menu allows you to directly execute one of your saved commands as well as open the preferences or
The context menu allows you to directly execute one of your saved commands as well as open the settings or
management window.

..
Expand Down Expand Up @@ -122,11 +122,11 @@ Use the Terminal application to run the command so that the output can be viewed



Preferences
Settings
-----------

.. image:: ../Screenshots/TrackRunnerPrefs.png
:alt: Preferences window
:alt: Settings window
:align: center


Expand Down
4 changes: 2 additions & 2 deletions Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ set(${PROJECT_NAME}_sources
CommandsWindow.cpp
RunnerAddOn.cpp
RunnerApp.cpp
Preferences.cpp
PreferencesWindow.cpp
Settings.cpp
SettingsWindow.cpp
SortableListView.cpp
TrackRunner.rdef
)
Expand Down
4 changes: 2 additions & 2 deletions Source/CommandSelectWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "CommandSelectWindow.h"
#include "CommandListItem.h"
#include "Constants.h"
#include "Preferences.h"
#include "Settings.h"
#include "RunnerAddOn.h"

#include <Alert.h>
Expand Down Expand Up @@ -241,7 +241,7 @@ status_t
CommandSelectWindow::_LoadCommands()
{
BMessage message;
if (Preferences::ReadPreferences(message) != B_OK)
if (Settings::ReadSettings(message) != B_OK)
return B_ERROR;

BMessage itemMessage;
Expand Down
8 changes: 4 additions & 4 deletions Source/CommandsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "CommandsWindow.h"
#include "CommandListItem.h"
#include "Constants.h"
#include "Preferences.h"
#include "Settings.h"
#include "RunnerAddOn.h"
#include "SortableListView.h"

Expand Down Expand Up @@ -354,7 +354,7 @@ status_t
CommandsWindow::_LoadCommands()
{
BMessage message;
if (Preferences::ReadPreferences(message) != B_OK)
if (Settings::ReadSettings(message) != B_OK)
return B_ERROR;

BMessage itemMessage;
Expand All @@ -378,7 +378,7 @@ status_t
CommandsWindow::_SaveCommands()
{
BMessage message;
if (Preferences::ReadPreferences(message) != B_OK)
if (Settings::ReadSettings(message) != B_OK)
return B_ERROR;

// clear out old command entries
Expand All @@ -397,7 +397,7 @@ CommandsWindow::_SaveCommands()
message.AddMessage(kEntryKey, &itemMessage);
}

return Preferences::WritePreferences(message);
return Settings::WriteSettings(message);
}


Expand Down
17 changes: 0 additions & 17 deletions Source/Preferences.h

This file was deleted.

4 changes: 2 additions & 2 deletions Source/RunnerAddOn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "RunnerAddOn.h"
#include "Constants.h"
#include "Preferences.h"
#include "Settings.h"

#include <Alert.h>
#include <InterfaceDefs.h>
Expand Down Expand Up @@ -169,7 +169,7 @@ populate_menu(BMessage* message, BMenu* menu, BHandler* handler)
menu->RemoveItem(menuItem);

BMessage prefsMessage;
Preferences::ReadPreferences(prefsMessage);
Settings::ReadSettings(prefsMessage);

BMenu* trackMenu = new BMenu(prefsMessage.GetString(kMenuLabelKey, kAppTitle));
BLayoutBuilder::Menu<> builder = BLayoutBuilder::Menu<>(trackMenu);
Expand Down
12 changes: 6 additions & 6 deletions Source/RunnerApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "CommandSelectWindow.h"
#include "CommandsWindow.h"
#include "Constants.h"
#include "PreferencesWindow.h"
#include "SettingsWindow.h"

#include <Alert.h>
#include <Application.h>
Expand Down Expand Up @@ -35,17 +35,17 @@ RunnerApp::MessageReceived(BMessage* message)
switch (message->what) {
case kLaunchPrefsWhat:
{
// search for existing preferences window
// search for existing settings window
for (int32 index = 0; index < CountWindows(); index++) {
PreferencesWindow* window = dynamic_cast<PreferencesWindow*>(WindowAt(index));
SettingsWindow* window = dynamic_cast<SettingsWindow*>(WindowAt(index));
if (window != NULL) {
window->Activate();
return;
}
}

fInitialWindowShown = true;
_ShowPreferencesWindow();
_ShowSettingsWindow();
}
break;
case kLaunchManageWhat:
Expand Down Expand Up @@ -103,11 +103,11 @@ RunnerApp::AboutRequested()


void
RunnerApp::_ShowPreferencesWindow()
RunnerApp::_ShowSettingsWindow()
{
BString title(B_TRANSLATE("%trackrunner% settings"));
title.ReplaceFirst("%trackrunner%", kAppTitle);
PreferencesWindow* window = new PreferencesWindow(title);
SettingsWindow* window = new SettingsWindow(title);
window->Lock();
window->CenterOnScreen();
window->Show();
Expand Down
2 changes: 1 addition & 1 deletion Source/RunnerApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class RunnerApp : public BApplication {

private:
void _ShowManageWindow();
void _ShowPreferencesWindow();
void _ShowSettingsWindow();

bool fInitialWindowShown;
};
Expand Down
6 changes: 3 additions & 3 deletions Source/Preferences.cpp → Source/Settings.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: 2022 Chris Roberts

#include "Preferences.h"
#include "Settings.h"
#include "Constants.h"

#include <File.h>
Expand All @@ -10,7 +10,7 @@


status_t
Preferences::ReadPreferences(BMessage& message)
Settings::ReadSettings(BMessage& message)
{
BPath prefsPath;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &prefsPath) != B_OK)
Expand All @@ -30,7 +30,7 @@ Preferences::ReadPreferences(BMessage& message)


status_t
Preferences::WritePreferences(BMessage& message)
Settings::WriteSettings(BMessage& message)
{
BPath prefsPath;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &prefsPath) != B_OK)
Expand Down
17 changes: 17 additions & 0 deletions Source/Settings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: 2022 Chris Roberts

#ifndef _SETTINGS_H_
#define _SETTINGS_H_

#include <SupportDefs.h>

class BMessage;

class Settings {
public:
static status_t ReadSettings(BMessage& message);
static status_t WriteSettings(BMessage& message);
};

#endif // _SETTINGS_H_
26 changes: 13 additions & 13 deletions Source/PreferencesWindow.cpp → Source/SettingsWindow.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: 2022 Chris Roberts

#include "PreferencesWindow.h"
#include "SettingsWindow.h"
#include "Constants.h"
#include "Preferences.h"
#include "Settings.h"

#include <Application.h>
#include <Button.h>
Expand All @@ -15,7 +15,7 @@
#include <Catalog.h>

#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "PreferencesWindow"
#define B_TRANSLATION_CONTEXT "SettingsWindow"
#else
#define B_TRANSLATE(x) x
#endif
Expand All @@ -30,13 +30,13 @@ enum {
};


PreferencesWindow::PreferencesWindow(BString& title)
SettingsWindow::SettingsWindow(BString& title)
:
BWindow(BRect(100, 100, 400, 300), title, B_TITLED_WINDOW,
B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE)
{
BMessage message;
Preferences::ReadPreferences(message);
Settings::ReadSettings(message);

fMenuLabelControl = new BTextControl(B_TRANSLATE("Menu label:"),
message.GetString(kMenuLabelKey, kAppTitle), NULL);
Expand Down Expand Up @@ -69,7 +69,7 @@ PreferencesWindow::PreferencesWindow(BString& title)


bool
PreferencesWindow::QuitRequested()
SettingsWindow::QuitRequested()
{
if (be_app->CountWindows() == 1)
be_app->PostMessage(B_QUIT_REQUESTED);
Expand All @@ -79,23 +79,23 @@ PreferencesWindow::QuitRequested()


void
PreferencesWindow::MessageReceived(BMessage* message)
SettingsWindow::MessageReceived(BMessage* message)
{
switch (message->what) {
case kDefaultsButtonWhat:
fMenuLabelControl->SetText(kAppTitle);
#ifdef USE_MENUITEM_ICONS
fIconMenuCheckBox->SetValue(kIconMenusDefault);
#endif
_WritePreferences();
_WriteSettings();
break;
#ifdef USE_MENUITEM_ICONS
case kIconCheckBoxWhat:
_WritePreferences();
_WriteSettings();
break;
#endif
case kMenuLabelWhat:
_WritePreferences();
_WriteSettings();
break;
default:
BWindow::MessageReceived(message);
Expand All @@ -104,11 +104,11 @@ PreferencesWindow::MessageReceived(BMessage* message)


status_t
PreferencesWindow::_WritePreferences()
SettingsWindow::_WriteSettings()
{
BMessage message;

Preferences::ReadPreferences(message);
Settings::ReadSettings(message);

#ifdef USE_MENUITEM_ICONS
message.SetBool(kIconMenusKey, fIconMenuCheckBox->Value());
Expand All @@ -130,5 +130,5 @@ PreferencesWindow::_WritePreferences()
fMenuLabelControl->TextView()->SetFontAndColor(&font, B_FONT_ALL, &textColor);
fMenuLabelControl->SetViewColor(viewColor);

return Preferences::WritePreferences(message);
return Settings::WriteSettings(message);
}
12 changes: 6 additions & 6 deletions Source/PreferencesWindow.h → Source/SettingsWindow.h
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: 2022 Chris Roberts

#ifndef _PREFERENCESWINDOW_H_
#define _PREFERENCESWINDOW_H_
#ifndef _SETTINGSWINDOW_H_
#define _SETTINGSWINDOW_H_

#include <Window.h>

class BCheckBox;
class BTextControl;


class PreferencesWindow : public BWindow {
class SettingsWindow : public BWindow {

public:
PreferencesWindow(BString& title);
SettingsWindow(BString& title);

virtual void MessageReceived(BMessage* message);
virtual bool QuitRequested();

private:
status_t _WritePreferences();
status_t _WriteSettings();

#ifdef USE_MENUITEM_ICONS
BCheckBox* fIconMenuCheckBox;
#endif
BTextControl* fMenuLabelControl;
};

#endif // _PREFERENCESWINDOW_H_
#endif // _SETTINGSWINDOW_H_
6 changes: 3 additions & 3 deletions Source/locales/en.catkeys
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Manage commands… RunnerAddOn Manage commands…
Use Terminal CommandSelectWindow Use Terminal
Settings & Help RunnerAddOn Settings & Help
Settings… RunnerAddOn Settings…
Defaults PreferencesWindow Defaults
Defaults SettingsWindow Defaults
Failed to launch URL RunnerAddOn Failed to launch URL
Command: CommandsWindow Command:
TrackRunner\nWritten by Chris Roberts RunnerApp TrackRunner\nWritten by Chris Roberts
Expand All @@ -23,9 +23,9 @@ Cancel CommandSelectWindow Cancel
New CommandsWindow New
Do you wish to delete '%s'? CommandsWindow Do you wish to delete '%s'?
Unable to launch TrackRunner application RunnerAddOn Unable to launch TrackRunner application
Menu label: PreferencesWindow Menu label:
Menu label: SettingsWindow Menu label:
Show in Tracker CommandsWindow Show in Tracker
Close PreferencesWindow Close
Close SettingsWindow Close
Cancel CommandsWindow Cancel
Browse… CommandSelectWindow Browse…
Open the user guide CommandsWindow Open the user guide
Expand Down

0 comments on commit ee11e6c

Please sign in to comment.