Skip to content

Commit 46b2e6f

Browse files
committed
add descriptor menu
1 parent 6c35317 commit 46b2e6f

File tree

10 files changed

+247
-85
lines changed

10 files changed

+247
-85
lines changed

Cargo.lock

Lines changed: 33 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ members = [
99
]
1010

1111
[workspace.package]
12-
version = "0.0.12" # JAVA_ASM_VERSION
12+
version = "0.0.13" # JAVA_ASM_VERSION
1313
authors = ["zsqw123"]
1414
edition = "2021"
1515
license = "Apache-2.0"
@@ -20,9 +20,9 @@ homepage = "https://crates.io/crates/java_asm"
2020
readme = "README.md"
2121

2222
[workspace.dependencies]
23-
java_asm_macro = { path = "asm_macro", version = "0.0.12" } # JAVA_ASM_VERSION
24-
java_asm = { path = "asm", version = "0.0.12" } # JAVA_ASM_VERSION
25-
java_asm_server = { path = "asm_server", version = "0.0.12" } # JAVA_ASM_VERSION
23+
java_asm_macro = { path = "asm_macro", version = "0.0.13" } # JAVA_ASM_VERSION
24+
java_asm = { path = "asm", version = "0.0.13" } # JAVA_ASM_VERSION
25+
java_asm_server = { path = "asm_server", version = "0.0.13" } # JAVA_ASM_VERSION
2626

2727
enum_dispatch = "0.3.13"
2828
zip = "2.2.0"
@@ -33,7 +33,7 @@ egui_extras = "0.31.1"
3333
egui_flex = "0.3.0"
3434

3535
tokio = { version = "1.44.2", features = ["full"] }
36-
parking_lot = "0.12.3"
36+
parking_lot = { version = "0.12.3", features = ["deadlock_detection"] }
3737

3838
#iced = "0.13.1"
3939
#cosmic-text = "0.12.1"

asm_egui/src/app.rs

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ use eframe::{CreationContext, Frame};
66
use egui::{Context, DroppedFile, ScrollArea};
77
use egui_extras::{Size, StripBuilder};
88
use java_asm_server::ui::log::{inject_log, LogHolder};
9-
use java_asm_server::ui::{AppContainer, Content};
9+
use java_asm_server::ui::AppContainer;
1010
use java_asm_server::{AsmServer, ServerMut};
11-
use std::ops::DerefMut;
1211
use std::sync::Arc;
1312

1413
pub struct EguiApp {
@@ -89,27 +88,17 @@ impl EguiApp {
8988

9089
fn central_panel(&mut self, ctx: &Context) {
9190
egui::CentralPanel::default().show(ctx, |ui| {
92-
let mut server_content = self.server_app.content().lock();
93-
let Content { current, opened_tabs } = server_content.deref_mut();
94-
95-
let mut deleted_tab = None;
91+
let server_locked = self.server.lock();
92+
let Some(server) = server_locked.as_ref() else {
93+
return;
94+
};
95+
let server_app = &self.server_app;
9696

97-
render_tabs(ui, current, opened_tabs, &mut deleted_tab);
97+
render_tabs(ui, server_app);
9898

9999
ui.separator();
100100

101-
if let Some(current_tab) = current {
102-
let current_tab = *current_tab;
103-
let content = &opened_tabs[current_tab].content;
104-
ScrollArea::vertical().show(ui, |ui| {
105-
smali_layout(ui, content);
106-
});
107-
}
108-
109-
// remove tab after this time rendering
110-
if let Some(index) = deleted_tab {
111-
opened_tabs.remove(index);
112-
}
101+
smali_layout(ui, server, &self.server_app);
113102
});
114103
}
115104
}

asm_egui/src/file_tab.rs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,54 @@
1+
use std::ops::DerefMut;
12
use eframe::emath::Align;
23
use eframe::epaint::StrokeKind;
34
use egui::{Layout, Pos2, Rect, Response, Sense, TextStyle, Ui, Vec2, WidgetInfo, WidgetText, WidgetType};
45
use egui_flex::{item, Flex, FlexAlignContent};
56
use java_asm::StrRef;
6-
use java_asm_server::ui::Tab;
7-
8-
pub fn render_tabs(ui: &mut Ui, current: &mut Option<usize>, tabs: &Vec<Tab>, deleted_tab: &mut Option<usize>) {
7+
use java_asm_server::ui::{AppContainer, Tab};
8+
9+
pub fn render_tabs(
10+
ui: &mut Ui, app_container: &AppContainer,
11+
) {
12+
let mut deleted_tab = None;
13+
let mut content_locked = app_container.content().lock();
14+
let content_ref = content_locked.deref_mut();
15+
let selected_tab_index = &mut content_ref.selected;
16+
let opened_tabs = &mut content_ref.opened_tabs;
917
Flex::horizontal()
1018
.align_content(FlexAlignContent::Start)
1119
.w_full()
1220
.wrap(true)
1321
.show(ui, |flex| {
14-
for tab in tabs.iter().enumerate() {
22+
for tab in opened_tabs.iter().enumerate() {
1523
flex.add_ui(item(), |ui: &mut Ui| {
16-
file_title(ui, current, deleted_tab, tab)
24+
file_title(ui, selected_tab_index, &mut deleted_tab, tab)
1725
});
1826
}
1927
});
28+
// remove tab after this time rendering
29+
if let Some(index) = deleted_tab {
30+
opened_tabs.remove(index);
31+
}
2032
}
2133

22-
fn file_title(ui: &mut Ui, current: &mut Option<usize>, deleted_tab: &mut Option<usize>, tab: (usize, &Tab)) {
34+
fn file_title(ui: &mut Ui, selected_tab_index: &mut Option<usize>, deleted_tab: &mut Option<usize>, tab: (usize, &Tab)) {
2335
let (index, tab) = tab;
24-
let selected = current.map(|current| current == index).unwrap_or_default();
36+
let selected = selected_tab_index.map(|current| current == index).unwrap_or_default();
2537
let title = tab.title.clone();
2638
let selectable_label = SelectableClosableLabel { selected, title };
2739
let response = selectable_label.ui(ui);
2840
if response.closed {
2941
*deleted_tab = Some(index);
3042
// recalculate current tab
31-
if let Some(cur) = *current {
43+
if let Some(cur) = *selected_tab_index {
3244
if cur == index {
33-
*current = None;
45+
*selected_tab_index = None;
3446
} else if cur > index {
35-
*current = Some(cur - 1);
47+
*selected_tab_index = Some(cur - 1);
3648
}
3749
}
3850
} else if response.raw.clicked() {
39-
*current = Some(index);
51+
*selected_tab_index = Some(index);
4052
}
4153
}
4254

asm_egui/src/file_tree.rs

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
use crate::app::EguiApp;
22
use egui::text::LayoutJob;
33
use egui::{ScrollArea, TextStyle};
4-
use java_asm_server::ui::{Content, FileEntry, FileInfo, RawDirInfo, Tab};
4+
use java_asm_server::ui::{AppContainer, FileEntry, FileInfo, RawDirInfo};
55
use java_asm_server::AsmServer;
66
use std::ops::Deref;
7-
use std::sync::Arc;
87

98
pub fn render_dir(ui: &mut egui::Ui, app: &mut EguiApp) {
109
let server_app = &app.server_app;
1110
let mut server_app_left = server_app.left().lock();
12-
let mut server_app_content = server_app.content().lock();
1311
let entries = &mut server_app_left.root_node.visible_items();
1412
let server = app.server.lock();
1513
if let Some(server) = server.deref() {
16-
let content = &mut server_app_content;
1714
let row_height = ui.spacing().interact_size.y;
1815
ScrollArea::vertical().auto_shrink(false)
1916
.show_rows(ui, row_height, entries.len(), |ui, range| {
@@ -24,7 +21,7 @@ pub fn render_dir(ui: &mut egui::Ui, app: &mut EguiApp) {
2421
render_dir_raw(ui, raw_dir);
2522
}
2623
FileEntry::File(file_info) => {
27-
render_file(ui, file_info, server, content);
24+
render_file(ui, file_info, server, server_app);
2825
}
2926
}
3027
}
@@ -34,31 +31,15 @@ pub fn render_dir(ui: &mut egui::Ui, app: &mut EguiApp) {
3431

3532
fn render_file(
3633
ui: &mut egui::Ui, file_info: &mut FileInfo,
37-
server: &AsmServer, content: &mut Content,
34+
server: &AsmServer, app: &AppContainer,
3835
) {
3936
let FileInfo { title, file_key, level } = file_info;
4037
ui.horizontal(|ui| {
4138
ui.add_space((*level as f32) * 12.0);
4239
let layout_job = layout_string(ui, title.to_string());
4340
let label = ui.selectable_label(false, layout_job);
4441
if label.clicked() {
45-
let existed_tab = content.opened_tabs.iter().position(|tab| tab.file_key == *file_key);
46-
if let Some(existed_tab) = existed_tab {
47-
content.current = Some(existed_tab);
48-
return;
49-
}
50-
let smali = server.read_content(file_key);
51-
if let Some(smali) = smali {
52-
let current_tab = Tab {
53-
selected: false,
54-
file_key: Arc::clone(file_key),
55-
title: Arc::clone(title),
56-
content: smali,
57-
};
58-
let current = content.opened_tabs.len();
59-
content.opened_tabs.push(current_tab);
60-
content.current = Some(current);
61-
}
42+
server.switch_or_open(file_key, app);
6243
}
6344
});
6445
}

0 commit comments

Comments
 (0)