From 65eac8b08ddeda1824f1c53a7de7b87b0616393d Mon Sep 17 00:00:00 2001 From: Thomas Jollans Date: Mon, 10 Sep 2012 00:34:54 +0200 Subject: [PATCH] New module: preferences dialog (unfinished) --- configure.ac | 1 + data/config.json | 3 +- po/POTFILES.in | 4 + po/POTFILES.skip | 2 + src/modules/Makefile.am | 1 + src/modules/module.mk | 1 + src/modules/preferences/Makefile.am | 13 + src/modules/preferences/columns.vala | 167 +++++ src/modules/preferences/preferences.module.in | 4 + src/modules/preferences/preferences.vala | 130 ++++ src/modules/preferences/prefs_dialog.ui | 619 ++++++++++++++++++ 11 files changed, 944 insertions(+), 1 deletion(-) create mode 100644 src/modules/preferences/Makefile.am create mode 100644 src/modules/preferences/columns.vala create mode 100644 src/modules/preferences/preferences.module.in create mode 100644 src/modules/preferences/preferences.vala create mode 100644 src/modules/preferences/prefs_dialog.ui diff --git a/configure.ac b/configure.ac index 50f62c3..3b6800b 100644 --- a/configure.ac +++ b/configure.ac @@ -122,6 +122,7 @@ AC_CONFIG_FILES([Makefile po/Makefile.in src/modules/filters/Makefile src/modules/monitor_directory/Makefile src/modules/netmenu/Makefile + src/modules/preferences/Makefile src/modules/preview/Makefile src/modules/quick_filter/Makefile src/modules/sort/Makefile diff --git a/data/config.json b/data/config.json index 236f2c1..e489938 100644 --- a/data/config.json +++ b/data/config.json @@ -13,7 +13,8 @@ "externalist", "preview", "quick_filter", - "command_button_bar" + "command_button_bar", + "preferences" ] }, "user-interface": { diff --git a/po/POTFILES.in b/po/POTFILES.in index 241a176..9f25f4d 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -27,6 +27,9 @@ src/modules/file_transfer/file_transfer.vala src/modules/filters/filters.vala src/modules/monitor_directory/monitor_directory.vala src/modules/netmenu/netmenu.vala +src/modules/preferences/preferences.vala +src/modules/preferences/columns.vala +src/modules/preferences/prefs_dialog.ui src/modules/preview/preview.vala src/modules/quick_filter/quick_filter.vala src/modules/sort/sort.vala @@ -40,6 +43,7 @@ src/modules/volume_toolbar/volume_toolbar.vala [type: gettext/ini]src/modules/filters/filters.module.in [type: gettext/ini]src/modules/monitor_directory/monitor_directory.module.in [type: gettext/ini]src/modules/netmenu/netmenu.module.in +[type: gettext/ini]src/modules/preferences/preferences.module.in [type: gettext/ini]src/modules/preview/preview.module.in [type: gettext/ini]src/modules/quick_filter/quick_filter.module.in [type: gettext/ini]src/modules/sort/sort.module.in diff --git a/po/POTFILES.skip b/po/POTFILES.skip index faa46a8..a770b90 100644 --- a/po/POTFILES.skip +++ b/po/POTFILES.skip @@ -25,6 +25,8 @@ src/modules/volume_toolbar/volume_toolbar.c src/modules/externalist/externalist.c src/modules/sort/sort.c src/modules/basic_columns/basic_columns.c +src/modules/preferences/preferences.c +src/modules/preferences/columns.c src/modules/preview/preview.c src/modules/command_button_bar/command_button_bar.c src/modules/file_pane_title_bar/file_pane_title_bar.c diff --git a/src/modules/Makefile.am b/src/modules/Makefile.am index 4695b46..9d0ac01 100644 --- a/src/modules/Makefile.am +++ b/src/modules/Makefile.am @@ -8,6 +8,7 @@ SUBDIRS = \ filters \ monitor_directory \ netmenu \ + preferences \ preview \ quick_filter \ sort \ diff --git a/src/modules/module.mk b/src/modules/module.mk index 55d22f7..0cf0e87 100644 --- a/src/modules/module.mk +++ b/src/modules/module.mk @@ -2,5 +2,6 @@ AM_CFLAGS=@GLOBAL_CFLAGS@ @EMPEROREXT_CFLAGS@ AM_VALAFLAGS=@EMPEROREXT_VALAFLAGS@ AM_LDFLAGS=-avoid-version moduledir=$(pkglibdir) +resdir = $(pkgdatadir)/res %.module: %.module.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache diff --git a/src/modules/preferences/Makefile.am b/src/modules/preferences/Makefile.am new file mode 100644 index 0000000..92a54ee --- /dev/null +++ b/src/modules/preferences/Makefile.am @@ -0,0 +1,13 @@ +include $(srcdir)/../module.mk + +module_in_files = preferences.module.in +module_files = $(module_in_files:.module.in=.module) +module_DATA = $(module_files) + +res_DATA = prefs_dialog.ui + +module_LTLIBRARIES = libpreferences.la +libpreferences_la_SOURCES = preferences.vala columns.vala + +EXTRA_DIST = $(module_in_files) $(res_DATA) +CLEANFILES = $(module_files) diff --git a/src/modules/preferences/columns.vala b/src/modules/preferences/columns.vala new file mode 100644 index 0000000..376d800 --- /dev/null +++ b/src/modules/preferences/columns.vala @@ -0,0 +1,167 @@ +/* Emperor - an orthodox file manager for the GNOME desktop + * Copyright (C) 2012 Thomas Jollans + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +using GLib; +using Gtk; +using Gee; +using Emperor.App; + +namespace Emperor.Modules { + + public class ColumnPrefs : Object + { + public EmperorCore app { get; construct; } + public Preferences prefs { get; construct; } + public TreeView column_list_view { get; construct; } + public ListStore column_list { get; construct; } + public Json.Parser col_types_parser { get; construct; } + + int m_count = 0; + + public + ColumnPrefs (Preferences prefs) + throws ConfigurationError + { + var col_list = prefs.builder.get_object ("lstColumns") as ListStore; + var col_view = prefs.builder.get_object ("columnList") as TreeView; + + Json.Parser parser; + try { + parser = new Json.Parser (); + var coltypes_filename = prefs.app.get_config_file_path ("column-types.json"); + parser.load_from_file (coltypes_filename); + } catch (Error e) { + throw new ConfigurationError.PARSE_ERROR (e.message); + } + + Object ( app : prefs.app, + prefs : prefs, + column_list : col_list, + column_list_view : col_view, + col_types_parser : parser ); + } + + construct { + // get all columns and add them to the ListStore + var added_columns = new HashMap (); + + var col_cfg_node = app.config["user-interface"]["file-pane-columns"]; + + foreach (var node in col_cfg_node.get_array ().get_elements ()) { + if (node.get_value_type () == typeof (string)) { + var name = node.get_string (); + TreeIter iter; + column_list.append (out iter); + column_list.set (iter, 0, true, // active + 1, name, // name + -1); + added_columns[name] = iter; + m_count ++; + } + } + + var col_types_object = col_types_parser.get_root ().get_object (); + + foreach (var col_name in col_types_object.get_members ()) { + var col_def = col_types_object.get_object_member (col_name); + TreeIter iter; + if (added_columns.has_key (col_name)) { + iter = added_columns[col_name]; + } else { + column_list.append (out iter); + column_list.set (iter, 0, false, // inactive + 1, col_name, // name + -1); + m_count ++; + } + column_list.set (iter, 2, _(col_def.get_string_member ("title")), + 3, _(col_def.get_string_member ("description")), + -1); + } + + prefs.apply.connect (apply); + } + + public void + move_column_up () + { + TreeModel model; + TreeIter iter; + column_list_view.get_selection ().get_selected (out model, out iter); + + assert (model == column_list); + + TreeIter prev = iter; + if (column_list.iter_previous (ref prev)) { + column_list.swap (iter, prev); + } + } + + public void + move_column_down () + { + TreeModel model; + TreeIter iter; + column_list_view.get_selection ().get_selected (out model, out iter); + + assert (model == column_list); + + TreeIter next = iter; + if (column_list.iter_next (ref next)) { + column_list.swap (iter, next); + } + } + + public void + column_active_toggled (CellRendererToggle cellrenderer, string path_string) + { + TreeIter iter; + column_list.get_iter_from_string (out iter, path_string); + + bool active; + column_list.get (iter, 0, out active, -1); + active = !active; + column_list.set (iter, 0, active, -1); + } + + public void + apply () + { + var array = new Json.Array (); + + TreeIter iter; + if (!column_list.get_iter_first (out iter)) { + return; + } + + do { + bool active; + string name; + column_list.get (iter, 0, out active, + 1, out name, + -1); + if (active) { + array.add_string_element (name); + } + } while (column_list.iter_next (ref iter)); + + var json_node = new Json.Node (Json.NodeType.ARRAY); + json_node.set_array (array); + app.config["user-interface"]["file-pane-columns"] = json_node; + } + } +} \ No newline at end of file diff --git a/src/modules/preferences/preferences.module.in b/src/modules/preferences/preferences.module.in new file mode 100644 index 0000000..f010a14 --- /dev/null +++ b/src/modules/preferences/preferences.module.in @@ -0,0 +1,4 @@ +[Emperor Module] +_Name=Preferences dialog +_Description=Configure Emperor using a graphical interface +Module=preferences diff --git a/src/modules/preferences/preferences.vala b/src/modules/preferences/preferences.vala new file mode 100644 index 0000000..744b8ce --- /dev/null +++ b/src/modules/preferences/preferences.vala @@ -0,0 +1,130 @@ +/* Emperor - an orthodox file manager for the GNOME desktop + * Copyright (C) 2012 Thomas Jollans + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +using GLib; +using Gtk; +using Gee; +using Emperor.App; + +namespace Emperor.Modules { + + // Use the annotation for pretty signal handler names + [CCode (cprefix = "prefs_")] + public class Preferences : Object + { + public EmperorCore app { get; construct; } + public Gtk.Builder builder { get; construct; } + public Window dialog_window { get; construct; } + + public ColumnPrefs column_prefs { get; private set; } + + public + Preferences (EmperorCore app) + throws Error + { + var builder = new Gtk.Builder (); + builder.add_from_file (app.get_resource_file_path ("prefs_dialog.ui")); + var dialog_window = builder.get_object ("configDialog") as Window; + + Object ( app : app, + builder : builder, + dialog_window : dialog_window ); + } + + construct { + builder.connect_signals (this); + dialog_window.application = app; + dialog_window.transient_for = app.main_window; + + try { + column_prefs = new ColumnPrefs (this); + } catch (ConfigurationError cerr) { + error (_("Error loading preferences dialog.")); + } + } + + [CCode (cname = "load_module")] + public static void + load_module (ModuleRegistry reg) + { + var app = reg.application; + + app.ui_manager.get_menu (_("_Tools"), 4); + + var prefs_action = reg.new_action ("preferences"); + prefs_action.label = _("_Preferences"); + app.ui_manager.add_action_to_menu (_("_Tools"), prefs_action, 90); + + prefs_action.activate.connect ( () => { + // Create preferences dialog + try { + var prefs = new Preferences (app); + prefs.show_preferences_dialog (); + } catch (Error err) { + error (_("Error loading preferences dialog.")); + } + }); + } + + public void + show_preferences_dialog () + { + dialog_window.show_all (); + this.@ref (); + } + + [CCode (instance_pos = -1)] + public void + close_dialog (Button source) + { + apply (); + dialog_window.destroy (); + } + + public signal void apply (); + + [CCode (instance_pos = -1)] + public void + on_configDialog_destroy () + { + this.unref (); + } + + [CCode (instance_pos = -1)] + public void + move_column_up (Button source) + { + column_prefs.move_column_up (); + } + + [CCode (instance_pos = -1)] + public void + move_column_down (Button source) + { + column_prefs.move_column_down (); + } + + [CCode (instance_pos = -1)] + public void + column_active_toggled (CellRendererToggle cellrenderer, string path) + { + column_prefs.column_active_toggled (cellrenderer, path); + } + + } + +} diff --git a/src/modules/preferences/prefs_dialog.ui b/src/modules/preferences/prefs_dialog.ui new file mode 100644 index 0000000..6091774 --- /dev/null +++ b/src/modules/preferences/prefs_dialog.ui @@ -0,0 +1,619 @@ + + + + + True + False + gtk-go-up + + + True + False + gtk-go-down + + + False + Preferences + True + center-on-parent + 500 + 350 + True + dialog + + + + True + False + 10 + 10 + 10 + 10 + vertical + + + True + True + + + True + False + 5 + 5 + 5 + 5 + + + True + True + in + + + True + True + lstColumns + False + + + + + + + + #000000000000 + rgba(0,0,0,0) + 2 + 2 + + + + 0 + + + + + + + + + 600 + + + 2 + + + + + + + + + + 3 + + + + + + + + + True + True + 0 + + + + + True + False + vertical + start + + + Move Up + False + True + True + True + False + image1 + + + + False + True + 0 + + + + + Move Down + False + True + True + True + False + image2 + + + + False + True + 1 + + + + + False + True + 1 + + + + + + + True + False + Columns + + + False + + + + + True + False + 5 + 5 + 5 + 5 + vertical + 5 + + + True + False + 0 + Selection mode + + + + + + False + True + 0 + + + + + True + False + selectionModes + + + + + 1 + + + + + False + True + 1 + + + + + True + False + 0 + 20 + 10 + fill + True + + + False + True + 2 + + + + + 1 + + + + + True + False + Mouse + + + 1 + False + + + + + True + True + 5 + 5 + 5 + 5 + + + True + False + 5 + 5 + 5 + 5 + vertical + + + True + True + in + + + True + False + + + + + + + + True + True + 0 + + + + + True + False + end + + + gtk-add + False + True + True + True + False + True + + + + False + True + 0 + + + + + False + True + 1 + + + + + + + True + False + Viewers + + + False + + + + + True + False + 5 + 5 + 5 + 5 + vertical + + + True + True + in + + + True + False + + + + + + + + True + True + 0 + + + + + True + False + end + + + gtk-add + False + True + True + True + False + True + + + + False + True + 0 + + + + + False + True + 1 + + + + + 1 + + + + + True + False + Editors + + + 1 + False + + + + + 2 + + + + + True + False + center + Applications + + + 2 + False + + + + + True + False + 5 + 5 + 5 + 5 + vertical + + + True + True + filterModules + False + + + + + + + + + 1 + + + + + + + + + + 5 + + + + + + + True + True + 0 + + + + + True + False + + + Show core modules + False + True + True + False + False + 0 + True + + + + False + True + 0 + + + + + gtk-preferences + False + True + False + True + True + False + True + + + + False + True + end + 1 + + + + + False + True + 1 + + + + + 3 + + + + + True + False + Modules + + + 3 + False + + + + + True + True + 0 + + + + + True + False + end + + + gtk-close + False + True + True + True + 10 + False + True + + + + False + True + 0 + + + + + False + True + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + lstModules + + + + + + + + + + + + + 1 + Left mouse button + Every click selects a file. To select multiple files at once, hold the Control or Shift keys. The right mouse button activates a context menu. Double-clicking opens a file. + + + 2 + Right mouse button + Select a file by right-clicking it. Clicking with the left mouse button does not change the selection. Hold the right mouse button pressed to open a context menu. Double-clicking opens a file. + + + +