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_style.h"
#include "command/command.h"
#include "compat.h"
#include "dialog_progress.h"
#include "include/aegisub/context.h"
#include "main.h"
#include "standard_paths.h"
#include "string_codec.h"
#include "subtitle_format.h"
#include "utils.h"
/// DOCME
namespace Automation4 {
/// @brief DOCME
/// @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)
bool CalculateTextExtents(AssStyle *style, wxString const& text, double &width, double &height, double &descent, double &extlead)
{
width = height = descent = extlead = 0;
@ -219,7 +212,7 @@ namespace Automation4 {
wxString val = c->ass->GetScriptInfo(GetScriptSettingsIdentifier());
if (!val.empty())
config_dialog->Unserialise(val);
return config_dialog->GetWindow(parent);
return config_dialog->CreateWindow(parent);
}
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
wxDEFINE_EVENT(EVT_SHOW_CONFIG_DIALOG, wxThreadEvent);
wxDEFINE_EVENT(EVT_SHOW_DIALOG, wxThreadEvent);
ProgressSink::ProgressSink(agi::ProgressSink *impl, BackgroundScriptRunner *bsr)
: impl(impl)
@ -277,10 +238,10 @@ namespace Automation4 {
{
}
void ProgressSink::ShowConfigDialog(ScriptConfigDialog *config_dialog)
void ProgressSink::ShowDialog(ScriptDialog *config_dialog)
{
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));
bsr->QueueEvent(evt);
sema.Wait();
@ -289,27 +250,27 @@ namespace Automation4 {
BackgroundScriptRunner::BackgroundScriptRunner(wxWindow *parent, wxString const& 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()
{
}
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
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
w.SetSizerAndFit(s);
w.CenterOnParent();
w.ShowModal();
payload.first->ReadBack();
payload.first->DeleteWindow();
// Tell the calling thread it can wake up now
payload.second->Post();
}

View File

@ -39,6 +39,7 @@
#ifndef AGI_PRE
#include <list>
#include <vector>
#include <wx/dialog.h>
@ -80,15 +81,15 @@ namespace Automation4 {
DEFINE_SIMPLE_EXCEPTION_NOINNER(MacroRunError, AutomationError, "automation/macro/generic")
// 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 {
ScriptConfigDialog *config_dialog;
ScriptDialog *config_dialog;
/// subclasses should implement this, producing a new ScriptConfigDialog
virtual ScriptConfigDialog* GenerateConfigDialog(wxWindow *parent, agi::Context *c) = 0;
/// subclasses should implement this, producing a new ScriptDialog
virtual ScriptDialog* GenerateConfigDialog(wxWindow *parent, agi::Context *c) = 0;
protected:
wxString GetScriptSettingsIdentifier();
@ -103,40 +104,27 @@ namespace Automation4 {
// Subclasses must implement ProcessSubs from AssExportFilter
};
/// DOCME
/// @class ScriptConfigDialog
/// @brief DOCME
///
/// DOCME
class ScriptConfigDialog {
private:
/// DOCME
wxWindow *win;
protected:
virtual wxWindow* CreateWindow(wxWindow *parent) = 0;
/// A "dialog" which actually generates a non-top-level window that is then
/// either inserted into a dialog or into the export filter configuration
/// panel
class ScriptDialog {
public:
virtual ~ScriptDialog() { }
/// @brief DOCME
///
ScriptConfigDialog() : win(0) { }
/// Create a window with the given parent
virtual wxWindow *CreateWindow(wxWindow *parent) = 0;
/// @brief DOCME
///
virtual ~ScriptConfigDialog() { }
wxWindow* GetWindow(wxWindow *parent);
void DeleteWindow();
/// 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 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
/// @param serialised
///
virtual void Unserialise(const wxString &serialised) { }
/// Restore the values of the controls in this dialog from a string
/// stored in the subtitle script
virtual void Unserialise(wxString const& serialised) { }
};
class ProgressSink;
@ -144,9 +132,8 @@ namespace Automation4 {
class BackgroundScriptRunner {
agi::scoped_ptr<DialogProgress> impl;
void OnConfigDialog(wxThreadEvent &evt);
void OnDialog(wxThreadEvent &evt);
public:
void QueueEvent(wxEvent *evt);
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
/// thread until it closes
void ShowConfigDialog(ScriptConfigDialog *config_dialog);
void ShowDialog(ScriptDialog *config_dialog);
/// Get the current automation trace level
int GetTraceLevel() const { return trace_level; }

View File

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

View File

@ -136,111 +136,74 @@ namespace Automation4 {
static ProgressSink* GetObjPointer(lua_State *L, int idx);
};
/// DOCME
/// @class LuaConfigDialogControl
/// @brief DOCME
///
/// DOCME
class LuaConfigDialogControl {
/// Base class for controls in dialogs
class LuaDialogControl {
public:
/// Name of this control in the output table
wxString name;
/// DOCME
wxControl *cw; // control window
/// Tooltip of this control
wxString hint;
/// DOCME
/// DOCME
wxString name, hint;
/// DOCME
/// DOCME
/// DOCME
/// DOCME
int x, y, width, height;
/// Create the associated wxControl
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;
/// 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;
/// Does this control have any user-changeable data that can be serialized?
virtual bool CanSerialiseValue() const { return false; }
/// @brief DOCME
/// @return
///
virtual bool CanSerialiseValue() { return false; }
/// Serialize the control's current value so that it can be stored
/// in the script
virtual wxString SerialiseValue() const { return ""; }
/// @brief DOCME
/// @return
///
virtual wxString SerialiseValue() { return ""; }
/// @brief DOCME
/// @param serialised
///
/// Restore the control's value from a saved value in the script
virtual void UnserialiseValue(const wxString &serialised) { }
LuaConfigDialogControl(lua_State *L);
LuaDialogControl(lua_State *L);
/// @brief DOCME
///
virtual ~LuaConfigDialogControl() { }
/// Virtual destructor so this can safely be inherited from
virtual ~LuaDialogControl() { }
};
/// DOCME
/// @class LuaConfigDialog
/// @brief DOCME
///
/// DOCME
class LuaConfigDialog : public ScriptConfigDialog {
private:
/// DOCME
std::vector<LuaConfigDialogControl*> controls;
/// DOCME
/// A lua-generated dialog or panel in the export options dialog
class LuaDialog : public ScriptDialog {
/// Controls in this dialog
std::vector<LuaDialogControl*> controls;
/// The names of buttons in this dialog if non-default ones were used
std::vector<wxString> buttons;
/// DOCME
/// Does the dialog contain any buttons
bool use_buttons;
/// DOCME
/// @class ButtonEventHandler
/// @brief DOCME
///
/// DOCME
class ButtonEventHandler : public wxEvtHandler {
public:
/// DOCME
int *button_pushed;
void OnButtonPush(wxCommandEvent &evt);
};
/// DOCME
ButtonEventHandler *button_event;
/// DOCME
/// Id of the button pushed (once a button has been pushed)
int button_pushed;
protected:
wxWindow* CreateWindow(wxWindow *parent);
void OnButtonPush(wxCommandEvent &evt);
public:
LuaConfigDialog(lua_State *_L, bool include_buttons);
virtual ~LuaConfigDialog();
int LuaReadBack(lua_State *L); // read back internal structure to lua structures
LuaDialog(lua_State *L, bool include_buttons);
~LuaDialog();
/// 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();
void Unserialise(const wxString &serialised);
void ReadBack(); // from auto4 base
void ReadBack();
};
class LuaFeature {
@ -252,7 +215,6 @@ namespace Automation4 {
void UnregisterFeature();
void GetFeatureFunction(const char *function);
void ThrowError();
LuaFeature(lua_State *L);
};
@ -285,12 +247,12 @@ namespace Automation4 {
class LuaExportFilter : public ExportFilter, private LuaFeature {
bool has_config;
LuaConfigDialog *config_dialog;
LuaDialog *config_dialog;
protected:
LuaExportFilter(lua_State *L);
ScriptConfigDialog* GenerateConfigDialog(wxWindow *parent, agi::Context *c);
ScriptDialog* GenerateConfigDialog(wxWindow *parent, agi::Context *c);
public:
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));
// Check that two arguments were actually given
// If only one, add another empty table for buttons
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);
LuaDialog dlg(L, true); // magically creates the config dialog structure etc
ps->ShowDialog(&dlg);
// more magic: puts two values on stack: button pushed and table with control results
return dlg.LuaReadBack(L);