Remove useless parens
[pysize.git] / pysize / core / history.py
bloba9848ea0f6868198866d9887685298c55f345bac
1 from pysize.core.pysize_fs_tree import pysize_tree
2 from pysize.core.observable import observable
4 # [(fullpaths, name)]
5 history = []
6 next_insertion_index = 0
7 history_observable = observable()
9 def add_entry(tree):
10 global next_insertion_index
11 fp = tree.fullpaths
12 same = next_insertion_index and fp == history[next_insertion_index - 1][0]
13 if not same:
14 if next_insertion_index == len(history):
15 # History is being written
16 history.append(None)
17 else:
18 paths, name = history[next_insertion_index]
19 if fp != paths:
20 # History took another path, clear the remaining forward history
21 del history[next_insertion_index + 1:]
22 history[next_insertion_index] = fp, tree.root.get_name()
23 next_insertion_index += 1
24 history_observable.fire_observers(next_insertion_index, history)
26 def go_to_history(index):
27 global next_insertion_index
28 entry = history[index][0]
29 next_insertion_index = index + 1
30 history_observable.fire_observers(next_insertion_index, history)
31 return entry
33 def forward():
34 if len(history) > next_insertion_index:
35 return go_to_history(next_insertion_index)
37 def back():
38 if next_insertion_index > 1:
39 return go_to_history(next_insertion_index - 2)