Le 31/01/2010 17:44, Little, Douglas a écrit : > Guillaume, > Looks great. I think people will really like it. > Thanks for all the hard work. > > Cheers! > Doug > > > -----Original Message----- > From: Guillaume Lelarge [mailto:guilla...@lelarge.info] > Sent: Sunday, January 31, 2010 10:04 AM > To: Dave Page > Cc: pgadmin-support; Little, Douglas > Subject: Re: [pgadmin-support] feture request > > Le 28/01/2010 10:04, Dave Page a écrit : >> On Thu, Jan 28, 2010 at 8:45 AM, Guillaume Lelarge >> <guilla...@lelarge.info> wrote: >>>>> * probably I need to add a Clear button? >>>> >>>> Nah - just delete the file. >>>> >>> >>> When should it delete the file? do you mean that we should have a delete >>> button? in the option dialog? >> >> No, I mean the user can delete it. If possible (not likely, but might >> be fun to figure out), it might be nice to add a remove icon (circle >> with an X?) to the end of the combo box so individual queries can be >> removed. >> > > Here is the patch I intend to commit. I added a "Delete All" and a > "Delete Current" buttons. I didn't add code for the filename change, it > will be part of another patch. > > See the screenshot to see how it looks on the query window. > > There's probably more to do with this feature, like the maximum number > of statements to keep. I'll work on that later, probably not for the > next release. > > Any more comments? >
I changed a few things, the way we handle multiline queries for example. Any last comments? -- Guillaume. http://www.postgresqlfr.org http://dalibo.com
diff --git a/pgadmin/frm/frmQuery.cpp b/pgadmin/frm/frmQuery.cpp index 7da6853..50979f3 100644 --- a/pgadmin/frm/frmQuery.cpp +++ b/pgadmin/frm/frmQuery.cpp @@ -79,6 +79,10 @@ #define CTRLID_CONNECTION 4200 #define CTRLID_DATABASELABEL 4201 +#define XML_FROM_WXSTRING(s) ((const xmlChar *)(const char *)s.mb_str(wxConvUTF8)) +#define WXSTRING_FROM_XML(s) wxString((char *)s, wxConvUTF8) +#define XML_STR(s) ((const xmlChar *)s) + // Initialize execution 'mutex'. As this will always run in the // main thread, there aren't any real concurrency issues, so // a simple flag will suffice. @@ -89,6 +93,7 @@ BEGIN_EVENT_TABLE(frmQuery, pgFrame) EVT_ERASE_BACKGROUND( frmQuery::OnEraseBackground) EVT_SIZE( frmQuery::OnSize) EVT_COMBOBOX(CTRLID_CONNECTION, frmQuery::OnChangeConnection) +EVT_COMBOBOX(CTL_SQLQUERYCBOX, frmQuery::OnChangeQuery) EVT_CLOSE( frmQuery::OnClose) EVT_SET_FOCUS( frmQuery::OnSetFocus) EVT_MENU(MNU_NEW, frmQuery::OnNew) @@ -153,6 +158,8 @@ EVT_MENU(QUERY_COMPLETE, frmQuery::OnQueryComplete) EVT_MENU(PGSCRIPT_COMPLETE, frmQuery::OnScriptComplete) EVT_NOTEBOOK_PAGE_CHANGED(CTL_NTBKCENTER, frmQuery::OnChangeNotebook) EVT_SPLITTER_SASH_POS_CHANGED(GQB_HORZ_SASH, frmQuery::OnResizeHorizontally) +EVT_BUTTON(CTL_DELETECURRENTBTN, frmQuery::OnDeleteCurrent) +EVT_BUTTON(CTL_DELETEALLBTN, frmQuery::OnDeleteAll) END_EVENT_TABLE() class DnDFile : public wxFileDropTarget @@ -401,12 +408,50 @@ pgsTimer(new pgScriptTimer(this)) //Create SQL editor notebook sqlNotebook = new wxNotebook(this, CTL_NTBKCENTER, wxDefaultPosition, wxDefaultSize); + // Create panel for query + wxPanel *pnlQuery = new wxPanel(sqlNotebook); + + // Create the outer box sizer + wxBoxSizer *boxQuery = new wxBoxSizer(wxVERTICAL); + + // Create the inner box sizer + // This one will contain the combobox, and the two buttons + wxBoxSizer *boxHistory = new wxBoxSizer(wxHORIZONTAL); + + // Query combobox + sqlQueries = new wxComboBox(pnlQuery, CTL_SQLQUERYCBOX, wxT(""), wxDefaultPosition, wxDefaultSize, NULL, wxCB_DROPDOWN); + LoadQueries(); + boxHistory->Add(sqlQueries, 1, wxEXPAND | wxALL, 1); + + // Delete Current button + btnDeleteCurrent = new wxButton(pnlQuery, CTL_DELETECURRENTBTN, wxT("Delete Current")); + btnDeleteCurrent->Enable(false); + boxHistory->Add(btnDeleteCurrent, 0, wxALL | wxALIGN_RIGHT, 1); + + // Delete All button + btnDeleteAll = new wxButton(pnlQuery, CTL_DELETEALLBTN, wxT("Delete All")); + btnDeleteAll->Enable(sqlQueries->GetCount() > 0); + boxHistory->Add(btnDeleteAll, 0, wxALL | wxALIGN_RIGHT, 1); + + boxQuery->Add(boxHistory, 0, wxEXPAND | wxALL, 1); + + // Create the other inner box sizer + // This one will contain the SQL box + wxBoxSizer *boxSQL = new wxBoxSizer(wxHORIZONTAL); + // Query box - sqlQuery = new ctlSQLBox(sqlNotebook, CTL_SQLQUERY, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxSIMPLE_BORDER | wxTE_RICH2); + sqlQuery = new ctlSQLBox(pnlQuery, CTL_SQLQUERY, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxSIMPLE_BORDER | wxTE_RICH2); sqlQuery->SetDatabase(conn); sqlQuery->SetMarginWidth(1, 16); - sqlQuery->SetDropTarget(new DnDFile(this)); + sqlQuery->SetDropTarget(new DnDFile(this)); SetEOLModeDisplay(sqlQuery->GetEOLMode()); + boxSQL->Add(sqlQuery, 1, wxEXPAND | wxRIGHT | wxLEFT | wxBOTTOM, 1); + + boxQuery->Add(boxSQL, 1, wxEXPAND | wxRIGHT | wxLEFT | wxBOTTOM, 1); + + // Auto-sizing + pnlQuery->SetSizer(boxQuery); + boxQuery->Fit(pnlQuery); // Results pane outputPane = new wxNotebook(this, CTL_NTBKGQB, wxDefaultPosition, wxSize(500, 300)); @@ -426,7 +471,7 @@ pgsTimer(new pgScriptTimer(this)) adjustSizesTimer=NULL; // Timer used to avoid a bug when close outputPane // Setup SQL editor notebook NBP_SQLEDTR - sqlNotebook->AddPage(sqlQuery, _("SQL Editor")); + sqlNotebook->AddPage(pnlQuery, _("SQL Editor")); sqlNotebook->AddPage(controller->getViewContainer(), _("Graphical Query Builder")); sqlNotebook->SetSelection(0); @@ -2182,6 +2227,13 @@ void frmQuery::execQuery(const wxString &query, int resultToRetrieve, bool singl Update(); wxTheApp->Yield(true); + wxString tmp = query; + tmp.Replace(wxT("\n"), wxT(" ")); + tmp.Replace(wxT("\r"), wxT(" ")); + sqlQueries->Append(tmp); + histoQueries.Add(query); + SaveQueries(); + startTimeQuery=wxGetLocalTimeMillis(); timer.Start(10); @@ -2627,6 +2679,129 @@ wxColour frmQuery::GetServerColour() return tmp; } +void frmQuery::LoadQueries() +{ + xmlTextReaderPtr reader; + + if (!wxFile::Access(sysSettings::GetConfigFile(sysSettings::PGAHISTOQUERIES), wxFile::read)) + return; + + reader = xmlReaderForFile((const char *)sysSettings::GetConfigFile(sysSettings::PGAHISTOQUERIES).mb_str(wxConvUTF8),NULL,0); + if (!reader) + { + wxMessageBox(_("Failed to load histoqueries file!")); + return; + } + + while (xmlTextReaderRead(reader)) + { + wxString nodename = WXSTRING_FROM_XML(xmlTextReaderConstName(reader)); + + if (nodename == wxT("histoquery")) + { + xmlChar *cont = xmlTextReaderReadString(reader); + + if (!cont) + continue; + + if (WXSTRING_FROM_XML(cont) != wxT("")) + { + wxString query = WXSTRING_FROM_XML(cont); + wxString tmp = query; + tmp.Replace(wxT("\n"), wxT(" ")); + tmp.Replace(wxT("\r"), wxT(" ")); + sqlQueries->Append(tmp); + histoQueries.Add(query); + } + + xmlFree(cont); + } + } + + xmlTextReaderClose(reader); + xmlFreeTextReader(reader); + xmlCleanupParser(); + + return; +} + + +void frmQuery::SaveQueries() +{ + size_t i; + xmlTextWriterPtr writer; + + writer = xmlNewTextWriterFilename((const char *)sysSettings::GetConfigFile(sysSettings::PGAHISTOQUERIES).mb_str(wxConvUTF8),0); + if (!writer) + { + wxMessageBox(_("Failed to write to histoqueries file!")); + return; + } + xmlTextWriterSetIndent(writer, 1); + + if ((xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL) < 0) || + (xmlTextWriterStartElement(writer, XML_STR("histoqueries")) < 0)) + { + wxMessageBox(_("Failed to write to histoqueries file!")); + xmlFreeTextWriter(writer); + return; + } + + for (i = 0; i < histoQueries.GetCount(); i++) + { + xmlTextWriterStartElement(writer, XML_STR("histoquery")); + xmlTextWriterWriteString(writer, XML_FROM_WXSTRING(histoQueries.Item(i))); + xmlTextWriterEndElement(writer); + } + + if (xmlTextWriterEndDocument(writer) < 0) + { + wxMessageBox(_("Failed to write to histoqueries file!")); + } + + xmlFreeTextWriter(writer); +} + + +void frmQuery::OnChangeQuery(wxCommandEvent &event) +{ + wxString query = histoQueries.Item(sqlQueries->GetSelection()); + if (query.Length() > 0) + { + sqlQuery->SetText(query); + sqlQuery->Colourise(0, query.Length()); + wxSafeYield(); // needed to process sqlQuery modify event + changed = false; + setExtendedTitle(); + SetLineEndingStyle(); + btnDeleteCurrent->Enable(true); + } + btnDeleteAll->Enable(sqlQueries->GetCount() > 0); +} + + +void frmQuery::OnDeleteCurrent(wxCommandEvent& event) +{ + histoQueries.RemoveAt(sqlQueries->GetSelection()); + sqlQueries->Delete(sqlQueries->GetSelection()); + sqlQueries->SetValue(wxT("")); + btnDeleteCurrent->Enable(false); + btnDeleteAll->Enable(sqlQueries->GetCount() > 0); + SaveQueries(); +} + + +void frmQuery::OnDeleteAll(wxCommandEvent& event) +{ + histoQueries.Clear(); + sqlQueries->Clear(); + sqlQueries->SetValue(wxT("")); + btnDeleteCurrent->Enable(false); + btnDeleteAll->Enable(false); + SaveQueries(); +} + + /////////////////////////////////////////////////////// wxWindow *queryToolBaseFactory::StartDialogSql(frmMain *form, pgObject *obj, const wxString &sql) diff --git a/pgadmin/include/frm/frmQuery.h b/pgadmin/include/frm/frmQuery.h index 0b771db..3ffc24c 100644 --- a/pgadmin/include/frm/frmQuery.h +++ b/pgadmin/include/frm/frmQuery.h @@ -83,6 +83,10 @@ private: wxTextCtrl *msgResult, *msgHistory; wxBitmapComboBox *cbConnection; wxTextCtrl *scratchPad; + wxComboBox *sqlQueries; + wxButton *btnDeleteCurrent; + wxButton *btnDeleteAll; + wxArrayString histoQueries; // Query timing/status update wxTimer timer; @@ -173,6 +177,9 @@ private: void OnCommentText(wxCommandEvent& event); void OnUncommentText(wxCommandEvent& event); + void OnDeleteCurrent(wxCommandEvent& event); + void OnDeleteAll(wxCommandEvent& event); + void OnTimer(wxTimerEvent & event); void OpenLastFile(); @@ -191,6 +198,10 @@ private: void OnMacroManage(wxCommandEvent& event); void UpdateMacrosList(); + void LoadQueries(); + void SaveQueries(); + void OnChangeQuery(wxCommandEvent &event); + wxBitmap CreateBitmap(const wxColour& colour); wxColour GetServerColour(); @@ -236,7 +247,10 @@ enum CTL_COLSGRID, CTL_TIMERSIZES, CTL_TIMERFRM, - CTL_NTBKGQB + CTL_NTBKGQB, + CTL_SQLQUERYCBOX, + CTL_DELETECURRENTBTN, + CTL_DELETEALLBTN }; /////////////////////////////////////////////////////// diff --git a/pgadmin/include/utils/sysSettings.h b/pgadmin/include/utils/sysSettings.h index 95e7682..81e6788 100644 --- a/pgadmin/include/utils/sysSettings.h +++ b/pgadmin/include/utils/sysSettings.h @@ -181,7 +181,8 @@ public: { PGPASS, PGAFAVOURITES, - PGAMACROS + PGAMACROS, + PGAHISTOQUERIES }; static wxString GetConfigFile(configFileName cfgname); diff --git a/pgadmin/utils/sysSettings.cpp b/pgadmin/utils/sysSettings.cpp index faa8c16..b9a73cb 100644 --- a/pgadmin/utils/sysSettings.cpp +++ b/pgadmin/utils/sysSettings.cpp @@ -683,7 +683,7 @@ void sysSettings::SetCanonicalLanguage(const wxLanguage &lang) ////////////////////////////////////////////////////////////////////////// wxString sysSettings::GetConfigFile(configFileName cfgname) { - if (cfgname == PGPASS || cfgname == PGAFAVOURITES || cfgname == PGAMACROS) + if (cfgname == PGPASS || cfgname == PGAFAVOURITES || cfgname == PGAMACROS || cfgname == PGAHISTOQUERIES) { wxStandardPaths stdp; wxString fname=stdp.GetUserConfigDir(); @@ -702,6 +702,9 @@ wxString sysSettings::GetConfigFile(configFileName cfgname) case PGAMACROS: fname += wxT("\\pgadmin_macros.xml"); break; + case PGAHISTOQUERIES: + fname += wxT("\\pgadmin_histoqueries.xml"); + break; } #else switch(cfgname) @@ -715,6 +718,9 @@ wxString sysSettings::GetConfigFile(configFileName cfgname) case PGAMACROS: fname += wxT("/.pgadminmacros"); break; + case PGAHISTOQUERIES: + fname += wxT("/.pgadmin_histoqueries"); + break; } #endif return fname;
-- Sent via pgadmin-support mailing list (pgadmin-support@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgadmin-support