1 """Provides a selection model to handle selection."""
3 from cola
.models
.observable
import ObservableModel
4 from cola
.decorators
import memoize
9 """Provides access to a static SelectionModel instance."""
10 return SelectionModel()
14 """Return the current selection."""
15 model
= selection_model()
16 return (model
.staged
, model
.modified
, model
.unmerged
, model
.untracked
)
19 def single_selection():
20 """Scan across staged, modified, etc. and return a single item."""
21 staged
, modified
, unmerged
, untracked
= selection()
38 s
, m
, um
, ut
= single_selection()
50 class SelectionModel(ObservableModel
):
51 """Provides information about selected file paths."""
52 # Notification message sent out when selection changes
53 message_selection_changed
= 'selection_changed'
55 # These properties wrap the individual selection items
56 # to provide higher-level pseudo-selections.
57 unstaged
= property(lambda self
: self
.modified
+
61 all
= property(lambda self
: self
.staged
+
67 ObservableModel
.__init
__(self
)
73 def set_selection(self
, staged
, modified
, unmerged
, untracked
):
74 """Set the new selection."""
75 self
.set_staged(staged
)
76 self
.set_modified(modified
)
77 self
.set_unmerged(unmerged
)
78 self
.set_untracked(untracked
)
79 self
.notify_message_observers(self
.message_selection_changed
)