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 "
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
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
MenuRegistry
;
114
115
// Register menu items
116
117
AttachedItem
sAttachment1
{
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..."
),
124
CommandDispatch::OnAudacityCommand
,
AudioIONotBusyFlag
() ),
125
Command
(
wxT
(
"SetPreference"
),
XXO
(
"Set Preference..."
),
126
CommandDispatch::OnAudacityCommand
,
AudioIONotBusyFlag
() )
127
),
128
wxT
(
"Optional/Extra/Part2/Scriptables1"
)
129
};
130
}
wxT
wxT("CloseDown"))
sAttachment1
AttachedItem sAttachment1
Definition:
BatchProcessDialog.cpp:1590
CommandContext.h
CommandDispatch.h
AudioIONotBusyFlag
const ReservedCommandFlag & AudioIONotBusyFlag()
Definition:
CommonCommandFlags.cpp:118
XO
XO("Cut/Copy/Paste")
XXO
XXO("&Cut/Copy/Paste Toolbar")
LoadCommands.h
MenuRegistry.h
PreferenceCommands.h
gPrefs
audacity::BasicSettings * gPrefs
Definition:
Prefs.cpp:68
Prefs.h
DoReloadPreferences
void DoReloadPreferences(AudacityProject &project)
Definition:
PrefsDialog.cpp:860
SettingsVisitor.h
ShuttleGui.h
project
const auto project
Definition:
TestWaveTrackMaker.cpp:18
S
#define S(N)
Definition:
ToChars.cpp:64
CommandContext
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
Definition:
CommandContext.h:37
CommandContext::Status
virtual void Status(const wxString &message, bool bFlush=false) const
Definition:
CommandContext.cpp:60
CommandContext::project
AudacityProject & project
Definition:
CommandContext.h:71
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition:
ComponentInterfaceSymbol.h:27
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
Registry::RegisteredItem
Generates classes whose instances register items at construction.
Definition:
Registry.h:388
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:640
audacity::BasicSettings::Flush
virtual bool Flush() noexcept=0
audacity::BasicSettings::Write
virtual bool Write(const wxString &key, bool value)=0
audacity::BasicSettings::Read
virtual bool Read(const wxString &key, bool *value) const =0
CommandDispatch::OnAudacityCommand
AUDACITY_DLL_API void OnAudacityCommand(const CommandContext &ctx)
Definition:
CommandDispatch.cpp:96
MenuRegistry
Definition:
MenuRegistry.cpp:19
MenuRegistry::Items
constexpr auto Items
Definition:
MenuRegistry.h:427
MenuRegistry::Command
constexpr auto Command
Definition:
MenuRegistry.h:456
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
Generated by
1.9.3