Audacity  3.0.3
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 "LoadCommands.h"
22 #include "Prefs.h"
23 #include "../Shuttle.h"
24 #include "../ShuttleGui.h"
25 #include "../commands/CommandContext.h"
26 #include "../prefs/PrefsDialog.h"
27 
29 { XO("Get Preference") };
30 
32 
34  S.Define( mName, wxT("Name"), wxT("") );
35  return true;
36 }
37 
39 {
40  S.AddSpace(0, 5);
41 
42  S.StartMultiColumn(2, wxALIGN_CENTER);
43  {
44  S.TieTextBox(XXO("Name:"),mName);
45  }
46  S.EndMultiColumn();
47 }
48 
49 
51 {
52  wxString prefValue;
53  if (!gPrefs->Read(mName, &prefValue))
54  return false;
55 
56  context.Status(prefValue);
57  return true;
58 }
59 
61 { XO("Set Preference") };
62 
64 
66  S.Define( mName, wxT("Name"), wxT("") );
67  S.Define( mValue, wxT("Value"), wxT("") );
68  S.Define( mbReload, wxT("Reload"), false );
69  return true;
70 }
71 
73 {
74  S.AddSpace(0, 5);
75 
76  S.StartMultiColumn(2, wxALIGN_CENTER);
77  {
78  S.TieTextBox(XXO("Name:"),mName);
79  S.TieTextBox(XXO("Value:"),mValue);
80  S.TieCheckBox(XXO("Reload"),mbReload);
81  }
82  S.EndMultiColumn();
83 }
84 
86 {
87  bool bOK = gPrefs->Write(mName, mValue) && gPrefs->Flush();
88  if( bOK && mbReload ){
89  auto &project = context.project;
90  DoReloadPreferences( project );
91  }
92  return bOK;
93 }
94 
DoReloadPreferences
void DoReloadPreferences(AudacityProject &project)
Definition: PrefsDialog.cpp:845
SetPreferenceCommand::mValue
wxString mValue
Definition: PreferenceCommands.h:65
LoadCommands.h
gPrefs
FileConfig * gPrefs
Definition: Prefs.cpp:70
ShuttleGuiBase::TieCheckBox
wxCheckBox * TieCheckBox(const TranslatableString &Prompt, bool &Var)
Definition: ShuttleGui.cpp:1629
ShuttleGui::AddSpace
wxSizerItem * AddSpace(int width, int height, int prop=0)
Definition: ShuttleGui.cpp:2447
anonymous_namespace{PreferenceCommands.cpp}::reg2
BuiltinCommandsModule::Registration< SetPreferenceCommand > reg2
Definition: PreferenceCommands.cpp:63
XO
#define XO(s)
Definition: Internat.h:31
ShuttleParams
Shuttle that deals with parameters. This is a base class with lots of virtual functions that do nothi...
Definition: Shuttle.h:62
PreferenceCommands.h
ShuttleGuiBase::EndMultiColumn
void EndMultiColumn()
Definition: ShuttleGui.cpp:1238
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterfaceSymbol.h:27
GetPreferenceCommand::mName
wxString mName
Definition: PreferenceCommands.h:44
ShuttleGuiBase::TieTextBox
wxTextCtrl * TieTextBox(const TranslatableString &Caption, wxString &Value, const int nChars=0)
Definition: ShuttleGui.cpp:1652
BuiltinCommandsModule::Registration
Definition: LoadCommands.h:41
CommandContext::Status
virtual void Status(const wxString &message, bool bFlush=false) const
Definition: CommandContext.cpp:63
SetPreferenceCommand::PopulateOrExchange
void PopulateOrExchange(ShuttleGui &S) override
Definition: PreferenceCommands.cpp:72
XXO
#define XXO(s)
Definition: Internat.h:44
SetPreferenceCommand::mbReload
bool mbReload
Definition: PreferenceCommands.h:66
CommandContext
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
Definition: CommandContext.h:22
ShuttleGuiBase::StartMultiColumn
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Definition: ShuttleGui.cpp:1229
SetPreferenceCommand::Symbol
static const ComponentInterfaceSymbol Symbol
Definition: PreferenceCommands.h:52
SetPreferenceCommand::DefineParams
bool DefineParams(ShuttleParams &S) override
Definition: PreferenceCommands.cpp:65
GetPreferenceCommand::Symbol
static const ComponentInterfaceSymbol Symbol
Definition: PreferenceCommands.h:32
SetPreferenceCommand::mName
wxString mName
Definition: PreferenceCommands.h:64
GetPreferenceCommand::Apply
bool Apply(const CommandContext &context) override
Definition: PreferenceCommands.cpp:50
GetPreferenceCommand::PopulateOrExchange
void PopulateOrExchange(ShuttleGui &S) override
Definition: PreferenceCommands.cpp:38
FileConfig::Flush
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
Definition: FileConfig.cpp:143
SetPreferenceCommand::Apply
bool Apply(const CommandContext &context) override
Definition: PreferenceCommands.cpp:85
GetPreferenceCommand::DefineParams
bool DefineParams(ShuttleParams &S) override
Definition: PreferenceCommands.cpp:33
anonymous_namespace{PreferenceCommands.cpp}::reg
BuiltinCommandsModule::Registration< GetPreferenceCommand > reg
Definition: PreferenceCommands.cpp:31
Prefs.h
ShuttleParams::Define
virtual void Define(bool &var, const wxChar *key, const bool vdefault, const bool vmin=false, const bool vmax=false, const bool vscl=false)
Definition: Shuttle.cpp:332
CommandContext::project
AudacityProject & project
Definition: CommandContext.h:52
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:631