Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New module: preferences dialog (unfinished)
- Loading branch information
Showing
11 changed files
with
944 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ SUBDIRS = \ | |
filters \ | ||
monitor_directory \ | ||
netmenu \ | ||
preferences \ | ||
preview \ | ||
quick_filter \ | ||
sort \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
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<string,TreeIter?> (); | ||
|
||
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[Emperor Module] | ||
_Name=Preferences dialog | ||
_Description=Configure Emperor using a graphical interface | ||
Module=preferences |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
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); | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.