Re: Enabling SQL text field in the SQL tab of object dialog

Поиск
Список
Период
Сортировка
От Guillaume Lelarge
Тема Re: Enabling SQL text field in the SQL tab of object dialog
Дата
Msg-id 4853CF39.3030405@lelarge.info
обсуждение исходный текст
Ответ на Re: Enabling SQL text field in the SQL tab of object dialog  (Dave Page <dpage@postgresql.org>)
Ответы Re: Enabling SQL text field in the SQL tab of object dialog  ("Dave Page" <dpage@postgresql.org>)
Список pgadmin-hackers
Dave Page a écrit :
> Guillaume Lelarge wrote:
> [...]
>> Ideas ? Comments ?
>
> I think I'd like to see a prototype so we can get a feel for how it
> would work and what might explode. It shouldn't be too hard to do - just
> add an option to the SQL tab, and when selected, lock the tabset to that
> tab. That should be doable on the appropriate base class.
>

Finally, here is the prototype. As I first talked about this one year
ago, I will summarize the idea : adding a checkbox on the SQL tab of an
object's properties to let the user change the SQL query. Checking will
disable the contents of the other tabs because we don't want to try to
reverse engineer the user's changes.

So, here is the patch that does this. I'm sure there's work left to do
(most notably some duplicate code) but, at least, it works for me on two
different scenarios : changing the SQL query and adding another SQL query.

Comments are welcome.

Regards.


--
Guillaume.
  http://www.postgresqlfr.org
  http://dalibo.com
Index: pgadmin/include/dlg/dlgProperty.h
===================================================================
--- pgadmin/include/dlg/dlgProperty.h    (revision 7373)
+++ pgadmin/include/dlg/dlgProperty.h    (working copy)
@@ -86,6 +86,7 @@
     void OnChange(wxCommandEvent &ev);
     void OnChangeOwner(wxCommandEvent &ev);
     void OnChangeStc(wxStyledTextEvent& event);
+    void OnChangeReadOnly(wxCommandEvent& event);

 protected:
     void AddUsers(ctlComboBoxFix *cb1, ctlComboBoxFix *cb2=0);
@@ -97,7 +98,7 @@
     pgDatabase *database;

     frmMain *mainForm;
-    ctlSQLBox *sqlPane;
+    wxPanel *sqlPane;

     wxTextValidator numericValidator;

@@ -105,6 +106,8 @@
     wxTextCtrl *txtName, *txtOid, *txtComment;
     ctlComboBox *cbOwner;
     ctlComboBox *cbClusterSet;
+    wxCheckBox *chkReadOnly;
+    ctlSQLBox *sqlTextField;

     int width, height;
     wxTreeItemId item, owneritem;
Index: pgadmin/dlg/dlgProperty.cpp
===================================================================
--- pgadmin/dlg/dlgProperty.cpp    (revision 7373)
+++ pgadmin/dlg/dlgProperty.cpp    (working copy)
@@ -59,8 +59,6 @@
 #include "schema/pgUser.h"


-
-
 class replClientData : public wxClientData
 {
 public:
@@ -72,6 +70,9 @@
 };


+#define CTRLID_CHKSQLTEXTFIELD 1000
+
+
 BEGIN_EVENT_TABLE(dlgProperty, DialogWithHelp)
     EVT_NOTEBOOK_PAGE_CHANGED(XRCID("nbNotebook"),  dlgProperty::OnPageSelect)

@@ -80,6 +81,8 @@
     EVT_COMBOBOX(XRCID("cbOwner"),                  dlgProperty::OnChange)
     EVT_TEXT(XRCID("txtComment"),                   dlgProperty::OnChange)

+    EVT_CHECKBOX(CTRLID_CHKSQLTEXTFIELD,            dlgProperty::OnChangeReadOnly)
+
     EVT_BUTTON(wxID_HELP,                           dlgProperty::OnHelp)
     EVT_BUTTON(wxID_OK,                             dlgProperty::OnOK)
     EVT_BUTTON(wxID_APPLY,                          dlgProperty::OnApply)
@@ -90,6 +93,7 @@
 {
     readOnly=false;
     sqlPane=0;
+    sqlTextField=0;
     processing=false;
     mainForm=frame;
     database=0;
@@ -311,7 +315,34 @@

 void dlgProperty::CreateAdditionalPages()
 {
-    sqlPane = new ctlSQLBox(nbNotebook, CTL_PROPSQL, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE |
wxSUNKEN_BORDER| wxTE_READONLY | wxTE_RICH2); 
+    int width, height;
+
+    // get a few sizes and widths
+#ifdef __WIN32__
+    GetClientSize(&width, &height);
+#else
+    nbNotebook->GetClientSize(&width, &height);
+    height -= ConvertDialogToPixels(wxPoint(0, 20)).y;   // sizes of tabs
+#endif
+    wxPoint zeroPos=ConvertDialogToPixels(wxPoint(5, 5));
+    wxSize chkSize=ConvertDialogToPixels(wxSize(65,12));
+
+    // add a panel
+    sqlPane = new wxPanel(nbNotebook);
+
+    // add checkbox to the panel
+    chkReadOnly = new wxCheckBox(sqlPane, CTRLID_CHKSQLTEXTFIELD, wxT("Read only"),
+      wxPoint(zeroPos.x, zeroPos.y),
+      chkSize);
+    chkReadOnly->SetValue(true);
+
+    // add ctlSQLBox to the panel
+    sqlTextField = new ctlSQLBox(sqlPane, CTL_PROPSQL,
+      wxPoint(zeroPos.x, zeroPos.y + chkSize.GetHeight()),
+      wxSize(width - 2*zeroPos.x, height - 2*zeroPos.y),
+      wxTE_MULTILINE | wxSUNKEN_BORDER | wxTE_RICH2);
+
+    // add panel to the notebook
     nbNotebook->AddPage(sqlPane, wxT("SQL"));
 }

@@ -506,6 +537,42 @@
 }


+void dlgProperty::OnChangeReadOnly(wxCommandEvent &ev)
+{
+    size_t pos;
+
+    sqlTextField->SetReadOnly(chkReadOnly->GetValue());
+    for (pos = 0; pos < nbNotebook->GetPageCount() - 1; pos++)
+    {
+        nbNotebook->GetPage(pos)->Enable(chkReadOnly->GetValue());
+    }
+
+    if (chkReadOnly->GetValue())
+    {
+        // create a function because this is a duplicated code
+        sqlTextField->SetReadOnly(false);
+        if (btnOK->IsEnabled())
+        {
+            wxString tmp;
+            if (cbClusterSet && cbClusterSet->GetSelection() > 0)
+            {
+                replClientData *data=(replClientData*)cbClusterSet->GetClientData(cbClusterSet->GetSelection());
+                tmp.Printf(_("-- Execute replicated using cluster \"%s\", set %ld\n"), data->cluster.c_str(),
data->setId);
+            }
+            sqlTextField->SetText(tmp + GetSql() + GetSql2());
+        }
+        else
+        {
+            if (GetObject())
+                sqlTextField->SetText(_("-- nothing to change"));
+            else
+                sqlTextField->SetText(_("-- definition incomplete"));
+        }
+        sqlTextField->SetReadOnly(true);
+    }
+}
+
+
 bool dlgProperty::tryUpdate(wxTreeItemId collectionItem)
 {
     ctlTree *browser=mainForm->GetBrowser();
@@ -753,7 +820,16 @@
         return;
     }

-    wxString sql=GetSql();
+    wxString sql;
+    if (chkReadOnly->GetValue())
+    {
+        sql = GetSql();
+    }
+    else
+    {
+        sql = sqlTextField->GetText();
+    }
+
     wxString sql2=GetSql2();

     if (!apply(sql, sql2))
@@ -768,9 +844,10 @@

 void dlgProperty::OnPageSelect(wxNotebookEvent& event)
 {
-    if (sqlPane && event.GetSelection() == (int)nbNotebook->GetPageCount()-1)
+    if (sqlTextField && chkReadOnly->GetValue() &&
+        event.GetSelection() == (int)nbNotebook->GetPageCount()-1)
     {
-        sqlPane->SetReadOnly(false);
+        sqlTextField->SetReadOnly(false);
         if (btnOK->IsEnabled())
         {
             wxString tmp;
@@ -779,16 +856,16 @@
                 replClientData *data=(replClientData*)cbClusterSet->GetClientData(cbClusterSet->GetSelection());
                 tmp.Printf(_("-- Execute replicated using cluster \"%s\", set %ld\n"), data->cluster.c_str(),
data->setId);
             }
-            sqlPane->SetText(tmp + GetSql() + GetSql2());
+            sqlTextField->SetText(tmp + GetSql() + GetSql2());
         }
         else
         {
             if (GetObject())
-                sqlPane->SetText(_("-- nothing to change"));
+                sqlTextField->SetText(_("-- nothing to change"));
             else
-                sqlPane->SetText(_("-- definition incomplete"));
+                sqlTextField->SetText(_("-- definition incomplete"));
         }
-        sqlPane->SetReadOnly(true);
+        sqlTextField->SetReadOnly(true);
     }
 }


В списке pgadmin-hackers по дате отправления:

Предыдущее
От: "Dave Page"
Дата:
Сообщение: Re: Comments on a separate tab?
Следующее
От: svn@pgadmin.org
Дата:
Сообщение: SVN Commit by guillaume: r7374 - trunk/pgadmin3