Audacity 3.2.0
PreferenceCommands.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity - A Digital Audio Editor
4 Copyright 1999-2018 Audacity Team
5 File License: wxWidgets
6
7 Dan Horgan
8 James Crook
9
10******************************************************************//*******************************************************************/
17
18
19#include "PreferenceCommands.h"
20
21#include "CommandDispatch.h"
22#include "CommandManager.h"
23#include "../CommonCommandFlags.h"
24#include "LoadCommands.h"
25#include "Prefs.h"
26#include "SettingsVisitor.h"
27#include "ShuttleGui.h"
28#include "../commands/CommandContext.h"
29#include "../prefs/PrefsDialog.h"
30
32{ XO("Get Preference") };
33
35
36template<bool Const>
38 S.Define( mName, wxT("Name"), wxString{} );
39 return true;
40}
41
43 { return VisitSettings<false>(S); }
44
46 { return VisitSettings<true>(S); }
47
49{
50 S.AddSpace(0, 5);
51
52 S.StartMultiColumn(2, wxALIGN_CENTER);
53 {
54 S.TieTextBox(XXO("Name:"),mName);
55 }
56 S.EndMultiColumn();
57}
58
59
61{
62 wxString prefValue;
63 if (!gPrefs->Read(mName, &prefValue))
64 return false;
65
66 context.Status(prefValue);
67 return true;
68}
69
71{ XO("Set Preference") };
72
74
75template<bool Const>
77 S.Define( mName, wxT("Name"), wxString{} );
78 S.Define( mValue, wxT("Value"), wxString{} );
79 S.Define( mbReload, wxT("Reload"), false );
80 return true;
81}
82
84 { return VisitSettings<false>(S); }
85
87 { return VisitSettings<true>(S); }
88
90{
91 S.AddSpace(0, 5);
92
93 S.StartMultiColumn(2, wxALIGN_CENTER);
94 {
95 S.TieTextBox(XXO("Name:"),mName);
96 S.TieTextBox(XXO("Value:"),mValue);
97 S.TieCheckBox(XXO("Reload"),mbReload);
98 }
99 S.EndMultiColumn();
100}
101
103{
104 bool bOK = gPrefs->Write(mName, mValue) && gPrefs->Flush();
105 if( bOK && mbReload ){
106 auto &project = context.project;
107 DoReloadPreferences( project );
108 }
109 return bOK;
110}
111
112namespace {
113using namespace MenuTable;
114
115// Register menu items
116
118 wxT("Optional/Extra/Part2/Scriptables1"),
119 Items( wxT(""),
120 // Note that the PLUGIN_SYMBOL must have a space between words,
121 // whereas the short-form used here must not.
122 // (So if you did write "Compare Audio" for the PLUGIN_SYMBOL name, then
123 // you would have to use "CompareAudio" here.)
124 Command( wxT("GetPreference"), XXO("Get Preference..."),
126 Command( wxT("SetPreference"), XXO("Set Preference..."),
128 )
129};
130}
wxT("CloseDown"))
AttachedItem sAttachment1
const ReservedCommandFlag & AudioIONotBusyFlag()
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
FileConfig * gPrefs
Definition: Prefs.cpp:70
void DoReloadPreferences(AudacityProject &project)
#define S(N)
Definition: ToChars.cpp:64
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
virtual void Status(const wxString &message, bool bFlush=false) const
AudacityProject & project
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
Definition: FileConfig.cpp:143
static const ComponentInterfaceSymbol Symbol
bool VisitSettings(SettingsVisitorBase< Const > &S)
bool Apply(const CommandContext &context) override
void PopulateOrExchange(ShuttleGui &S) override
bool Apply(const CommandContext &context) override
void PopulateOrExchange(ShuttleGui &S) override
bool VisitSettings(SettingsVisitorBase< Const > &S)
static const ComponentInterfaceSymbol Symbol
Visitor of effect or command parameters. This is a base class with lots of virtual functions that do ...
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:625
AUDACITY_DLL_API void OnAudacityCommand(const CommandContext &ctx)
std::unique_ptr< MenuItems > Items(const Identifier &internalName, Args &&... args)
std::unique_ptr< CommandItem > Command(const CommandID &name, const TranslatableString &label_in, void(Handler::*pmf)(const CommandContext &), CommandFlag flags, const CommandManager::Options &options={}, CommandHandlerFinder finder=FinderScope::DefaultFinder())
BuiltinCommandsModule::Registration< SetPreferenceCommand > reg2
BuiltinCommandsModule::Registration< GetPreferenceCommand > reg