From f5ff011c1b23575004fa0c1ac800d7dd63432fd0 Mon Sep 17 00:00:00 2001 From: Glenford Williams Date: Sun, 9 Jan 2022 14:31:51 -0500 Subject: Spreadsheet: Properly pass parent window to Workbook Change the parent of the WizardDialog to that of the Spreadsheet window. Previously the WizardDialog was using the open file dialog as the parent resulting in the csv import dialog --- Userland/Applications/Spreadsheet/ImportDialog.cpp | 5 +++-- Userland/Applications/Spreadsheet/ImportDialog.h | 2 +- Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp | 2 +- Userland/Applications/Spreadsheet/Workbook.cpp | 5 +++-- Userland/Applications/Spreadsheet/Workbook.h | 3 ++- 5 files changed, 10 insertions(+), 7 deletions(-) (limited to 'Userland/Applications/Spreadsheet') diff --git a/Userland/Applications/Spreadsheet/ImportDialog.cpp b/Userland/Applications/Spreadsheet/ImportDialog.cpp index 2c646bf41b..4540b738b1 100644 --- a/Userland/Applications/Spreadsheet/ImportDialog.cpp +++ b/Userland/Applications/Spreadsheet/ImportDialog.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -174,9 +175,9 @@ void CSVImportDialogPage::update_preview() m_data_preview_table_view->update(); } -Result, String> ImportDialog::make_and_run_for(StringView mime, Core::File& file, Workbook& workbook) +Result, String> ImportDialog::make_and_run_for(GUI::Window* parent, StringView mime, Core::File& file, Workbook& workbook) { - auto wizard = GUI::WizardDialog::construct(GUI::Application::the()->active_window()); + auto wizard = GUI::WizardDialog::construct(parent); wizard->set_title("File Import Wizard"); wizard->set_icon(GUI::Icon::default_icon("app-spreadsheet").bitmap_for_size(16)); diff --git a/Userland/Applications/Spreadsheet/ImportDialog.h b/Userland/Applications/Spreadsheet/ImportDialog.h index 4ba081359a..c0e3a45e21 100644 --- a/Userland/Applications/Spreadsheet/ImportDialog.h +++ b/Userland/Applications/Spreadsheet/ImportDialog.h @@ -56,7 +56,7 @@ private: }; struct ImportDialog { - static Result, String> make_and_run_for(StringView mime, Core::File& file, Workbook&); + static Result, String> make_and_run_for(GUI::Window* parent, StringView mime, Core::File& file, Workbook&); }; } diff --git a/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp b/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp index 4160c7110b..50814fbac0 100644 --- a/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp +++ b/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp @@ -26,7 +26,7 @@ namespace Spreadsheet { SpreadsheetWidget::SpreadsheetWidget(NonnullRefPtrVector&& sheets, bool should_add_sheet_if_empty) - : m_workbook(make(move(sheets))) + : m_workbook(make(move(sheets), window())) { set_fill_with_background_color(true); set_layout().set_margins(2); diff --git a/Userland/Applications/Spreadsheet/Workbook.cpp b/Userland/Applications/Spreadsheet/Workbook.cpp index b6d90dd0af..41a133e74a 100644 --- a/Userland/Applications/Spreadsheet/Workbook.cpp +++ b/Userland/Applications/Spreadsheet/Workbook.cpp @@ -17,12 +17,13 @@ namespace Spreadsheet { -Workbook::Workbook(NonnullRefPtrVector&& sheets) +Workbook::Workbook(NonnullRefPtrVector&& sheets, GUI::Window* parent_window) : m_sheets(move(sheets)) , m_vm(JS::VM::create()) , m_interpreter(JS::Interpreter::create(m_vm)) , m_interpreter_scope(*m_interpreter) , m_main_execution_context(m_vm->heap()) + , m_parent_window(parent_window) { m_workbook_object = m_vm->heap().allocate(m_interpreter->global_object(), *this); m_interpreter->global_object().define_direct_property("workbook", workbook_object(), JS::default_attributes); @@ -62,7 +63,7 @@ Result Workbook::load(StringView filename) auto mime = Core::guess_mime_type_based_on_filename(filename); // Make an import dialog, we might need to import it. - auto result = ImportDialog::make_and_run_for(mime, file_or_error.value(), *this); + auto result = ImportDialog::make_and_run_for(m_parent_window, mime, file_or_error.value(), *this); if (result.is_error()) return result.error(); diff --git a/Userland/Applications/Spreadsheet/Workbook.h b/Userland/Applications/Spreadsheet/Workbook.h index 99206d0e6b..7fa7946136 100644 --- a/Userland/Applications/Spreadsheet/Workbook.h +++ b/Userland/Applications/Spreadsheet/Workbook.h @@ -15,7 +15,7 @@ namespace Spreadsheet { class Workbook { public: - Workbook(NonnullRefPtrVector&& sheets); + Workbook(NonnullRefPtrVector&& sheets, GUI::Window* parent_window); Result save(StringView filename); Result load(StringView filename); @@ -48,6 +48,7 @@ private: JS::VM::InterpreterExecutionScope m_interpreter_scope; WorkbookObject* m_workbook_object { nullptr }; JS::ExecutionContext m_main_execution_context; + GUI::Window* m_parent_window { nullptr }; String m_current_filename; bool m_dirty { false }; -- cgit v1.2.3