Skip to content

Commit

Permalink
Make lua editor a window rather than a dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
crumblingstatue committed Oct 16, 2024
1 parent 4c53e98 commit e05aa19
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 32 deletions.
5 changes: 2 additions & 3 deletions src/gui/dialogs.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
mod auto_save_reload;
mod jump;
mod lua_color;
mod lua_execute;
mod lua_fill;
pub mod pattern_fill;
mod truncate;
mod x86_asm;

pub use {
auto_save_reload::AutoSaveReloadDialog, jump::JumpDialog, lua_color::LuaColorDialog,
lua_execute::LuaExecuteDialog, lua_fill::LuaFillDialog, pattern_fill::PatternFillDialog,
truncate::TruncateDialog, x86_asm::X86AsmDialog,
lua_fill::LuaFillDialog, pattern_fill::PatternFillDialog, truncate::TruncateDialog,
x86_asm::X86AsmDialog,
};
8 changes: 2 additions & 6 deletions src/gui/top_menu/scripting.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
use {
crate::{
app::App,
gui::{dialogs::LuaExecuteDialog, Gui},
shell::msg_if_fail,
},
crate::{app::App, gui::Gui, shell::msg_if_fail},
mlua::Lua,
};

Expand All @@ -16,7 +12,7 @@ pub fn ui(
line_spacing: u16,
) {
if ui.button("🖹 Lua editor").clicked() {
Gui::add_dialog(&mut gui.dialogs, LuaExecuteDialog::default());
gui.win.lua_editor.open.toggle();
ui.close_menu();
}
if ui.button("📃 Script manager").clicked() {
Expand Down
4 changes: 4 additions & 0 deletions src/gui/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use {
},
super::Gui,
crate::app::App,
lua_editor::LuaEditorWindow,
};

mod about;
Expand All @@ -28,6 +29,7 @@ mod find_dialog;
mod find_memory_pointers_window;
mod layouts_window;
mod lua_console;
mod lua_editor;
mod lua_help;
mod lua_watch;
mod meta_diff_window;
Expand Down Expand Up @@ -56,6 +58,7 @@ pub struct Windows {
pub preferences: PreferencesWindow,
pub about: AboutWindow,
pub vars: VarsWindow,
pub lua_editor: LuaEditorWindow,
pub lua_help: LuaHelpWindow,
pub lua_console: LuaConsoleWindow,
pub lua_watch: Vec<LuaWatchWindow>,
Expand Down Expand Up @@ -148,6 +151,7 @@ impl Windows {
advanced_open,
external_command,
preferences,
lua_editor,
lua_help,
lua_console,
script_manager,
Expand Down
40 changes: 19 additions & 21 deletions src/gui/dialogs/lua_execute.rs → src/gui/windows/lua_editor.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use {
super::{WinCtx, WindowOpen},
crate::{
app::App,
gui::{Dialog, Gui},
gui::Gui,
meta::{Script, ScriptKey},
scripting::SCRIPT_ARG_FMT_HELP_STR,
shell::msg_if_fail,
Expand All @@ -14,29 +15,26 @@ use {
std::time::Instant,
};

#[derive(Debug, Default)]
pub struct LuaExecuteDialog {
#[derive(Default)]
pub struct LuaEditorWindow {
pub open: WindowOpen,
result_info_string: String,
err: bool,
new_script_name: String,
args_string: String,
edit_key: Option<ScriptKey>,
}

impl Dialog for LuaExecuteDialog {
fn title(&self) -> &str {
"Lua Editor"
}

fn ui(
&mut self,
ui: &mut egui::Ui,
app: &mut App,
gui: &mut crate::gui::Gui,
lua: &Lua,
font_size: u16,
line_spacing: u16,
) -> bool {
impl super::Window for LuaEditorWindow {
fn ui(&mut self, ctx: super::WinCtx) {
let WinCtx {
ui,
gui,
app,
lua,
font_size,
line_spacing,
} = ctx;
let ctrl_enter =
ui.input_mut(|inp| inp.consume_key(egui::Modifiers::CTRL, egui::Key::Enter));
let ctrl_s = ui.input_mut(|inp| inp.consume_key(egui::Modifiers::CTRL, egui::Key::S));
Expand Down Expand Up @@ -165,14 +163,14 @@ impl Dialog for LuaExecuteDialog {
});
},
);
true
}
fn has_close_button(&self) -> bool {
true

fn title(&self) -> &str {
"Lua Editor"
}
}

impl LuaExecuteDialog {
impl LuaEditorWindow {
fn exec_lua(
&mut self,
app: &mut App,
Expand Down
4 changes: 2 additions & 2 deletions src/gui/windows/script_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use {
super::{WinCtx, WindowOpen},
crate::{
app::App,
gui::{dialogs::LuaExecuteDialog, Gui},
gui::Gui,
meta::{ScriptKey, ScriptMap},
scripting::exec_lua,
shell::msg_if_fail,
Expand Down Expand Up @@ -63,7 +63,7 @@ impl super::Window for ScriptManagerWindow {
ui.label("There are no saved scripts.");
}
if ui.link("Open lua editor").clicked() {
Gui::add_dialog(&mut gui.dialogs, LuaExecuteDialog::default());
gui.win.lua_editor.open.set(true);
}
ui.separator();
self.selected_script_ui(ui, gui, app, lua, &mut scripts, font_size, line_spacing);
Expand Down

0 comments on commit e05aa19

Please sign in to comment.