[file-roller] added 'list mode' and 'show folders' options to the app menu
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [file-roller] added 'list mode' and 'show folders' options to the app menu
- Date: Mon, 3 Dec 2012 18:39:25 +0000 (UTC)
commit a765d237ae4b6346acbd36147434d7fa6c03d296
Author: Paolo Bacchilega <paobac src gnome org>
Date: Mon Dec 3 19:28:37 2012 +0100
added 'list mode' and 'show folders' options to the app menu
src/app-menu.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++++---
src/fr-window.c | 18 ++++++++
src/glib-utils.c | 32 +++++++++++++
src/glib-utils.h | 7 +++
src/typedefs.h | 2 +-
src/ui/app-menu.ui | 19 ++++++++
6 files changed, 192 insertions(+), 9 deletions(-)
---
diff --git a/src/app-menu.c b/src/app-menu.c
index 974476a..8a51e0e 100644
--- a/src/app-menu.c
+++ b/src/app-menu.c
@@ -23,7 +23,42 @@
#include <config.h>
#include "actions.h"
#include "app-menu.h"
+#include "fr-application.h"
+#include "fr-enum-types.h"
+#include "glib-utils.h"
#include "gtk-utils.h"
+#include "preferences.h"
+
+
+#define GET_ACTION(action_name) (G_SIMPLE_ACTION (g_action_map_lookup_action (G_ACTION_MAP (application), (action_name))))
+
+
+static void
+update_app_menu_sensitivity (GApplication *application)
+{
+ GVariant *state;
+ FrWindowListMode list_mode;
+
+ state = g_action_get_state (G_ACTION (GET_ACTION (PREF_LISTING_LIST_MODE)));
+ list_mode = _g_enum_type_get_value_by_nick (FR_TYPE_WINDOW_LIST_MODE, g_variant_get_string (state, NULL))->value;
+ g_variant_unref (state);
+
+ g_simple_action_set_enabled (GET_ACTION (PREF_UI_VIEW_FOLDERS), list_mode == FR_WINDOW_LIST_MODE_AS_DIR);
+}
+
+
+static void
+toggle_action_activated (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer data)
+{
+ GVariant *state;
+
+ state = g_action_get_state (G_ACTION (action));
+ g_action_change_state (G_ACTION (action), g_variant_new_boolean (! g_variant_get_boolean (state)));
+
+ g_variant_unref (state);
+}
static void
@@ -41,6 +76,38 @@ activate_new (GSimpleAction *action,
static void
+activate_view_folders (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ FrApplication *application = user_data;
+ GSettings *settings;
+
+ settings = fr_application_get_settings (application, FILE_ROLLER_SCHEMA_UI);
+ g_settings_set_boolean (settings, PREF_UI_VIEW_FOLDERS, g_variant_get_boolean (parameter));
+}
+
+
+static void
+activate_list_mode (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ FrApplication *application = user_data;
+ GSettings *settings;
+ FrWindowListMode list_mode;
+
+ g_simple_action_set_state (action, g_variant_new_string (g_variant_get_string (parameter, NULL)));
+ list_mode = _g_enum_type_get_value_by_nick (FR_TYPE_WINDOW_LIST_MODE, g_variant_get_string (parameter, NULL))->value;
+
+ settings = fr_application_get_settings (application, FILE_ROLLER_SCHEMA_LISTING);
+ g_settings_set_enum (settings, PREF_LISTING_LIST_MODE, list_mode);
+ g_settings_set_boolean (settings, PREF_LISTING_SHOW_PATH, list_mode == FR_WINDOW_LIST_MODE_FLAT);
+ update_app_menu_sensitivity (G_APPLICATION (application));
+}
+
+
+static void
activate_help (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
@@ -79,23 +146,46 @@ activate_quit (GSimpleAction *action,
static const GActionEntry app_menu_entries[] = {
{ "new", activate_new },
+ { PREF_UI_VIEW_FOLDERS, toggle_action_activated, NULL, "true", activate_view_folders },
+ { PREF_LISTING_LIST_MODE, activate_list_mode, "s", "'as-dir'", NULL },
{ "help", activate_help },
{ "about", activate_about },
{ "quit", activate_quit }
};
+static void
+pref_view_folders_changed (GSettings *settings,
+ const char *key,
+ gpointer user_data)
+{
+ GApplication *application = user_data;
+
+ g_simple_action_set_state (GET_ACTION (PREF_UI_VIEW_FOLDERS),
+ g_variant_new_boolean (g_settings_get_boolean (settings, PREF_UI_VIEW_FOLDERS)));
+ update_app_menu_sensitivity (application);
+}
+
+
+static void
+pref_list_mode_changed (GSettings *settings,
+ const char *key,
+ gpointer user_data)
+{
+ GApplication *application = user_data;
+
+ g_simple_action_set_state (GET_ACTION (PREF_LISTING_LIST_MODE),
+ g_variant_new_string (_g_enum_type_get_value (FR_TYPE_WINDOW_LIST_MODE,
+ g_settings_get_enum (settings, PREF_LISTING_LIST_MODE))->value_nick));
+ update_app_menu_sensitivity (application);
+}
+
+
void
initialize_app_menu (GApplication *application)
{
- gboolean show_app_menu;
GtkBuilder *builder;
-
- g_object_get (gtk_settings_get_default (),
- "gtk-shell-shows-app-menu", &show_app_menu,
- NULL);
- if (! show_app_menu)
- return;
+ GSettings *settings;
g_action_map_add_action_entries (G_ACTION_MAP (application),
app_menu_entries,
@@ -105,6 +195,23 @@ initialize_app_menu (GApplication *application)
builder = _gtk_builder_new_from_resource ("app-menu.ui");
gtk_application_set_app_menu (GTK_APPLICATION (application),
G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu")));
-
g_object_unref (builder);
+
+ settings = fr_application_get_settings (FR_APPLICATION (application), FILE_ROLLER_SCHEMA_UI);
+ g_simple_action_set_state (GET_ACTION (PREF_UI_VIEW_FOLDERS),
+ g_variant_new_boolean (g_settings_get_boolean (settings, PREF_UI_VIEW_FOLDERS)));
+
+ settings = fr_application_get_settings (FR_APPLICATION (application), FILE_ROLLER_SCHEMA_LISTING);
+ g_simple_action_set_state (GET_ACTION (PREF_LISTING_LIST_MODE),
+ g_variant_new_string (_g_enum_type_get_value (FR_TYPE_WINDOW_LIST_MODE,
+ g_settings_get_enum (settings, PREF_LISTING_LIST_MODE))->value_nick));
+
+ g_signal_connect (fr_application_get_settings (FR_APPLICATION (application), FILE_ROLLER_SCHEMA_UI),
+ "changed::" PREF_UI_VIEW_FOLDERS,
+ G_CALLBACK (pref_view_folders_changed),
+ application);
+ g_signal_connect (fr_application_get_settings (FR_APPLICATION (application), FILE_ROLLER_SCHEMA_LISTING),
+ "changed::" PREF_LISTING_LIST_MODE,
+ G_CALLBACK (pref_list_mode_changed),
+ application);
}
diff --git a/src/fr-window.c b/src/fr-window.c
index e643822..0b151ee 100644
--- a/src/fr-window.c
+++ b/src/fr-window.c
@@ -5090,6 +5090,17 @@ pref_show_field_changed (GSettings *settings,
static void
+pref_list_mode_changed (GSettings *settings,
+ const char *key,
+ gpointer user_data)
+{
+ FrWindow *window = user_data;
+
+ fr_window_set_list_mode (window, g_settings_get_enum (settings, key));
+}
+
+
+static void
pref_click_policy_changed (GSettings *settings,
const char *key,
gpointer user_data)
@@ -5906,6 +5917,10 @@ fr_window_construct (FrWindow *window)
"changed::" PREF_LISTING_SHOW_PATH,
G_CALLBACK (pref_show_field_changed),
window);
+ g_signal_connect (window->priv->settings_listing,
+ "changed::" PREF_LISTING_LIST_MODE,
+ G_CALLBACK (pref_list_mode_changed),
+ window);
if (window->priv->settings_nautilus)
g_signal_connect (window->priv->settings_nautilus,
@@ -7152,6 +7167,9 @@ fr_window_set_list_mode (FrWindow *window,
{
g_return_if_fail (window != NULL);
+ if (list_mode == window->priv->list_mode)
+ return;
+
window->priv->list_mode = window->priv->last_list_mode = list_mode;
if (window->priv->list_mode == FR_WINDOW_LIST_MODE_FLAT) {
fr_window_history_clear (window);
diff --git a/src/glib-utils.c b/src/glib-utils.c
index 119edf4..8f086d4 100644
--- a/src/glib-utils.c
+++ b/src/glib-utils.c
@@ -79,6 +79,38 @@ _g_object_list_unref (GList *list)
g_list_free (list);
}
+/* enum */
+
+
+GEnumValue *
+_g_enum_type_get_value (GType enum_type,
+ int value)
+{
+ GEnumClass *class;
+ GEnumValue *enum_value;
+
+ class = G_ENUM_CLASS (g_type_class_ref (enum_type));
+ enum_value = g_enum_get_value (class, value);
+ g_type_class_unref (class);
+
+ return enum_value;
+}
+
+
+GEnumValue *
+_g_enum_type_get_value_by_nick (GType enum_type,
+ const char *nick)
+{
+ GEnumClass *class;
+ GEnumValue *enum_value;
+
+ class = G_ENUM_CLASS (g_type_class_ref (enum_type));
+ enum_value = g_enum_get_value_by_nick (class, nick);
+ g_type_class_unref (class);
+
+ return enum_value;
+}
+
/* error */
diff --git a/src/glib-utils.h b/src/glib-utils.h
index c409ea1..64f4821 100644
--- a/src/glib-utils.h
+++ b/src/glib-utils.h
@@ -52,6 +52,13 @@ void _g_clear_object (gpointer p);
GList * _g_object_list_ref (GList *list);
void _g_object_list_unref (GList *list);
+/* enum */
+
+GEnumValue * _g_enum_type_get_value (GType enum_type,
+ int value);
+GEnumValue * _g_enum_type_get_value_by_nick (GType enum_type,
+ const char *nick);
+
/* error */
void _g_error_free (GError *error);
diff --git a/src/typedefs.h b/src/typedefs.h
index 12a5e4a..b69f28c 100644
--- a/src/typedefs.h
+++ b/src/typedefs.h
@@ -42,7 +42,7 @@ typedef enum { /*< skip >*/
FR_WINDOW_SORT_BY_PATH = 4
} FrWindowSortMethod;
-typedef enum { /*< skip >*/
+typedef enum {
FR_WINDOW_LIST_MODE_FLAT,
FR_WINDOW_LIST_MODE_AS_DIR
} FrWindowListMode;
diff --git a/src/ui/app-menu.ui b/src/ui/app-menu.ui
index ab10fb3..cd43381 100644
--- a/src/ui/app-menu.ui
+++ b/src/ui/app-menu.ui
@@ -7,6 +7,25 @@
</item>
</section>
<section>
+ <attribute name="label" translatable="yes">List Mode</attribute>
+ <item>
+ <attribute name="label" translatable="yes">View All _Files</attribute>
+ <attribute name="action">app.list-mode</attribute>
+ <attribute name="target">flat</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">View as a F_older</attribute>
+ <attribute name="action">app.list-mode</attribute>
+ <attribute name="target">as-dir</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name="action">app.view-folders</attribute>
+ <attribute name="label" translatable="yes">_Folders</attribute>
+ </item>
+ </section>
+ <section>
<item>
<attribute name="action">app.help</attribute>
<attribute name="label" translatable="yes">_Help</attribute>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]