summaryrefslogtreecommitdiff
path: root/Userland/DevTools/HackStudio/HackStudioWidget.cpp
diff options
context:
space:
mode:
authorFalseHonesty <thefalsehonesty@gmail.com>2021-04-15 12:42:40 -0400
committerAndreas Kling <kling@serenityos.org>2021-04-18 17:02:40 +0200
commite0be8a3f598d43e7ce6df6ff2a1eb5d7ac817177 (patch)
treeae7732993daa637a00334cb015541c73ef0078c1 /Userland/DevTools/HackStudio/HackStudioWidget.cpp
parent7a1396f509800978d3e1cc2cbc8e043ccf758db9 (diff)
downloadserenity-e0be8a3f598d43e7ce6df6ff2a1eb5d7ac817177.zip
HackStudio: Don't crash when invalid file is requested to be opened
Previously, if the running debugger asked for HackStudio to open an invalid file, it would crash trying to switch to it. Now it will just continue without switching the editor.
Diffstat (limited to 'Userland/DevTools/HackStudio/HackStudioWidget.cpp')
-rw-r--r--Userland/DevTools/HackStudio/HackStudioWidget.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.cpp b/Userland/DevTools/HackStudio/HackStudioWidget.cpp
index b8a6deac45..3382a5dfe2 100644
--- a/Userland/DevTools/HackStudio/HackStudioWidget.cpp
+++ b/Userland/DevTools/HackStudio/HackStudioWidget.cpp
@@ -223,15 +223,15 @@ Vector<String> HackStudioWidget::selected_file_paths() const
return files;
}
-void HackStudioWidget::open_file(const String& full_filename)
+bool HackStudioWidget::open_file(const String& full_filename)
{
String filename = full_filename;
if (full_filename.starts_with(project().root_path())) {
filename = LexicalPath::relative_path(full_filename, project().root_path());
}
dbgln("HackStudio is opening {}", filename);
- if (Core::File::is_directory(filename))
- return;
+ if (Core::File::is_directory(filename) || !Core::File::exists(filename))
+ return false;
if (!currently_open_file().is_empty()) {
// Since the file is previously open, it should always be in m_open_files.
@@ -282,6 +282,7 @@ void HackStudioWidget::open_file(const String& full_filename)
current_editor_wrapper().filename_label().set_text(filename);
current_editor().set_focus(true);
+ return true;
}
EditorWrapper& HackStudioWidget::current_editor_wrapper()
@@ -647,7 +648,8 @@ void HackStudioWidget::initialize_debugger()
make<Core::DeferredInvocationEvent>(
[this, source_position, &regs](auto&) {
m_current_editor_in_execution = get_editor_of_file(source_position.value().file_path);
- m_current_editor_in_execution->editor().set_execution_position(source_position.value().line_number - 1);
+ if (m_current_editor_in_execution)
+ m_current_editor_in_execution->editor().set_execution_position(source_position.value().line_number - 1);
m_debug_info_widget->update_state(*Debugger::the().session(), regs);
m_debug_info_widget->set_debug_actions_enabled(true);
m_disassembly_widget->update_state(*Debugger::the().session(), regs);
@@ -689,7 +691,7 @@ String HackStudioWidget::get_full_path_of_serenity_source(const String& file)
return String::formatted("{}/{}", serenity_sources_base, relative_path_builder.to_string());
}
-NonnullRefPtr<EditorWrapper> HackStudioWidget::get_editor_of_file(const String& file_name)
+RefPtr<EditorWrapper> HackStudioWidget::get_editor_of_file(const String& file_name)
{
String file_path = file_name;
@@ -700,7 +702,8 @@ NonnullRefPtr<EditorWrapper> HackStudioWidget::get_editor_of_file(const String&
file_path = get_full_path_of_serenity_source(file_name);
}
- open_file(file_path);
+ if (!open_file(file_path))
+ return nullptr;
return current_editor_wrapper();
}