mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:38:11 +00:00
HackStudio: Store and restore the scrollbar values of ProjectFiles when they are closed and reopened from the list of open files.
This commit is contained in:
parent
39a1c9d827
commit
85d65b06ab
4 changed files with 48 additions and 9 deletions
|
@ -204,23 +204,34 @@ Vector<String> HackStudioWidget::selected_file_names() const
|
|||
|
||||
void HackStudioWidget::open_file(const String& filename)
|
||||
{
|
||||
auto project_file = m_project->get_file(filename);
|
||||
if (!currently_open_file().is_empty()) {
|
||||
// Since the file is previously open, it should always be in m_open_files.
|
||||
ASSERT(m_open_files.find(currently_open_file()) != m_open_files.end());
|
||||
auto previous_open_project_file = m_open_files.get(currently_open_file()).value();
|
||||
|
||||
if (!project_file) {
|
||||
// Update the scrollbar values of the previous_open_project_file and save them to m_open_files.
|
||||
previous_open_project_file->vertical_scroll_value(current_editor().vertical_scrollbar().value());
|
||||
previous_open_project_file->horizontal_scroll_value(current_editor().horizontal_scrollbar().value());
|
||||
m_open_files.set(currently_open_file(), previous_open_project_file);
|
||||
}
|
||||
|
||||
RefPtr<ProjectFile> new_project_file = nullptr;
|
||||
if (auto it = m_open_files.find(filename); it != m_open_files.end()) {
|
||||
project_file = it->value;
|
||||
new_project_file = it->value;
|
||||
} else {
|
||||
project_file = ProjectFile::construct_with_name(filename);
|
||||
new_project_file = m_project->get_file(filename);
|
||||
if (!new_project_file) {
|
||||
new_project_file = ProjectFile::construct_with_name(filename);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_open_files.set(filename, *project_file) == AK::HashSetResult::InsertedNewEntry) {
|
||||
m_open_files.set(filename, *new_project_file);
|
||||
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_document(const_cast<GUI::TextDocument&>(new_project_file->document()));
|
||||
current_editor().set_mode(GUI::TextEditor::Editable);
|
||||
current_editor().horizontal_scrollbar().set_value(new_project_file->horizontal_scroll_value());
|
||||
current_editor().vertical_scrollbar().set_value(new_project_file->vertical_scroll_value());
|
||||
|
||||
if (filename.ends_with(".frm")) {
|
||||
set_edit_mode(EditMode::Form);
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include <LibGUI/Splitter.h>
|
||||
#include <LibGUI/Widget.h>
|
||||
#include <LibThread/Thread.h>
|
||||
#include <LibGUI/ScrollBar.h>
|
||||
|
||||
namespace HackStudio {
|
||||
|
||||
|
|
|
@ -51,4 +51,24 @@ const GUI::TextDocument& ProjectFile::document() const
|
|||
return *m_document;
|
||||
}
|
||||
|
||||
int ProjectFile::vertical_scroll_value() const
|
||||
{
|
||||
return m_vertical_scroll_value;
|
||||
}
|
||||
|
||||
void ProjectFile::vertical_scroll_value(int vertical_scroll_value)
|
||||
{
|
||||
m_vertical_scroll_value = vertical_scroll_value;
|
||||
}
|
||||
|
||||
int ProjectFile::horizontal_scroll_value() const
|
||||
{
|
||||
return m_horizontal_scroll_value;
|
||||
}
|
||||
|
||||
void ProjectFile::horizontal_scroll_value(int horizontal_scroll_value)
|
||||
{
|
||||
m_horizontal_scroll_value = horizontal_scroll_value;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -45,11 +45,18 @@ public:
|
|||
|
||||
const GUI::TextDocument& document() const;
|
||||
|
||||
int vertical_scroll_value() const;
|
||||
void vertical_scroll_value(int);
|
||||
int horizontal_scroll_value() const;
|
||||
void horizontal_scroll_value(int);
|
||||
|
||||
private:
|
||||
explicit ProjectFile(const String& name);
|
||||
|
||||
String m_name;
|
||||
mutable RefPtr<CodeDocument> m_document;
|
||||
int m_vertical_scroll_value{ 0 };
|
||||
int m_horizontal_scroll_value{ 0 };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue