1
// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-
3
* Copyright (c) 2015-2016 elementary LLC (http://launchpad.net/elementary)
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Library General Public
7
* License as published by the Free Software Foundation; either
8
* version 2 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Library General Public License for more details.
15
* You should have received a copy of the GNU Library General Public
16
* License along with this library; if not, write to the
17
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
* Boston, MA 02111-1307, USA.
20
* Authored by: Corentin Noël <tintou@mailoo.org>
23
namespace Marlin.View.Chrome {
24
public class LocationBar : Gtk.Box {
25
public Breadcrumbs bread;
28
public new string path {
30
var new_path = GLib.Uri.unescape_string (value);
31
if (new_path != null) {
34
if (!bread.is_focus) {
36
bread.change_breadcrumbs (new_path);
39
warning ("Tried to set null path\n");
47
public new signal void activate (GLib.File file);
48
public signal void escape ();
49
public signal void change_to_file (string filename);
51
public override void get_preferred_width (out int minimum_width, out int natural_width) {
56
public LocationBar (Gtk.Widget parent) {
57
bread = new Breadcrumbs ();
58
bread.escape.connect (() => { escape (); });
59
bread.activate_alternate.connect ((file) => {
60
path = "file://" + file.get_path ();
61
change_to_file (file.get_path ());
64
bread.path_changed.connect ((file) => {
65
path = "file://" + file.get_path ();
66
change_to_file (file.get_path ());
74
pack_start (bread, true, true, 0);
78
public class Breadcrumbs : BasePathBar {
81
private bool drop_data_ready = false;
82
private bool drop_occurred = false;
83
private GLib.List<GLib.File> drop_file_list = null;
85
Gdk.DragAction current_suggested_action = 0;
86
Gdk.DragAction current_actions = 0;
90
/* The string split of the path url is kinda too basic,
91
* we should use the GFile to split our uris and determine the protocol (if any) with g_uri_parse_scheme or g_file_get_uri_scheme */
92
add_icon ({ "afp://", Marlin.ICON_FOLDER_REMOTE_SYMBOLIC, true, null, null, null, true, Marlin.PROTOCOL_NAME_AFP});
93
add_icon ({ "dav://", Marlin.ICON_FOLDER_REMOTE_SYMBOLIC, true, null, null, null, true, Marlin.PROTOCOL_NAME_DAV});
94
add_icon ({ "davs://", Marlin.ICON_FOLDER_REMOTE_SYMBOLIC, true, null, null, null, true,Marlin.PROTOCOL_NAME_DAVS});
95
add_icon ({ "ftp://", Marlin.ICON_FOLDER_REMOTE_SYMBOLIC, true, null, null, null, true, Marlin.PROTOCOL_NAME_FTP});
96
add_icon ({ "network://", Marlin.ICON_FOLDER_REMOTE_SYMBOLIC, true, null, null, null, true, Marlin.PROTOCOL_NAME_NETWORK});
97
add_icon ({ "sftp://", Marlin.ICON_FOLDER_REMOTE_SYMBOLIC, true, null, null, null, true, Marlin.PROTOCOL_NAME_SFTP});
98
add_icon ({ "smb://", Marlin.ICON_FOLDER_REMOTE_SYMBOLIC, true, null, null, null, true,Marlin.PROTOCOL_NAME_SMB});
99
add_icon ({ "trash://", Marlin.ICON_TRASH_SYMBOLIC, true, null, null, null, true, Marlin.PROTOCOL_NAME_TRASH});
102
dir = Environment.get_user_special_dir (UserDirectory.MUSIC);
103
if (dir.contains ("/")) {
104
IconDirectory icon = {dir, Marlin.ICON_FOLDER_MUSIC_SYMBOLIC, false, null, null, dir.split ("/"), false, null};
105
icon.exploded[0] = "/";
110
dir = Environment.get_user_special_dir (UserDirectory.PICTURES);
111
if (dir.contains ("/")) {
112
IconDirectory icon = {dir, Marlin.ICON_FOLDER_PICTURES_SYMBOLIC, false, null, null, dir.split ("/"), false, null};
113
icon.exploded[0] = "/";
118
dir = Environment.get_user_special_dir (UserDirectory.VIDEOS);
119
if (dir.contains ("/")) {
120
IconDirectory icon = {dir, Marlin.ICON_FOLDER_VIDEOS_SYMBOLIC, false, null, null, dir.split ("/"), false, null};
121
icon.exploded[0] = "/";
125
dir = Environment.get_user_special_dir (UserDirectory.DOWNLOAD);
126
if (dir.contains ("/")) {
127
IconDirectory icon = {dir, Marlin.ICON_FOLDER_DOWNLOADS_SYMBOLIC, false, null, null, dir.split ("/"), false, null};
128
icon.exploded[0] = "/";
132
dir = Environment.get_user_special_dir (UserDirectory.DOCUMENTS);
133
if (dir.contains ("/")) {
134
IconDirectory icon = {dir, Marlin.ICON_FOLDER_DOCUMENTS_SYMBOLIC, false, null, null, dir.split ("/"), false, null};
135
icon.exploded[0] = "/";
139
dir = Environment.get_user_special_dir (UserDirectory.TEMPLATES);
140
if (dir.contains ("/")) {
141
IconDirectory icon = {dir, Marlin.ICON_FOLDER_TEMPLATES_SYMBOLIC, false, null, null, dir.split ("/"), false, null};
142
icon.exploded[0] = "/";
146
dir = Environment.get_home_dir ();
147
if (dir.contains ("/")) {
148
IconDirectory icon = {dir, Marlin.ICON_GO_HOME_SYMBOLIC, false, null, null, dir.split ("/"), true, null};
149
icon.exploded[0] = "/";
155
if (dir.contains ("/")) {
156
IconDirectory icon = {dir, Marlin.ICON_FILESYSTEM_SYMBOLIC, false, null, null, dir.split ("/"), true, null};
157
icon.exploded[0] = "/";
161
IconDirectory icon = {"/", Marlin.ICON_FILESYSTEM_SYMBOLIC, false, null, null, null, false, null};
162
icon.exploded = {"/"};
165
menu = new Gtk.Menu ();
169
protected override void load_right_click_menu (double x, double y) {
173
protected override bool on_drag_motion (Gdk.DragContext context, int x, int y, uint time) {
174
Gtk.drag_unhighlight (this);
176
foreach (BreadcrumbsElement element in elements)
177
element.pressed = false;
179
var el = get_element_from_coordinates (x, y);
184
/* No action taken on drop */
185
Gdk.drag_status (context, 0, time);
192
protected override bool on_drag_drop (Gdk.DragContext context,
196
Gtk.TargetList list = null;
197
bool ok_to_drop = false;
199
Gdk.Atom target = Gtk.drag_dest_find_target (this, context, list);
201
ok_to_drop = (target != Gdk.Atom.NONE);
204
drop_occurred = true;
205
Gtk.drag_get_data (this, context, target, timestamp);
211
protected override void on_drag_data_received (Gdk.DragContext context,
214
Gtk.SelectionData selection_data,
217
bool success = false;
219
if (!drop_data_ready) {
220
drop_file_list = null;
221
foreach (var uri in selection_data.get_uris ()) {
222
debug ("Path to move: %s\n", uri);
223
drop_file_list.append (File.new_for_uri (uri));
224
drop_data_ready = true;
228
if (drop_data_ready && drop_occurred && info == TargetType.TEXT_URI_LIST) {
229
drop_occurred = false;
231
current_suggested_action = 0;
233
Gtk.drag_finish (context, success, false, timestamp);
234
on_drag_leave (context, timestamp);
238
protected override void on_drag_leave (Gdk.DragContext drag_context, uint time) {
239
foreach (BreadcrumbsElement element in elements) {
240
if (element.pressed) {
241
element.pressed = false;
246
drop_occurred = false;
247
drop_data_ready = false;
248
drop_file_list = null;