diff options
| author | Alexander Valavanis <valavanisalex@gmail.com> | 2019-01-27 11:53:05 +0000 |
|---|---|---|
| committer | Alexander Valavanis <valavanisalex@gmail.com> | 2019-01-27 11:53:05 +0000 |
| commit | cdb5052c77519ed176427244a41873b59733a4f9 (patch) | |
| tree | 8a37822b205b3297f3824239d0d0b259ac81aad4 /src | |
| parent | Merge branch 'master' of gitlab.com:inkscape/inkscape (diff) | |
| download | inkscape-cdb5052c77519ed176427244a41873b59733a4f9.tar.gz inkscape-cdb5052c77519ed176427244a41873b59733a4f9.zip | |
Toolbars: Fix alt+x focus switching
Diffstat (limited to 'src')
| -rw-r--r-- | src/ui/toolbar/rect-toolbar.cpp | 2 | ||||
| -rw-r--r-- | src/ui/tools/rect-tool.cpp | 2 | ||||
| -rw-r--r-- | src/ui/tools/select-tool.cpp | 2 | ||||
| -rw-r--r-- | src/ui/widget/spin-button-tool-item.cpp | 10 | ||||
| -rw-r--r-- | src/ui/widget/spin-button-tool-item.h | 1 | ||||
| -rw-r--r-- | src/widgets/desktop-widget.cpp | 13 | ||||
| -rw-r--r-- | src/widgets/spw-utilities.cpp | 36 | ||||
| -rw-r--r-- | src/widgets/spw-utilities.h | 2 |
8 files changed, 61 insertions, 7 deletions
diff --git a/src/ui/toolbar/rect-toolbar.cpp b/src/ui/toolbar/rect-toolbar.cpp index 7841f182e..e4caae189 100644 --- a/src/ui/toolbar/rect-toolbar.cpp +++ b/src/ui/toolbar/rect-toolbar.cpp @@ -109,7 +109,6 @@ RectToolbar::RectToolbar(SPDesktop *desktop) // holder->_width_action = create_adjustment_action( "RectWidthAction", // _("Width"), _("W:"), - // TRUE, "altx-rect", // labels, values, G_N_ELEMENTS(labels), } @@ -132,7 +131,6 @@ RectToolbar::RectToolbar(SPDesktop *desktop) _height_item->set_sensitive(false); // holder->_height_action = create_adjustment_action( "RectHeightAction", - // FALSE, nullptr, // labels, values, G_N_ELEMENTS(labels), } diff --git a/src/ui/tools/rect-tool.cpp b/src/ui/tools/rect-tool.cpp index 4000e4924..fdb7bace9 100644 --- a/src/ui/tools/rect-tool.cpp +++ b/src/ui/tools/rect-tool.cpp @@ -283,7 +283,7 @@ bool RectTool::root_handler(GdkEvent* event) { case GDK_KEY_x: case GDK_KEY_X: if (MOD__ALT_ONLY(event)) { - desktop->setToolboxFocusTo ("altx-rect"); + desktop->setToolboxFocusTo("rect-width"); ret = TRUE; } break; diff --git a/src/ui/tools/select-tool.cpp b/src/ui/tools/select-tool.cpp index a630f06a7..01ede4b6d 100644 --- a/src/ui/tools/select-tool.cpp +++ b/src/ui/tools/select-tool.cpp @@ -1032,7 +1032,7 @@ bool SelectTool::root_handler(GdkEvent* event) { case GDK_KEY_x: case GDK_KEY_X: if (MOD__ALT_ONLY(event)) { - desktop->setToolboxFocusTo ("altx"); + desktop->setToolboxFocusTo ("select-x"); ret = TRUE; } break; diff --git a/src/ui/widget/spin-button-tool-item.cpp b/src/ui/widget/spin-button-tool-item.cpp index 2276b161d..cb6767445 100644 --- a/src/ui/widget/spin-button-tool-item.cpp +++ b/src/ui/widget/spin-button-tool-item.cpp @@ -354,6 +354,7 @@ SpinButtonToolItem::SpinButtonToolItem(const Glib::ustring name, { set_margin_start(3); set_margin_end(3); + set_name(_name); // Handle button events auto btn_focus_in_event_cb = sigc::mem_fun(*this, &SpinButtonToolItem::on_btn_focus_in_event); @@ -380,6 +381,15 @@ SpinButtonToolItem::SpinButtonToolItem(const Glib::ustring name, } /** + * \brief Transfers focus to the child spinbutton by default + */ +void +SpinButtonToolItem::on_grab_focus() +{ + grab_button_focus(); +} + +/** * \brief Set the tooltip to display on this (and all child widgets) * * \param[in] text The tooltip to display diff --git a/src/ui/widget/spin-button-tool-item.h b/src/ui/widget/spin-button-tool-item.h index cc48e453b..2df2024d3 100644 --- a/src/ui/widget/spin-button-tool-item.h +++ b/src/ui/widget/spin-button-tool-item.h @@ -49,6 +49,7 @@ private: protected: bool on_create_menu_proxy() override; + void on_grab_focus() override; public: SpinButtonToolItem(const Glib::ustring name, diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index 9db8b2af4..aa29294f5 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -1515,10 +1515,17 @@ void SPDesktopWidget::layoutWidgets() void SPDesktopWidget::setToolboxFocusTo (const gchar* label) { - gpointer hb = sp_search_by_data_recursive(aux_toolbox, (gpointer) label); - if (hb && GTK_IS_WIDGET(hb)) + // First try looking for a named widget + auto hb = sp_search_by_name_recursive(Glib::wrap(aux_toolbox), label); + + // Fallback to looking for a named data member (deprecated) + if (!hb) { + hb = Glib::wrap(GTK_WIDGET(sp_search_by_data_recursive(aux_toolbox, (gpointer) label))); + } + + if (hb) { - gtk_widget_grab_focus(GTK_WIDGET(hb)); + hb->grab_focus(); } } diff --git a/src/widgets/spw-utilities.cpp b/src/widgets/spw-utilities.cpp index 5b2a5d778..f0fd21c2b 100644 --- a/src/widgets/spw-utilities.cpp +++ b/src/widgets/spw-utilities.cpp @@ -144,6 +144,42 @@ gpointer sp_search_by_data_recursive(GtkWidget *w, gpointer key) } /** + * Returns a named descendent of parent, which has the given name, or nullptr if there's none. + * + * \param[in] parent The widget to search + * \param[in] name The name of the desired child widget + * + * \return The specified child widget, or nullptr if it cannot be found + */ +Gtk::Widget * +sp_search_by_name_recursive(Gtk::Widget *parent, const Glib::ustring& name) +{ + auto parent_bin = dynamic_cast<Gtk::Bin *>(parent); + auto parent_container = dynamic_cast<Gtk::Container *>(parent); + + if (parent && parent->get_name() == name) { + return parent; + } + else if (parent_bin) { + auto child = parent_bin->get_child(); + return sp_search_by_name_recursive(child, name); + } + else if (parent_container) { + auto children = parent_container->get_children(); + + for (auto child : children) { + auto tmp = sp_search_by_name_recursive(child, name); + + if (tmp) { + return tmp; + } + } + } + + return nullptr; +} + +/** * Returns the descendant of w which has the given key and value pair, or NULL if there's none. */ GtkWidget *sp_search_by_value_recursive(GtkWidget *w, gchar *key, gchar *value) diff --git a/src/widgets/spw-utilities.h b/src/widgets/spw-utilities.h index 8801ce46f..44bd4f88a 100644 --- a/src/widgets/spw-utilities.h +++ b/src/widgets/spw-utilities.h @@ -35,6 +35,8 @@ void sp_set_font_size_smaller (GtkWidget *w); gpointer sp_search_by_data_recursive(GtkWidget *w, gpointer data); GtkWidget *sp_search_by_value_recursive(GtkWidget *w, gchar *key, gchar *value); +Gtk::Widget * sp_search_by_name_recursive(Gtk::Widget *parent, + const Glib::ustring& name); #endif /* |
