1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:27:35 +00:00

Spreadsheet: Drop all references to example windows when closing them

Fixes #4716.
This commit is contained in:
AnotherTest 2021-01-02 10:06:53 +03:30 committed by Andreas Kling
parent e080a4f74a
commit 4bc33ee3ae
4 changed files with 13 additions and 10 deletions

View file

@ -124,11 +124,13 @@ HelpWindow::HelpWindow(GUI::Window* parent)
return; return;
} }
auto dialog = GUI::Window::construct(this); auto window = GUI::Window::construct(this);
dialog->resize(size()); window->resize(size());
dialog->set_icon(icon()); window->set_icon(icon());
dialog->set_title(String::formatted("Spreadsheet Help - Example {} for {}", name, entry)); window->set_title(String::formatted("Spreadsheet Help - Example {} for {}", name, entry));
auto& widget = dialog->set_main_widget<SpreadsheetWidget>(NonnullRefPtrVector<Sheet> {}, false); window->on_close = [window = window.ptr()] { window->remove_from_parent(); };
auto& widget = window->set_main_widget<SpreadsheetWidget>(NonnullRefPtrVector<Sheet> {}, false);
auto sheet = Sheet::from_json(value.as_object(), widget.workbook()); auto sheet = Sheet::from_json(value.as_object(), widget.workbook());
if (!sheet) { if (!sheet) {
GUI::MessageBox::show_error(this, String::formatted("Corrupted example '{}' in '{}'", name, url.path())); GUI::MessageBox::show_error(this, String::formatted("Corrupted example '{}' in '{}'", name, url.path()));
@ -136,7 +138,7 @@ HelpWindow::HelpWindow(GUI::Window* parent)
} }
widget.add_sheet(sheet.release_nonnull()); widget.add_sheet(sheet.release_nonnull());
dialog->show(); window->show();
} else if (url.host() == "doc") { } else if (url.host() == "doc") {
auto entry = LexicalPath(url.path()).basename(); auto entry = LexicalPath(url.path()).basename();
m_webview->load(URL::create_with_data("text/html", render(entry))); m_webview->load(URL::create_with_data("text/html", render(entry)));

View file

@ -27,6 +27,7 @@
#pragma once #pragma once
#include <AK/JsonObject.h> #include <AK/JsonObject.h>
#include <LibGUI/Dialog.h>
#include <LibGUI/Widget.h> #include <LibGUI/Widget.h>
#include <LibGUI/Window.h> #include <LibGUI/Window.h>
#include <LibWeb/OutOfProcessWebView.h> #include <LibWeb/OutOfProcessWebView.h>
@ -37,12 +38,12 @@ class HelpWindow : public GUI::Window {
C_OBJECT(HelpWindow); C_OBJECT(HelpWindow);
public: public:
static NonnullRefPtr<HelpWindow> the() static NonnullRefPtr<HelpWindow> the(GUI::Window* window)
{ {
if (s_the) if (s_the)
return *s_the; return *s_the;
return *(s_the = adopt(*new HelpWindow)); return *(s_the = adopt(*new HelpWindow(window)));
} }
virtual ~HelpWindow() override; virtual ~HelpWindow() override;

View file

@ -60,7 +60,7 @@ SpreadsheetWidget::SpreadsheetWidget(NonnullRefPtrVector<Sheet>&& sheets, bool s
help_button.set_fixed_size(20, 20); help_button.set_fixed_size(20, 20);
help_button.on_click = [&](auto) { help_button.on_click = [&](auto) {
auto docs = m_selected_view->sheet().gather_documentation(); auto docs = m_selected_view->sheet().gather_documentation();
auto help_window = HelpWindow::the(); auto help_window = HelpWindow::the(window());
help_window->set_docs(move(docs)); help_window->set_docs(move(docs));
help_window->show(); help_window->show();
}; };

View file

@ -236,7 +236,7 @@ int main(int argc, char* argv[])
help_menu.add_action(GUI::Action::create( help_menu.add_action(GUI::Action::create(
"Functions Help", [&](auto&) { "Functions Help", [&](auto&) {
auto docs = spreadsheet_widget.current_worksheet().gather_documentation(); auto docs = spreadsheet_widget.current_worksheet().gather_documentation();
auto help_window = Spreadsheet::HelpWindow::the(); auto help_window = Spreadsheet::HelpWindow::the(window);
help_window->set_docs(move(docs)); help_window->set_docs(move(docs));
help_window->show(); help_window->show();
}, },