2015-10-11 20:39:18 +00:00
|
|
|
/* gtkshortcutswindow.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015 Christian Hergert <christian@hergert.me>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2016-10-15 20:22:48 +00:00
|
|
|
#include "gtkshortcutswindowprivate.h"
|
2018-02-08 05:15:10 +00:00
|
|
|
|
|
|
|
#include "gtkbox.h"
|
2020-05-02 19:17:20 +00:00
|
|
|
#include "gtkbuildable.h"
|
2018-02-08 05:15:10 +00:00
|
|
|
#include "gtkgrid.h"
|
|
|
|
#include "gtkheaderbar.h"
|
|
|
|
#include "gtkintl.h"
|
|
|
|
#include "gtklabel.h"
|
|
|
|
#include "gtklistbox.h"
|
2019-03-16 03:48:26 +00:00
|
|
|
#include "gtkmain.h"
|
2018-02-08 05:15:10 +00:00
|
|
|
#include "gtkmenubutton.h"
|
|
|
|
#include "gtkpopover.h"
|
|
|
|
#include "gtkprivate.h"
|
2015-10-11 20:39:18 +00:00
|
|
|
#include "gtkscrolledwindow.h"
|
2018-02-08 05:15:10 +00:00
|
|
|
#include "gtksearchbar.h"
|
|
|
|
#include "gtksearchentry.h"
|
2015-10-11 20:39:18 +00:00
|
|
|
#include "gtkshortcutssection.h"
|
|
|
|
#include "gtkshortcutsgroup.h"
|
2016-04-17 17:38:51 +00:00
|
|
|
#include "gtkshortcutsshortcutprivate.h"
|
2018-02-08 05:15:10 +00:00
|
|
|
#include "gtksizegroup.h"
|
|
|
|
#include "gtkstack.h"
|
|
|
|
#include "gtktogglebutton.h"
|
|
|
|
#include "gtktypebuiltins.h"
|
2015-10-26 11:22:28 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2015-10-11 20:39:18 +00:00
|
|
|
|
|
|
|
/**
|
2021-02-27 04:16:11 +00:00
|
|
|
* GtkShortcutsWindow:
|
2015-10-11 20:39:18 +00:00
|
|
|
*
|
2021-02-27 04:16:11 +00:00
|
|
|
* A `GtkShortcutsWindow` shows information about the keyboard shortcuts
|
|
|
|
* and gestures of an application.
|
|
|
|
*
|
|
|
|
* The shortcuts can be grouped, and you can have multiple sections in this
|
|
|
|
* window, corresponding to the major modes of your application.
|
2015-10-11 20:39:18 +00:00
|
|
|
*
|
|
|
|
* Additionally, the shortcuts can be filtered by the current view, to avoid
|
|
|
|
* showing information that is not relevant in the current application context.
|
|
|
|
*
|
2021-02-27 04:16:11 +00:00
|
|
|
* The recommended way to construct a `GtkShortcutsWindow` is with
|
|
|
|
* [class@Gtk.Builder], by populating a `GtkShortcutsWindow` with one or
|
|
|
|
* more `GtkShortcutsSection` objects, which contain `GtkShortcutsGroups`
|
|
|
|
* that in turn contain objects of class `GtkShortcutsShortcut`.
|
2015-10-11 20:39:18 +00:00
|
|
|
*
|
|
|
|
* # A simple example:
|
|
|
|
*
|
|
|
|
* ![](gedit-shortcuts.png)
|
|
|
|
*
|
|
|
|
* This example has as single section. As you can see, the shortcut groups
|
|
|
|
* are arranged in columns, and spread across several pages if there are too
|
|
|
|
* many to find on a single page.
|
|
|
|
*
|
2021-11-29 22:37:49 +00:00
|
|
|
* The .ui file for this example can be found [here](https://gitlab.gnome.org/GNOME/gtk/tree/main/demos/gtk-demo/shortcuts-gedit.ui).
|
2015-10-11 20:39:18 +00:00
|
|
|
*
|
|
|
|
* # An example with multiple views:
|
|
|
|
*
|
|
|
|
* ![](clocks-shortcuts.png)
|
|
|
|
*
|
2021-02-27 04:16:11 +00:00
|
|
|
* This example shows a `GtkShortcutsWindow` that has been configured to show only
|
2015-10-11 20:39:18 +00:00
|
|
|
* the shortcuts relevant to the "stopwatch" view.
|
|
|
|
*
|
2021-11-29 22:37:49 +00:00
|
|
|
* The .ui file for this example can be found [here](https://gitlab.gnome.org/GNOME/gtk/tree/main/demos/gtk-demo/shortcuts-clocks.ui).
|
2015-10-11 20:39:18 +00:00
|
|
|
*
|
|
|
|
* # An example with multiple sections:
|
|
|
|
*
|
|
|
|
* ![](builder-shortcuts.png)
|
|
|
|
*
|
2021-02-27 04:16:11 +00:00
|
|
|
* This example shows a `GtkShortcutsWindow` with two sections, "Editor Shortcuts"
|
2015-10-11 20:39:18 +00:00
|
|
|
* and "Terminal Shortcuts".
|
|
|
|
*
|
2021-11-29 22:37:49 +00:00
|
|
|
* The .ui file for this example can be found [here](https://gitlab.gnome.org/GNOME/gtk/tree/main/demos/gtk-demo/shortcuts-builder.ui).
|
2015-10-11 20:39:18 +00:00
|
|
|
*/
|
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
struct _GtkShortcutsWindow
|
2019-05-19 19:03:49 +00:00
|
|
|
{
|
2020-09-19 20:22:04 +00:00
|
|
|
GtkWindow parent_instance;
|
2019-05-19 19:03:49 +00:00
|
|
|
|
2015-10-11 20:39:18 +00:00
|
|
|
GHashTable *keywords;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *initial_section;
|
|
|
|
char *last_section_name;
|
|
|
|
char *view_name;
|
2015-10-11 20:39:18 +00:00
|
|
|
GtkSizeGroup *search_text_group;
|
|
|
|
GtkSizeGroup *search_image_group;
|
|
|
|
GHashTable *search_items_hash;
|
|
|
|
|
|
|
|
GtkStack *stack;
|
|
|
|
GtkStack *title_stack;
|
|
|
|
GtkMenuButton *menu_button;
|
|
|
|
GtkSearchBar *search_bar;
|
|
|
|
GtkSearchEntry *search_entry;
|
|
|
|
GtkHeaderBar *header_bar;
|
2015-11-20 19:59:56 +00:00
|
|
|
GtkWidget *main_box;
|
2015-10-11 20:39:18 +00:00
|
|
|
GtkPopover *popover;
|
|
|
|
GtkListBox *list_box;
|
|
|
|
GtkBox *search_gestures;
|
|
|
|
GtkBox *search_shortcuts;
|
2016-04-17 17:38:51 +00:00
|
|
|
|
|
|
|
GtkWindow *window;
|
|
|
|
gulong keys_changed_id;
|
2020-09-19 20:22:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GtkWindowClass parent_class;
|
|
|
|
|
|
|
|
void (*close) (GtkShortcutsWindow *self);
|
|
|
|
void (*search) (GtkShortcutsWindow *self);
|
|
|
|
} GtkShortcutsWindowClass;
|
2015-10-11 20:39:18 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GtkShortcutsWindow *self;
|
|
|
|
GtkBuilder *builder;
|
|
|
|
GQueue *stack;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *property_name;
|
2015-10-11 20:39:18 +00:00
|
|
|
guint translatable : 1;
|
|
|
|
} ViewsParserData;
|
|
|
|
|
2020-05-02 19:17:20 +00:00
|
|
|
static void gtk_shortcuts_window_buildable_iface_init (GtkBuildableIface *iface);
|
2015-10-11 20:39:18 +00:00
|
|
|
|
2020-05-02 19:17:20 +00:00
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkShortcutsWindow, gtk_shortcuts_window, GTK_TYPE_WINDOW,
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
|
|
|
|
gtk_shortcuts_window_buildable_iface_init))
|
2015-10-11 20:39:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
CLOSE,
|
|
|
|
SEARCH,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
PROP_SECTION_NAME,
|
|
|
|
PROP_VIEW_NAME,
|
|
|
|
LAST_PROP
|
|
|
|
};
|
|
|
|
|
|
|
|
static GParamSpec *properties[LAST_PROP];
|
|
|
|
static guint signals[LAST_SIGNAL];
|
|
|
|
|
|
|
|
|
2020-05-10 01:02:56 +00:00
|
|
|
static gboolean
|
|
|
|
more_than_three_children (GtkWidget *widget)
|
2015-10-11 20:39:18 +00:00
|
|
|
{
|
2020-05-10 01:02:56 +00:00
|
|
|
GtkWidget *child;
|
|
|
|
int i;
|
2015-10-11 20:39:18 +00:00
|
|
|
|
2020-05-10 01:02:56 +00:00
|
|
|
for (child = gtk_widget_get_first_child (widget), i = 0;
|
|
|
|
child != NULL;
|
|
|
|
child = gtk_widget_get_next_sibling (child), i++)
|
|
|
|
{
|
|
|
|
if (i == 3)
|
|
|
|
return TRUE;
|
|
|
|
}
|
2015-10-11 20:39:18 +00:00
|
|
|
|
2020-05-10 01:02:56 +00:00
|
|
|
return FALSE;
|
2015-10-11 20:39:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_title_stack (GtkShortcutsWindow *self)
|
|
|
|
{
|
|
|
|
GtkWidget *visible_child;
|
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
visible_child = gtk_stack_get_visible_child (self->stack);
|
2015-10-11 20:39:18 +00:00
|
|
|
|
|
|
|
if (GTK_IS_SHORTCUTS_SECTION (visible_child))
|
|
|
|
{
|
2020-09-19 20:22:04 +00:00
|
|
|
if (more_than_three_children (GTK_WIDGET (self->stack)))
|
2015-10-11 20:39:18 +00:00
|
|
|
{
|
2020-05-10 01:02:56 +00:00
|
|
|
char *title;
|
2015-10-11 20:39:18 +00:00
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
gtk_stack_set_visible_child_name (self->title_stack, "sections");
|
2015-10-11 20:39:18 +00:00
|
|
|
g_object_get (visible_child, "title", &title, NULL);
|
2020-09-19 20:22:04 +00:00
|
|
|
gtk_menu_button_set_label (self->menu_button, title);
|
2015-10-11 20:39:18 +00:00
|
|
|
g_free (title);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-09-19 20:22:04 +00:00
|
|
|
gtk_stack_set_visible_child_name (self->title_stack, "title");
|
2015-10-11 20:39:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (visible_child != NULL)
|
|
|
|
{
|
2020-09-19 20:22:04 +00:00
|
|
|
gtk_stack_set_visible_child_name (self->title_stack, "search");
|
2015-10-11 20:39:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_shortcuts_window_add_search_item (GtkWidget *child, gpointer data)
|
|
|
|
{
|
|
|
|
GtkShortcutsWindow *self = data;
|
|
|
|
GtkWidget *item;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *accelerator = NULL;
|
|
|
|
char *title = NULL;
|
|
|
|
char *hash_key = NULL;
|
2016-01-03 14:22:06 +00:00
|
|
|
GIcon *icon = NULL;
|
|
|
|
gboolean icon_set = FALSE;
|
|
|
|
gboolean subtitle_set = FALSE;
|
2015-11-15 03:34:19 +00:00
|
|
|
GtkTextDirection direction;
|
2016-01-03 14:22:06 +00:00
|
|
|
GtkShortcutType shortcut_type;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *action_name = NULL;
|
|
|
|
char *subtitle;
|
|
|
|
char *str;
|
|
|
|
char *keywords;
|
2015-10-11 20:39:18 +00:00
|
|
|
|
|
|
|
if (GTK_IS_SHORTCUTS_SHORTCUT (child))
|
|
|
|
{
|
2016-06-20 03:24:44 +00:00
|
|
|
GEnumClass *class;
|
|
|
|
GEnumValue *value;
|
|
|
|
|
2015-10-11 20:39:18 +00:00
|
|
|
g_object_get (child,
|
|
|
|
"accelerator", &accelerator,
|
|
|
|
"title", &title,
|
2015-11-15 03:34:19 +00:00
|
|
|
"direction", &direction,
|
2016-01-03 14:22:06 +00:00
|
|
|
"icon-set", &icon_set,
|
|
|
|
"subtitle-set", &subtitle_set,
|
|
|
|
"shortcut-type", &shortcut_type,
|
2016-04-17 17:38:51 +00:00
|
|
|
"action-name", &action_name,
|
2015-10-11 20:39:18 +00:00
|
|
|
NULL);
|
|
|
|
|
2016-06-20 03:24:44 +00:00
|
|
|
class = G_ENUM_CLASS (g_type_class_ref (GTK_TYPE_SHORTCUT_TYPE));
|
|
|
|
value = g_enum_get_value (class, shortcut_type);
|
|
|
|
|
|
|
|
hash_key = g_strdup_printf ("%s-%s-%s", title, value->value_nick, accelerator);
|
|
|
|
|
|
|
|
g_type_class_unref (class);
|
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
if (g_hash_table_contains (self->search_items_hash, hash_key))
|
2015-10-11 20:39:18 +00:00
|
|
|
{
|
|
|
|
g_free (hash_key);
|
|
|
|
g_free (title);
|
|
|
|
g_free (accelerator);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
g_hash_table_insert (self->search_items_hash, hash_key, GINT_TO_POINTER (1));
|
2015-10-11 20:39:18 +00:00
|
|
|
|
|
|
|
item = g_object_new (GTK_TYPE_SHORTCUTS_SHORTCUT,
|
|
|
|
"accelerator", accelerator,
|
|
|
|
"title", title,
|
2015-11-15 03:34:19 +00:00
|
|
|
"direction", direction,
|
2016-01-03 14:22:06 +00:00
|
|
|
"shortcut-type", shortcut_type,
|
2020-09-19 20:22:04 +00:00
|
|
|
"accel-size-group", self->search_image_group,
|
|
|
|
"title-size-group", self->search_text_group,
|
2016-04-17 17:38:51 +00:00
|
|
|
"action-name", action_name,
|
2015-10-11 20:39:18 +00:00
|
|
|
NULL);
|
2016-01-03 14:22:06 +00:00
|
|
|
if (icon_set)
|
|
|
|
{
|
|
|
|
g_object_get (child, "icon", &icon, NULL);
|
|
|
|
g_object_set (item, "icon", icon, NULL);
|
|
|
|
g_clear_object (&icon);
|
|
|
|
}
|
|
|
|
if (subtitle_set)
|
|
|
|
{
|
|
|
|
g_object_get (child, "subtitle", &subtitle, NULL);
|
|
|
|
g_object_set (item, "subtitle", subtitle, NULL);
|
|
|
|
g_free (subtitle);
|
|
|
|
}
|
2015-10-11 20:39:18 +00:00
|
|
|
str = g_strdup_printf ("%s %s", accelerator, title);
|
|
|
|
keywords = g_utf8_strdown (str, -1);
|
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
g_hash_table_insert (self->keywords, item, keywords);
|
2016-01-03 14:32:38 +00:00
|
|
|
if (shortcut_type == GTK_SHORTCUT_ACCELERATOR)
|
2020-09-19 20:22:04 +00:00
|
|
|
gtk_box_append (GTK_BOX (self->search_shortcuts), item);
|
2016-01-03 14:32:38 +00:00
|
|
|
else
|
2020-09-19 20:22:04 +00:00
|
|
|
gtk_box_append (GTK_BOX (self->search_gestures), item);
|
2015-10-11 20:39:18 +00:00
|
|
|
|
|
|
|
g_free (title);
|
|
|
|
g_free (accelerator);
|
|
|
|
g_free (str);
|
2016-04-17 17:38:51 +00:00
|
|
|
g_free (action_name);
|
2015-10-11 20:39:18 +00:00
|
|
|
}
|
2020-05-09 12:26:52 +00:00
|
|
|
else
|
2015-10-11 20:39:18 +00:00
|
|
|
{
|
2020-05-09 12:26:52 +00:00
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
|
|
for (widget = gtk_widget_get_first_child (child);
|
|
|
|
widget != NULL;
|
|
|
|
widget = gtk_widget_get_next_sibling (widget))
|
|
|
|
gtk_shortcuts_window_add_search_item (widget, self);
|
2015-10-11 20:39:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-21 03:03:39 +00:00
|
|
|
static void
|
|
|
|
section_notify_cb (GObject *section,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkShortcutsWindow *self = data;
|
|
|
|
|
|
|
|
if (strcmp (pspec->name, "section-name") == 0)
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
char *name;
|
2015-11-21 03:03:39 +00:00
|
|
|
|
|
|
|
g_object_get (section, "section-name", &name, NULL);
|
2020-09-19 20:22:04 +00:00
|
|
|
g_object_set (gtk_stack_get_page (self->stack, GTK_WIDGET (section)), "name", name, NULL);
|
2015-11-21 03:03:39 +00:00
|
|
|
g_free (name);
|
|
|
|
}
|
|
|
|
else if (strcmp (pspec->name, "title") == 0)
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
char *title;
|
2015-11-21 03:03:39 +00:00
|
|
|
GtkWidget *label;
|
|
|
|
|
|
|
|
label = g_object_get_data (section, "gtk-shortcuts-title");
|
|
|
|
g_object_get (section, "title", &title, NULL);
|
|
|
|
gtk_label_set_label (GTK_LABEL (label), title);
|
|
|
|
g_free (title);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-11 20:39:18 +00:00
|
|
|
static void
|
|
|
|
gtk_shortcuts_window_add_section (GtkShortcutsWindow *self,
|
|
|
|
GtkShortcutsSection *section)
|
|
|
|
{
|
|
|
|
GtkListBoxRow *row;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *title;
|
|
|
|
char *name;
|
|
|
|
const char *visible_section;
|
2015-10-11 20:39:18 +00:00
|
|
|
GtkWidget *label;
|
2020-05-09 12:26:52 +00:00
|
|
|
GtkWidget *child;
|
2015-10-11 20:39:18 +00:00
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
for (child = gtk_widget_get_first_child (GTK_WIDGET (section));
|
|
|
|
child != NULL;
|
|
|
|
child = gtk_widget_get_next_sibling (child))
|
|
|
|
gtk_shortcuts_window_add_search_item (child, self);
|
2015-10-11 20:39:18 +00:00
|
|
|
|
|
|
|
g_object_get (section,
|
|
|
|
"section-name", &name,
|
|
|
|
"title", &title,
|
|
|
|
NULL);
|
|
|
|
|
2015-11-21 03:03:39 +00:00
|
|
|
g_signal_connect (section, "notify", G_CALLBACK (section_notify_cb), self);
|
|
|
|
|
2015-10-11 20:39:18 +00:00
|
|
|
if (name == NULL)
|
|
|
|
name = g_strdup ("shortcuts");
|
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
gtk_stack_add_titled (self->stack, GTK_WIDGET (section), name, title);
|
2015-10-11 20:39:18 +00:00
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
visible_section = gtk_stack_get_visible_child_name (self->stack);
|
2015-10-11 20:39:18 +00:00
|
|
|
if (strcmp (visible_section, "internal-search") == 0 ||
|
2020-09-19 20:22:04 +00:00
|
|
|
(self->initial_section && strcmp (self->initial_section, visible_section) == 0))
|
|
|
|
gtk_stack_set_visible_child (self->stack, GTK_WIDGET (section));
|
2015-10-11 20:39:18 +00:00
|
|
|
|
|
|
|
row = g_object_new (GTK_TYPE_LIST_BOX_ROW,
|
|
|
|
NULL);
|
2015-11-21 03:03:39 +00:00
|
|
|
g_object_set_data (G_OBJECT (row), "gtk-shortcuts-section", section);
|
2015-10-11 20:39:18 +00:00
|
|
|
label = g_object_new (GTK_TYPE_LABEL,
|
2020-02-26 01:57:20 +00:00
|
|
|
"margin-start", 6,
|
|
|
|
"margin-end", 6,
|
|
|
|
"margin-top", 6,
|
|
|
|
"margin-bottom", 6,
|
2015-10-11 20:39:18 +00:00
|
|
|
"label", title,
|
|
|
|
"xalign", 0.5f,
|
|
|
|
NULL);
|
2015-11-21 03:03:39 +00:00
|
|
|
g_object_set_data (G_OBJECT (section), "gtk-shortcuts-title", label);
|
2020-05-03 04:09:18 +00:00
|
|
|
gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (row), GTK_WIDGET (label));
|
2020-09-19 20:22:04 +00:00
|
|
|
gtk_list_box_insert (GTK_LIST_BOX (self->list_box), GTK_WIDGET (row), -1);
|
2015-10-11 20:39:18 +00:00
|
|
|
|
|
|
|
update_title_stack (self);
|
|
|
|
|
|
|
|
g_free (name);
|
|
|
|
g_free (title);
|
|
|
|
}
|
|
|
|
|
2020-05-02 19:17:20 +00:00
|
|
|
static GtkBuildableIface *parent_buildable_iface;
|
2015-10-11 20:39:18 +00:00
|
|
|
|
2015-11-20 19:59:56 +00:00
|
|
|
static void
|
2020-05-02 19:17:20 +00:00
|
|
|
gtk_shortcuts_window_buildable_add_child (GtkBuildable *buildable,
|
|
|
|
GtkBuilder *builder,
|
|
|
|
GObject *child,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *type)
|
2020-05-02 19:17:20 +00:00
|
|
|
{
|
|
|
|
if (GTK_IS_SHORTCUTS_SECTION (child))
|
|
|
|
gtk_shortcuts_window_add_section (GTK_SHORTCUTS_WINDOW (buildable),
|
|
|
|
GTK_SHORTCUTS_SECTION (child));
|
2015-12-05 18:52:09 +00:00
|
|
|
else
|
2020-05-02 19:17:20 +00:00
|
|
|
parent_buildable_iface->add_child (buildable, builder, child, type);
|
2015-11-20 19:59:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-05-02 19:17:20 +00:00
|
|
|
gtk_shortcuts_window_buildable_iface_init (GtkBuildableIface *iface)
|
2015-11-20 19:59:56 +00:00
|
|
|
{
|
2020-05-02 19:17:20 +00:00
|
|
|
parent_buildable_iface = g_type_interface_peek_parent (iface);
|
2017-04-22 20:16:27 +00:00
|
|
|
|
2020-05-02 19:17:20 +00:00
|
|
|
iface->add_child = gtk_shortcuts_window_buildable_add_child;
|
2015-11-20 19:59:56 +00:00
|
|
|
}
|
|
|
|
|
2015-10-11 20:39:18 +00:00
|
|
|
static void
|
|
|
|
gtk_shortcuts_window_set_view_name (GtkShortcutsWindow *self,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *view_name)
|
2015-10-11 20:39:18 +00:00
|
|
|
{
|
2020-05-10 01:02:56 +00:00
|
|
|
GtkWidget *section;
|
2015-10-11 20:39:18 +00:00
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
g_free (self->view_name);
|
|
|
|
self->view_name = g_strdup (view_name);
|
2015-10-11 20:39:18 +00:00
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
for (section = gtk_widget_get_first_child (GTK_WIDGET (self->stack));
|
2020-05-10 01:02:56 +00:00
|
|
|
section != NULL;
|
|
|
|
section = gtk_widget_get_next_sibling (section))
|
2015-10-11 20:39:18 +00:00
|
|
|
{
|
|
|
|
if (GTK_IS_SHORTCUTS_SECTION (section))
|
2020-09-19 20:22:04 +00:00
|
|
|
g_object_set (section, "view-name", self->view_name, NULL);
|
2015-10-11 20:39:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_shortcuts_window_set_section_name (GtkShortcutsWindow *self,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *section_name)
|
2015-10-11 20:39:18 +00:00
|
|
|
{
|
2015-11-21 03:58:06 +00:00
|
|
|
GtkWidget *section = NULL;
|
2015-10-11 20:39:18 +00:00
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
g_free (self->initial_section);
|
|
|
|
self->initial_section = g_strdup (section_name);
|
2015-10-11 20:39:18 +00:00
|
|
|
|
2016-10-14 11:16:07 +00:00
|
|
|
if (section_name)
|
2020-09-19 20:22:04 +00:00
|
|
|
section = gtk_stack_get_child_by_name (self->stack, section_name);
|
2015-10-11 20:39:18 +00:00
|
|
|
if (section)
|
2020-09-19 20:22:04 +00:00
|
|
|
gtk_stack_set_visible_child (self->stack, section);
|
2015-10-11 20:39:18 +00:00
|
|
|
}
|
|
|
|
|
2016-04-17 17:38:51 +00:00
|
|
|
static void
|
|
|
|
update_accels_cb (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkShortcutsWindow *self = data;
|
|
|
|
|
|
|
|
if (GTK_IS_SHORTCUTS_SHORTCUT (widget))
|
2020-09-19 20:22:04 +00:00
|
|
|
gtk_shortcuts_shortcut_update_accel (GTK_SHORTCUTS_SHORTCUT (widget), self->window);
|
2020-05-09 12:26:52 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkWidget *child;
|
|
|
|
|
|
|
|
for (child = gtk_widget_get_first_child (GTK_WIDGET (widget));
|
|
|
|
child != NULL;
|
|
|
|
child = gtk_widget_get_next_sibling (child ))
|
|
|
|
update_accels_cb (child, self);
|
|
|
|
}
|
2016-04-17 17:38:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_accels_for_actions (GtkShortcutsWindow *self)
|
|
|
|
{
|
2020-09-19 20:22:04 +00:00
|
|
|
if (self->window)
|
2020-05-02 19:17:20 +00:00
|
|
|
{
|
|
|
|
GtkWidget *child;
|
|
|
|
|
|
|
|
for (child = gtk_widget_get_first_child (GTK_WIDGET (self));
|
|
|
|
child != NULL;
|
|
|
|
child = gtk_widget_get_next_sibling (child))
|
|
|
|
update_accels_cb (child, self);
|
|
|
|
}
|
2016-04-17 17:38:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
keys_changed_handler (GtkWindow *window,
|
|
|
|
GtkShortcutsWindow *self)
|
|
|
|
{
|
|
|
|
update_accels_for_actions (self);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_shortcuts_window_set_window (GtkShortcutsWindow *self,
|
|
|
|
GtkWindow *window)
|
|
|
|
{
|
2020-09-19 20:22:04 +00:00
|
|
|
if (self->keys_changed_id)
|
2016-04-17 17:38:51 +00:00
|
|
|
{
|
2020-09-19 20:22:04 +00:00
|
|
|
g_signal_handler_disconnect (self->window, self->keys_changed_id);
|
|
|
|
self->keys_changed_id = 0;
|
2016-04-17 17:38:51 +00:00
|
|
|
}
|
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
self->window = window;
|
2016-04-17 17:38:51 +00:00
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
if (self->window)
|
|
|
|
self->keys_changed_id = g_signal_connect (window, "keys-changed",
|
2016-04-17 17:38:51 +00:00
|
|
|
G_CALLBACK (keys_changed_handler),
|
|
|
|
self);
|
|
|
|
|
|
|
|
update_accels_for_actions (self);
|
|
|
|
}
|
|
|
|
|
2015-10-11 20:39:18 +00:00
|
|
|
static void
|
|
|
|
gtk_shortcuts_window__list_box__row_activated (GtkShortcutsWindow *self,
|
|
|
|
GtkListBoxRow *row,
|
|
|
|
GtkListBox *list_box)
|
|
|
|
{
|
2015-11-21 03:03:39 +00:00
|
|
|
GtkWidget *section;
|
2015-10-11 20:39:18 +00:00
|
|
|
|
2015-11-21 03:03:39 +00:00
|
|
|
section = g_object_get_data (G_OBJECT (row), "gtk-shortcuts-section");
|
2020-09-19 20:22:04 +00:00
|
|
|
gtk_stack_set_visible_child (self->stack, section);
|
|
|
|
gtk_popover_popdown (self->popover);
|
2015-10-11 20:39:18 +00:00
|
|
|
}
|
|
|
|
|
2015-11-15 03:34:19 +00:00
|
|
|
static gboolean
|
|
|
|
hidden_by_direction (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
if (GTK_IS_SHORTCUTS_SHORTCUT (widget))
|
|
|
|
{
|
|
|
|
GtkTextDirection dir;
|
|
|
|
|
|
|
|
g_object_get (widget, "direction", &dir, NULL);
|
|
|
|
if (dir != GTK_TEXT_DIR_NONE &&
|
|
|
|
dir != gtk_widget_get_direction (widget))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-10-11 20:39:18 +00:00
|
|
|
static void
|
|
|
|
gtk_shortcuts_window__entry__changed (GtkShortcutsWindow *self,
|
|
|
|
GtkSearchEntry *search_entry)
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
char *downcase = NULL;
|
2015-10-11 20:39:18 +00:00
|
|
|
GHashTableIter iter;
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *text;
|
|
|
|
const char *last_section_name;
|
2015-10-11 20:39:18 +00:00
|
|
|
gpointer key;
|
|
|
|
gpointer value;
|
|
|
|
gboolean has_result;
|
|
|
|
|
2019-02-28 19:31:36 +00:00
|
|
|
text = gtk_editable_get_text (GTK_EDITABLE (search_entry));
|
2015-10-11 20:39:18 +00:00
|
|
|
|
|
|
|
if (!text || !*text)
|
|
|
|
{
|
2020-09-19 20:22:04 +00:00
|
|
|
if (self->last_section_name != NULL)
|
2015-10-11 20:39:18 +00:00
|
|
|
{
|
2020-09-19 20:22:04 +00:00
|
|
|
gtk_stack_set_visible_child_name (self->stack, self->last_section_name);
|
2015-10-11 20:39:18 +00:00
|
|
|
return;
|
2015-11-15 03:34:19 +00:00
|
|
|
|
2015-10-11 20:39:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
last_section_name = gtk_stack_get_visible_child_name (self->stack);
|
2015-10-11 20:39:18 +00:00
|
|
|
|
|
|
|
if (g_strcmp0 (last_section_name, "internal-search") != 0 &&
|
|
|
|
g_strcmp0 (last_section_name, "no-search-results") != 0)
|
|
|
|
{
|
2020-09-19 20:22:04 +00:00
|
|
|
g_free (self->last_section_name);
|
|
|
|
self->last_section_name = g_strdup (last_section_name);
|
2015-10-11 20:39:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
downcase = g_utf8_strdown (text, -1);
|
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
g_hash_table_iter_init (&iter, self->keywords);
|
2015-10-11 20:39:18 +00:00
|
|
|
|
|
|
|
has_result = FALSE;
|
|
|
|
while (g_hash_table_iter_next (&iter, &key, &value))
|
|
|
|
{
|
|
|
|
GtkWidget *widget = key;
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *keywords = value;
|
2015-10-11 20:39:18 +00:00
|
|
|
gboolean match;
|
|
|
|
|
2015-11-15 03:34:19 +00:00
|
|
|
if (hidden_by_direction (widget))
|
|
|
|
match = FALSE;
|
|
|
|
else
|
|
|
|
match = strstr (keywords, downcase) != NULL;
|
|
|
|
|
2015-10-11 20:39:18 +00:00
|
|
|
gtk_widget_set_visible (widget, match);
|
|
|
|
has_result |= match;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (downcase);
|
|
|
|
|
|
|
|
if (has_result)
|
2020-09-19 20:22:04 +00:00
|
|
|
gtk_stack_set_visible_child_name (self->stack, "internal-search");
|
2015-10-11 20:39:18 +00:00
|
|
|
else
|
2020-09-19 20:22:04 +00:00
|
|
|
gtk_stack_set_visible_child_name (self->stack, "no-search-results");
|
2015-10-11 20:39:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_shortcuts_window__search_mode__changed (GtkShortcutsWindow *self)
|
|
|
|
{
|
2020-09-19 20:22:04 +00:00
|
|
|
if (!gtk_search_bar_get_search_mode (self->search_bar))
|
2015-10-11 20:39:18 +00:00
|
|
|
{
|
2020-09-19 20:22:04 +00:00
|
|
|
if (self->last_section_name != NULL)
|
|
|
|
gtk_stack_set_visible_child_name (self->stack, self->last_section_name);
|
2015-10-11 20:39:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_shortcuts_window_close (GtkShortcutsWindow *self)
|
|
|
|
{
|
|
|
|
gtk_window_close (GTK_WINDOW (self));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_shortcuts_window_search (GtkShortcutsWindow *self)
|
|
|
|
{
|
2020-09-19 20:22:04 +00:00
|
|
|
gtk_search_bar_set_search_mode (self->search_bar, TRUE);
|
2015-10-11 20:39:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_shortcuts_window_constructed (GObject *object)
|
|
|
|
{
|
|
|
|
GtkShortcutsWindow *self = (GtkShortcutsWindow *)object;
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_shortcuts_window_parent_class)->constructed (object);
|
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
if (self->initial_section != NULL)
|
|
|
|
gtk_stack_set_visible_child_name (self->stack, self->initial_section);
|
2015-10-11 20:39:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_shortcuts_window_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkShortcutsWindow *self = (GtkShortcutsWindow *)object;
|
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
g_clear_pointer (&self->keywords, g_hash_table_unref);
|
|
|
|
g_clear_pointer (&self->initial_section, g_free);
|
|
|
|
g_clear_pointer (&self->view_name, g_free);
|
|
|
|
g_clear_pointer (&self->last_section_name, g_free);
|
|
|
|
g_clear_pointer (&self->search_items_hash, g_hash_table_unref);
|
2015-10-11 20:39:18 +00:00
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
g_clear_object (&self->search_image_group);
|
|
|
|
g_clear_object (&self->search_text_group);
|
2015-10-11 20:39:18 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_shortcuts_window_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2015-11-21 03:58:06 +00:00
|
|
|
static void
|
|
|
|
gtk_shortcuts_window_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
GtkShortcutsWindow *self = (GtkShortcutsWindow *)object;
|
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
if (self->stack)
|
|
|
|
g_signal_handlers_disconnect_by_func (self->stack, G_CALLBACK (update_title_stack), self);
|
2015-11-21 03:58:06 +00:00
|
|
|
|
2016-04-17 17:38:51 +00:00
|
|
|
gtk_shortcuts_window_set_window (self, NULL);
|
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
self->stack = NULL;
|
|
|
|
self->search_bar = NULL;
|
|
|
|
self->main_box = NULL;
|
2017-01-10 14:59:26 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_shortcuts_window_parent_class)->dispose (object);
|
2015-11-21 03:58:06 +00:00
|
|
|
}
|
|
|
|
|
2015-10-11 20:39:18 +00:00
|
|
|
static void
|
|
|
|
gtk_shortcuts_window_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkShortcutsWindow *self = (GtkShortcutsWindow *)object;
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_SECTION_NAME:
|
|
|
|
{
|
2020-09-19 20:22:04 +00:00
|
|
|
GtkWidget *child = gtk_stack_get_visible_child (self->stack);
|
2015-10-11 20:39:18 +00:00
|
|
|
|
|
|
|
if (child != NULL)
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
char *name = NULL;
|
2015-10-11 20:39:18 +00:00
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
g_object_get (gtk_stack_get_page (self->stack, child),
|
2015-10-11 20:39:18 +00:00
|
|
|
"name", &name,
|
|
|
|
NULL);
|
|
|
|
g_value_take_string (value, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_VIEW_NAME:
|
2020-09-19 20:22:04 +00:00
|
|
|
g_value_set_string (value, self->view_name);
|
2015-10-11 20:39:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_shortcuts_window_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkShortcutsWindow *self = (GtkShortcutsWindow *)object;
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_SECTION_NAME:
|
|
|
|
gtk_shortcuts_window_set_section_name (self, g_value_get_string (value));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_VIEW_NAME:
|
|
|
|
gtk_shortcuts_window_set_view_name (self, g_value_get_string (value));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_shortcuts_window_unmap (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkShortcutsWindow *self = (GtkShortcutsWindow *)widget;
|
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
gtk_search_bar_set_search_mode (self->search_bar, FALSE);
|
|
|
|
gtk_editable_set_text (GTK_EDITABLE (self->search_entry), "");
|
2015-10-11 20:39:18 +00:00
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_shortcuts_window_parent_class)->unmap (widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_shortcuts_window_class_init (GtkShortcutsWindowClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->constructed = gtk_shortcuts_window_constructed;
|
|
|
|
object_class->finalize = gtk_shortcuts_window_finalize;
|
|
|
|
object_class->get_property = gtk_shortcuts_window_get_property;
|
|
|
|
object_class->set_property = gtk_shortcuts_window_set_property;
|
2015-11-21 03:58:06 +00:00
|
|
|
object_class->dispose = gtk_shortcuts_window_dispose;
|
2015-10-11 20:39:18 +00:00
|
|
|
|
|
|
|
widget_class->unmap = gtk_shortcuts_window_unmap;
|
|
|
|
|
|
|
|
klass->close = gtk_shortcuts_window_close;
|
|
|
|
klass->search = gtk_shortcuts_window_search;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkShortcutsWindow:section-name:
|
|
|
|
*
|
|
|
|
* The name of the section to show.
|
|
|
|
*
|
2021-02-27 04:16:11 +00:00
|
|
|
* This should be the section-name of one of the `GtkShortcutsSection`
|
2015-10-11 20:39:18 +00:00
|
|
|
* objects that are in this shortcuts window.
|
|
|
|
*/
|
|
|
|
properties[PROP_SECTION_NAME] =
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_string ("section-name", NULL, NULL,
|
2015-10-27 12:48:08 +00:00
|
|
|
"internal-search",
|
2015-10-11 20:39:18 +00:00
|
|
|
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkShortcutsWindow:view-name:
|
|
|
|
*
|
|
|
|
* The view name by which to filter the contents.
|
|
|
|
*
|
2021-02-27 04:16:11 +00:00
|
|
|
* This should correspond to the [property@Gtk.ShortcutsGroup:view]
|
|
|
|
* property of some of the [class@Gtk.ShortcutsGroup] objects that
|
|
|
|
* are inside this shortcuts window.
|
2015-10-11 20:39:18 +00:00
|
|
|
*
|
|
|
|
* Set this to %NULL to show all groups.
|
|
|
|
*/
|
|
|
|
properties[PROP_VIEW_NAME] =
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_string ("view-name", NULL, NULL,
|
2015-10-11 20:39:18 +00:00
|
|
|
NULL,
|
|
|
|
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
g_object_class_install_properties (object_class, LAST_PROP, properties);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkShortcutsWindow::close:
|
|
|
|
*
|
2021-02-27 04:16:11 +00:00
|
|
|
* Emitted when the user uses a keybinding to close the window.
|
|
|
|
*
|
|
|
|
* This is a [keybinding signal](class.SignalAction.html).
|
2015-10-11 20:39:18 +00:00
|
|
|
*
|
|
|
|
* The default binding for this signal is the Escape key.
|
|
|
|
*/
|
|
|
|
signals[CLOSE] = g_signal_new (I_("close"),
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
|
|
|
G_STRUCT_OFFSET (GtkShortcutsWindowClass, close),
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE,
|
|
|
|
0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkShortcutsWindow::search:
|
|
|
|
*
|
2021-02-27 04:16:11 +00:00
|
|
|
* Emitted when the user uses a keybinding to start a search.
|
|
|
|
*
|
|
|
|
* This is a [keybinding signal](class.SignalAction.html).
|
2015-10-11 20:39:18 +00:00
|
|
|
*
|
|
|
|
* The default binding for this signal is Control-F.
|
|
|
|
*/
|
|
|
|
signals[SEARCH] = g_signal_new (I_("search"),
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
|
|
|
G_STRUCT_OFFSET (GtkShortcutsWindowClass, search),
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE,
|
|
|
|
0);
|
|
|
|
|
2018-08-12 13:41:53 +00:00
|
|
|
gtk_widget_class_add_binding_signal (widget_class,
|
|
|
|
GDK_KEY_Escape, 0,
|
|
|
|
"close",
|
|
|
|
NULL);
|
|
|
|
gtk_widget_class_add_binding_signal (widget_class,
|
|
|
|
GDK_KEY_f, GDK_CONTROL_MASK,
|
|
|
|
"search",
|
|
|
|
NULL);
|
2015-10-11 20:39:18 +00:00
|
|
|
|
|
|
|
g_type_ensure (GTK_TYPE_SHORTCUTS_GROUP);
|
|
|
|
g_type_ensure (GTK_TYPE_SHORTCUTS_SHORTCUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_shortcuts_window_init (GtkShortcutsWindow *self)
|
|
|
|
{
|
2016-10-10 14:53:32 +00:00
|
|
|
GtkWidget *search_button;
|
2015-10-11 20:39:18 +00:00
|
|
|
GtkBox *box;
|
|
|
|
GtkWidget *scroller;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *empty;
|
|
|
|
PangoAttrList *attributes;
|
|
|
|
|
|
|
|
gtk_window_set_resizable (GTK_WINDOW (self), FALSE);
|
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
self->keywords = g_hash_table_new_full (NULL, NULL, NULL, g_free);
|
|
|
|
self->search_items_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
2015-10-11 20:39:18 +00:00
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
self->search_text_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
|
|
|
|
self->search_image_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
|
2015-10-11 20:39:18 +00:00
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
self->header_bar = GTK_HEADER_BAR (gtk_header_bar_new ());
|
|
|
|
gtk_window_set_titlebar (GTK_WINDOW (self), GTK_WIDGET (self->header_bar));
|
2015-10-11 20:39:18 +00:00
|
|
|
|
2017-01-12 12:10:14 +00:00
|
|
|
search_button = g_object_new (GTK_TYPE_TOGGLE_BUTTON,
|
|
|
|
"icon-name", "edit-find-symbolic",
|
|
|
|
NULL);
|
2020-09-19 20:22:04 +00:00
|
|
|
gtk_header_bar_pack_start (GTK_HEADER_BAR (self->header_bar), search_button);
|
2015-10-11 20:39:18 +00:00
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
self->main_box = g_object_new (GTK_TYPE_BOX,
|
2015-10-11 20:39:18 +00:00
|
|
|
"orientation", GTK_ORIENTATION_VERTICAL,
|
|
|
|
NULL);
|
2020-09-19 20:22:04 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (self), self->main_box);
|
2015-10-11 20:39:18 +00:00
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
self->search_bar = g_object_new (GTK_TYPE_SEARCH_BAR, NULL);
|
|
|
|
g_object_bind_property (self->search_bar, "search-mode-enabled",
|
2015-10-11 20:39:18 +00:00
|
|
|
search_button, "active",
|
|
|
|
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
|
2020-09-19 20:22:04 +00:00
|
|
|
gtk_box_append (GTK_BOX (self->main_box), GTK_WIDGET (self->search_bar));
|
|
|
|
gtk_search_bar_set_key_capture_widget (GTK_SEARCH_BAR (self->search_bar),
|
2019-04-03 11:17:54 +00:00
|
|
|
GTK_WIDGET (self));
|
2015-10-11 20:39:18 +00:00
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
self->stack = g_object_new (GTK_TYPE_STACK,
|
2020-02-25 23:25:52 +00:00
|
|
|
"hexpand", TRUE,
|
|
|
|
"vexpand", TRUE,
|
2020-04-28 23:53:33 +00:00
|
|
|
"hhomogeneous", TRUE,
|
|
|
|
"vhomogeneous", TRUE,
|
2015-10-11 20:39:18 +00:00
|
|
|
"transition-type", GTK_STACK_TRANSITION_TYPE_CROSSFADE,
|
|
|
|
NULL);
|
2020-09-19 20:22:04 +00:00
|
|
|
gtk_box_append (GTK_BOX (self->main_box), GTK_WIDGET (self->stack));
|
2015-10-11 20:39:18 +00:00
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
self->title_stack = g_object_new (GTK_TYPE_STACK,
|
2015-10-11 20:39:18 +00:00
|
|
|
NULL);
|
2020-09-19 20:22:04 +00:00
|
|
|
gtk_header_bar_set_title_widget (self->header_bar, GTK_WIDGET (self->title_stack));
|
2015-10-11 20:39:18 +00:00
|
|
|
|
2017-06-08 19:05:55 +00:00
|
|
|
/* Translators: This is the window title for the shortcuts window in normal mode */
|
2015-10-11 20:39:18 +00:00
|
|
|
label = gtk_label_new (_("Shortcuts"));
|
2020-08-13 23:49:02 +00:00
|
|
|
gtk_widget_add_css_class (label, "title");
|
2020-09-19 20:22:04 +00:00
|
|
|
gtk_stack_add_named (self->title_stack, label, "title");
|
2015-10-11 20:39:18 +00:00
|
|
|
|
2017-06-08 19:05:55 +00:00
|
|
|
/* Translators: This is the window title for the shortcuts window in search mode */
|
2015-10-11 20:39:18 +00:00
|
|
|
label = gtk_label_new (_("Search Results"));
|
2020-08-13 23:49:02 +00:00
|
|
|
gtk_widget_add_css_class (label, "title");
|
2020-09-19 20:22:04 +00:00
|
|
|
gtk_stack_add_named (self->title_stack, label, "search");
|
2015-10-11 20:39:18 +00:00
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
self->menu_button = g_object_new (GTK_TYPE_MENU_BUTTON,
|
2015-10-11 20:39:18 +00:00
|
|
|
"focus-on-click", FALSE,
|
|
|
|
NULL);
|
2020-09-19 20:22:04 +00:00
|
|
|
gtk_widget_add_css_class (GTK_WIDGET (self->menu_button), "flat");
|
|
|
|
gtk_stack_add_named (self->title_stack, GTK_WIDGET (self->menu_button), "sections");
|
2015-10-11 20:39:18 +00:00
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
self->popover = g_object_new (GTK_TYPE_POPOVER,
|
2015-10-11 20:39:18 +00:00
|
|
|
"position", GTK_POS_BOTTOM,
|
|
|
|
NULL);
|
2020-09-19 20:22:04 +00:00
|
|
|
gtk_menu_button_set_popover (self->menu_button, GTK_WIDGET (self->popover));
|
2015-10-11 20:39:18 +00:00
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
self->list_box = g_object_new (GTK_TYPE_LIST_BOX,
|
2015-10-11 20:39:18 +00:00
|
|
|
"selection-mode", GTK_SELECTION_NONE,
|
|
|
|
NULL);
|
2020-09-19 20:22:04 +00:00
|
|
|
g_signal_connect_object (self->list_box,
|
2015-10-11 20:39:18 +00:00
|
|
|
"row-activated",
|
|
|
|
G_CALLBACK (gtk_shortcuts_window__list_box__row_activated),
|
|
|
|
self,
|
|
|
|
G_CONNECT_SWAPPED);
|
2020-09-19 20:22:04 +00:00
|
|
|
gtk_popover_set_child (GTK_POPOVER (self->popover), GTK_WIDGET (self->list_box));
|
2015-10-11 20:39:18 +00:00
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
self->search_entry = GTK_SEARCH_ENTRY (gtk_search_entry_new ());
|
|
|
|
gtk_search_bar_set_child (GTK_SEARCH_BAR (self->search_bar), GTK_WIDGET (self->search_entry));
|
2020-05-03 13:58:27 +00:00
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
g_object_set (self->search_entry,
|
2017-06-08 19:05:55 +00:00
|
|
|
/* Translators: This is placeholder text for the search entry in the shortcuts window */
|
2015-10-11 20:39:18 +00:00
|
|
|
"placeholder-text", _("Search Shortcuts"),
|
|
|
|
"width-chars", 40,
|
|
|
|
NULL);
|
2020-09-19 20:22:04 +00:00
|
|
|
g_signal_connect_object (self->search_entry,
|
2015-10-11 20:39:18 +00:00
|
|
|
"search-changed",
|
|
|
|
G_CALLBACK (gtk_shortcuts_window__entry__changed),
|
|
|
|
self,
|
|
|
|
G_CONNECT_SWAPPED);
|
2020-09-19 20:22:04 +00:00
|
|
|
g_signal_connect_object (self->search_bar,
|
2015-10-11 20:39:18 +00:00
|
|
|
"notify::search-mode-enabled",
|
|
|
|
G_CALLBACK (gtk_shortcuts_window__search_mode__changed),
|
|
|
|
self,
|
|
|
|
G_CONNECT_SWAPPED);
|
|
|
|
|
2020-06-24 15:25:09 +00:00
|
|
|
scroller = gtk_scrolled_window_new ();
|
2015-10-11 20:39:18 +00:00
|
|
|
box = g_object_new (GTK_TYPE_BOX,
|
|
|
|
"halign", GTK_ALIGN_CENTER,
|
|
|
|
"orientation", GTK_ORIENTATION_VERTICAL,
|
|
|
|
NULL);
|
2020-02-06 16:32:26 +00:00
|
|
|
gtk_widget_add_css_class (GTK_WIDGET (box), "shortcuts-search-results");
|
2020-05-02 04:51:20 +00:00
|
|
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scroller), GTK_WIDGET (box));
|
2020-09-19 20:22:04 +00:00
|
|
|
gtk_stack_add_named (self->stack, scroller, "internal-search");
|
2015-10-11 20:39:18 +00:00
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
self->search_shortcuts = g_object_new (GTK_TYPE_BOX,
|
2015-10-11 20:39:18 +00:00
|
|
|
"halign", GTK_ALIGN_CENTER,
|
|
|
|
"spacing", 6,
|
|
|
|
"orientation", GTK_ORIENTATION_VERTICAL,
|
|
|
|
NULL);
|
2020-09-19 20:22:04 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), GTK_WIDGET (self->search_shortcuts));
|
2015-10-11 20:39:18 +00:00
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
self->search_gestures = g_object_new (GTK_TYPE_BOX,
|
2015-10-11 20:39:18 +00:00
|
|
|
"halign", GTK_ALIGN_CENTER,
|
|
|
|
"spacing", 6,
|
|
|
|
"orientation", GTK_ORIENTATION_VERTICAL,
|
|
|
|
NULL);
|
2020-09-19 20:22:04 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), GTK_WIDGET (self->search_gestures));
|
2015-10-11 20:39:18 +00:00
|
|
|
|
|
|
|
empty = g_object_new (GTK_TYPE_GRID,
|
|
|
|
"row-spacing", 12,
|
2020-02-26 01:57:20 +00:00
|
|
|
"margin-start", 12,
|
|
|
|
"margin-end", 12,
|
|
|
|
"margin-top", 12,
|
|
|
|
"margin-bottom", 12,
|
2015-10-11 20:39:18 +00:00
|
|
|
"hexpand", TRUE,
|
|
|
|
"vexpand", TRUE,
|
|
|
|
"halign", GTK_ALIGN_CENTER,
|
|
|
|
"valign", GTK_ALIGN_CENTER,
|
|
|
|
NULL);
|
2020-08-13 23:49:02 +00:00
|
|
|
gtk_widget_add_css_class (empty, "dim-label");
|
2015-10-11 20:39:18 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (empty),
|
|
|
|
g_object_new (GTK_TYPE_IMAGE,
|
|
|
|
"icon-name", "edit-find-symbolic",
|
|
|
|
"pixel-size", 72,
|
|
|
|
NULL),
|
|
|
|
0, 0, 1, 1);
|
|
|
|
attributes = pango_attr_list_new ();
|
|
|
|
pango_attr_list_insert (attributes, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
|
|
|
|
pango_attr_list_insert (attributes, pango_attr_scale_new (1.44));
|
|
|
|
label = g_object_new (GTK_TYPE_LABEL,
|
|
|
|
"label", _("No Results Found"),
|
|
|
|
"attributes", attributes,
|
|
|
|
NULL);
|
|
|
|
pango_attr_list_unref (attributes);
|
|
|
|
gtk_grid_attach (GTK_GRID (empty), label, 0, 1, 1, 1);
|
|
|
|
label = g_object_new (GTK_TYPE_LABEL,
|
|
|
|
"label", _("Try a different search"),
|
|
|
|
NULL);
|
|
|
|
gtk_grid_attach (GTK_GRID (empty), label, 0, 2, 1, 1);
|
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
gtk_stack_add_named (self->stack, empty, "no-search-results");
|
2015-11-21 03:58:06 +00:00
|
|
|
|
2020-09-19 20:22:04 +00:00
|
|
|
g_signal_connect_object (self->stack, "notify::visible-child",
|
2015-11-21 03:58:06 +00:00
|
|
|
G_CALLBACK (update_title_stack), self, G_CONNECT_SWAPPED);
|
|
|
|
|
2015-10-11 20:39:18 +00:00
|
|
|
}
|