[Libreoffice-commits] .: sc/source

Kohei Yoshida kohei at kemper.freedesktop.org
Thu May 17 19:14:19 PDT 2012


 sc/source/ui/inc/gridwin.hxx  |    2 -
 sc/source/ui/view/gridwin.cxx |   46 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 1 deletion(-)

New commits:
commit 2a755c0cd61b619ed14e023ad34fc7596eafdf34
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Thu May 17 22:16:42 2012 -0400

    Add sort options to the autofilter popup.
    
    Change-Id: I217b41f966220b8b1ee9638d3f6a31a23dc4bf2e

diff --git a/sc/source/ui/inc/gridwin.hxx b/sc/source/ui/inc/gridwin.hxx
index 1b10ad0..8a64de9 100644
--- a/sc/source/ui/inc/gridwin.hxx
+++ b/sc/source/ui/inc/gridwin.hxx
@@ -304,7 +304,7 @@ protected:
     virtual void    StartDrag( sal_Int8 nAction, const Point& rPosPixel );
 
 public:
-    enum AutoFilterMode { Normal, Top10, Custom, Empty, NonEmpty };
+    enum AutoFilterMode { Normal, Top10, Custom, Empty, NonEmpty, SortAscending, SortDescending };
 
     ScGridWindow( Window* pParent, ScViewData* pData, ScSplitPos eWhichPos );
     ~ScGridWindow();
diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index 9bb8c63..40e8f38 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -129,6 +129,8 @@
 #include "cliputil.hxx"
 #include "queryentry.hxx"
 #include "markdata.hxx"
+#include "checklistmenu.hrc"
+#include "strload.hxx"
 
 #include <svx/sdrpagewindow.hxx>
 #include <svx/sdr/overlay/overlaymanager.hxx>
@@ -705,6 +707,13 @@ void ScGridWindow::LaunchAutoFilterMenu(SCCOL nCol, SCROW nRow)
 
     // Populate the menu.
     mpAutoFilterPopup->addMenuItem(
+        ScRscStrLoader(RID_POPUP_FILTER, STR_MENU_SORT_ASC).GetString(),
+        true, new AutoFilterAction(this, SortAscending));
+    mpAutoFilterPopup->addMenuItem(
+        ScRscStrLoader(RID_POPUP_FILTER, STR_MENU_SORT_DESC).GetString(),
+        true, new AutoFilterAction(this, SortDescending));
+    mpAutoFilterPopup->addSeparator();
+    mpAutoFilterPopup->addMenuItem(
         SC_RESSTR(SCSTR_TOP10FILTER), true, new AutoFilterAction(this, Top10));
     mpAutoFilterPopup->addMenuItem(
         SC_RESSTR(SCSTR_FILTER_EMPTY), true, new AutoFilterAction(this, Empty));
@@ -746,6 +755,43 @@ void ScGridWindow::UpdateAutoFilterFromMenu(AutoFilterMode eMode)
     if (!pDBData)
         return;
 
+    switch (eMode)
+    {
+        case SortAscending:
+        case SortDescending:
+        {
+            ScDocument* pDoc = pViewData->GetDocument();
+            SCTAB nTab = pViewData->GetTabNo();
+            SCCOL nCol = rPos.Col();
+            ScSortParam aSortParam;
+            pDBData->GetSortParam(aSortParam);
+            if (nCol < aSortParam.nCol1 || nCol > aSortParam.nCol2)
+                // out of bound
+                return;
+
+            bool bHasHeader = pDoc->HasColHeader(
+                aSortParam.nCol1, aSortParam.nRow1, aSortParam.nCol2, aSortParam.nRow2, nTab);
+
+            aSortParam.bHasHeader = bHasHeader;
+            aSortParam.bByRow = true;
+            aSortParam.bCaseSens = false;
+            aSortParam.bNaturalSort = false;
+            aSortParam.bIncludePattern = true;
+            aSortParam.bInplace = true;
+            aSortParam.maKeyState[0].bDoSort = true;
+            aSortParam.maKeyState[0].nField = nCol;
+            aSortParam.maKeyState[0].bAscending = (eMode == SortAscending);
+
+            for (size_t i = 1; i < aSortParam.GetSortKeyCount(); ++i)
+                aSortParam.maKeyState[i].bDoSort = false;
+
+            pViewData->GetViewShell()->UISort(aSortParam);
+            return;
+        }
+        default:
+            ;
+    }
+
     if (eMode == Custom)
     {
         ScRange aRange;


More information about the Libreoffice-commits mailing list