Hi,
The idea is to automatically open a file if a user drags it from the explorer
window onto the query tool.
The patch attached does this.
Comments?
--
Guillaume.
http://www.postgresqlfr.org
http://dalibo.com
Index: pgadmin/frm/frmQuery.cpp
===================================================================
--- pgadmin/frm/frmQuery.cpp (révision 8079)
+++ pgadmin/frm/frmQuery.cpp (copie de travail)
@@ -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_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 @@
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: pgadmin/include/frm/frmQuery.h
===================================================================
--- pgadmin/include/frm/frmQuery.h (révision 8079)
+++ pgadmin/include/frm/frmQuery.h (copie de travail)
@@ -63,7 +63,15 @@
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;
wxAuiManager manager;
@@ -165,7 +173,6 @@
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 @@
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);
Index: pgadmin/include/dlg/dlgClasses.h
===================================================================
--- pgadmin/include/dlg/dlgClasses.h (révision 8079)
+++ pgadmin/include/dlg/dlgClasses.h (copie de travail)
@@ -59,6 +59,9 @@
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 @@
virtual bool CheckChanged(bool canVeto) { return false; }
virtual wxString GetHelpPage() const { return wxEmptyString; }
- void UpdateRecentFiles();
-
windowList frames;
menuFactoryList *menuFactories;
wxString dlgName;
--
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers