summaryrefslogtreecommitdiff
path: root/Applications/Spreadsheet/SpreadsheetWidget.cpp
diff options
context:
space:
mode:
authorAnotherTest <ali.mpfard@gmail.com>2020-12-20 15:09:57 +0330
committerAndreas Kling <kling@serenityos.org>2020-12-22 23:35:29 +0100
commitb3a9a25416f4d3643c672b671e8038758f263bb9 (patch)
tree903dee6b7607958539c107ebd115e75c8ea415db /Applications/Spreadsheet/SpreadsheetWidget.cpp
parentf1f9fd1c60141e7ea5253c0c5bceb3adcfa23539 (diff)
downloadserenity-b3a9a25416f4d3643c672b671e8038758f263bb9.zip
Spreadsheet: Make it possible to rename sheets
Diffstat (limited to 'Applications/Spreadsheet/SpreadsheetWidget.cpp')
-rw-r--r--Applications/Spreadsheet/SpreadsheetWidget.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/Applications/Spreadsheet/SpreadsheetWidget.cpp b/Applications/Spreadsheet/SpreadsheetWidget.cpp
index a079a73266..5734b888f0 100644
--- a/Applications/Spreadsheet/SpreadsheetWidget.cpp
+++ b/Applications/Spreadsheet/SpreadsheetWidget.cpp
@@ -27,10 +27,12 @@
#include "SpreadsheetWidget.h"
#include "CellSyntaxHighlighter.h"
#include "HelpWindow.h"
+#include "LibGUI/InputBox.h"
#include <LibCore/File.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Button.h>
#include <LibGUI/Label.h>
+#include <LibGUI/Menu.h>
#include <LibGUI/MessageBox.h>
#include <LibGUI/Splitter.h>
#include <LibGUI/TabWidget.h>
@@ -81,6 +83,28 @@ SpreadsheetWidget::SpreadsheetWidget(NonnullRefPtrVector<Sheet>&& sheets, bool s
if (!m_workbook->has_sheets() && should_add_sheet_if_empty)
m_workbook->add_sheet("Sheet 1");
+ m_tab_context_menu = GUI::Menu::construct();
+ auto rename_action = GUI::Action::create("Rename...", [this](auto&) {
+ ASSERT(m_tab_context_menu_sheet_view);
+
+ auto& sheet = m_tab_context_menu_sheet_view->sheet();
+ String new_name;
+ if (GUI::InputBox::show(new_name, window(), String::formatted("New name for '{}'", sheet.name()), "Rename sheet") == GUI::Dialog::ExecOK) {
+ sheet.set_name(new_name);
+ sheet.update();
+ m_tab_widget->set_tab_title(static_cast<GUI::Widget&>(*m_tab_context_menu_sheet_view), new_name);
+ }
+ });
+ m_tab_context_menu->add_action(rename_action);
+ m_tab_context_menu->add_action(GUI::Action::create("Add new sheet...", [this](auto&) {
+ String name;
+ if (GUI::InputBox::show(name, window(), "Name for new sheet", "Create sheet") == GUI::Dialog::ExecOK) {
+ NonnullRefPtrVector<Sheet> new_sheets;
+ new_sheets.append(m_workbook->add_sheet(name));
+ setup_tabs(move(new_sheets));
+ }
+ }));
+
setup_tabs(m_workbook->sheets());
}
@@ -159,6 +183,11 @@ void SpreadsheetWidget::setup_tabs(NonnullRefPtrVector<Sheet> new_sheets)
m_tab_widget->on_change = [change = move(change)](auto& selected_widget) {
change(selected_widget);
};
+
+ m_tab_widget->on_context_menu_request = [&](auto& widget, auto& event) {
+ m_tab_context_menu_sheet_view = widget;
+ m_tab_context_menu->popup(event.screen_position());
+ };
}
void SpreadsheetWidget::save(const StringView& filename)