mirror of
https://github.com/alexkay/spek.git
synced 2025-06-05 01:43:22 +03:00
DnD support (issue 4)
This commit is contained in:
parent
82b5e2c779
commit
e4e8e6bb23
@ -27,6 +27,9 @@ namespace Spek {
|
|||||||
private FileFilter filter_all;
|
private FileFilter filter_all;
|
||||||
private FileFilter filter_audio;
|
private FileFilter filter_audio;
|
||||||
private FileFilter filter_png;
|
private FileFilter filter_png;
|
||||||
|
private const Gtk.TargetEntry[] DEST_TARGET_ENTRIES = {
|
||||||
|
{ "text/uri-list", 0, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
public Window (string? file_name) {
|
public Window (string? file_name) {
|
||||||
title = _("Spek - Acoustic Spectrum Analyser");
|
title = _("Spek - Acoustic Spectrum Analyser");
|
||||||
@ -96,11 +99,31 @@ namespace Spek {
|
|||||||
add (vbox);
|
add (vbox);
|
||||||
show_all ();
|
show_all ();
|
||||||
|
|
||||||
|
// Set up Drag and Drop
|
||||||
|
drag_dest_set (this, DestDefaults.ALL, DEST_TARGET_ENTRIES, DragAction.COPY);
|
||||||
|
drag_data_received.connect (on_dropped);
|
||||||
|
|
||||||
if (file_name != null) {
|
if (file_name != null) {
|
||||||
open_file (file_name);
|
open_file (file_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void on_dropped (DragContext cx, int x, int y, SelectionData data, uint info, uint time) {
|
||||||
|
if (data.length > 0 && data.format == 8) {
|
||||||
|
string[] files = data.get_uris ();
|
||||||
|
if (files.length > 0) {
|
||||||
|
try {
|
||||||
|
string hostname;
|
||||||
|
var file = filename_from_uri (files[0], out hostname);
|
||||||
|
open_file (file);
|
||||||
|
drag_finish (cx, true, false, time);
|
||||||
|
return;
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
drag_finish (cx, false, false, time);
|
||||||
|
}
|
||||||
|
|
||||||
private void open_file (string file_name) {
|
private void open_file (string file_name) {
|
||||||
cur_dir = Path.get_dirname (file_name);
|
cur_dir = Path.get_dirname (file_name);
|
||||||
spectrogram.open (file_name);
|
spectrogram.open (file_name);
|
||||||
|
@ -14,3 +14,9 @@ namespace Config {
|
|||||||
public const string PKGDATADIR; /* /usr/local/share/spek */
|
public const string PKGDATADIR; /* /usr/local/share/spek */
|
||||||
public const string PKGLIBDIR; /* /usr/local/lib/spek */
|
public const string PKGLIBDIR; /* /usr/local/lib/spek */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: file a bug to have this included
|
||||||
|
[CCode (cprefix = "G", lower_case_cprefix = "g_", cheader_filename = "glib.h", gir_namespace = "GLib", gir_version = "2.0")]
|
||||||
|
namespace GLib {
|
||||||
|
public static string filename_from_uri (string uri, out string hostname) throws Error;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user