Audacity
3.2.0
src
commands
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
31
const
ComponentInterfaceSymbol
GetPreferenceCommand::Symbol
32
{
XO
(
"Get Preference"
) };
33
34
namespace
{
BuiltinCommandsModule::Registration< GetPreferenceCommand >
reg
; }
35
36
template
<
bool
Const>
37
bool
GetPreferenceCommand::VisitSettings
(
SettingsVisitorBase<Const>
&
S
){
38
S
.Define(
mName
,
wxT
(
"Name"
), wxString{} );
39
return
true
;
40
}
41
42
bool
GetPreferenceCommand::VisitSettings
(
SettingsVisitor
&
S
)
43
{
return
VisitSettings<false>(
S
); }
44
45
bool
GetPreferenceCommand::VisitSettings
(
ConstSettingsVisitor
&
S
)
46
{
return
VisitSettings<true>(
S
); }
47
48
void
GetPreferenceCommand::PopulateOrExchange
(
ShuttleGui
&
S
)
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
60
bool
GetPreferenceCommand::Apply
(
const
CommandContext
& context)
61
{
62
wxString prefValue;
63
if
(!
gPrefs
->Read(
mName
, &prefValue))
64
return
false
;
65
66
context.
Status
(prefValue);
67
return
true
;
68
}
69
70
const
ComponentInterfaceSymbol
SetPreferenceCommand::Symbol
71
{
XO
(
"Set Preference"
) };
72
73
namespace
{
BuiltinCommandsModule::Registration< SetPreferenceCommand >
reg2
; }
74
75
template
<
bool
Const>
76
bool
SetPreferenceCommand::VisitSettings
(
SettingsVisitorBase<Const>
&
S
){
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
83
bool
SetPreferenceCommand::VisitSettings
(
SettingsVisitor
&
S
)
84
{
return
VisitSettings<false>(
S
); }
85
86
bool
SetPreferenceCommand::VisitSettings
(
ConstSettingsVisitor
&
S
)
87
{
return
VisitSettings<true>(
S
); }
88
89
void
SetPreferenceCommand::PopulateOrExchange
(
ShuttleGui
&
S
)
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
102
bool
SetPreferenceCommand::Apply
(
const
CommandContext
& context)
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
112
namespace
{
113
using namespace
MenuTable
;
114
115
// Register menu items
116
117
AttachedItem
sAttachment1
{
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..."
),
125
CommandDispatch::OnAudacityCommand
,
AudioIONotBusyFlag
() ),
126
Command
(
wxT
(
"SetPreference"
),
XXO
(
"Set Preference..."
),
127
CommandDispatch::OnAudacityCommand
,
AudioIONotBusyFlag
() )
128
)
129
};
130
}
wxT
wxT("CloseDown"))
sAttachment1
AttachedItem sAttachment1
Definition:
BatchProcessDialog.cpp:1578
CommandDispatch.h
CommandManager.h
AudioIONotBusyFlag
const ReservedCommandFlag & AudioIONotBusyFlag()
Definition:
CommonCommandFlags.cpp:127
XO
XO("Cut/Copy/Paste")
XXO
XXO("&Cut/Copy/Paste Toolbar")
LoadCommands.h
PreferenceCommands.h
gPrefs
FileConfig * gPrefs
Definition:
Prefs.cpp:70
Prefs.h
DoReloadPreferences
void DoReloadPreferences(AudacityProject &project)
Definition:
PrefsDialog.cpp:862
SettingsVisitor.h
ShuttleGui.h
S
#define S(N)
Definition:
ToChars.cpp:64
CommandContext
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
Definition:
CommandContext.h:34
CommandContext::Status
virtual void Status(const wxString &message, bool bFlush=false) const
Definition:
CommandContext.cpp:62
CommandContext::project
AudacityProject & project
Definition:
CommandContext.h:64
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition:
ComponentInterfaceSymbol.h:27
FileConfig::Flush
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
Definition:
FileConfig.cpp:143
GetPreferenceCommand::Symbol
static const ComponentInterfaceSymbol Symbol
Definition:
PreferenceCommands.h:32
GetPreferenceCommand::VisitSettings
bool VisitSettings(SettingsVisitorBase< Const > &S)
Definition:
PreferenceCommands.cpp:37
GetPreferenceCommand::Apply
bool Apply(const CommandContext &context) override
Definition:
PreferenceCommands.cpp:60
GetPreferenceCommand::mName
wxString mName
Definition:
PreferenceCommands.h:46
GetPreferenceCommand::PopulateOrExchange
void PopulateOrExchange(ShuttleGui &S) override
Definition:
PreferenceCommands.cpp:48
SetPreferenceCommand::mName
wxString mName
Definition:
PreferenceCommands.h:68
SetPreferenceCommand::mbReload
bool mbReload
Definition:
PreferenceCommands.h:70
SetPreferenceCommand::Apply
bool Apply(const CommandContext &context) override
Definition:
PreferenceCommands.cpp:102
SetPreferenceCommand::mValue
wxString mValue
Definition:
PreferenceCommands.h:69
SetPreferenceCommand::PopulateOrExchange
void PopulateOrExchange(ShuttleGui &S) override
Definition:
PreferenceCommands.cpp:89
SetPreferenceCommand::VisitSettings
bool VisitSettings(SettingsVisitorBase< Const > &S)
Definition:
PreferenceCommands.cpp:76
SetPreferenceCommand::Symbol
static const ComponentInterfaceSymbol Symbol
Definition:
PreferenceCommands.h:54
SettingsVisitorBase
Visitor of effect or command parameters. This is a base class with lots of virtual functions that do ...
Definition:
SettingsVisitor.h:79
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition:
ShuttleGui.h:625
CommandDispatch::OnAudacityCommand
AUDACITY_DLL_API void OnAudacityCommand(const CommandContext &ctx)
Definition:
CommandDispatch.cpp:95
MenuTable
Definition:
CommandManager.h:418
MenuTable::Items
std::unique_ptr< MenuItems > Items(const Identifier &internalName, Args &&... args)
Definition:
CommandManager.h:636
MenuTable::Command
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())
Definition:
CommandManager.h:714
anonymous_namespace{PreferenceCommands.cpp}::reg2
BuiltinCommandsModule::Registration< SetPreferenceCommand > reg2
Definition:
PreferenceCommands.cpp:73
anonymous_namespace{PreferenceCommands.cpp}::reg
BuiltinCommandsModule::Registration< GetPreferenceCommand > reg
Definition:
PreferenceCommands.cpp:34
BuiltinCommandsModule::Registration
Definition:
LoadCommands.h:41
MenuTable::AttachedItem
Definition:
CommandManager.h:779
Generated by
1.9.3