Commit 7e12154b authored by Debarshi Ray's avatar Debarshi Ray

main-toolbar: Add a gear menu with "Open" and "Properties" in it

parent 5787502e
......@@ -17,6 +17,7 @@ src/photos-load-more-button.c
src/photos-main-toolbar.c
src/photos-main-window.c
src/photos-organize-collection-dialog.c
[type: gettext/glade]src/photos-preview-menu.ui
src/photos-properties-dialog.c
src/photos-search-type-manager.c
[type: gettext/glade]src/photos-selection-menu.ui
......
......@@ -163,6 +163,7 @@ EXTRA_DIST = \
photos.gresource.xml \
photos-app-menu.ui \
photos-marshalers.list \
photos-preview-menu.ui \
photos-selection-menu.ui \
photos-tracker-resources.xml \
$(null)
......
......@@ -32,8 +32,10 @@
#include "eog-debug.h"
#include "photos-application.h"
#include "photos-item-manager.h"
#include "photos-main-window.h"
#include "photos-mode-controller.h"
#include "photos-properties-dialog.h"
#include "photos-resources.h"
......@@ -41,9 +43,13 @@ struct _PhotosApplicationPrivate
{
GResource *resource;
GSimpleAction *fs_action;
GSimpleAction *gear_action;
GSimpleAction *open_action;
GSimpleAction *properties_action;
GSimpleAction *sel_all_action;
GSimpleAction *sel_none_action;
GtkWidget *main_window;
PhotosBaseManager *item_mngr;
PhotosModeController *mode_cntrlr;
};
......@@ -51,6 +57,24 @@ struct _PhotosApplicationPrivate
G_DEFINE_TYPE (PhotosApplication, photos_application, GTK_TYPE_APPLICATION)
static void
photos_application_action_toggle (GSimpleAction *simple, GVariant *parameter, gpointer user_data)
{
PhotosApplication *self = PHOTOS_APPLICATION (user_data);
PhotosApplicationPrivate *priv = self->priv;
GVariant *state;
GVariant *new_state;
state = g_action_get_state (G_ACTION (simple));
if (state == NULL)
return;
new_state = g_variant_new ("b", !g_variant_get_boolean (state));
g_action_change_state (G_ACTION (simple), new_state);
g_variant_unref (state);
}
static void
photos_application_can_fullscreen_changed (PhotosModeController *mode_cntrlr, gpointer user_data)
{
......@@ -73,6 +97,42 @@ photos_application_fullscreen (GSimpleAction *simple, GVariant *parameter, gpoin
}
static void
photos_application_open_current (PhotosApplication *self)
{
PhotosApplicationPrivate *priv = self->priv;
GdkScreen *screen;
PhotosBaseItem *item;
guint32 time;
item = PHOTOS_BASE_ITEM (photos_base_manager_get_active_object (priv->item_mngr));
if (item == NULL)
return;
screen = gtk_window_get_screen (GTK_WINDOW (priv->main_window));
time = gtk_get_current_event_time ();
photos_base_item_open (item, screen, time);
}
static void
photos_application_properties (PhotosApplication *self)
{
PhotosApplicationPrivate *priv = self->priv;
GtkWidget *dialog;
PhotosBaseItem *item;
const gchar *id;
item = PHOTOS_BASE_ITEM (photos_base_manager_get_active_object (priv->item_mngr));
if (item == NULL)
return;
id = photos_base_item_get_id (item);
dialog = photos_properties_dialog_new (GTK_WINDOW (priv->main_window), id);
g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
}
static void
photos_application_quit (GSimpleAction *simple, GVariant *parameter, gpointer user_data)
{
......@@ -92,6 +152,11 @@ photos_application_window_mode_changed (PhotosApplication *self, PhotosWindowMod
enable = (mode == PHOTOS_WINDOW_MODE_OVERVIEW || mode == PHOTOS_WINDOW_MODE_FAVORITES);
g_simple_action_set_enabled (priv->sel_all_action, enable);
g_simple_action_set_enabled (priv->sel_none_action, enable);
enable = (mode == PHOTOS_WINDOW_MODE_PREVIEW);
g_simple_action_set_enabled (priv->gear_action, enable);
g_simple_action_set_enabled (priv->open_action, enable);
g_simple_action_set_enabled (priv->properties_action, enable);
}
......@@ -114,6 +179,7 @@ photos_application_startup (GApplication *application)
GSimpleAction *action;
GtkBuilder *builder;
GtkSettings *settings;
GVariant *state;
G_APPLICATION_CLASS (photos_application_parent_class)
->startup (application);
......@@ -126,6 +192,7 @@ photos_application_startup (GApplication *application)
settings = gtk_settings_get_default ();
g_object_set (settings, "gtk-application-prefer-dark-theme", TRUE, NULL);
priv->item_mngr = photos_item_manager_new ();
priv->mode_cntrlr = photos_mode_controller_new ();
action = g_simple_action_new ("about", NULL);
......@@ -142,6 +209,19 @@ photos_application_startup (GApplication *application)
G_CALLBACK (photos_application_can_fullscreen_changed),
self);
state = g_variant_new ("b", FALSE);
priv->gear_action = g_simple_action_new_stateful ("gear-menu", NULL, state);
g_signal_connect (priv->gear_action, "activate", G_CALLBACK (photos_application_action_toggle), self);
g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->gear_action));
priv->open_action = g_simple_action_new ("open-current", NULL);
g_signal_connect_swapped (priv->open_action, "activate", G_CALLBACK (photos_application_open_current), self);
g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->open_action));
priv->properties_action = g_simple_action_new ("properties", NULL);
g_signal_connect_swapped (priv->properties_action, "activate", G_CALLBACK (photos_application_properties), self);
g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->properties_action));
action = g_simple_action_new ("quit", NULL);
g_signal_connect (action, "activate", G_CALLBACK (photos_application_quit), self);
g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (action));
......@@ -167,6 +247,7 @@ photos_application_startup (GApplication *application)
gtk_application_add_accelerator (GTK_APPLICATION (self), "<Primary>q", "app.quit", NULL);
gtk_application_add_accelerator (GTK_APPLICATION (self), "F11", "app.fullscreen", NULL);
gtk_application_add_accelerator (GTK_APPLICATION (self), "F10", "app.gear-menu", NULL);
gtk_application_add_accelerator (GTK_APPLICATION (self), "<Primary>a", "app.select-all", NULL);
priv->main_window = photos_main_window_new (GTK_APPLICATION (self));
......@@ -206,8 +287,12 @@ photos_application_dispose (GObject *object)
}
g_clear_object (&priv->fs_action);
g_clear_object (&priv->gear_action);
g_clear_object (&priv->open_action);
g_clear_object (&priv->properties_action);
g_clear_object (&priv->sel_all_action);
g_clear_object (&priv->sel_none_action);
g_clear_object (&priv->item_mngr);
g_clear_object (&priv->mode_cntrlr);
G_OBJECT_CLASS (photos_application_parent_class)
......
......@@ -30,6 +30,7 @@
#include <glib/gi18n.h>
#include <libgd/gd.h>
#include "photos-application.h"
#include "photos-collection-manager.h"
#include "photos-header-bar.h"
#include "photos-item-manager.h"
......@@ -41,6 +42,7 @@
struct _PhotosMainToolbarPrivate
{
GSimpleAction *gear_menu;
GtkWidget *coll_back_button;
GtkWidget *selection_menu;
GtkWidget *toolbar;
......@@ -249,6 +251,43 @@ photos_main_toolbar_clear_toolbar (PhotosMainToolbar *self)
photos_main_toolbar_clear_state_data (self);
photos_header_bar_clear (PHOTOS_HEADER_BAR (priv->toolbar));
g_simple_action_set_enabled (priv->gear_menu, FALSE);
}
static GMenu *
photos_main_toolbar_create_preview_menu (PhotosMainToolbar *self)
{
GMenu *menu;
GtkBuilder *builder;
PhotosBaseItem *item;
builder = gtk_builder_new ();
gtk_builder_add_from_resource (builder, "/org/gnome/photos/preview-menu.ui", NULL);
menu = G_MENU (g_object_ref (gtk_builder_get_object (builder, "preview-menu")));
item = PHOTOS_BASE_ITEM (photos_base_manager_get_active_object (self->priv->item_mngr));
if (item != NULL)
{
const gchar *default_app_name;
default_app_name = photos_base_item_get_default_app_name (item);
if (default_app_name != NULL)
{
GMenu *section;
gchar *label;
section = G_MENU (gtk_builder_get_object (builder, "open-section"));
g_menu_remove (section, 0);
label = g_strdup_printf (_("Open with %s"), default_app_name);
g_menu_prepend (section, label, "app.open-current");
g_free (label);
}
}
g_object_unref (builder);
return menu;
}
......@@ -292,12 +331,23 @@ static void
photos_main_toolbar_populate_for_preview (PhotosMainToolbar *self)
{
PhotosMainToolbarPrivate *priv = self->priv;
GMenu *preview_menu;
GtkWidget *back_button;
GtkWidget *menu_button;
photos_header_bar_set_mode (PHOTOS_HEADER_BAR (priv->toolbar), PHOTOS_HEADER_BAR_MODE_STANDALONE);
back_button = photos_main_toolbar_add_back_button (self);
g_signal_connect (back_button, "clicked", G_CALLBACK (photos_main_toolbar_back_button_clicked), self);
preview_menu = photos_main_toolbar_create_preview_menu (self);
menu_button = gd_header_menu_button_new ();
gtk_actionable_set_action_name (GTK_ACTIONABLE (menu_button), "app.gear-menu");
gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (menu_button), G_MENU_MODEL (preview_menu));
gd_header_button_set_symbolic_icon_name (GD_HEADER_BUTTON (menu_button), "emblem-system-symbolic");
gd_header_bar_pack_end (GD_HEADER_BAR (priv->toolbar), menu_button);
g_simple_action_set_enabled (priv->gear_menu, TRUE);
}
......@@ -398,6 +448,7 @@ photos_main_toolbar_init (PhotosMainToolbar *self)
{
PhotosMainToolbarPrivate *priv;
GMenu *selection_menu;
GtkApplication *app;
GtkBuilder *builder;
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, PHOTOS_TYPE_MAIN_TOOLBAR, PhotosMainToolbarPrivate);
......@@ -410,6 +461,10 @@ photos_main_toolbar_init (PhotosMainToolbar *self)
gtk_container_add (GTK_CONTAINER (self), priv->toolbar);
gtk_widget_show (priv->toolbar);
app = photos_application_new ();
priv->gear_menu = G_SIMPLE_ACTION (g_action_map_lookup_action (G_ACTION_MAP (app), "gear-menu"));
g_object_unref (app);
builder = gtk_builder_new ();
gtk_builder_add_from_resource (builder, "/org/gnome/photos/selection-menu.ui", NULL);
......
<interface>
<menu id="preview-menu">
<section id="open-section">
<item>
<attribute name="action">app.open-current</attribute>
<attribute name="label" translatable="yes">Open</attribute>
</item>
</section>
<section>
<item>
<attribute name="action">app.properties</attribute>
<attribute name="label" translatable="yes">Properties</attribute>
</item>
</section>
</menu>
</interface>
......@@ -2,6 +2,7 @@
<gresources>
<gresource prefix="/org/gnome/photos">
<file alias="app-menu.ui" preprocess="xml-stripblanks">photos-app-menu.ui</file>
<file alias="preview-menu.ui" preprocess="xml-stripblanks">photos-preview-menu.ui</file>
<file alias="selection-menu.ui" preprocess="xml-stripblanks">photos-selection-menu.ui</file>
</gresource>
</gresources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment