Merge pull request #325 from KLayout/issue-318

Issue 318
This commit is contained in:
Matthias Köfferlein 2019-08-18 17:30:25 +02:00 committed by GitHub
commit 0f3e30c046
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 315 additions and 177 deletions

View File

@ -82,26 +82,13 @@
<item>
<widget class="lay::DecoratedLineEdit" name="binding_le"/>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Examples:
<string>Delete text for
&quot;no key bound&quot;.
Key examples:
- &quot;Ctrl+A&quot;
- &quot;Shift+F2&quot;
- &quot;M&quot;

View File

@ -326,76 +326,6 @@ MainConfigPage5::commit (lay::PluginRoot *root)
// ------------------------------------------------------------
// The "key bindings" config page
std::vector<std::pair<std::string, std::string> >
unpack_key_binding (const std::string &packed)
{
tl::Extractor ex (packed.c_str ());
std::vector<std::pair<std::string, std::string> > key_bindings;
while (! ex.at_end ()) {
ex.test(";");
key_bindings.push_back (std::make_pair (std::string (), std::string ()));
ex.read_word_or_quoted (key_bindings.back ().first);
ex.test(":");
ex.read_word_or_quoted (key_bindings.back ().second);
}
return key_bindings;
}
std::string
pack_key_binding (const std::vector<std::pair<std::string, std::string> > &unpacked)
{
std::string packed;
for (std::vector<std::pair<std::string, std::string> >::const_iterator p = unpacked.begin (); p != unpacked.end (); ++p) {
if (! packed.empty ()) {
packed += ";";
}
packed += tl::to_word_or_quoted_string (p->first);
packed += ":";
packed += tl::to_word_or_quoted_string (p->second);
}
return packed;
}
std::vector<std::pair<std::string, bool> >
unpack_menu_items_hidden (const std::string &packed)
{
tl::Extractor ex (packed.c_str ());
std::vector<std::pair<std::string, bool> > hidden;
while (! ex.at_end ()) {
ex.test(";");
hidden.push_back (std::make_pair (std::string (), false));
ex.read_word_or_quoted (hidden.back ().first);
ex.test(":");
ex.read (hidden.back ().second);
}
return hidden;
}
std::string
pack_menu_items_hidden (const std::vector<std::pair<std::string, bool> > &unpacked)
{
std::string packed;
for (std::vector<std::pair<std::string, bool> >::const_iterator p = unpacked.begin (); p != unpacked.end (); ++p) {
if (! packed.empty ()) {
packed += ";";
}
packed += tl::to_word_or_quoted_string (p->first);
packed += ":";
packed += tl::to_string (p->second);
}
return packed;
}
CustomizeMenuConfigPage::CustomizeMenuConfigPage (QWidget *parent)
: lay::ConfigPage (parent), m_enable_event (true)
{
@ -407,6 +337,7 @@ CustomizeMenuConfigPage::CustomizeMenuConfigPage (QWidget *parent)
mp_ui->binding_le->setEnabled (false);
mp_ui->binding_le->set_clear_button_enabled (true);
connect (mp_ui->binding_le, SIGNAL (clear_pressed ()), this, SLOT (text_cleared ()));
connect (mp_ui->binding_le, SIGNAL (textChanged (QString)), this, SLOT (text_changed ()));
mp_ui->filter->set_clear_button_enabled (true);
@ -433,7 +364,7 @@ static void get_shortcuts (const lay::AbstractMenu &menu, const std::string &roo
}
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_shortcut ()));
bindings.insert (std::make_pair (*i, with_defaults ? menu.action (*i).get_default_shortcut () : menu.action (*i).get_effective_shortcut ()));
}
}
}
@ -483,7 +414,8 @@ CustomizeMenuConfigPage::apply (const std::vector<std::pair<std::string, std::st
for (std::map<std::string, std::string>::iterator kb = m_current_bindings.begin (); kb != m_current_bindings.end (); ++kb) {
std::map<std::string, std::string>::iterator bb = b.find (kb->first);
if (bb != b.end ()) {
kb->second = bb->second;
lay::Action a = lay::MainWindow::instance ()->menu ()->action (kb->first);
kb->second = a.get_effective_shortcut_for (bb->second);
} else {
kb->second.clear ();
}
@ -517,13 +449,9 @@ CustomizeMenuConfigPage::apply (const std::vector<std::pair<std::string, std::st
bool hidden = m_hidden_flags[cb->first];
std::map<std::string, std::string>::const_iterator db = default_bindings.find (cb->first);
bool is_default = false;
std::string sc = cb->second;
if (sc.empty () && db != default_bindings.end ()) {
sc = db->second;
is_default = true;
}
bool is_default = (db != default_bindings.end () && db->second == sc);
const std::string &path = cb->first;
@ -599,7 +527,16 @@ CustomizeMenuConfigPage::commit (lay::PluginRoot *root)
for (std::vector<std::pair<std::string, std::string> >::iterator kb = key_bindings.begin (); kb != key_bindings.end (); ++kb) {
std::map<std::string, std::string>::iterator cb = m_current_bindings.find (kb->first);
if (cb != m_current_bindings.end ()) {
kb->second = cb->second;
lay::Action a = lay::MainWindow::instance ()->menu ()->action (kb->first);
if (cb->second != a.get_default_shortcut ()) {
if (cb->second.empty ()) {
kb->second = lay::Action::no_shortcut ();
} else {
kb->second = cb->second;
}
} else {
kb->second.clear ();
}
m_current_bindings.erase (cb);
}
}
@ -631,6 +568,21 @@ CustomizeMenuConfigPage::commit (lay::PluginRoot *root)
root->config_set (cfg_menu_items_hidden, packed_hidden_flags);
}
void
CustomizeMenuConfigPage::text_cleared ()
{
QTreeWidgetItem *item = mp_ui->bindings_list->currentItem ();
if (! item) {
return;
}
std::string path = tl::to_string (item->data (0, Qt::UserRole).toString ());
lay::Action a = lay::MainWindow::instance ()->menu ()->action (path);
// "clear" reverts to default
mp_ui->binding_le->setText (tl::to_qstring (a.get_default_shortcut ()));
}
void
CustomizeMenuConfigPage::text_changed ()
{
@ -673,17 +625,18 @@ CustomizeMenuConfigPage::update_list_item (QTreeWidgetItem *item)
std::string path = tl::to_string (item->data (0, Qt::UserRole).toString ());
std::string shortcut = tl::to_string (mp_ui->binding_le->text ().simplified ());
// normalize string
shortcut = tl::to_string (QKeySequence (tl::to_qstring (shortcut)).toString ());
m_current_bindings[path] = shortcut;
bool is_default = false;
std::string eff_shortcut = shortcut;
if (shortcut.empty ()) {
lay::Action a = lay::MainWindow::instance ()->menu ()->action (path);
eff_shortcut = a.get_default_shortcut ();
is_default = true;
}
item->setData (2, Qt::DisplayRole, tl::to_qstring (eff_shortcut));
lay::Action a = lay::MainWindow::instance ()->menu ()->action (path);
std::string def_shortcut = a.get_default_shortcut ();
is_default = (def_shortcut == shortcut);
item->setData (2, Qt::DisplayRole, tl::to_qstring (shortcut));
item->setData (2, Qt::ForegroundRole, palette ().color (is_default ? QPalette::Disabled : QPalette::Normal, QPalette::Text));
// Set the aliases too
@ -696,7 +649,7 @@ CustomizeMenuConfigPage::update_list_item (QTreeWidgetItem *item)
m_current_bindings[*p] = shortcut;
std::map<std::string, QTreeWidgetItem *>::const_iterator i = m_item_for_path.find (*p);
if (i != m_item_for_path.end ()) {
i->second->setData (2, Qt::DisplayRole, tl::to_qstring (eff_shortcut));
i->second->setData (2, Qt::DisplayRole, tl::to_qstring (shortcut));
i->second->setData (2, Qt::ForegroundRole, palette ().color (is_default ? QPalette::Disabled : QPalette::Normal, QPalette::Text));
}
}

View File

@ -48,27 +48,6 @@ class QAction;
namespace lay
{
/**
* @brief A utility function to convert the packed key binding in the cfg_key_bindings string to a vector
*/
std::vector<std::pair<std::string, std::string> > unpack_key_binding (const std::string &packed);
/**
* @brief A utility function to convert the key binding (as path/shortcut pair vector) to a packed string for cfg_key_bindings
*/
std::string pack_key_binding (const std::vector<std::pair<std::string, std::string> > &unpacked);
/**
* @brief A utility function to convert the packed hidden flags in the cfg_menu_items_hidden string to a vector
*/
std::vector<std::pair<std::string, bool> > unpack_menu_items_hidden (const std::string &packed);
/**
* @brief A utility function to convert the hidde flags (as path/bool pair vector) to a packed string for cfg_menu_items_hidden
*/
std::string pack_menu_items_hidden (const std::vector<std::pair<std::string, bool> > &unpacked);
class ColorButton;
class MainConfigPage
@ -199,6 +178,7 @@ private slots:
void current_changed (QTreeWidgetItem *current, QTreeWidgetItem *previous);
void item_changed (QTreeWidgetItem *, int);
void text_changed ();
void text_cleared ();
void filter_changed ();
void reset_clicked ();

View File

@ -28,7 +28,65 @@
namespace gsi
{
static std::string pack_key_binding (const std::map<std::string, std::string> &kb)
{
std::vector<std::pair<std::string, std::string> > v;
v.insert (v.end (), kb.begin (), kb.end ());
return lay::pack_key_binding (v);
}
static std::map<std::string, std::string> unpack_key_binding (const std::string &s)
{
std::vector<std::pair<std::string, std::string> > v = lay::unpack_key_binding (s);
std::map<std::string, std::string> kb;
kb.insert (v.begin (), v.end ());
return kb;
}
static std::string pack_menu_items_hidden (const std::map<std::string, bool> &kb)
{
std::vector<std::pair<std::string, bool> > v;
v.insert (v.end (), kb.begin (), kb.end ());
return lay::pack_menu_items_hidden (v);
}
static std::map<std::string, bool> unpack_menu_items_hidden (const std::string &s)
{
std::vector<std::pair<std::string, bool> > v = lay::unpack_menu_items_hidden (s);
std::map<std::string, bool> kb;
kb.insert (v.begin (), v.end ());
return kb;
}
Class<lay::AbstractMenu> decl_AbstractMenu ("lay", "AbstractMenu",
method ("pack_key_binding", &pack_key_binding, gsi::arg ("path_to_keys"),
"@brief Serializes a key binding definition into a single string\n"
"The serialized format is used by the 'key-bindings' config key. "
"This method will take an array of path/key definitions (including the \\Action#NoKeyBound option) "
"and convert it to a single string suitable for assigning to the config key.\n"
"\n"
"This method has been introduced in version 0.26."
) +
method ("unpack_key_binding", &unpack_key_binding, gsi::arg ("s"),
"@brief Deserializes a key binding definition\n"
"This method is the reverse of \\pack_key_binding.\n"
"\n"
"This method has been introduced in version 0.26."
) +
method ("pack_menu_items_hidden", &pack_menu_items_hidden, gsi::arg ("path_to_visibility"),
"@brief Serializes a menu item visibility definition into a single string\n"
"The serialized format is used by the 'menu-items-hidden' config key. "
"This method will take an array of path/visibility flag definitions "
"and convert it to a single string suitable for assigning to the config key.\n"
"\n"
"This method has been introduced in version 0.26."
) +
method ("unpack_menu_items_hidden", &unpack_menu_items_hidden, gsi::arg ("s"),
"@brief Deserializes a menu item visibility definition\n"
"This method is the reverse of \\pack_menu_items_hidden.\n"
"\n"
"This method has been introduced in version 0.26."
) +
method ("action", &lay::AbstractMenu::action,
"@brief Get the reference to a Action object associated with the given path\n"
"@args path\n"
@ -157,8 +215,16 @@ Class<lay::Action> decl_ActionBase ("lay", "ActionBase",
method ("shortcut=", (void (lay::Action::*)(const std::string &)) &lay::Action::set_shortcut,
"@brief Sets the keyboard shortcut\n"
"@args shortcut\n"
"If the shortcut string is empty, the default shortcut will be used. If the string "
"is equal to \\Action#NoKeyBound, no keyboard shortcut will be assigned.\n"
"\n"
"@param shortcut The keyboard shortcut (i.e. \"Ctrl+C\")\n"
"@param shortcut The keyboard shortcut in Qt notation (i.e. \"Ctrl+C\")\n"
"\n"
"The NoKeyBound option has been added in version 0.26."
) +
constant ("NoKeyBound", &lay::Action::no_shortcut,
"@brief Gets a shortcut value indicating that no shortcut shall be assigned\n"
"This method has been introduced in version 0.26."
) +
method ("shortcut", &lay::Action::get_shortcut,
"@brief Gets the keyboard shortcut\n"

View File

@ -65,6 +65,79 @@ static const bool s_can_move_menu = true;
#endif
// ---------------------------------------------------------------
// Serialization of key bindings and hidden menu state
std::vector<std::pair<std::string, std::string> >
unpack_key_binding (const std::string &packed)
{
tl::Extractor ex (packed.c_str ());
std::vector<std::pair<std::string, std::string> > key_bindings;
while (! ex.at_end ()) {
ex.test(";");
key_bindings.push_back (std::make_pair (std::string (), std::string ()));
ex.read_word_or_quoted (key_bindings.back ().first);
ex.test(":");
ex.read_word_or_quoted (key_bindings.back ().second);
}
return key_bindings;
}
std::string
pack_key_binding (const std::vector<std::pair<std::string, std::string> > &unpacked)
{
std::string packed;
for (std::vector<std::pair<std::string, std::string> >::const_iterator p = unpacked.begin (); p != unpacked.end (); ++p) {
if (! packed.empty ()) {
packed += ";";
}
packed += tl::to_word_or_quoted_string (p->first);
packed += ":";
packed += tl::to_word_or_quoted_string (p->second);
}
return packed;
}
std::vector<std::pair<std::string, bool> >
unpack_menu_items_hidden (const std::string &packed)
{
tl::Extractor ex (packed.c_str ());
std::vector<std::pair<std::string, bool> > hidden;
while (! ex.at_end ()) {
ex.test(";");
hidden.push_back (std::make_pair (std::string (), false));
ex.read_word_or_quoted (hidden.back ().first);
ex.test(":");
ex.read (hidden.back ().second);
}
return hidden;
}
std::string
pack_menu_items_hidden (const std::vector<std::pair<std::string, bool> > &unpacked)
{
std::string packed;
for (std::vector<std::pair<std::string, bool> >::const_iterator p = unpacked.begin (); p != unpacked.end (); ++p) {
if (! packed.empty ()) {
packed += ";";
}
packed += tl::to_word_or_quoted_string (p->first);
packed += ":";
packed += tl::to_string (p->second);
}
return packed;
}
// ---------------------------------------------------------------
// Helper function to parse a title with potential shortcut and
// icon specification
@ -279,7 +352,8 @@ ActionHandle::ActionHandle (QWidget *parent)
m_ref_count (0),
m_owned (true),
m_visible (true),
m_hidden (false)
m_hidden (false),
m_no_key_sequence (false)
{
if (! sp_actionHandles) {
sp_actionHandles = new std::set<ActionHandle *> ();
@ -296,7 +370,8 @@ ActionHandle::ActionHandle (QAction *action, bool owned)
m_ref_count (0),
m_owned (owned),
m_visible (true),
m_hidden (false)
m_hidden (false),
m_no_key_sequence (false)
{
if (! sp_actionHandles) {
sp_actionHandles = new std::set<ActionHandle *> ();
@ -313,7 +388,8 @@ ActionHandle::ActionHandle (QMenu *menu, bool owned)
m_ref_count (0),
m_owned (owned),
m_visible (true),
m_hidden (false)
m_hidden (false),
m_no_key_sequence (false)
{
if (! sp_actionHandles) {
sp_actionHandles = new std::set<ActionHandle *> ();
@ -390,7 +466,7 @@ ActionHandle::set_visible (bool v)
m_visible = v;
if (mp_action) {
mp_action->setVisible (is_effective_visible ());
mp_action->setShortcut (get_effective_shortcut ());
mp_action->setShortcut (get_key_sequence ());
}
}
}
@ -402,7 +478,7 @@ ActionHandle::set_hidden (bool h)
m_hidden = h;
if (mp_action) {
mp_action->setVisible (is_effective_visible ());
mp_action->setShortcut (get_effective_shortcut ());
mp_action->setShortcut (get_key_sequence ());
}
}
}
@ -426,49 +502,69 @@ ActionHandle::is_effective_visible () const
}
void
ActionHandle::set_default_shortcut (const QKeySequence &sc)
ActionHandle::set_default_shortcut (const std::string &sc)
{
if (m_default_shortcut != sc) {
m_default_shortcut = sc;
m_default_key_sequence = QKeySequence (tl::to_qstring (sc));
if (mp_action) {
mp_action->setShortcut (get_effective_shortcut ());
mp_action->setShortcut (get_key_sequence ());
}
}
}
void
ActionHandle::set_shortcut (const QKeySequence &sc)
ActionHandle::set_shortcut (const std::string &sc)
{
if (m_shortcut != sc) {
m_shortcut = sc;
m_no_key_sequence = (sc == Action::no_shortcut ());
m_key_sequence = m_no_key_sequence ? QKeySequence () : QKeySequence (tl::to_qstring (m_shortcut));
if (mp_action) {
mp_action->setShortcut (get_effective_shortcut ());
mp_action->setShortcut (get_key_sequence ());
}
}
}
const QKeySequence &
std::string
ActionHandle::get_default_shortcut () const
{
return m_default_shortcut;
return tl::to_string (m_default_key_sequence.toString ());
}
const QKeySequence &
std::string
ActionHandle::get_shortcut () const
{
return m_shortcut;
return m_no_key_sequence ? Action::no_shortcut () : tl::to_string (m_key_sequence.toString ());
}
QKeySequence
ActionHandle::get_effective_shortcut () const
ActionHandle::get_key_sequence () const
{
if (m_hidden) {
// A hidden menu item does not have a key sequence too.
return QKeySequence ();
} else if (m_shortcut.isEmpty ()) {
return m_default_shortcut;
} else if (m_no_key_sequence) {
return QKeySequence ();
} else if (m_key_sequence.isEmpty ()) {
return m_default_key_sequence;
} else {
return m_shortcut;
return m_key_sequence;
}
}
QKeySequence
ActionHandle::get_key_sequence_for (const std::string &sc) const
{
if (m_hidden) {
// A hidden menu item does not have a key sequence too.
return QKeySequence ();
} else if (sc.empty ()) {
return m_default_key_sequence;
} else if (sc == Action::no_shortcut ()) {
return QKeySequence ();
} else {
return QKeySequence::fromString (tl::to_qstring (sc));
}
}
@ -485,6 +581,13 @@ Action::Action ()
}
}
const std::string &
Action::no_shortcut ()
{
static const std::string no_shortcut ("none");
return no_shortcut;
}
Action::Action (const std::string &title)
{
mp_handle = AbstractMenu::create_action (title);
@ -587,7 +690,7 @@ Action::get_title () const
}
void
Action::set_shortcut (const QKeySequence &s)
Action::set_shortcut (const std::string &s)
{
if (mp_handle) {
mp_handle->set_shortcut (s);
@ -595,30 +698,28 @@ Action::set_shortcut (const QKeySequence &s)
}
void
Action::set_default_shortcut (const QKeySequence &s)
Action::set_default_shortcut (const std::string &s)
{
if (mp_handle) {
mp_handle->set_default_shortcut (s);
}
}
void
Action::set_shortcut (const std::string &s)
{
set_shortcut (QKeySequence (tl::to_qstring (s)));
}
void
Action::set_default_shortcut (const std::string &s)
{
set_default_shortcut (QKeySequence (tl::to_qstring (s)));
}
std::string
Action::get_effective_shortcut () const
{
if (mp_handle) {
return tl::to_string (mp_handle->get_effective_shortcut ().toString ());
return tl::to_string (mp_handle->get_key_sequence ().toString ());
} else {
return std::string ();
}
}
std::string
Action::get_effective_shortcut_for (const std::string &sc) const
{
if (mp_handle) {
return tl::to_string (mp_handle->get_key_sequence_for (sc).toString ());
} else {
return std::string ();
}
@ -628,7 +729,7 @@ std::string
Action::get_shortcut () const
{
if (mp_handle) {
return tl::to_string (mp_handle->get_shortcut ().toString ());
return mp_handle->get_shortcut ();
} else {
return std::string ();
}
@ -638,7 +739,7 @@ std::string
Action::get_default_shortcut () const
{
if (mp_handle) {
return tl::to_string (mp_handle->get_default_shortcut ().toString ());
return mp_handle->get_default_shortcut ();
} else {
return std::string ();
}
@ -930,7 +1031,7 @@ AbstractMenu::create_action (const std::string &s)
}
if (! shortcut.empty ()) {
ah->set_default_shortcut (QKeySequence (tl::to_qstring (shortcut)));
ah->set_default_shortcut (shortcut);
}
return ah;

View File

@ -55,6 +55,26 @@ class Action;
class AbstractMenu;
class PluginRoot;
/**
* @brief A utility function to convert the packed key binding in the cfg_key_bindings string to a vector
*/
LAYBASIC_PUBLIC std::vector<std::pair<std::string, std::string> > unpack_key_binding (const std::string &packed);
/**
* @brief A utility function to convert the key binding (as path/shortcut pair vector) to a packed string for cfg_key_bindings
*/
LAYBASIC_PUBLIC std::string pack_key_binding (const std::vector<std::pair<std::string, std::string> > &unpacked);
/**
* @brief A utility function to convert the packed hidden flags in the cfg_menu_items_hidden string to a vector
*/
LAYBASIC_PUBLIC std::vector<std::pair<std::string, bool> > unpack_menu_items_hidden (const std::string &packed);
/**
* @brief A utility function to convert the hidde flags (as path/bool pair vector) to a packed string for cfg_menu_items_hidden
*/
LAYBASIC_PUBLIC std::string pack_menu_items_hidden (const std::vector<std::pair<std::string, bool> > &unpacked);
/**
* @brief A helper class that does reference counting for the QAction object
*/
@ -79,11 +99,12 @@ public:
bool is_hidden () const;
bool is_effective_visible () const;
void set_default_shortcut (const QKeySequence &sc);
void set_shortcut (const QKeySequence &sc);
const QKeySequence &get_default_shortcut () const;
const QKeySequence &get_shortcut () const;
QKeySequence get_effective_shortcut () const;
void set_default_shortcut (const std::string &sc);
void set_shortcut (const std::string &sc);
std::string get_default_shortcut () const;
std::string get_shortcut() const;
QKeySequence get_key_sequence () const;
QKeySequence get_key_sequence_for (const std::string &sc) const;
protected slots:
void destroyed (QObject *obj);
@ -95,8 +116,11 @@ private:
bool m_owned;
bool m_visible;
bool m_hidden;
QKeySequence m_default_shortcut;
QKeySequence m_shortcut;
std::string m_default_shortcut;
QKeySequence m_default_key_sequence;
std::string m_shortcut;
QKeySequence m_key_sequence;
bool m_no_key_sequence;
// no copying
ActionHandle (const ActionHandle &);
@ -173,14 +197,14 @@ public:
std::string get_title () const;
/**
* @brief Sets the keyboard shortcut (as a QKeySequence object)
* If no shortcut is set, the default shortcut will be taken.
* @brief Gets the shortcut string for "no shortcut present"
*/
void set_shortcut (const QKeySequence &s);
static const std::string &no_shortcut ();
/**
* @brief Sets the keyboard shortcut
* If no shortcut is set, the default shortcut will be taken.
* If no shortcut is set (empty string), the default shortcut will be taken.
* If the shortcut string is "no_shortcut()", no shortcut will be assigned to the item.
*/
void set_shortcut (const std::string &s);
@ -191,12 +215,6 @@ public:
*/
std::string get_shortcut () const;
/**
* @brief Sets the default keyboard shortcut (as a QKeySequence object)
* This shortcut is used when no specific shortcut is set.
*/
void set_default_shortcut (const QKeySequence &s);
/**
* @brief Sets the default keyboard shortcut
* This shortcut is used when no specific shortcut is set.
@ -215,6 +233,11 @@ public:
*/
std::string get_effective_shortcut () const;
/**
* @brief Gets the effective shortcut for a given key sequence string
*/
std::string get_effective_shortcut_for (const std::string &sc) const;
/**
* @brief "is_checkable" attribute
*/

View File

@ -1100,6 +1100,7 @@ void DecoratedLineEdit::mouseReleaseEvent (QMouseEvent *event)
if (c == mp_clear_label) {
clear ();
emit clear_pressed (); // might modify the text
emit textEdited (text ());
}

View File

@ -439,6 +439,7 @@ signals:
void esc_pressed ();
void tab_pressed ();
void backtab_pressed ();
void clear_pressed ();
protected:
void mousePressEvent (QMouseEvent *event);

View File

@ -59,6 +59,12 @@ class LAYMenuTest_TestClass < TestBase
assert_equal(b.shortcut, "")
assert_equal(b.effective_shortcut, "X")
a.shortcut = RBA::Action::NoKeyBound
assert_equal(a.default_shortcut, "X")
assert_equal(a.shortcut, "none")
assert_equal(a.effective_shortcut, "")
a.shortcut = ""
assert_equal(a.is_visible?, true)
a.hidden = false
@ -319,6 +325,26 @@ RESULT
end
def test_3
map = RBA::AbstractMenu::unpack_key_binding("'path.a':X;'path.b':''")
assert_equal(map["path.a"], "X")
assert_equal(map["path.b"], "")
assert_equal(map["path.c"], nil)
map2 = RBA::AbstractMenu::unpack_key_binding(RBA::AbstractMenu::pack_key_binding(map))
assert_equal(map == map2, true)
map = RBA::AbstractMenu::unpack_menu_items_hidden("'path.a':true;'path.b':false")
assert_equal(map["path.a"], true)
assert_equal(map["path.b"], false)
assert_equal(map["path.c"], nil)
map2 = RBA::AbstractMenu::unpack_menu_items_hidden(RBA::AbstractMenu::pack_menu_items_hidden(map))
assert_equal(map == map2, true)
end
end
load("test_epilogue.rb")