summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-10-26 12:13:32 +0100
committerAndreas Kling <kling@serenityos.org>2020-10-26 14:29:26 +0100
commit333ab53b8d1eb6c5e7b561383da13ec193a5d5d1 (patch)
tree1b4229dc7c0c3afee0084dc2cfeae6d6c8d5dbfb
parent76a2c6e44dd5b7852eea3b9f24cae0fd6c0aac68 (diff)
downloadserenity-333ab53b8d1eb6c5e7b561383da13ec193a5d5d1.zip
HackStudio: Add a simple "open files" view
Instead of files disappearing after you switch to something else, we now keep track of them in a little ListView below the project tree. You can return to any previously opened file by activating it in the open files list. :^)
-rw-r--r--DevTools/HackStudio/HackStudioWidget.cpp44
-rw-r--r--DevTools/HackStudio/HackStudioWidget.h7
-rw-r--r--DevTools/HackStudio/Project.cpp2
-rw-r--r--DevTools/HackStudio/Project.h2
4 files changed, 43 insertions, 12 deletions
diff --git a/DevTools/HackStudio/HackStudioWidget.cpp b/DevTools/HackStudio/HackStudioWidget.cpp
index ffe54ca1ea..ef79a84bd2 100644
--- a/DevTools/HackStudio/HackStudioWidget.cpp
+++ b/DevTools/HackStudio/HackStudioWidget.cpp
@@ -59,6 +59,7 @@
#include <LibGUI/Button.h>
#include <LibGUI/FilePicker.h>
#include <LibGUI/InputBox.h>
+#include <LibGUI/ItemListModel.h>
#include <LibGUI/Label.h>
#include <LibGUI/Menu.h>
#include <LibGUI/MenuBar.h>
@@ -97,9 +98,15 @@ HackStudioWidget::HackStudioWidget(const String& path_to_project)
auto& toolbar_container = add<GUI::ToolBarContainer>();
auto& outer_splitter = add<GUI::HorizontalSplitter>();
- create_project_tree_view(outer_splitter);
+
+ auto& left_hand_splitter = outer_splitter.add<GUI::VerticalSplitter>();
+ left_hand_splitter.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
+ left_hand_splitter.set_preferred_size(150, 0);
+ create_project_tree_view(left_hand_splitter);
m_project_tree_view_context_menu = create_project_tree_view_context_menu();
+ create_open_files_view(left_hand_splitter);
+
m_right_hand_splitter = outer_splitter.add<GUI::VerticalSplitter>();
m_right_hand_stack = m_right_hand_splitter->add<GUI::StackWidget>();
create_form_editor(*m_right_hand_stack);
@@ -198,15 +205,23 @@ Vector<String> HackStudioWidget::selected_file_names() const
void HackStudioWidget::open_file(const String& filename)
{
auto project_file = m_project->get_file(filename);
- if (project_file) {
- current_editor().set_document(const_cast<GUI::TextDocument&>(project_file->document()));
- current_editor().set_mode(GUI::TextEditor::Editable);
- } else {
- auto external_file = ProjectFile::construct_with_name(filename);
- current_editor().set_document(const_cast<GUI::TextDocument&>(external_file->document()));
- current_editor().set_mode(GUI::TextEditor::ReadOnly);
+
+ if (!project_file) {
+ if (auto it = m_open_files.find(filename); it != m_open_files.end()) {
+ project_file = it->value;
+ } else {
+ project_file = ProjectFile::construct_with_name(filename);
+ }
+ }
+
+ if (m_open_files.set(filename, *project_file) == AK::HashSetResult::InsertedNewEntry) {
+ m_open_files_vector.append(filename);
+ m_open_files_view->model()->update();
}
+ current_editor().set_document(const_cast<GUI::TextDocument&>(project_file->document()));
+ current_editor().set_mode(GUI::TextEditor::Editable);
+
if (filename.ends_with(".frm")) {
set_edit_mode(EditMode::Form);
} else {
@@ -625,8 +640,6 @@ void HackStudioWidget::create_project_tree_view(GUI::Widget& parent)
{
m_project_tree_view = parent.add<GUI::TreeView>();
m_project_tree_view->set_model(m_project->model());
- m_project_tree_view->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
- m_project_tree_view->set_preferred_size(140, 0);
m_project_tree_view->toggle_index(m_project_tree_view->model()->index(0, 0));
m_project_tree_view->on_context_menu_request = [this](const GUI::ModelIndex& index, const GUI::ContextMenuEvent& event) {
@@ -646,6 +659,17 @@ void HackStudioWidget::create_project_tree_view(GUI::Widget& parent)
};
}
+void HackStudioWidget::create_open_files_view(GUI::Widget& parent)
+{
+ m_open_files_view = parent.add<GUI::ListView>();
+ auto open_files_model = GUI::ItemListModel<String>::create(m_open_files_vector);
+ m_open_files_view->set_model(open_files_model);
+
+ m_open_files_view->on_activation = [this] (auto& index) {
+ open_file(index.data().to_string());
+ };
+}
+
void HackStudioWidget::create_form_editor(GUI::Widget& parent)
{
m_form_inner_container = parent.add<GUI::Widget>();
diff --git a/DevTools/HackStudio/HackStudioWidget.h b/DevTools/HackStudio/HackStudioWidget.h
index c7f254446b..f6e930de3a 100644
--- a/DevTools/HackStudio/HackStudioWidget.h
+++ b/DevTools/HackStudio/HackStudioWidget.h
@@ -103,6 +103,7 @@ private:
void initialize_debugger();
void create_project_tree_view(GUI::Widget& parent);
+ void create_open_files_view(GUI::Widget& parent);
void create_form_editor(GUI::Widget& parent);
void create_toolbar(GUI::Widget& parent);
void create_action_tab(GUI::Widget& parent);
@@ -121,10 +122,16 @@ private:
NonnullRefPtrVector<EditorWrapper> m_all_editor_wrappers;
RefPtr<EditorWrapper> m_current_editor_wrapper;
+ // FIXME: This doesn't seem compatible with multiple split editors
String m_currently_open_file;
+
+ HashMap<String, NonnullRefPtr<ProjectFile>> m_open_files;
+ Vector<String> m_open_files_vector; // NOTE: This contains the keys from m_open_files
+
OwnPtr<Project> m_project;
RefPtr<GUI::TreeView> m_project_tree_view;
+ RefPtr<GUI::ListView> m_open_files_view;
RefPtr<GUI::VerticalSplitter> m_right_hand_splitter;
RefPtr<GUI::StackWidget> m_right_hand_stack;
RefPtr<GUI::Splitter> m_editors_splitter;
diff --git a/DevTools/HackStudio/Project.cpp b/DevTools/HackStudio/Project.cpp
index 6c71337896..8ff6a13a06 100644
--- a/DevTools/HackStudio/Project.cpp
+++ b/DevTools/HackStudio/Project.cpp
@@ -291,7 +291,7 @@ bool Project::save()
return true;
}
-ProjectFile* Project::get_file(const String& filename)
+RefPtr<ProjectFile> Project::get_file(const String& filename)
{
for (auto& file : m_files) {
if (LexicalPath(file.name()).string() == LexicalPath(filename).string())
diff --git a/DevTools/HackStudio/Project.h b/DevTools/HackStudio/Project.h
index d1a3c31ac8..dddb34726f 100644
--- a/DevTools/HackStudio/Project.h
+++ b/DevTools/HackStudio/Project.h
@@ -55,7 +55,7 @@ public:
[[nodiscard]] bool remove_file(const String& filename);
[[nodiscard]] bool save();
- ProjectFile* get_file(const String& filename);
+ RefPtr<ProjectFile> get_file(const String& filename);
ProjectType type() const { return m_type; }
GUI::Model& model() { return *m_model; }