mirror of
https://github.com/alexkay/spek.git
synced 2025-04-16 16:42:19 +03:00
Drag'n'drop files
This commit is contained in:
parent
dcec7595f7
commit
9f381eb03c
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user