Hi Dave, Thanks for the feedback. A positive note certainly helps :)
I've tried to work on the things mentioned and although I can think of a few more additions, I think I'd work on them separately once this gets through. A few updates: 1. Replaced all SQL related _() with wxT() 2. Created a separate Tools Menu. Moved 'Sort / Filter ...' there and added all the new 'right-clickable options' there as well. 3. Right-clicking a cell makes that cell the selected cell on the grid. 4. Empty strings are now taken care of as well. 5. As earlier, all options(including the sort options) refresh the grid immediately. Hope I didn't miss anything! Regards, *Robins Tharakan* ---------- Forwarded message ---------- From: Dave Page <[EMAIL PROTECTED]> Date: Feb 4, 2008 5:55 PM Subject: Re: [pgadmin-hackers] Fwd: Filter by Selection on Grid To: [EMAIL PROTECTED] Cc: pgadmin-hackers@postgresql.org Hi, On Feb 1, 2008 4:38 AM, Robins Tharakan <[EMAIL PROTECTED]> wrote: > The good part is that now the patch does the following: > 1. Provide options for 'Filter by Selection' / 'Filter Excluding Selection' > / 'Remove Filter' > 2. Takes care if cells have NULL value > 3. Takes multiple Include / Exclude selections and refreshes automatically Looks good :-) Some minor comments: - the _() macro is used for strings that need translation, so please use wxT() for those that don't, such as parts of SQL queries. - I think we should have the menu options on a new Tools menu as well (we normally duplicate context menu options onto the main menu for accessibility reasons). We should probably move the Sort/Filter option onto there as well. > Limitations that I plan to remove soon: > 1. The cell chosen is the 'Selected cell' and that may not be the one > right-clicked. I'd change that soon. Yeah - I've actually been thinking that for various reasons we might want to have the active cell follow the mouse clicks and row/column selections anyway. > 2. I am unable to evaluate strings if they are Empty, so > including/excluding empty-cells (not NULLs) doesn't do anything ! > Frustrating ! May be I just need a break, a bit of reading and I'll get that > done soon as well! Don't forget that empty strings are displayed as '' (two single quotes), and a string that actually is two single quotes is \'\'. You'll need to allow for those when building your filters. > In case this patch is considered by and large fine, and in case you are ok > with more additions, I'll try adding more features in the right click menu > (Filter by Custom String / Sort options etc..) similar to what we have in > the Access UI. I look forward to it :-) Thanks, Dave
Index: pgadmin/include/frm/frmEditGrid.h =================================================================== --- pgadmin/include/frm/frmEditGrid.h (revision 7027) +++ pgadmin/include/frm/frmEditGrid.h (working copy) @@ -122,6 +122,7 @@ int GetNumberStoredRows(); int GetNumberCols(); wxString GetColLabelValue(int col); + wxString GetColLabelValueUnformatted(int col); wxString GetRowLabelValue(int row); wxGridCellAttr* GetAttr(int row, int col, wxGridCellAttr::wxAttrKind kind); @@ -214,9 +215,16 @@ void OnEditorHidden(wxGridEvent& event); void OnKey(wxKeyEvent& event); void OnCopy(wxCommandEvent& event); + void OnIncludeFilter(wxCommandEvent& event); + void OnExcludeFilter(wxCommandEvent& event); + void OnRemoveFilters(wxCommandEvent& event); + void OnAscSort(wxCommandEvent& event); + void OnDescSort(wxCommandEvent& event); + void OnRemoveSort(wxCommandEvent& event); void OnPaste(wxCommandEvent& event); void OnLabelDoubleClick(wxGridEvent& event); void OnLabelRightClick(wxGridEvent& event); + void OnCellRightClick(wxGridEvent& event); void Abort(); void OnToggleScratchPad(wxCommandEvent& event); void OnToggleLimitBar(wxCommandEvent& event); @@ -230,7 +238,7 @@ frmMain *mainForm; pgConn *connection; pgQueryThread *thread; - wxMenu *fileMenu, *editMenu, *viewMenu, *helpMenu; + wxMenu *fileMenu, *editMenu, *viewMenu, *toolsMenu, *helpMenu; wxToolBar *toolBar; ctlComboBoxFix *cbLimit; wxTextCtrl *scratchPad; Index: pgadmin/include/frm/menu.h =================================================================== --- pgadmin/include/frm/menu.h (revision 7027) +++ pgadmin/include/frm/menu.h (working copy) @@ -46,6 +46,12 @@ MNU_OPTIONS, MNU_CUT, MNU_COPY, + MNU_INCLUDEFILTER, + MNU_EXCLUDEFILTER, + MNU_REMOVEFILTERS, + MNU_ASCSORT, + MNU_DESCSORT, + MNU_REMOVESORT, MNU_PASTE, MNU_CLEAR, MNU_FIND, Index: pgadmin/frm/frmEditGrid.cpp =================================================================== --- pgadmin/frm/frmEditGrid.cpp (revision 7027) +++ pgadmin/frm/frmEditGrid.cpp (working copy) @@ -59,6 +59,12 @@ EVT_MENU(MNU_REFRESH, frmEditGrid::OnRefresh) EVT_MENU(MNU_DELETE, frmEditGrid::OnDelete) EVT_MENU(MNU_SAVE, frmEditGrid::OnSave) + EVT_MENU(MNU_INCLUDEFILTER, frmEditGrid::OnIncludeFilter) + EVT_MENU(MNU_EXCLUDEFILTER, frmEditGrid::OnExcludeFilter) + EVT_MENU(MNU_REMOVEFILTERS, frmEditGrid::OnRemoveFilters) + EVT_MENU(MNU_ASCSORT, frmEditGrid::OnAscSort) + EVT_MENU(MNU_DESCSORT, frmEditGrid::OnDescSort) + EVT_MENU(MNU_REMOVESORT, frmEditGrid::OnRemoveSort) EVT_MENU(MNU_UNDO, frmEditGrid::OnUndo) EVT_MENU(MNU_OPTIONS, frmEditGrid::OnOptions) EVT_MENU(MNU_HELP, frmEditGrid::OnHelp) @@ -76,6 +82,7 @@ EVT_GRID_SELECT_CELL( frmEditGrid::OnCellChange) EVT_GRID_EDITOR_SHOWN( frmEditGrid::OnEditorShown) EVT_GRID_EDITOR_HIDDEN( frmEditGrid::OnEditorHidden) + EVT_GRID_CELL_RIGHT_CLICK( frmEditGrid::OnCellRightClick) EVT_GRID_LABEL_RIGHT_CLICK( frmEditGrid::OnLabelRightClick) EVT_AUI_PANE_BUTTON( frmEditGrid::OnAuiUpdate) END_EVENT_TABLE() @@ -171,14 +178,25 @@ viewMenu = new wxMenu(); viewMenu->Append(MNU_REFRESH, _("&Refresh\tF5"),_("Refresh.")); viewMenu->AppendSeparator(); - viewMenu->Append(MNU_OPTIONS, _("&Sort/filter..."),_("Sort/filter options.")); - viewMenu->AppendSeparator(); viewMenu->Append(MNU_LIMITBAR, _("&Limit bar\tCtrl-Alt-L"), _("Show or hide the row limit options bar."), wxITEM_CHECK); viewMenu->Append(MNU_SCRATCHPAD, _("S&cratch pad\tCtrl-Alt-S"), _("Show or hide the scratch pad."), wxITEM_CHECK); viewMenu->Append(MNU_TOOLBAR, _("&Tool bar\tCtrl-Alt-T"), _("Show or hide the tool bar."), wxITEM_CHECK); viewMenu->AppendSeparator(); viewMenu->Append(MNU_DEFAULTVIEW, _("&Default view\tCtrl-Alt-V"), _("Restore the default view.")); + + // Tools menu + toolsMenu = new wxMenu(); + toolsMenu->Append(MNU_OPTIONS, _("&Sort / Filter ..."),_("Sort / Filter options.")); + toolsMenu->AppendSeparator(); + toolsMenu->Append(MNU_INCLUDEFILTER, _("Filter By &Selection"),_("Display only those rows that have this value in this column.")); + toolsMenu->Append(MNU_EXCLUDEFILTER, _("Filter E&xcluding Selection"),_("Display only those rows that do not have this value in this column.")); + toolsMenu->Append(MNU_REMOVEFILTERS, _("&Remove Filter"),_("Remove all filters on this table")); + toolsMenu->AppendSeparator(); + toolsMenu->Append(MNU_ASCSORT, _("Sort &Ascending"),_("Append an ASCENDING sort condition based on this column")); + toolsMenu->Append(MNU_DESCSORT, _("Sort &Descending"),_("Append a DESCENDING sort condition based on this column")); + toolsMenu->Append(MNU_REMOVESORT, _("&Remove Sort"),_("Remove all sort conditions")); + // Help menu helpMenu = new wxMenu(); helpMenu->Append(MNU_CONTENTS, _("&Help contents"),_("Open the helpfile.")); @@ -188,6 +206,7 @@ menuBar->Append(fileMenu, _("&File")); menuBar->Append(editMenu, _("&Edit")); menuBar->Append(viewMenu, _("&View")); + menuBar->Append(toolsMenu,_("&Tools")); menuBar->Append(helpMenu, _("&Help")); SetMenuBar(menuBar); @@ -388,6 +407,32 @@ } +void frmEditGrid::OnCellRightClick(wxGridEvent& event) +{ + wxMenu *xmenu = new wxMenu(); + + sqlGrid->SetGridCursor(event.GetRow(), event.GetCol()); + + xmenu->Append(MNU_INCLUDEFILTER, _("Filter By &Selection"),_("Display only those rows that have this value in this column.")); + xmenu->Append(MNU_EXCLUDEFILTER, _("Filter E&xcluding Selection"),_("Display only those rows that do not have this value in this column.")); + xmenu->Append(MNU_REMOVEFILTERS, _("&Remove Filter"),_("Remove all filters on this table")); + xmenu->InsertSeparator(3); + xmenu->Append(MNU_ASCSORT, _("Sort &Ascending"),_("Append an ASCENDING sort condition based on this column")); + xmenu->Append(MNU_DESCSORT, _("Sort &Descending"),_("Append a DESCENDING sort condition based on this column")); + xmenu->Append(MNU_REMOVESORT, _("&Remove Sort"),_("Remove all sort conditions")); + xmenu->InsertSeparator(7); + + xmenu->Enable(MNU_INCLUDEFILTER, true); + xmenu->Enable(MNU_EXCLUDEFILTER, true); + xmenu->Enable(MNU_REMOVEFILTERS, true); + xmenu->Enable(MNU_ASCSORT, true); + xmenu->Enable(MNU_DESCSORT, true); + xmenu->Enable(MNU_REMOVESORT, true); + + sqlGrid->PopupMenu(xmenu); +} + + void frmEditGrid::OnCellChange(wxGridEvent& event) { sqlTable *table=sqlGrid->GetTable(); @@ -416,6 +461,149 @@ } +void frmEditGrid::OnIncludeFilter(wxCommandEvent &event) +{ + int curcol=sqlGrid->GetGridCursorCol(); + int currow=sqlGrid->GetGridCursorRow(); + + sqlTable *table=sqlGrid->GetTable(); + wxString column_label = table->GetColLabelValueUnformatted(curcol); + wxString new_filter_string; + + size_t old_filter_string_length = GetFilter().Trim().Len(); + + if (old_filter_string_length > 0) { + new_filter_string = GetFilter().Trim() + wxT(" \n AND "); + } + + if (table->IsColText(curcol)) { + + if (sqlGrid->GetCellValue(currow, curcol).IsNull()) { + new_filter_string += column_label + wxT(" IS NULL "); + } else { + + if (sqlGrid->GetCellValue(currow, curcol) == wxT("\'\'")) { + new_filter_string += column_label + wxT(" = ''"); + } else { + new_filter_string += column_label + wxT(" = '") + sqlGrid->GetCellValue(currow, curcol) + wxT("' "); + } + } + } else { + + if (sqlGrid->GetCellValue(currow, curcol).IsNull()) { + new_filter_string += column_label + wxT(" IS NULL "); + } else { + new_filter_string += column_label + wxT(" = ") + sqlGrid->GetCellValue(currow, curcol); + } + } + + SetFilter(new_filter_string); + + Go(); +} + + +void frmEditGrid::OnExcludeFilter(wxCommandEvent &event) +{ + int curcol=sqlGrid->GetGridCursorCol(); + int currow=sqlGrid->GetGridCursorRow(); + + sqlTable *table=sqlGrid->GetTable(); + wxString column_label = table->GetColLabelValueUnformatted(curcol); + wxString new_filter_string; + + size_t old_filter_string_length = GetFilter().Trim().Len(); + + if (old_filter_string_length > 0) { + new_filter_string = GetFilter().Trim() + wxT(" \n AND "); + } + + if (table->IsColText(curcol)) { + if (sqlGrid->GetCellValue(currow, curcol).IsNull()) { + new_filter_string += column_label + wxT(" IS NOT NULL "); + } else { + + if (sqlGrid->GetCellValue(currow, curcol) == wxT("\'\'")) { + new_filter_string += column_label + wxString::Format(_(" <> '' ")) ; + } else { + new_filter_string += column_label + wxT(" <> '") + sqlGrid->GetCellValue(currow, curcol) + wxT("' "); + } + } + } else { + + if (sqlGrid->GetCellValue(currow, curcol).IsNull()) { + new_filter_string += column_label + wxT(" IS NOT NULL ") ; + } else { + new_filter_string += column_label + wxT(" <> ") + sqlGrid->GetCellValue(currow, curcol); + } + } + + SetFilter(new_filter_string); + + Go(); +} + + +void frmEditGrid::OnRemoveFilters(wxCommandEvent &event) +{ + SetFilter(wxT("")); + + Go(); +} + + +void frmEditGrid::OnAscSort(wxCommandEvent &ev) +{ + int curcol=sqlGrid->GetGridCursorCol(); + + sqlTable *table=sqlGrid->GetTable(); + wxString column_label = table->GetColLabelValueUnformatted(curcol); + wxString new_sort_string; + + size_t old_sort_string_length = GetSortCols().Trim().Len(); + + if (old_sort_string_length > 0) { + new_sort_string = GetSortCols().Trim() + wxT(" , "); + } + + new_sort_string += column_label + wxT(" ASC "); + + SetSortCols(new_sort_string); + + Go(); +} + + +void frmEditGrid::OnDescSort(wxCommandEvent &ev) +{ + int curcol=sqlGrid->GetGridCursorCol(); + + sqlTable *table=sqlGrid->GetTable(); + wxString column_label = table->GetColLabelValueUnformatted(curcol); + wxString new_sort_string; + + size_t old_sort_string_length = GetSortCols().Trim().Len(); + + if (old_sort_string_length > 0) { + new_sort_string = GetSortCols().Trim() + wxT(" , "); + } + + new_sort_string += column_label + wxT(" DESC "); + + SetSortCols(new_sort_string); + + Go(); +} + + +void frmEditGrid::OnRemoveSort(wxCommandEvent &ev) +{ + SetSortCols(wxT("")); + + Go(); +} + + void frmEditGrid::OnCopy(wxCommandEvent &ev) { wxWindow *wnd=FindFocus(); @@ -746,6 +934,7 @@ if (optionsChanged) Go(); } + template < class T > int ArrayCmp(T *a, T *b) { @@ -1994,6 +2183,12 @@ } +wxString sqlTable::GetColLabelValueUnformatted(int col) +{ + return columns[col].name; +} + + wxString sqlTable::GetRowLabelValue(int row) { wxString label; Index: pgadmin/dlg/dlgEditGridOptions.cpp =================================================================== --- pgadmin/dlg/dlgEditGridOptions.cpp (revision 7027) +++ pgadmin/dlg/dlgEditGridOptions.cpp (working copy) @@ -187,6 +187,7 @@ OnLstSortColsChange(nullLstEvent); } + void dlgEditGridOptions::OnAsc(wxCommandEvent &ev) { long itm = lstSortCols->GetItemCount();
---------------------------(end of broadcast)--------------------------- TIP 4: Have you searched our list archives? http://archives.postgresql.org