Remove "Config" from the name of ScriptConfigDialog and friends as they're used for more than just config, and clean up the implementations.

Originally committed to SVN as r5645.
This commit is contained in:
Thomas Goyne 2011-09-28 19:49:27 +00:00
parent 59d11f4cc4
commit a9dc1f045d
6 changed files with 326 additions and 920 deletions

View File

@ -62,26 +62,19 @@
#include "ass_file.h" #include "ass_file.h"
#include "ass_style.h" #include "ass_style.h"
#include "command/command.h"
#include "compat.h" #include "compat.h"
#include "dialog_progress.h" #include "dialog_progress.h"
#include "include/aegisub/context.h" #include "include/aegisub/context.h"
#include "main.h" #include "main.h"
#include "standard_paths.h" #include "standard_paths.h"
#include "string_codec.h" #include "string_codec.h"
#include "subtitle_format.h"
#include "utils.h" #include "utils.h"
/// DOCME /// DOCME
namespace Automation4 { namespace Automation4 {
/// @brief DOCME bool CalculateTextExtents(AssStyle *style, wxString const& text, double &width, double &height, double &descent, double &extlead)
/// @param style
/// @param text
/// @param width
/// @param height
/// @param descent
/// @param extlead
/// @return
///
bool CalculateTextExtents(AssStyle *style, wxString &text, double &width, double &height, double &descent, double &extlead)
{ {
width = height = descent = extlead = 0; width = height = descent = extlead = 0;
@ -219,7 +212,7 @@ namespace Automation4 {
wxString val = c->ass->GetScriptInfo(GetScriptSettingsIdentifier()); wxString val = c->ass->GetScriptInfo(GetScriptSettingsIdentifier());
if (!val.empty()) if (!val.empty())
config_dialog->Unserialise(val); config_dialog->Unserialise(val);
return config_dialog->GetWindow(parent); return config_dialog->CreateWindow(parent);
} }
return 0; return 0;
@ -235,40 +228,8 @@ namespace Automation4 {
} }
} }
// ScriptConfigDialog
/// @brief DOCME
/// @param parent
/// @return
///
wxWindow* ScriptConfigDialog::GetWindow(wxWindow *parent)
{
if (win) return win;
return win = CreateWindow(parent);
}
/// @brief DOCME
///
void ScriptConfigDialog::DeleteWindow()
{
if (win) delete win;
win = 0;
}
/// @brief DOCME
/// @return
///
wxString ScriptConfigDialog::Serialise()
{
return "";
}
// ProgressSink // ProgressSink
wxDEFINE_EVENT(EVT_SHOW_CONFIG_DIALOG, wxThreadEvent); wxDEFINE_EVENT(EVT_SHOW_DIALOG, wxThreadEvent);
ProgressSink::ProgressSink(agi::ProgressSink *impl, BackgroundScriptRunner *bsr) ProgressSink::ProgressSink(agi::ProgressSink *impl, BackgroundScriptRunner *bsr)
: impl(impl) : impl(impl)
@ -277,10 +238,10 @@ namespace Automation4 {
{ {
} }
void ProgressSink::ShowConfigDialog(ScriptConfigDialog *config_dialog) void ProgressSink::ShowDialog(ScriptDialog *config_dialog)
{ {
wxSemaphore sema(0, 1); wxSemaphore sema(0, 1);
wxThreadEvent *evt = new wxThreadEvent(EVT_SHOW_CONFIG_DIALOG); wxThreadEvent *evt = new wxThreadEvent(EVT_SHOW_DIALOG);
evt->SetPayload(std::make_pair(config_dialog, &sema)); evt->SetPayload(std::make_pair(config_dialog, &sema));
bsr->QueueEvent(evt); bsr->QueueEvent(evt);
sema.Wait(); sema.Wait();
@ -289,27 +250,27 @@ namespace Automation4 {
BackgroundScriptRunner::BackgroundScriptRunner(wxWindow *parent, wxString const& title) BackgroundScriptRunner::BackgroundScriptRunner(wxWindow *parent, wxString const& title)
: impl(new DialogProgress(parent, title)) : impl(new DialogProgress(parent, title))
{ {
impl->Bind(EVT_SHOW_CONFIG_DIALOG, &BackgroundScriptRunner::OnConfigDialog, this); impl->Bind(EVT_SHOW_DIALOG, &BackgroundScriptRunner::OnDialog, this);
} }
BackgroundScriptRunner::~BackgroundScriptRunner() BackgroundScriptRunner::~BackgroundScriptRunner()
{ {
} }
void BackgroundScriptRunner::OnConfigDialog(wxThreadEvent &evt) void BackgroundScriptRunner::OnDialog(wxThreadEvent &evt)
{ {
std::pair<ScriptConfigDialog*, wxSemaphore*> payload = evt.GetPayload<std::pair<ScriptConfigDialog*, wxSemaphore*> >(); std::pair<ScriptDialog*, wxSemaphore*> payload = evt.GetPayload<std::pair<ScriptDialog*, wxSemaphore*> >();
wxDialog w(impl.get(), -1, impl->GetTitle()); // container dialog box wxDialog w(impl.get(), -1, impl->GetTitle()); // container dialog box
wxBoxSizer *s = new wxBoxSizer(wxHORIZONTAL); // sizer for putting contents in wxBoxSizer *s = new wxBoxSizer(wxHORIZONTAL); // sizer for putting contents in
wxWindow *ww = payload.first->GetWindow(&w); // get/generate actual dialog contents wxWindow *ww = payload.first->CreateWindow(&w); // generate actual dialog contents
s->Add(ww, 0, wxALL, 5); // add contents to dialog s->Add(ww, 0, wxALL, 5); // add contents to dialog
w.SetSizerAndFit(s); w.SetSizerAndFit(s);
w.CenterOnParent(); w.CenterOnParent();
w.ShowModal(); w.ShowModal();
payload.first->ReadBack(); payload.first->ReadBack();
payload.first->DeleteWindow();
// Tell the calling thread it can wake up now
payload.second->Post(); payload.second->Post();
} }

View File

@ -39,6 +39,7 @@
#ifndef AGI_PRE #ifndef AGI_PRE
#include <list>
#include <vector> #include <vector>
#include <wx/dialog.h> #include <wx/dialog.h>
@ -80,15 +81,15 @@ namespace Automation4 {
DEFINE_SIMPLE_EXCEPTION_NOINNER(MacroRunError, AutomationError, "automation/macro/generic") DEFINE_SIMPLE_EXCEPTION_NOINNER(MacroRunError, AutomationError, "automation/macro/generic")
// Calculate the extents of a text string given a style // Calculate the extents of a text string given a style
bool CalculateTextExtents(AssStyle *style, wxString &text, double &width, double &height, double &descent, double &extlead); bool CalculateTextExtents(AssStyle *style, wxString const& text, double &width, double &height, double &descent, double &extlead);
class ScriptConfigDialog; class ScriptDialog;
class ExportFilter : public AssExportFilter { class ExportFilter : public AssExportFilter {
ScriptConfigDialog *config_dialog; ScriptDialog *config_dialog;
/// subclasses should implement this, producing a new ScriptConfigDialog /// subclasses should implement this, producing a new ScriptDialog
virtual ScriptConfigDialog* GenerateConfigDialog(wxWindow *parent, agi::Context *c) = 0; virtual ScriptDialog* GenerateConfigDialog(wxWindow *parent, agi::Context *c) = 0;
protected: protected:
wxString GetScriptSettingsIdentifier(); wxString GetScriptSettingsIdentifier();
@ -103,40 +104,27 @@ namespace Automation4 {
// Subclasses must implement ProcessSubs from AssExportFilter // Subclasses must implement ProcessSubs from AssExportFilter
}; };
/// A "dialog" which actually generates a non-top-level window that is then
/// DOCME /// either inserted into a dialog or into the export filter configuration
/// @class ScriptConfigDialog /// panel
/// @brief DOCME class ScriptDialog {
///
/// DOCME
class ScriptConfigDialog {
private:
/// DOCME
wxWindow *win;
protected:
virtual wxWindow* CreateWindow(wxWindow *parent) = 0;
public: public:
virtual ~ScriptDialog() { }
/// @brief DOCME /// Create a window with the given parent
/// virtual wxWindow *CreateWindow(wxWindow *parent) = 0;
ScriptConfigDialog() : win(0) { }
/// @brief DOCME /// Read the values of the controls in this dialog and cache them in
/// /// some way so that they can be accessed from a background thread
virtual ~ScriptConfigDialog() { }
wxWindow* GetWindow(wxWindow *parent);
void DeleteWindow();
virtual void ReadBack() = 0; virtual void ReadBack() = 0;
virtual wxString Serialise(); /// Serialize the values of the controls in this dialog to a string
/// suitable for storage in the subtitle script
virtual wxString Serialise() { return ""; }
/// @brief DOCME /// Restore the values of the controls in this dialog from a string
/// @param serialised /// stored in the subtitle script
/// virtual void Unserialise(wxString const& serialised) { }
virtual void Unserialise(const wxString &serialised) { }
}; };
class ProgressSink; class ProgressSink;
@ -144,9 +132,8 @@ namespace Automation4 {
class BackgroundScriptRunner { class BackgroundScriptRunner {
agi::scoped_ptr<DialogProgress> impl; agi::scoped_ptr<DialogProgress> impl;
void OnConfigDialog(wxThreadEvent &evt); void OnDialog(wxThreadEvent &evt);
public: public:
void QueueEvent(wxEvent *evt); void QueueEvent(wxEvent *evt);
void Run(std::tr1::function<void(ProgressSink*)> task); void Run(std::tr1::function<void(ProgressSink*)> task);
@ -171,7 +158,7 @@ namespace Automation4 {
/// Show the passed dialog on the GUI thread, blocking the calling /// Show the passed dialog on the GUI thread, blocking the calling
/// thread until it closes /// thread until it closes
void ShowConfigDialog(ScriptConfigDialog *config_dialog); void ShowDialog(ScriptDialog *config_dialog);
/// Get the current automation trace level /// Get the current automation trace level
int GetTraceLevel() const { return trace_level; } int GetTraceLevel() const { return trace_level; }

View File

@ -744,7 +744,7 @@ namespace Automation4 {
subsobj->ProcessingComplete(); subsobj->ProcessingComplete();
} }
ScriptConfigDialog* LuaExportFilter::GenerateConfigDialog(wxWindow *parent, agi::Context *c) ScriptDialog* LuaExportFilter::GenerateConfigDialog(wxWindow *parent, agi::Context *c)
{ {
if (!has_config) if (!has_config)
return 0; return 0;
@ -765,7 +765,7 @@ namespace Automation4 {
lua_pop(L, 1); // remove error message lua_pop(L, 1); // remove error message
} else { } else {
// Create config dialogue from table on top of stack // Create config dialogue from table on top of stack
config_dialog = new LuaConfigDialog(L, false); config_dialog = new LuaDialog(L, false);
} }
return config_dialog; return config_dialog;

View File

@ -136,111 +136,74 @@ namespace Automation4 {
static ProgressSink* GetObjPointer(lua_State *L, int idx); static ProgressSink* GetObjPointer(lua_State *L, int idx);
}; };
/// Base class for controls in dialogs
class LuaDialogControl {
/// DOCME
/// @class LuaConfigDialogControl
/// @brief DOCME
///
/// DOCME
class LuaConfigDialogControl {
public: public:
/// Name of this control in the output table
wxString name;
/// DOCME /// Tooltip of this control
wxControl *cw; // control window wxString hint;
/// DOCME
/// DOCME
wxString name, hint;
/// DOCME
/// DOCME
/// DOCME
/// DOCME
int x, y, width, height; int x, y, width, height;
/// Create the associated wxControl
virtual wxControl *Create(wxWindow *parent) = 0; virtual wxControl *Create(wxWindow *parent) = 0;
/// Get the default flags to use when inserting this control into a sizer
virtual int GetSizerFlags() const { return wxEXPAND; }
/// Read the current value of the control. Must not touch Lua as this is called on the GUI thread.
virtual void ControlReadBack() = 0; virtual void ControlReadBack() = 0;
/// Push the current value of the control onto the lua stack. Must not
/// touch the GUI as this may be called on a background thread.
virtual void LuaReadBack(lua_State *L) = 0; virtual void LuaReadBack(lua_State *L) = 0;
/// Does this control have any user-changeable data that can be serialized?
virtual bool CanSerialiseValue() const { return false; }
/// @brief DOCME /// Serialize the control's current value so that it can be stored
/// @return /// in the script
/// virtual wxString SerialiseValue() const { return ""; }
virtual bool CanSerialiseValue() { return false; }
/// @brief DOCME /// Restore the control's value from a saved value in the script
/// @return
///
virtual wxString SerialiseValue() { return ""; }
/// @brief DOCME
/// @param serialised
///
virtual void UnserialiseValue(const wxString &serialised) { } virtual void UnserialiseValue(const wxString &serialised) { }
LuaConfigDialogControl(lua_State *L); LuaDialogControl(lua_State *L);
/// @brief DOCME /// Virtual destructor so this can safely be inherited from
/// virtual ~LuaDialogControl() { }
virtual ~LuaConfigDialogControl() { }
}; };
/// A lua-generated dialog or panel in the export options dialog
/// DOCME class LuaDialog : public ScriptDialog {
/// @class LuaConfigDialog /// Controls in this dialog
/// @brief DOCME std::vector<LuaDialogControl*> controls;
/// /// The names of buttons in this dialog if non-default ones were used
/// DOCME
class LuaConfigDialog : public ScriptConfigDialog {
private:
/// DOCME
std::vector<LuaConfigDialogControl*> controls;
/// DOCME
std::vector<wxString> buttons; std::vector<wxString> buttons;
/// DOCME /// Does the dialog contain any buttons
bool use_buttons; bool use_buttons;
/// Id of the button pushed (once a button has been pushed)
/// DOCME
/// @class ButtonEventHandler
/// @brief DOCME
///
/// DOCME
class ButtonEventHandler : public wxEvtHandler {
public:
/// DOCME
int *button_pushed;
void OnButtonPush(wxCommandEvent &evt);
};
/// DOCME
ButtonEventHandler *button_event;
/// DOCME
int button_pushed; int button_pushed;
protected: void OnButtonPush(wxCommandEvent &evt);
wxWindow* CreateWindow(wxWindow *parent);
public: public:
LuaConfigDialog(lua_State *_L, bool include_buttons); LuaDialog(lua_State *L, bool include_buttons);
virtual ~LuaConfigDialog(); ~LuaDialog();
int LuaReadBack(lua_State *L); // read back internal structure to lua structures
/// Push the values of the controls in this dialog onto the lua stack
/// in a single table
int LuaReadBack(lua_State *L);
// ScriptDialog implementation
wxWindow* CreateWindow(wxWindow *parent);
wxString Serialise(); wxString Serialise();
void Unserialise(const wxString &serialised); void Unserialise(const wxString &serialised);
void ReadBack();
void ReadBack(); // from auto4 base
}; };
class LuaFeature { class LuaFeature {
@ -252,7 +215,6 @@ namespace Automation4 {
void UnregisterFeature(); void UnregisterFeature();
void GetFeatureFunction(const char *function); void GetFeatureFunction(const char *function);
void ThrowError();
LuaFeature(lua_State *L); LuaFeature(lua_State *L);
}; };
@ -285,12 +247,12 @@ namespace Automation4 {
class LuaExportFilter : public ExportFilter, private LuaFeature { class LuaExportFilter : public ExportFilter, private LuaFeature {
bool has_config; bool has_config;
LuaConfigDialog *config_dialog; LuaDialog *config_dialog;
protected: protected:
LuaExportFilter(lua_State *L); LuaExportFilter(lua_State *L);
ScriptConfigDialog* GenerateConfigDialog(wxWindow *parent, agi::Context *c); ScriptDialog* GenerateConfigDialog(wxWindow *parent, agi::Context *c);
public: public:
static int LuaRegister(lua_State *L); static int LuaRegister(lua_State *L);

File diff suppressed because it is too large Load Diff

View File

@ -175,18 +175,8 @@ namespace Automation4 {
{ {
ProgressSink *ps = GetObjPointer(L, lua_upvalueindex(1)); ProgressSink *ps = GetObjPointer(L, lua_upvalueindex(1));
// Check that two arguments were actually given LuaDialog dlg(L, true); // magically creates the config dialog structure etc
// If only one, add another empty table for buttons ps->ShowDialog(&dlg);
if (lua_gettop(L) == 1) {
lua_newtable(L);
}
// If more than two, remove the excess
if (lua_gettop(L) > 2) {
lua_settop(L, 2);
}
LuaConfigDialog dlg(L, true); // magically creates the config dialog structure etc
ps->ShowConfigDialog(&dlg);
// more magic: puts two values on stack: button pushed and table with control results // more magic: puts two values on stack: button pushed and table with control results
return dlg.LuaReadBack(L); return dlg.LuaReadBack(L);