Index: src/base/factory.cpp =================================================================== --- src/base/factory.cpp (revision 4967) +++ src/base/factory.cpp (working copy) @@ -263,7 +263,24 @@ { wxMenuItem *menuItem=menuBar->FindItem(id); if (menuItem && menuItem->IsEnabled()) - lastItem = treeContextMenu->Append(id, menuItem->GetLabel(), menuItem->GetHelp()); + { + if (!menuItem->IsSubMenu()) + lastItem = treeContextMenu->Append(id, menuItem->GetLabel(), menuItem->GetHelp()); + else + { + /* Copy of submenu */ + wxMenu *oldSubMenu = menuItem->GetSubMenu(); + wxMenu *newSubMenu = new wxMenu(); + + size_t i; + for (i=0; i < oldSubMenu->GetMenuItemCount(); i++) + { + wxMenuItem *oldMenuItem = oldSubMenu->FindItemByPosition(i); + newSubMenu->Append(oldMenuItem->GetId(), oldMenuItem->GetLabel(), oldMenuItem->GetHelp()); + } + lastItem = treeContextMenu->Append(id, menuItem->GetLabel(), newSubMenu); + } + } } } else Index: src/dlg/dlgEditGridOptions.cpp =================================================================== --- src/dlg/dlgEditGridOptions.cpp (revision 4967) +++ src/dlg/dlgEditGridOptions.cpp (working copy) @@ -43,6 +43,7 @@ #define lstSortCols CTRL_LISTVIEW("lstSortCols") #define pnlSort CTRL_PANEL("pnlSort") #define pnlFilter CTRL_PANEL("pnlFilter") +#define cboRowLimit CTRL_COMBOBOX("cboRowLimit") BEGIN_EVENT_TABLE(dlgEditGridOptions, pgDialog) EVT_BUTTON (wxID_OK, dlgEditGridOptions::OnOK) @@ -56,7 +57,7 @@ EVT_LIST_ITEM_DESELECTED (XRCID("lstSortCols"), dlgEditGridOptions::OnLstSortColsChange) END_EVENT_TABLE() -dlgEditGridOptions::dlgEditGridOptions(frmEditGrid *win, pgConn *conn, const wxString &rel, ctlSQLGrid *grid) +dlgEditGridOptions::dlgEditGridOptions(frmEditGrid *win, pgConn *conn, const wxString &rel, ctlSQLGrid *grid, int limit) { wxLogInfo(wxT("Creating an edit grid options dialogue")); editGrid=grid; @@ -96,6 +97,12 @@ wxXmlResource::Get()->AttachUnknownControl(wxT("sqlFilter"), filter); filter->SetText(parent->GetFilter()); + // Setup limit combo + if (limit <= 0) + cboRowLimit->SetValue(_("No limit")); + else + cboRowLimit->SetValue(wxString::Format(wxT("%i"), limit)); + // Get the current sort columns, and populate the listbox. // The current columns will be parsed char by char to allow us // to cope with quoted column names with commas in them (let's hope @@ -234,6 +241,7 @@ void dlgEditGridOptions::OnOK(wxCommandEvent &ev) { + long limit; // Check the filter syntax if (!Validate()) return; @@ -259,12 +267,27 @@ } parent->SetFilter(filter->GetText().Trim()); + + if (cboRowLimit->GetValue() == _("No limit")) + limit = 0; + else + cboRowLimit->GetValue().ToLong(&limit); + parent->SetLimit(limit); EndModal(true); } bool dlgEditGridOptions::Validate() { extern frmMain *winMain; + long templong; + + if (cboRowLimit->GetValue() != _("No limit") && + !cboRowLimit->GetValue().ToLong(&templong)) + { + wxLogError(_("Limit must be number or 'No limit'")); + return false; + } + winMain->StartMsg(_("Validating filter string")); filter->MarkerDeleteAll(0); if (!filter->GetText().Trim().Length()) { Index: src/frm/frmEditGrid.cpp =================================================================== --- src/frm/frmEditGrid.cpp (revision 4967) +++ src/frm/frmEditGrid.cpp (working copy) @@ -77,6 +77,7 @@ mainForm=form; thread=0; relkind=0; + limit=0; relid=(Oid)obj->GetOid(); @@ -168,6 +169,14 @@ } } +void frmEditGrid::SetLimit(const int rowlimit) +{ + if (rowlimit != limit) { + limit = rowlimit; + optionsChanged = true; + } +} + void frmEditGrid::OnLabelRightClick(wxGridEvent& event) { wxArrayInt rows=sqlGrid->GetSelectedRows(); @@ -484,7 +493,7 @@ void frmEditGrid::OnOptions(wxCommandEvent& event) { optionsChanged = false; - dlgEditGridOptions *winOptions = new dlgEditGridOptions(this, connection, tableName, sqlGrid); + dlgEditGridOptions *winOptions = new dlgEditGridOptions(this, connection, tableName, sqlGrid, limit); winOptions->ShowModal(); if (optionsChanged) Go(); @@ -597,7 +606,7 @@ { if (filter) { - dlgEditGridOptions *winOptions = new dlgEditGridOptions(this, connection, tableName, sqlGrid); + dlgEditGridOptions *winOptions = new dlgEditGridOptions(this, connection, tableName, sqlGrid, limit); abort = !(winOptions->ShowModal()); } if (abort) { @@ -632,7 +641,10 @@ { qry += wxT(" ORDER BY ") + orderBy; } + if (limit > 0) + qry += wxT(" LIMIT ") + wxString::Format(wxT("%i"), limit); thread=new pgQueryThread(connection, qry); if (thread->Create() != wxTHREAD_NO_ERROR) { @@ -2011,6 +2023,7 @@ + wxT(" - ") + obj->GetFullIdentifier(); frmEditGrid *eg= new frmEditGrid(form, txt, conn, (pgSchemaObject*)obj); + eg->SetLimit(rowlimit); eg->ShowForm(filter); return eg; } @@ -2020,8 +2033,9 @@ editGridFactory::editGridFactory(menuFactoryList *list, wxMenu *mnu, wxToolBar *toolbar) : editGridFactoryBase(list) { - mnu->Append(id, _("View &Data"), _("View the data in the selected object.")); - toolbar->AddTool(id, _("View Data"), wxBitmap(viewdata_xpm), _("View the data in the selected object."), wxITEM_NORMAL); + mnu->Append(id, _("View &All Rows"), _("View the data in the selected object.")); + toolbar->AddTool(id, _("View All Rows"), wxBitmap(viewdata_xpm), _("View the data in the selected object."), wxITEM_NORMAL); + context = false; } @@ -2034,8 +2048,9 @@ #include "images/viewfiltereddata.xpm" editGridFilteredFactory::editGridFilteredFactory(menuFactoryList *list, wxMenu *mnu, wxToolBar *toolbar) : editGridFactoryBase(list) { - mnu->Append(id, _("View F&iltered Data..."), _("Apply a filter and view the data in the selected object.")); - toolbar->AddTool(id, _("View Filtered Data"), wxBitmap(viewfiltereddata_xpm), _("Apply a filter and view the data in the selected object."), wxITEM_NORMAL); + mnu->Append(id, _("View F&iltered Rows..."), _("Apply a filter and view the data in the selected object.")); + toolbar->AddTool(id, _("View Filtered Rows"), wxBitmap(viewfiltereddata_xpm), _("Apply a filter and view the data in the selected object."), wxITEM_NORMAL); + context = false; } @@ -2044,3 +2059,14 @@ return ViewData(form, obj, true); } +editGridLimitedFactory::editGridLimitedFactory(menuFactoryList *list, wxMenu *mnu, wxToolBar *toolbar, int limit) : editGridFactoryBase(list) +{ + mnu->Append(id, wxString::Format(_("View Top %i Rows"), limit), _("View a limited number of rows in the selected object.")); + rowlimit = limit; + context = false; +} + +wxWindow *editGridLimitedFactory::StartDialog(frmMain *form, pgObject *obj) +{ + return ViewData(form, obj, false); +} \ No newline at end of file Index: src/frm/frmMain.cpp =================================================================== --- src/frm/frmMain.cpp (revision 4967) +++ src/frm/frmMain.cpp (working copy) @@ -124,6 +124,7 @@ viewMenu = new wxMenu(); helpMenu = new wxMenu(); newMenu=new wxMenu(); + viewDataMenu = new wxMenu(); wxMenu *cfgMenu=new wxMenu(); @@ -141,6 +142,12 @@ actionFactory *refFact=new refreshFactory(menuFactories, viewMenu, toolBar); new countRowsFactory(menuFactories, viewMenu, 0); + new editGridLimitedFactory(menuFactories, viewDataMenu, toolBar, 10); + new editGridFactory(menuFactories, viewDataMenu, toolBar); + new editGridFilteredFactory(menuFactories, viewDataMenu, toolBar); + viewdataMenuFactory = new dummyActionFactory(menuFactories); // placeholder where "View data" submenu will be inserted + toolsMenu->Append(viewdataMenuFactory->GetId(), _("View &Data"), viewDataMenu, _("View data.")); + new separatorFactory(menuFactories); viewMenu->AppendSeparator(); @@ -190,9 +197,8 @@ toolBar->AddSeparator(); toolsMenu->AppendSeparator(); new queryToolFactory(menuFactories, toolsMenu, toolBar); - new editGridFactory(menuFactories, toolsMenu, toolBar); - new editGridFilteredFactory(menuFactories, toolsMenu, toolBar); - new maintenanceFactory(menuFactories, toolsMenu, toolBar); + + new maintenanceFactory(menuFactories, toolsMenu, toolBar); new backupFactory(menuFactories, toolsMenu, 0); new restoreFactory(menuFactories, toolsMenu, 0); Index: src/include/dlgEditGridOptions.h =================================================================== --- src/include/dlgEditGridOptions.h (revision 4967) +++ src/include/dlgEditGridOptions.h (working copy) @@ -38,7 +38,7 @@ public: // Construction - dlgEditGridOptions(frmEditGrid *parent, pgConn *conn, const wxString &rel, ctlSQLGrid *grid); + dlgEditGridOptions(frmEditGrid *parent, pgConn *conn, const wxString &rel, ctlSQLGrid *grid, int limit); private: Index: src/include/frmEditGrid.h =================================================================== --- src/include/frmEditGrid.h (revision 4967) +++ src/include/frmEditGrid.h (working copy) @@ -163,6 +163,8 @@ void SetSortCols(const wxString &cols); wxString GetFilter() const { return rowFilter; } ; void SetFilter(const wxString &filter); + int GetLimit() const { return limit; } ; + void SetLimit(const int rowlimit); private: void OnClose(wxCloseEvent& event); @@ -196,6 +198,7 @@ wxString primaryKeyColNumbers; wxString orderBy; wxString rowFilter; + int limit; DECLARE_EVENT_TABLE(); }; @@ -207,8 +210,9 @@ bool CheckEnable(pgObject *obj); protected: - editGridFactoryBase(menuFactoryList *list) : contextActionFactory(list) {} + editGridFactoryBase(menuFactoryList *list) : contextActionFactory(list) { rowlimit = 0; } wxWindow *ViewData(frmMain *form, pgObject *obj, bool filter); + int rowlimit; }; @@ -227,5 +231,12 @@ wxWindow *StartDialog(frmMain *form, pgObject *obj); }; +class editGridLimitedFactory : public editGridFactoryBase +{ +public: + editGridLimitedFactory(menuFactoryList *list, wxMenu *mnu, wxToolBar *toolbar, int limit); + wxWindow *StartDialog(frmMain *form, pgObject *obj); +}; + #endif Index: src/include/frmMain.h =================================================================== --- src/include/frmMain.h (revision 4967) +++ src/include/frmMain.h (working copy) @@ -71,12 +71,13 @@ ctlListView *referencedBy, *dependsOn; wxNotebook *listViews; ctlSQLBox *sqlPane; - wxMenu *newMenu, *toolsMenu, *viewMenu, *treeContextMenu, *newContextMenu, *slonyMenu; + wxMenu *newMenu, *toolsMenu, *viewMenu, *treeContextMenu, *newContextMenu, *slonyMenu, *viewDataMenu; pgServerCollection *serversObj; wxSplitterWindow *horizontal, *vertical; propertyFactory *propFactory; actionFactory *newMenuFactory; + actionFactory *viewdataMenuFactory; wxStopWatch stopwatch; wxString timermsg; Index: src/main/events.cpp =================================================================== --- src/main/events.cpp (revision 4967) +++ src/main/events.cpp (working copy) @@ -364,6 +364,7 @@ enableSubmenu(MNU_CONFIGSUBMENU); enableSubmenu(MNU_SLONY_SUBMENU); enableSubmenu(newMenuFactory->GetId()); + enableSubmenu(viewdataMenuFactory->GetId()); } Index: src/ui/dlgEditGridOptions.xrc =================================================================== --- src/ui/dlgEditGridOptions.xrc (revision 4967) +++ src/ui/dlgEditGridOptions.xrc (working copy) @@ -147,6 +147,33 @@ wxGROW + + + 3 + + + zz + + + + 3,3d + + + + + No limit + 100 + 500 + 1000 + + + Enter number of rows to show. + 100,12d + + + + wxGROW + 3,3d