Skip to content

Commit

Permalink
panel/files: Save cursor location in history entry.
Browse files Browse the repository at this point in the history
This is really not the best; we should save the selection instead and also
do it on every back/forward as well (so that new selections will be
retained in the history). It's better than nothing though.

Addresses https://github.com/exaile/exaile/issues/195#issuecomment-214732297
  • Loading branch information
sjohannes authored and tfree87 committed May 5, 2016
1 parent 8390311 commit 84cc24e
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions xlgui/panel/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from gi.repository import GLib
from gi.repository import GObject
from gi.repository import Gtk
import collections
import locale
import logging
import os
Expand Down Expand Up @@ -60,6 +61,11 @@
logger = logging.getLogger(__name__)


# TODO: Cursor is wrong if the directory content is modified.
# Maybe use the selected gfiles instead.
HistoryEntry = collections.namedtuple('HistoryEntry', 'gfile cursor')


class FilesPanel(panel.Panel):
"""
The Files panel
Expand Down Expand Up @@ -92,7 +98,7 @@ def __init__(self, parent, collection, name):

first_dir = Gio.File.new_for_commandline_arg(settings.get_option('gui/files_panel_dir',
xdg.homedir))
self.history = [first_dir]
self.history = [HistoryEntry(first_dir, None)]
self.load_directory(first_dir, False)

def _setup_tree(self):
Expand Down Expand Up @@ -299,7 +305,8 @@ def go_forward(self, widget):
"""
if self.i < len(self.history) - 1:
self.i += 1
self.load_directory(self.history[self.i], False)
hentry = self.history[self.i]
self.load_directory(hentry.gfile, False, cursor=hentry.cursor)
if self.i >= len(self.history) - 1:
self.forward.set_sensitive(False)
if len(self.history):
Expand All @@ -311,7 +318,8 @@ def go_back(self, widget):
"""
if self.i > 0:
self.i -= 1
self.load_directory(self.history[self.i], False)
hentry = self.history[self.i]
self.load_directory(hentry.gfile, False, cursor=hentry.cursor)
if self.i == 0:
self.back.set_sensitive(False)
if len(self.history):
Expand Down Expand Up @@ -398,6 +406,8 @@ def idle():
model = self.model
view = self.tree

old_cursor = view.get_cursor()

model.clear()
for sortname, name, f in subdirs:
model.append((f, self.directory, name, ''))
Expand All @@ -422,9 +432,11 @@ def idle():
self.entry.set_text(directory.get_parse_name())
if history:
self.back.set_sensitive(True)
self.history = self.history[:self.i + 1]
self.history.append(self.current)
self.i = len(self.history) - 1
hist = self.history
del hist[self.i+1:]
hist[-1] = HistoryEntry(hist[-1].gfile, old_cursor)
hist.append(HistoryEntry(self.current, None))
self.i = len(hist) - 1
self.forward.set_sensitive(False)
self.up.set_sensitive(bool(directory.get_parent()))

Expand Down

0 comments on commit 84cc24e

Please sign in to comment.