mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 22:17:43 +00:00
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
This commit is contained in:
parent
876424923a
commit
f5ff011c1b
5 changed files with 10 additions and 7 deletions
|
@ -19,6 +19,7 @@
|
||||||
#include <LibGUI/StackWidget.h>
|
#include <LibGUI/StackWidget.h>
|
||||||
#include <LibGUI/TableView.h>
|
#include <LibGUI/TableView.h>
|
||||||
#include <LibGUI/TextBox.h>
|
#include <LibGUI/TextBox.h>
|
||||||
|
#include <LibGUI/Window.h>
|
||||||
#include <LibGUI/Wizards/WizardDialog.h>
|
#include <LibGUI/Wizards/WizardDialog.h>
|
||||||
#include <LibGUI/Wizards/WizardPage.h>
|
#include <LibGUI/Wizards/WizardPage.h>
|
||||||
|
|
||||||
|
@ -174,9 +175,9 @@ void CSVImportDialogPage::update_preview()
|
||||||
m_data_preview_table_view->update();
|
m_data_preview_table_view->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<NonnullRefPtrVector<Sheet>, String> ImportDialog::make_and_run_for(StringView mime, Core::File& file, Workbook& workbook)
|
Result<NonnullRefPtrVector<Sheet>, 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_title("File Import Wizard");
|
||||||
wizard->set_icon(GUI::Icon::default_icon("app-spreadsheet").bitmap_for_size(16));
|
wizard->set_icon(GUI::Icon::default_icon("app-spreadsheet").bitmap_for_size(16));
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ImportDialog {
|
struct ImportDialog {
|
||||||
static Result<NonnullRefPtrVector<Sheet>, String> make_and_run_for(StringView mime, Core::File& file, Workbook&);
|
static Result<NonnullRefPtrVector<Sheet>, String> make_and_run_for(GUI::Window* parent, StringView mime, Core::File& file, Workbook&);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
namespace Spreadsheet {
|
namespace Spreadsheet {
|
||||||
|
|
||||||
SpreadsheetWidget::SpreadsheetWidget(NonnullRefPtrVector<Sheet>&& sheets, bool should_add_sheet_if_empty)
|
SpreadsheetWidget::SpreadsheetWidget(NonnullRefPtrVector<Sheet>&& sheets, bool should_add_sheet_if_empty)
|
||||||
: m_workbook(make<Workbook>(move(sheets)))
|
: m_workbook(make<Workbook>(move(sheets), window()))
|
||||||
{
|
{
|
||||||
set_fill_with_background_color(true);
|
set_fill_with_background_color(true);
|
||||||
set_layout<GUI::VerticalBoxLayout>().set_margins(2);
|
set_layout<GUI::VerticalBoxLayout>().set_margins(2);
|
||||||
|
|
|
@ -17,12 +17,13 @@
|
||||||
|
|
||||||
namespace Spreadsheet {
|
namespace Spreadsheet {
|
||||||
|
|
||||||
Workbook::Workbook(NonnullRefPtrVector<Sheet>&& sheets)
|
Workbook::Workbook(NonnullRefPtrVector<Sheet>&& sheets, GUI::Window* parent_window)
|
||||||
: m_sheets(move(sheets))
|
: m_sheets(move(sheets))
|
||||||
, m_vm(JS::VM::create())
|
, m_vm(JS::VM::create())
|
||||||
, m_interpreter(JS::Interpreter::create<JS::GlobalObject>(m_vm))
|
, m_interpreter(JS::Interpreter::create<JS::GlobalObject>(m_vm))
|
||||||
, m_interpreter_scope(*m_interpreter)
|
, m_interpreter_scope(*m_interpreter)
|
||||||
, m_main_execution_context(m_vm->heap())
|
, m_main_execution_context(m_vm->heap())
|
||||||
|
, m_parent_window(parent_window)
|
||||||
{
|
{
|
||||||
m_workbook_object = m_vm->heap().allocate<WorkbookObject>(m_interpreter->global_object(), *this);
|
m_workbook_object = m_vm->heap().allocate<WorkbookObject>(m_interpreter->global_object(), *this);
|
||||||
m_interpreter->global_object().define_direct_property("workbook", workbook_object(), JS::default_attributes);
|
m_interpreter->global_object().define_direct_property("workbook", workbook_object(), JS::default_attributes);
|
||||||
|
@ -62,7 +63,7 @@ Result<bool, String> Workbook::load(StringView filename)
|
||||||
auto mime = Core::guess_mime_type_based_on_filename(filename);
|
auto mime = Core::guess_mime_type_based_on_filename(filename);
|
||||||
|
|
||||||
// Make an import dialog, we might need to import it.
|
// 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())
|
if (result.is_error())
|
||||||
return result.error();
|
return result.error();
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace Spreadsheet {
|
||||||
|
|
||||||
class Workbook {
|
class Workbook {
|
||||||
public:
|
public:
|
||||||
Workbook(NonnullRefPtrVector<Sheet>&& sheets);
|
Workbook(NonnullRefPtrVector<Sheet>&& sheets, GUI::Window* parent_window);
|
||||||
|
|
||||||
Result<bool, String> save(StringView filename);
|
Result<bool, String> save(StringView filename);
|
||||||
Result<bool, String> load(StringView filename);
|
Result<bool, String> load(StringView filename);
|
||||||
|
@ -48,6 +48,7 @@ private:
|
||||||
JS::VM::InterpreterExecutionScope m_interpreter_scope;
|
JS::VM::InterpreterExecutionScope m_interpreter_scope;
|
||||||
WorkbookObject* m_workbook_object { nullptr };
|
WorkbookObject* m_workbook_object { nullptr };
|
||||||
JS::ExecutionContext m_main_execution_context;
|
JS::ExecutionContext m_main_execution_context;
|
||||||
|
GUI::Window* m_parent_window { nullptr };
|
||||||
|
|
||||||
String m_current_filename;
|
String m_current_filename;
|
||||||
bool m_dirty { false };
|
bool m_dirty { false };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue