[baobab/wip/vala: 15/53] Implement Drag and Drop.
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [baobab/wip/vala: 15/53] Implement Drag and Drop.
- Date: Thu, 5 Apr 2012 22:02:49 +0000 (UTC)
commit c9c5e0fc120d2bd4d69bcdfe6c6c1aee00ecd7ee
Author: Paolo Borelli <pborelli gnome org>
Date: Fri Jan 6 10:51:56 2012 +0100
Implement Drag and Drop.
Start scanning when a directory uri is dropped on the window.
src/baobab-window.vala | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 48 insertions(+), 0 deletions(-)
---
diff --git a/src/baobab-window.vala b/src/baobab-window.vala
index d6c8703..29cdf4b 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -1,6 +1,7 @@
/* Baobab - disk usage analyzer
*
* Copyright (C) 2012 Ryan Lortie <desrt desrt ca>
+ * Copyright (C) 2012 Paolo Borelli <pborelli gnome org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -23,6 +24,14 @@ namespace Baobab {
Chart rings_chart;
Chart treemap;
+ enum DndTargets {
+ URI_LIST
+ }
+
+ const Gtk.TargetEntry dnd_target_list[1] = {
+ {"text/uri-list", 0, DndTargets.URI_LIST}
+ };
+
public Window (Application app) {
Object (application: app);
@@ -53,6 +62,10 @@ namespace Baobab {
var statusbar = builder.get_object ("statusbar") as Gtk.Widget;
statusbar.visible = ui_settings.get_boolean ("statusbar-visible");
+ // Setup drag-n-drop
+ drag_data_received.connect(on_drag_data_received);
+ enable_drop ();
+
// Go live.
add (builder.get_object ("window-contents") as Gtk.Widget);
title = _("Disk Usage Analyzer");
@@ -84,6 +97,37 @@ namespace Baobab {
print ("r\n");
}
+ void on_drag_data_received (Gtk.Widget widget, Gdk.DragContext context, int x, int y,
+ Gtk.SelectionData selection_data, uint target_type, uint time) {
+ File dir = null;
+
+ if ((selection_data != null) && (selection_data.get_length () >= 0) && (target_type == DndTargets.URI_LIST)) {
+ var uris = GLib.Uri.list_extract_uris ((string) selection_data.get_data ());
+ if (uris != null && uris.length == 1) {
+ dir = File.new_for_uri (uris[0]);
+ }
+ }
+
+ if (dir != null) {
+ // finish drop before scanning, since the it can time out
+ Gtk.drag_finish (context, true, false, time);
+ scan_directory (dir);
+ } else {
+ Gtk.drag_finish (context, false, false, time);
+ }
+ }
+
+ void enable_drop () {
+ Gtk.drag_dest_set (this,
+ Gtk.DestDefaults.DROP | Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
+ dnd_target_list,
+ Gdk.DragAction.COPY);
+ }
+
+ void disable_drop () {
+ Gtk.drag_dest_unset (this);
+ }
+
private const GLib.ActionEntry[] action_entries = {
{ "scan-home", scan_home_activated },
{ "scan-filesystem", scan_filesystem_activated },
@@ -158,10 +202,14 @@ namespace Baobab {
return;
}
+ disable_drop ();
+
var scanner = new ThreadedScanner ();
scanner.scan (directory);
set_model (scanner);
+
+ enable_drop ();
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]