2007-01-10 02:36:05 +01:00
|
|
|
// Copyright (c) 2006, 2007, Niels Martin Hansen
|
2006-12-28 22:18:35 +01:00
|
|
|
// 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.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
|
|
|
/// @file auto4_lua_dialog.cpp
|
|
|
|
/// @brief Lua 5.1-based scripting engine (configuration-dialogue interface)
|
|
|
|
/// @ingroup scripting
|
|
|
|
///
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
#include "auto4_lua.h"
|
|
|
|
|
2013-05-26 01:31:48 +02:00
|
|
|
#include "auto4_lua_utils.h"
|
2013-01-04 16:01:50 +01:00
|
|
|
#include "ass_style.h"
|
|
|
|
#include "colour_button.h"
|
|
|
|
#include "compat.h"
|
|
|
|
#include "string_codec.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "validators.h"
|
|
|
|
|
|
|
|
#include <boost/algorithm/string/case_conv.hpp>
|
Add support for using standard button IDs from automation
Some example uses:
-- ~special snowflake~ OK/Cancel
aegisub.dialog.display(config, {ok='Accept', cancel='Cancel'})
-- On OS X the 'Help' button will be just a left-aligned ?
aegisub.dialog.display(config, {ok='OK', cancel='Cancel', help='Help'})
-- Each button in its own subtable to preserve passed order
-- Unnecessary when using only IDed buttons since the passed order will
-- be ignored in favor of the platform-standard order
aegisub.dialog.display(config,
{{ok='Accept'}, {cancel='Cancel'}, {help='Help'}, 'Another Button'})
In some cases the passed labels will be ignored in favor of the
platform-standard labels.
Available IDs:
ok
yes
save
apply
close
no
cancel
help
context_help
Note that many combinations of button IDs do not make sense and may have
strange effects.
Buttons with an ID of 'cancel' return false, as if ESC was pressed. A
button with an ID of 'close' results in that button being triggered on
ESC rather than cancel.
Buttons with an ID of 'ok', 'yes' and 'save' are set as the default
affirmative button for the dialog.
Closes #1609.
2013-05-23 03:58:53 +02:00
|
|
|
#include <boost/range/adaptors.hpp>
|
|
|
|
#include <boost/range/algorithm.hpp>
|
2013-01-04 16:01:50 +01:00
|
|
|
#include <boost/tokenizer.hpp>
|
2012-02-28 02:23:24 +01:00
|
|
|
#include <cassert>
|
2013-01-04 16:01:50 +01:00
|
|
|
#include <cfloat>
|
Add support for using standard button IDs from automation
Some example uses:
-- ~special snowflake~ OK/Cancel
aegisub.dialog.display(config, {ok='Accept', cancel='Cancel'})
-- On OS X the 'Help' button will be just a left-aligned ?
aegisub.dialog.display(config, {ok='OK', cancel='Cancel', help='Help'})
-- Each button in its own subtable to preserve passed order
-- Unnecessary when using only IDed buttons since the passed order will
-- be ignored in favor of the platform-standard order
aegisub.dialog.display(config,
{{ok='Accept'}, {cancel='Cancel'}, {help='Help'}, 'Another Button'})
In some cases the passed labels will be ignored in favor of the
platform-standard labels.
Available IDs:
ok
yes
save
apply
close
no
cancel
help
context_help
Note that many combinations of button IDs do not make sense and may have
strange effects.
Buttons with an ID of 'cancel' return false, as if ESC was pressed. A
button with an ID of 'close' results in that button being triggered on
ESC rather than cancel.
Buttons with an ID of 'ok', 'yes' and 'save' are set as the default
affirmative button for the dialog.
Closes #1609.
2013-05-23 03:58:53 +02:00
|
|
|
#include <unordered_map>
|
2008-03-05 05:10:20 +01:00
|
|
|
|
2006-12-28 22:18:35 +01:00
|
|
|
#include <wx/button.h>
|
2009-09-10 12:26:50 +02:00
|
|
|
#include <wx/checkbox.h>
|
2009-09-10 15:06:40 +02:00
|
|
|
#include <wx/combobox.h>
|
|
|
|
#include <wx/gbsizer.h>
|
2009-09-10 12:26:50 +02:00
|
|
|
#include <wx/panel.h>
|
2009-09-10 15:06:40 +02:00
|
|
|
#include <wx/spinctrl.h>
|
2013-01-04 16:01:50 +01:00
|
|
|
#include <wx/stattext.h>
|
2009-09-10 15:06:40 +02:00
|
|
|
#include <wx/validate.h>
|
2012-03-25 06:04:59 +02:00
|
|
|
#include <wx/valgen.h>
|
2012-02-28 02:23:24 +01:00
|
|
|
#include <wx/valnum.h>
|
2009-09-10 15:06:40 +02:00
|
|
|
#include <wx/window.h>
|
2009-09-10 12:26:50 +02:00
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
namespace {
|
2013-01-04 16:01:50 +01:00
|
|
|
inline void get_if_right_type(lua_State *L, std::string &def) {
|
2011-09-28 21:49:27 +02:00
|
|
|
if (lua_isstring(L, -1))
|
2013-01-04 16:01:50 +01:00
|
|
|
def = lua_tostring(L, -1);
|
2011-09-28 21:49:27 +02:00
|
|
|
}
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
inline void get_if_right_type(lua_State *L, double &def) {
|
2011-09-28 21:49:27 +02:00
|
|
|
if (lua_isnumber(L, -1))
|
2012-02-28 02:23:24 +01:00
|
|
|
def = lua_tonumber(L, -1);
|
2011-09-28 21:49:27 +02:00
|
|
|
}
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
inline void get_if_right_type(lua_State *L, int &def) {
|
2011-09-28 21:49:27 +02:00
|
|
|
if (lua_isnumber(L, -1))
|
2012-02-28 02:23:24 +01:00
|
|
|
def = lua_tointeger(L, -1);
|
2011-09-28 21:49:27 +02:00
|
|
|
}
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
inline void get_if_right_type(lua_State *L, bool &def) {
|
2011-09-28 21:49:27 +02:00
|
|
|
if (lua_isboolean(L, -1))
|
|
|
|
def = !!lua_toboolean(L, -1);
|
|
|
|
}
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
template<class T>
|
2013-01-04 16:01:50 +01:00
|
|
|
T get_field(lua_State *L, const char *name, T def) {
|
2011-09-28 21:49:27 +02:00
|
|
|
lua_getfield(L, -1, name);
|
|
|
|
get_if_right_type(L, def);
|
2006-12-28 22:18:35 +01:00
|
|
|
lua_pop(L, 1);
|
2011-09-28 21:49:27 +02:00
|
|
|
return def;
|
|
|
|
}
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
inline std::string get_field(lua_State *L, const char *name) {
|
|
|
|
return get_field(L, name, std::string());
|
2011-09-28 21:49:27 +02:00
|
|
|
}
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
template<class T>
|
2013-01-04 16:01:50 +01:00
|
|
|
void read_string_array(lua_State *L, T &cont) {
|
Add support for using standard button IDs from automation
Some example uses:
-- ~special snowflake~ OK/Cancel
aegisub.dialog.display(config, {ok='Accept', cancel='Cancel'})
-- On OS X the 'Help' button will be just a left-aligned ?
aegisub.dialog.display(config, {ok='OK', cancel='Cancel', help='Help'})
-- Each button in its own subtable to preserve passed order
-- Unnecessary when using only IDed buttons since the passed order will
-- be ignored in favor of the platform-standard order
aegisub.dialog.display(config,
{{ok='Accept'}, {cancel='Cancel'}, {help='Help'}, 'Another Button'})
In some cases the passed labels will be ignored in favor of the
platform-standard labels.
Available IDs:
ok
yes
save
apply
close
no
cancel
help
context_help
Note that many combinations of button IDs do not make sense and may have
strange effects.
Buttons with an ID of 'cancel' return false, as if ESC was pressed. A
button with an ID of 'close' results in that button being triggered on
ESC rather than cancel.
Buttons with an ID of 'ok', 'yes' and 'save' are set as the default
affirmative button for the dialog.
Closes #1609.
2013-05-23 03:58:53 +02:00
|
|
|
lua_for_each(L, [&] {
|
2011-09-28 21:49:27 +02:00
|
|
|
if (lua_isstring(L, -1))
|
2013-01-04 16:01:50 +01:00
|
|
|
cont.push_back(lua_tostring(L, -1));
|
Add support for using standard button IDs from automation
Some example uses:
-- ~special snowflake~ OK/Cancel
aegisub.dialog.display(config, {ok='Accept', cancel='Cancel'})
-- On OS X the 'Help' button will be just a left-aligned ?
aegisub.dialog.display(config, {ok='OK', cancel='Cancel', help='Help'})
-- Each button in its own subtable to preserve passed order
-- Unnecessary when using only IDed buttons since the passed order will
-- be ignored in favor of the platform-standard order
aegisub.dialog.display(config,
{{ok='Accept'}, {cancel='Cancel'}, {help='Help'}, 'Another Button'})
In some cases the passed labels will be ignored in favor of the
platform-standard labels.
Available IDs:
ok
yes
save
apply
close
no
cancel
help
context_help
Note that many combinations of button IDs do not make sense and may have
strange effects.
Buttons with an ID of 'cancel' return false, as if ESC was pressed. A
button with an ID of 'close' results in that button being triggered on
ESC rather than cancel.
Buttons with an ID of 'ok', 'yes' and 'save' are set as the default
affirmative button for the dialog.
Closes #1609.
2013-05-23 03:58:53 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
int string_to_wx_id(std::string const& str) {
|
|
|
|
static std::unordered_map<std::string, int> ids;
|
|
|
|
if (ids.empty()) {
|
|
|
|
ids["ok"] = wxID_OK;
|
|
|
|
ids["yes"] = wxID_YES;
|
|
|
|
ids["save"] = wxID_SAVE;
|
|
|
|
ids["apply"] = wxID_APPLY;
|
|
|
|
ids["close"] = wxID_CLOSE;
|
|
|
|
ids["no"] = wxID_NO;
|
|
|
|
ids["cancel"] = wxID_CANCEL;
|
|
|
|
ids["help"] = wxID_HELP;
|
|
|
|
ids["context_help"] = wxID_CONTEXT_HELP;
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
Add support for using standard button IDs from automation
Some example uses:
-- ~special snowflake~ OK/Cancel
aegisub.dialog.display(config, {ok='Accept', cancel='Cancel'})
-- On OS X the 'Help' button will be just a left-aligned ?
aegisub.dialog.display(config, {ok='OK', cancel='Cancel', help='Help'})
-- Each button in its own subtable to preserve passed order
-- Unnecessary when using only IDed buttons since the passed order will
-- be ignored in favor of the platform-standard order
aegisub.dialog.display(config,
{{ok='Accept'}, {cancel='Cancel'}, {help='Help'}, 'Another Button'})
In some cases the passed labels will be ignored in favor of the
platform-standard labels.
Available IDs:
ok
yes
save
apply
close
no
cancel
help
context_help
Note that many combinations of button IDs do not make sense and may have
strange effects.
Buttons with an ID of 'cancel' return false, as if ESC was pressed. A
button with an ID of 'close' results in that button being triggered on
ESC rather than cancel.
Buttons with an ID of 'ok', 'yes' and 'save' are set as the default
affirmative button for the dialog.
Closes #1609.
2013-05-23 03:58:53 +02:00
|
|
|
auto it = ids.find(str);
|
|
|
|
return it == end(ids) ? -1 : it->second;
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
2011-09-28 21:49:27 +02:00
|
|
|
}
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
namespace Automation4 {
|
|
|
|
// LuaDialogControl
|
|
|
|
LuaDialogControl::LuaDialogControl(lua_State *L)
|
|
|
|
// Assume top of stack is a control table (don't do checking)
|
|
|
|
: name(get_field(L, "name"))
|
|
|
|
, hint(get_field(L, "hint"))
|
|
|
|
, x(get_field(L, "x", 0))
|
|
|
|
, y(get_field(L, "y", 0))
|
|
|
|
, width(get_field(L, "width", 1))
|
|
|
|
, height(get_field(L, "height", 1))
|
|
|
|
{
|
2013-01-04 16:01:50 +01:00
|
|
|
LOG_D("automation/lua/dialog") << "created control: '" << name << "', (" << x << "," << y << ")(" << width << "," << height << "), " << hint;
|
2011-09-28 21:49:27 +02:00
|
|
|
}
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2006-12-28 22:18:35 +01:00
|
|
|
namespace LuaControl {
|
2011-09-28 21:49:27 +02:00
|
|
|
/// A static text label
|
|
|
|
class Label : public LuaDialogControl {
|
2013-01-04 16:01:50 +01:00
|
|
|
std::string label;
|
2011-09-28 21:49:27 +02:00
|
|
|
public:
|
2013-01-04 16:01:50 +01:00
|
|
|
Label(lua_State *L) : LuaDialogControl(L), label(get_field(L, "label")) { }
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
wxControl *Create(wxWindow *parent) {
|
|
|
|
return new wxStaticText(parent, -1, to_wx(label));
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
int GetSizerFlags() const { return wxALIGN_CENTRE_VERTICAL | wxALIGN_LEFT; }
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
void LuaReadBack(lua_State *L) {
|
2006-12-28 22:18:35 +01:00
|
|
|
// Label doesn't produce output, so let it be nil
|
|
|
|
lua_pushnil(L);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
/// A single-line text edit control
|
|
|
|
class Edit : public LuaDialogControl {
|
|
|
|
protected:
|
2013-01-04 16:01:50 +01:00
|
|
|
std::string text;
|
2011-09-28 21:49:27 +02:00
|
|
|
wxTextCtrl *cw;
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
public:
|
2006-12-28 22:18:35 +01:00
|
|
|
Edit(lua_State *L)
|
2011-09-28 21:49:27 +02:00
|
|
|
: LuaDialogControl(L)
|
|
|
|
, text(get_field(L, "value"))
|
2012-10-15 06:37:14 +02:00
|
|
|
, cw(0)
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
2009-05-12 17:32:11 +02:00
|
|
|
// Undocumented behaviour, 'value' is also accepted as key for text,
|
|
|
|
// mostly so a text control can stand in for other things.
|
|
|
|
// This shouldn't be exploited and might change later.
|
2011-09-28 21:49:27 +02:00
|
|
|
text = get_field(L, "text", text);
|
2007-04-04 02:01:17 +02:00
|
|
|
}
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
bool CanSerialiseValue() const { return true; }
|
2013-01-04 16:01:50 +01:00
|
|
|
std::string SerialiseValue() const { return inline_string_encode(text); }
|
|
|
|
void UnserialiseValue(const std::string &serialised) { text = inline_string_decode(serialised); }
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
wxControl *Create(wxWindow *parent) {
|
|
|
|
cw = new wxTextCtrl(parent, -1, to_wx(text));
|
|
|
|
cw->SetValidator(StringBinder(&text));
|
|
|
|
cw->SetToolTip(to_wx(hint));
|
2007-06-28 19:59:27 +02:00
|
|
|
return cw;
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
void LuaReadBack(lua_State *L) {
|
|
|
|
lua_pushstring(L, text.c_str());
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
/// A color-picker button
|
|
|
|
class Color : public LuaDialogControl {
|
2013-01-04 16:01:50 +01:00
|
|
|
std::string text;
|
2013-01-13 20:20:44 +01:00
|
|
|
bool alpha;
|
2008-03-12 08:04:07 +01:00
|
|
|
|
2012-03-07 02:30:52 +01:00
|
|
|
struct ColorValidator : public wxValidator {
|
2013-01-04 16:01:50 +01:00
|
|
|
std::string *text;
|
|
|
|
ColorValidator(std::string *text) : text(text) { }
|
2012-03-07 02:30:52 +01:00
|
|
|
wxValidator *Clone() const { return new ColorValidator(text); }
|
|
|
|
bool Validate(wxWindow*) { return true; }
|
|
|
|
bool TransferToWindow() { return true; }
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
bool TransferFromWindow() {
|
|
|
|
*text = static_cast<ColourButton*>(GetWindow())->GetColor().GetHexFormatted();
|
2012-03-07 02:30:52 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2013-01-04 16:01:50 +01:00
|
|
|
|
2012-03-07 02:30:52 +01:00
|
|
|
public:
|
2013-01-13 20:20:44 +01:00
|
|
|
Color(lua_State *L, bool alpha)
|
2011-09-28 21:49:27 +02:00
|
|
|
: LuaDialogControl(L)
|
|
|
|
, text(get_field(L, "value"))
|
2013-01-13 20:20:44 +01:00
|
|
|
, alpha(alpha)
|
2008-03-12 08:04:07 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
bool CanSerialiseValue() const { return true; }
|
2013-01-04 16:01:50 +01:00
|
|
|
std::string SerialiseValue() const { return inline_string_encode(text); }
|
|
|
|
void UnserialiseValue(const std::string &serialised) { text = inline_string_decode(serialised); }
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
wxControl *Create(wxWindow *parent) {
|
|
|
|
agi::Color colour(text);
|
2013-01-13 20:20:44 +01:00
|
|
|
wxControl *cw = new ColourButton(parent, wxSize(50*width,10*height), alpha, colour, ColorValidator(&text));
|
2013-01-04 16:01:50 +01:00
|
|
|
cw->SetToolTip(to_wx(hint));
|
2008-03-12 08:04:07 +01:00
|
|
|
return cw;
|
|
|
|
}
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
void LuaReadBack(lua_State *L) {
|
|
|
|
lua_pushstring(L, text.c_str());
|
2008-03-12 08:04:07 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
/// A multiline text edit control
|
2006-12-28 22:18:35 +01:00
|
|
|
class Textbox : public Edit {
|
|
|
|
public:
|
2013-01-04 16:01:50 +01:00
|
|
|
Textbox(lua_State *L) : Edit(L) { }
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2007-04-04 02:01:17 +02:00
|
|
|
// Same serialisation interface as single-line edit
|
2013-01-04 16:01:50 +01:00
|
|
|
wxControl *Create(wxWindow *parent) {
|
|
|
|
cw = new wxTextCtrl(parent, -1, "", wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE, StringBinder(&text));
|
2006-12-28 22:18:35 +01:00
|
|
|
cw->SetMinSize(wxSize(0, 30));
|
2013-01-04 16:01:50 +01:00
|
|
|
cw->SetToolTip(to_wx(hint));
|
2006-12-28 22:18:35 +01:00
|
|
|
return cw;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
/// Integer only edit
|
2006-12-28 22:18:35 +01:00
|
|
|
class IntEdit : public Edit {
|
2011-09-28 21:49:27 +02:00
|
|
|
wxSpinCtrl *cw;
|
2006-12-28 22:18:35 +01:00
|
|
|
int value;
|
|
|
|
int min, max;
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
public:
|
2006-12-28 22:18:35 +01:00
|
|
|
IntEdit(lua_State *L)
|
2011-09-28 21:49:27 +02:00
|
|
|
: Edit(L)
|
2012-10-15 06:37:14 +02:00
|
|
|
, cw(0)
|
2011-09-28 21:49:27 +02:00
|
|
|
, value(get_field(L, "value", 0))
|
2012-02-28 02:23:15 +01:00
|
|
|
, min(get_field(L, "min", INT_MIN))
|
|
|
|
, max(get_field(L, "max", INT_MAX))
|
2011-09-28 21:49:27 +02:00
|
|
|
{
|
2012-02-28 02:23:15 +01:00
|
|
|
if (min >= max) {
|
2011-09-28 21:49:27 +02:00
|
|
|
max = INT_MAX;
|
|
|
|
min = INT_MIN;
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
bool CanSerialiseValue() const { return true; }
|
2013-01-04 16:01:50 +01:00
|
|
|
std::string SerialiseValue() const { return std::to_string(value); }
|
|
|
|
void UnserialiseValue(const std::string &serialised) { value = atoi(serialised.c_str()); }
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
wxControl *Create(wxWindow *parent) {
|
|
|
|
cw = new wxSpinCtrl(parent, -1, "", wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, min, max, value);
|
2012-03-07 02:30:52 +01:00
|
|
|
cw->SetValidator(wxGenericValidator(&value));
|
2013-01-04 16:01:50 +01:00
|
|
|
cw->SetToolTip(to_wx(hint));
|
2007-06-28 19:59:27 +02:00
|
|
|
return cw;
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
void LuaReadBack(lua_State *L) {
|
2006-12-28 22:18:35 +01:00
|
|
|
lua_pushinteger(L, value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Float only edit
|
|
|
|
class FloatEdit : public Edit {
|
2011-09-28 21:49:27 +02:00
|
|
|
double value;
|
2012-02-28 02:23:24 +01:00
|
|
|
double min;
|
|
|
|
double max;
|
|
|
|
double step;
|
|
|
|
wxSpinCtrlDouble *scd;
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2012-03-07 02:30:52 +01:00
|
|
|
struct DoubleValidator : public wxValidator {
|
|
|
|
double *value;
|
|
|
|
DoubleValidator(double *value) : value(value) { }
|
|
|
|
wxValidator *Clone() const { return new DoubleValidator(value); }
|
|
|
|
bool Validate(wxWindow*) { return true; }
|
2013-05-26 00:46:57 +02:00
|
|
|
|
|
|
|
bool TransferToWindow() {
|
|
|
|
static_cast<wxSpinCtrlDouble*>(GetWindow())->SetValue(*value);
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-07 02:30:52 +01:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
bool TransferFromWindow() {
|
2012-03-07 02:30:52 +01:00
|
|
|
*value = static_cast<wxSpinCtrlDouble*>(GetWindow())->GetValue();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-02-28 02:23:24 +01:00
|
|
|
public:
|
2006-12-28 22:18:35 +01:00
|
|
|
FloatEdit(lua_State *L)
|
2011-09-28 21:49:27 +02:00
|
|
|
: Edit(L)
|
2011-12-28 22:27:22 +01:00
|
|
|
, value(get_field(L, "value", 0.0))
|
2012-02-28 02:23:24 +01:00
|
|
|
, min(get_field(L, "min", -DBL_MAX))
|
|
|
|
, max(get_field(L, "max", DBL_MAX))
|
|
|
|
, step(get_field(L, "step", 0.0))
|
|
|
|
, scd(0)
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
2012-02-28 02:23:24 +01:00
|
|
|
if (min >= max) {
|
|
|
|
max = DBL_MAX;
|
|
|
|
min = -DBL_MAX;
|
|
|
|
}
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
2012-02-28 02:23:24 +01:00
|
|
|
bool CanSerialiseValue() const { return true; }
|
2013-01-04 16:01:50 +01:00
|
|
|
std::string SerialiseValue() const { return std::to_string(value); }
|
|
|
|
void UnserialiseValue(const std::string &serialised) { value = atof(serialised.c_str()); }
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
wxControl *Create(wxWindow *parent) {
|
2012-02-28 02:23:24 +01:00
|
|
|
if (step > 0) {
|
2013-01-04 16:01:50 +01:00
|
|
|
scd = new wxSpinCtrlDouble(parent, -1, "", wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, min, max, value, step);
|
2012-03-07 02:30:52 +01:00
|
|
|
scd->SetValidator(DoubleValidator(&value));
|
2013-01-04 16:01:50 +01:00
|
|
|
scd->SetToolTip(to_wx(hint));
|
2012-02-28 02:23:24 +01:00
|
|
|
return scd;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxFloatingPointValidator<double> val(4, &value, wxNUM_VAL_NO_TRAILING_ZEROES);
|
|
|
|
val.SetRange(min, max);
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
cw = new wxTextCtrl(parent, -1, "", wxDefaultPosition, wxDefaultSize, 0, val);
|
|
|
|
cw->SetToolTip(to_wx(hint));
|
2007-06-28 19:59:27 +02:00
|
|
|
return cw;
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
void LuaReadBack(lua_State *L) {
|
2006-12-28 22:18:35 +01:00
|
|
|
lua_pushnumber(L, value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
/// A dropdown list
|
|
|
|
class Dropdown : public LuaDialogControl {
|
2013-01-04 16:01:50 +01:00
|
|
|
std::vector<std::string> items;
|
|
|
|
std::string value;
|
2011-09-28 21:49:27 +02:00
|
|
|
wxComboBox *cw;
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2012-03-07 02:30:52 +01:00
|
|
|
public:
|
2006-12-28 22:18:35 +01:00
|
|
|
Dropdown(lua_State *L)
|
2011-09-28 21:49:27 +02:00
|
|
|
: LuaDialogControl(L)
|
|
|
|
, value(get_field(L, "value"))
|
2012-10-15 06:37:14 +02:00
|
|
|
, cw(0)
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
|
|
|
lua_getfield(L, -1, "items");
|
2011-09-28 21:49:27 +02:00
|
|
|
read_string_array(L, items);
|
2007-04-04 02:01:17 +02:00
|
|
|
}
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
bool CanSerialiseValue() const { return true; }
|
2013-01-04 16:01:50 +01:00
|
|
|
std::string SerialiseValue() const { return inline_string_encode(value); }
|
|
|
|
void UnserialiseValue(const std::string &serialised) { value = inline_string_decode(serialised); }
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
wxControl *Create(wxWindow *parent) {
|
|
|
|
cw = new wxComboBox(parent, -1, to_wx(value), wxDefaultPosition, wxDefaultSize, to_wx(items), wxCB_READONLY, StringBinder(&value));
|
|
|
|
cw->SetToolTip(to_wx(hint));
|
2007-06-28 19:59:27 +02:00
|
|
|
return cw;
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
void LuaReadBack(lua_State *L) {
|
|
|
|
lua_pushstring(L, value.c_str());
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
class Checkbox : public LuaDialogControl {
|
2013-01-04 16:01:50 +01:00
|
|
|
std::string label;
|
2006-12-28 22:18:35 +01:00
|
|
|
bool value;
|
2011-09-28 21:49:27 +02:00
|
|
|
wxCheckBox *cw;
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
public:
|
2006-12-28 22:18:35 +01:00
|
|
|
Checkbox(lua_State *L)
|
2011-09-28 21:49:27 +02:00
|
|
|
: LuaDialogControl(L)
|
|
|
|
, label(get_field(L, "label"))
|
|
|
|
, value(get_field(L, "value", false))
|
2012-10-15 06:37:14 +02:00
|
|
|
, cw(0)
|
2007-04-04 02:01:17 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
bool CanSerialiseValue() const { return true; }
|
2013-01-04 16:01:50 +01:00
|
|
|
std::string SerialiseValue() const { return value ? "1" : "0"; }
|
|
|
|
void UnserialiseValue(const std::string &serialised) { value = serialised != "0"; }
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
wxControl *Create(wxWindow *parent) {
|
|
|
|
cw = new wxCheckBox(parent, -1, to_wx(label));
|
2012-03-07 02:30:52 +01:00
|
|
|
cw->SetValidator(wxGenericValidator(&value));
|
2013-01-04 16:01:50 +01:00
|
|
|
cw->SetToolTip(to_wx(hint));
|
2011-09-28 21:49:27 +02:00
|
|
|
cw->SetValue(value);
|
2007-06-28 19:59:27 +02:00
|
|
|
return cw;
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
void LuaReadBack(lua_State *L) {
|
2006-12-28 22:18:35 +01:00
|
|
|
lua_pushboolean(L, value);
|
|
|
|
}
|
|
|
|
};
|
2011-12-28 22:27:06 +01:00
|
|
|
}
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
// LuaDialog
|
|
|
|
LuaDialog::LuaDialog(lua_State *L, bool include_buttons)
|
|
|
|
: use_buttons(include_buttons)
|
|
|
|
, button_pushed(0)
|
2012-10-15 06:37:14 +02:00
|
|
|
, window(0)
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
2011-09-28 21:49:27 +02:00
|
|
|
LOG_D("automation/lua/dialog") << "creating LuaDialoug, addr: " << this;
|
2006-12-28 22:18:35 +01:00
|
|
|
|
|
|
|
// assume top of stack now contains a dialog table
|
2011-09-28 21:49:27 +02:00
|
|
|
if (!lua_istable(L, 1))
|
|
|
|
luaL_error(L, "Cannot create config dialog from something non-table");
|
2006-12-28 22:18:35 +01:00
|
|
|
|
|
|
|
// Ok, so there is a table with controls
|
2013-05-26 01:31:48 +02:00
|
|
|
lua_for_each(L, [&] {
|
2013-01-04 16:01:50 +01:00
|
|
|
if (!lua_istable(L, -1))
|
|
|
|
luaL_error(L, "bad control table entry");
|
2011-09-28 21:49:27 +02:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
std::string controlclass = get_field(L, "class");
|
|
|
|
boost::to_lower(controlclass);
|
2011-09-28 21:49:27 +02:00
|
|
|
|
|
|
|
LuaDialogControl *ctl;
|
|
|
|
|
|
|
|
// Check control class and create relevant control
|
2013-01-04 16:01:50 +01:00
|
|
|
if (controlclass == "label")
|
2011-09-28 21:49:27 +02:00
|
|
|
ctl = new LuaControl::Label(L);
|
2013-01-04 16:01:50 +01:00
|
|
|
else if (controlclass == "edit")
|
2011-09-28 21:49:27 +02:00
|
|
|
ctl = new LuaControl::Edit(L);
|
2013-01-04 16:01:50 +01:00
|
|
|
else if (controlclass == "intedit")
|
2011-09-28 21:49:27 +02:00
|
|
|
ctl = new LuaControl::IntEdit(L);
|
2013-01-04 16:01:50 +01:00
|
|
|
else if (controlclass == "floatedit")
|
2011-09-28 21:49:27 +02:00
|
|
|
ctl = new LuaControl::FloatEdit(L);
|
2013-01-04 16:01:50 +01:00
|
|
|
else if (controlclass == "textbox")
|
2011-09-28 21:49:27 +02:00
|
|
|
ctl = new LuaControl::Textbox(L);
|
2013-01-04 16:01:50 +01:00
|
|
|
else if (controlclass == "dropdown")
|
2011-09-28 21:49:27 +02:00
|
|
|
ctl = new LuaControl::Dropdown(L);
|
2013-01-04 16:01:50 +01:00
|
|
|
else if (controlclass == "checkbox")
|
2011-09-28 21:49:27 +02:00
|
|
|
ctl = new LuaControl::Checkbox(L);
|
2013-01-04 16:01:50 +01:00
|
|
|
else if (controlclass == "color")
|
2013-01-13 20:20:44 +01:00
|
|
|
ctl = new LuaControl::Color(L, false);
|
2013-01-04 16:01:50 +01:00
|
|
|
else if (controlclass == "coloralpha")
|
2013-01-13 20:20:44 +01:00
|
|
|
ctl = new LuaControl::Color(L, true);
|
2013-01-04 16:01:50 +01:00
|
|
|
else if (controlclass == "alpha")
|
2011-09-28 21:49:27 +02:00
|
|
|
// FIXME
|
|
|
|
ctl = new LuaControl::Edit(L);
|
2013-01-04 16:01:50 +01:00
|
|
|
else
|
2011-09-28 21:49:27 +02:00
|
|
|
luaL_error(L, "bad control table entry");
|
|
|
|
|
|
|
|
controls.push_back(ctl);
|
2013-05-26 01:31:48 +02:00
|
|
|
});
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
if (include_buttons && lua_istable(L, 2)) {
|
|
|
|
lua_pushvalue(L, 2);
|
Add support for using standard button IDs from automation
Some example uses:
-- ~special snowflake~ OK/Cancel
aegisub.dialog.display(config, {ok='Accept', cancel='Cancel'})
-- On OS X the 'Help' button will be just a left-aligned ?
aegisub.dialog.display(config, {ok='OK', cancel='Cancel', help='Help'})
-- Each button in its own subtable to preserve passed order
-- Unnecessary when using only IDed buttons since the passed order will
-- be ignored in favor of the platform-standard order
aegisub.dialog.display(config,
{{ok='Accept'}, {cancel='Cancel'}, {help='Help'}, 'Another Button'})
In some cases the passed labels will be ignored in favor of the
platform-standard labels.
Available IDs:
ok
yes
save
apply
close
no
cancel
help
context_help
Note that many combinations of button IDs do not make sense and may have
strange effects.
Buttons with an ID of 'cancel' return false, as if ESC was pressed. A
button with an ID of 'close' results in that button being triggered on
ESC rather than cancel.
Buttons with an ID of 'ok', 'yes' and 'save' are set as the default
affirmative button for the dialog.
Closes #1609.
2013-05-23 03:58:53 +02:00
|
|
|
lua_for_each(L, [&]{
|
|
|
|
// String key: key is button ID, value is button label
|
|
|
|
// lua_isstring actually checks "is convertible to string"
|
|
|
|
if (lua_type(L, -2) == LUA_TSTRING)
|
|
|
|
buttons.emplace_back(
|
|
|
|
string_to_wx_id(lua_tostring(L, -2)),
|
|
|
|
luaL_checkstring(L, -1));
|
|
|
|
|
|
|
|
// Number key, string value: value is label
|
|
|
|
else if (lua_isstring(L, -1))
|
|
|
|
buttons.emplace_back(-1, lua_tostring(L, -1));
|
|
|
|
|
|
|
|
// Table value: Is a subtable that needs to be flatten.
|
|
|
|
// Used for ordered key-value pairs
|
|
|
|
else if (lua_istable(L, -1)) {
|
|
|
|
lua_pushvalue(L, -1);
|
|
|
|
lua_for_each(L, [&]{
|
|
|
|
buttons.emplace_back(
|
|
|
|
string_to_wx_id(luaL_checkstring(L, -2)),
|
|
|
|
luaL_checkstring(L, -1));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
luaL_error(L, "Invalid entry in buttons table");
|
|
|
|
});
|
2011-09-28 21:49:27 +02:00
|
|
|
}
|
|
|
|
}
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
LuaDialog::~LuaDialog() {
|
2011-09-28 21:49:27 +02:00
|
|
|
delete_clear(controls);
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
wxWindow* LuaDialog::CreateWindow(wxWindow *parent) {
|
2012-03-07 02:30:52 +01:00
|
|
|
window = new wxPanel(parent);
|
2006-12-28 22:18:35 +01:00
|
|
|
|
Add support for using standard button IDs from automation
Some example uses:
-- ~special snowflake~ OK/Cancel
aegisub.dialog.display(config, {ok='Accept', cancel='Cancel'})
-- On OS X the 'Help' button will be just a left-aligned ?
aegisub.dialog.display(config, {ok='OK', cancel='Cancel', help='Help'})
-- Each button in its own subtable to preserve passed order
-- Unnecessary when using only IDed buttons since the passed order will
-- be ignored in favor of the platform-standard order
aegisub.dialog.display(config,
{{ok='Accept'}, {cancel='Cancel'}, {help='Help'}, 'Another Button'})
In some cases the passed labels will be ignored in favor of the
platform-standard labels.
Available IDs:
ok
yes
save
apply
close
no
cancel
help
context_help
Note that many combinations of button IDs do not make sense and may have
strange effects.
Buttons with an ID of 'cancel' return false, as if ESC was pressed. A
button with an ID of 'close' results in that button being triggered on
ESC rather than cancel.
Buttons with an ID of 'ok', 'yes' and 'save' are set as the default
affirmative button for the dialog.
Closes #1609.
2013-05-23 03:58:53 +02:00
|
|
|
auto s = new wxGridBagSizer(4, 4);
|
2012-11-04 04:53:03 +01:00
|
|
|
for (auto c : controls)
|
Add support for using standard button IDs from automation
Some example uses:
-- ~special snowflake~ OK/Cancel
aegisub.dialog.display(config, {ok='Accept', cancel='Cancel'})
-- On OS X the 'Help' button will be just a left-aligned ?
aegisub.dialog.display(config, {ok='OK', cancel='Cancel', help='Help'})
-- Each button in its own subtable to preserve passed order
-- Unnecessary when using only IDed buttons since the passed order will
-- be ignored in favor of the platform-standard order
aegisub.dialog.display(config,
{{ok='Accept'}, {cancel='Cancel'}, {help='Help'}, 'Another Button'})
In some cases the passed labels will be ignored in favor of the
platform-standard labels.
Available IDs:
ok
yes
save
apply
close
no
cancel
help
context_help
Note that many combinations of button IDs do not make sense and may have
strange effects.
Buttons with an ID of 'cancel' return false, as if ESC was pressed. A
button with an ID of 'close' results in that button being triggered on
ESC rather than cancel.
Buttons with an ID of 'ok', 'yes' and 'save' are set as the default
affirmative button for the dialog.
Closes #1609.
2013-05-23 03:58:53 +02:00
|
|
|
s->Add(c->Create(window), wxGBPosition(c->y, c->x),
|
|
|
|
wxGBSpan(c->height, c->width), c->GetSizerFlags());
|
2006-12-28 22:18:35 +01:00
|
|
|
|
Add support for using standard button IDs from automation
Some example uses:
-- ~special snowflake~ OK/Cancel
aegisub.dialog.display(config, {ok='Accept', cancel='Cancel'})
-- On OS X the 'Help' button will be just a left-aligned ?
aegisub.dialog.display(config, {ok='OK', cancel='Cancel', help='Help'})
-- Each button in its own subtable to preserve passed order
-- Unnecessary when using only IDed buttons since the passed order will
-- be ignored in favor of the platform-standard order
aegisub.dialog.display(config,
{{ok='Accept'}, {cancel='Cancel'}, {help='Help'}, 'Another Button'})
In some cases the passed labels will be ignored in favor of the
platform-standard labels.
Available IDs:
ok
yes
save
apply
close
no
cancel
help
context_help
Note that many combinations of button IDs do not make sense and may have
strange effects.
Buttons with an ID of 'cancel' return false, as if ESC was pressed. A
button with an ID of 'close' results in that button being triggered on
ESC rather than cancel.
Buttons with an ID of 'ok', 'yes' and 'save' are set as the default
affirmative button for the dialog.
Closes #1609.
2013-05-23 03:58:53 +02:00
|
|
|
if (!use_buttons) {
|
2013-01-04 16:01:50 +01:00
|
|
|
window->SetSizerAndFit(s);
|
Add support for using standard button IDs from automation
Some example uses:
-- ~special snowflake~ OK/Cancel
aegisub.dialog.display(config, {ok='Accept', cancel='Cancel'})
-- On OS X the 'Help' button will be just a left-aligned ?
aegisub.dialog.display(config, {ok='OK', cancel='Cancel', help='Help'})
-- Each button in its own subtable to preserve passed order
-- Unnecessary when using only IDed buttons since the passed order will
-- be ignored in favor of the platform-standard order
aegisub.dialog.display(config,
{{ok='Accept'}, {cancel='Cancel'}, {help='Help'}, 'Another Button'})
In some cases the passed labels will be ignored in favor of the
platform-standard labels.
Available IDs:
ok
yes
save
apply
close
no
cancel
help
context_help
Note that many combinations of button IDs do not make sense and may have
strange effects.
Buttons with an ID of 'cancel' return false, as if ESC was pressed. A
button with an ID of 'close' results in that button being triggered on
ESC rather than cancel.
Buttons with an ID of 'ok', 'yes' and 'save' are set as the default
affirmative button for the dialog.
Closes #1609.
2013-05-23 03:58:53 +02:00
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buttons.size() == 0) {
|
|
|
|
buttons.emplace_back(wxID_OK, "");
|
|
|
|
buttons.emplace_back(wxID_CANCEL, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
auto dialog = static_cast<wxDialog *>(parent);
|
|
|
|
auto bs = new wxStdDialogButtonSizer;
|
|
|
|
|
|
|
|
auto make_button = [&](wxWindowID id, int button_pushed, wxString const& text) -> wxButton *{
|
|
|
|
auto button = new wxButton(window, id, text);
|
|
|
|
button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, [=](wxCommandEvent &evt) {
|
|
|
|
this->button_pushed = button_pushed;
|
|
|
|
dialog->EndModal(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (id == wxID_OK || id == wxID_YES || id == wxID_SAVE) {
|
|
|
|
button->SetFocus();
|
|
|
|
button->SetDefault();
|
|
|
|
dialog->SetAffirmativeId(id);
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
Add support for using standard button IDs from automation
Some example uses:
-- ~special snowflake~ OK/Cancel
aegisub.dialog.display(config, {ok='Accept', cancel='Cancel'})
-- On OS X the 'Help' button will be just a left-aligned ?
aegisub.dialog.display(config, {ok='OK', cancel='Cancel', help='Help'})
-- Each button in its own subtable to preserve passed order
-- Unnecessary when using only IDed buttons since the passed order will
-- be ignored in favor of the platform-standard order
aegisub.dialog.display(config,
{{ok='Accept'}, {cancel='Cancel'}, {help='Help'}, 'Another Button'})
In some cases the passed labels will be ignored in favor of the
platform-standard labels.
Available IDs:
ok
yes
save
apply
close
no
cancel
help
context_help
Note that many combinations of button IDs do not make sense and may have
strange effects.
Buttons with an ID of 'cancel' return false, as if ESC was pressed. A
button with an ID of 'close' results in that button being triggered on
ESC rather than cancel.
Buttons with an ID of 'ok', 'yes' and 'save' are set as the default
affirmative button for the dialog.
Closes #1609.
2013-05-23 03:58:53 +02:00
|
|
|
if (id == wxID_CLOSE || id == wxID_NO)
|
|
|
|
dialog->SetEscapeId(id);
|
2006-12-28 22:18:35 +01:00
|
|
|
|
Add support for using standard button IDs from automation
Some example uses:
-- ~special snowflake~ OK/Cancel
aegisub.dialog.display(config, {ok='Accept', cancel='Cancel'})
-- On OS X the 'Help' button will be just a left-aligned ?
aegisub.dialog.display(config, {ok='OK', cancel='Cancel', help='Help'})
-- Each button in its own subtable to preserve passed order
-- Unnecessary when using only IDed buttons since the passed order will
-- be ignored in favor of the platform-standard order
aegisub.dialog.display(config,
{{ok='Accept'}, {cancel='Cancel'}, {help='Help'}, 'Another Button'})
In some cases the passed labels will be ignored in favor of the
platform-standard labels.
Available IDs:
ok
yes
save
apply
close
no
cancel
help
context_help
Note that many combinations of button IDs do not make sense and may have
strange effects.
Buttons with an ID of 'cancel' return false, as if ESC was pressed. A
button with an ID of 'close' results in that button being triggered on
ESC rather than cancel.
Buttons with an ID of 'ok', 'yes' and 'save' are set as the default
affirmative button for the dialog.
Closes #1609.
2013-05-23 03:58:53 +02:00
|
|
|
return button;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (boost::count(buttons | boost::adaptors::map_keys, -1) == 0) {
|
|
|
|
for (size_t i = 0; i < buttons.size(); ++i)
|
|
|
|
bs->AddButton(make_button(buttons[i].first, i, wxEmptyString));
|
|
|
|
bs->Realize();
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
Add support for using standard button IDs from automation
Some example uses:
-- ~special snowflake~ OK/Cancel
aegisub.dialog.display(config, {ok='Accept', cancel='Cancel'})
-- On OS X the 'Help' button will be just a left-aligned ?
aegisub.dialog.display(config, {ok='OK', cancel='Cancel', help='Help'})
-- Each button in its own subtable to preserve passed order
-- Unnecessary when using only IDed buttons since the passed order will
-- be ignored in favor of the platform-standard order
aegisub.dialog.display(config,
{{ok='Accept'}, {cancel='Cancel'}, {help='Help'}, 'Another Button'})
In some cases the passed labels will be ignored in favor of the
platform-standard labels.
Available IDs:
ok
yes
save
apply
close
no
cancel
help
context_help
Note that many combinations of button IDs do not make sense and may have
strange effects.
Buttons with an ID of 'cancel' return false, as if ESC was pressed. A
button with an ID of 'close' results in that button being triggered on
ESC rather than cancel.
Buttons with an ID of 'ok', 'yes' and 'save' are set as the default
affirmative button for the dialog.
Closes #1609.
2013-05-23 03:58:53 +02:00
|
|
|
else {
|
|
|
|
for (size_t i = 0; i < buttons.size(); ++i)
|
|
|
|
bs->Add(make_button(buttons[i].first, i, buttons[i].second));
|
|
|
|
}
|
|
|
|
|
|
|
|
auto ms = new wxBoxSizer(wxVERTICAL);
|
|
|
|
ms->Add(s, 0, wxBOTTOM, 5);
|
|
|
|
ms->Add(bs);
|
|
|
|
window->SetSizerAndFit(ms);
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2012-03-07 02:30:52 +01:00
|
|
|
return window;
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
int LuaDialog::LuaReadBack(lua_State *L) {
|
2006-12-28 22:18:35 +01:00
|
|
|
// First read back which button was pressed, if any
|
|
|
|
if (use_buttons) {
|
Add support for using standard button IDs from automation
Some example uses:
-- ~special snowflake~ OK/Cancel
aegisub.dialog.display(config, {ok='Accept', cancel='Cancel'})
-- On OS X the 'Help' button will be just a left-aligned ?
aegisub.dialog.display(config, {ok='OK', cancel='Cancel', help='Help'})
-- Each button in its own subtable to preserve passed order
-- Unnecessary when using only IDed buttons since the passed order will
-- be ignored in favor of the platform-standard order
aegisub.dialog.display(config,
{{ok='Accept'}, {cancel='Cancel'}, {help='Help'}, 'Another Button'})
In some cases the passed labels will be ignored in favor of the
platform-standard labels.
Available IDs:
ok
yes
save
apply
close
no
cancel
help
context_help
Note that many combinations of button IDs do not make sense and may have
strange effects.
Buttons with an ID of 'cancel' return false, as if ESC was pressed. A
button with an ID of 'close' results in that button being triggered on
ESC rather than cancel.
Buttons with an ID of 'ok', 'yes' and 'save' are set as the default
affirmative button for the dialog.
Closes #1609.
2013-05-23 03:58:53 +02:00
|
|
|
if (buttons[button_pushed].first == wxID_CANCEL)
|
|
|
|
lua_pushboolean(L, false);
|
|
|
|
else
|
|
|
|
lua_pushstring(L, buttons[button_pushed].second.c_str());
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Then read controls back
|
|
|
|
lua_newtable(L);
|
2012-11-04 04:53:03 +01:00
|
|
|
for (auto control : controls) {
|
|
|
|
control->LuaReadBack(L);
|
2013-01-04 16:01:50 +01:00
|
|
|
lua_setfield(L, -2, control->name.c_str());
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
return use_buttons ? 2 : 1;
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
std::string LuaDialog::Serialise() {
|
|
|
|
std::string res;
|
2007-04-04 02:01:17 +02:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
// Format into "name1:value1|name2:value2|name3:value3"
|
2012-11-04 04:53:03 +01:00
|
|
|
for (auto control : controls) {
|
|
|
|
if (control->CanSerialiseValue()) {
|
2013-01-04 16:01:50 +01:00
|
|
|
if (!res.empty())
|
|
|
|
res += "|";
|
|
|
|
res += inline_string_encode(control->name) + ":" + control->SerialiseValue();
|
2007-04-04 02:01:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
void LuaDialog::Unserialise(const std::string &serialised) {
|
|
|
|
boost::char_separator<char> psep("|"), csep(":");
|
|
|
|
for (auto const& cur : boost::tokenizer<boost::char_separator<char>>(serialised, psep)) {
|
|
|
|
size_t pos = cur.find(':');
|
|
|
|
if (pos == std::string::npos) continue;
|
|
|
|
|
|
|
|
std::string name = inline_string_decode(cur.substr(0, pos));
|
|
|
|
std::string value = cur.substr(pos + 1);
|
2007-04-04 02:01:17 +02:00
|
|
|
|
|
|
|
// Hand value to all controls matching name
|
2012-11-04 04:53:03 +01:00
|
|
|
for (auto control : controls) {
|
|
|
|
if (control->name == name && control->CanSerialiseValue())
|
|
|
|
control->UnserialiseValue(value);
|
2007-04-04 02:01:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-12-28 22:27:06 +01:00
|
|
|
}
|