Add XAppFavorites support to the file menu.

This adds a Favorites submenu, and it moves the recent list into
a submenu.

See:
c9c885a841
This commit is contained in:
Michael Webster 2020-09-16 13:29:41 -04:00
parent 15b607ddc0
commit 9e805380d4
5 changed files with 106 additions and 6 deletions

4
debian/control vendored
View File

@ -12,7 +12,7 @@ Build-Depends: debhelper (>= 9),
libgtk-3-dev,
libgtksourceview-4-dev,
libpeas-dev,
libxapp-dev,
libxapp-dev (>= 1.9),
libsm-dev,
libx11-dev,
libxml2-dev,
@ -32,7 +32,7 @@ Depends: iso-codes,
${shlibs:Depends},
python3,
python3-gi,
xapps-common,
xapps-common (>= 1.9.0),
zenity
XB-Python-Version: ${python:Versions}
Description: Text editor

View File

@ -16,9 +16,15 @@
<placeholder name="FileOps_5"/>
<menuitem name="FilePrintPreviewMenu" action="FilePrintPreview"/>
<menuitem name="FilePrintMenu" action="FilePrint"/>
<placeholder name="FileRecentsPlaceholder">
<separator/>
<menu name="XAppFavoritesMenu" action="XAppFavoritesMenu">
<placeholder name="XAppFavorites">
</placeholder>
</menu>
<menu name="FileRecentsMenu" action="FileRecentsMenu">
<placeholder name="FileRecentsPlaceholder">
</placeholder>
</menu>
<separator/>
<menuitem name="FileCloseMenu" action="FileClose"/>
<menuitem name="FileQuitMenu" action="FileQuit"/>

View File

@ -48,6 +48,8 @@ static const GtkActionEntry xed_always_sensitive_menu_entries[] =
{ "Tools", NULL, N_("_Tools") },
{ "Documents", NULL, N_("_Documents") },
{ "Help", NULL, N_("_Help") },
{ "XAppFavoritesMenu", NULL, N_("Favorites")},
{ "FileRecentsMenu", NULL, N_("Recents")},
/* File menu */
{ "FileNew", "document-new-symbolic", N_("_New"), "<control>N",

View File

@ -32,6 +32,7 @@
#define __XED_WINDOW_PRIVATE_H__
#include <libpeas/peas-extension-set.h>
#include <libxapp/xapp-favorites.h>
#include "xed/xed-window.h"
#include "xed-message-bus.h"
@ -101,6 +102,10 @@ struct _XedWindowPrivate
guint recents_menu_ui_id;
gulong recents_handler_id;
GtkActionGroup *favorites_action_group;
guint favorites_menu_ui_id;
gulong favorites_handler_id;
XedTab *active_tab;
gint num_tabs;

View File

@ -209,6 +209,14 @@ xed_window_dispose (GObject *object)
window->priv->recents_handler_id = 0;
}
if (window->priv->favorites_handler_id != 0)
{
XAppFavorites *favorites;
favorites = xapp_favorites_get_default ();
g_signal_handler_disconnect (favorites, window->priv->favorites_handler_id);
window->priv->favorites_handler_id = 0;
}
g_clear_object (&window->priv->manager);
g_clear_object (&window->priv->message_bus);
g_clear_object (&window->priv->window_group);
@ -878,7 +886,7 @@ update_recent_files_menu (XedWindow *window)
gtk_action_group_add_action (p->recents_action_group, action);
g_object_unref (action);
gtk_ui_manager_add_ui (p->manager, p->recents_menu_ui_id, "/MenuBar/FileMenu/FileRecentsPlaceholder",
gtk_ui_manager_add_ui (p->manager, p->recents_menu_ui_id, "/MenuBar/FileMenu/FileRecentsMenu/FileRecentsPlaceholder",
action_name, action_name, GTK_UI_MANAGER_MENUITEM, FALSE);
g_free (action_name);
@ -911,6 +919,71 @@ toolbar_visibility_changed (GtkWidget *toolbar,
}
}
static void
favorite_activated (GtkAction *action,
gpointer user_data)
{
GFile *location;
location = g_file_new_for_uri (gtk_action_get_name (action));
xed_commands_load_location (XED_WINDOW (user_data), location, NULL, 0);
g_object_unref (location);
}
static void
update_favorites_menu (XedWindow *window)
{
XedWindowPrivate *p = window->priv;
XAppFavorites *favorites;
GList *actions, *l;
GList *items = NULL;
guint i;
xed_debug (DEBUG_WINDOW);
g_return_if_fail (p->favorites_action_group != NULL);
if (p->favorites_menu_ui_id != 0)
{
gtk_ui_manager_remove_ui (p->manager, p->favorites_menu_ui_id);
}
actions = gtk_action_group_list_actions (p->favorites_action_group);
for (l = actions; l != NULL; l = l->next)
{
g_signal_handlers_disconnect_by_func(GTK_ACTION (l->data), G_CALLBACK (favorite_activated), window);
gtk_action_group_remove_action (p->favorites_action_group, GTK_ACTION(l->data));
}
g_list_free (actions);
p->favorites_menu_ui_id = gtk_ui_manager_new_merge_id (p->manager);
favorites = xapp_favorites_get_default ();
const gchar *supported_mimetypes[2] = {
"text/plain",
NULL
};
items = xapp_favorites_create_actions (favorites, supported_mimetypes);
for (l = items; l != NULL; l = l->next)
{
GtkAction *action = GTK_ACTION (l->data);
const gchar *name = gtk_action_get_name (action);
g_signal_connect (action, "activate", G_CALLBACK (favorite_activated), window);
gtk_action_group_add_action (p->favorites_action_group, action);
gtk_ui_manager_add_ui (p->manager, p->favorites_menu_ui_id, "/MenuBar/FileMenu/XAppFavoritesMenu/XAppFavorites",
name, name, GTK_UI_MANAGER_MENUITEM, FALSE);
}
g_list_free_full (items, g_object_unref);
}
static GtkWidget *
create_toolbar_button (GtkAction *action)
{
@ -943,6 +1016,7 @@ create_menu_bar_and_toolbar (XedWindow *window,
GtkWidget *box;
GtkWidget *separator;
GtkWidget *button;
XAppFavorites *favorites;
xed_debug (DEBUG_WINDOW);
@ -1017,6 +1091,19 @@ create_menu_bar_and_toolbar (XedWindow *window,
window);
update_recent_files_menu (window);
action_group = gtk_action_group_new ("FavoriteFilesActions");
gtk_action_group_set_translation_domain (action_group, NULL);
window->priv->favorites_action_group = action_group;
gtk_ui_manager_insert_action_group (manager, action_group, 0);
g_object_unref (action_group);
favorites = xapp_favorites_get_default ();
window->priv->favorites_handler_id = g_signal_connect_swapped (favorites,
"changed", G_CALLBACK (update_favorites_menu),
window);
update_favorites_menu (window);
/* list of open documents menu */
action_group = gtk_action_group_new ("DocumentsListActions");
gtk_action_group_set_translation_domain (action_group, NULL);