@@ -51,6 +51,8 @@ def __init__(self, parent=None):
51
51
self ._diff_window = None
52
52
53
53
self ._init_ui ()
54
+ self ._create_actions ()
55
+ self ._create_toolbar ()
54
56
55
57
icon_loader = IconLoader ()
56
58
self .setWindowIcon (icon_loader ['code-review@svg' ])
@@ -97,14 +99,48 @@ def _init_ui(self):
97
99
98
100
def _create_actions (self ):
99
101
100
- pass
101
102
# 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 )
102
136
103
137
##############################################
104
138
105
139
def _create_toolbar (self ):
106
140
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 )
108
144
109
145
##############################################
110
146
@@ -136,23 +172,42 @@ def show_message(self, message=None, timeout=0, warn=False):
136
172
137
173
##############################################
138
174
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 ()
140
179
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
+
142
189
if index :
143
190
self ._current_revision = index
144
191
log_table_model = self ._log_table .model ()
145
192
commit1 = log_table_model [index ]
146
193
try :
147
194
commit2 = log_table_model [index + 1 ]
148
- commit1 , commit2 = commit2 , commit1 # Fixme:
195
+ kwargs = dict ( a = commit2 , b = commit1 ) # Fixme:
149
196
except IndexError :
150
- commit2 = None
151
- else :
197
+ kwargs = dict ( a = commit1 )
198
+ else : # working directory
152
199
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' )
154
209
155
- self ._diff = self ._application .repository .diff (commit1 , commit2 )
210
+ self ._diff = self ._application .repository .diff (** kwargs )
156
211
157
212
commit_table_model = self ._commit_table .model ()
158
213
commit_table_model .update (self ._diff )
0 commit comments