Web pgadmin.org
 Home 
 ·  ·  ·  ·  ·  ·  · 
Repost: Patch: view data for tables/views on double click

Repost: Patch: view data for tables/views on double click



Andreas Pflug wrote:
First of all, this is certainly hackers stuff, please post on pgadmin-hackers!

Agreed. This is a repost/rewrite of the patch I have posted to the
pgadmin-support list a few days ago.

Dave Page wrote:
That breaks the principle of least surprise because it introduces inconsistent behaviour.

Perhaps a better approach would be to open the data view only if 'double-click-for-properties' is turned off?

Andreas Pflug wrote:
- the default action might differ from user to user. For sure, an
unconditional "View Data" on a table is a bad idea. I already hear
those guys yelling double clicking on a 100 million row table...

This version of the patch tries to address those issues in the following ways:

1. There is an additional checkbox in the Preferences tab of the Options dialog, labeled "Show data instead of properties for tables and views", placed as a subordinate of "Show object properties on double click" (I have stripped the "in treeview" part, since double click should also work in the Properties pane). The checkbox is disabled if its superior is disabled.

2. In the same tab, a parameter labeled "Maximum rows in data view" is introduced. It is used to limit the number of rows retrieved when constructing the data view/edit grid if greater than zero. The default value is set to 500, although it could be set to 0 (unlimited) to keep the behavior prior to its introduction.

The patch also arranges reading and writing of the new parameters from and to the configuration file.

The patch is against the beta1 source tree; I could re-sync it to the latest snapshot if needed.

i.
--- src/include/frmMain.h.old	Tue Aug 10 22:51:45 2004
+++ src/include/frmMain.h	Wed Sep 15 11:56:51 2004
@@ -110,6 +110,7 @@
     
     void OnPageChange(wxNotebookEvent& event);
     void OnPropSelChanged(wxListEvent& event);
+    void OnPropSelActivated(wxListEvent& event);
     void OnTreeSelChanged(wxTreeEvent &event);
     void OnTreeKeyDown(wxTreeEvent& event);
     void OnConnect(wxCommandEvent &ev);
--- src/include/sysSettings.h.old	Mon Aug  9 09:59:20 2004
+++ src/include/sysSettings.h	Wed Sep 22 11:51:58 2004
@@ -53,6 +53,8 @@
     void SetLastSSL(const int newval);
     long GetMaxRows() const { return maxRows; }
     void SetMaxRows(const long l) { maxRows=l; }
+    long GetMaxViewRows() const { return maxViewRows; }
+    void SetMaxViewRows(const long l) { maxViewRows=l; }
     long GetMaxColSize() const { return maxColSize; }
     void SetMaxColSize(const long l) { maxColSize=l; }
     bool GetAskSaveConfirmation() const { return askSaveConfirmation; }
@@ -89,6 +91,10 @@
     bool GetDoubleClickProperties() const { return doubleClickProperties; }
     void SetDoubleClickProperties(const bool newval);
 
+    // View instead of Properties
+    bool GetDoubleClickView() const { return doubleClickView; }
+    void SetDoubleClickView(const bool newval);
+
     // maximum size of server log to read
     long GetMaxServerLogSize() const { return maxServerLogSize; }
     void SetMaxServerLogSize(long l) { maxServerLogSize = l; }
@@ -172,9 +178,9 @@
     bool showUsersForPrivileges;
     bool askSaveConfirmation;
     bool confirmDelete;
-    long maxRows, maxColSize, autoRowCountThreshold;
+    long maxRows, maxColSize, autoRowCountThreshold, maxViewRows;
     bool stickySql, unicodeFile;
-    bool doubleClickProperties;
+    bool doubleClickProperties, doubleClickView;
     long maxServerLogSize;
 
     wxString searchPath;
--- src/include/frmOptions.h.old	Fri Jun 11 20:17:52 2004
+++ src/include/frmOptions.h	Wed Sep 22 12:30:59 2004
@@ -37,6 +37,7 @@
     void OnOK(wxCommandEvent &ev);
     void OnCancel(wxCommandEvent &ev);
     void OnHelp(wxCommandEvent &ev);
+    void OnDoubleClickProps(wxCommandEvent &ev);
     DECLARE_EVENT_TABLE()
 };
 
--- src/ui/common/frmOptions.xrc.old	Tue Sep  7 10:38:13 2004
+++ src/ui/common/frmOptions.xrc	Wed Sep 22 12:03:26 2004
@@ -58,33 +58,49 @@
           </object>
           <object class="wxCheckBox" name="chkUnicodeFile">
             <label>Read and write Unicode UTF-8 files</label>
-            <pos>5,35d</pos>
+            <pos>5,25d</pos>
             <size>226,12d</size>
           </object>
           <object class="wxCheckBox" name="chkAskSaveConfirm">
             <label>Do not prompt for unsaved files on exit</label>
             <checked>0</checked>
-            <pos>5,47d</pos>
+            <pos>5,37d</pos>
             <size>226,12d</size>
           </object>
           <object class="wxCheckBox" name="chkAskDelete">
             <label>Confirm object deletion?</label>
             <checked>1</checked>
-            <pos>5,59d</pos>
+            <pos>5,49d</pos>
             <size>226,12d</size>
           </object>
           <object class="wxCheckBox" name="chkShowUsersForPrivileges">
             <label>Show users for privileges?</label>
             <checked>0</checked>
-            <pos>5,71d</pos>
+            <pos>5,61d</pos>
             <size>226,12d</size>
           </object>
           <object class="wxCheckBox" name="chkDoubleClickProperties">
-            <label>Show object properties on double click in treeview?</label>
+            <label>Show object properties on double click?</label>
+            <checked>0</checked>
+            <pos>5,73d</pos>
+            <size>226,12d</size>
+          </object>
+          <object class="wxCheckBox" name="chkDoubleClickView">
+            <label>Show data instead of properties for tables and views?</label>
             <checked>0</checked>
-            <pos>5,83d</pos>
+            <pos>15,85d</pos>
             <size>226,12d</size>
           </object>
+          <object class="wxStaticText" name="lblMaxViewRows">
+	    <label>Maximum rows in data view</label>
+            <pos>5,100d</pos>
+	  </object>
+          <object class="wxTextCtrl" name="txtMaxViewRows">
+            <value>500</value>
+            <pos>175,98d</pos>
+            <size>35,-1d</size>
+            <tooltip>Maximums rows to retrieve into data view grid; 0 = unlimited</tooltip>
+          </object>
         </object>
       </object>
       <object class="notebookpage">
@@ -199,4 +215,4 @@
       <tooltip>Cancel any changes and close the dialogue.</tooltip>
     </object>
   </object>
-</resource>
\ No newline at end of file
+</resource>
--- src/ui/events.cpp.old	Tue Sep  7 10:34:34 2004
+++ src/ui/events.cpp	Wed Sep 22 12:57:28 2004
@@ -122,6 +122,7 @@
     EVT_MENU(MNU_CONTEXTMENU,               frmMain::OnContextMenu) 
     EVT_NOTEBOOK_PAGE_CHANGED(CTL_NOTEBOOK, frmMain::OnPageChange)
     EVT_LIST_ITEM_SELECTED(CTL_PROPVIEW,    frmMain::OnPropSelChanged)
+    EVT_LIST_ITEM_ACTIVATED(CTL_PROPVIEW,   frmMain::OnPropSelActivated)
     EVT_TREE_SEL_CHANGED(CTL_BROWSER,       frmMain::OnTreeSelChanged)
     EVT_TREE_ITEM_EXPANDING(CTL_BROWSER,    frmMain::OnExpand)
     EVT_TREE_ITEM_COLLAPSING(CTL_BROWSER,   frmMain::OnCollapse)
@@ -684,6 +685,30 @@
 }
 
 
+void frmMain::OnPropSelActivated(wxListEvent& event)
+{
+    wxTreeItemId item=browser->GetSelection();
+    pgObject *data=(pgObject*)browser->GetItemData(item);
+    wxCommandEvent nullEvent;
+
+    if (!settings->GetDoubleClickProperties())
+	return;
+    if (data && data->IsCollection())
+    {
+	data=((pgCollection*)data)->FindChild(browser, event.GetIndex());
+	if (data)
+	{
+	    int type = data->GetType();
+	    if (settings->GetDoubleClickView() && (type == PG_TABLE || type == PG_VIEW))
+		ViewData(false);
+	    else if (data->CanEdit())
+		if (!dlgProperty::EditObjectDialog(this, sqlPane, data))
+		    checkAlive();
+	}
+    }
+}
+
+
 void frmMain::OnTreeSelChanged(wxTreeEvent& event)
 {
     denyCollapseItem=wxTreeItemId();
@@ -958,13 +983,22 @@
             }
             break;
 
+        case PG_TABLE:
+        case PG_VIEW:
+            if (settings->GetDoubleClickProperties() && settings->GetDoubleClickView()) {
+		denyCollapseItem=item;
+		ViewData(false);
+		return;
+	    }
+	    /* FALL-THROUGH */
+
         default:
             if (settings->GetDoubleClickProperties())
             {
                 if (data->CanEdit())
                 {
+		    denyCollapseItem=item;
                     OnProperties(nullEvent);
-                    event.Skip();
                     return;
                 }
             }
--- src/ui/frmEditGrid.cpp.old	Tue Sep  7 15:44:56 2004
+++ src/ui/frmEditGrid.cpp	Wed Sep 22 13:03:10 2004
@@ -599,6 +599,11 @@
     {
         qry += wxT(" ORDER BY ") + orderBy;
     }
+    long maxViewRows = settings->GetMaxViewRows();
+    if (maxViewRows > 0)
+    {
+	qry += wxT(" LIMIT ") + NumToStr(maxViewRows);
+    }
 
     thread=new pgQueryThread(connection, qry);
     if (thread->Create() != wxTHREAD_NO_ERROR)
--- src/ui/frmOptions.cpp.old	Tue Sep  7 10:38:12 2004
+++ src/ui/frmOptions.cpp	Wed Sep 22 12:32:32 2004
@@ -38,6 +38,7 @@
 #define txtLogfile                  CTRL_TEXT("txtLogfile")
 #define radLoglevel                 CTRL_RADIOBOX("radLoglevel")
 #define txtMaxRows                  CTRL_TEXT("txtMaxRows")
+#define txtMaxViewRows              CTRL_TEXT("txtMaxViewRows")
 #define txtMaxColSize               CTRL_TEXT("txtMaxColSize")
 #define txtFont                     CTRL_TEXT("txtFont")
 #define chkUnicodeFile              CTRL_CHECKBOX("chkUnicodeFile")
@@ -47,6 +48,7 @@
 #define txtAutoRowCount             CTRL_TEXT("txtAutoRowCount")
 #define chkStickySql                CTRL_CHECKBOX("chkStickySql")
 #define chkDoubleClickProperties    CTRL_CHECKBOX("chkDoubleClickProperties")
+#define chkDoubleClickView          CTRL_CHECKBOX("chkDoubleClickView")
 #define cbLanguage                  CTRL_COMBOBOX("cbLanguage")
 #define txtSqlFont                  CTRL_TEXT("txtSqlFont")
 
@@ -59,6 +61,8 @@
     EVT_BUTTON (XRCID("btnOK"),               frmOptions::OnOK)
     EVT_BUTTON (XRCID("btnHelp"),             frmOptions::OnHelp)
     EVT_BUTTON (XRCID("btnCancel"),           frmOptions::OnCancel)
+    EVT_CHECKBOX
+	(XRCID("chkDoubleClickProperties"),   frmOptions::OnDoubleClickProps)
 END_EVENT_TABLE()
 
 frmOptions::frmOptions(frmMain *parent)
@@ -82,12 +86,14 @@
 
     wxTextValidator numval(wxFILTER_NUMERIC);
     txtMaxRows->SetValidator(numval);
+    txtMaxViewRows->SetValidator(numval);
     txtMaxColSize->SetValidator(numval);
     txtAutoRowCount->SetValidator(numval);
     
     txtLogfile->SetValue(settings->GetLogFile());
     radLoglevel->SetSelection(settings->GetLogLevel());
     txtMaxRows->SetValue(NumToStr(settings->GetMaxRows()));
+    txtMaxViewRows->SetValue(NumToStr(settings->GetMaxViewRows()));
     txtMaxColSize->SetValue(NumToStr(settings->GetMaxColSize()));
     chkAskSaveConfirm->SetValue(!settings->GetAskSaveConfirmation());
     chkAskDelete->SetValue(settings->GetConfirmDelete());
@@ -95,6 +101,8 @@
     txtAutoRowCount->SetValue(NumToStr(settings->GetAutoRowCountThreshold()));
     chkStickySql->SetValue(settings->GetStickySql());
     chkDoubleClickProperties->SetValue(settings->GetDoubleClickProperties());
+    chkDoubleClickView->SetValue(settings->GetDoubleClickView());
+    chkDoubleClickView->Enable(settings->GetDoubleClickProperties());
     txtSqlHelpSite->SetValue(settings->GetSqlHelpSite());
     txtProxy->SetValue(settings->GetProxy());
     chkUnicodeFile->SetValue(settings->GetUnicodeFile());
@@ -178,12 +186,15 @@
     settings->SetMaxRows(StrToLong(txtMaxRows->GetValue()));
     settings->SetMaxColSize(StrToLong(txtMaxColSize->GetValue()));
 
+    // Preferences
     settings->SetAskSaveConfirmation(!chkAskSaveConfirm->GetValue());
     settings->SetConfirmDelete(chkAskDelete->GetValue());
     settings->SetShowUsersForPrivileges(chkShowUsersForPrivileges->GetValue());
     settings->SetAutoRowCountThreshold(StrToLong(txtAutoRowCount->GetValue()));
     settings->SetStickySql(chkStickySql->GetValue());
     settings->SetDoubleClickProperties(chkDoubleClickProperties->GetValue());
+    settings->SetDoubleClickView(chkDoubleClickView->GetValue());
+    settings->SetMaxViewRows(StrToLong(txtMaxViewRows->GetValue()));
     settings->SetUnicodeFile(chkUnicodeFile->GetValue());
     settings->SetFont(currentFont);
     settings->SetSQLFont(currentSqlFont);
@@ -276,3 +287,8 @@
     if (logFile.ShowModal() == wxID_OK)
         txtLogfile->SetValue(logFile.GetPath());
 }
+
+void frmOptions::OnDoubleClickProps(wxCommandEvent &ev)
+{
+    chkDoubleClickView->Enable(chkDoubleClickProperties->IsChecked());
+}
--- src/utils/sysSettings.cpp.old	Mon Aug  9 09:59:20 2004
+++ src/utils/sysSettings.cpp	Wed Sep 22 13:11:28 2004
@@ -70,6 +70,8 @@
     autoRowCountThreshold=Read(wxT("AutoRowCount"), 2000);
     Read(wxT("StickySql"), &stickySql, false);
     Read(wxT("DoubleClickProperties"), &doubleClickProperties, true);
+    Read(wxT("DoubleClickView"), &doubleClickView, false);
+    maxViewRows=Read(wxT("MaxViewRows"), 500L);
     Read(wxT("WriteUnicodeFile"), &unicodeFile, false);
     Read(wxT("SearchPath"), &searchPath, wxEmptyString);
     Read(wxT("MaxServerLogSize"), &maxServerLogSize, 100000L);
@@ -147,6 +149,7 @@
     Write(wxT("AskSaveConfirmation"), BoolToStr(askSaveConfirmation));
     Write(wxT("ConfirmDelete"), BoolToStr(confirmDelete));
     Write(wxT("ShowUsersForPrivileges"), BoolToStr(showUsersForPrivileges));
+    Write(wxT("MaxViewRows"), maxViewRows);
     Write(wxT("SqlHelpSite"), sqlHelpSite);
     Write(wxT("Proxy"), proxy);
     Write(wxT("AutoRowCount"), autoRowCountThreshold);
@@ -328,3 +331,13 @@
     doubleClickProperties = newval;
     Write(wxT("DoubleClickProperties"), doubleClickProperties);
 }
+
+//////////////////////////////////////////////////////////////////////////
+// View instead of properties
+//////////////////////////////////////////////////////////////////////////
+
+void sysSettings::SetDoubleClickView(const bool newval)
+{
+    doubleClickView = newval;
+    Write(wxT("DoubleClickView"), doubleClickView);
+}


Home | Main Index | Thread Index

top