|
1 | 1 | use crate::lore::patch::Patch; |
2 | 2 |
|
3 | 3 | pub struct BookmarkedPatchsets { |
| 4 | + /// List of all bookmarked patchsets |
4 | 5 | pub bookmarked_patchsets: Vec<Patch>, |
| 6 | + /// Index of the currently selected patchset |
5 | 7 | pub patchset_index: usize, |
6 | 8 | } |
7 | 9 |
|
8 | 10 | impl BookmarkedPatchsets { |
| 11 | + /// Increments `patchset_index` by one, unless the last patchset |
| 12 | + /// is already selected. |
9 | 13 | pub fn select_below_patchset(&mut self) { |
10 | 14 | if self.patchset_index + 1 < self.bookmarked_patchsets.len() { |
11 | 15 | self.patchset_index += 1; |
12 | 16 | } |
13 | 17 | } |
14 | 18 |
|
| 19 | + /// Decrements `patchset_index` by one, unless the first patchset |
| 20 | + // is alredy selected. |
15 | 21 | pub fn select_above_patchset(&mut self) { |
16 | 22 | self.patchset_index = self.patchset_index.saturating_sub(1); |
17 | 23 | } |
18 | 24 |
|
| 25 | + /// Get a clone of the actual selected patchset |
19 | 26 | pub fn get_selected_patchset(&self) -> Patch { |
20 | 27 | self.bookmarked_patchsets |
21 | 28 | .get(self.patchset_index) |
22 | 29 | .unwrap() |
23 | 30 | .clone() |
24 | 31 | } |
25 | 32 |
|
| 33 | + /// Add a patchset to the list of bookmarks if is not already on the list |
26 | 34 | pub fn bookmark_selected_patch(&mut self, patch_to_bookmark: &Patch) { |
27 | 35 | if !self.bookmarked_patchsets.contains(patch_to_bookmark) { |
28 | 36 | self.bookmarked_patchsets.push(patch_to_bookmark.clone()); |
29 | 37 | } |
30 | 38 | } |
31 | 39 |
|
| 40 | + /// Remove a patchset from the list of bookmarks |
32 | 41 | pub fn unbookmark_selected_patch(&mut self, patch_to_unbookmark: &Patch) { |
33 | 42 | if let Some(index) = self |
34 | 43 | .bookmarked_patchsets |
|
0 commit comments