mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 10:22:05 -05:00
HackStudio: Disable debug specific context entries
Context menu entries like evaluate expression and move execution to line action should only be enabled when a debug session is running. Otherwise they should be disabled.
This commit is contained in:
parent
488d0722bd
commit
dfc33cd412
5 changed files with 28 additions and 8 deletions
|
@ -43,18 +43,12 @@ Editor::Editor()
|
|||
initialize_documentation_tooltip();
|
||||
initialize_parameters_hint_tooltip();
|
||||
m_evaluate_expression_action = GUI::Action::create("Evaluate expression", { Mod_Ctrl, Key_E }, [this](auto&) {
|
||||
if (!execution_position().has_value()) {
|
||||
GUI::MessageBox::show(window(), "Program is not running", "Error", GUI::MessageBox::Type::Error);
|
||||
return;
|
||||
}
|
||||
VERIFY(is_program_running());
|
||||
auto dialog = EvaluateExpressionDialog::construct(window());
|
||||
dialog->exec();
|
||||
});
|
||||
m_move_execution_to_line_action = GUI::Action::create("Set execution point to line", [this](auto&) {
|
||||
if (!execution_position().has_value()) {
|
||||
GUI::MessageBox::show(window(), "Program must be paused", "Error", GUI::MessageBox::Type::Error);
|
||||
return;
|
||||
}
|
||||
VERIFY(is_program_running());
|
||||
auto success = Debugger::the().set_execution_position(currently_open_file(), cursor().line());
|
||||
if (success) {
|
||||
set_execution_position(cursor().line());
|
||||
|
@ -62,6 +56,9 @@ Editor::Editor()
|
|||
GUI::MessageBox::show(window(), "Failed to set execution position", "Error", GUI::MessageBox::Type::Error);
|
||||
}
|
||||
});
|
||||
|
||||
set_debug_mode(false);
|
||||
|
||||
add_custom_context_menu_action(*m_evaluate_expression_action);
|
||||
add_custom_context_menu_action(*m_move_execution_to_line_action);
|
||||
|
||||
|
@ -672,4 +669,10 @@ void Editor::handle_function_parameters_hint_request()
|
|||
cursor().column());
|
||||
}
|
||||
|
||||
void Editor::set_debug_mode(bool enabled)
|
||||
{
|
||||
m_evaluate_expression_action->set_enabled(enabled);
|
||||
m_move_execution_to_line_action->set_enabled(enabled);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,8 +34,10 @@ public:
|
|||
const Vector<size_t>& breakpoint_lines() const { return code_document().breakpoint_lines(); }
|
||||
Vector<size_t>& breakpoint_lines() { return code_document().breakpoint_lines(); }
|
||||
Optional<size_t> execution_position() const { return code_document().execution_position(); }
|
||||
bool is_program_running() const { return execution_position().has_value(); }
|
||||
void set_execution_position(size_t line_number);
|
||||
void clear_execution_position();
|
||||
void set_debug_mode(bool);
|
||||
|
||||
const CodeDocument& code_document() const;
|
||||
CodeDocument& code_document();
|
||||
|
|
|
@ -137,4 +137,9 @@ void EditorWrapper::update_title()
|
|||
m_filename_label->set_text(title.to_string());
|
||||
}
|
||||
|
||||
void EditorWrapper::set_debug_mode(bool enabled)
|
||||
{
|
||||
m_editor->set_debug_mode(enabled);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ public:
|
|||
|
||||
void set_mode_displayable();
|
||||
void set_mode_non_displayable();
|
||||
void set_debug_mode(bool);
|
||||
void set_filename(const String&);
|
||||
const String& filename() const { return m_filename; }
|
||||
bool document_dirty() const { return m_document_dirty; }
|
||||
|
|
|
@ -639,6 +639,10 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_debug_action()
|
|||
m_debugger_thread->start();
|
||||
m_stop_action->set_enabled(true);
|
||||
m_run_action->set_enabled(false);
|
||||
|
||||
for (auto& editor_wrapper : m_all_editor_wrappers) {
|
||||
editor_wrapper.set_debug_mode(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -690,6 +694,11 @@ void HackStudioWidget::initialize_debugger()
|
|||
m_stop_action->set_enabled(false);
|
||||
m_run_action->set_enabled(true);
|
||||
m_debugger_thread.clear();
|
||||
|
||||
for (auto& editor_wrapper : m_all_editor_wrappers) {
|
||||
editor_wrapper.set_debug_mode(false);
|
||||
}
|
||||
|
||||
HackStudioWidget::hide_action_tabs();
|
||||
GUI::MessageBox::show(window(), "Program Exited", "Debugger", GUI::MessageBox::Type::Information);
|
||||
}));
|
||||
|
|
Loading…
Add table
Reference in a new issue