From 4e6b527570345ec9cc4149a49fa6ce8b17cf4c8a Mon Sep 17 00:00:00 2001 From: guillaume Date: Thu, 19 Nov 2009 07:12:08 +0000 Subject: [PATCH] Support for drag-and-drop of a file in the query tool. git-svn-id: svn://svn.pgadmin.org/trunk/pgadmin3@8080 a7884b65-44f6-0310-8a51-81a127f17b15 --- CHANGELOG | 1 + pgadmin/frm/frmQuery.cpp | 41 ++++++++++++++++++++++++++++++++ pgadmin/include/dlg/dlgClasses.h | 5 ++-- pgadmin/include/frm/frmQuery.h | 11 ++++++--- 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index c281145ba..fdf5eb703 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -36,6 +36,7 @@ Changes Date Dev Ver Change details ---------- --- ------ -------------- +2009-11-19 GL 1.12.0 Support for drag-and-drop of a file in the query tool. 2009-11-16 GL 1.10.1 Fix an issue with the ordering of the mappings in a text search configuration. 2009-10-28 DP 1.12.0 Extend the branding code to allow the vendor-specific diff --git a/pgadmin/frm/frmQuery.cpp b/pgadmin/frm/frmQuery.cpp index a97f7cb9c..f93926e03 100644 --- a/pgadmin/frm/frmQuery.cpp +++ b/pgadmin/frm/frmQuery.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -151,6 +152,45 @@ EVT_NOTEBOOK_PAGE_CHANGED(CTL_NTBKCENTER, frmQuery::OnChangeNotebook) EVT_SPLITTER_SASH_POS_CHANGED(GQB_HORZ_SASH, frmQuery::OnResizeHorizontally) END_EVENT_TABLE() +class DnDFile : public wxFileDropTarget +{ + public: + DnDFile(frmQuery * fquery) { m_fquery = fquery; } + + virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames) + { + size_t nFiles = filenames.GetCount(); + if ((int) nFiles > 1) + wxLogError(wxT("Drag one file at a time")); + else if ((int) nFiles == 1) + { + wxString str; + bool modeUnicode = settings->GetUnicodeFile(); + wxUtfFile file(filenames[0], wxFile::read, modeUnicode ? wxFONTENCODING_UTF8:wxFONTENCODING_DEFAULT); + + if (file.IsOpened()) + file.Read(str); + + if (!str.IsEmpty() && !m_fquery->CheckChanged(true)) + { + m_fquery->SetLastPath(filenames[0]); + m_fquery->SetQueryText(str); + m_fquery->ColouriseQuery(0, str.Length()); + wxSafeYield(); // needed to process sqlQuery modify event + m_fquery->SetChanged(false); + m_fquery->setExtendedTitle(); + m_fquery->SetLineEndingStyle(); + m_fquery->UpdateRecentFiles(); + } + } + return true; + } + + private: + frmQuery * m_fquery; +}; + + frmQuery::frmQuery(frmMain *form, const wxString& _title, pgConn *_conn, const wxString& query, const wxString& file) : pgFrame(NULL, _title), timer(this,CTL_TIMERFRM), @@ -359,6 +399,7 @@ pgsTimer(new pgScriptTimer(this)) sqlQuery = new ctlSQLBox(sqlNotebook, CTL_SQLQUERY, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxSIMPLE_BORDER | wxTE_RICH2); sqlQuery->SetDatabase(conn); sqlQuery->SetMarginWidth(1, 16); + sqlQuery->SetDropTarget(new DnDFile(this)); SetEOLModeDisplay(sqlQuery->GetEOLMode()); // Results pane diff --git a/pgadmin/include/dlg/dlgClasses.h b/pgadmin/include/dlg/dlgClasses.h index 0b50f99c0..5f878b6cb 100644 --- a/pgadmin/include/dlg/dlgClasses.h +++ b/pgadmin/include/dlg/dlgClasses.h @@ -59,6 +59,9 @@ public: void RestorePosition(int defaultX=-1, int defaultY=-1, int defaultW=-1, int defaultH=-1, int minW=100, int minH=70); void SavePosition(); void OnAction(wxCommandEvent& event); + + void UpdateRecentFiles(); + menuFactoryList *GetMenuFactories() { return menuFactories; } protected: @@ -72,8 +75,6 @@ protected: virtual bool CheckChanged(bool canVeto) { return false; } virtual wxString GetHelpPage() const { return wxEmptyString; } - void UpdateRecentFiles(); - windowList frames; menuFactoryList *menuFactories; wxString dlgName; diff --git a/pgadmin/include/frm/frmQuery.h b/pgadmin/include/frm/frmQuery.h index c66321ae6..5a70f82ce 100644 --- a/pgadmin/include/frm/frmQuery.h +++ b/pgadmin/include/frm/frmQuery.h @@ -63,6 +63,14 @@ public: void Go(); void writeScriptOutput(); + void setExtendedTitle(); + void SetLineEndingStyle(); + + void SetQueryText(wxString str) { sqlQuery->SetText(str); } + void ColouriseQuery(int start, int stop) { sqlQuery->Colourise(start, stop); } + void SetChanged(bool p_changed) { changed = p_changed; } + void SetLastPath(wxString p_lastpath) { lastPath = p_lastpath; } + bool CheckChanged(bool canVeto); private: frmMain *mainForm; @@ -165,7 +173,6 @@ private: void OnTimer(wxTimerEvent & event); - bool CheckChanged(bool canVeto); void OpenLastFile(); void updateMenu(wxObject *obj=0); void execQuery(const wxString &query, int resultToRetrieve=0, bool singleResult=false, const int queryOffset=0, bool toFile=false, bool explain=false, bool verbose=false); @@ -174,9 +181,7 @@ private: void OnScriptComplete(wxCommandEvent &ev); void setTools(const bool running); void showMessage(const wxString& msg, const wxString &msgShort=wxT("")); - void setExtendedTitle(); void UpdateFavouritesList(); - void SetLineEndingStyle(); int GetLineEndingStyle(); void OnSetEOLMode(wxCommandEvent& event); void SetEOLModeDisplay(int mode); -- 2.39.5