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
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
#include "auto4_lua.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"
|
|
|
|
|
2014-04-26 00:40:43 +02:00
|
|
|
#include <libaegisub/log.h>
|
2014-03-27 03:24:37 +01:00
|
|
|
#include <libaegisub/lua/utils.h>
|
2014-04-26 00:40:43 +02:00
|
|
|
#include <libaegisub/make_unique.h>
|
2013-06-10 15:58:13 +02:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
#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
|
|
|
|
2014-03-27 03:24:37 +01:00
|
|
|
using namespace agi::lua;
|
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
|
2014-03-13 02:39:07 +01:00
|
|
|
class Label final : 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-11-21 18:13:36 +01:00
|
|
|
wxControl *Create(wxWindow *parent) override {
|
2013-01-04 16:01:50 +01:00
|
|
|
return new wxStaticText(parent, -1, to_wx(label));
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
2013-11-21 18:13:36 +01:00
|
|
|
int GetSizerFlags() const override { 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-11-21 18:13:36 +01:00
|
|
|
void LuaReadBack(lua_State *L) override {
|
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;
|
2014-04-28 16:07:07 +02:00
|
|
|
wxTextCtrl *cw = nullptr;
|
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"))
|
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
|
|
|
}
|
|
|
|
|
2013-11-21 18:13:36 +01:00
|
|
|
bool CanSerialiseValue() const override { return true; }
|
|
|
|
std::string SerialiseValue() const override { return inline_string_encode(text); }
|
|
|
|
void UnserialiseValue(const std::string &serialised) override { 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-11-21 18:13:36 +01:00
|
|
|
wxControl *Create(wxWindow *parent) override {
|
2013-01-04 16:01:50 +01:00
|
|
|
cw = new wxTextCtrl(parent, -1, to_wx(text));
|
2014-04-16 17:09:52 +02:00
|
|
|
cw->SetMaxLength(0);
|
2013-01-04 16:01:50 +01:00
|
|
|
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-11-21 18:13:36 +01:00
|
|
|
void LuaReadBack(lua_State *L) override {
|
2013-01-04 16:01:50 +01:00
|
|
|
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
|
2014-03-13 02:39:07 +01:00
|
|
|
class Color final : public LuaDialogControl {
|
2013-06-12 01:32:59 +02:00
|
|
|
agi::Color color;
|
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
|
|
|
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)
|
2013-06-12 01:32:59 +02:00
|
|
|
, color(get_field(L, "value"))
|
2013-01-13 20:20:44 +01:00
|
|
|
, alpha(alpha)
|
2008-03-12 08:04:07 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-11-21 18:13:36 +01:00
|
|
|
bool CanSerialiseValue() const override { return true; }
|
2014-03-02 16:24:06 +01:00
|
|
|
std::string SerialiseValue() const override { return inline_string_encode(color.GetHexFormatted(alpha)); }
|
2013-11-21 18:13:36 +01:00
|
|
|
void UnserialiseValue(const std::string &serialised) override { color = 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-11-21 18:13:36 +01:00
|
|
|
wxControl *Create(wxWindow *parent) override {
|
2013-06-12 01:32:59 +02:00
|
|
|
wxControl *cw = new ColourButton(parent, wxSize(50*width,10*height), alpha, color, ColorValidator(&color));
|
2013-01-04 16:01:50 +01:00
|
|
|
cw->SetToolTip(to_wx(hint));
|
2008-03-12 08:04:07 +01:00
|
|
|
return cw;
|
|
|
|
}
|
|
|
|
|
2013-11-21 18:13:36 +01:00
|
|
|
void LuaReadBack(lua_State *L) override {
|
2014-03-02 16:24:06 +01:00
|
|
|
lua_pushstring(L, color.GetHexFormatted(alpha).c_str());
|
2008-03-12 08:04:07 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
/// A multiline text edit control
|
2014-03-13 02:39:07 +01:00
|
|
|
class Textbox final : public Edit {
|
2006-12-28 22:18:35 +01:00
|
|
|
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-11-21 18:13:36 +01:00
|
|
|
wxControl *Create(wxWindow *parent) override {
|
2013-01-04 16:01:50 +01:00
|
|
|
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
|
2014-03-13 02:39:07 +01:00
|
|
|
class IntEdit final : public Edit {
|
2014-04-28 16:07:07 +02:00
|
|
|
wxSpinCtrl *cw = nullptr;
|
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)
|
|
|
|
, 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-21 18:13:36 +01:00
|
|
|
bool CanSerialiseValue() const override { return true; }
|
|
|
|
std::string SerialiseValue() const override { return std::to_string(value); }
|
|
|
|
void UnserialiseValue(const std::string &serialised) override { 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-11-21 18:13:36 +01:00
|
|
|
wxControl *Create(wxWindow *parent) override {
|
2013-01-04 16:01:50 +01:00
|
|
|
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-11-21 18:13:36 +01:00
|
|
|
void LuaReadBack(lua_State *L) override {
|
2006-12-28 22:18:35 +01:00
|
|
|
lua_pushinteger(L, value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Float only edit
|
2014-03-13 02:39:07 +01:00
|
|
|
class FloatEdit final : 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;
|
2014-04-28 16:07:07 +02:00
|
|
|
wxSpinCtrlDouble *scd = nullptr;
|
2012-03-07 02:30:52 +01:00
|
|
|
|
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))
|
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
|
|
|
}
|
|
|
|
|
2013-11-21 18:13:36 +01:00
|
|
|
bool CanSerialiseValue() const override { return true; }
|
|
|
|
std::string SerialiseValue() const override { return std::to_string(value); }
|
|
|
|
void UnserialiseValue(const std::string &serialised) override { 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-11-21 18:13:36 +01:00
|
|
|
wxControl *Create(wxWindow *parent) override {
|
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);
|
2014-04-28 16:07:07 +02:00
|
|
|
scd->SetValidator(DoubleSpinValidator(&value));
|
2013-01-04 16:01:50 +01:00
|
|
|
scd->SetToolTip(to_wx(hint));
|
2012-02-28 02:23:24 +01:00
|
|
|
return scd;
|
|
|
|
}
|
|
|
|
|
2014-04-28 16:07:07 +02:00
|
|
|
DoubleValidator val(&value, 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-11-21 18:13:36 +01:00
|
|
|
void LuaReadBack(lua_State *L) override {
|
2006-12-28 22:18:35 +01:00
|
|
|
lua_pushnumber(L, value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
/// A dropdown list
|
2014-03-13 02:39:07 +01:00
|
|
|
class Dropdown final : public LuaDialogControl {
|
2013-01-04 16:01:50 +01:00
|
|
|
std::vector<std::string> items;
|
|
|
|
std::string value;
|
2014-04-28 16:07:07 +02:00
|
|
|
wxComboBox *cw = nullptr;
|
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"))
|
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
|
|
|
}
|
|
|
|
|
2013-11-21 18:13:36 +01:00
|
|
|
bool CanSerialiseValue() const override { return true; }
|
|
|
|
std::string SerialiseValue() const override { return inline_string_encode(value); }
|
|
|
|
void UnserialiseValue(const std::string &serialised) override { 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-11-21 18:13:36 +01:00
|
|
|
wxControl *Create(wxWindow *parent) override {
|
2013-01-04 16:01:50 +01:00
|
|
|
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-11-21 18:13:36 +01:00
|
|
|
void LuaReadBack(lua_State *L) override {
|
2013-01-04 16:01:50 +01:00
|
|
|
lua_pushstring(L, value.c_str());
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-03-13 02:39:07 +01:00
|
|
|
class Checkbox final : public LuaDialogControl {
|
2013-01-04 16:01:50 +01:00
|
|
|
std::string label;
|
2006-12-28 22:18:35 +01:00
|
|
|
bool value;
|
2014-04-28 16:07:07 +02:00
|
|
|
wxCheckBox *cw = nullptr;
|
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))
|
2007-04-04 02:01:17 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-11-21 18:13:36 +01:00
|
|
|
bool CanSerialiseValue() const override { return true; }
|
|
|
|
std::string SerialiseValue() const override { return value ? "1" : "0"; }
|
|
|
|
void UnserialiseValue(const std::string &serialised) override { 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-11-21 18:13:36 +01:00
|
|
|
wxControl *Create(wxWindow *parent) override {
|
2013-01-04 16:01:50 +01:00
|
|
|
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-11-21 18:13:36 +01:00
|
|
|
void LuaReadBack(lua_State *L) override {
|
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)
|
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))
|
2014-04-27 16:20:11 +02:00
|
|
|
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 17:33:13 +02:00
|
|
|
lua_pushvalue(L, 1);
|
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))
|
2014-04-27 16:20:11 +02:00
|
|
|
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
|
|
|
|
2013-06-10 15:58:13 +02:00
|
|
|
std::unique_ptr<LuaDialogControl> ctl;
|
2011-09-28 21:49:27 +02:00
|
|
|
|
|
|
|
// Check control class and create relevant control
|
2013-01-04 16:01:50 +01:00
|
|
|
if (controlclass == "label")
|
2014-04-23 22:53:24 +02:00
|
|
|
ctl = agi::make_unique<LuaControl::Label>(L);
|
2013-01-04 16:01:50 +01:00
|
|
|
else if (controlclass == "edit")
|
2014-04-23 22:53:24 +02:00
|
|
|
ctl = agi::make_unique<LuaControl::Edit>(L);
|
2013-01-04 16:01:50 +01:00
|
|
|
else if (controlclass == "intedit")
|
2014-04-23 22:53:24 +02:00
|
|
|
ctl = agi::make_unique<LuaControl::IntEdit>(L);
|
2013-01-04 16:01:50 +01:00
|
|
|
else if (controlclass == "floatedit")
|
2014-04-23 22:53:24 +02:00
|
|
|
ctl = agi::make_unique<LuaControl::FloatEdit>(L);
|
2013-01-04 16:01:50 +01:00
|
|
|
else if (controlclass == "textbox")
|
2014-04-23 22:53:24 +02:00
|
|
|
ctl = agi::make_unique<LuaControl::Textbox>(L);
|
2013-01-04 16:01:50 +01:00
|
|
|
else if (controlclass == "dropdown")
|
2014-04-23 22:53:24 +02:00
|
|
|
ctl = agi::make_unique<LuaControl::Dropdown>(L);
|
2013-01-04 16:01:50 +01:00
|
|
|
else if (controlclass == "checkbox")
|
2014-04-23 22:53:24 +02:00
|
|
|
ctl = agi::make_unique<LuaControl::Checkbox>(L);
|
2013-01-04 16:01:50 +01:00
|
|
|
else if (controlclass == "color")
|
2014-04-23 22:53:24 +02:00
|
|
|
ctl = agi::make_unique<LuaControl::Color>(L, false);
|
2013-01-04 16:01:50 +01:00
|
|
|
else if (controlclass == "coloralpha")
|
2014-04-23 22:53:24 +02:00
|
|
|
ctl = agi::make_unique<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
|
2014-04-23 22:53:24 +02:00
|
|
|
ctl = agi::make_unique<LuaControl::Edit>(L);
|
2013-01-04 16:01:50 +01:00
|
|
|
else
|
2014-04-27 16:20:11 +02:00
|
|
|
error(L, "bad control table entry");
|
2011-09-28 21:49:27 +02:00
|
|
|
|
2013-06-10 15:58:13 +02:00
|
|
|
controls.emplace_back(std::move(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, [&]{
|
2014-04-27 16:20:11 +02:00
|
|
|
buttons.emplace_back(-1, check_string(L, -1));
|
2013-05-27 22:10:05 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (include_buttons && lua_istable(L, 3)) {
|
|
|
|
lua_pushvalue(L, 3);
|
|
|
|
lua_for_each(L, [&]{
|
2014-04-27 16:20:11 +02:00
|
|
|
int id = string_to_wx_id(check_string(L, -2));
|
|
|
|
std::string label = check_string(L, -1);
|
2013-05-27 22:10:05 +02:00
|
|
|
auto btn = boost::find_if(buttons,
|
|
|
|
[&](std::pair<int, std::string>& btn) { return btn.second == label; });
|
|
|
|
if (btn == end(buttons))
|
2014-04-27 16:20:11 +02:00
|
|
|
error(L, "Invalid button for id %s", lua_tostring(L, -2));
|
2013-05-27 22:10:05 +02:00
|
|
|
btn->first = id;
|
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
|
|
|
});
|
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
|
|
|
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);
|
2013-06-10 15:58:13 +02: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);
|
2013-12-12 03:25:13 +01:00
|
|
|
button->Bind(wxEVT_BUTTON, [=](wxCommandEvent &evt) {
|
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
|
|
|
this->button_pushed = button_pushed;
|
2013-05-26 17:36:49 +02:00
|
|
|
dialog->TransferDataFromWindow();
|
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
|
|
|
dialog->EndModal(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (id == wxID_OK || id == wxID_YES || id == wxID_SAVE) {
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2013-08-10 16:46:33 +02:00
|
|
|
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, buttons[i].second));
|
2013-08-02 05:42:01 +02:00
|
|
|
bs->Realize();
|
2013-08-10 16:46:33 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (size_t i = 0; i < buttons.size(); ++i)
|
|
|
|
bs->Add(make_button(buttons[i].first, i, buttons[i].second));
|
|
|
|
}
|
2013-08-02 05:42:01 +02: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 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) {
|
2013-11-09 15:17:40 +01:00
|
|
|
if (button_pushed == -1 || buttons[button_pushed].first == wxID_CANCEL)
|
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_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
|
2014-04-27 15:41:28 +02:00
|
|
|
lua_createtable(L, 0, controls.size());
|
2013-06-10 15:58:13 +02:00
|
|
|
for (auto& control : controls) {
|
2012-11-04 04:53:03 +01:00
|
|
|
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"
|
2013-06-10 15:58:13 +02:00
|
|
|
for (auto& control : controls) {
|
2012-11-04 04:53:03 +01:00
|
|
|
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
|
2013-06-10 15:58:13 +02:00
|
|
|
for (auto& control : controls) {
|
2012-11-04 04:53:03 +01:00
|
|
|
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
|
|
|
}
|