Skip to content

Commit

Permalink
HackStudio: Disable debug specific context entries
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hieronymusma authored and gunnarbeutner committed Jul 11, 2021
1 parent 488d072 commit dfc33cd
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
19 changes: 11 additions & 8 deletions Userland/DevTools/HackStudio/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,22 @@ 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());
} else {
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);

Expand Down Expand Up @@ -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);
}

}
2 changes: 2 additions & 0 deletions Userland/DevTools/HackStudio/Editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ class Editor final : public GUI::TextEditor {
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();
Expand Down
5 changes: 5 additions & 0 deletions Userland/DevTools/HackStudio/EditorWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
1 change: 1 addition & 0 deletions Userland/DevTools/HackStudio/EditorWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class EditorWrapper : public GUI::Widget {

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; }
Expand Down
9 changes: 9 additions & 0 deletions Userland/DevTools/HackStudio/HackStudioWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
}

Expand Down Expand Up @@ -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);
}));
Expand Down

0 comments on commit dfc33cd

Please sign in to comment.