1 """This controller handles the stash dialog."""
7 from cola
import qtutils
8 from cola
.qobserver
import QObserver
9 from cola
.views
import StashView
11 def stash(model
, parent
):
13 model
.create( stash_list
=[], stash_revids
=[] )
14 view
= StashView(parent
)
15 ctl
= StashController(model
, view
)
18 class StashController(QObserver
):
19 def init (self
, model
, view
):
20 self
.add_observables('stash_list')
21 self
.add_callbacks(button_stash_show
= self
.stash_show
,
22 button_stash_apply
= self
.stash_apply
,
23 button_stash_drop
= self
.stash_drop
,
24 button_stash_clear
= self
.stash_clear
,
25 button_stash_save
= self
.stash_save
)
28 def update_model(self
):
29 self
.model
.set_stash_list(self
.model
.parse_stash_list())
30 self
.model
.set_stash_revids(self
.model
.parse_stash_list(revids
=True))
33 def get_selected_stash(self
):
34 list_widget
= self
.view
.stash_list
35 stash_list
= self
.model
.get_stash_revids()
36 return qtutils
.get_selected_item(list_widget
, stash_list
)
39 if not qtutils
.question(self
.view
,
40 self
.tr('Stash Changes?'),
41 self
.tr('This will stash your current '
42 'changes away for later use.\n'
46 stash_name
, ok
= qtutils
.input(self
.tr('Enter a name for this stash'))
49 while stash_name
in self
.model
.get_stash_list():
50 qtutils
.information(self
.tr("Oops!"),
51 self
.tr('That name already exists. '
52 'Please enter another name.'))
53 stash_name
, ok
= qtutils
.input(self
.tr("Enter a name for this stash"))
60 # Sanitize our input, just in case
61 stash_name
= utils
.sanitize_input(stash_name
)
62 qtutils
.log(self
.model
.git
.stash('save', stash_name
),
68 """Shows the current stash in the main view."""
69 selection
= self
.get_selected_stash()
72 diffstat
= self
.model
.git
.stash('show', selection
)
73 diff
= self
.model
.stash('show', '-p', selection
)
74 self
.view
.parent_view
.display('%s\n\n%s' % (diffstat
, diff
))
76 def stash_apply(self
):
77 selection
= self
.get_selected_stash()
80 (status
, stdout
, stderr
) =\
81 self
.model
.git
.stash('apply', selection
,
82 with_extended_output
=True)
83 qtutils
.log(stdout
+ stderr
,
89 selection
= self
.get_selected_stash()
92 if not qtutils
.question(self
.view
,
93 self
.tr('Drop Stash?'),
94 self
.tr('This will permanently remove the '
96 'Recovering these changes may not '
100 qtutils
.log(self
.model
.git
.stash('drop', selection
),
105 def stash_clear(self
):
106 if not qtutils
.question(self
.view
,
107 self
.tr('Drop All Stashes?'),
108 self
.tr('This will permanently remove '
109 'ALL stashed changes.\n'
110 'Recovering these changes may not '
114 self
.model
.git
.stash('clear'),