Support for drag-and-drop of a file in the query tool.
authorguillaume <guillaume@a7884b65-44f6-0310-8a51-81a127f17b15>
Thu, 19 Nov 2009 07:12:08 +0000 (07:12 +0000)
committerguillaume <guillaume@a7884b65-44f6-0310-8a51-81a127f17b15>
Thu, 19 Nov 2009 07:12:08 +0000 (07:12 +0000)
git-svn-id: svn://svn.pgadmin.org/trunk/pgadmin3@8080 a7884b65-44f6-0310-8a51-81a127f17b15

CHANGELOG
pgadmin/frm/frmQuery.cpp
pgadmin/include/dlg/dlgClasses.h
pgadmin/include/frm/frmQuery.h

index c281145baf3adb0d242af17ecf10a3a8de20dfb4..fdf5eb703319576955d0879c0cd70dc839dd25cc 100644 (file)
--- 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
index a97f7cb9c2473450f0e1902fa1a9d36fe90eaa05..f93926e03fb3782bbbb9d94bf706dcc760c62c4e 100644 (file)
@@ -16,6 +16,7 @@
 #include <wx/busyinfo.h>
 #include <wx/clipbrd.h>
 #include <wx/dcbuffer.h>
+#include <wx/dnd.h>
 #include <wx/filename.h>
 #include <wx/regex.h>
 #include <wx/textctrl.h>
@@ -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
index 0b50f99c00d988ac1fb8b5ca66bfd979e5f8b22b..5f878b6cb7da36348533440480879e59ad0aa79a 100644 (file)
@@ -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;
index c66321ae64282f5ba967cfc517a28a2f165ec090..5a70f82ce5a2047821318058d3f1b330156362e0 100644 (file)
@@ -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);