spek

Acoustic spectrum analyser
git clone http://git.hanabi.in/repos/spek.git
Log | Files | Refs | README

commit 9f381eb03c8db4be403b8c505adbcabe29f81778
parent dcec7595f7b55c829d22d0c04c7179f591e1c9e6
Author: Alexander Kojevnikov <alexander@kojevnikov.com>
Date:   Sun, 19 Aug 2012 14:39:17 -0700

Drag'n'drop files

Diffstat:
Msrc/spek-window.cc | 51++++++++++++++++++++++++++++++++++++---------------
Msrc/spek-window.hh | 2+-
Msrc/spek-window.vala | 18------------------
3 files changed, 37 insertions(+), 34 deletions(-)

diff --git a/src/spek-window.cc b/src/spek-window.cc @@ -17,6 +17,7 @@ */ #include <wx/artprov.h> +#include <wx/dnd.h> #include <wx/filename.h> #include "spek-spectrogram.hh" @@ -31,6 +32,24 @@ BEGIN_EVENT_TABLE(SpekWindow, wxFrame) EVT_MENU(wxID_ABOUT, SpekWindow::on_about) END_EVENT_TABLE() +class SpekDropTarget : public wxFileDropTarget +{ +public: + SpekDropTarget(SpekWindow *window) : wxFileDropTarget(), window(window) {} + +protected: + virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames){ + if (filenames.GetCount() == 1) { + window->open(filenames[0]); + return true; + } + return false; + } + +private: + SpekWindow *window; +}; + SpekWindow::SpekWindow(const wxString& path) : path(path), wxFrame(NULL, -1, wxEmptyString) { @@ -85,6 +104,23 @@ SpekWindow::SpekWindow(const wxString& path) : if (!path.IsEmpty()) { open(path); } + + SetDropTarget(new SpekDropTarget(this)); +} + +void SpekWindow::open(const wxString& path) +{ + wxFileName file_name(path); + if (file_name.FileExists()) { + this->path = path; + wxString full_name = file_name.GetFullName(); + // TRANSLATORS: window title, %s is replaced with the file name + wxString title = wxString::Format(_("Spek - %s"), full_name.c_str()); + // TODO: make sure the above works on all platforms, both in x32 and x64. + SetTitle(title); + + this->spectrogram->open(path); + } } // TODO: s/audio/media/ @@ -206,18 +242,3 @@ void SpekWindow::on_preferences(wxCommandEvent& WXUNUSED(event)) void SpekWindow::on_about(wxCommandEvent& WXUNUSED(event)) { } - -void SpekWindow::open(const wxString& path) -{ - wxFileName file_name(path); - if (file_name.FileExists()) { - this->path = path; - wxString full_name = file_name.GetFullName(); - // TRANSLATORS: window title, %s is replaced with the file name - wxString title = wxString::Format(_("Spek - %s"), full_name.c_str()); - // TODO: make sure the above works on all platforms, both in x32 and x64. - SetTitle(title); - - this->spectrogram->open(path); - } -} diff --git a/src/spek-window.hh b/src/spek-window.hh @@ -27,6 +27,7 @@ class SpekWindow : public wxFrame { public: SpekWindow(const wxString& path); + void open(const wxString& path); private: void on_open(wxCommandEvent& event); @@ -34,7 +35,6 @@ private: void on_exit(wxCommandEvent& event); void on_preferences(wxCommandEvent& event); void on_about(wxCommandEvent& event); - void open(const wxString& path); SpekSpectrogram *spectrogram; wxString path; diff --git a/src/spek-window.vala b/src/spek-window.vala @@ -57,30 +57,12 @@ namespace Spek { show (); - // Set up Drag and Drop - drag_dest_set (this, DestDefaults.ALL, DEST_TARGET_ENTRIES, DragAction.COPY); - drag_data_received.connect (on_dropped); - try { Thread.create<void*> (check_version, false); } catch (ThreadError e) { } } - void on_dropped (DragContext cx, int x, int y, SelectionData data, uint info, uint time) { - if (data.get_length () > 0 && data.get_format () == 8) { - string[] files = data.get_uris (); - if (files.length > 0) { - try { - open_file (Filename.from_uri (files[0])); - drag_finish (cx, true, false, time); - return; - } catch (ConvertError e) {} - } - } - drag_finish (cx, false, false, time); - } - private void on_edit_preferences () { var dlg = new PreferencesDialog (); dlg.transient_for = this;