Skip to content

Commit 0abc0fb

Browse files
committed
open files when in smali
1 parent 674d779 commit 0abc0fb

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

asm_egui/src/smali.rs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ use egui::text::LayoutJob;
33
use egui::{CursorIcon, FontId, Response, ScrollArea, TextStyle, Ui, Vec2};
44
use java_asm::smali::SmaliToken;
55
use java_asm::StrRef;
6-
use java_asm_server::ui::{AppContainer, Content, Left, Top};
6+
use java_asm_server::ui::{AppContainer, OpenFileMessage, UIMessage};
77
use java_asm_server::AsmServer;
8-
use std::ops::{Deref, DerefMut};
98

109
pub fn smali_layout(ui: &mut Ui, server: &AsmServer, app: &AppContainer) {
11-
let mut content_locked = app.content().lock();
12-
let mut left_locked = app.left().lock();
10+
let content_locked = app.content().lock();
1311
let selected_tab_index = content_locked.selected;
1412
let Some(selected_tab_index) = selected_tab_index else { return; };
1513

@@ -27,17 +25,13 @@ pub fn smali_layout(ui: &mut Ui, server: &AsmServer, app: &AppContainer) {
2725
let lines = smali_node.render_to_lines();
2826
let row_height = ui.text_style_height(&TextStyle::Monospace);
2927

30-
let content_mut = content_locked.deref_mut();
3128
let scroll_area = ScrollArea::vertical().auto_shrink(false);
3229
let spacing_y = ui.spacing().item_spacing.y;
3330

34-
let mut top_locked = app.top().lock();
3531
let mut render_context = RenderContext {
32+
app: &app,
3633
server,
3734
font: &font,
38-
content: content_mut,
39-
top: &mut top_locked,
40-
left: &mut left_locked,
4135
lines: &lines,
4236
smali_style: &smali_style,
4337
dft_color,
@@ -52,10 +46,8 @@ pub fn smali_layout(ui: &mut Ui, server: &AsmServer, app: &AppContainer) {
5246
}
5347

5448
struct RenderContext<'a> {
49+
pub app: &'a AppContainer,
5550
pub server: &'a AsmServer,
56-
pub left: &'a mut Left,
57-
pub top: &'a mut Top,
58-
pub content: &'a mut Content,
5951
pub lines: &'a Vec<Vec<SmaliToken>>,
6052

6153
pub font: &'a FontId,
@@ -255,18 +247,18 @@ impl<'a> RenderContext<'a> {
255247
fn render_single_descriptor(
256248
&mut self, ui: &mut Ui, descriptor: &str,
257249
) {
258-
let RenderContext {
259-
server, content, top, left, ..
260-
} = self;
261-
let existed = server.find_class(descriptor);
250+
let existed = self.server.find_class(descriptor);
262251
if !existed {
263252
ui.label(format!("{descriptor}"));
264253
} else {
265-
let accessor_locked = server.accessor.lock();
266-
let Some(accessor) = accessor_locked.deref() else { return };
267254
let link = ui.link(descriptor);
268255
if link.clicked() {
269-
server.switch_or_open_lock_free(descriptor, accessor, left, content, top)
256+
let file_open_message = UIMessage::OpenFile(
257+
OpenFileMessage {
258+
path: descriptor.into(),
259+
}
260+
);
261+
self.app.send_message(file_open_message);
270262
}
271263
}
272264
}

asm_egui/src/top_bar.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ impl EguiApp {
3434
self.server.clone(), self.ui_app.clone(),
3535
);
3636
}
37-
self.file_path_input(ui);
37+
if self.server.lock().is_some() {
38+
self.file_path_input(ui);
39+
}
3840
});
3941
}
4042

0 commit comments

Comments
 (0)