mirror of https://github.com/odrling/Aegisub
Fixed bug with grid scrollbar not updating.
Removed some old, unused auto3 files. Originally committed to SVN as r1073.
This commit is contained in:
parent
51cd2f5ced
commit
4b569de80d
File diff suppressed because it is too large
Load Diff
|
@ -1,159 +0,0 @@
|
||||||
// Copyright (c) 2005, 2006, Niels Martin Hansen
|
|
||||||
// All rights reserved.
|
|
||||||
//
|
|
||||||
// Redistribution and use in source and binary forms, with or without
|
|
||||||
// modification, are permitted provided that the following conditions are met:
|
|
||||||
//
|
|
||||||
// * Redistributions of source code must retain the above copyright notice,
|
|
||||||
// this list of conditions and the following disclaimer.
|
|
||||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
// this list of conditions and the following disclaimer in the documentation
|
|
||||||
// and/or other materials provided with the distribution.
|
|
||||||
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
||||||
// may be used to endorse or promote products derived from this software
|
|
||||||
// without specific prior written permission.
|
|
||||||
//
|
|
||||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
||||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
// POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
//
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// AEGISUB
|
|
||||||
//
|
|
||||||
// Website: http://aegisub.cellosoft.com
|
|
||||||
// Contact: mailto:zeratul@cellosoft.com
|
|
||||||
//
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
#if HAVE_LUA50_LUA_H
|
|
||||||
#include <lua50/lua.h>
|
|
||||||
#else
|
|
||||||
#include <lua.h>
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <wx/wxprec.h>
|
|
||||||
#include <wx/filefn.h>
|
|
||||||
#include <vector>
|
|
||||||
#include "ass_file.h"
|
|
||||||
#include "ass_dialogue.h"
|
|
||||||
#include "ass_override.h"
|
|
||||||
#include "ass_style.h"
|
|
||||||
|
|
||||||
#include <setjmp.h>
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
|
|
||||||
class AutomationError {
|
|
||||||
public:
|
|
||||||
wxString message;
|
|
||||||
AutomationError(wxString msg);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
enum AutomationScriptConfigurationOptionKind {
|
|
||||||
COK_INVALID = 0,
|
|
||||||
COK_LABEL,
|
|
||||||
COK_TEXT,
|
|
||||||
COK_INT,
|
|
||||||
COK_FLOAT,
|
|
||||||
COK_BOOL,
|
|
||||||
COK_COLOUR,
|
|
||||||
COK_STYLE
|
|
||||||
};
|
|
||||||
|
|
||||||
struct AutomationScriptConfigurationOption {
|
|
||||||
wxString name;
|
|
||||||
AutomationScriptConfigurationOptionKind kind;
|
|
||||||
wxString label;
|
|
||||||
wxString hint;
|
|
||||||
union {
|
|
||||||
bool isset;
|
|
||||||
int intval;
|
|
||||||
double floatval;
|
|
||||||
} min, max;
|
|
||||||
struct {
|
|
||||||
wxString stringval;
|
|
||||||
int intval;
|
|
||||||
double floatval;
|
|
||||||
bool boolval;
|
|
||||||
AssColor colourval;
|
|
||||||
} default_val, value;
|
|
||||||
};
|
|
||||||
|
|
||||||
class AutomationScriptConfiguration {
|
|
||||||
public:
|
|
||||||
|
|
||||||
bool present; // is there any configuration option set at all?
|
|
||||||
|
|
||||||
std::vector<AutomationScriptConfigurationOption> options;
|
|
||||||
|
|
||||||
wxString serialize(); // make a string from the option name+value pairs
|
|
||||||
void unserialize(wxString &settings); // set the option values from a serialized string
|
|
||||||
|
|
||||||
void load_from_lua(lua_State *L); // top of the stack must be a table in the format of the global "configuration" table, or nil; fill the options vector from that table. (the current options vector will be cleared. all values will be set to the defaults.)
|
|
||||||
void store_to_lua(lua_State *L); // create a process_lines@config style table from the options name:value pairs. after the call, the top of the stack will be such a table.
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct AutomationScriptFile {
|
|
||||||
bool utf8bom;
|
|
||||||
char *scriptdata;
|
|
||||||
size_t scriptlen;
|
|
||||||
wxString filename;
|
|
||||||
|
|
||||||
~AutomationScriptFile();
|
|
||||||
static AutomationScriptFile *CreateFromString(wxString &script);
|
|
||||||
static AutomationScriptFile *CreateFromFile(wxString filename);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class AutomationScript {
|
|
||||||
protected:
|
|
||||||
lua_State *L;
|
|
||||||
jmp_buf panicjmp;
|
|
||||||
|
|
||||||
static int L_panicfunc(lua_State *L);
|
|
||||||
|
|
||||||
public:
|
|
||||||
AutomationScript(AutomationScriptFile *script);
|
|
||||||
virtual ~AutomationScript();
|
|
||||||
|
|
||||||
// Reporting functions. These do nothing in the base class.
|
|
||||||
// They should be overridden in a derived class.
|
|
||||||
virtual void OutputDebugString(wxString str, bool isdebug = false);
|
|
||||||
virtual void ReportProgress(float progress);
|
|
||||||
|
|
||||||
// stuff corresponding to globals in the script
|
|
||||||
float version;
|
|
||||||
wxString kind;
|
|
||||||
wxString name;
|
|
||||||
wxString description;
|
|
||||||
AutomationScriptConfiguration configuration;
|
|
||||||
|
|
||||||
// filename the script was loaded from
|
|
||||||
wxString filename;
|
|
||||||
// include path for scripts
|
|
||||||
wxPathList include_path;
|
|
||||||
|
|
||||||
volatile bool force_cancel;
|
|
||||||
void *progress_target;
|
|
||||||
void *debug_target;
|
|
||||||
typedef void (*progress_reporter_t)(float progress, AutomationScript *script, void *target);
|
|
||||||
typedef void (*debug_reporter_t)(wxString &str, bool isdebug, AutomationScript *script, void *target);
|
|
||||||
progress_reporter_t progress_reporter;
|
|
||||||
debug_reporter_t debug_reporter;
|
|
||||||
|
|
||||||
virtual void process_lines(AssFile *input);
|
|
||||||
};
|
|
||||||
|
|
|
@ -1,293 +0,0 @@
|
||||||
// Copyright (c) 2005, Niels Martin Hansen
|
|
||||||
// All rights reserved.
|
|
||||||
//
|
|
||||||
// Redistribution and use in source and binary forms, with or without
|
|
||||||
// modification, are permitted provided that the following conditions are met:
|
|
||||||
//
|
|
||||||
// * Redistributions of source code must retain the above copyright notice,
|
|
||||||
// this list of conditions and the following disclaimer.
|
|
||||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
// this list of conditions and the following disclaimer in the documentation
|
|
||||||
// and/or other materials provided with the distribution.
|
|
||||||
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
||||||
// may be used to endorse or promote products derived from this software
|
|
||||||
// without specific prior written permission.
|
|
||||||
//
|
|
||||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
||||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
// POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
//
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// AEGISUB
|
|
||||||
//
|
|
||||||
// Website: http://aegisub.cellosoft.com
|
|
||||||
// Contact: mailto:zeratul@cellosoft.com
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "automation_filter.h"
|
|
||||||
#include <wx/sizer.h>
|
|
||||||
#include <wx/stattext.h>
|
|
||||||
#include <wx/textctrl.h>
|
|
||||||
#include <wx/spinctrl.h>
|
|
||||||
#include <wx/checkbox.h>
|
|
||||||
#include <wx/choice.h>
|
|
||||||
#include <wx/filename.h>
|
|
||||||
#include "dialog_progress.h"
|
|
||||||
|
|
||||||
|
|
||||||
AutomationScriptThread::AutomationScriptThread(AutomationScript *a_script, AssFile *a_subs)
|
|
||||||
: wxThread(wxTHREAD_JOINABLE), script(a_script), subs(a_subs)
|
|
||||||
{
|
|
||||||
Create();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
wxThread::ExitCode AutomationScriptThread::Entry()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
script->process_lines(subs);
|
|
||||||
}
|
|
||||||
catch (AutomationError &e) {
|
|
||||||
script->OutputDebugString(wxString(_T("Script wrapper: Script produced an exception.")), true);
|
|
||||||
script->OutputDebugString(wxString::Format(_T("Message was: %s"), e.message.c_str()), true);
|
|
||||||
script->OutputDebugString(wxString(_T("Script wrapper: Output data are probably unchanged or corrupted.")), true);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
AutomationFilterConfigDialog::AutomationFilterConfigDialog(wxWindow *parent, AutomationScriptConfiguration &config)
|
|
||||||
: wxPanel(parent, wxID_ANY)
|
|
||||||
{
|
|
||||||
wxFlexGridSizer *sizer = new wxFlexGridSizer(2, 5, 5);
|
|
||||||
|
|
||||||
//wxLogMessage(_T("Now going to create %d controls for automation script"), config.options.size());
|
|
||||||
|
|
||||||
for (std::vector<AutomationScriptConfigurationOption>::iterator opt = config.options.begin(); opt != config.options.end(); opt++) {
|
|
||||||
//wxLogMessage(_T("Creating control for kind: %d"), opt->kind);
|
|
||||||
if (opt->kind == COK_INVALID)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
Control control;
|
|
||||||
control.option = &*opt;
|
|
||||||
|
|
||||||
switch (opt->kind) {
|
|
||||||
case COK_LABEL:
|
|
||||||
control.control = new wxStaticText(this, -1, opt->label);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case COK_TEXT:
|
|
||||||
control.control = new wxTextCtrl(this, -1, opt->value.stringval);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case COK_INT:
|
|
||||||
control.control = new wxSpinCtrl(this, -1);
|
|
||||||
if (opt->min.isset && opt->max.isset) {
|
|
||||||
((wxSpinCtrl*)control.control)->SetRange(opt->min.intval, opt->max.intval);
|
|
||||||
} else if (opt->min.isset) {
|
|
||||||
((wxSpinCtrl*)control.control)->SetRange(opt->min.intval, 0x7fff);
|
|
||||||
} else if (opt->max.isset) {
|
|
||||||
((wxSpinCtrl*)control.control)->SetRange(-0x7fff, opt->max.intval);
|
|
||||||
} else {
|
|
||||||
((wxSpinCtrl*)control.control)->SetRange(-0x7fff, 0x7fff);
|
|
||||||
}
|
|
||||||
((wxSpinCtrl*)control.control)->SetValue(opt->value.intval);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case COK_FLOAT:
|
|
||||||
control.control = new wxTextCtrl(this, -1, wxString::Format(_T("%f"), opt->value.floatval));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case COK_BOOL:
|
|
||||||
control.control = new wxCheckBox(this, -1, opt->label);
|
|
||||||
((wxCheckBox*)control.control)->SetValue(opt->value.boolval);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case COK_COLOUR:
|
|
||||||
// *FIXME* what to do here?
|
|
||||||
// just put a stupid edit box for now
|
|
||||||
control.control = new wxTextCtrl(this, -1, opt->value.colourval.GetASSFormatted(false));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case COK_STYLE:
|
|
||||||
control.control = new wxChoice(this, -1, wxDefaultPosition, wxDefaultSize, AssFile::top->GetStyles());
|
|
||||||
((wxChoice*)control.control)->Insert(_T(""), 0);
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (opt->kind != COK_LABEL && opt->kind != COK_BOOL) {
|
|
||||||
control.label = new wxStaticText(this, -1, opt->label);
|
|
||||||
sizer->Add(control.label, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL);
|
|
||||||
} else {
|
|
||||||
control.label = 0;
|
|
||||||
sizer->AddSpacer(0);
|
|
||||||
}
|
|
||||||
control.control->SetToolTip(opt->hint);
|
|
||||||
sizer->Add(control.control, 1, wxEXPAND);
|
|
||||||
|
|
||||||
controls.push_back(control);
|
|
||||||
}
|
|
||||||
|
|
||||||
SetSizerAndFit(sizer);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
AssAutomationFilter::AssAutomationFilter(AutomationScript *a_script)
|
|
||||||
: script(a_script), dialog(0)
|
|
||||||
{
|
|
||||||
Register(wxString::Format(_T("Automation: %s"), script->name.c_str()), 2000);
|
|
||||||
if (script->description.IsEmpty()) {
|
|
||||||
description = wxString::Format(_T("%s\r\n(This Automation script has not provided a description.)"), script->name.c_str());
|
|
||||||
} else {
|
|
||||||
description = script->description;
|
|
||||||
}
|
|
||||||
automation_filter_list.push_back(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AssAutomationFilter::Init() {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
AssAutomationFilter::~AssAutomationFilter()
|
|
||||||
{
|
|
||||||
Unregister();
|
|
||||||
automation_filter_list.remove(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void progress_reporter(float progress, AutomationScript *script, void *dialog)
|
|
||||||
{
|
|
||||||
((DialogProgress*)dialog)->SetProgress((int)(progress*10), 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void debug_reporter(wxString &str, bool isdebug, AutomationScript *script, void *dialog)
|
|
||||||
{
|
|
||||||
((DialogProgress*)dialog)->SetText(str);
|
|
||||||
if (isdebug) {
|
|
||||||
wxLogMessage(str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AssAutomationFilter::ProcessSubs(AssFile *subs)
|
|
||||||
{
|
|
||||||
AutomationScriptThread thread(script, subs);
|
|
||||||
|
|
||||||
// prepare a progress dialog
|
|
||||||
DialogProgress *dialog = new DialogProgress(0, script->name, &script->force_cancel, _T(""), 0, 1000);
|
|
||||||
dialog->Show();
|
|
||||||
|
|
||||||
// make the script aware of it
|
|
||||||
script->progress_reporter = progress_reporter;
|
|
||||||
script->progress_target = dialog;
|
|
||||||
script->debug_reporter = debug_reporter;
|
|
||||||
script->debug_target = dialog;
|
|
||||||
|
|
||||||
// run the script
|
|
||||||
thread.Run();
|
|
||||||
thread.Wait();
|
|
||||||
|
|
||||||
// make sure the dialog won't be touched again
|
|
||||||
script->progress_reporter = 0;
|
|
||||||
script->debug_reporter = 0;
|
|
||||||
delete dialog;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AssAutomationFilter::LoadSettings(bool IsDefault)
|
|
||||||
{
|
|
||||||
wxString opthname = wxString::Format(_T("Automation Settings %s"), wxFileName(script->filename).GetFullName().c_str());
|
|
||||||
|
|
||||||
// if it's an auto export, just read the serialized settings from the ass file
|
|
||||||
// (does nothing if no settings are serialized)
|
|
||||||
if (IsDefault) {
|
|
||||||
wxString serialized = AssFile::top->GetScriptInfo(opthname);
|
|
||||||
script->configuration.unserialize(serialized);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if there's no dialog, we can't do anything
|
|
||||||
if (!dialog) return;
|
|
||||||
|
|
||||||
for (std::vector<AutomationFilterConfigDialog::Control>::iterator ctl = dialog->controls.begin(); ctl != dialog->controls.end(); ctl++) {
|
|
||||||
switch (ctl->option->kind) {
|
|
||||||
case COK_TEXT:
|
|
||||||
ctl->option->value.stringval = ((wxTextCtrl*)ctl->control)->GetValue();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case COK_INT:
|
|
||||||
ctl->option->value.intval = ((wxSpinCtrl*)ctl->control)->GetValue();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case COK_FLOAT:
|
|
||||||
if (!((wxTextCtrl*)ctl->control)->GetValue().ToDouble(&ctl->option->value.floatval)) {
|
|
||||||
wxLogWarning(
|
|
||||||
_T("The value entered for field '%s' (%s) could not be converted to a floating-point number. Default value (%f) substituted for the entered value."),
|
|
||||||
ctl->option->label.c_str(),
|
|
||||||
((wxTextCtrl*)ctl->control)->GetValue().c_str(),
|
|
||||||
ctl->option->default_val.floatval);
|
|
||||||
ctl->option->value.floatval = ctl->option->default_val.floatval;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case COK_BOOL:
|
|
||||||
ctl->option->value.boolval = ((wxCheckBox*)ctl->control)->GetValue();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case COK_COLOUR:
|
|
||||||
// *FIXME* needs to be updated to use a proper color control
|
|
||||||
ctl->option->value.colourval.ParseASS(((wxTextCtrl*)ctl->control)->GetValue());
|
|
||||||
break;
|
|
||||||
|
|
||||||
case COK_STYLE:
|
|
||||||
ctl->option->value.stringval = ((wxChoice*)ctl->control)->GetStringSelection();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// serialize the new settings and save them to the file
|
|
||||||
AssFile::top->SetScriptInfo(opthname, script->configuration.serialize());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
wxWindow *AssAutomationFilter::GetConfigDialogWindow(wxWindow *parent)
|
|
||||||
{
|
|
||||||
wxString opthname = wxString::Format(_T("Automation Settings %s"), wxFileName(script->filename).GetFullName().c_str());
|
|
||||||
wxString serialized = AssFile::top->GetScriptInfo(opthname);
|
|
||||||
script->configuration.unserialize(serialized);
|
|
||||||
|
|
||||||
if (script->configuration.present)
|
|
||||||
return dialog = new AutomationFilterConfigDialog(parent, script->configuration);
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
AutomationScript *AssAutomationFilter::GetScript()
|
|
||||||
{
|
|
||||||
return script;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const std::list<AssAutomationFilter*>& AssAutomationFilter::GetFilterList()
|
|
||||||
{
|
|
||||||
return AssAutomationFilter::automation_filter_list;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// static list of loaded automation filters
|
|
||||||
std::list<AssAutomationFilter*> AssAutomationFilter::automation_filter_list;
|
|
||||||
|
|
|
@ -1,85 +0,0 @@
|
||||||
// Copyright (c) 2005, Niels Martin Hansen
|
|
||||||
// All rights reserved.
|
|
||||||
//
|
|
||||||
// Redistribution and use in source and binary forms, with or without
|
|
||||||
// modification, are permitted provided that the following conditions are met:
|
|
||||||
//
|
|
||||||
// * Redistributions of source code must retain the above copyright notice,
|
|
||||||
// this list of conditions and the following disclaimer.
|
|
||||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
// this list of conditions and the following disclaimer in the documentation
|
|
||||||
// and/or other materials provided with the distribution.
|
|
||||||
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
||||||
// may be used to endorse or promote products derived from this software
|
|
||||||
// without specific prior written permission.
|
|
||||||
//
|
|
||||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
||||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
// POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
//
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// AEGISUB
|
|
||||||
//
|
|
||||||
// Website: http://aegisub.cellosoft.com
|
|
||||||
// Contact: mailto:zeratul@cellosoft.com
|
|
||||||
//
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "automation.h"
|
|
||||||
#include "ass_export_filter.h"
|
|
||||||
|
|
||||||
|
|
||||||
class AutomationScriptThread : public wxThread {
|
|
||||||
protected:
|
|
||||||
AutomationScript *script;
|
|
||||||
AssFile *subs;
|
|
||||||
public:
|
|
||||||
AutomationScriptThread(AutomationScript *a_script, AssFile *a_subs);
|
|
||||||
wxThread::ExitCode Entry();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class AutomationFilterConfigDialog : public wxPanel {
|
|
||||||
public:
|
|
||||||
struct Control {
|
|
||||||
wxStaticText *label;
|
|
||||||
wxControl *control;
|
|
||||||
AutomationScriptConfigurationOption *option;
|
|
||||||
Control() : label(0), control(0), option(0) {}
|
|
||||||
};
|
|
||||||
std::vector<Control> controls;
|
|
||||||
|
|
||||||
AutomationFilterConfigDialog(wxWindow *parent, AutomationScriptConfiguration &config);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class AssAutomationFilter : public AssExportFilter {
|
|
||||||
private:
|
|
||||||
AutomationScript *script;
|
|
||||||
AutomationFilterConfigDialog *dialog;
|
|
||||||
|
|
||||||
static std::list<AssAutomationFilter*> automation_filter_list;
|
|
||||||
void Init();
|
|
||||||
|
|
||||||
public:
|
|
||||||
AssAutomationFilter(AutomationScript *a_script);
|
|
||||||
~AssAutomationFilter();
|
|
||||||
|
|
||||||
void ProcessSubs(AssFile *subs);
|
|
||||||
wxWindow *GetConfigDialogWindow(wxWindow *parent);
|
|
||||||
void LoadSettings(bool IsDefault);
|
|
||||||
|
|
||||||
AutomationScript *GetScript();
|
|
||||||
|
|
||||||
static const std::list<AssAutomationFilter*>& GetFilterList();
|
|
||||||
};
|
|
|
@ -1,394 +0,0 @@
|
||||||
// Copyright (c) 2005, Niels Martin Hansen
|
|
||||||
// All rights reserved.
|
|
||||||
//
|
|
||||||
// Redistribution and use in source and binary forms, with or without
|
|
||||||
// modification, are permitted provided that the following conditions are met:
|
|
||||||
//
|
|
||||||
// * Redistributions of source code must retain the above copyright notice,
|
|
||||||
// this list of conditions and the following disclaimer.
|
|
||||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
// this list of conditions and the following disclaimer in the documentation
|
|
||||||
// and/or other materials provided with the distribution.
|
|
||||||
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
||||||
// may be used to endorse or promote products derived from this software
|
|
||||||
// without specific prior written permission.
|
|
||||||
//
|
|
||||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
||||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
// POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
//
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// AEGISUB
|
|
||||||
//
|
|
||||||
// Website: http://aegisub.cellosoft.com
|
|
||||||
// Contact: mailto:zeratul@cellosoft.com
|
|
||||||
//
|
|
||||||
|
|
||||||
#include <wx/filename.h>
|
|
||||||
#include <wx/filedlg.h>
|
|
||||||
#include <wx/msgdlg.h>
|
|
||||||
#include <wx/textfile.h>
|
|
||||||
#include <wx/utils.h>
|
|
||||||
#include "automation_gui.h"
|
|
||||||
#include "options.h"
|
|
||||||
|
|
||||||
|
|
||||||
DialogAutomationManager::DialogAutomationManager(wxWindow *parent, SubtitlesGrid *grid)
|
|
||||||
: wxDialog(parent, -1, _("Automation Manager"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, _T("AutoMan"))
|
|
||||||
{
|
|
||||||
subgrid = grid;
|
|
||||||
|
|
||||||
// create main controls
|
|
||||||
script_list = new wxListView(this, AUTOMAN_SCRIPTLIST, wxDefaultPosition, wxSize(600, 175), wxLC_REPORT|wxLC_SINGLE_SEL);
|
|
||||||
create_button = new wxButton(this, AUTOMAN_CREATE, _("&Create..."));
|
|
||||||
add_button = new wxButton(this, AUTOMAN_ADD, _("&Add..."));
|
|
||||||
remove_button = new wxButton(this, AUTOMAN_REMOVE, _("&Remove"));
|
|
||||||
test_button = new wxButton(this, AUTOMAN_APPLY, _("&Apply now"));
|
|
||||||
edit_button = new wxButton(this, AUTOMAN_EDIT, _("&Edit..."));
|
|
||||||
reload_button = new wxButton(this, AUTOMAN_RELOAD, _("Rel&oad"));
|
|
||||||
close_button = new wxButton(this, wxID_CLOSE, _("C&lose"));
|
|
||||||
|
|
||||||
// add headers to list view
|
|
||||||
script_list->InsertColumn(0, _("Script name"), wxLIST_FORMAT_LEFT, 140);
|
|
||||||
script_list->InsertColumn(1, _("File"), wxLIST_FORMAT_LEFT, 100);
|
|
||||||
//script_list->InsertColumn(2, _("Flags"), wxLIST_FORMAT_LEFT, 45);
|
|
||||||
script_list->InsertColumn(2, _("Description"), wxLIST_FORMAT_LEFT, 350);
|
|
||||||
|
|
||||||
// button layout
|
|
||||||
wxSizer *button_box = new wxBoxSizer(wxHORIZONTAL);
|
|
||||||
button_box->AddStretchSpacer(2);
|
|
||||||
button_box->Add(create_button, 0);
|
|
||||||
button_box->Add(add_button, 0);
|
|
||||||
button_box->Add(remove_button, 0);
|
|
||||||
button_box->AddSpacer(10);
|
|
||||||
button_box->Add(test_button, 0);
|
|
||||||
button_box->AddSpacer(10);
|
|
||||||
button_box->Add(edit_button, 0);
|
|
||||||
button_box->Add(reload_button, 0);
|
|
||||||
button_box->AddSpacer(10);
|
|
||||||
button_box->Add(close_button, 0);
|
|
||||||
button_box->AddStretchSpacer(2);
|
|
||||||
|
|
||||||
// main layout
|
|
||||||
wxSizer *main_box = new wxBoxSizer(wxVERTICAL);
|
|
||||||
main_box->Add(script_list, 1, wxEXPAND|wxALL, 5);
|
|
||||||
main_box->Add(button_box, 0, wxEXPAND|wxALL&~wxTOP, 5);
|
|
||||||
main_box->SetSizeHints(this);
|
|
||||||
SetSizer(main_box);
|
|
||||||
Center();
|
|
||||||
|
|
||||||
// fill the list view
|
|
||||||
std::list<AssAutomationFilter*>::const_iterator f = AssAutomationFilter::GetFilterList().begin();
|
|
||||||
for (;f != AssAutomationFilter::GetFilterList().end(); ++f) {
|
|
||||||
AddScriptToList(*f);
|
|
||||||
}
|
|
||||||
|
|
||||||
UpdateDisplay();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DialogAutomationManager::~DialogAutomationManager()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(DialogAutomationManager,wxDialog)
|
|
||||||
EVT_BUTTON(AUTOMAN_CREATE,DialogAutomationManager::OnCreate)
|
|
||||||
EVT_BUTTON(AUTOMAN_ADD,DialogAutomationManager::OnAdd)
|
|
||||||
EVT_BUTTON(AUTOMAN_REMOVE,DialogAutomationManager::OnRemove)
|
|
||||||
EVT_BUTTON(AUTOMAN_APPLY,DialogAutomationManager::OnApply)
|
|
||||||
EVT_BUTTON(AUTOMAN_EDIT,DialogAutomationManager::OnEdit)
|
|
||||||
EVT_BUTTON(AUTOMAN_RELOAD,DialogAutomationManager::OnReload)
|
|
||||||
EVT_BUTTON(wxID_CLOSE,DialogAutomationManager::OnClose)
|
|
||||||
EVT_LIST_ITEM_SELECTED(AUTOMAN_SCRIPTLIST,DialogAutomationManager::OnSelectionChange)
|
|
||||||
EVT_LIST_ITEM_DESELECTED(AUTOMAN_SCRIPTLIST,DialogAutomationManager::OnSelectionChange)
|
|
||||||
END_EVENT_TABLE()
|
|
||||||
|
|
||||||
|
|
||||||
void DialogAutomationManager::OnCreate(wxCommandEvent &event)
|
|
||||||
{
|
|
||||||
wxString path = Options.AsText(_T("Last open automation path"));
|
|
||||||
wxString sfnames = wxFileSelector(_("Create Automation script"), path, _T("*.lua"), _T("lua"), _T("Automation Lua scripts (*.lua)|*.lua|All files (*.*)|*.*"), wxSAVE|wxOVERWRITE_PROMPT, this);
|
|
||||||
if (sfnames.empty()) return;
|
|
||||||
Options.SetText(_T("Last open automation path"), sfnames);
|
|
||||||
|
|
||||||
wxFileName sfname(sfnames);
|
|
||||||
|
|
||||||
if (sfname.FileExists()) {
|
|
||||||
if (!wxRemoveFile(sfnames)) {
|
|
||||||
wxMessageBox(_T("The old file by this name could not be deleted."), _T("Error creating Automation script"), wxOK|wxICON_ERROR, this);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
wxTextFile file;
|
|
||||||
file.Create(sfnames);
|
|
||||||
file.AddLine(_T("-- Aegisub Automation script"));
|
|
||||||
file.AddLine(_T(""));
|
|
||||||
file.AddLine(_T("-- You should change these two lines"));
|
|
||||||
file.AddLine(wxString::Format(_T("name = \"%s\""), sfname.GetName().c_str()));
|
|
||||||
file.AddLine(_T("description = \"New Automation script\""));
|
|
||||||
file.AddLine(_T(""));
|
|
||||||
file.AddLine(_T("-- Enter the configuration settings here, if needed. Refer to the manual for details"));
|
|
||||||
file.AddLine(_T("configuration = {}"));
|
|
||||||
file.AddLine(_T(""));
|
|
||||||
file.AddLine(_T("-- You should NOT change this line!"));
|
|
||||||
file.AddLine(_T("version, kind = 3, 'basic_ass'"));
|
|
||||||
file.AddLine(_T(""));
|
|
||||||
file.AddLine(_T("-- You should write your script in this function (don't change its name!)"));
|
|
||||||
file.AddLine(_T("function process_lines(meta, styles, lines, config)"));
|
|
||||||
file.AddLine(_T("\t-- For now, just return the subtitles as-is, no changes"));
|
|
||||||
file.AddLine(_T("\treturn lines"));
|
|
||||||
file.AddLine(_T("end"));
|
|
||||||
file.AddLine(_T(""));
|
|
||||||
file.Write(wxTextFileType_None, wxConvUTF8);
|
|
||||||
file.Close();
|
|
||||||
|
|
||||||
AutomationScriptFile *sfile = AutomationScriptFile::CreateFromFile(sfnames);
|
|
||||||
AutomationScript *script = new AutomationScript(sfile);
|
|
||||||
AssAutomationFilter *filter = new AssAutomationFilter(script);
|
|
||||||
AddScriptToList(filter);
|
|
||||||
delete sfile;
|
|
||||||
|
|
||||||
EditScript(script);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DialogAutomationManager::OnAdd(wxCommandEvent &event)
|
|
||||||
{
|
|
||||||
wxString path = Options.AsText(_T("Last open automation path"));
|
|
||||||
wxString sfnames = wxFileSelector(_("Load Automation script"), path, _T("*.lua"), _T("lua"), _T("Automation Lua scripts (*.lua)|*.lua|All files (*.*)|*.*"), wxOPEN|wxFILE_MUST_EXIST, this);
|
|
||||||
if (sfnames.empty()) return;
|
|
||||||
Options.SetText(_T("Last open automation path"), sfnames);
|
|
||||||
|
|
||||||
try {
|
|
||||||
AutomationScriptFile *sfile = AutomationScriptFile::CreateFromFile(sfnames);
|
|
||||||
AutomationScript *script = new AutomationScript(sfile);
|
|
||||||
AssAutomationFilter *filter = new AssAutomationFilter(script);
|
|
||||||
wxString script_settings = subgrid->ass->GetScriptInfo(wxString::Format(_T("Automation Settings %s"), wxFileName(sfnames).GetFullName().c_str()));
|
|
||||||
script->configuration.unserialize(script_settings);
|
|
||||||
AddScriptToList(filter);
|
|
||||||
delete sfile;
|
|
||||||
}
|
|
||||||
catch (AutomationError &err) {
|
|
||||||
wxMessageBox(wxString::Format(_T("Error loading Automation script '%s':\r\n\r\n%s"), sfnames.c_str(), err.message.c_str()), _T("Error loading Automation script"), wxOK | wxICON_ERROR, this);
|
|
||||||
}
|
|
||||||
catch (wxString &err) {
|
|
||||||
wxMessageBox(wxString::Format(_T("Error loading Automation script %s:\r\n\r\n%s"), sfnames.c_str(), err.c_str()), _T("Error loading Automation script"), wxOK|wxICON_ERROR, this);
|
|
||||||
}
|
|
||||||
catch (const wchar_t *err) {
|
|
||||||
wxMessageBox(wxString::Format(_T("Error loading Automation script %s:\r\n\r\n%s"), sfnames.c_str(), err), _T("Error loading Automation script"), wxOK|wxICON_ERROR, this);
|
|
||||||
}
|
|
||||||
catch (...) {
|
|
||||||
wxMessageBox(_T("Unknown error loading Automation script."), _T("Error loading Automation script"), wxOK | wxICON_ERROR, this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DialogAutomationManager::OnRemove(wxCommandEvent &event)
|
|
||||||
{
|
|
||||||
// assume only one item can be selected at a time...
|
|
||||||
// removing multiple scripts might be disasterous (for the user) anyway
|
|
||||||
// TODO: ask for confirmation if script supports configuration
|
|
||||||
int selid = script_list->GetFirstSelected();
|
|
||||||
AssAutomationFilter *filter = (AssAutomationFilter*)script_list->GetItemData(selid);
|
|
||||||
script_list->DeleteItem(selid);
|
|
||||||
AutomationScript *script = filter->GetScript();
|
|
||||||
delete filter;
|
|
||||||
delete script;
|
|
||||||
UpdateDisplay();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DialogAutomationManager::OnApply(wxCommandEvent &event)
|
|
||||||
{
|
|
||||||
int selid = script_list->GetFirstSelected();
|
|
||||||
AssAutomationFilter *filter = (AssAutomationFilter*)script_list->GetItemData(selid);
|
|
||||||
// Attempt to make a config window, if needed
|
|
||||||
{
|
|
||||||
wxDialog *dlg = new wxDialog(this, -1, filter->GetScript()->name, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, _T("AutomationScriptConfigDlg"));
|
|
||||||
try {
|
|
||||||
wxWindow *config_frame = filter->GetConfigDialogWindow(dlg);
|
|
||||||
if (!config_frame) {
|
|
||||||
delete dlg;
|
|
||||||
goto skip_config;
|
|
||||||
}
|
|
||||||
wxSizer *main_sizer = new wxBoxSizer(wxVERTICAL);
|
|
||||||
main_sizer->Add(config_frame, 0, wxALL, 7);
|
|
||||||
wxButton *ok = new wxButton(dlg, wxID_OK);
|
|
||||||
wxButton *cancel = new wxButton(dlg, wxID_CANCEL);
|
|
||||||
wxSizer *button_sizer = new wxBoxSizer(wxHORIZONTAL);
|
|
||||||
button_sizer->Add(ok, 0, wxALL, 7);
|
|
||||||
button_sizer->Add(cancel, 0, wxALL&~wxLEFT, 7);
|
|
||||||
main_sizer->Add(button_sizer, wxALIGN_CENTER);
|
|
||||||
dlg->SetSizer(main_sizer);
|
|
||||||
main_sizer->SetSizeHints(dlg);
|
|
||||||
dlg->Layout();
|
|
||||||
switch (dlg->ShowModal()) {
|
|
||||||
case wxID_OK:
|
|
||||||
filter->LoadSettings(false);
|
|
||||||
delete dlg;
|
|
||||||
break;
|
|
||||||
case wxID_CANCEL:
|
|
||||||
delete dlg;
|
|
||||||
return;
|
|
||||||
default:
|
|
||||||
wxLogWarning(_T("Config dialog returned an unexpected value. This shouldn't happen. Please report to a dev."));
|
|
||||||
delete dlg;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (...) {
|
|
||||||
delete dlg;
|
|
||||||
wxLogError(_T("Error while working on Automation script config dialog. This shouldn't happen. Please report to a dev."));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
skip_config:
|
|
||||||
// Now apply script
|
|
||||||
filter->ProcessSubs(subgrid->ass);
|
|
||||||
subgrid->LoadFromAss();
|
|
||||||
script_list->Select(selid, false);
|
|
||||||
UpdateDisplay();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DialogAutomationManager::OnEdit(wxCommandEvent &event)
|
|
||||||
{
|
|
||||||
int selid = script_list->GetFirstSelected();
|
|
||||||
AssAutomationFilter *filter = (AssAutomationFilter*)script_list->GetItemData(selid);
|
|
||||||
AutomationScript *script = filter->GetScript();
|
|
||||||
EditScript(script);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DialogAutomationManager::OnReload(wxCommandEvent &event)
|
|
||||||
{
|
|
||||||
int selid = script_list->GetFirstSelected();
|
|
||||||
AssAutomationFilter *filter = (AssAutomationFilter*)script_list->GetItemData(selid);
|
|
||||||
AutomationScript *script = filter->GetScript();
|
|
||||||
wxFileName sfname(script->filename);
|
|
||||||
if (sfname.FileExists()) {
|
|
||||||
AutomationScript *newscript;
|
|
||||||
try {
|
|
||||||
AutomationScriptFile *sfile = AutomationScriptFile::CreateFromFile(sfname.GetFullPath());
|
|
||||||
newscript = new AutomationScript(sfile);
|
|
||||||
delete sfile;
|
|
||||||
}
|
|
||||||
catch (AutomationError &err) {
|
|
||||||
wxMessageBox(wxString::Format(_T("Error reloading Automation script '%s'.\r\nThe old version has been retained.\r\n\r\n%s"), sfname.GetFullPath().c_str(), err.message.c_str()), _T("Error reloading Automation script"), wxOK | wxICON_ERROR, this);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
newscript->configuration = script->configuration;
|
|
||||||
delete filter;
|
|
||||||
delete script;
|
|
||||||
AssAutomationFilter *newfilter = new AssAutomationFilter(newscript);
|
|
||||||
script_list->DeleteItem(selid);
|
|
||||||
AddScriptToList(newfilter);
|
|
||||||
script_list->Select(0);
|
|
||||||
} else {
|
|
||||||
wxMessageBox(_T("The script file could not be found on disk. If you want to remove the script, please use the Remove button."), _T("Error reloading Automation script"), wxOK|wxICON_EXCLAMATION, this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DialogAutomationManager::OnClose(wxCommandEvent &event)
|
|
||||||
{
|
|
||||||
EndModal(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DialogAutomationManager::OnSelectionChange(wxListEvent &event)
|
|
||||||
{
|
|
||||||
UpdateDisplay();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DialogAutomationManager::UpdateDisplay()
|
|
||||||
{
|
|
||||||
bool script_selected = script_list->GetSelectedItemCount() > 0;
|
|
||||||
// enable/disable buttons
|
|
||||||
create_button->Enable(true);
|
|
||||||
add_button->Enable(true);
|
|
||||||
remove_button->Enable(script_selected);
|
|
||||||
test_button->Enable(script_selected);
|
|
||||||
edit_button->Enable(script_selected);
|
|
||||||
reload_button->Enable(script_selected);
|
|
||||||
close_button->Enable(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DialogAutomationManager::AddScriptToList(AssAutomationFilter *filter)
|
|
||||||
{
|
|
||||||
wxFileName fn(filter->GetScript()->filename);
|
|
||||||
wxListItem item;
|
|
||||||
item.SetText(filter->GetScript()->name);
|
|
||||||
item.SetData(filter);
|
|
||||||
int i = script_list->InsertItem(item);
|
|
||||||
script_list->SetItem(i, 1, fn.GetFullName());
|
|
||||||
//script_list->SetItem(i, 2, _T("")); // Flags - unused
|
|
||||||
script_list->SetItem(i, 2, filter->GetScript()->description);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DialogAutomationManager::EditScript(AutomationScript *script)
|
|
||||||
{
|
|
||||||
if (!script) {
|
|
||||||
wxMessageBox(_T("DialogAutomationManager::EditScript() called without a valid script object. Sloppy programming? You can probably blame jfs."), _T("Blame Canada!"), wxOK|wxICON_ERROR);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxFileName sfname(script->filename);
|
|
||||||
if (!sfname.FileExists()) {
|
|
||||||
wxMessageBox(_T("The script file \"%s\" does not exist, and thus cannot be edited."), _T("Automation warning"), wxOK|wxICON_WARNING);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxString editor;
|
|
||||||
if (!Options.IsDefined(_T("automation script editor")) || wxGetKeyState(WXK_SHIFT)) {
|
|
||||||
wxMessageBox(_T("You have not selected a script editor yet. Please select your script editor in the next window. It's recommended to use an editor with syntax highlighting for Lua scripts."), _T("Aegisub"), wxOK|wxICON_INFORMATION);
|
|
||||||
#if defined(__WINDOWS__)
|
|
||||||
editor = wxFileSelector(_T("Select script editor"), _T(""), _T("C:\\Windows\\Notepad.exe"), _T("exe"), _T("Execatuables (*.exe)|*.exe|All files (*.*)|*.*"), wxOPEN|wxFILE_MUST_EXIST);
|
|
||||||
#elif defined(__APPLE__)
|
|
||||||
editor = wxFileSelector(_T("Select script editor"), _T(""), _T("/Applications/TextEdit.app"), _T("app"), _T("Applications (*.app)|*.app|All files (*.*)|*.*"), wxOPEN|wxFILE_MUST_EXIST);
|
|
||||||
#else
|
|
||||||
char *env_editor = getenv("EDITOR");
|
|
||||||
wxString editor(env_editor ? env_editor : "/usr/bin/gvim", wxConvLocal);
|
|
||||||
editor = wxFileSelector(_T("Select script editor"), _T(""), editor, _T(""), _T("All files (*)|*"), wxOPEN|wxFILE_MUST_EXIST);
|
|
||||||
#endif
|
|
||||||
if (editor.empty()) return;
|
|
||||||
Options.SetText(_T("automation script editor"), editor);
|
|
||||||
Options.Save();
|
|
||||||
} else {
|
|
||||||
editor = Options.AsText(_T("automation script editor"));
|
|
||||||
}
|
|
||||||
|
|
||||||
wxWCharBuffer editorbuf = editor.c_str(), sfnamebuf = sfname.GetFullPath().c_str();
|
|
||||||
wchar_t **cmdline = new wchar_t*[5];
|
|
||||||
#ifndef __APPLE__
|
|
||||||
cmdline[0] = editorbuf.data();
|
|
||||||
cmdline[1] = sfnamebuf.data();
|
|
||||||
cmdline[2] = 0;
|
|
||||||
#else
|
|
||||||
cmdline[0] = _T("/usr/bin/open");
|
|
||||||
cmdline[1] = _T("-a");
|
|
||||||
cmdline[2] = editorbuf.data();
|
|
||||||
cmdline[3] = sfnamebuf.data();
|
|
||||||
cmdline[4] = 0;
|
|
||||||
#endif
|
|
||||||
long res = wxExecute(cmdline);
|
|
||||||
delete cmdline;
|
|
||||||
|
|
||||||
if (!res) {
|
|
||||||
wxMessageBox(_T("Some error occurred trying to launch the external editor. Sorry!"), _T("Automation Error"), wxOK|wxICON_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,87 +0,0 @@
|
||||||
// Copyright (c) 2005, Niels Martin Hansen
|
|
||||||
// All rights reserved.
|
|
||||||
//
|
|
||||||
// Redistribution and use in source and binary forms, with or without
|
|
||||||
// modification, are permitted provided that the following conditions are met:
|
|
||||||
//
|
|
||||||
// * Redistributions of source code must retain the above copyright notice,
|
|
||||||
// this list of conditions and the following disclaimer.
|
|
||||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
// this list of conditions and the following disclaimer in the documentation
|
|
||||||
// and/or other materials provided with the distribution.
|
|
||||||
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
||||||
// may be used to endorse or promote products derived from this software
|
|
||||||
// without specific prior written permission.
|
|
||||||
//
|
|
||||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
||||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
// POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
//
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// AEGISUB
|
|
||||||
//
|
|
||||||
// Website: http://aegisub.cellosoft.com
|
|
||||||
// Contact: mailto:zeratul@cellosoft.com
|
|
||||||
//
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <wx/window.h>
|
|
||||||
#include <wx/listctrl.h>
|
|
||||||
#include "subs_grid.h"
|
|
||||||
#include "automation_filter.h"
|
|
||||||
|
|
||||||
|
|
||||||
class DialogAutomationManager : public wxDialog {
|
|
||||||
private:
|
|
||||||
wxListView *script_list;
|
|
||||||
wxButton *create_button;
|
|
||||||
wxButton *add_button;
|
|
||||||
wxButton *remove_button;
|
|
||||||
wxButton *test_button;
|
|
||||||
wxButton *edit_button;
|
|
||||||
wxButton *reload_button;
|
|
||||||
wxButton *close_button;
|
|
||||||
|
|
||||||
SubtitlesGrid *subgrid;
|
|
||||||
|
|
||||||
void OnCreate(wxCommandEvent &event);
|
|
||||||
void OnAdd(wxCommandEvent &event);
|
|
||||||
void OnRemove(wxCommandEvent &event);
|
|
||||||
void OnApply(wxCommandEvent &event);
|
|
||||||
void OnEdit(wxCommandEvent &event);
|
|
||||||
void OnReload(wxCommandEvent &event);
|
|
||||||
void OnClose(wxCommandEvent &event);
|
|
||||||
void OnSelectionChange(wxListEvent &event);
|
|
||||||
|
|
||||||
void UpdateDisplay();
|
|
||||||
void AddScriptToList(AssAutomationFilter *filter);
|
|
||||||
|
|
||||||
public:
|
|
||||||
DialogAutomationManager(wxWindow *parent, SubtitlesGrid *grid);
|
|
||||||
~DialogAutomationManager();
|
|
||||||
|
|
||||||
static void EditScript(AutomationScript *script);
|
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
|
||||||
};
|
|
||||||
|
|
||||||
enum {
|
|
||||||
AUTOMAN_SCRIPTLIST = 3200,
|
|
||||||
AUTOMAN_CREATE,
|
|
||||||
AUTOMAN_ADD,
|
|
||||||
AUTOMAN_REMOVE,
|
|
||||||
AUTOMAN_APPLY,
|
|
||||||
AUTOMAN_EDIT,
|
|
||||||
AUTOMAN_RELOAD,
|
|
||||||
AUTOMAN_CLOSE
|
|
||||||
};
|
|
|
@ -863,6 +863,7 @@ void SubtitlesGrid::InsertLine(AssDialogue *line,int n,bool after,bool update) {
|
||||||
if (update) {
|
if (update) {
|
||||||
ass->FlagAsModified(_("line insertion"));
|
ass->FlagAsModified(_("line insertion"));
|
||||||
CommitChanges();
|
CommitChanges();
|
||||||
|
AdjustScrollbar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue