mirror of https://github.com/KLayout/klayout.git
Merge pull request #712 from KLayout/gsi-fixes
Some enhancements to script API
This commit is contained in:
commit
97ed4cf0f2
|
|
@ -80,6 +80,7 @@ struct Callback
|
|||
|
||||
#define _TMPLARGPART
|
||||
#define _FUNCARGLIST
|
||||
#define _COMMA
|
||||
#define _CALLARGLIST
|
||||
#define _CALLARGS
|
||||
#define _SETVALUE
|
||||
|
|
@ -87,6 +88,7 @@ struct Callback
|
|||
#include "gsiCallbackVar.h"
|
||||
|
||||
#undef _SETVALUE
|
||||
#undef _COMMA
|
||||
#undef _CALLARGLIST
|
||||
#undef _CALLARGS
|
||||
#undef _FUNCARGLIST
|
||||
|
|
@ -94,15 +96,17 @@ struct Callback
|
|||
|
||||
// 1 argument
|
||||
|
||||
#define _TMPLARGPART , class A1
|
||||
#define _TMPLARGPART class A1
|
||||
#define _FUNCARGLIST A1
|
||||
#define _CALLARGLIST , A1 a1
|
||||
#define _COMMA ,
|
||||
#define _CALLARGLIST A1 a1
|
||||
#define _CALLARGS a1
|
||||
#define _SETVALUE args.write<A1> (a1); \
|
||||
|
||||
#include "gsiCallbackVar.h"
|
||||
|
||||
#undef _SETVALUE
|
||||
#undef _COMMA
|
||||
#undef _CALLARGS
|
||||
#undef _CALLARGLIST
|
||||
#undef _FUNCARGLIST
|
||||
|
|
@ -110,9 +114,10 @@ struct Callback
|
|||
|
||||
// 2 arguments
|
||||
|
||||
#define _TMPLARGPART , class A1, class A2
|
||||
#define _TMPLARGPART class A1, class A2
|
||||
#define _FUNCARGLIST A1, A2
|
||||
#define _CALLARGLIST , A1 a1, A2 a2
|
||||
#define _COMMA ,
|
||||
#define _CALLARGLIST A1 a1, A2 a2
|
||||
#define _CALLARGS a1, a2
|
||||
#define _SETVALUE args.write<A1> (a1); \
|
||||
args.write<A2> (a2); \
|
||||
|
|
@ -120,6 +125,7 @@ struct Callback
|
|||
#include "gsiCallbackVar.h"
|
||||
|
||||
#undef _SETVALUE
|
||||
#undef _COMMA
|
||||
#undef _CALLARGS
|
||||
#undef _CALLARGLIST
|
||||
#undef _FUNCARGLIST
|
||||
|
|
@ -127,9 +133,10 @@ struct Callback
|
|||
|
||||
// 3 arguments
|
||||
|
||||
#define _TMPLARGPART , class A1, class A2, class A3
|
||||
#define _TMPLARGPART class A1, class A2, class A3
|
||||
#define _FUNCARGLIST A1, A2, A3
|
||||
#define _CALLARGLIST , A1 a1, A2 a2, A3 a3
|
||||
#define _COMMA ,
|
||||
#define _CALLARGLIST A1 a1, A2 a2, A3 a3
|
||||
#define _CALLARGS a1, a2, a3
|
||||
#define _SETVALUE args.write<A1> (a1); \
|
||||
args.write<A2> (a2); \
|
||||
|
|
@ -138,6 +145,7 @@ struct Callback
|
|||
#include "gsiCallbackVar.h"
|
||||
|
||||
#undef _SETVALUE
|
||||
#undef _COMMA
|
||||
#undef _CALLARGS
|
||||
#undef _CALLARGLIST
|
||||
#undef _FUNCARGLIST
|
||||
|
|
@ -145,9 +153,10 @@ struct Callback
|
|||
|
||||
// 4 arguments
|
||||
|
||||
#define _TMPLARGPART , class A1, class A2, class A3, class A4
|
||||
#define _TMPLARGPART class A1, class A2, class A3, class A4
|
||||
#define _FUNCARGLIST A1, A2, A3, A4
|
||||
#define _CALLARGLIST , A1 a1, A2 a2, A3 a3, A4 a4
|
||||
#define _COMMA ,
|
||||
#define _CALLARGLIST A1 a1, A2 a2, A3 a3, A4 a4
|
||||
#define _CALLARGS a1, a2, a3, a4
|
||||
#define _SETVALUE args.write<A1> (a1); \
|
||||
args.write<A2> (a2); \
|
||||
|
|
@ -157,6 +166,7 @@ struct Callback
|
|||
#include "gsiCallbackVar.h"
|
||||
|
||||
#undef _SETVALUE
|
||||
#undef _COMMA
|
||||
#undef _CALLARGS
|
||||
#undef _CALLARGLIST
|
||||
#undef _FUNCARGLIST
|
||||
|
|
@ -164,9 +174,10 @@ struct Callback
|
|||
|
||||
// 5 arguments
|
||||
|
||||
#define _TMPLARGPART , class A1, class A2, class A3, class A4, class A5
|
||||
#define _TMPLARGPART class A1, class A2, class A3, class A4, class A5
|
||||
#define _FUNCARGLIST A1, A2, A3, A4, A5
|
||||
#define _CALLARGLIST , A1 a1, A2 a2, A3 a3, A4 a4, A5 a5
|
||||
#define _COMMA ,
|
||||
#define _CALLARGLIST A1 a1, A2 a2, A3 a3, A4 a4, A5 a5
|
||||
#define _CALLARGS a1, a2, a3, a4, a5
|
||||
#define _SETVALUE args.write<A1> (a1); \
|
||||
args.write<A2> (a2); \
|
||||
|
|
@ -177,6 +188,7 @@ struct Callback
|
|||
#include "gsiCallbackVar.h"
|
||||
|
||||
#undef _SETVALUE
|
||||
#undef _COMMA
|
||||
#undef _CALLARGS
|
||||
#undef _CALLARGLIST
|
||||
#undef _FUNCARGLIST
|
||||
|
|
@ -184,9 +196,10 @@ struct Callback
|
|||
|
||||
// 6 arguments
|
||||
|
||||
#define _TMPLARGPART , class A1, class A2, class A3, class A4, class A5, class A6
|
||||
#define _TMPLARGPART class A1, class A2, class A3, class A4, class A5, class A6
|
||||
#define _FUNCARGLIST A1, A2, A3, A4, A5, A6
|
||||
#define _CALLARGLIST , A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6
|
||||
#define _COMMA ,
|
||||
#define _CALLARGLIST A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6
|
||||
#define _CALLARGS a1, a2, a3, a4, a5, a6
|
||||
#define _SETVALUE args.write<A1> (a1); \
|
||||
args.write<A2> (a2); \
|
||||
|
|
@ -198,6 +211,7 @@ struct Callback
|
|||
#include "gsiCallbackVar.h"
|
||||
|
||||
#undef _SETVALUE
|
||||
#undef _COMMA
|
||||
#undef _CALLARGS
|
||||
#undef _CALLARGLIST
|
||||
#undef _FUNCARGLIST
|
||||
|
|
@ -205,9 +219,10 @@ struct Callback
|
|||
|
||||
// 7 arguments
|
||||
|
||||
#define _TMPLARGPART , class A1, class A2, class A3, class A4, class A5, class A6, class A7
|
||||
#define _TMPLARGPART class A1, class A2, class A3, class A4, class A5, class A6, class A7
|
||||
#define _FUNCARGLIST A1, A2, A3, A4, A5, A6, A7
|
||||
#define _CALLARGLIST , A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7
|
||||
#define _COMMA ,
|
||||
#define _CALLARGLIST A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7
|
||||
#define _CALLARGS a1, a2, a3, a4, a5, a6, a7
|
||||
#define _SETVALUE args.write<A1> (a1); \
|
||||
args.write<A2> (a2); \
|
||||
|
|
@ -220,6 +235,7 @@ struct Callback
|
|||
#include "gsiCallbackVar.h"
|
||||
|
||||
#undef _SETVALUE
|
||||
#undef _COMMA
|
||||
#undef _CALLARGS
|
||||
#undef _CALLARGLIST
|
||||
#undef _FUNCARGLIST
|
||||
|
|
@ -227,9 +243,10 @@ struct Callback
|
|||
|
||||
// 8 arguments
|
||||
|
||||
#define _TMPLARGPART , class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8
|
||||
#define _TMPLARGPART class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8
|
||||
#define _FUNCARGLIST A1, A2, A3, A4, A5, A6, A7, A8
|
||||
#define _CALLARGLIST , A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8
|
||||
#define _COMMA ,
|
||||
#define _CALLARGLIST A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8
|
||||
#define _CALLARGS a1, a2, a3, a4, a5, a6, a7, a8
|
||||
#define _SETVALUE args.write<A1> (a1); \
|
||||
args.write<A2> (a2); \
|
||||
|
|
@ -243,6 +260,7 @@ struct Callback
|
|||
#include "gsiCallbackVar.h"
|
||||
|
||||
#undef _SETVALUE
|
||||
#undef _COMMA
|
||||
#undef _CALLARGS
|
||||
#undef _CALLARGLIST
|
||||
#undef _FUNCARGLIST
|
||||
|
|
|
|||
|
|
@ -30,24 +30,24 @@
|
|||
// _CALLARGLIST ", A1 a1"
|
||||
// _SETVALUE "args.template write<A1> (a1);"
|
||||
|
||||
template <class X _TMPLARGPART>
|
||||
void issue (void (X::*) (_FUNCARGLIST) _CALLARGLIST) const
|
||||
template <class X _COMMA _TMPLARGPART>
|
||||
void issue (void (X::*) (_FUNCARGLIST) _COMMA _CALLARGLIST) const
|
||||
{
|
||||
SerialArgs args (argsize), ret (retsize);
|
||||
_SETVALUE
|
||||
call_int (args, ret);
|
||||
}
|
||||
|
||||
template <class X _TMPLARGPART>
|
||||
void issue (void (X::*) (_FUNCARGLIST) const _CALLARGLIST) const
|
||||
template <class X _COMMA _TMPLARGPART>
|
||||
void issue (void (X::*) (_FUNCARGLIST) const _COMMA _CALLARGLIST) const
|
||||
{
|
||||
SerialArgs args (argsize), ret (retsize);
|
||||
_SETVALUE
|
||||
call_int (args, ret);
|
||||
}
|
||||
|
||||
template <class X, class R _TMPLARGPART>
|
||||
R issue (R (X::*) (_FUNCARGLIST) _CALLARGLIST) const
|
||||
template <class X, class R _COMMA _TMPLARGPART>
|
||||
R issue (R (X::*) (_FUNCARGLIST) _COMMA _CALLARGLIST) const
|
||||
{
|
||||
tl::Heap heap;
|
||||
SerialArgs args (argsize), ret (retsize);
|
||||
|
|
@ -56,8 +56,8 @@ R issue (R (X::*) (_FUNCARGLIST) _CALLARGLIST) const
|
|||
return ret.template read<R> (heap);
|
||||
}
|
||||
|
||||
template <class X, class R _TMPLARGPART>
|
||||
R issue (R (X::*) (_FUNCARGLIST) const _CALLARGLIST) const
|
||||
template <class X, class R _COMMA _TMPLARGPART>
|
||||
R issue (R (X::*) (_FUNCARGLIST) const _COMMA _CALLARGLIST) const
|
||||
{
|
||||
tl::Heap heap;
|
||||
SerialArgs args (argsize), ret (retsize);
|
||||
|
|
@ -66,4 +66,3 @@ R issue (R (X::*) (_FUNCARGLIST) const _CALLARGLIST) const
|
|||
return ret.template read<R> (heap);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
#include "gsiDecl.h"
|
||||
#include "gsiSignals.h"
|
||||
#include "layMainWindow.h"
|
||||
#include "layConfig.h"
|
||||
|
||||
#if defined(HAVE_QTBINDINGS)
|
||||
# include "gsiQtGuiExternals.h"
|
||||
|
|
@ -189,11 +190,266 @@ gsi::Methods cm_method_decl ()
|
|||
// is not the first base class.
|
||||
static lay::AbstractMenu *menu (lay::MainWindow *mw)
|
||||
{
|
||||
return mw->menu ();
|
||||
return mw->dispatcher ()->menu ();
|
||||
}
|
||||
|
||||
static void clear_config (lay::MainWindow *mw)
|
||||
{
|
||||
mw->dispatcher ()->clear_config ();
|
||||
}
|
||||
|
||||
static bool write_config (lay::MainWindow *mw, const std::string &config_file)
|
||||
{
|
||||
return mw->dispatcher ()->write_config (config_file);
|
||||
}
|
||||
|
||||
static bool read_config (lay::MainWindow *mw, const std::string &config_file)
|
||||
{
|
||||
return mw->dispatcher ()->read_config (config_file);
|
||||
}
|
||||
|
||||
static tl::Variant get_config (lay::MainWindow *mw, const std::string &name)
|
||||
{
|
||||
std::string value;
|
||||
if (mw->dispatcher ()->config_get (name, value)) {
|
||||
return tl::Variant (value);
|
||||
} else {
|
||||
return tl::Variant ();
|
||||
}
|
||||
}
|
||||
|
||||
static void set_config (lay::MainWindow *mw, const std::string &name, const std::string &value)
|
||||
{
|
||||
mw->dispatcher ()->config_set (name, value);
|
||||
}
|
||||
|
||||
static std::vector<std::string>
|
||||
get_config_names (lay::MainWindow *mw)
|
||||
{
|
||||
std::vector<std::string> names;
|
||||
mw->dispatcher ()->get_config_names (names);
|
||||
return names;
|
||||
}
|
||||
|
||||
static void
|
||||
config_end (lay::MainWindow *mw)
|
||||
{
|
||||
mw->dispatcher ()->config_end ();
|
||||
}
|
||||
|
||||
static void
|
||||
set_key_bindings (lay::MainWindow *mw, const std::map<std::string, std::string> &bindings)
|
||||
{
|
||||
std::map<std::string, std::string> b = mw->menu ()->get_shortcuts (false);
|
||||
std::map<std::string, std::string> b_def = mw->menu ()->get_shortcuts (true);
|
||||
|
||||
for (std::map<std::string, std::string>::const_iterator i = bindings.begin (); i != bindings.end (); ++i) {
|
||||
b[i->first] = i->second;
|
||||
}
|
||||
|
||||
// cfg_key_bindings needs a special notation: lay::Action::no_shortcut () to force "none" instead of default
|
||||
// and and empty string to restore default.
|
||||
for (std::map<std::string, std::string>::iterator i = b.begin (); i != b.end (); ++i) {
|
||||
std::map<std::string, std::string>::const_iterator j = b_def.find (i->first);
|
||||
if (j != b_def.end ()) {
|
||||
if (i->second != j->second) {
|
||||
if (i->second.empty ()) {
|
||||
i->second = lay::Action::no_shortcut ();
|
||||
}
|
||||
} else {
|
||||
i->second.clear ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::pair<std::string, std::string> > bv (b.begin (), b.end ());
|
||||
mw->dispatcher ()->config_set (lay::cfg_key_bindings, lay::pack_key_binding (bv));
|
||||
}
|
||||
|
||||
static std::map<std::string, std::string>
|
||||
get_key_bindings (lay::MainWindow *mw)
|
||||
{
|
||||
return mw->menu ()->get_shortcuts (false);
|
||||
}
|
||||
|
||||
static std::map<std::string, std::string>
|
||||
get_default_key_bindings (lay::MainWindow *mw)
|
||||
{
|
||||
return mw->menu ()->get_shortcuts (true);
|
||||
}
|
||||
|
||||
|
||||
static std::map<std::string, bool>
|
||||
get_menu_items_hidden (lay::MainWindow *mw)
|
||||
{
|
||||
std::map<std::string, std::string> kb = get_key_bindings (mw);
|
||||
std::map<std::string, bool> h;
|
||||
|
||||
if (mw->dispatcher ()->menu ()) {
|
||||
for (std::map<std::string, std::string>::const_iterator i = kb.begin (); i != kb.end (); ++i) {
|
||||
lay::Action *a = mw->dispatcher ()->menu ()->action (i->first);
|
||||
if (a) {
|
||||
h.insert (std::make_pair (i->first, a->is_hidden ()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
static std::map<std::string, bool>
|
||||
get_default_menu_items_hidden (lay::MainWindow *mw)
|
||||
{
|
||||
std::map<std::string, std::string> kb = get_key_bindings (mw);
|
||||
|
||||
// currently, all menu items are visible by default
|
||||
std::map<std::string, bool> h;
|
||||
for (std::map<std::string, std::string>::const_iterator i = kb.begin (); i != kb.end (); ++i) {
|
||||
h.insert (std::make_pair (i->first, false));
|
||||
}
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
static void
|
||||
set_menu_items_hidden (lay::MainWindow *mw, const std::map<std::string, bool> &hidden)
|
||||
{
|
||||
std::map<std::string, bool> h = get_menu_items_hidden (mw);
|
||||
for (std::map<std::string, bool>::const_iterator i = hidden.begin (); i != hidden.end (); ++i) {
|
||||
h[i->first] = i->second;
|
||||
}
|
||||
|
||||
std::vector<std::pair<std::string, bool> > hv;
|
||||
hv.insert (hv.end (), h.begin (), h.end ());
|
||||
mw->dispatcher ()->config_set (lay::cfg_menu_items_hidden, lay::pack_menu_items_hidden (hv));
|
||||
}
|
||||
|
||||
Class<lay::MainWindow> decl_MainWindow (QT_EXTERNAL_BASE (QMainWindow) "lay", "MainWindow",
|
||||
|
||||
// Dispatcher interface and convenience functions
|
||||
method ("dispatcher", &lay::MainWindow::dispatcher,
|
||||
"@brief Gets the dispatcher interface (the plugin root configuration space)\n"
|
||||
"This method has been introduced in version 0.27."
|
||||
) +
|
||||
method_ext ("clear_config", &clear_config,
|
||||
"@brief Clears the configuration parameters\n"
|
||||
"This method is provided for using MainWindow without an Application object. "
|
||||
"It's a convience method which is equivalent to 'dispatcher().clear_config()'. See \\Dispatcher#clear_config for details.\n"
|
||||
"\n"
|
||||
"This method has been introduced in version 0.27.\n"
|
||||
) +
|
||||
method_ext ("write_config", &write_config, gsi::arg ("file_name"),
|
||||
"@brief Writes configuration to a file\n"
|
||||
"This method is provided for using MainWindow without an Application object. "
|
||||
"It's a convience method which is equivalent to 'dispatcher().write_config(...)'. See \\Dispatcher#write_config for details.\n"
|
||||
"\n"
|
||||
"This method has been introduced in version 0.27.\n"
|
||||
) +
|
||||
method_ext ("read_config", &read_config, gsi::arg ("file_name"),
|
||||
"@brief Reads the configuration from a file\n"
|
||||
"This method is provided for using MainWindow without an Application object. "
|
||||
"It's a convience method which is equivalent to 'dispatcher().read_config(...)'. See \\Dispatcher#read_config for details.\n"
|
||||
"\n"
|
||||
"This method has been introduced in version 0.27.\n"
|
||||
) +
|
||||
method_ext ("get_config", &get_config, gsi::arg ("name"),
|
||||
"@brief Gets the value of a local configuration parameter\n"
|
||||
"This method is provided for using MainWindow without an Application object. "
|
||||
"It's a convience method which is equivalent to 'dispatcher().get_config(...)'. See \\Dispatcher#get_config for details.\n"
|
||||
"\n"
|
||||
"This method has been introduced in version 0.27.\n"
|
||||
) +
|
||||
method_ext ("set_config", &set_config, gsi::arg ("name"), gsi::arg ("value"),
|
||||
"@brief Set a local configuration parameter with the given name to the given value\n"
|
||||
"This method is provided for using MainWindow without an Application object. "
|
||||
"It's a convience method which is equivalent to 'dispatcher().set_config(...)'. See \\Dispatcher#set_config for details.\n"
|
||||
"\n"
|
||||
"This method has been introduced in version 0.27.\n"
|
||||
) +
|
||||
method_ext ("get_config_names", &get_config_names,
|
||||
"@brief Gets the configuration parameter names\n"
|
||||
"This method is provided for using MainWindow without an Application object. "
|
||||
"It's a convience method which is equivalent to 'dispatcher().get_config_names(...)'. See \\Dispatcher#get_config_names for details.\n"
|
||||
"\n"
|
||||
"This method has been introduced in version 0.27.\n"
|
||||
) +
|
||||
method_ext ("commit_config", &config_end,
|
||||
"@brief Commits the configuration settings\n"
|
||||
"This method is provided for using MainWindow without an Application object. "
|
||||
"It's a convience method which is equivalent to 'dispatcher().config_end(...)'. See \\Dispatcher#config_end for details.\n"
|
||||
"\n"
|
||||
"This method has been introduced in version 0.27.\n"
|
||||
) +
|
||||
|
||||
// key binding configuration
|
||||
gsi::method_ext ("get_key_bindings", &get_key_bindings,
|
||||
"@brief Gets the current key bindings\n"
|
||||
"This method returns a hash with the key binding vs. menu item path.\n"
|
||||
"\n"
|
||||
"This method has been introduced in version 0.27.\n"
|
||||
) +
|
||||
gsi::method_ext ("get_default_key_bindings", &get_default_key_bindings,
|
||||
"@brief Gets the default key bindings\n"
|
||||
"This method returns a hash with the default key binding vs. menu item path.\n"
|
||||
"You can use this hash with \\set_key_bindings to reset all key bindings to the default ones.\n"
|
||||
"\n"
|
||||
"This method has been introduced in version 0.27.\n"
|
||||
) +
|
||||
gsi::method_ext ("set_key_bindings", &set_key_bindings, gsi::arg ("bindings"),
|
||||
"@brief Sets key bindings.\n"
|
||||
"Sets the given key bindings. "
|
||||
"Pass a hash listing the key bindings per menu item paths. Key strings follow the usual notation, e.g. 'Ctrl+A', 'Shift+X' or just 'F2'.\n"
|
||||
"Use an empty value to remove a key binding from a menu entry.\n"
|
||||
"\n"
|
||||
"\\get_key_bindings will give you the current key bindings, \\get_default_key_bindings will give you the default ones.\n"
|
||||
"\n"
|
||||
"Examples:\n"
|
||||
"\n"
|
||||
"@code\n"
|
||||
"# reset all key bindings to default:\n"
|
||||
"mw = RBA::MainWindow.instance()\n"
|
||||
"mw.set_key_bindings(mw.get_default_key_bindings())\n"
|
||||
"\n"
|
||||
"# disable key binding for 'copy':\n"
|
||||
"RBA::MainWindow.instance.set_key_bindings({ \"edit_menu.copy\" => \"\" })\n"
|
||||
"\n"
|
||||
"# configure 'copy' to use Shift+K and 'cut' to use Ctrl+K:\n"
|
||||
"RBA::MainWindow.instance.set_key_bindings({ \"edit_menu.copy\" => \"Shift+K\", \"edit_menu.cut\" => \"Ctrl+K\" })\n"
|
||||
"@/code\n"
|
||||
"\n"
|
||||
"This method has been introduced in version 0.27.\n"
|
||||
) +
|
||||
gsi::method_ext ("get_menu_items_hidden", &get_menu_items_hidden,
|
||||
"@brief Gets the flags indicating whether menu items are hidden\n"
|
||||
"This method returns a hash with the hidden flag vs. menu item path.\n"
|
||||
"You can use this hash with \\set_menu_items_hidden.\n"
|
||||
"\n"
|
||||
"This method has been introduced in version 0.27.\n"
|
||||
) +
|
||||
gsi::method_ext ("get_default_menu_items_hidden", &get_default_menu_items_hidden,
|
||||
"@brief Gets the flags indicating whether menu items are hidden by default\n"
|
||||
"You can use this hash with \\set_menu_items_hidden to restore the visibility of all menu items.\n"
|
||||
"\n"
|
||||
"This method has been introduced in version 0.27.\n"
|
||||
) +
|
||||
gsi::method_ext ("set_menu_items_hidden", &set_menu_items_hidden,
|
||||
"@brief sets the flags indicating whether menu items are hidden\n"
|
||||
"This method allows hiding certain menu items. It takes a hash with hidden flags vs. menu item paths. "
|
||||
"\n"
|
||||
"Examples:\n"
|
||||
"\n"
|
||||
"@code\n"
|
||||
"# show all menu items:\n"
|
||||
"mw = RBA::MainWindow.instance()\n"
|
||||
"mw.set_menu_items_hidden(mw.get_default_menu_items_hidden())\n"
|
||||
"\n"
|
||||
"# hide the 'copy' entry from the 'Edit' menu:\n"
|
||||
"RBA::MainWindow.instance().set_menu_items_hidden({ \"edit_menu.copy\" => true })\n"
|
||||
"@/code\n"
|
||||
"\n"
|
||||
"This method has been introduced in version 0.27.\n"
|
||||
) +
|
||||
|
||||
// QMainWindow interface
|
||||
gsi::method_ext ("menu", &menu,
|
||||
"@brief Returns a reference to the abstract menu\n"
|
||||
|
|
@ -510,7 +766,7 @@ Class<lay::MainWindow> decl_MainWindow (QT_EXTERNAL_BASE (QMainWindow) "lay", "M
|
|||
"\n"
|
||||
"This method has been introduced in version 0.26.\n"
|
||||
) +
|
||||
gsi::method ("call_menu", &lay::MainWindow::menu_activated,
|
||||
gsi::method ("call_menu", &lay::MainWindow::menu_activated, gsi::arg ("symbol"),
|
||||
"@brief Calls the menu item with the provided symbol.\n"
|
||||
"To obtain all symbols, use menu_symbols.\n"
|
||||
"\n"
|
||||
|
|
|
|||
|
|
@ -605,7 +605,7 @@ ApplicationBase::init_app ()
|
|||
bool editable_from_config = false;
|
||||
|
||||
{
|
||||
lay::Dispatcher cfg (0);
|
||||
lay::Dispatcher cfg;
|
||||
|
||||
for (std::vector <std::string>::const_iterator c = m_config_files.begin (); c != m_config_files.end (); ++c) {
|
||||
try {
|
||||
|
|
@ -1474,7 +1474,7 @@ GuiApplication::start_recording ()
|
|||
lay::Dispatcher *
|
||||
GuiApplication::dispatcher () const
|
||||
{
|
||||
return mp_mw;
|
||||
return mp_mw->dispatcher ();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -1482,7 +1482,7 @@ GuiApplication::setup ()
|
|||
{
|
||||
tl_assert (mp_mw == 0);
|
||||
|
||||
mp_mw = new lay::MainWindow (this, 0, "main_window", is_undo_enabled ());
|
||||
mp_mw = new lay::MainWindow (this, "main_window", is_undo_enabled ());
|
||||
|
||||
QObject::connect (mp_mw, SIGNAL (closed ()), this, SLOT (quit ()));
|
||||
|
||||
|
|
@ -1579,7 +1579,7 @@ NonGuiApplication::setup ()
|
|||
mp_pr = new lay::ProgressReporter ();
|
||||
mp_pb = new TextProgress (10 /*verbosity level*/);
|
||||
mp_pr->set_progress_bar (mp_pb);
|
||||
mp_dispatcher = new lay::Dispatcher (0);
|
||||
mp_dispatcher = new lay::Dispatcher ();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -356,27 +356,6 @@ CustomizeMenuConfigPage::~CustomizeMenuConfigPage ()
|
|||
mp_ui = 0;
|
||||
}
|
||||
|
||||
static void get_shortcuts (const lay::AbstractMenu &menu, const std::string &root, std::map<std::string, std::string> &bindings, bool with_defaults)
|
||||
{
|
||||
std::vector<std::string> items = menu.items (root);
|
||||
for (std::vector<std::string>::const_iterator i = items.begin (); i != items.end (); ++i) {
|
||||
if (i->size () > 0) {
|
||||
if (menu.is_valid (*i) && menu.action (*i)->is_visible ()) {
|
||||
if (menu.is_menu (*i)) {
|
||||
// a menu must be listed (so it can be hidden), but does not have a shortcut
|
||||
// but we don't include special menus
|
||||
if (i->at (0) != '@') {
|
||||
bindings.insert (std::make_pair (*i, std::string ()));
|
||||
}
|
||||
get_shortcuts (menu, *i, bindings, with_defaults);
|
||||
} else if (! menu.is_separator (*i)) {
|
||||
bindings.insert (std::make_pair (*i, with_defaults ? menu.action (*i)->get_default_shortcut () : menu.action (*i)->get_effective_shortcut ()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CustomizeMenuConfigPage::reset_clicked ()
|
||||
{
|
||||
|
|
@ -405,12 +384,10 @@ CustomizeMenuConfigPage::apply (const std::vector<std::pair<std::string, std::st
|
|||
m_paths_for_action.clear ();
|
||||
|
||||
// get the current bindings
|
||||
m_current_bindings.clear ();
|
||||
get_shortcuts (*mp_dispatcher->menu (), std::string (), m_current_bindings, false);
|
||||
m_current_bindings = mp_dispatcher->menu ()->get_shortcuts (false);
|
||||
|
||||
// get the default bindings
|
||||
std::map<std::string, std::string> default_bindings;
|
||||
get_shortcuts (*mp_dispatcher->menu (), std::string (), default_bindings, true);
|
||||
std::map<std::string, std::string> default_bindings = mp_dispatcher->menu ()->get_shortcuts (true);
|
||||
|
||||
m_enable_event = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -154,9 +154,11 @@ show_dock_widget (QDockWidget *dock_widget, bool visible)
|
|||
|
||||
// -------------------------------------------------------------
|
||||
|
||||
MainWindow::MainWindow (QApplication *app, lay::Plugin *plugin_parent, const char *name, bool undo_enabled)
|
||||
MainWindow::MainWindow (QApplication *app, const char *name, bool undo_enabled)
|
||||
: QMainWindow (0),
|
||||
lay::Dispatcher (plugin_parent, false),
|
||||
tl::Object (),
|
||||
lay::DispatcherDelegate (),
|
||||
m_dispatcher (this),
|
||||
m_text_progress (this, 10 /*verbosity threshold*/),
|
||||
m_mode (std::numeric_limits<unsigned int>::max ()),
|
||||
mp_setup_form (0),
|
||||
|
|
@ -175,6 +177,9 @@ MainWindow::MainWindow (QApplication *app, lay::Plugin *plugin_parent, const cha
|
|||
mp_app (app),
|
||||
m_manager (undo_enabled)
|
||||
{
|
||||
// install us as menu widget parent
|
||||
m_dispatcher.set_menu_parent_widget (this);
|
||||
|
||||
// ensures the deferred method scheduler is present
|
||||
tl::DeferredMethodScheduler::instance ();
|
||||
|
||||
|
|
@ -699,7 +704,7 @@ MainWindow::about_to_exec ()
|
|||
bool f;
|
||||
|
||||
f = false;
|
||||
config_get (cfg_full_hier_new_cell, f);
|
||||
dispatcher ()->config_get (cfg_full_hier_new_cell, f);
|
||||
if (!f) {
|
||||
TipDialog td (this,
|
||||
tl::to_string (QObject::tr ("<html><body>"
|
||||
|
|
@ -737,7 +742,7 @@ MainWindow::about_to_exec ()
|
|||
}
|
||||
|
||||
f = false;
|
||||
config_get (cfg_no_stipple, f);
|
||||
dispatcher ()->config_get (cfg_no_stipple, f);
|
||||
if (f) {
|
||||
TipDialog td (this,
|
||||
tl::to_string (QObject::tr ("Layers are shown without fill because fill has been intentionally turned off. This can be confusing since selecting a stipple does not have an effect in this case.\n\nTo turn this feature off, uncheck \"Show Layers Without Fill\" in the \"View\" menu.")),
|
||||
|
|
@ -749,7 +754,7 @@ MainWindow::about_to_exec ()
|
|||
}
|
||||
|
||||
f = false;
|
||||
config_get (cfg_markers_visible, f);
|
||||
dispatcher ()->config_get (cfg_markers_visible, f);
|
||||
if (! f) {
|
||||
TipDialog td (this,
|
||||
tl::to_string (QObject::tr ("Markers are not visible because they have been turned off.\nYou may not see markers when using the marker browser feature.\n\nTo turn markers on, check \"Show Markers\" in the \"View\" menu.")),
|
||||
|
|
@ -761,7 +766,7 @@ MainWindow::about_to_exec ()
|
|||
}
|
||||
|
||||
f = false;
|
||||
config_get (cfg_hide_empty_layers, f);
|
||||
dispatcher ()->config_get (cfg_hide_empty_layers, f);
|
||||
if (f) {
|
||||
TipDialog td (this,
|
||||
tl::to_string (QObject::tr ("The \"Hide Empty Layers\" feature is enabled. This can be confusing, in particular in edit mode, because layers are not shown although they are actually present.\n\nTo disable this feature, uncheck \"Hide Empty Layers\" in the layer panel's context menu.")),
|
||||
|
|
@ -916,8 +921,6 @@ MainWindow::config_finalize ()
|
|||
bool
|
||||
MainWindow::configure (const std::string &name, const std::string &value)
|
||||
{
|
||||
lay::Dispatcher::configure (name, value);
|
||||
|
||||
if (name == cfg_grid) {
|
||||
|
||||
double g = 0.0;
|
||||
|
|
@ -3337,7 +3340,7 @@ MainWindow::do_create_view ()
|
|||
view->set_synchronous (synchronous ());
|
||||
|
||||
int tl = 0;
|
||||
config_get (cfg_initial_hier_depth, tl);
|
||||
dispatcher ()->config_get (cfg_initial_hier_depth, tl);
|
||||
view->set_hier_levels (std::make_pair (0, tl));
|
||||
|
||||
// select the current mode and select the enabled editables
|
||||
|
|
@ -3399,7 +3402,7 @@ MainWindow::create_or_load_layout (const std::string *filename, const db::LoadLa
|
|||
if (mode == 0) {
|
||||
// reset the hierarchy depth in the "replace" case
|
||||
int tl = 0;
|
||||
config_get (cfg_initial_hier_depth, tl);
|
||||
dispatcher ()->config_get (cfg_initial_hier_depth, tl);
|
||||
vw->set_hier_levels (std::make_pair (0, tl));
|
||||
vw->clear_states ();
|
||||
vw->store_state ();
|
||||
|
|
@ -3552,7 +3555,7 @@ MainWindow::get_hier_levels () const
|
|||
return current_view ()->get_hier_levels ();
|
||||
} else {
|
||||
int tl = 0;
|
||||
config_get (cfg_initial_hier_depth, tl);
|
||||
dispatcher ()->config_get (cfg_initial_hier_depth, tl);
|
||||
return std::make_pair (0, tl);
|
||||
}
|
||||
}
|
||||
|
|
@ -4136,7 +4139,7 @@ MainWindow::plugin_registered (lay::PluginDeclaration *cls)
|
|||
void
|
||||
MainWindow::plugin_removed (lay::PluginDeclaration *cls)
|
||||
{
|
||||
cls->remove_menu_items (this);
|
||||
cls->remove_menu_items (dispatcher ());
|
||||
|
||||
// recreate all plugins except the one that got removed
|
||||
for (std::vector <lay::LayoutView *>::iterator vp = mp_views.begin (); vp != mp_views.end (); ++vp) {
|
||||
|
|
|
|||
|
|
@ -94,7 +94,8 @@ class ProgressWidget;
|
|||
*/
|
||||
class LAY_PUBLIC MainWindow
|
||||
: public QMainWindow,
|
||||
public lay::Dispatcher
|
||||
public tl::Object,
|
||||
public lay::DispatcherDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
|
@ -107,7 +108,7 @@ public:
|
|||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
MainWindow (QApplication *app = 0, lay::Plugin *parent_plugin = 0, const char *name = "main_window", bool undo_enabled = true);
|
||||
MainWindow (QApplication *app = 0, const char *name = "main_window", bool undo_enabled = true);
|
||||
|
||||
/**
|
||||
* @brief Destructor
|
||||
|
|
@ -115,11 +116,11 @@ public:
|
|||
~MainWindow ();
|
||||
|
||||
/**
|
||||
* @brief Implementation of the Dispatcher interface
|
||||
* @brief Gets the dispatcher interface
|
||||
*/
|
||||
QWidget *menu_parent_widget ()
|
||||
lay::Dispatcher *dispatcher () const
|
||||
{
|
||||
return this;
|
||||
return const_cast<lay::Dispatcher *> (&m_dispatcher);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -498,6 +499,14 @@ public:
|
|||
*/
|
||||
void show_macro_editor (const std::string &cat = std::string (), bool add = false);
|
||||
|
||||
/**
|
||||
* @brief Gets the main window's menu
|
||||
*/
|
||||
AbstractMenu *menu ()
|
||||
{
|
||||
return m_dispatcher.menu ();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Handles a generic menu request
|
||||
*/
|
||||
|
|
@ -658,6 +667,8 @@ protected:
|
|||
void do_update_mru_menus ();
|
||||
|
||||
private:
|
||||
lay::Dispatcher m_dispatcher;
|
||||
|
||||
TextProgressDelegate m_text_progress;
|
||||
|
||||
// Main menu
|
||||
|
|
|
|||
|
|
@ -572,8 +572,8 @@ Navigator::showEvent (QShowEvent *)
|
|||
void
|
||||
Navigator::closeEvent (QCloseEvent *)
|
||||
{
|
||||
mp_main_window->config_set (cfg_show_navigator, "false");
|
||||
mp_main_window->config_end ();
|
||||
mp_main_window->dispatcher ()->config_set (cfg_show_navigator, "false");
|
||||
mp_main_window->dispatcher ()->config_end ();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
|
|
@ -127,30 +127,48 @@ public:
|
|||
virtual bool mouse_press_event (const db::DPoint &p, unsigned int buttons, bool prio)
|
||||
{
|
||||
if (f_mouse_press_event.can_issue ()) {
|
||||
return f_mouse_press_event.issue<lay::ViewService, bool, const db::DPoint &, unsigned int, bool> (&lay::ViewService::mouse_press_event, p, buttons, prio);
|
||||
return f_mouse_press_event.issue (&PluginBase::mouse_press_event_noref, p, buttons, prio);
|
||||
} else {
|
||||
return lay::ViewService::mouse_press_event (p, buttons, prio);
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: this version doesn't take a point reference which allows up to store the point
|
||||
bool mouse_press_event_noref (db::DPoint p, unsigned int buttons, bool prio)
|
||||
{
|
||||
return mouse_press_event (p, buttons, prio);
|
||||
}
|
||||
|
||||
virtual bool mouse_click_event (const db::DPoint &p, unsigned int buttons, bool prio)
|
||||
{
|
||||
if (f_mouse_click_event.can_issue ()) {
|
||||
return f_mouse_click_event.issue<lay::ViewService, bool, const db::DPoint &, unsigned int, bool> (&lay::ViewService::mouse_click_event, p, buttons, prio);
|
||||
return f_mouse_click_event.issue (&PluginBase::mouse_click_event_noref, p, buttons, prio);
|
||||
} else {
|
||||
return lay::ViewService::mouse_click_event (p, buttons, prio);
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: this version doesn't take a point reference which allows up to store the point
|
||||
bool mouse_click_event_noref (db::DPoint p, unsigned int buttons, bool prio)
|
||||
{
|
||||
return mouse_click_event (p, buttons, prio);
|
||||
}
|
||||
|
||||
virtual bool mouse_double_click_event (const db::DPoint &p, unsigned int buttons, bool prio)
|
||||
{
|
||||
if (f_mouse_double_click_event.can_issue ()) {
|
||||
return f_mouse_double_click_event.issue<lay::ViewService, bool, const db::DPoint &, unsigned int, bool> (&lay::ViewService::mouse_double_click_event, p, buttons, prio);
|
||||
return f_mouse_double_click_event.issue (&PluginBase::mouse_double_click_event_noref, p, buttons, prio);
|
||||
} else {
|
||||
return lay::ViewService::mouse_double_click_event (p, buttons, prio);
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: this version doesn't take a point reference which allows up to store the point
|
||||
bool mouse_double_click_event_noref (db::DPoint p, unsigned int buttons, bool prio)
|
||||
{
|
||||
return mouse_double_click_event (p, buttons, prio);
|
||||
}
|
||||
|
||||
virtual bool leave_event (bool prio)
|
||||
{
|
||||
if (f_leave_event.can_issue ()) {
|
||||
|
|
@ -172,30 +190,48 @@ public:
|
|||
virtual bool mouse_move_event (const db::DPoint &p, unsigned int buttons, bool prio)
|
||||
{
|
||||
if (f_mouse_move_event.can_issue ()) {
|
||||
return f_mouse_move_event.issue<lay::ViewService, bool, const db::DPoint &, unsigned int, bool> (&lay::ViewService::mouse_move_event, p, buttons, prio);
|
||||
return f_mouse_move_event.issue (&PluginBase::mouse_move_event_noref, p, buttons, prio);
|
||||
} else {
|
||||
return lay::ViewService::mouse_move_event (p, buttons, prio);
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: this version doesn't take a point reference which allows up to store the point
|
||||
bool mouse_move_event_noref (db::DPoint p, unsigned int buttons, bool prio)
|
||||
{
|
||||
return mouse_move_event (p, buttons, prio);
|
||||
}
|
||||
|
||||
virtual bool mouse_release_event (const db::DPoint &p, unsigned int buttons, bool prio)
|
||||
{
|
||||
if (f_mouse_release_event.can_issue ()) {
|
||||
return f_mouse_release_event.issue<lay::ViewService, bool, const db::DPoint &, unsigned int, bool> (&lay::ViewService::mouse_release_event, p, buttons, prio);
|
||||
return f_mouse_release_event.issue (&PluginBase::mouse_release_event_noref, p, buttons, prio);
|
||||
} else {
|
||||
return lay::ViewService::mouse_release_event (p, buttons, prio);
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: this version doesn't take a point reference which allows up to store the point
|
||||
bool mouse_release_event_noref (db::DPoint p, unsigned int buttons, bool prio)
|
||||
{
|
||||
return mouse_release_event (p, buttons, prio);
|
||||
}
|
||||
|
||||
virtual bool wheel_event (int delta, bool horizontal, const db::DPoint &p, unsigned int buttons, bool prio)
|
||||
{
|
||||
if (f_wheel_event.can_issue ()) {
|
||||
return f_wheel_event.issue<lay::ViewService, bool, int, bool, const db::DPoint &, unsigned int, bool> (&lay::ViewService::wheel_event, delta, horizontal, p, buttons, prio);
|
||||
return f_wheel_event.issue (&PluginBase::wheel_event_noref, delta, horizontal, p, buttons, prio);
|
||||
} else {
|
||||
return lay::ViewService::wheel_event (delta, horizontal, p, buttons, prio);
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: this version doesn't take a point reference which allows up to store the point
|
||||
bool wheel_event_noref (int delta, bool horizontal, db::DPoint p, unsigned int buttons, bool prio)
|
||||
{
|
||||
return wheel_event (delta, horizontal, p, buttons, prio);
|
||||
}
|
||||
|
||||
virtual void activated ()
|
||||
{
|
||||
if (f_activated.can_issue ()) {
|
||||
|
|
@ -693,7 +729,7 @@ Class<gsi::PluginBase> decl_Plugin ("lay", "Plugin",
|
|||
"@param buttons A combination of the constants in the \\ButtonState class which codes both the mouse buttons and the key modifiers (.e. ShiftButton etc).\n"
|
||||
"@return True to terminate dispatcher\n"
|
||||
) +
|
||||
callback ("mouse_button_pressed_event", &gsi::PluginBase::mouse_press_event, &gsi::PluginBase::f_mouse_press_event, gsi::arg ("p"), gsi::arg ("buttons"), gsi::arg ("prio"),
|
||||
callback ("mouse_button_pressed_event", &gsi::PluginBase::mouse_press_event_noref, &gsi::PluginBase::f_mouse_press_event, gsi::arg ("p"), gsi::arg ("buttons"), gsi::arg ("prio"),
|
||||
"@brief Handles the mouse button pressed event\n"
|
||||
"This method will called by the view when a button is pressed on the mouse.\n"
|
||||
"\n"
|
||||
|
|
@ -715,11 +751,11 @@ Class<gsi::PluginBase> decl_Plugin ("lay", "Plugin",
|
|||
"@param buttons A combination of the constants in the \\ButtonState class which codes both the mouse buttons and the key modifiers (.e. LeftButton, ShiftButton etc).\n"
|
||||
"@return True to terminate dispatcher\n"
|
||||
) +
|
||||
callback ("mouse_click_event", &gsi::PluginBase::mouse_click_event, &gsi::PluginBase::f_mouse_click_event, gsi::arg ("p"), gsi::arg ("buttons"), gsi::arg ("prio"),
|
||||
callback ("mouse_click_event", &gsi::PluginBase::mouse_click_event_noref, &gsi::PluginBase::f_mouse_click_event, gsi::arg ("p"), gsi::arg ("buttons"), gsi::arg ("prio"),
|
||||
"@brief Handles the mouse button click event (after the button has been released)\n"
|
||||
"The behaviour of this callback is the same than for \\mouse_press_event, except that it is called when the mouse button has been released without moving it.\n"
|
||||
) +
|
||||
callback ("mouse_double_click_event", &gsi::PluginBase::mouse_double_click_event, &gsi::PluginBase::f_mouse_double_click_event, gsi::arg ("p"), gsi::arg ("buttons"), gsi::arg ("prio"),
|
||||
callback ("mouse_double_click_event", &gsi::PluginBase::mouse_double_click_event_noref, &gsi::PluginBase::f_mouse_double_click_event, gsi::arg ("p"), gsi::arg ("buttons"), gsi::arg ("prio"),
|
||||
"@brief Handles the mouse button double-click event\n"
|
||||
"The behaviour of this callback is the same than for \\mouse_press_event, except that it is called when the mouse button has been double-clicked.\n"
|
||||
) +
|
||||
|
|
@ -733,15 +769,15 @@ Class<gsi::PluginBase> decl_Plugin ("lay", "Plugin",
|
|||
"The behaviour of this callback is the same than for \\mouse_press_event, except that it is called when the mouse enters the canvas area.\n"
|
||||
"This method does not have a position nor button flags.\n"
|
||||
) +
|
||||
callback ("mouse_moved_event", &gsi::PluginBase::mouse_move_event, &gsi::PluginBase::f_mouse_move_event, gsi::arg ("p"), gsi::arg ("buttons"), gsi::arg ("prio"),
|
||||
callback ("mouse_moved_event", &gsi::PluginBase::mouse_move_event_noref, &gsi::PluginBase::f_mouse_move_event, gsi::arg ("p"), gsi::arg ("buttons"), gsi::arg ("prio"),
|
||||
"@brief Handles the mouse move event\n"
|
||||
"The behaviour of this callback is the same than for \\mouse_press_event, except that it is called when the mouse is moved in the canvas area.\n"
|
||||
) +
|
||||
callback ("mouse_button_released_event", &gsi::PluginBase::mouse_release_event, &gsi::PluginBase::f_mouse_release_event, gsi::arg ("p"), gsi::arg ("buttons"), gsi::arg ("prio"),
|
||||
callback ("mouse_button_released_event", &gsi::PluginBase::mouse_release_event_noref, &gsi::PluginBase::f_mouse_release_event, gsi::arg ("p"), gsi::arg ("buttons"), gsi::arg ("prio"),
|
||||
"@brief Handles the mouse button release event\n"
|
||||
"The behaviour of this callback is the same than for \\mouse_press_event, except that it is called when the mouse button is released.\n"
|
||||
) +
|
||||
callback ("wheel_event", &gsi::PluginBase::wheel_event, &gsi::PluginBase::f_wheel_event, gsi::arg ("delta"), gsi::arg ("horizontal"), gsi::arg ("p"), gsi::arg ("buttons"), gsi::arg ("prio"),
|
||||
callback ("wheel_event", &gsi::PluginBase::wheel_event_noref, &gsi::PluginBase::f_wheel_event, gsi::arg ("delta"), gsi::arg ("horizontal"), gsi::arg ("p"), gsi::arg ("buttons"), gsi::arg ("prio"),
|
||||
"The behaviour of this callback is the same than for \\mouse_press_event, except that it is called when the mouse wheel is rotated.\n"
|
||||
"Additional parameters for this event are 'delta' (the rotation angle in units of 1/8th degree) and 'horizontal' which is true when the horizontal wheel was rotated and "
|
||||
"false if the vertical wheel was rotated.\n"
|
||||
|
|
|
|||
|
|
@ -1677,4 +1677,26 @@ AbstractMenu::collect_configure_actions (std::vector<lay::ConfigureAction *> &ca
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
AbstractMenu::get_shortcuts (const std::string &root, std::map<std::string, std::string> &bindings, bool with_defaults)
|
||||
{
|
||||
std::vector<std::string> items = this->items (root);
|
||||
for (std::vector<std::string>::const_iterator i = items.begin (); i != items.end (); ++i) {
|
||||
if (i->size () > 0) {
|
||||
if (is_valid (*i) && action (*i)->is_visible ()) {
|
||||
if (is_menu (*i)) {
|
||||
// a menu must be listed (so it can be hidden), but does not have a shortcut
|
||||
// but we don't include special menus
|
||||
if (i->at (0) != '@') {
|
||||
bindings.insert (std::make_pair (*i, std::string ()));
|
||||
}
|
||||
get_shortcuts (*i, bindings, with_defaults);
|
||||
} else if (! is_separator (*i)) {
|
||||
bindings.insert (std::make_pair (*i, with_defaults ? action (*i)->get_default_shortcut () : action (*i)->get_effective_shortcut ()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -773,6 +773,18 @@ public:
|
|||
*/
|
||||
QActionGroup *make_exclusive_group (const std::string &name);
|
||||
|
||||
/**
|
||||
* @brief Gets the keyboard shortcuts
|
||||
* @param with_defaults Returns the default shortcuts if true. Otherwise returns the effective shortcut.
|
||||
* @return a hash with menu paths for keys and key binding for values
|
||||
*/
|
||||
std::map<std::string, std::string> get_shortcuts (bool with_defaults)
|
||||
{
|
||||
std::map<std::string, std::string> b;
|
||||
get_shortcuts (std::string (), b, with_defaults);
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the root node of the menu
|
||||
*/
|
||||
|
|
@ -798,6 +810,7 @@ private:
|
|||
void collect_group (std::vector<std::string> &grp, const std::string &name, const AbstractMenuItem &item) const;
|
||||
void collect_configure_actions (std::vector<ConfigureAction *> &ca, AbstractMenuItem &item);
|
||||
void emit_changed ();
|
||||
void get_shortcuts (const std::string &root, std::map<std::string, std::string> &bindings, bool with_defaults);
|
||||
|
||||
Dispatcher *mp_dispatcher;
|
||||
AbstractMenuItem m_root;
|
||||
|
|
|
|||
|
|
@ -36,13 +36,26 @@ static Dispatcher *ms_dispatcher_instance = 0;
|
|||
|
||||
Dispatcher::Dispatcher (Plugin *parent, bool standalone)
|
||||
: Plugin (parent, standalone),
|
||||
m_menu (this)
|
||||
m_menu (this),
|
||||
mp_menu_parent_widget (0),
|
||||
mp_delegate (0)
|
||||
{
|
||||
if (! parent && ! ms_dispatcher_instance) {
|
||||
ms_dispatcher_instance = this;
|
||||
}
|
||||
}
|
||||
|
||||
Dispatcher::Dispatcher (DispatcherDelegate *delegate, Plugin *parent, bool standalone)
|
||||
: Plugin (parent, standalone),
|
||||
m_menu (this),
|
||||
mp_menu_parent_widget (0),
|
||||
mp_delegate (delegate)
|
||||
{
|
||||
if (! ms_dispatcher_instance) {
|
||||
ms_dispatcher_instance = this;
|
||||
}
|
||||
}
|
||||
|
||||
Dispatcher::~Dispatcher ()
|
||||
{
|
||||
if (ms_dispatcher_instance == this) {
|
||||
|
|
@ -57,9 +70,23 @@ Dispatcher::configure (const std::string &name, const std::string &value)
|
|||
for (std::vector<lay::ConfigureAction *>::const_iterator a = ca.begin (); a != ca.end (); ++a) {
|
||||
(*a)->configure (value);
|
||||
}
|
||||
return false;
|
||||
|
||||
if (mp_delegate) {
|
||||
return mp_delegate->configure (name, value);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Dispatcher::config_finalize ()
|
||||
{
|
||||
if (mp_delegate) {
|
||||
return mp_delegate->config_finalize ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Writing and Reading of configuration
|
||||
|
||||
struct ConfigGetAdaptor
|
||||
|
|
|
|||
|
|
@ -41,11 +41,69 @@ class AbstractMenu;
|
|||
class Action;
|
||||
class ConfigureAction;
|
||||
|
||||
/**
|
||||
* @brief A delegate by which the dispatcher can submit notification events
|
||||
*/
|
||||
class LAYBASIC_PUBLIC DispatcherDelegate
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Notifies the plugin root that a new plugin class has been registered
|
||||
*
|
||||
* This method is called when a plugin is loaded dynamically during runtime.
|
||||
*/
|
||||
virtual void plugin_registered (lay::PluginDeclaration * /*cls*/)
|
||||
{
|
||||
// .. this implementation does nothing ..
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Notifies the plugin root that a plugin class is about to be removed
|
||||
*/
|
||||
virtual void plugin_removed (lay::PluginDeclaration * /*cls*/)
|
||||
{
|
||||
// .. this implementation does nothing ..
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Selects the given mode
|
||||
*
|
||||
* The implementation is supposed to select the given mode on all related plugins.
|
||||
*/
|
||||
virtual void select_mode (int /*mode*/)
|
||||
{
|
||||
// .. this implementation does nothing ..
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Menu command handler
|
||||
*/
|
||||
virtual void menu_activated (const std::string & /*symbol*/)
|
||||
{
|
||||
// .. this implementation does nothing ..
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Receives configuration events
|
||||
*/
|
||||
virtual bool configure (const std::string & /*name*/, const std::string & /*value*/)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configuration finalization
|
||||
*/
|
||||
virtual void config_finalize ()
|
||||
{
|
||||
// .. the default implementation does nothing ..
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The central menu event and configuration dispatcher class
|
||||
*
|
||||
* This class acts as the top level dispatcher for plugin events and the menu configuration.
|
||||
*
|
||||
*/
|
||||
class LAYBASIC_PUBLIC Dispatcher
|
||||
: public Plugin
|
||||
|
|
@ -57,7 +115,14 @@ public:
|
|||
* @param parent Usually 0, but a dispatcher may have parents. In this case, the dispatcher is not the actual dispatcher, but the real plugin chain's root is.
|
||||
* @param standalone The standalone flag passed to the plugin constructor.
|
||||
*/
|
||||
Dispatcher (Plugin *parent, bool standalone = false);
|
||||
Dispatcher (Plugin *parent = 0, bool standalone = false);
|
||||
|
||||
/**
|
||||
* @brief The root constructor
|
||||
*
|
||||
* @param delegate The notification receiver for dispatcher events
|
||||
*/
|
||||
Dispatcher (DispatcherDelegate *delegate, Plugin *parent = 0, bool standalone = false);
|
||||
|
||||
/**
|
||||
* @brief Destructor
|
||||
|
|
@ -95,29 +160,65 @@ public:
|
|||
*
|
||||
* This method is called when a plugin is loaded dynamically during runtime.
|
||||
*/
|
||||
virtual void plugin_registered (lay::PluginDeclaration * /*cls*/) { }
|
||||
virtual void plugin_registered (lay::PluginDeclaration *cls)
|
||||
{
|
||||
if (mp_delegate) {
|
||||
mp_delegate->plugin_registered (cls);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Notifies the plugin root that a plugin class is about to be removed
|
||||
*/
|
||||
virtual void plugin_removed (lay::PluginDeclaration * /*cls*/) { }
|
||||
virtual void plugin_removed (lay::PluginDeclaration *cls)
|
||||
{
|
||||
if (mp_delegate) {
|
||||
mp_delegate->plugin_registered (cls);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Selects the given mode
|
||||
*
|
||||
* The implementation is supposed to select the given mode on all related plugins.
|
||||
*/
|
||||
virtual void select_mode (int /*mode*/) { }
|
||||
virtual void select_mode (int mode)
|
||||
{
|
||||
if (mp_delegate) {
|
||||
mp_delegate->select_mode (mode);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called, when a menu item is selected
|
||||
*/
|
||||
virtual void menu_activated (const std::string &symbol)
|
||||
{
|
||||
if (mp_delegate) {
|
||||
mp_delegate->menu_activated (symbol);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the parent widget
|
||||
*/
|
||||
virtual QWidget *menu_parent_widget () { return 0; }
|
||||
QWidget *menu_parent_widget ()
|
||||
{
|
||||
return mp_menu_parent_widget;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the parent widget
|
||||
*/
|
||||
void set_menu_parent_widget (QWidget *w)
|
||||
{
|
||||
mp_menu_parent_widget = w;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns true, if the dispatcher supplies a user interface
|
||||
*/
|
||||
virtual bool has_ui () { return menu_parent_widget () != 0; }
|
||||
bool has_ui () { return menu_parent_widget () != 0; }
|
||||
|
||||
/**
|
||||
* @brief Gets the AbstractMenu object
|
||||
|
|
@ -132,12 +233,15 @@ public:
|
|||
protected:
|
||||
// capture the configuration events so we can change the value of the configuration actions
|
||||
virtual bool configure (const std::string &name, const std::string &value);
|
||||
virtual void config_finalize ();
|
||||
|
||||
private:
|
||||
Dispatcher (const Dispatcher &);
|
||||
Dispatcher &operator= (const Dispatcher &);
|
||||
|
||||
lay::AbstractMenu m_menu;
|
||||
QWidget *mp_menu_parent_widget;
|
||||
DispatcherDelegate *mp_delegate;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -261,6 +261,7 @@ LayoutView::LayoutView (db::Manager *manager, bool editable, lay::Plugin *plugin
|
|||
{
|
||||
// either it's us or the parent has a dispatcher
|
||||
tl_assert (dispatcher () != 0);
|
||||
set_menu_parent_widget (this);
|
||||
|
||||
// ensures the deferred method scheduler is present
|
||||
tl::DeferredMethodScheduler::instance ();
|
||||
|
|
@ -712,11 +713,6 @@ LayoutView::~LayoutView ()
|
|||
mp_bookmarks_view = 0;
|
||||
}
|
||||
|
||||
QWidget *LayoutView::menu_parent_widget ()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
lay::EditorOptionsPages *LayoutView::editor_options_pages ()
|
||||
{
|
||||
if (! mp_editor_options_frame) {
|
||||
|
|
|
|||
|
|
@ -2917,9 +2917,6 @@ private:
|
|||
|
||||
std::list<lay::CellView>::iterator cellview_iter (int cv_index);
|
||||
std::list<lay::CellView>::const_iterator cellview_iter (int cv_index) const;
|
||||
|
||||
// implementation of Dispatcher
|
||||
virtual QWidget *menu_parent_widget ();
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -383,6 +383,42 @@ RESULT
|
|||
|
||||
end
|
||||
|
||||
def test_6
|
||||
|
||||
app = RBA::Application.instance
|
||||
mw = app.main_window
|
||||
|
||||
assert_equal(mw.get_key_bindings["file_menu.exit"], "Ctrl+Q")
|
||||
|
||||
# key bindings
|
||||
|
||||
mw.set_key_bindings({"file_menu.exit" => "F2"})
|
||||
assert_equal(mw.get_key_bindings["file_menu.exit"], "F2")
|
||||
|
||||
mw.set_key_bindings({"file_menu.exit" => ""})
|
||||
assert_equal(mw.get_key_bindings["file_menu.exit"], "")
|
||||
|
||||
mw.set_key_bindings(mw.get_default_key_bindings)
|
||||
assert_equal(mw.get_key_bindings["file_menu.exit"], "Ctrl+Q")
|
||||
|
||||
mw.set_key_bindings({"file_menu.exit" => ""})
|
||||
assert_equal(mw.get_key_bindings["file_menu.exit"], "")
|
||||
|
||||
# menu items hidden
|
||||
|
||||
assert_equal(mw.get_menu_items_hidden["file_menu.exit"], false)
|
||||
|
||||
mw.set_menu_items_hidden({"file_menu.exit" => true})
|
||||
assert_equal(mw.get_menu_items_hidden["file_menu.exit"], true)
|
||||
|
||||
mw.set_menu_items_hidden(mw.get_default_menu_items_hidden)
|
||||
assert_equal(mw.get_menu_items_hidden["file_menu.exit"], false)
|
||||
|
||||
mw.set_menu_items_hidden({"file_menu.exit" => true})
|
||||
assert_equal(mw.get_menu_items_hidden["file_menu.exit"], true)
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
load("test_epilogue.rb")
|
||||
|
|
|
|||
Loading…
Reference in New Issue