[gedit/wip/open-recent-menu] Window: better create open recent menu
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/wip/open-recent-menu] Window: better create open recent menu
- Date: Thu, 21 Jul 2022 15:53:04 +0000 (UTC)
commit bbc20b15a995167b71cd7737b8c43611221cdb85
Author: Sébastien Wilmet <swilmet informatique-libre be>
Date: Thu Jul 21 17:04:56 2022 +0200
Window: better create open recent menu
Amtk 5.5.2 is needed for
amtk_application_window_create_open_recent_menu_base().
When using amtk_application_window_create_open_recent_menu() (so the
more complete one), it calls g_application_open() which is not suitable
in gedit, because it calls _gedit_cmd_load_files_from_prompt(). From
prompt, if the file doesn't exist, it sets the 'create' param to TRUE,
which creates the file, so it doesn't show a warning infobar if the file
doesn't exist.
When opening a file from the recent menu, we *want* a warning infobar if
the file doesn't exist instead of showing an empty document. (if it
shows an empty document, we may think that the file *exists* and is
empty).
gedit/gedit-window.c | 33 ++++++++++++++++++++++++++++++---
meson.build | 1 +
2 files changed, 31 insertions(+), 3 deletions(-)
---
diff --git a/gedit/gedit-window.c b/gedit/gedit-window.c
index 2f9a2076f..56e970a02 100644
--- a/gedit/gedit-window.c
+++ b/gedit/gedit-window.c
@@ -2617,6 +2617,23 @@ init_amtk_application_window (GeditWindow *gedit_window)
amtk_application_window_set_statusbar (amtk_window, GTK_STATUSBAR (gedit_window->priv->statusbar));
}
+static void
+open_recent_menu_item_activated_cb (GtkRecentChooser *recent_chooser,
+ gpointer user_data)
+{
+ GeditWindow *window = GEDIT_WINDOW (user_data);
+ gchar *uri;
+ GFile *location;
+
+ uri = gtk_recent_chooser_get_current_uri (recent_chooser);
+ location = g_file_new_for_uri (uri);
+
+ gedit_commands_load_location (window, location, NULL, 0, 0);
+
+ g_free (uri);
+ g_object_unref (location);
+}
+
static GtkWidget *
create_open_buttons (GeditWindow *window,
GtkMenuButton **open_recent_button)
@@ -2626,7 +2643,7 @@ create_open_buttons (GeditWindow *window,
GtkWidget *open_dialog_button;
GtkWidget *my_open_recent_button;
AmtkApplicationWindow *amtk_window;
- GtkWidget *recent_menu;
+ GtkRecentChooserMenu *recent_menu;
/* It currently needs to be a GtkBox, not a GtkGrid, because GtkGrid and
* GTK_STYLE_CLASS_LINKED doesn't work as expected in a RTL locale.
@@ -2643,9 +2660,19 @@ create_open_buttons (GeditWindow *window,
my_open_recent_button = gtk_menu_button_new ();
gtk_widget_set_tooltip_text (my_open_recent_button, _("Open a recently used file"));
+ recent_menu = amtk_application_window_create_open_recent_menu_base ();
+
amtk_window = amtk_application_window_get_from_gtk_application_window (GTK_APPLICATION_WINDOW
(window));
- recent_menu = amtk_application_window_create_open_recent_menu (amtk_window);
- gtk_menu_button_set_popup (GTK_MENU_BUTTON (my_open_recent_button), recent_menu);
+ amtk_application_window_connect_recent_chooser_menu_to_statusbar (amtk_window, recent_menu);
+
+ g_signal_connect_object (recent_menu,
+ "item-activated",
+ G_CALLBACK (open_recent_menu_item_activated_cb),
+ window,
+ 0);
+
+ gtk_menu_button_set_popup (GTK_MENU_BUTTON (my_open_recent_button),
+ GTK_WIDGET (recent_menu));
gtk_container_add (GTK_CONTAINER (hbox), open_dialog_button);
gtk_container_add (GTK_CONTAINER (hbox), my_open_recent_button);
diff --git a/meson.build b/meson.build
index a9ce7d0da..fca16772d 100644
--- a/meson.build
+++ b/meson.build
@@ -45,6 +45,7 @@ gio_dep = dependency('gio-2.0', version: '>= 2.70')
libgedit_public_deps = [
gio_dep,
dependency('gtk+-3.0', version: '>= 3.22'),
+ dependency('amtk-5', version: '>= 5.5.2'),
dependency('tepl-6', version: '>= 6.1.2'),
dependency('libpeas-gtk-1.0'),
]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]