=?utf-8?q?Bug=20507683=20=E2=80=93=20Store=20application=20UI=20state
authorPaweł Paprota <ppawel@fastmail.fm>
Sun, 16 Mar 2008 10:38:00 +0000 (16 11:38 +0100)
committerPaweł Paprota <ppawel@fastmail.fm>
Sun, 20 Apr 2008 16:45:48 +0000 (20 18:45 +0200)
=20Added=20storing=20last=20selected=20node=20in=20the=20feed=20list.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

straw/Application.py
straw/Config.py
straw/Constants.py
straw/FeedListView.py

index 370de2d..6da19a6 100644 (file)
@@ -156,6 +156,7 @@ class ApplicationPresenter(MVP.BasicPresenter):
 
         self._init_widgets()
         self._init_presenters()
+        self._restore_state()
         self._view.present()
 
     def _init_widgets(self):
@@ -223,6 +224,9 @@ class ApplicationPresenter(MVP.BasicPresenter):
     def set_current_item(self, item):
         self._current_item = item
         self._current_item_connect_id = item.connect("is-read-changed", self._on_current_item_is_read_changed)
+    
+    def _restore_state(self):
+        self._feed_list_presenter.restore_state()
 
     def clear_current_item(self):
         if self._current_item:
@@ -257,7 +261,7 @@ class ApplicationPresenter(MVP.BasicPresenter):
                 Config.set(OPTION_WINDOW_SIZE_W, width)
                 Config.set(OPTION_WINDOW_SIZE_H, height)
 
-            if (x, y) == widget.window.get_position():
+            if widget.window and (x, y) == widget.window.get_position():
                 Config.set(OPTION_WINDOW_LEFT, x)
                 Config.set(OPTION_WINDOW_TOP, y)
 
@@ -425,6 +429,7 @@ class ApplicationPresenter(MVP.BasicPresenter):
         feedproperties.show(self._curr_feed)
 
     def quit(self):
+        self._feed_list_presenter.store_state()
         gtk.main_quit()
 
     def _setup_filechooser_dialog(self, title, action, extra_widget_title):
@@ -727,7 +732,7 @@ class ApplicationView(MVP.WidgetView):
         self._widget.present()
 
     def should_present(self):
-        if self._widget.window.get_state() is not gtk.gdk.WINDOW_STATE_WITHDRAWN:
+        if self._widget.window and self._widget.window.get_state() is not gtk.gdk.WINDOW_STATE_WITHDRAWN:
             self._widget.hide()
         else:
             self._widget.present()
index b8a8337..6d5cd8a 100644 (file)
@@ -238,7 +238,9 @@ class Config(gobject.GObject):
 
     def set(self, key, value):
         if self._options.has_key(key):# and self._options[key] != value:
-            value = type(self._defaults[key])(value)
+            if value:
+                value = type(self._defaults[key])(value)
+
             self.persistence.save_option(key, value)
             self._options[key] = value
 
index a732b92..c15b839 100644 (file)
@@ -12,22 +12,26 @@ OPTION_ITEMS_STORED = "/general/number_of_items_stored"
 OPTION_ITEM_ORDER = "/general/item_order_newest"
 OPTION_WEB_BROWSER_CMD = "/general/browser_cmd"
 OPTION_WEB_BROWSER_TYPE = "/general/browser_type"
+
 OPTION_WINDOW_LEFT = "/ui/window_left"
 OPTION_WINDOW_TOP = "/ui/window_top"
 OPTION_WINDOW_SIZE_H = "/ui/window_height"
 OPTION_WINDOW_SIZE_W = "/ui/window_width"
+OPTION_WINDOW_MAX = "/ui/window_maximized"
+
 OPTION_MAIN_PANE_POS = "/ui/main_pane_position"
 OPTION_SUB_PANE_POS = "/ui/sub_pane_position"
-OPTION_WINDOW_MAX = "/ui/window_maximized"
+
 OPTION_MAGNIFICATION = "/ui/text_magnification"
 OPTION_PANE_LAYOUT = "/ui/pane_layout"
 OPTION_OFFLINE = "/general/offline"
 OPTION_POLL_FREQUENCY = "/general/poll_frequency"
 
+OPTION_LAST_SELECTED_NODE = "/ui/last_selected_node"
+
 OPTION_PROXY_TYPE = "/network/proxy_type"
 OPTION_PROXY_SERVER = "/network/proxy_server"
 OPTION_PROXY_PORT = "/network/proxy_port"
-
 OPTION_PROXY_AUTH_ACTIVE = "/network/proxy_auth_active"
 OPTION_PROXY_AUTH_USERNAME = "/network/proxy_auth_username"
 OPTION_PROXY_AUTH_PASSWORD = "/network/proxy_auth_password"
@@ -39,17 +43,23 @@ config_options_defaults = \
     OPTION_ITEM_ORDER:        True,
     OPTION_WEB_BROWSER_CMD:   "",
     OPTION_WEB_BROWSER_TYPE:  "gnome",
+
     OPTION_WINDOW_LEFT:       0,
     OPTION_WINDOW_TOP:        0,
     OPTION_WINDOW_SIZE_W:     640,
     OPTION_WINDOW_SIZE_H:     480,
+    OPTION_WINDOW_MAX:        False,
+
     OPTION_MAIN_PANE_POS:     100,
     OPTION_SUB_PANE_POS:      100,
-    OPTION_WINDOW_MAX:        False,
+
     OPTION_MAGNIFICATION:     1.0,
     OPTION_PANE_LAYOUT:       "vertical",
     OPTION_OFFLINE:           True,
     OPTION_POLL_FREQUENCY:    1800,
+
+    OPTION_LAST_SELECTED_NODE: -1,
+
     OPTION_PROXY_TYPE:        "none",
     OPTION_PROXY_SERVER:      "http://example.server/",
     OPTION_PROXY_PORT:        8080,
index ecfe7f6..1d8d87e 100644 (file)
@@ -425,6 +425,26 @@ class FeedsView(MVP.WidgetView):
 
         return retval
 
+    def get_selected_node(self):
+        nodes = [node for node in self.selected()]
+        
+        if len(nodes) > 0:
+            return nodes[0].node
+        else:
+            return None
+    
+    def select_node(self, id):
+        path = self.model.tv_nodes[id].path
+
+        if not path:
+            return
+
+        selection = self._widget.get_selection()
+        selection.unselect_all()
+        self._widget.expand_to_path(path)
+        selection.select_path(path)
+        self._widget.grab_focus()
+
     def selected_count(self):
         selection = self._widget.get_selection()
         pathlist = selection.get_selected_rows()[1]
@@ -615,11 +635,22 @@ class FeedsView(MVP.WidgetView):
 class FeedsPresenter(MVP.BasicPresenter):
     def _initialize(self):
         self.model = FeedListModel()
-        self._init_signals()
 
-    def _init_signals(self):
-        pass
-    
+    def store_state(self):
+        node = self.view.get_selected_node()
+        id = -1
+
+        if node:
+            id = node.id
+
+        Config.set(OPTION_LAST_SELECTED_NODE, id)
+
+    def restore_state(self):
+        id = Config.get(OPTION_LAST_SELECTED_NODE)
+        
+        if id != -1:
+            self.view.select_node(id)
+
     def add_category(self):
         self.view.add_category()