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 "MenuRegistry.h"
23#include "../CommonCommandFlags.h"
24#include "LoadCommands.h"
25#include "Prefs.h"
26#include "SettingsVisitor.h"
27#include "ShuttleGui.h"
28#include "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;
108 }
109 return bOK;
110}
111
112namespace {
113using namespace MenuRegistry;
114
115// Register menu items
116
118 Items( wxT(""),
119 // Note that the PLUGIN_SYMBOL must have a space between words,
120 // whereas the short-form used here must not.
121 // (So if you did write "Compare Audio" for the PLUGIN_SYMBOL name, then
122 // you would have to use "CompareAudio" here.)
123 Command( wxT("GetPreference"), XXO("Get Preference..."),
125 Command( wxT("SetPreference"), XXO("Set Preference..."),
127 ),
128 wxT("Optional/Extra/Part2/Scriptables1")
129};
130}
wxT("CloseDown"))
AttachedItem sAttachment1
const ReservedCommandFlag & AudioIONotBusyFlag()
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
void DoReloadPreferences(AudacityProject &project)
const auto 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,...
static const ComponentInterfaceSymbol Symbol
bool VisitSettings(SettingsVisitorBase< Const > &S)
bool Apply(const CommandContext &context) override
void PopulateOrExchange(ShuttleGui &S) override
Generates classes whose instances register items at construction.
Definition: Registry.h:388
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:640
virtual bool Flush() noexcept=0
virtual bool Write(const wxString &key, bool value)=0
virtual bool Read(const wxString &key, bool *value) const =0
AUDACITY_DLL_API void OnAudacityCommand(const CommandContext &ctx)
constexpr auto Items
Definition: MenuRegistry.h:427
constexpr auto Command
Definition: MenuRegistry.h:456
BuiltinCommandsModule::Registration< SetPreferenceCommand > reg2
BuiltinCommandsModule::Registration< GetPreferenceCommand > reg