mirror of https://github.com/odrling/Aegisub
Load/store Auto4 export filter settings to original subs file
Originally committed to SVN as r991.
This commit is contained in:
parent
a0f3e58894
commit
9c85a4795c
|
@ -298,8 +298,7 @@ namespace Automation4 {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
Auto3ConfigDialog::Auto3ConfigDialog(lua_State *L, const wxString &_ident)
|
Auto3ConfigDialog::Auto3ConfigDialog(lua_State *L)
|
||||||
: ident(_ident)
|
|
||||||
{
|
{
|
||||||
present = false;
|
present = false;
|
||||||
if (!lua_istable(L, -1)) {
|
if (!lua_istable(L, -1)) {
|
||||||
|
@ -523,8 +522,6 @@ continue_invalid_option:
|
||||||
|
|
||||||
void Auto3ConfigDialog::ReadBack()
|
void Auto3ConfigDialog::ReadBack()
|
||||||
{
|
{
|
||||||
wxString opthname = wxString::Format(_T("Automation Settings %s"), ident.c_str());
|
|
||||||
|
|
||||||
for (std::vector<Control>::iterator ctl = controls.begin(); ctl != controls.end(); ctl++) {
|
for (std::vector<Control>::iterator ctl = controls.begin(); ctl != controls.end(); ctl++) {
|
||||||
switch (ctl->option->kind) {
|
switch (ctl->option->kind) {
|
||||||
case COK_TEXT:
|
case COK_TEXT:
|
||||||
|
@ -560,12 +557,9 @@ continue_invalid_option:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// serialize the new settings and save them to the file
|
|
||||||
AssFile::top->SetScriptInfo(opthname, serialize());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString Auto3ConfigDialog::serialize()
|
wxString Auto3ConfigDialog::Serialise()
|
||||||
{
|
{
|
||||||
if (options.size() == 0)
|
if (options.size() == 0)
|
||||||
return _T("");
|
return _T("");
|
||||||
|
@ -599,7 +593,7 @@ continue_invalid_option:
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Auto3ConfigDialog::unserialize(wxString &settings)
|
void Auto3ConfigDialog::Unserialise(const wxString &settings)
|
||||||
{
|
{
|
||||||
wxStringTokenizer toker(settings, _T("|"), wxTOKEN_STRTOK);
|
wxStringTokenizer toker(settings, _T("|"), wxTOKEN_STRTOK);
|
||||||
while (toker.HasMoreTokens()) {
|
while (toker.HasMoreTokens()) {
|
||||||
|
@ -667,11 +661,7 @@ continue_invalid_option:
|
||||||
{
|
{
|
||||||
// configuration (let the config object do all the loading)
|
// configuration (let the config object do all the loading)
|
||||||
lua_getglobal(L, "configuration");
|
lua_getglobal(L, "configuration");
|
||||||
config = new Auto3ConfigDialog(L, GetName());
|
config = new Auto3ConfigDialog(L);
|
||||||
|
|
||||||
wxString opthname = wxString::Format(_T("Automation Settings %s"), GetName().c_str());
|
|
||||||
wxString serialized = AssFile::top->GetScriptInfo(opthname);
|
|
||||||
config->unserialize(serialized);
|
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,20 +113,18 @@ namespace Automation4 {
|
||||||
};
|
};
|
||||||
std::vector<Control> controls;
|
std::vector<Control> controls;
|
||||||
|
|
||||||
wxString ident;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
wxWindow* CreateWindow(wxWindow *parent);
|
wxWindow* CreateWindow(wxWindow *parent);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Auto3ConfigDialog(lua_State *L, const wxString &_ident);
|
Auto3ConfigDialog(lua_State *L);
|
||||||
virtual ~Auto3ConfigDialog();
|
virtual ~Auto3ConfigDialog();
|
||||||
int LuaReadBack(lua_State *L); // read back internal structure to lua structures
|
int LuaReadBack(lua_State *L); // read back internal structure to lua structures
|
||||||
|
|
||||||
void ReadBack(); // from auto4 base
|
void ReadBack(); // from auto4 base
|
||||||
|
|
||||||
wxString serialize(); // make a string from the option name+value pairs
|
wxString Serialise(); // make a string from the option name+value pairs
|
||||||
void unserialize(wxString &settings); // set the option values from a serialized string
|
void Unserialise(const wxString &settings); // set the option values from a serialized string
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,8 @@
|
||||||
#include "auto4_base.h"
|
#include "auto4_base.h"
|
||||||
#include "ass_style.h"
|
#include "ass_style.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
|
#include "string_codec.h"
|
||||||
|
#include "ass_file.h"
|
||||||
#include <wx/filename.h>
|
#include <wx/filename.h>
|
||||||
#include <wx/dir.h>
|
#include <wx/dir.h>
|
||||||
#include <wx/dialog.h>
|
#include <wx/dialog.h>
|
||||||
|
@ -243,12 +245,21 @@ namespace Automation4 {
|
||||||
Unregister();
|
Unregister();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxString FeatureFilter::GetScriptSettingsIdentifier()
|
||||||
|
{
|
||||||
|
return inline_string_encode(wxString::Format(_T("Automation Settings %s"), GetName().c_str()));
|
||||||
|
}
|
||||||
|
|
||||||
wxWindow* FeatureFilter::GetConfigDialogWindow(wxWindow *parent) {
|
wxWindow* FeatureFilter::GetConfigDialogWindow(wxWindow *parent) {
|
||||||
if (config_dialog) {
|
if (config_dialog) {
|
||||||
delete config_dialog;
|
delete config_dialog;
|
||||||
config_dialog = 0;
|
config_dialog = 0;
|
||||||
}
|
}
|
||||||
if ((config_dialog = GenerateConfigDialog(parent)) != NULL) {
|
if ((config_dialog = GenerateConfigDialog(parent)) != NULL) {
|
||||||
|
wxString val = AssFile::top->GetScriptInfo(GetScriptSettingsIdentifier());
|
||||||
|
if (!val.IsEmpty()) {
|
||||||
|
config_dialog->Unserialise(val);
|
||||||
|
}
|
||||||
return config_dialog->GetWindow(parent);
|
return config_dialog->GetWindow(parent);
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -258,6 +269,11 @@ namespace Automation4 {
|
||||||
void FeatureFilter::LoadSettings(bool IsDefault) {
|
void FeatureFilter::LoadSettings(bool IsDefault) {
|
||||||
if (config_dialog) {
|
if (config_dialog) {
|
||||||
config_dialog->ReadBack();
|
config_dialog->ReadBack();
|
||||||
|
|
||||||
|
wxString val = config_dialog->Serialise();
|
||||||
|
if (!val.IsEmpty()) {
|
||||||
|
AssFile::top->SetScriptInfo(GetScriptSettingsIdentifier(), val);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -306,6 +322,11 @@ namespace Automation4 {
|
||||||
win = 0;
|
win = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxString ScriptConfigDialog::Serialise()
|
||||||
|
{
|
||||||
|
return _T("");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ProgressSink
|
// ProgressSink
|
||||||
|
|
||||||
|
|
|
@ -127,6 +127,8 @@ namespace Automation4 {
|
||||||
|
|
||||||
virtual ScriptConfigDialog* GenerateConfigDialog(wxWindow *parent) = 0; // subclasses should implement this, producing a new ScriptConfigDialog
|
virtual ScriptConfigDialog* GenerateConfigDialog(wxWindow *parent) = 0; // subclasses should implement this, producing a new ScriptConfigDialog
|
||||||
|
|
||||||
|
wxString GetScriptSettingsIdentifier();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~FeatureFilter();
|
virtual ~FeatureFilter();
|
||||||
|
|
||||||
|
@ -174,6 +176,9 @@ namespace Automation4 {
|
||||||
wxWindow* GetWindow(wxWindow *parent);
|
wxWindow* GetWindow(wxWindow *parent);
|
||||||
void DeleteWindow();
|
void DeleteWindow();
|
||||||
virtual void ReadBack() = 0;
|
virtual void ReadBack() = 0;
|
||||||
|
|
||||||
|
virtual wxString Serialise();
|
||||||
|
virtual void Unserialise(const wxString &serialised) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -736,12 +736,12 @@ namespace Automation4 {
|
||||||
|
|
||||||
ps->ShowModal();
|
ps->ShowModal();
|
||||||
wxThread::ExitCode code = call.Wait();
|
wxThread::ExitCode code = call.Wait();
|
||||||
//if (code) ThrowError();
|
|
||||||
|
|
||||||
delete ps;
|
delete ps;
|
||||||
|
|
||||||
// The config dialog table should now be on stack
|
|
||||||
if (!code) {
|
if (!code) {
|
||||||
|
// The config dialog table should now be on stack as LuaConfigDialog constructor expects
|
||||||
return config_dialog = new LuaConfigDialog(L, false);
|
return config_dialog = new LuaConfigDialog(L, false);
|
||||||
} else {
|
} else {
|
||||||
return config_dialog = 0;
|
return config_dialog = 0;
|
||||||
|
|
|
@ -130,6 +130,10 @@ namespace Automation4 {
|
||||||
virtual void ControlReadBack() = 0;
|
virtual void ControlReadBack() = 0;
|
||||||
virtual void LuaReadBack(lua_State *L) = 0;
|
virtual void LuaReadBack(lua_State *L) = 0;
|
||||||
|
|
||||||
|
virtual bool CanSerialiseValue() { return false; }
|
||||||
|
virtual wxString SerialiseValue() { return _T(""); }
|
||||||
|
virtual void UnserialiseValue(const wxString &serialised) { }
|
||||||
|
|
||||||
LuaConfigDialogControl(lua_State *L);
|
LuaConfigDialogControl(lua_State *L);
|
||||||
virtual ~LuaConfigDialogControl() { }
|
virtual ~LuaConfigDialogControl() { }
|
||||||
};
|
};
|
||||||
|
@ -157,6 +161,9 @@ namespace Automation4 {
|
||||||
virtual ~LuaConfigDialog();
|
virtual ~LuaConfigDialog();
|
||||||
int LuaReadBack(lua_State *L); // read back internal structure to lua structures
|
int LuaReadBack(lua_State *L); // read back internal structure to lua structures
|
||||||
|
|
||||||
|
wxString Serialise();
|
||||||
|
void Unserialise(const wxString &serialised);
|
||||||
|
|
||||||
void ReadBack(); // from auto4 base
|
void ReadBack(); // from auto4 base
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -36,11 +36,14 @@
|
||||||
#include "auto4_lua.h"
|
#include "auto4_lua.h"
|
||||||
#include "../lua51/src/lualib.h"
|
#include "../lua51/src/lualib.h"
|
||||||
#include "../lua51/src/lauxlib.h"
|
#include "../lua51/src/lauxlib.h"
|
||||||
|
#include "string_codec.h"
|
||||||
|
#include "utils.h"
|
||||||
#include <wx/window.h>
|
#include <wx/window.h>
|
||||||
#include <wx/spinctrl.h>
|
#include <wx/spinctrl.h>
|
||||||
#include <wx/gbsizer.h>
|
#include <wx/gbsizer.h>
|
||||||
#include <wx/button.h>
|
#include <wx/button.h>
|
||||||
#include <wx/validate.h>
|
#include <wx/validate.h>
|
||||||
|
#include <wx/tokenzr.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
namespace Automation4 {
|
namespace Automation4 {
|
||||||
|
@ -125,6 +128,8 @@ namespace Automation4 {
|
||||||
|
|
||||||
virtual ~Label() { }
|
virtual ~Label() { }
|
||||||
|
|
||||||
|
// Doesn't have a serialisable value so don't implement that sub-interface
|
||||||
|
|
||||||
wxControl *Create(wxWindow *parent)
|
wxControl *Create(wxWindow *parent)
|
||||||
{
|
{
|
||||||
return cw = new wxStaticText(parent, -1, label);
|
return cw = new wxStaticText(parent, -1, label);
|
||||||
|
@ -159,6 +164,21 @@ namespace Automation4 {
|
||||||
|
|
||||||
virtual ~Edit() { }
|
virtual ~Edit() { }
|
||||||
|
|
||||||
|
bool CanSerialiseValue()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString SerialiseValue()
|
||||||
|
{
|
||||||
|
return inline_string_encode(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnserialiseValue(const wxString &serialised)
|
||||||
|
{
|
||||||
|
text = inline_string_decode(serialised);
|
||||||
|
}
|
||||||
|
|
||||||
wxControl *Create(wxWindow *parent)
|
wxControl *Create(wxWindow *parent)
|
||||||
{
|
{
|
||||||
return cw = new wxTextCtrl(parent, -1, text, wxDefaultPosition, wxDefaultSize, 0);
|
return cw = new wxTextCtrl(parent, -1, text, wxDefaultPosition, wxDefaultSize, 0);
|
||||||
|
@ -190,6 +210,8 @@ namespace Automation4 {
|
||||||
|
|
||||||
virtual ~Textbox() { }
|
virtual ~Textbox() { }
|
||||||
|
|
||||||
|
// Same serialisation interface as single-line edit
|
||||||
|
|
||||||
wxControl *Create(wxWindow *parent)
|
wxControl *Create(wxWindow *parent)
|
||||||
{
|
{
|
||||||
cw = new wxTextCtrl(parent, -1, text, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
|
cw = new wxTextCtrl(parent, -1, text, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
|
||||||
|
@ -238,6 +260,23 @@ nospin:
|
||||||
|
|
||||||
virtual ~IntEdit() { }
|
virtual ~IntEdit() { }
|
||||||
|
|
||||||
|
bool CanSerialiseValue()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString SerialiseValue()
|
||||||
|
{
|
||||||
|
return wxString::Format(_T("%d"), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnserialiseValue(const wxString &serialised)
|
||||||
|
{
|
||||||
|
long tmp;
|
||||||
|
if (serialised.ToLong(&tmp))
|
||||||
|
value = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
typedef wxValidator IntTextValidator; // TODO
|
typedef wxValidator IntTextValidator; // TODO
|
||||||
wxControl *Create(wxWindow *parent)
|
wxControl *Create(wxWindow *parent)
|
||||||
{
|
{
|
||||||
|
@ -288,6 +327,23 @@ nospin:
|
||||||
|
|
||||||
virtual ~FloatEdit() { }
|
virtual ~FloatEdit() { }
|
||||||
|
|
||||||
|
bool CanSerialiseValue()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString SerialiseValue()
|
||||||
|
{
|
||||||
|
return PrettyFloatF(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnserialiseValue(const wxString &serialised)
|
||||||
|
{
|
||||||
|
double tmp;
|
||||||
|
if (serialised.ToDouble(&tmp))
|
||||||
|
value = (float)tmp;
|
||||||
|
}
|
||||||
|
|
||||||
typedef wxValidator FloatTextValidator;
|
typedef wxValidator FloatTextValidator;
|
||||||
wxControl *Create(wxWindow *parent)
|
wxControl *Create(wxWindow *parent)
|
||||||
{
|
{
|
||||||
|
@ -338,6 +394,21 @@ nospin:
|
||||||
|
|
||||||
virtual ~Dropdown() { }
|
virtual ~Dropdown() { }
|
||||||
|
|
||||||
|
bool CanSerialiseValue()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString SerialiseValue()
|
||||||
|
{
|
||||||
|
return inline_string_encode(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnserialiseValue(const wxString &serialised)
|
||||||
|
{
|
||||||
|
value = inline_string_decode(serialised);
|
||||||
|
}
|
||||||
|
|
||||||
wxControl *Create(wxWindow *parent)
|
wxControl *Create(wxWindow *parent)
|
||||||
{
|
{
|
||||||
return cw = new wxComboBox(parent, -1, value, wxDefaultPosition, wxDefaultSize, items, wxCB_READONLY);
|
return cw = new wxComboBox(parent, -1, value, wxDefaultPosition, wxDefaultSize, items, wxCB_READONLY);
|
||||||
|
@ -377,6 +448,22 @@ nospin:
|
||||||
|
|
||||||
virtual ~Checkbox() { }
|
virtual ~Checkbox() { }
|
||||||
|
|
||||||
|
bool CanSerialiseValue()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString SerialiseValue()
|
||||||
|
{
|
||||||
|
return value ? _T("1") : _T("0");
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnserialiseValue(const wxString &serialised)
|
||||||
|
{
|
||||||
|
// fixme? should this allow more different "false" values?
|
||||||
|
value = (serialised == _T("0")) ? false : true;
|
||||||
|
}
|
||||||
|
|
||||||
wxControl *Create(wxWindow *parent)
|
wxControl *Create(wxWindow *parent)
|
||||||
{
|
{
|
||||||
return cw = new wxCheckBox(parent, -1, label);
|
return cw = new wxCheckBox(parent, -1, label);
|
||||||
|
@ -576,6 +663,48 @@ badcontrol:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxString LuaConfigDialog::Serialise()
|
||||||
|
{
|
||||||
|
if (controls.size() == 0)
|
||||||
|
return _T("");
|
||||||
|
|
||||||
|
wxString res;
|
||||||
|
|
||||||
|
// Format into "name1:value1|name2:value2|name3:value3|"
|
||||||
|
for (size_t i = 0; i < controls.size(); ++i) {
|
||||||
|
if (controls[i]->CanSerialiseValue()) {
|
||||||
|
wxString sn = inline_string_encode(controls[i]->name);
|
||||||
|
wxString sv = controls[i]->SerialiseValue();
|
||||||
|
res += wxString::Format(_T("%s:%s|"), sn.c_str(), sv.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove trailing pipe
|
||||||
|
if (!res.IsEmpty())
|
||||||
|
res.RemoveLast();
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LuaConfigDialog::Unserialise(const wxString &serialised)
|
||||||
|
{
|
||||||
|
// Split by pipe
|
||||||
|
wxStringTokenizer tk(serialised, _T("|"));
|
||||||
|
while (tk.HasMoreTokens()) {
|
||||||
|
// Split by colon
|
||||||
|
wxString pair = tk.GetNextToken();
|
||||||
|
wxString name = inline_string_decode(pair.BeforeFirst(_T(':')));
|
||||||
|
wxString value = pair.AfterFirst(_T(':'));
|
||||||
|
|
||||||
|
// Hand value to all controls matching name
|
||||||
|
for (size_t i = 0; i < controls.size(); ++i) {
|
||||||
|
if (controls[i]->name == name && controls[i]->CanSerialiseValue()) {
|
||||||
|
controls[i]->UnserialiseValue(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void LuaConfigDialog::ReadBack()
|
void LuaConfigDialog::ReadBack()
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < controls.size(); ++i) {
|
for (size_t i = 0; i < controls.size(); ++i) {
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
|
|
||||||
#include "string_codec.h"
|
#include "string_codec.h"
|
||||||
|
|
||||||
wxString inline_string_encode(wxString &input)
|
wxString inline_string_encode(const wxString &input)
|
||||||
{
|
{
|
||||||
const size_t inlen = input.length();
|
const size_t inlen = input.length();
|
||||||
wxString output(_T(""));
|
wxString output(_T(""));
|
||||||
|
@ -54,7 +54,7 @@ wxString inline_string_encode(wxString &input)
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString inline_string_decode(wxString &input)
|
wxString inline_string_decode(const wxString &input)
|
||||||
{
|
{
|
||||||
const size_t inlen = input.length();
|
const size_t inlen = input.length();
|
||||||
wxString output(_T(""));
|
wxString output(_T(""));
|
||||||
|
|
|
@ -58,7 +58,7 @@
|
||||||
#include <wx/wxprec.h>
|
#include <wx/wxprec.h>
|
||||||
#include <wx/string.h>
|
#include <wx/string.h>
|
||||||
|
|
||||||
wxString inline_string_encode(wxString &input);
|
wxString inline_string_encode(const wxString &input);
|
||||||
wxString inline_string_decode(wxString &input);
|
wxString inline_string_decode(const wxString &input);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue