mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:27:35 +00:00
Spreadsheet: Show the opened filename in the window title
Prior to this commit, there was a set_filename() function that could set the window title, but actually it never did that. It was called only in one place -- by the 'Save as...' action, but it always failed to change anything, because there was a check that tried to reassign the same filename. :/ This patch: 1. removes that check, and therefore 2. renames the function to simply `update_window_title()`, 3. starts calling the function from more places (at startup and after loading a file), 4. changes the window title order (`{app_name} - {filename}` -> `{filename} - {app_name}`) to match the other applications style on the system. :^)
This commit is contained in:
parent
b59773de17
commit
dc65543fa9
3 changed files with 13 additions and 12 deletions
|
@ -140,6 +140,7 @@ SpreadsheetWidget::SpreadsheetWidget(GUI::Window& parent_window, NonnullRefPtrVe
|
||||||
return;
|
return;
|
||||||
|
|
||||||
save(save_path.value());
|
save(save_path.value());
|
||||||
|
update_window_title();
|
||||||
} else {
|
} else {
|
||||||
save(current_filename());
|
save(current_filename());
|
||||||
}
|
}
|
||||||
|
@ -152,9 +153,7 @@ SpreadsheetWidget::SpreadsheetWidget(GUI::Window& parent_window, NonnullRefPtrVe
|
||||||
return;
|
return;
|
||||||
|
|
||||||
save(save_path.value());
|
save(save_path.value());
|
||||||
|
update_window_title();
|
||||||
if (!current_filename().is_empty())
|
|
||||||
set_filename(current_filename());
|
|
||||||
});
|
});
|
||||||
|
|
||||||
m_quit_action = GUI::CommonActions::make_quit_action([&](auto&) {
|
m_quit_action = GUI::CommonActions::make_quit_action([&](auto&) {
|
||||||
|
@ -457,6 +456,7 @@ void SpreadsheetWidget::load_file(Core::File& file)
|
||||||
}
|
}
|
||||||
|
|
||||||
setup_tabs(m_workbook->sheets());
|
setup_tabs(m_workbook->sheets());
|
||||||
|
update_window_title();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SpreadsheetWidget::request_close()
|
bool SpreadsheetWidget::request_close()
|
||||||
|
@ -473,6 +473,7 @@ bool SpreadsheetWidget::request_close()
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
save(save_path.value());
|
save(save_path.value());
|
||||||
|
update_window_title();
|
||||||
} else {
|
} else {
|
||||||
save(current_filename());
|
save(current_filename());
|
||||||
}
|
}
|
||||||
|
@ -506,16 +507,16 @@ void SpreadsheetWidget::add_sheet(NonnullRefPtr<Sheet>&& sheet)
|
||||||
setup_tabs(new_sheets);
|
setup_tabs(new_sheets);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpreadsheetWidget::set_filename(const String& filename)
|
void SpreadsheetWidget::update_window_title()
|
||||||
{
|
{
|
||||||
if (m_workbook->set_filename(filename)) {
|
StringBuilder builder;
|
||||||
StringBuilder builder;
|
if (current_filename().is_empty())
|
||||||
builder.append("Spreadsheet - ");
|
builder.append("Untitled");
|
||||||
|
else
|
||||||
builder.append(current_filename());
|
builder.append(current_filename());
|
||||||
|
builder.append("[*] - Spreadsheet");
|
||||||
|
|
||||||
window()->set_title(builder.string_view());
|
window()->set_title(builder.to_string());
|
||||||
window()->update();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpreadsheetWidget::clipboard_action(bool is_cut)
|
void SpreadsheetWidget::clipboard_action(bool is_cut)
|
||||||
|
|
|
@ -27,7 +27,7 @@ public:
|
||||||
|
|
||||||
const String& current_filename() const { return m_workbook->current_filename(); }
|
const String& current_filename() const { return m_workbook->current_filename(); }
|
||||||
Sheet* current_worksheet_if_available() { return m_selected_view ? m_selected_view->sheet_if_available() : nullptr; }
|
Sheet* current_worksheet_if_available() { return m_selected_view ? m_selected_view->sheet_if_available() : nullptr; }
|
||||||
void set_filename(const String& filename);
|
void update_window_title();
|
||||||
|
|
||||||
Workbook& workbook() { return *m_workbook; }
|
Workbook& workbook() { return *m_workbook; }
|
||||||
const Workbook& workbook() const { return *m_workbook; }
|
const Workbook& workbook() const { return *m_workbook; }
|
||||||
|
|
|
@ -54,13 +54,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
|
|
||||||
auto app_icon = GUI::Icon::default_icon("app-spreadsheet");
|
auto app_icon = GUI::Icon::default_icon("app-spreadsheet");
|
||||||
auto window = GUI::Window::construct();
|
auto window = GUI::Window::construct();
|
||||||
window->set_title("Spreadsheet");
|
|
||||||
window->resize(640, 480);
|
window->resize(640, 480);
|
||||||
window->set_icon(app_icon.bitmap_for_size(16));
|
window->set_icon(app_icon.bitmap_for_size(16));
|
||||||
|
|
||||||
auto& spreadsheet_widget = window->set_main_widget<Spreadsheet::SpreadsheetWidget>(*window, NonnullRefPtrVector<Spreadsheet::Sheet> {}, filename == nullptr);
|
auto& spreadsheet_widget = window->set_main_widget<Spreadsheet::SpreadsheetWidget>(*window, NonnullRefPtrVector<Spreadsheet::Sheet> {}, filename == nullptr);
|
||||||
|
|
||||||
spreadsheet_widget.initialize_menubar(*window);
|
spreadsheet_widget.initialize_menubar(*window);
|
||||||
|
spreadsheet_widget.update_window_title();
|
||||||
|
|
||||||
window->on_close_request = [&]() -> GUI::Window::CloseRequestDecision {
|
window->on_close_request = [&]() -> GUI::Window::CloseRequestDecision {
|
||||||
if (spreadsheet_widget.request_close())
|
if (spreadsheet_widget.request_close())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue