OSDN Git Service

Fix bug where switching between wide & narrow views wouldn't restore the sort column...
authorRandy Baumgarte <randy@fbn.cx>
Thu, 16 Dec 2010 19:31:42 +0000 (14:31 -0500)
committerRandy Baumgarte <randy@fbn.cx>
Sun, 19 Dec 2010 04:00:45 +0000 (23:00 -0500)
src/cx/fbn/nevernote/Global.java
src/cx/fbn/nevernote/NeverNote.java

index c7b2abe..05887c2 100644 (file)
@@ -372,8 +372,9 @@ public class Global {
                settings.endGroup();\r
     }\r
     public static void setSortColumn(int i) {\r
+       int view = Global.getListView();\r
                settings.beginGroup("General");\r
-       if (Global.getListView() == Global.View_List_Wide)\r
+       if (view == Global.View_List_Wide)\r
                settings.setValue("sortColumn", i);\r
        else\r
                settings.setValue("sortColumn-Narrow", i);\r
@@ -403,19 +404,30 @@ public class Global {
        return order;\r
     }\r
     public static void setSortOrder(int i) {\r
+       int view = Global.getListView();\r
                settings.beginGroup("General");\r
-               settings.setValue("sortOrder", i);\r
+       if (view == Global.View_List_Wide)\r
+               settings.setValue("sortOrder", i);\r
+       else\r
+               settings.setValue("sortOrder-Narrow", i);\r
                settings.endGroup();\r
     }\r
     public static int getSortOrder() {\r
+       int view = Global.getListView();\r
                settings.beginGroup("General");\r
+               String key;\r
+       if (view == Global.View_List_Wide)\r
+               key = "sortOrder";\r
+               else\r
+                       key = "sortOrder-Narrow";\r
+\r
                int order;      \r
                try {\r
-                       String val  = settings.value("sortOrder", new Integer(0)).toString();\r
+                       String val  = settings.value(key, new Integer(0)).toString();\r
                        order = new Integer(val.trim());\r
                } catch (Exception e) {\r
                        try {\r
-                               order = (Integer)settings.value("sortOrder", 0);\r
+                               order = (Integer)settings.value(key, 0);\r
                        } catch (Exception e1) {\r
                            order = 0;\r
                        }\r
index bc58d73..b9c7c61 100644 (file)
@@ -668,14 +668,18 @@ public class NeverNote extends QMainWindow{
        historyGuids.add(currentNoteGuid);
        historyPosition = 1;
        
+       menuBar.blockSignals(true);
+       menuBar.narrowListView.blockSignals(true);
+       menuBar.wideListView.blockSignals(true);
         if (Global.getListView() == Global.View_List_Narrow) { 
                menuBar.narrowListView.setChecked(true);
-//             narrowListView();
         }
         else{ 
                menuBar.wideListView.setChecked(true);
-//             wideListView();
         }
+        menuBar.blockSignals(false);
+       menuBar.narrowListView.blockSignals(false);
+       menuBar.wideListView.blockSignals(false);
 
         if (Global.getListView() == Global.View_List_Wide) {
                browserIndexSplitter.addWidget(noteTableView);
@@ -3726,7 +3730,12 @@ public class NeverNote extends QMainWindow{
        saveNoteColumnPositions();
        saveNoteIndexWidth();
        saveWindowState();
-       Global.setListView(Global.View_List_Narrow);
+               int sortCol = noteTableView.proxyModel.sortColumn();
+               int sortOrder = noteTableView.proxyModel.sortOrder().value();
+               Global.setSortColumn(sortCol);
+               Global.setSortOrder(sortOrder);
+
+               Global.setListView(Global.View_List_Narrow);
        
        menuBar.wideListView.blockSignals(true);
        menuBar.narrowListView.blockSignals(true);
@@ -3743,12 +3752,22 @@ public class NeverNote extends QMainWindow{
        noteTableView.repositionColumns();
        noteTableView.resizeColumnWidths();
        noteTableView.resizeRowHeights();
+       
+       sortCol = Global.getSortColumn();
+               sortOrder = Global.getSortOrder();
+               noteTableView.sortByColumn(sortCol, SortOrder.resolve(sortOrder));
+               
        showColumns();
        noteTableView.load(false);
        scrollToCurrentGuid();
     }
     public void wideListView() {
-       saveWindowState();
+               int sortCol = noteTableView.proxyModel.sortColumn();
+               int sortOrder = noteTableView.proxyModel.sortOrder().value();
+               Global.setSortColumn(sortCol);
+               Global.setSortOrder(sortOrder);
+
+               saveWindowState();
        saveNoteColumnPositions();
        saveNoteIndexWidth();
        Global.setListView(Global.View_List_Wide);
@@ -3768,6 +3787,11 @@ public class NeverNote extends QMainWindow{
        noteTableView.repositionColumns();
        noteTableView.resizeColumnWidths();
        noteTableView.resizeRowHeights();
+       
+       sortCol = Global.getSortColumn();
+               sortOrder = Global.getSortOrder();
+               noteTableView.sortByColumn(sortCol, SortOrder.resolve(sortOrder));
+       
        showColumns();
        noteTableView.load(false);
        scrollToCurrentGuid();