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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use crate::tui::main_view::MainViewState;
use crate::tui::model::{AppState, AppView, GitObjectType};
use super::main_view::{GitObjectsState, PackPreViewState, PreviewState};
impl AppState {
// Helper method to load pack objects if the selected object is a pack file
pub fn load_pack_objects_if_needed(&mut self, _plumber: &crate::GitPlumber) {
if let AppView::Main {
state:
MainViewState {
git_objects:
GitObjectsState {
flat_view,
selected_index,
..
},
preview_state,
..
},
} = &mut self.view
{
if *selected_index >= flat_view.len() {
return;
}
// Check if we're in Pack preview state
let (pack_object_list, pack_file_path) = match preview_state {
PreviewState::Pack(PackPreViewState {
pack_object_list,
pack_file_path,
..
}) => (pack_object_list, pack_file_path),
_ => return, // Not in pack preview state
};
// Check if current object is a pack object
let is_pack_object = match &flat_view[*selected_index].1.obj_type {
GitObjectType::PackFolder { .. } => true,
GitObjectType::PackFile { file_type, .. } => {
file_type == "packfile" || file_type == "pack"
}
_ => false,
};
if !is_pack_object {
return;
}
// Extract the pack file path from the object type
let path = match &flat_view[*selected_index].1.obj_type {
GitObjectType::PackFolder { pack_group, .. } => {
// Get the pack file path from the pack group
if let Some(pack_path) = &pack_group.pack_file {
pack_path
} else {
return; // No pack file in this group
}
}
GitObjectType::PackFile { path, .. } => path,
_ => return, // This shouldn't happen due to the match above, but just in case
};
// Load if we don't have the same pack loaded OR if the object list is empty
if pack_file_path != path || pack_object_list.is_empty() {
self.effects
.push(crate::tui::message::Command::LoadPackObjects { path: path.clone() });
}
}
}
}