@@ -51,6 +51,8 @@ def __init__(self, parent=None):
5151 self ._diff_window = None
5252
5353 self ._init_ui ()
54+ self ._create_actions ()
55+ self ._create_toolbar ()
5456
5557 icon_loader = IconLoader ()
5658 self .setWindowIcon (icon_loader ['code-review@svg' ])
@@ -97,14 +99,48 @@ def _init_ui(self):
9799
98100 def _create_actions (self ):
99101
100- pass
101102 # icon_loader = IconLoader()
103+
104+ self ._stagged_mode_action = \
105+ QtWidgets .QAction ('Stagged' ,
106+ self ,
107+ toolTip = 'Stagged Mode' ,
108+ shortcut = 'Ctrl+1' ,
109+ checkable = True ,
110+ )
111+
112+ self ._not_stagged_mode_action = \
113+ QtWidgets .QAction ('Not Stagged' ,
114+ self ,
115+ toolTip = 'Not Stagged Mode' ,
116+ shortcut = 'Ctrl+2' ,
117+ checkable = True ,
118+ )
119+
120+ self ._all_change_mode_action = \
121+ QtWidgets .QAction ('All' ,
122+ self ,
123+ toolTip = 'All Mode' ,
124+ shortcut = 'Ctrl+3' ,
125+ checkable = True ,
126+ )
127+
128+ self ._action_group = QtWidgets .QActionGroup (self )
129+ self ._action_group .triggered .connect (self ._update_working_tree_diff )
130+ for action in (self ._all_change_mode_action ,
131+ self ._stagged_mode_action ,
132+ self ._not_stagged_mode_action ,
133+ ):
134+ self ._action_group .addAction (action )
135+ self ._all_change_mode_action .setChecked (True )
102136
103137 ##############################################
104138
105139 def _create_toolbar (self ):
106140
107- pass
141+ self ._tool_bar = self .addToolBar ('Diff on Working Tree' )
142+ for item in self ._action_group .actions ():
143+ self ._tool_bar .addAction (item )
108144
109145 ##############################################
110146
@@ -136,23 +172,42 @@ def show_message(self, message=None, timeout=0, warn=False):
136172
137173 ##############################################
138174
139- def _update_commit_table (self , index ):
175+ def _update_working_tree_diff (self ):
176+
177+ if self ._log_table .currentIndex ().row () == 0 :
178+ self ._update_commit_table ()
140179
141- index = index .row ()
180+ ##############################################
181+
182+ def _update_commit_table (self , index = None ):
183+
184+ if index is not None :
185+ index = index .row ()
186+ else :
187+ index = 0
188+
142189 if index :
143190 self ._current_revision = index
144191 log_table_model = self ._log_table .model ()
145192 commit1 = log_table_model [index ]
146193 try :
147194 commit2 = log_table_model [index + 1 ]
148- commit1 , commit2 = commit2 , commit1 # Fixme:
195+ kwargs = dict ( a = commit2 , b = commit1 ) # Fixme:
149196 except IndexError :
150- commit2 = None
151- else :
197+ kwargs = dict ( a = commit1 )
198+ else : # working directory
152199 self ._current_revision = None
153- commit1 = commit2 = None
200+ if self ._stagged_mode_action .isChecked ():
201+ # Changes between the index and your last commit
202+ kwargs = dict (a = 'HEAD' , cached = True )
203+ elif self ._not_stagged_mode_action .isChecked ():
204+ # Changes in the working tree not yet staged for the next commit
205+ kwargs = {}
206+ elif self ._all_change_mode_action .isChecked ():
207+ # Changes in the working tree since your last commit
208+ kwargs = dict (a = 'HEAD' )
154209
155- self ._diff = self ._application .repository .diff (commit1 , commit2 )
210+ self ._diff = self ._application .repository .diff (** kwargs )
156211
157212 commit_table_model = self ._commit_table .model ()
158213 commit_table_model .update (self ._diff )
0 commit comments