SpreadsheetWidget.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. /*
  2. * Copyright (c) 2020-2022, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "SpreadsheetWidget.h"
  7. #include "CellSyntaxHighlighter.h"
  8. #include "HelpWindow.h"
  9. #include "LibFileSystemAccessClient/Client.h"
  10. #include <LibGUI/Application.h>
  11. #include <LibGUI/BoxLayout.h>
  12. #include <LibGUI/Button.h>
  13. #include <LibGUI/FilePicker.h>
  14. #include <LibGUI/InputBox.h>
  15. #include <LibGUI/Label.h>
  16. #include <LibGUI/Menu.h>
  17. #include <LibGUI/MessageBox.h>
  18. #include <LibGUI/Splitter.h>
  19. #include <LibGUI/TabWidget.h>
  20. #include <LibGUI/TextEditor.h>
  21. #include <LibGUI/Toolbar.h>
  22. #include <LibGUI/ToolbarContainer.h>
  23. #include <LibGfx/Font/FontDatabase.h>
  24. #include <string.h>
  25. namespace Spreadsheet {
  26. SpreadsheetWidget::SpreadsheetWidget(GUI::Window& parent_window, NonnullRefPtrVector<Sheet>&& sheets, bool should_add_sheet_if_empty)
  27. : m_workbook(make<Workbook>(move(sheets), parent_window))
  28. {
  29. set_fill_with_background_color(true);
  30. set_layout<GUI::VerticalBoxLayout>().set_margins(2);
  31. auto& toolbar_container = add<GUI::ToolbarContainer>();
  32. auto& toolbar = toolbar_container.add<GUI::Toolbar>();
  33. auto& container = add<GUI::VerticalSplitter>();
  34. auto& top_bar = container.add<GUI::Frame>();
  35. top_bar.set_layout<GUI::HorizontalBoxLayout>().set_spacing(1);
  36. top_bar.set_fixed_height(26);
  37. auto& current_cell_label = top_bar.add<GUI::Label>("");
  38. current_cell_label.set_fixed_width(50);
  39. auto& help_button = top_bar.add<GUI::Button>("");
  40. help_button.set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-help.png").release_value_but_fixme_should_propagate_errors());
  41. help_button.set_tooltip("Functions Help");
  42. help_button.set_fixed_size(20, 20);
  43. help_button.on_click = [&](auto) {
  44. if (!current_view()) {
  45. GUI::MessageBox::show_error(window(), "Can only show function documentation/help when a worksheet exists and is open");
  46. } else if (auto* sheet_ptr = current_worksheet_if_available()) {
  47. auto docs = sheet_ptr->gather_documentation();
  48. auto help_window = HelpWindow::the(window());
  49. help_window->set_docs(move(docs));
  50. help_window->show();
  51. }
  52. };
  53. auto& cell_value_editor = top_bar.add<GUI::TextEditor>(GUI::TextEditor::Type::SingleLine);
  54. cell_value_editor.set_font(Gfx::FontDatabase::default_fixed_width_font());
  55. cell_value_editor.set_scrollbars_enabled(false);
  56. cell_value_editor.on_return_pressed = [this]() {
  57. current_view()->move_cursor(GUI::AbstractView::CursorMovement::Down);
  58. };
  59. cell_value_editor.set_syntax_highlighter(make<CellSyntaxHighlighter>());
  60. cell_value_editor.set_enabled(false);
  61. current_cell_label.set_enabled(false);
  62. m_tab_widget = container.add<GUI::TabWidget>();
  63. m_tab_widget->set_tab_position(GUI::TabWidget::TabPosition::Bottom);
  64. m_cell_value_editor = cell_value_editor;
  65. m_current_cell_label = current_cell_label;
  66. m_inline_documentation_window = GUI::Window::construct(window());
  67. m_inline_documentation_window->set_rect(m_cell_value_editor->rect().translated(0, m_cell_value_editor->height() + 7).inflated(6, 6));
  68. m_inline_documentation_window->set_window_type(GUI::WindowType::Tooltip);
  69. m_inline_documentation_window->set_resizable(false);
  70. auto& inline_widget = m_inline_documentation_window->set_main_widget<GUI::Frame>();
  71. inline_widget.set_fill_with_background_color(true);
  72. inline_widget.set_layout<GUI::VerticalBoxLayout>().set_margins(4);
  73. inline_widget.set_frame_shape(Gfx::FrameShape::Box);
  74. m_inline_documentation_label = inline_widget.add<GUI::Label>();
  75. m_inline_documentation_label->set_fill_with_background_color(true);
  76. m_inline_documentation_label->set_autosize(false);
  77. m_inline_documentation_label->set_text_alignment(Gfx::TextAlignment::CenterLeft);
  78. if (!m_workbook->has_sheets() && should_add_sheet_if_empty)
  79. m_workbook->add_sheet("Sheet 1");
  80. m_tab_context_menu = GUI::Menu::construct();
  81. m_rename_action = GUI::CommonActions::make_rename_action([this](auto&) {
  82. VERIFY(m_tab_context_menu_sheet_view);
  83. auto* sheet_ptr = m_tab_context_menu_sheet_view->sheet_if_available();
  84. VERIFY(sheet_ptr); // How did we get here without a sheet?
  85. auto& sheet = *sheet_ptr;
  86. String new_name;
  87. if (GUI::InputBox::show(window(), new_name, String::formatted("New name for '{}'", sheet.name()), "Rename sheet") == GUI::Dialog::ExecResult::OK) {
  88. sheet.set_name(new_name);
  89. sheet.update();
  90. m_tab_widget->set_tab_title(static_cast<GUI::Widget&>(*m_tab_context_menu_sheet_view), new_name);
  91. }
  92. });
  93. m_tab_context_menu->add_action(*m_rename_action);
  94. m_tab_context_menu->add_action(GUI::Action::create("Add new sheet...", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/new-tab.png").release_value_but_fixme_should_propagate_errors(), [this](auto&) {
  95. String name;
  96. if (GUI::InputBox::show(window(), name, "Name for new sheet", "Create sheet") == GUI::Dialog::ExecResult::OK) {
  97. NonnullRefPtrVector<Sheet> new_sheets;
  98. new_sheets.append(m_workbook->add_sheet(name));
  99. setup_tabs(move(new_sheets));
  100. }
  101. }));
  102. setup_tabs(m_workbook->sheets());
  103. m_new_action = GUI::Action::create("Add New Sheet", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/new-tab.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
  104. add_sheet();
  105. });
  106. m_open_action = GUI::CommonActions::make_open_action([&](auto&) {
  107. if (!request_close())
  108. return;
  109. Optional<String> load_path = GUI::FilePicker::get_open_filepath(window());
  110. if (!load_path.has_value())
  111. return;
  112. auto response = FileSystemAccessClient::Client::the().try_request_file_read_only_approved(window(), *load_path);
  113. if (response.is_error())
  114. return;
  115. load_file(*response.value());
  116. });
  117. m_save_action = GUI::CommonActions::make_save_action([&](auto&) {
  118. if (current_filename().is_empty()) {
  119. m_save_as_action->activate();
  120. return;
  121. }
  122. save(current_filename());
  123. });
  124. m_save_as_action = GUI::CommonActions::make_save_as_action([&](auto&) {
  125. String name = "workbook";
  126. Optional<String> save_path = GUI::FilePicker::get_save_filepath(window(), name, "sheets");
  127. if (!save_path.has_value())
  128. return;
  129. save(save_path.value());
  130. update_window_title();
  131. });
  132. m_quit_action = GUI::CommonActions::make_quit_action([&](auto&) {
  133. if (!request_close())
  134. return;
  135. GUI::Application::the()->quit(0);
  136. });
  137. m_cut_action = GUI::CommonActions::make_cut_action([&](auto&) { clipboard_action(true); }, window());
  138. m_copy_action = GUI::CommonActions::make_copy_action([&](auto&) { clipboard_action(false); }, window());
  139. m_paste_action = GUI::CommonActions::make_paste_action([&](auto&) {
  140. ScopeGuard update_after_paste { [&] { update(); } };
  141. auto* worksheet_ptr = current_worksheet_if_available();
  142. if (!worksheet_ptr) {
  143. GUI::MessageBox::show_error(window(), "There are no active worksheets");
  144. return;
  145. }
  146. auto& sheet = *worksheet_ptr;
  147. auto& cells = sheet.selected_cells();
  148. VERIFY(!cells.is_empty());
  149. const auto& data = GUI::Clipboard::the().fetch_data_and_type();
  150. if (auto spreadsheet_data = data.metadata.get("text/x-spreadsheet-data"); spreadsheet_data.has_value()) {
  151. Vector<Spreadsheet::Position> source_positions, target_positions;
  152. auto lines = spreadsheet_data.value().split_view('\n');
  153. auto action = lines.take_first();
  154. for (auto& line : lines) {
  155. dbgln("Paste line '{}'", line);
  156. auto position = sheet.position_from_url(line);
  157. if (position.has_value())
  158. source_positions.append(position.release_value());
  159. }
  160. for (auto& position : sheet.selected_cells())
  161. target_positions.append(position);
  162. if (source_positions.is_empty())
  163. return;
  164. auto first_position = source_positions.take_first();
  165. auto cell_changes = sheet.copy_cells(move(source_positions), move(target_positions), first_position, action == "cut" ? Spreadsheet::Sheet::CopyOperation::Cut : Spreadsheet::Sheet::CopyOperation::Copy);
  166. undo_stack().push(make<CellsUndoCommand>(cell_changes));
  167. } else {
  168. for (auto& cell : sheet.selected_cells())
  169. sheet.ensure(cell).set_data(StringView { data.data.data(), data.data.size() });
  170. update();
  171. }
  172. },
  173. window());
  174. m_undo_action = GUI::CommonActions::make_undo_action([&](auto&) {
  175. undo();
  176. });
  177. m_redo_action = GUI::CommonActions::make_redo_action([&](auto&) {
  178. redo();
  179. });
  180. m_undo_stack.on_state_change = [this] {
  181. m_undo_action->set_enabled(m_undo_stack.can_undo());
  182. m_redo_action->set_enabled(m_undo_stack.can_redo());
  183. };
  184. m_undo_action->set_enabled(false);
  185. m_redo_action->set_enabled(false);
  186. m_functions_help_action = GUI::Action::create(
  187. "&Functions Help", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-help.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
  188. if (auto* worksheet_ptr = current_worksheet_if_available()) {
  189. auto docs = worksheet_ptr->gather_documentation();
  190. auto help_window = Spreadsheet::HelpWindow::the(window());
  191. help_window->set_docs(move(docs));
  192. help_window->show();
  193. } else {
  194. GUI::MessageBox::show_error(window(), "Cannot prepare documentation/help without an active worksheet");
  195. }
  196. },
  197. window());
  198. m_about_action = GUI::CommonActions::make_about_action("Spreadsheet", GUI::Icon::default_icon("app-spreadsheet"), window());
  199. toolbar.add_action(*m_new_action);
  200. toolbar.add_action(*m_open_action);
  201. toolbar.add_action(*m_save_action);
  202. toolbar.add_separator();
  203. toolbar.add_action(*m_cut_action);
  204. toolbar.add_action(*m_copy_action);
  205. toolbar.add_action(*m_paste_action);
  206. toolbar.add_action(*m_undo_action);
  207. toolbar.add_action(*m_redo_action);
  208. m_cut_action->set_enabled(false);
  209. m_copy_action->set_enabled(false);
  210. m_paste_action->set_enabled(false);
  211. m_tab_widget->on_change = [this](auto& selected_widget) {
  212. // for keyboard shortcuts and command palette
  213. m_tab_context_menu_sheet_view = static_cast<SpreadsheetView&>(selected_widget);
  214. };
  215. m_tab_widget->on_context_menu_request = [&](auto& widget, auto& event) {
  216. m_tab_context_menu_sheet_view = static_cast<SpreadsheetView&>(widget);
  217. m_tab_context_menu->popup(event.screen_position());
  218. };
  219. m_tab_widget->on_double_click = [&](auto& widget) {
  220. m_tab_context_menu_sheet_view = static_cast<SpreadsheetView&>(widget);
  221. m_rename_action->activate();
  222. };
  223. }
  224. void SpreadsheetWidget::resize_event(GUI::ResizeEvent& event)
  225. {
  226. GUI::Widget::resize_event(event);
  227. if (m_inline_documentation_window && m_cell_value_editor && window())
  228. m_inline_documentation_window->set_rect(m_cell_value_editor->screen_relative_rect().translated(0, m_cell_value_editor->height() + 7).inflated(6, 6));
  229. }
  230. void SpreadsheetWidget::clipboard_content_did_change(String const& mime_type)
  231. {
  232. if (auto* sheet = current_worksheet_if_available())
  233. m_paste_action->set_enabled(!sheet->selected_cells().is_empty() && mime_type.starts_with("text/"));
  234. }
  235. void SpreadsheetWidget::setup_tabs(NonnullRefPtrVector<Sheet> new_sheets)
  236. {
  237. for (auto& sheet : new_sheets) {
  238. auto& new_view = m_tab_widget->add_tab<SpreadsheetView>(sheet.name(), sheet);
  239. new_view.model()->on_cell_data_change = [&](auto& cell, auto& previous_data) {
  240. undo_stack().push(make<CellsUndoCommand>(cell, previous_data));
  241. window()->set_modified(true);
  242. };
  243. new_view.model()->on_cells_data_change = [&](Vector<CellChange> cell_changes) {
  244. undo_stack().push(make<CellsUndoCommand>(cell_changes));
  245. window()->set_modified(true);
  246. };
  247. new_view.on_selection_changed = [&](Vector<Position>&& selection) {
  248. auto* sheet_ptr = current_worksheet_if_available();
  249. // How did this even happen?
  250. VERIFY(sheet_ptr);
  251. auto& sheet = *sheet_ptr;
  252. VERIFY(!selection.is_empty());
  253. m_cut_action->set_enabled(true);
  254. m_copy_action->set_enabled(true);
  255. m_paste_action->set_enabled(GUI::Clipboard::the().fetch_mime_type().starts_with("text/"));
  256. m_current_cell_label->set_enabled(true);
  257. m_cell_value_editor->set_enabled(true);
  258. if (selection.size() == 1) {
  259. auto& position = selection.first();
  260. m_current_cell_label->set_text(position.to_cell_identifier(sheet));
  261. auto& cell = sheet.ensure(position);
  262. m_cell_value_editor->on_change = nullptr;
  263. m_cell_value_editor->set_text(cell.source());
  264. m_cell_value_editor->on_change = [&] {
  265. auto text = m_cell_value_editor->text();
  266. // FIXME: Lines?
  267. auto offset = m_cell_value_editor->cursor().column();
  268. try_generate_tip_for_input_expression(text, offset);
  269. cell.set_data(move(text));
  270. sheet.update();
  271. update();
  272. };
  273. static_cast<CellSyntaxHighlighter*>(const_cast<Syntax::Highlighter*>(m_cell_value_editor->syntax_highlighter()))->set_cell(&cell);
  274. return;
  275. }
  276. // There are many cells selected, change all of them.
  277. StringBuilder builder;
  278. builder.appendff("<{}>", selection.size());
  279. m_current_cell_label->set_text(builder.string_view());
  280. Vector<Cell&> cells;
  281. for (auto& position : selection)
  282. cells.append(sheet.ensure(position));
  283. auto& first_cell = cells.first();
  284. m_cell_value_editor->on_change = nullptr;
  285. m_cell_value_editor->set_text("");
  286. m_should_change_selected_cells = false;
  287. m_cell_value_editor->on_focusin = [this] { m_should_change_selected_cells = true; };
  288. m_cell_value_editor->on_focusout = [this] { m_should_change_selected_cells = false; };
  289. m_cell_value_editor->on_change = [cells = move(cells), this]() mutable {
  290. if (m_should_change_selected_cells) {
  291. auto* sheet_ptr = current_worksheet_if_available();
  292. if (!sheet_ptr)
  293. return;
  294. auto& sheet = *sheet_ptr;
  295. auto text = m_cell_value_editor->text();
  296. // FIXME: Lines?
  297. auto offset = m_cell_value_editor->cursor().column();
  298. try_generate_tip_for_input_expression(text, offset);
  299. for (auto& cell : cells)
  300. cell.set_data(text);
  301. sheet.update();
  302. update();
  303. }
  304. };
  305. static_cast<CellSyntaxHighlighter*>(const_cast<Syntax::Highlighter*>(m_cell_value_editor->syntax_highlighter()))->set_cell(&first_cell);
  306. };
  307. new_view.on_selection_dropped = [&]() {
  308. m_current_cell_label->set_enabled(false);
  309. m_current_cell_label->set_text({});
  310. m_cell_value_editor->on_change = nullptr;
  311. m_cell_value_editor->on_focusin = nullptr;
  312. m_cell_value_editor->on_focusout = nullptr;
  313. m_cell_value_editor->set_text({});
  314. m_cell_value_editor->set_enabled(false);
  315. m_cut_action->set_enabled(false);
  316. m_copy_action->set_enabled(false);
  317. m_paste_action->set_enabled(false);
  318. static_cast<CellSyntaxHighlighter*>(const_cast<Syntax::Highlighter*>(m_cell_value_editor->syntax_highlighter()))->set_cell(nullptr);
  319. };
  320. }
  321. }
  322. void SpreadsheetWidget::try_generate_tip_for_input_expression(StringView source, size_t cursor_offset)
  323. {
  324. auto* sheet_ptr = current_view()->sheet_if_available();
  325. if (!sheet_ptr)
  326. return;
  327. auto& sheet = *sheet_ptr;
  328. m_inline_documentation_window->set_rect(m_cell_value_editor->screen_relative_rect().translated(0, m_cell_value_editor->height() + 7).inflated(6, 6));
  329. if (!current_view() || !source.starts_with('=')) {
  330. m_inline_documentation_window->hide();
  331. return;
  332. }
  333. auto maybe_function_and_argument = get_function_and_argument_index(source.substring_view(0, cursor_offset));
  334. if (!maybe_function_and_argument.has_value()) {
  335. m_inline_documentation_window->hide();
  336. return;
  337. }
  338. auto& [name, index] = maybe_function_and_argument.value();
  339. auto text = sheet.generate_inline_documentation_for(name, index);
  340. if (text.is_empty()) {
  341. m_inline_documentation_window->hide();
  342. } else {
  343. m_inline_documentation_label->set_text(move(text));
  344. m_inline_documentation_window->show();
  345. }
  346. }
  347. void SpreadsheetWidget::undo()
  348. {
  349. if (!m_undo_stack.can_undo())
  350. return;
  351. m_undo_stack.undo();
  352. update();
  353. }
  354. void SpreadsheetWidget::redo()
  355. {
  356. if (!m_undo_stack.can_redo())
  357. return;
  358. m_undo_stack.redo();
  359. update();
  360. }
  361. void SpreadsheetWidget::save(StringView filename)
  362. {
  363. auto result = m_workbook->save(filename);
  364. if (result.is_error()) {
  365. GUI::MessageBox::show_error(window(), result.error());
  366. return;
  367. }
  368. undo_stack().set_current_unmodified();
  369. window()->set_modified(false);
  370. }
  371. void SpreadsheetWidget::load_file(Core::File& file)
  372. {
  373. auto result = m_workbook->open_file(file);
  374. if (result.is_error()) {
  375. GUI::MessageBox::show_error(window(), result.error());
  376. return;
  377. }
  378. m_cell_value_editor->on_change = nullptr;
  379. m_current_cell_label->set_text("");
  380. m_should_change_selected_cells = false;
  381. while (auto* widget = m_tab_widget->active_widget()) {
  382. m_tab_widget->remove_tab(*widget);
  383. }
  384. setup_tabs(m_workbook->sheets());
  385. update_window_title();
  386. }
  387. bool SpreadsheetWidget::request_close()
  388. {
  389. if (!undo_stack().is_current_modified())
  390. return true;
  391. auto result = GUI::MessageBox::ask_about_unsaved_changes(window(), current_filename());
  392. if (result == GUI::MessageBox::ExecResult::Yes) {
  393. m_save_action->activate();
  394. return !m_workbook->dirty();
  395. }
  396. if (result == GUI::MessageBox::ExecResult::No)
  397. return true;
  398. return false;
  399. }
  400. void SpreadsheetWidget::add_sheet()
  401. {
  402. StringBuilder name;
  403. name.append("Sheet");
  404. name.appendff(" {}", m_workbook->sheets().size() + 1);
  405. NonnullRefPtrVector<Sheet> new_sheets;
  406. new_sheets.append(m_workbook->add_sheet(name.string_view()));
  407. setup_tabs(move(new_sheets));
  408. }
  409. void SpreadsheetWidget::add_sheet(NonnullRefPtr<Sheet>&& sheet)
  410. {
  411. VERIFY(m_workbook == &sheet->workbook());
  412. NonnullRefPtrVector<Sheet> new_sheets;
  413. new_sheets.append(move(sheet));
  414. m_workbook->sheets().extend(new_sheets);
  415. setup_tabs(new_sheets);
  416. }
  417. void SpreadsheetWidget::update_window_title()
  418. {
  419. StringBuilder builder;
  420. if (current_filename().is_empty())
  421. builder.append("Untitled");
  422. else
  423. builder.append(current_filename());
  424. builder.append("[*] - Spreadsheet");
  425. window()->set_title(builder.to_string());
  426. }
  427. void SpreadsheetWidget::clipboard_action(bool is_cut)
  428. {
  429. /// text/x-spreadsheet-data:
  430. /// - action: copy/cut
  431. /// - currently selected cell
  432. /// - selected cell+
  433. auto* worksheet_ptr = current_worksheet_if_available();
  434. if (!worksheet_ptr) {
  435. GUI::MessageBox::show_error(window(), "There are no active worksheets");
  436. return;
  437. }
  438. auto& worksheet = *worksheet_ptr;
  439. auto& cells = worksheet.selected_cells();
  440. VERIFY(!cells.is_empty());
  441. StringBuilder text_builder, url_builder;
  442. url_builder.append(is_cut ? "cut\n" : "copy\n");
  443. bool first = true;
  444. auto cursor = current_selection_cursor();
  445. if (cursor) {
  446. Spreadsheet::Position position { (size_t)cursor->column(), (size_t)cursor->row() };
  447. url_builder.append(position.to_url(worksheet).to_string());
  448. url_builder.append('\n');
  449. }
  450. for (auto& cell : cells) {
  451. if (first && !cursor) {
  452. url_builder.append(cell.to_url(worksheet).to_string());
  453. url_builder.append('\n');
  454. }
  455. url_builder.append(cell.to_url(worksheet).to_string());
  456. url_builder.append('\n');
  457. auto cell_data = worksheet.at(cell);
  458. if (!first)
  459. text_builder.append('\t');
  460. if (cell_data)
  461. text_builder.append(cell_data->data());
  462. first = false;
  463. }
  464. HashMap<String, String> metadata;
  465. metadata.set("text/x-spreadsheet-data", url_builder.to_string());
  466. dbgln(url_builder.to_string());
  467. GUI::Clipboard::the().set_data(text_builder.string_view().bytes(), "text/plain", move(metadata));
  468. }
  469. void SpreadsheetWidget::initialize_menubar(GUI::Window& window)
  470. {
  471. auto& file_menu = window.add_menu("&File");
  472. file_menu.add_action(*m_new_action);
  473. file_menu.add_action(*m_open_action);
  474. file_menu.add_action(*m_save_action);
  475. file_menu.add_action(*m_save_as_action);
  476. file_menu.add_separator();
  477. file_menu.add_action(*m_quit_action);
  478. auto& edit_menu = window.add_menu("&Edit");
  479. edit_menu.add_action(*m_undo_action);
  480. edit_menu.add_action(*m_redo_action);
  481. edit_menu.add_separator();
  482. edit_menu.add_action(*m_cut_action);
  483. edit_menu.add_action(*m_copy_action);
  484. edit_menu.add_action(*m_paste_action);
  485. auto& help_menu = window.add_menu("&Help");
  486. help_menu.add_action(*m_functions_help_action);
  487. help_menu.add_action(*m_about_action);
  488. }
  489. }