2
* Copyright (c) 2015 elementary LLC (http://launchpad.net/elementary)
2
* Copyright (c) 2015-2016 elementary LLC (http://launchpad.net/elementary)
4
4
* This library is free software; you can redistribute it and/or
5
5
* modify it under the terms of the GNU Library General Public
19
19
* Authored by: Adam Bieńkowski <donadigos159@gmail.com>
22
/*** The Gtk.FileChooserWidget widget names and paths can be found in "gtkfilechooserwidget.ui"
23
* in the Gtk+3 source code package. Changes to that file could break this code.
22
25
public class CustomFileChooserDialog : Object {
23
26
private static Gtk.FileChooserDialog chooser_dialog;
24
27
private static Gtk.Widget rootwidget;
32
35
/* Paths to widgets */
33
36
private const string[] GTK_PATHBAR_PATH = { "widget", "browse_widgets_box", "browse_files_box", "browse_header_revealer" };
34
37
private const string[] GTK_FILTERCHOOSER_PATH = { "extra_and_filters", "filter_combo_hbox" };
38
private const string[] GTK_TREEVIEW_PATH = { "browse_files_stack", "browse_files_swin", "browse_files_tree_view" };
35
39
private const string PLACES_SIDEBAR_PATH = "places_sidebar";
37
41
private GLib.Queue<string> previous_paths;
42
46
private string current_path = null;
43
47
private bool is_previous = false;
44
48
private bool is_button_next = false;
49
private bool is_single_click = true;
50
private bool can_activate = true;
46
52
public CustomFileChooserDialog (Gtk.FileChooserDialog dialog) {
47
53
previous_paths = new GLib.Queue<string> ();
131
140
(root as Gtk.Container).get_children ().foreach ((w0) => {
132
141
if (w0.get_name () == GTK_PATHBAR_PATH[0]) {
133
142
/* Add top separator between headerbar and filechooser when is not Save action */
134
var chooserwidget = w0 as Gtk.Container;
135
chooserwidget.vexpand = true;
137
(root as Gtk.Container).remove (w0);
138
var root_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
143
var chooserwidget = w0 as Gtk.Container;
144
chooserwidget.vexpand = true;
146
(root as Gtk.Container).remove (w0);
147
var root_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
148
root_box.add (new Gtk.Separator (Gtk.Orientation.HORIZONTAL));
149
root_box.add (chooserwidget);
151
if (chooser_dialog.get_extra_widget () == null) {
139
152
root_box.add (new Gtk.Separator (Gtk.Orientation.HORIZONTAL));
140
root_box.add (chooserwidget);
142
if (chooser_dialog.get_extra_widget () == null) {
143
root_box.add (new Gtk.Separator (Gtk.Orientation.HORIZONTAL));
146
(root as Gtk.Container).add (root_box);
147
rootwidget = chooserwidget;
149
rootwidget.can_focus = true;
150
transform_rootwidget_container (rootwidget, w0);
155
(root as Gtk.Container).add (root_box);
156
rootwidget = chooserwidget;
158
rootwidget.can_focus = true;
159
transform_rootwidget_container (rootwidget, w0);
224
233
(w2 as Gtk.Container).remove (w3);
234
} else if (w3.get_name () == "list_and_preview_box") { /* file browser list and preview box */
235
var tv = find_tree_view (w3);
237
/* set its click behaviour the same as pantheon-files setting */
238
tv.set_activate_on_single_click (is_single_click);
239
if (is_single_click) {
240
/* We need to modify native behaviour to only activate on folders */
241
tv.add_events (Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK);
242
tv.button_press_event.connect (on_tv_button_press_event);
243
tv.button_release_event.connect (on_tv_button_release_event);
250
private Gtk.TreeView? find_tree_view (Gtk.Widget browser_box) {
251
/* Locate the TreeView */
252
Gtk.TreeView? tv = null;
253
((Gtk.Container)browser_box).get_children ().foreach ((w) => {
254
if (w.get_name () == GTK_TREEVIEW_PATH[0]) {
255
((Gtk.Container)w).get_children ().foreach ((w) => {
256
if (w.name == "GtkBox") {
257
((Gtk.Container)w).get_children ().foreach ((w) => {
258
if (w.get_name () == GTK_TREEVIEW_PATH[1]) {
259
((Gtk.Container)w).get_children ().foreach ((w) => {
260
if (w.get_name () == GTK_TREEVIEW_PATH[2]) {
261
tv = (Gtk.TreeView)w;
229
274
private void assign_container_box () {
266
311
((Gtk.ButtonBox) container_box).set_child_secondary (grid, true);
315
private bool on_tv_button_press_event (Gtk.Widget w, Gdk.EventButton event) {
316
can_activate = false;
317
if (event.type == Gdk.EventType.@2BUTTON_PRESS) {
326
Gtk.TreeView tv = ((Gtk.TreeView)(w));
327
Gtk.TreePath? path = null;
330
tv.get_path_at_pos ((int)(event.x), (int)(event.y), out path, null, out cell_x, out cell_y);
333
var model = tv.get_model ();
334
Gtk.TreeIter? iter = null;
335
if (model.get_iter (out iter, path)) {
337
model.@get (iter, 5, out is_folder);
347
private bool on_tv_button_release_event (Gdk.EventButton event) {
348
return !can_activate;