SpreadsheetWidget.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  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/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 (!m_selected_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 = m_selected_view->sheet_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. m_selected_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::Action::create("Rename...", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/rename.png").release_value_but_fixme_should_propagate_errors(), [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::ExecOK) {
  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::ExecOK) {
  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. String name = "workbook";
  120. Optional<String> save_path = GUI::FilePicker::get_save_filepath(window(), name, "sheets");
  121. if (!save_path.has_value())
  122. return;
  123. save(save_path.value());
  124. update_window_title();
  125. } else {
  126. save(current_filename());
  127. }
  128. });
  129. m_save_as_action = GUI::CommonActions::make_save_as_action([&](auto&) {
  130. String name = "workbook";
  131. Optional<String> save_path = GUI::FilePicker::get_save_filepath(window(), name, "sheets");
  132. if (!save_path.has_value())
  133. return;
  134. save(save_path.value());
  135. update_window_title();
  136. });
  137. m_quit_action = GUI::CommonActions::make_quit_action([&](auto&) {
  138. if (!request_close())
  139. return;
  140. GUI::Application::the()->quit(0);
  141. });
  142. m_cut_action = GUI::CommonActions::make_cut_action([&](auto&) { clipboard_action(true); }, window());
  143. m_copy_action = GUI::CommonActions::make_copy_action([&](auto&) { clipboard_action(false); }, window());
  144. m_paste_action = GUI::CommonActions::make_paste_action([&](auto&) {
  145. ScopeGuard update_after_paste { [&] { update(); } };
  146. auto* worksheet_ptr = current_worksheet_if_available();
  147. if (!worksheet_ptr) {
  148. GUI::MessageBox::show_error(window(), "There are no active worksheets");
  149. return;
  150. }
  151. auto& sheet = *worksheet_ptr;
  152. auto& cells = sheet.selected_cells();
  153. VERIFY(!cells.is_empty());
  154. const auto& data = GUI::Clipboard::the().fetch_data_and_type();
  155. if (auto spreadsheet_data = data.metadata.get("text/x-spreadsheet-data"); spreadsheet_data.has_value()) {
  156. Vector<Spreadsheet::Position> source_positions, target_positions;
  157. auto lines = spreadsheet_data.value().split_view('\n');
  158. auto action = lines.take_first();
  159. for (auto& line : lines) {
  160. dbgln("Paste line '{}'", line);
  161. auto position = sheet.position_from_url(line);
  162. if (position.has_value())
  163. source_positions.append(position.release_value());
  164. }
  165. for (auto& position : sheet.selected_cells())
  166. target_positions.append(position);
  167. if (source_positions.is_empty())
  168. return;
  169. auto first_position = source_positions.take_first();
  170. sheet.copy_cells(move(source_positions), move(target_positions), first_position, action == "cut" ? Spreadsheet::Sheet::CopyOperation::Cut : Spreadsheet::Sheet::CopyOperation::Copy);
  171. } else {
  172. for (auto& cell : sheet.selected_cells())
  173. sheet.ensure(cell).set_data(StringView { data.data.data(), data.data.size() });
  174. update();
  175. }
  176. },
  177. window());
  178. m_undo_action = GUI::CommonActions::make_undo_action([&](auto&) {
  179. undo();
  180. });
  181. m_redo_action = GUI::CommonActions::make_redo_action([&](auto&) {
  182. redo();
  183. });
  184. m_functions_help_action = GUI::Action::create(
  185. "&Functions Help", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-help.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
  186. if (auto* worksheet_ptr = current_worksheet_if_available()) {
  187. auto docs = worksheet_ptr->gather_documentation();
  188. auto help_window = Spreadsheet::HelpWindow::the(window());
  189. help_window->set_docs(move(docs));
  190. help_window->show();
  191. } else {
  192. GUI::MessageBox::show_error(window(), "Cannot prepare documentation/help without an active worksheet");
  193. }
  194. },
  195. window());
  196. m_about_action = GUI::CommonActions::make_about_action("Spreadsheet", GUI::Icon::default_icon("app-spreadsheet"), window());
  197. toolbar.add_action(*m_new_action);
  198. toolbar.add_action(*m_open_action);
  199. toolbar.add_action(*m_save_action);
  200. toolbar.add_separator();
  201. toolbar.add_action(*m_cut_action);
  202. toolbar.add_action(*m_copy_action);
  203. toolbar.add_action(*m_paste_action);
  204. toolbar.add_action(*m_undo_action);
  205. toolbar.add_action(*m_redo_action);
  206. m_cut_action->set_enabled(false);
  207. m_copy_action->set_enabled(false);
  208. }
  209. void SpreadsheetWidget::resize_event(GUI::ResizeEvent& event)
  210. {
  211. GUI::Widget::resize_event(event);
  212. if (m_inline_documentation_window && m_cell_value_editor && window())
  213. m_inline_documentation_window->set_rect(m_cell_value_editor->screen_relative_rect().translated(0, m_cell_value_editor->height() + 7).inflated(6, 6));
  214. }
  215. void SpreadsheetWidget::setup_tabs(NonnullRefPtrVector<Sheet> new_sheets)
  216. {
  217. for (auto& sheet : new_sheets) {
  218. auto& new_view = m_tab_widget->add_tab<SpreadsheetView>(sheet.name(), sheet);
  219. new_view.model()->on_cell_data_change = [&](auto& cell, auto& previous_data) {
  220. undo_stack().push(make<CellUndoCommand>(cell, previous_data));
  221. window()->set_modified(true);
  222. };
  223. new_view.on_selection_changed = [&](Vector<Position>&& selection) {
  224. auto* sheet_ptr = m_selected_view->sheet_if_available();
  225. // How did this even happen?
  226. VERIFY(sheet_ptr);
  227. auto& sheet = *sheet_ptr;
  228. VERIFY(!selection.is_empty());
  229. m_cut_action->set_enabled(true);
  230. m_copy_action->set_enabled(true);
  231. m_current_cell_label->set_enabled(true);
  232. m_cell_value_editor->set_enabled(true);
  233. if (selection.size() == 1) {
  234. auto& position = selection.first();
  235. m_current_cell_label->set_text(position.to_cell_identifier(sheet));
  236. auto& cell = sheet.ensure(position);
  237. m_cell_value_editor->on_change = nullptr;
  238. m_cell_value_editor->set_text(cell.source());
  239. m_cell_value_editor->on_change = [&] {
  240. auto text = m_cell_value_editor->text();
  241. // FIXME: Lines?
  242. auto offset = m_cell_value_editor->cursor().column();
  243. try_generate_tip_for_input_expression(text, offset);
  244. cell.set_data(move(text));
  245. sheet.update();
  246. update();
  247. };
  248. static_cast<CellSyntaxHighlighter*>(const_cast<Syntax::Highlighter*>(m_cell_value_editor->syntax_highlighter()))->set_cell(&cell);
  249. return;
  250. }
  251. // There are many cells selected, change all of them.
  252. StringBuilder builder;
  253. builder.appendff("<{}>", selection.size());
  254. m_current_cell_label->set_text(builder.string_view());
  255. Vector<Cell&> cells;
  256. for (auto& position : selection)
  257. cells.append(sheet.ensure(position));
  258. auto& first_cell = cells.first();
  259. m_cell_value_editor->on_change = nullptr;
  260. m_cell_value_editor->set_text("");
  261. m_should_change_selected_cells = false;
  262. m_cell_value_editor->on_focusin = [this] { m_should_change_selected_cells = true; };
  263. m_cell_value_editor->on_focusout = [this] { m_should_change_selected_cells = false; };
  264. m_cell_value_editor->on_change = [cells = move(cells), this]() mutable {
  265. if (m_should_change_selected_cells) {
  266. auto* sheet_ptr = m_selected_view->sheet_if_available();
  267. if (!sheet_ptr)
  268. return;
  269. auto& sheet = *sheet_ptr;
  270. auto text = m_cell_value_editor->text();
  271. // FIXME: Lines?
  272. auto offset = m_cell_value_editor->cursor().column();
  273. try_generate_tip_for_input_expression(text, offset);
  274. for (auto& cell : cells)
  275. cell.set_data(text);
  276. sheet.update();
  277. update();
  278. }
  279. };
  280. static_cast<CellSyntaxHighlighter*>(const_cast<Syntax::Highlighter*>(m_cell_value_editor->syntax_highlighter()))->set_cell(&first_cell);
  281. };
  282. new_view.on_selection_dropped = [&]() {
  283. m_current_cell_label->set_enabled(false);
  284. m_current_cell_label->set_text({});
  285. m_cell_value_editor->on_change = nullptr;
  286. m_cell_value_editor->on_focusin = nullptr;
  287. m_cell_value_editor->on_focusout = nullptr;
  288. m_cell_value_editor->set_text({});
  289. m_cell_value_editor->set_enabled(false);
  290. m_cut_action->set_enabled(false);
  291. m_copy_action->set_enabled(false);
  292. static_cast<CellSyntaxHighlighter*>(const_cast<Syntax::Highlighter*>(m_cell_value_editor->syntax_highlighter()))->set_cell(nullptr);
  293. };
  294. }
  295. m_tab_widget->on_change = [this](auto& selected_widget) {
  296. m_selected_view = &static_cast<SpreadsheetView&>(selected_widget);
  297. };
  298. m_tab_widget->on_context_menu_request = [&](auto& widget, auto& event) {
  299. m_tab_context_menu_sheet_view = static_cast<SpreadsheetView&>(widget);
  300. m_tab_context_menu->popup(event.screen_position());
  301. };
  302. m_tab_widget->on_double_click = [&](auto& widget) {
  303. m_tab_context_menu_sheet_view = static_cast<SpreadsheetView&>(widget);
  304. VERIFY(m_tab_context_menu_sheet_view);
  305. auto* sheet_ptr = m_tab_context_menu_sheet_view->sheet_if_available();
  306. VERIFY(sheet_ptr); // How did we get here without a sheet?
  307. auto& sheet = *sheet_ptr;
  308. String new_name;
  309. if (GUI::InputBox::show(window(), new_name, String::formatted("New name for '{}'", sheet.name()), "Rename sheet") == GUI::Dialog::ExecOK) {
  310. sheet.set_name(new_name);
  311. sheet.update();
  312. m_tab_widget->set_tab_title(static_cast<GUI::Widget&>(*m_tab_context_menu_sheet_view), new_name);
  313. }
  314. };
  315. }
  316. void SpreadsheetWidget::try_generate_tip_for_input_expression(StringView source, size_t cursor_offset)
  317. {
  318. auto* sheet_ptr = m_selected_view->sheet_if_available();
  319. if (!sheet_ptr)
  320. return;
  321. auto& sheet = *sheet_ptr;
  322. m_inline_documentation_window->set_rect(m_cell_value_editor->screen_relative_rect().translated(0, m_cell_value_editor->height() + 7).inflated(6, 6));
  323. if (!m_selected_view || !source.starts_with('=')) {
  324. m_inline_documentation_window->hide();
  325. return;
  326. }
  327. auto maybe_function_and_argument = get_function_and_argument_index(source.substring_view(0, cursor_offset));
  328. if (!maybe_function_and_argument.has_value()) {
  329. m_inline_documentation_window->hide();
  330. return;
  331. }
  332. auto& [name, index] = maybe_function_and_argument.value();
  333. auto text = sheet.generate_inline_documentation_for(name, index);
  334. if (text.is_empty()) {
  335. m_inline_documentation_window->hide();
  336. } else {
  337. m_inline_documentation_label->set_text(move(text));
  338. m_inline_documentation_window->show();
  339. }
  340. }
  341. void SpreadsheetWidget::undo()
  342. {
  343. if (!m_undo_stack.can_undo())
  344. return;
  345. m_undo_stack.undo();
  346. update();
  347. }
  348. void SpreadsheetWidget::redo()
  349. {
  350. if (!m_undo_stack.can_redo())
  351. return;
  352. m_undo_stack.redo();
  353. update();
  354. }
  355. void SpreadsheetWidget::save(StringView filename)
  356. {
  357. auto result = m_workbook->save(filename);
  358. if (result.is_error()) {
  359. GUI::MessageBox::show_error(window(), result.error());
  360. return;
  361. }
  362. undo_stack().set_current_unmodified();
  363. window()->set_modified(false);
  364. }
  365. void SpreadsheetWidget::load_file(Core::File& file)
  366. {
  367. auto result = m_workbook->open_file(file);
  368. if (result.is_error()) {
  369. GUI::MessageBox::show_error(window(), result.error());
  370. return;
  371. }
  372. m_tab_widget->on_change = nullptr;
  373. m_cell_value_editor->on_change = nullptr;
  374. m_current_cell_label->set_text("");
  375. m_should_change_selected_cells = false;
  376. while (auto* widget = m_tab_widget->active_widget()) {
  377. m_tab_widget->remove_tab(*widget);
  378. }
  379. setup_tabs(m_workbook->sheets());
  380. update_window_title();
  381. }
  382. bool SpreadsheetWidget::request_close()
  383. {
  384. if (!undo_stack().is_current_modified())
  385. return true;
  386. auto result = GUI::MessageBox::ask_about_unsaved_changes(window(), current_filename());
  387. if (result == GUI::MessageBox::ExecYes) {
  388. if (current_filename().is_empty()) {
  389. String name = "workbook";
  390. Optional<String> save_path = GUI::FilePicker::get_save_filepath(window(), name, "sheets");
  391. if (!save_path.has_value())
  392. return false;
  393. save(save_path.value());
  394. update_window_title();
  395. } else {
  396. save(current_filename());
  397. }
  398. return true;
  399. }
  400. if (result == GUI::MessageBox::ExecNo)
  401. return true;
  402. return false;
  403. }
  404. void SpreadsheetWidget::add_sheet()
  405. {
  406. StringBuilder name;
  407. name.append("Sheet");
  408. name.appendff(" {}", m_workbook->sheets().size() + 1);
  409. NonnullRefPtrVector<Sheet> new_sheets;
  410. new_sheets.append(m_workbook->add_sheet(name.string_view()));
  411. setup_tabs(move(new_sheets));
  412. }
  413. void SpreadsheetWidget::add_sheet(NonnullRefPtr<Sheet>&& sheet)
  414. {
  415. VERIFY(m_workbook == &sheet->workbook());
  416. NonnullRefPtrVector<Sheet> new_sheets;
  417. new_sheets.append(move(sheet));
  418. m_workbook->sheets().extend(new_sheets);
  419. setup_tabs(new_sheets);
  420. }
  421. void SpreadsheetWidget::update_window_title()
  422. {
  423. StringBuilder builder;
  424. if (current_filename().is_empty())
  425. builder.append("Untitled");
  426. else
  427. builder.append(current_filename());
  428. builder.append("[*] - Spreadsheet");
  429. window()->set_title(builder.to_string());
  430. }
  431. void SpreadsheetWidget::clipboard_action(bool is_cut)
  432. {
  433. /// text/x-spreadsheet-data:
  434. /// - action: copy/cut
  435. /// - currently selected cell
  436. /// - selected cell+
  437. auto* worksheet_ptr = current_worksheet_if_available();
  438. if (!worksheet_ptr) {
  439. GUI::MessageBox::show_error(window(), "There are no active worksheets");
  440. return;
  441. }
  442. auto& worksheet = *worksheet_ptr;
  443. auto& cells = worksheet.selected_cells();
  444. VERIFY(!cells.is_empty());
  445. StringBuilder text_builder, url_builder;
  446. url_builder.append(is_cut ? "cut\n" : "copy\n");
  447. bool first = true;
  448. auto cursor = current_selection_cursor();
  449. if (cursor) {
  450. Spreadsheet::Position position { (size_t)cursor->column(), (size_t)cursor->row() };
  451. url_builder.append(position.to_url(worksheet).to_string());
  452. url_builder.append('\n');
  453. }
  454. for (auto& cell : cells) {
  455. if (first && !cursor) {
  456. url_builder.append(cell.to_url(worksheet).to_string());
  457. url_builder.append('\n');
  458. }
  459. url_builder.append(cell.to_url(worksheet).to_string());
  460. url_builder.append('\n');
  461. auto cell_data = worksheet.at(cell);
  462. if (!first)
  463. text_builder.append('\t');
  464. if (cell_data)
  465. text_builder.append(cell_data->data());
  466. first = false;
  467. }
  468. HashMap<String, String> metadata;
  469. metadata.set("text/x-spreadsheet-data", url_builder.to_string());
  470. dbgln(url_builder.to_string());
  471. GUI::Clipboard::the().set_data(text_builder.string_view().bytes(), "text/plain", move(metadata));
  472. }
  473. void SpreadsheetWidget::initialize_menubar(GUI::Window& window)
  474. {
  475. auto& file_menu = window.add_menu("&File");
  476. file_menu.add_action(*m_new_action);
  477. file_menu.add_action(*m_open_action);
  478. file_menu.add_action(*m_save_action);
  479. file_menu.add_action(*m_save_as_action);
  480. file_menu.add_separator();
  481. file_menu.add_action(*m_quit_action);
  482. auto& edit_menu = window.add_menu("&Edit");
  483. edit_menu.add_action(*m_undo_action);
  484. edit_menu.add_action(*m_redo_action);
  485. edit_menu.add_separator();
  486. edit_menu.add_action(*m_cut_action);
  487. edit_menu.add_action(*m_copy_action);
  488. edit_menu.add_action(*m_paste_action);
  489. auto& help_menu = window.add_menu("&Help");
  490. help_menu.add_action(*m_functions_help_action);
  491. help_menu.add_action(*m_about_action);
  492. }
  493. }