mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 11:48:13 +00:00
Spreadsheet: Use new format functions.
In a few places I also simplified a few format strings: -outln("{} item{}", items, items.size() == 1 ? ' ' : 's'); +outln("{} item(s)", items); In my opinion this is more readable and in some places it incorrectly wrote '0 item' which is "fixed" now. In other places the placeholder space looked weird.
This commit is contained in:
parent
30ca17e78f
commit
f005548d56
5 changed files with 18 additions and 19 deletions
|
@ -56,9 +56,9 @@ CellTypeDialog::CellTypeDialog(const Vector<Position>& positions, Sheet& sheet,
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
|
|
||||||
if (positions.size() == 1)
|
if (positions.size() == 1)
|
||||||
builder.appendf("Format Cell %s%zu", positions.first().column.characters(), positions.first().row);
|
builder.appendff("Format Cell {}{}", positions.first().column, positions.first().row);
|
||||||
else
|
else
|
||||||
builder.appendf("Format %zu Cells", positions.size());
|
builder.appendff("Format {} Cells", positions.size());
|
||||||
|
|
||||||
set_title(builder.string_view());
|
set_title(builder.string_view());
|
||||||
resize(285, 360);
|
resize(285, 360);
|
||||||
|
|
|
@ -132,21 +132,21 @@ String HelpWindow::render(const GUI::ModelIndex& index)
|
||||||
|
|
||||||
markdown_builder.append("# ARGUMENTS\n");
|
markdown_builder.append("# ARGUMENTS\n");
|
||||||
if (argc > 0)
|
if (argc > 0)
|
||||||
markdown_builder.appendf("%d required argument%s: \n", argc, argc > 1 ? "s" : "");
|
markdown_builder.appendff("{} required argument(s):\n", argc);
|
||||||
else
|
else
|
||||||
markdown_builder.appendf("No required arguments.\n");
|
markdown_builder.appendf("No required arguments.\n");
|
||||||
|
|
||||||
for (size_t i = 0; i < argc; ++i)
|
for (size_t i = 0; i < argc; ++i)
|
||||||
markdown_builder.appendf("- `%s`\n", argnames.at(i).to_string().characters());
|
markdown_builder.appendff("- `{}`\n", argnames.at(i).to_string());
|
||||||
|
|
||||||
if (argc > 0)
|
if (argc > 0)
|
||||||
markdown_builder.append("\n");
|
markdown_builder.append("\n");
|
||||||
|
|
||||||
if ((size_t)argnames.size() > argc) {
|
if ((size_t)argnames.size() > argc) {
|
||||||
auto opt_count = argnames.size() - argc;
|
auto opt_count = argnames.size() - argc;
|
||||||
markdown_builder.appendf("%d optional argument%s: \n", opt_count, opt_count > 1 ? "s" : "");
|
markdown_builder.appendff("{} optional argument(s):\n", opt_count);
|
||||||
for (size_t i = argc; i < (size_t)argnames.size(); ++i)
|
for (size_t i = argc; i < (size_t)argnames.size(); ++i)
|
||||||
markdown_builder.appendf("- `%s`\n", argnames.at(i).to_string().characters());
|
markdown_builder.appendff("- `{}`\n", argnames.at(i).to_string());
|
||||||
markdown_builder.append("\n");
|
markdown_builder.append("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ String HelpWindow::render(const GUI::ModelIndex& index)
|
||||||
if (!examples.is_empty()) {
|
if (!examples.is_empty()) {
|
||||||
markdown_builder.append("# EXAMPLES\n");
|
markdown_builder.append("# EXAMPLES\n");
|
||||||
examples.for_each_member([&](auto& text, auto& description_value) {
|
examples.for_each_member([&](auto& text, auto& description_value) {
|
||||||
markdown_builder.appendf("- %s\n\n```js\n%s\n```\n", description_value.to_string().characters(), text.characters());
|
markdown_builder.appendf("- {}\n\n```js\n{}\n```\n", description_value.to_string(), text);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,16 +64,15 @@ Sheet::Sheet(Workbook& workbook)
|
||||||
auto buffer = file_or_error.value()->read_all();
|
auto buffer = file_or_error.value()->read_all();
|
||||||
JS::Parser parser { JS::Lexer(buffer) };
|
JS::Parser parser { JS::Lexer(buffer) };
|
||||||
if (parser.has_errors()) {
|
if (parser.has_errors()) {
|
||||||
dbg() << "Spreadsheet: Failed to parse runtime code";
|
dbgln("Spreadsheet: Failed to parse runtime code");
|
||||||
for (auto& error : parser.errors())
|
for (auto& error : parser.errors())
|
||||||
dbg() << "Error: " << error.to_string() << "\n"
|
dbgln("Error: {}\n{}", error.to_string(), error.source_location_hint(buffer));
|
||||||
<< error.source_location_hint(buffer);
|
|
||||||
} else {
|
} else {
|
||||||
interpreter().run(global_object(), parser.parse_program());
|
interpreter().run(global_object(), parser.parse_program());
|
||||||
if (auto exc = interpreter().exception()) {
|
if (auto exc = interpreter().exception()) {
|
||||||
dbg() << "Spreadsheet: Failed to run runtime code: ";
|
dbgln("Spreadsheet: Failed to run runtime code: ");
|
||||||
for (auto& t : exc->trace())
|
for (auto& t : exc->trace())
|
||||||
dbg() << t;
|
dbgln("{}", t);
|
||||||
interpreter().vm().clear_exception();
|
interpreter().vm().clear_exception();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -331,7 +330,7 @@ JsonObject Sheet::to_json() const
|
||||||
for (auto& it : m_cells) {
|
for (auto& it : m_cells) {
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
builder.append(it.key.column);
|
builder.append(it.key.column);
|
||||||
builder.appendf("%zu", it.key.row);
|
builder.appendff("{}", it.key.row);
|
||||||
auto key = builder.to_string();
|
auto key = builder.to_string();
|
||||||
|
|
||||||
JsonObject data;
|
JsonObject data;
|
||||||
|
@ -399,7 +398,7 @@ JsonObject Sheet::gather_documentation() const
|
||||||
if (!value_object.has_own_property(doc_name))
|
if (!value_object.has_own_property(doc_name))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
dbg() << "Found '" << it.key.to_display_string() << "'";
|
dbgln("Found '{}'", it.key.to_display_string());
|
||||||
auto doc = value_object.get(doc_name);
|
auto doc = value_object.get(doc_name);
|
||||||
if (!doc.is_string())
|
if (!doc.is_string())
|
||||||
return;
|
return;
|
||||||
|
@ -410,7 +409,7 @@ JsonObject Sheet::gather_documentation() const
|
||||||
if (doc_object.has_value())
|
if (doc_object.has_value())
|
||||||
object.set(it.key.to_display_string(), doc_object.value());
|
object.set(it.key.to_display_string(), doc_object.value());
|
||||||
else
|
else
|
||||||
dbg() << "Sheet::gather_documentation(): Failed to parse the documentation for '" << it.key.to_display_string() << "'!";
|
dbgln("Sheet::gather_documentation(): Failed to parse the documentation for '{}'!", it.key.to_display_string());
|
||||||
};
|
};
|
||||||
|
|
||||||
for (auto& it : interpreter().global_object().shape().property_table())
|
for (auto& it : interpreter().global_object().shape().property_table())
|
||||||
|
|
|
@ -104,7 +104,7 @@ void SpreadsheetWidget::setup_tabs(NonnullRefPtrVector<Sheet> new_sheets)
|
||||||
auto& position = selection.first();
|
auto& position = selection.first();
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
builder.append(position.column);
|
builder.append(position.column);
|
||||||
builder.appendf("%zu", position.row);
|
builder.appendff("{}", position.row);
|
||||||
m_current_cell_label->set_enabled(true);
|
m_current_cell_label->set_enabled(true);
|
||||||
m_current_cell_label->set_text(builder.string_view());
|
m_current_cell_label->set_text(builder.string_view());
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ void SpreadsheetWidget::setup_tabs(NonnullRefPtrVector<Sheet> new_sheets)
|
||||||
|
|
||||||
// There are many cells selected, change all of them.
|
// There are many cells selected, change all of them.
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
builder.appendf("<%zu>", selection.size());
|
builder.appendff("<{}>", selection.size());
|
||||||
m_current_cell_label->set_enabled(true);
|
m_current_cell_label->set_enabled(true);
|
||||||
m_current_cell_label->set_text(builder.string_view());
|
m_current_cell_label->set_text(builder.string_view());
|
||||||
|
|
||||||
|
@ -184,7 +184,7 @@ void SpreadsheetWidget::add_sheet()
|
||||||
{
|
{
|
||||||
StringBuilder name;
|
StringBuilder name;
|
||||||
name.append("Sheet");
|
name.append("Sheet");
|
||||||
name.appendf(" %d", m_workbook->sheets().size() + 1);
|
name.appendff(" {}", m_workbook->sheets().size() + 1);
|
||||||
|
|
||||||
auto& sheet = m_workbook->add_sheet(name.string_view());
|
auto& sheet = m_workbook->add_sheet(name.string_view());
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
if (filename) {
|
if (filename) {
|
||||||
if (!Core::File::exists(filename) || Core::File::is_directory(filename)) {
|
if (!Core::File::exists(filename) || Core::File::is_directory(filename)) {
|
||||||
fprintf(stderr, "File does not exist or is a directory: %s\n", filename);
|
warnln("File does not exist or is a directory: {}", filename);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue