blob: b7d7b0afeed460ef93a06b56f18fb7d50a1eb7c6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
use std::slice::IterMut;
use crate::tab::JoshutoTab;
pub struct TabContext {
pub index: usize,
tabs: Vec<JoshutoTab>,
}
impl std::default::Default for TabContext {
fn default() -> Self {
Self {
index: 0,
tabs: Vec::new(),
}
}
}
impl TabContext {
pub fn new() -> Self {
Self::default()
}
pub fn len(&self) -> usize {
self.tabs.len()
}
pub fn tab_mut(&mut self, i: usize) -> Option<&mut JoshutoTab> {
if i >= self.tabs.len() {
return None;
}
Some(&mut self.tabs[i])
}
pub fn curr_tab_ref(&self) -> &JoshutoTab {
&self.tabs[self.index]
}
pub fn curr_tab_mut(&mut self) -> &mut JoshutoTab {
&mut self.tabs[self.index]
}
pub fn push_tab(&mut self, tab: JoshutoTab) {
self.tabs.push(tab);
self.index = self.tabs.len() - 1;
}
pub fn pop_tab(&mut self, index: usize) -> JoshutoTab {
self.tabs.remove(index)
}
pub fn iter_mut(&mut self) -> IterMut<JoshutoTab> {
self.tabs.iter_mut()
}
}
|