@@ -8,7 +8,7 @@ use crate::{
8
8
keys,
9
9
queue:: { InternalEvent , NeedsUpdate , Queue } ,
10
10
strings,
11
- tabs:: { Revlog , Status } ,
11
+ tabs:: { Revlog , Stashing , Status } ,
12
12
ui:: style:: Theme ,
13
13
} ;
14
14
use asyncgit:: { sync, AsyncNotification , CWD } ;
@@ -38,6 +38,7 @@ pub struct App {
38
38
tab : usize ,
39
39
revlog : Revlog ,
40
40
status_tab : Status ,
41
+ stashing_tab : Stashing ,
41
42
queue : Queue ,
42
43
theme : Theme ,
43
44
}
@@ -60,6 +61,7 @@ impl App {
60
61
tab : 0 ,
61
62
revlog : Revlog :: new ( & sender, & theme) ,
62
63
status_tab : Status :: new ( & sender, & queue, & theme) ,
64
+ stashing_tab : Stashing :: new ( & queue, & theme) ,
63
65
queue,
64
66
theme,
65
67
}
@@ -81,11 +83,13 @@ impl App {
81
83
82
84
self . draw_tabs ( f, chunks_main[ 0 ] ) ;
83
85
84
- if self . tab == 0 {
85
- self . status_tab . draw ( f, chunks_main[ 1 ] ) ;
86
- } else {
87
- self . revlog . draw ( f, chunks_main[ 1 ] ) ;
88
- }
86
+ //TODO: macro because of generic draw call
87
+ match self . tab {
88
+ 0 => self . status_tab . draw ( f, chunks_main[ 1 ] ) ,
89
+ 1 => self . revlog . draw ( f, chunks_main[ 1 ] ) ,
90
+ 2 => self . stashing_tab . draw ( f, chunks_main[ 1 ] ) ,
91
+ _ => panic ! ( "unknown tab" ) ,
92
+ } ;
89
93
90
94
Self :: draw_commands (
91
95
f,
@@ -141,13 +145,15 @@ impl App {
141
145
pub fn update ( & mut self ) {
142
146
trace ! ( "update" ) ;
143
147
self . status_tab . update ( ) ;
148
+ self . stashing_tab . update ( ) ;
144
149
}
145
150
146
151
///
147
152
pub fn update_git ( & mut self , ev : AsyncNotification ) {
148
153
trace ! ( "update_git: {:?}" , ev) ;
149
154
150
155
self . status_tab . update_git ( ev) ;
156
+ self . stashing_tab . update_git ( ev) ;
151
157
152
158
match ev {
153
159
AsyncNotification :: Diff => ( ) ,
@@ -166,12 +172,16 @@ impl App {
166
172
pub fn any_work_pending ( & self ) -> bool {
167
173
self . status_tab . anything_pending ( )
168
174
|| self . revlog . any_work_pending ( )
175
+ || self . stashing_tab . anything_pending ( )
169
176
}
170
177
}
171
178
172
179
// private impls
173
180
impl App {
174
- accessors ! ( self , [ msg, reset, commit, help, revlog, status_tab] ) ;
181
+ accessors ! (
182
+ self ,
183
+ [ msg, reset, commit, help, revlog, status_tab, stashing_tab]
184
+ ) ;
175
185
176
186
fn check_quit ( & mut self , ev : Event ) -> bool {
177
187
if let Event :: Key ( e) = ev {
@@ -183,17 +193,29 @@ impl App {
183
193
false
184
194
}
185
195
196
+ fn get_tabs ( & mut self ) -> Vec < & mut dyn Component > {
197
+ vec ! [
198
+ & mut self . status_tab,
199
+ & mut self . revlog,
200
+ & mut self . stashing_tab,
201
+ ]
202
+ }
203
+
186
204
fn toggle_tabs ( & mut self ) {
187
- self . tab += 1 ;
188
- self . tab %= 2 ;
189
-
190
- if self . tab == 1 {
191
- self . status_tab . hide ( ) ;
192
- self . revlog . show ( ) ;
193
- } else {
194
- self . status_tab . show ( ) ;
195
- self . revlog . hide ( ) ;
205
+ let mut new_tab = self . tab + 1 ;
206
+ {
207
+ let tabs = self . get_tabs ( ) ;
208
+ new_tab %= tabs. len ( ) ;
209
+
210
+ for ( i, t) in tabs. into_iter ( ) . enumerate ( ) {
211
+ if new_tab == i {
212
+ t. show ( ) ;
213
+ } else {
214
+ t. hide ( ) ;
215
+ }
216
+ }
196
217
}
218
+ self . tab = new_tab;
197
219
}
198
220
199
221
fn update_commands ( & mut self ) {
@@ -327,7 +349,11 @@ impl App {
327
349
f. render_widget (
328
350
Tabs :: default ( )
329
351
. block ( Block :: default ( ) . borders ( Borders :: BOTTOM ) )
330
- . titles ( & [ strings:: TAB_STATUS , strings:: TAB_LOG ] )
352
+ . titles ( & [
353
+ strings:: TAB_STATUS ,
354
+ strings:: TAB_LOG ,
355
+ strings:: TAB_STASHING ,
356
+ ] )
331
357
. style ( Style :: default ( ) )
332
358
. highlight_style (
333
359
self . theme
0 commit comments