diff --git a/src/App.vala b/src/App.vala index d259133..1e14ea8 100644 --- a/src/App.vala +++ b/src/App.vala @@ -3,8 +3,6 @@ * SPDX-FileCopyrightText: 2017-2026 Spreadsheet Developers */ -using Spreadsheet.UI; - public class Spreadsheet.App : Gtk.Application { public static Settings settings { get; private set; } @@ -74,8 +72,8 @@ public class Spreadsheet.App : Gtk.Application { active_window.destroy (); } - private MainWindow new_window () { - var window = new MainWindow (this); + private UI.MainWindow new_window () { + var window = new UI.MainWindow (this); /* * Don't bind Settings to windows because state change in one window diff --git a/src/Models/Cell.vala b/src/Models/Cell.vala index 486092b..6bb0ae6 100644 --- a/src/Models/Cell.vala +++ b/src/Models/Cell.vala @@ -3,9 +3,6 @@ * SPDX-FileCopyrightText: 2017-2026 Spreadsheet Developers */ -using Spreadsheet.Services.Formula; -using Spreadsheet.Services.Parsing; - public class Spreadsheet.Models.Cell : Object { public weak Page page { get; set; } @@ -25,7 +22,9 @@ public class Spreadsheet.Models.Cell : Object { } try { - var parser = new FormulaParser (new Lexer (new FormulaGrammar ()).tokenize (value)); + var grammar = new Services.Formula.FormulaGrammar (); + var lexer = new Services.Parsing.Lexer (grammar); + var parser = new Services.Formula.FormulaParser (lexer.tokenize (value)); var expression = parser.parse (); var eval = expression.eval (page); @@ -34,7 +33,7 @@ public class Spreadsheet.Models.Cell : Object { } else if (eval.type () == typeof (string)) { display_content = (string)eval; } - } catch (ParserError err) { + } catch (Services.Parsing.ParserError err) { debug ("Error: " + err.message); display_content = "Error"; } diff --git a/src/Services/CSV/CSVGrammar.vala b/src/Services/CSV/CSVGrammar.vala index 092c030..0cb94b0 100644 --- a/src/Services/CSV/CSVGrammar.vala +++ b/src/Services/CSV/CSVGrammar.vala @@ -3,28 +3,26 @@ * SPDX-FileCopyrightText: 2017-2026 Spreadsheet Developers */ -using Spreadsheet.Services.Parsing; - -public class Spreadsheet.Services.CSV.CSVGrammar : Grammar { +public class Spreadsheet.Services.CSV.CSVGrammar : Parsing.Grammar { public CSVGrammar () { rules["root"] = root_rules (); rules["text"] = text_rules (); } - private Gee.ArrayList root_rules () { - return new Gee.ArrayList.wrap ({ - new Evaluator (/,/, token ("comma")), - new Evaluator (/\n/, token ("new-line")), - new Evaluator (re ("\""), token ("quote"), false, { "text" }), - new Evaluator (/./, token ("char")) + private Gee.ArrayList root_rules () { + return new Gee.ArrayList.wrap ({ + new Parsing.Evaluator (/,/, token ("comma")), + new Parsing.Evaluator (/\n/, token ("new-line")), + new Parsing.Evaluator (re ("\""), token ("quote"), false, { "text" }), + new Parsing.Evaluator (/./, token ("char")) }); } - private Gee.ArrayList text_rules () { - return new Gee.ArrayList.wrap ({ - new Evaluator (/""/, (m) => { return new Token ("char", "\""); }), - new Evaluator (re ("\""), token ("quote"), true), - new Evaluator (/./, token ("char")), + private Gee.ArrayList text_rules () { + return new Gee.ArrayList.wrap ({ + new Parsing.Evaluator (/""/, (m) => { return new Parsing.Token ("char", "\""); }), + new Parsing.Evaluator (re ("\""), token ("quote"), true), + new Parsing.Evaluator (/./, token ("char")), }); } } diff --git a/src/Services/CSV/CSVParser.vala b/src/Services/CSV/CSVParser.vala index e30f804..88b2c5e 100644 --- a/src/Services/CSV/CSVParser.vala +++ b/src/Services/CSV/CSVParser.vala @@ -3,9 +3,6 @@ * SPDX-FileCopyrightText: 2017-2026 Spreadsheet Developers */ -using Spreadsheet.Services.Parsing; -using Spreadsheet.Models; - public class Spreadsheet.Services.CSV.CSVParser : Parsing.Parser { private string path { get; set; } @@ -14,24 +11,24 @@ public class Spreadsheet.Services.CSV.CSVParser : Parsing.Parser { try { string content; FileUtils.get_contents (path, out content); - this (new Lexer (new CSVGrammar ()).tokenize (content)); + this (new Parsing.Lexer (new CSVGrammar ()).tokenize (content)); this.path = path; } catch (Error err) { critical (err.message); } } - public CSVParser (Gee.ArrayList tokens) { + public CSVParser (Gee.ArrayList tokens) { base (tokens); } - public Models.SpreadSheet parse (string page_name = "Sheet 1") throws ParserError { + public Models.SpreadSheet parse (string page_name = "Sheet 1") throws Parsing.ParserError { string basepath = Path.get_basename (path); var sheet = new Models.SpreadSheet () { title = basepath, file_path = path }; - var page = new Page () { + var page = new Models.Page () { title = page_name }; parse_sheet (page); @@ -39,13 +36,13 @@ public class Spreadsheet.Services.CSV.CSVParser : Parsing.Parser { return sheet; } - public Gee.ArrayList parse_sheet (Page page) throws ParserError { - var cells = new Gee.ArrayList (); + public Gee.ArrayList parse_sheet (Models.Page page) throws Parsing.ParserError { + var cells = new Gee.ArrayList (); int fields_count = 0; int line = 0; int col = 0; while (true) { - var cell = new Cell (); + var cell = new Models.Cell (); cell.line = line; cell.column = col; page.add_cell (cell); @@ -53,7 +50,7 @@ public class Spreadsheet.Services.CSV.CSVParser : Parsing.Parser { if (accept ("new-line")) { if (col != fields_count) { - throw new ParserError.UNEXPECTED (@"Unexpected number of fields on line $line"); + throw new Parsing.ParserError.UNEXPECTED (@"Unexpected number of fields on line $line"); } line++; col = 0; @@ -70,7 +67,7 @@ public class Spreadsheet.Services.CSV.CSVParser : Parsing.Parser { return cells; } - private string parse_text () throws ParserError { + private string parse_text () throws Parsing.ParserError { bool quoted = accept ("quote"); string res = ""; while (current.kind == "char") { diff --git a/src/Services/CSV/CSVWriter.vala b/src/Services/CSV/CSVWriter.vala index 9f1ae12..bfd29e1 100644 --- a/src/Services/CSV/CSVWriter.vala +++ b/src/Services/CSV/CSVWriter.vala @@ -3,12 +3,10 @@ * SPDX-FileCopyrightText: 2017-2026 Spreadsheet Developers */ -using Spreadsheet.Models; - public class Spreadsheet.Services.CSV.CSVWriter : Object { - public Page page { get; construct set; } + public Models.Page page { get; construct set; } - public CSVWriter (Page page) { + public CSVWriter (Models.Page page) { Object (page: page); } diff --git a/src/Services/Formula/AST/CallExpression.vala b/src/Services/Formula/AST/CallExpression.vala index 135990a..9a9700c 100644 --- a/src/Services/Formula/AST/CallExpression.vala +++ b/src/Services/Formula/AST/CallExpression.vala @@ -3,8 +3,6 @@ * SPDX-FileCopyrightText: 2017-2026 Spreadsheet Developers */ -using Spreadsheet.Models; - public class Spreadsheet.Services.Formula.AST.CallExpression : Expression { public string function { get; construct; } public Gee.ArrayList parameters { get; construct; } @@ -16,7 +14,7 @@ public class Spreadsheet.Services.Formula.AST.CallExpression : Expression { ); } - public override Value eval (Page sheet) { + public override Value eval (Models.Page sheet) { var params = new Value[] {}; foreach (var param in parameters) { params += param.eval (sheet); diff --git a/src/Services/Formula/AST/CellReference.vala b/src/Services/Formula/AST/CellReference.vala index 2871544..6bc9538 100644 --- a/src/Services/Formula/AST/CellReference.vala +++ b/src/Services/Formula/AST/CellReference.vala @@ -3,15 +3,13 @@ * SPDX-FileCopyrightText: 2017-2026 Spreadsheet Developers */ -using Spreadsheet.Models; - public class Spreadsheet.Services.Formula.AST.CellReference : Expression { public string cell_name { get; set; } public CellReference () { } - public override Value eval (Page sheet) { + public override Value eval (Models.Page sheet) { string letters = cell_name; letters.canon ("ABCDEFGHIJKLMNOPQRSTUVWXYZ", '?'); string _num = cell_name; diff --git a/src/Services/Formula/AST/Expression.vala b/src/Services/Formula/AST/Expression.vala index e14fc47..47f098a 100644 --- a/src/Services/Formula/AST/Expression.vala +++ b/src/Services/Formula/AST/Expression.vala @@ -3,8 +3,6 @@ * SPDX-FileCopyrightText: 2017-2026 Spreadsheet Developers */ -using Spreadsheet.Models; - public abstract class Spreadsheet.Services.Formula.AST.Expression : Object { - public abstract Value eval (Page sheet); + public abstract Value eval (Models.Page sheet); } diff --git a/src/Services/Formula/AST/NumberExpression.vala b/src/Services/Formula/AST/NumberExpression.vala index d8a17ce..e8438fe 100644 --- a/src/Services/Formula/AST/NumberExpression.vala +++ b/src/Services/Formula/AST/NumberExpression.vala @@ -3,8 +3,6 @@ * SPDX-FileCopyrightText: 2017-2026 Spreadsheet Developers */ -using Spreadsheet.Models; - public class Spreadsheet.Services.Formula.AST.NumberExpression : Expression { public double number { get; construct; } @@ -14,7 +12,7 @@ public class Spreadsheet.Services.Formula.AST.NumberExpression : Expression { ); } - public override Value eval (Page sheet) { + public override Value eval (Models.Page sheet) { return number; } } diff --git a/src/Services/Formula/AST/TextExpression.vala b/src/Services/Formula/AST/TextExpression.vala index 17b9da4..7af89bf 100644 --- a/src/Services/Formula/AST/TextExpression.vala +++ b/src/Services/Formula/AST/TextExpression.vala @@ -3,8 +3,6 @@ * SPDX-FileCopyrightText: 2017-2026 Spreadsheet Developers */ -using Spreadsheet.Models; - public class Spreadsheet.Services.Formula.AST.TextExpression : Expression { public string text { get; construct; } @@ -14,7 +12,7 @@ public class Spreadsheet.Services.Formula.AST.TextExpression : Expression { ); } - public override Value eval (Page sheet) { + public override Value eval (Models.Page sheet) { return text; } } diff --git a/src/Services/Formula/FormulaGrammar.vala b/src/Services/Formula/FormulaGrammar.vala index 4eaff8b..1832d8d 100644 --- a/src/Services/Formula/FormulaGrammar.vala +++ b/src/Services/Formula/FormulaGrammar.vala @@ -3,9 +3,7 @@ * SPDX-FileCopyrightText: 2017-2026 Spreadsheet Developers */ -using Spreadsheet.Services.Parsing; - -public class Spreadsheet.Services.Formula.FormulaGrammar : Grammar { +public class Spreadsheet.Services.Formula.FormulaGrammar : Parsing.Grammar { private string func_name_regex = ""; public FormulaGrammar () { @@ -26,24 +24,24 @@ public class Spreadsheet.Services.Formula.FormulaGrammar : Grammar { return func_name_regex; } - private Gee.ArrayList root_rules () { - return new Gee.ArrayList.wrap ({ - new Evaluator (/[ \t]/, token ("[[ignore]]")), - new Evaluator (/[A-Z]+[0-9]+/, token ("cell-name")), - new Evaluator (/=/, token ("equal")), - new Evaluator (get_func_name_regex (), token ("identifier")), - new Evaluator (/\(/, token ("left-parenthese")), // vala-lint=space-before-paren - new Evaluator (/\)/, token ("right-parenthese")), - new Evaluator (/,/, token ("comma")), - new Evaluator (/:/, token ("colon")), - new Evaluator (/\d+(\.\d+)?/, token ("number")), // vala-lint=space-before-paren - new Evaluator (/\+/, token ("plus")), - new Evaluator (/\*/, token ("star")), - new Evaluator (/-/, token ("dash")), - new Evaluator (/\//, token ("slash")), - new Evaluator (/%/, token ("percent")), - new Evaluator (/\^/, token ("carat")), - new Evaluator (/\D+/, token ("text")) + private Gee.ArrayList root_rules () { + return new Gee.ArrayList.wrap ({ + new Parsing.Evaluator (/[ \t]/, token ("[[ignore]]")), + new Parsing.Evaluator (/[A-Z]+[0-9]+/, token ("cell-name")), + new Parsing.Evaluator (/=/, token ("equal")), + new Parsing.Evaluator (get_func_name_regex (), token ("identifier")), + new Parsing.Evaluator (/\(/, token ("left-parenthese")), // vala-lint=space-before-paren + new Parsing.Evaluator (/\)/, token ("right-parenthese")), + new Parsing.Evaluator (/,/, token ("comma")), + new Parsing.Evaluator (/:/, token ("colon")), + new Parsing.Evaluator (/\d+(\.\d+)?/, token ("number")), // vala-lint=space-before-paren + new Parsing.Evaluator (/\+/, token ("plus")), + new Parsing.Evaluator (/\*/, token ("star")), + new Parsing.Evaluator (/-/, token ("dash")), + new Parsing.Evaluator (/\//, token ("slash")), + new Parsing.Evaluator (/%/, token ("percent")), + new Parsing.Evaluator (/\^/, token ("carat")), + new Parsing.Evaluator (/\D+/, token ("text")) }); } } diff --git a/src/Services/Formula/FormulaParser.vala b/src/Services/Formula/FormulaParser.vala index 9dc22df..11e0e40 100644 --- a/src/Services/Formula/FormulaParser.vala +++ b/src/Services/Formula/FormulaParser.vala @@ -3,23 +3,20 @@ * SPDX-FileCopyrightText: 2017-2026 Spreadsheet Developers */ -using Spreadsheet.Services.Formula.AST; -using Spreadsheet.Services.Parsing; - public class Spreadsheet.Services.Formula.FormulaParser : Parsing.Parser { - public FormulaParser (Gee.ArrayList tokens) { + public FormulaParser (Gee.ArrayList tokens) { base (tokens); } - public Expression parse () throws ParserError { + public AST.Expression parse () throws Parsing.ParserError { return parse_block (); } - private Expression parse_block () throws ParserError { + private AST.Expression parse_block () throws Parsing.ParserError { bool root = !accept ("left-square-brace"); var delimiter = root ? "eof" : "right-square-brace"; - Expression last; + AST.Expression last; while (true) { last = parse_expression (); @@ -32,11 +29,11 @@ public class Spreadsheet.Services.Formula.FormulaParser : Parsing.Parser { return last; } - private Expression parse_expression () throws ParserError { + private AST.Expression parse_expression () throws Parsing.ParserError { return parse_substraction (); } - private Expression parse_primary_expression () throws ParserError { + private AST.Expression parse_primary_expression () throws Parsing.ParserError { if (current.kind == "equal") { accept ("equal"); @@ -59,7 +56,7 @@ public class Spreadsheet.Services.Formula.FormulaParser : Parsing.Parser { } unexpected (); - return new NumberExpression (0.0); + return new AST.NumberExpression (0.0); } if (current.kind == "number") { @@ -85,78 +82,78 @@ public class Spreadsheet.Services.Formula.FormulaParser : Parsing.Parser { return parse_text (); } - private Expression parse_exponent () throws ParserError { + private AST.Expression parse_exponent () throws Parsing.ParserError { var left = parse_primary_expression (); while (accept ("carat")) { var right = parse_primary_expression (); - left = new CallExpression ("pow", new Gee.ArrayList.wrap ({ left, right })); + left = new AST.CallExpression ("pow", new Gee.ArrayList.wrap ({ left, right })); } return left; } - private Expression parse_multiplication () throws ParserError { + private AST.Expression parse_multiplication () throws Parsing.ParserError { var left = parse_exponent (); while (accept ("star")) { var right = parse_exponent (); - left = new CallExpression ("mul", new Gee.ArrayList.wrap ({ left, right })); + left = new AST.CallExpression ("mul", new Gee.ArrayList.wrap ({ left, right })); } return left; } - private Expression parse_division () throws ParserError { + private AST.Expression parse_division () throws Parsing.ParserError { var left = parse_multiplication (); while (accept ("slash")) { var right = parse_multiplication (); - left = new CallExpression ("div", new Gee.ArrayList.wrap ({ left, right })); + left = new AST.CallExpression ("div", new Gee.ArrayList.wrap ({ left, right })); } return left; } - private Expression parse_modulo () throws ParserError { - Expression left = parse_division (); + private AST.Expression parse_modulo () throws Parsing.ParserError { + AST.Expression left = parse_division (); while (accept ("percent")) { var right = parse_division (); - left = new CallExpression ("mod", new Gee.ArrayList.wrap ({ left, right })); + left = new AST.CallExpression ("mod", new Gee.ArrayList.wrap ({ left, right })); } return left; } - private Expression parse_substraction () throws ParserError { + private AST.Expression parse_substraction () throws Parsing.ParserError { var left = parse_addition (); while (accept ("dash")) { var right = parse_addition (); - left = new CallExpression ("sub", new Gee.ArrayList.wrap ({ left, right })); + left = new AST.CallExpression ("sub", new Gee.ArrayList.wrap ({ left, right })); } return left; } - private Expression parse_addition () throws ParserError { + private AST.Expression parse_addition () throws Parsing.ParserError { var left = parse_modulo (); while (accept ("plus")) { var right = parse_modulo (); - left = new CallExpression ("sum", new Gee.ArrayList.wrap ({ left, right })); + left = new AST.CallExpression ("sum", new Gee.ArrayList.wrap ({ left, right })); } return left; } - private CallExpression parse_call_expression () throws ParserError { + private AST.CallExpression parse_call_expression () throws Parsing.ParserError { var func = current.lexeme; expect ("identifier"); expect ("left-parenthese"); - var params = new Gee.ArrayList (); + var params = new Gee.ArrayList (); while (true) { params.add (parse_expression ()); @@ -165,28 +162,28 @@ public class Spreadsheet.Services.Formula.FormulaParser : Parsing.Parser { } if (!accept ("comma")) { - throw new ParserError.UNEXPECTED ("Use a comma to separate parameters"); + throw new Parsing.ParserError.UNEXPECTED ("Use a comma to separate parameters"); } } - return new CallExpression (func, params); + return new AST.CallExpression (func, params); } - private NumberExpression parse_number () throws ParserError { + private AST.NumberExpression parse_number () throws Parsing.ParserError { want ("number"); - NumberExpression res; + AST.NumberExpression res; if ("." in current.lexeme) { - res = new NumberExpression (double.parse (current.lexeme)); + res = new AST.NumberExpression (double.parse (current.lexeme)); } else { - res = new NumberExpression (double.parse (current.lexeme + ".0")); + res = new AST.NumberExpression (double.parse (current.lexeme + ".0")); } eat (); return res; } - private TextExpression parse_text () throws ParserError { + private AST.TextExpression parse_text () throws Parsing.ParserError { string val = ""; while (current.kind != "eof") { @@ -194,11 +191,11 @@ public class Spreadsheet.Services.Formula.FormulaParser : Parsing.Parser { eat (); } - return new TextExpression (val); + return new AST.TextExpression (val); } - private CellReference parse_cell_name () throws ParserError { - var cell = new CellReference () { cell_name = current.lexeme }; + private AST.CellReference parse_cell_name () throws Parsing.ParserError { + var cell = new AST.CellReference () { cell_name = current.lexeme }; expect ("cell-name"); return cell; } diff --git a/src/Services/FunctionManager.vala b/src/Services/FunctionManager.vala index b5ccf19..00ec8db 100644 --- a/src/Services/FunctionManager.vala +++ b/src/Services/FunctionManager.vala @@ -3,10 +3,8 @@ * SPDX-FileCopyrightText: 2017-2026 Spreadsheet Developers */ -using Spreadsheet.Models; - public class Spreadsheet.Services.FunctionManager : Object { - public Gee.ArrayList functions { get; private set; } + public Gee.ArrayList functions { get; private set; } public Gtk.FilterListModel filter_model { get; private set; } public static unowned FunctionManager get_default () { @@ -24,31 +22,31 @@ public class Spreadsheet.Services.FunctionManager : Object { } construct { - functions = new Gee.ArrayList (); - - functions.add (new Function ("sum", Functions.sum, _("Add numbers"))); - functions.add (new Function ("mul", Functions.mul, _("Multiply numbers"))); - functions.add (new Function ("div", Functions.div, _("Divide numbers"))); - functions.add (new Function ("sub", Functions.sub, _("Subtract numbers"))); - functions.add (new Function ("mod", Functions.mod, _("Gives the modulo of numbers"))); - - functions.add (new Function ("pow", Functions.pow, _("Elevate a number to the power of a second one"))); - functions.add (new Function ("sqrt", Functions.sqrt, _("The square root of a number"))); - functions.add (new Function ("round", Functions.round, _("Rounds a number to the nearest integer"))); - functions.add (new Function ("floor", Functions.floor, _("Removes the decimal part of a number"))); - functions.add (new Function ("min", Functions.min, _("Return the smallest value"))); - functions.add (new Function ("max", Functions.max, _("Return the biggest value"))); - functions.add (new Function ("mean", Functions.mean, _("Gives the mean of a list of numbers"))); - - functions.add (new Function ("cos", Functions.cos, _("Gives the cosine of a number (in radians)"))); - functions.add (new Function ("sin", Functions.sin, _("Gives the sine of an angle (in radians)"))); - functions.add (new Function ("tan", Functions.tan, _("Gives the tangent of a number (in radians)"))); - functions.add (new Function ("arccos", Functions.arccos, _("Gives the arc cosine of a number"))); - functions.add (new Function ("arcsin", Functions.arcsin, _("Gives the arc sine of a number"))); - functions.add (new Function ("arctan", Functions.arctan, _("Gives the arc tangent of a number"))); - - var func_name_exp = new Gtk.PropertyExpression (typeof (Function), null, "name"); - var func_doc_exp = new Gtk.PropertyExpression (typeof (Function), null, "doc"); + functions = new Gee.ArrayList (); + + functions.add (new Models.Function ("sum", Functions.sum, _("Add numbers"))); + functions.add (new Models.Function ("mul", Functions.mul, _("Multiply numbers"))); + functions.add (new Models.Function ("div", Functions.div, _("Divide numbers"))); + functions.add (new Models.Function ("sub", Functions.sub, _("Subtract numbers"))); + functions.add (new Models.Function ("mod", Functions.mod, _("Gives the modulo of numbers"))); + + functions.add (new Models.Function ("pow", Functions.pow, _("Elevate a number to the power of a second one"))); + functions.add (new Models.Function ("sqrt", Functions.sqrt, _("The square root of a number"))); + functions.add (new Models.Function ("round", Functions.round, _("Rounds a number to the nearest integer"))); + functions.add (new Models.Function ("floor", Functions.floor, _("Removes the decimal part of a number"))); + functions.add (new Models.Function ("min", Functions.min, _("Return the smallest value"))); + functions.add (new Models.Function ("max", Functions.max, _("Return the biggest value"))); + functions.add (new Models.Function ("mean", Functions.mean, _("Gives the mean of a list of numbers"))); + + functions.add (new Models.Function ("cos", Functions.cos, _("Gives the cosine of a number (in radians)"))); + functions.add (new Models.Function ("sin", Functions.sin, _("Gives the sine of an angle (in radians)"))); + functions.add (new Models.Function ("tan", Functions.tan, _("Gives the tangent of a number (in radians)"))); + functions.add (new Models.Function ("arccos", Functions.arccos, _("Gives the arc cosine of a number"))); + functions.add (new Models.Function ("arcsin", Functions.arcsin, _("Gives the arc sine of a number"))); + functions.add (new Models.Function ("arctan", Functions.arctan, _("Gives the arc tangent of a number"))); + + var func_name_exp = new Gtk.PropertyExpression (typeof (Models.Function), null, "name"); + var func_doc_exp = new Gtk.PropertyExpression (typeof (Models.Function), null, "doc"); var func_exp = new Gtk.CClosureExpression ( typeof (string), null, @@ -61,7 +59,7 @@ public class Spreadsheet.Services.FunctionManager : Object { match_mode = Gtk.StringFilterMatchMode.SUBSTRING }; - var func_liststore = new ListStore (typeof (Function)); + var func_liststore = new ListStore (typeof (Models.Function)); foreach (var func in functions) { func_liststore.append (func); } @@ -73,7 +71,7 @@ public class Spreadsheet.Services.FunctionManager : Object { func_filter.search = term; } - private static string create_func_searchterm (Function func) { + private static string create_func_searchterm (Models.Function func) { return "%s %s".printf (func.name, func.doc); } } diff --git a/src/Services/HistoryManager.vala b/src/Services/HistoryManager.vala index bedd17d..d40cf14 100644 --- a/src/Services/HistoryManager.vala +++ b/src/Services/HistoryManager.vala @@ -3,14 +3,12 @@ * SPDX-FileCopyrightText: 2017-2026 Spreadsheet Developers */ -using Spreadsheet.Models; - public class Spreadsheet.Services.HistoryManager : Object { private const int HISTORY_LIMIT = 20; // TODO: make it configurable? - public Queue undo_history = new Queue (); - public Queue redo_history = new Queue (); + public Queue undo_history = new Queue (); + public Queue redo_history = new Queue (); public bool can_undo () { return !undo_history.is_empty (); @@ -20,7 +18,7 @@ public class Spreadsheet.Services.HistoryManager : Object { return !redo_history.is_empty (); } - public void do_action (HistoryAction act) { + public void do_action (Models.HistoryAction act) { redo_history.clear (); undo_history.push_head (act); diff --git a/src/Services/RecentsManager.vala b/src/Services/RecentsManager.vala index 7df9fcc..f615a6e 100644 --- a/src/Services/RecentsManager.vala +++ b/src/Services/RecentsManager.vala @@ -3,8 +3,6 @@ * SPDX-FileCopyrightText: 2017-2026 Spreadsheet Developers */ -using Spreadsheet.Models; - /** * Remembers recently opened files. */ @@ -26,7 +24,7 @@ public class Spreadsheet.Services.RecentsManager : Object { } construct { - recents_liststore = new ListStore (typeof (RecentItem)); + recents_liststore = new ListStore (typeof (Models.RecentItem)); load (); sync (); } @@ -47,7 +45,7 @@ public class Spreadsheet.Services.RecentsManager : Object { uint recents_num = uint.min (recents_liststore.n_items, RECENTS_NUM_MAX); for (uint i = 0; i < recents_num; i++) { - var obj = ((RecentItem) recents_liststore.get_item (i)); + var obj = ((Models.RecentItem) recents_liststore.get_item (i)); new_recents.append_val (obj.path); } @@ -66,13 +64,13 @@ public class Spreadsheet.Services.RecentsManager : Object { return false; } - var recent_item = new RecentItem (path); + var recent_item = new Models.RecentItem (path); uint pos; bool dup_exists = recents_liststore.find_with_equal_func ( recent_item, ((a, b) => { - return ((RecentItem) a).path == ((RecentItem) b).path; + return ((Models.RecentItem) a).path == ((Models.RecentItem) b).path; }), out pos ); diff --git a/src/UI/MainWindow.vala b/src/UI/MainWindow.vala index 6c46c90..6e7043f 100644 --- a/src/UI/MainWindow.vala +++ b/src/UI/MainWindow.vala @@ -3,16 +3,10 @@ * SPDX-FileCopyrightText: 2017-2026 Spreadsheet Developers */ -using Spreadsheet.Widgets; -using Spreadsheet.Models; -using Spreadsheet.Services; -using Spreadsheet.Services.CSV; -using Spreadsheet.Services.Parsing; - public class Spreadsheet.UI.MainWindow : Gtk.ApplicationWindow { public App app { get; construct; } - public HistoryManager history_manager { get; private set; default = new HistoryManager (); } - private RecentsManager recents_manager; + public Services.HistoryManager history_manager { get; private set; default = new Services.HistoryManager (); } + private Services.RecentsManager recents_manager; private Gtk.HeaderBar header; private Adw.WindowTitle window_title; @@ -34,16 +28,16 @@ public class Spreadsheet.UI.MainWindow : Gtk.ApplicationWindow { private Adw.TabView tab_view; - public Sheet active_sheet { + public Widgets.Sheet active_sheet { get { Gtk.ScrolledWindow scroll = (Gtk.ScrolledWindow)tab_view.selected_page.child; Gtk.Viewport vp = (Gtk.Viewport)scroll.get_child (); - return (Sheet)vp.get_child (); + return (Widgets.Sheet)vp.get_child (); } } - private SpreadSheet _file; - public SpreadSheet file { + private Models.SpreadSheet _file; + public Models.SpreadSheet file { get { return _file; } @@ -62,12 +56,12 @@ public class Spreadsheet.UI.MainWindow : Gtk.ApplicationWindow { tab_view.close_page (tab_view.get_nth_page (0)); } - Sheet? last_sheet = null; + Widgets.Sheet? last_sheet = null; foreach (var page in value.pages) { - var sheet = new Sheet (page); + var sheet = new Widgets.Sheet (page); foreach (var cell in page.cells) { if (cell.selected) { - style_popup.child = new StyleModal (cell.font_style, cell.cell_style); + style_popup.child = new Widgets.StyleModal (cell.font_style, cell.cell_style); break; } } @@ -90,7 +84,7 @@ public class Spreadsheet.UI.MainWindow : Gtk.ApplicationWindow { func_button.sensitive = true; formula_entry.sensitive = true; style_button.sensitive = true; - style_popup.child = new StyleModal (cell.font_style, cell.cell_style); + style_popup.child = new Widgets.StyleModal (cell.font_style, cell.cell_style); } else { formula_entry.text = ""; func_button.sensitive = false; @@ -174,7 +168,7 @@ public class Spreadsheet.UI.MainWindow : Gtk.ApplicationWindow { cssprovider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); - recents_manager = RecentsManager.get_default (); + recents_manager = Services.RecentsManager.get_default (); welcome_view = new WelcomeView (); edit_view = sheet (); @@ -219,7 +213,7 @@ public class Spreadsheet.UI.MainWindow : Gtk.ApplicationWindow { placeholder_text = _("Search functions") }; - unowned var func_manager = FunctionManager.get_default (); + unowned var func_manager = Services.FunctionManager.get_default (); var func_selection_model = new Gtk.NoSelection (func_manager.filter_model); @@ -273,7 +267,7 @@ public class Spreadsheet.UI.MainWindow : Gtk.ApplicationWindow { var font_name_label = new Gtk.Label ("Open Sans 14"); Gdk.RGBA font_color = { 0.0f, 0.0f, 0.0f, 1.0f }; - var font_color_square = new RoundedSquare (font_color, 18, 18, 2) { + var font_color_square = new Widgets.RoundedSquare (font_color, 18, 18, 2) { halign = Gtk.Align.END }; @@ -303,7 +297,7 @@ public class Spreadsheet.UI.MainWindow : Gtk.ApplicationWindow { }); func_listview.activate.connect ((pos) => { - var func = func_manager.filter_model.get_item (pos) as Function; + var func = func_manager.filter_model.get_item (pos) as Models.Function; formula_entry.text += ")"; formula_entry.buffer.insert_text (formula_entry.get_position (), (func.name + "(").data); @@ -411,7 +405,7 @@ public class Spreadsheet.UI.MainWindow : Gtk.ApplicationWindow { active_sheet.grab_focus (); // Reset undecided changes - Cell? selected_cell = active_sheet.selected_cell; + Models.Cell? selected_cell = active_sheet.selected_cell; if (selected_cell == null) { formula_entry.text = ""; return; @@ -437,11 +431,11 @@ public class Spreadsheet.UI.MainWindow : Gtk.ApplicationWindow { used_filename = FileUtils.test (path, FileTest.EXISTS); } - var page = new Page.empty () { + var page = new Models.Page.empty () { title = _("Sheet 1") }; - var file = new SpreadSheet () { + var file = new Models.SpreadSheet () { title = filename, file_path = path }; @@ -481,11 +475,11 @@ public class Spreadsheet.UI.MainWindow : Gtk.ApplicationWindow { } public bool open_sheet (string path) { - SpreadSheet file; + Models.SpreadSheet file; try { - file = new CSVParser.from_file (path).parse (); - } catch (ParserError err) { + file = new Services.CSV.CSVParser.from_file (path).parse (); + } catch (Services.Parsing.ParserError err) { warning ("Failed to parse CSV file. path=%s: %s", path, err.message); var error_dialog = new Granite.MessageDialog.with_image_from_icon_name ( @@ -513,7 +507,7 @@ public class Spreadsheet.UI.MainWindow : Gtk.ApplicationWindow { // Triggered when an opened sheet is modified public void save_sheet () { - new CSVWriter (active_sheet.page).write_to_file (file.file_path); + new Services.CSV.CSVWriter (active_sheet.page).write_to_file (file.file_path); recents_manager.prepend (file.file_path); } @@ -545,13 +539,13 @@ public class Spreadsheet.UI.MainWindow : Gtk.ApplicationWindow { path += Util.FILE_SUFFIX; } - new CSVWriter (active_sheet.page).write_to_file (path); + new Services.CSV.CSVWriter (active_sheet.page).write_to_file (path); recents_manager.prepend (path); // Open the saved file try { - this.file = new CSVParser.from_file (path).parse (); - } catch (ParserError err) { + this.file = new Services.CSV.CSVParser.from_file (path).parse (); + } catch (Services.Parsing.ParserError err) { debug ("Error: " + err.message); return; } @@ -579,15 +573,15 @@ public class Spreadsheet.UI.MainWindow : Gtk.ApplicationWindow { private static void func_item_setup (Object obj) { var list_item = obj as Gtk.ListItem; - var row = new FunctionListRow (); + var row = new Widgets.FunctionListRow (); list_item.child = row; } private static void func_item_bind (Object obj) { var list_item = obj as Gtk.ListItem; - var func = list_item.item as Function; - var row = list_item.child as FunctionListRow; + var func = list_item.item as Models.Function; + var row = list_item.child as Widgets.FunctionListRow; row.name_text = func.name; row.doc_text = func.doc; @@ -595,22 +589,22 @@ public class Spreadsheet.UI.MainWindow : Gtk.ApplicationWindow { private void update_formula () { if (active_sheet.selected_cell != null) { - history_manager.do_action (new HistoryAction ( + history_manager.do_action (new Models.HistoryAction ( @"Change the formula to $(formula_entry.text)", active_sheet.selected_cell, (_text, _target) => { string text = _text == null ? formula_entry.text : (string)_text; - Cell target = (Cell)_target; + Models.Cell target = (Models.Cell)_target; string last_text = target.formula; target.formula = text; var undo_data = last_text; - return new StateChange (undo_data, text); + return new Models.StateChange (undo_data, text); }, (_text, _target) => { string text = (string)_text; - Cell target = (Cell)_target; + Models.Cell target = (Models.Cell)_target; target.formula = text; formula_entry.text = text; @@ -624,19 +618,19 @@ public class Spreadsheet.UI.MainWindow : Gtk.ApplicationWindow { private void clear_formula () { if (active_sheet.selected_cell != null) { - history_manager.do_action (new HistoryAction ( + history_manager.do_action (new Models.HistoryAction ( "Clear the formula", active_sheet.selected_cell, (_text, _target) => { - Cell target = (Cell)_target; + Models.Cell target = (Models.Cell)_target; string undo_data = target.formula; target.formula = ""; formula_entry.text = ""; - return new StateChange (undo_data, ""); + return new Models.StateChange (undo_data, ""); }, (_text, _target) => { string text = (string)_text; - Cell target = (Cell)_target; + Models.Cell target = (Models.Cell)_target; target.formula = text; formula_entry.text = text; diff --git a/src/UI/WelcomeView.vala b/src/UI/WelcomeView.vala index e1c297f..f749ce9 100644 --- a/src/UI/WelcomeView.vala +++ b/src/UI/WelcomeView.vala @@ -3,10 +3,6 @@ * SPDX-FileCopyrightText: 2017-2026 Spreadsheet Developers */ -using Spreadsheet.Models; -using Spreadsheet.Services; -using Spreadsheet.Widgets; - public class Spreadsheet.UI.WelcomeView : Gtk.Box { public signal void new_activated (); public signal void open_choose_activated (); @@ -44,7 +40,7 @@ public class Spreadsheet.UI.WelcomeView : Gtk.Box { }; recent_title.add_css_class (Granite.STYLE_CLASS_H2_LABEL); - var recents_manager = RecentsManager.get_default (); + var recents_manager = Services.RecentsManager.get_default (); var recents_selection_model = new Gtk.NoSelection (recents_manager.recents_liststore); @@ -92,7 +88,7 @@ public class Spreadsheet.UI.WelcomeView : Gtk.Box { }); recents_list.activate.connect ((pos) => { - var recent_item = recents_manager.recents_liststore.get_item (pos) as RecentItem; + var recent_item = recents_manager.recents_liststore.get_item (pos) as Models.RecentItem; open_activated (recent_item.path); }); @@ -104,14 +100,14 @@ public class Spreadsheet.UI.WelcomeView : Gtk.Box { private void recents_setup (Object obj) { var list_item = obj as Gtk.ListItem; - var row = new RecentListRow (); + var row = new Widgets.RecentListRow (); list_item.child = row; } private void recents_bind (Object obj) { var list_item = obj as Gtk.ListItem; - var recent_item = list_item.item as RecentItem; + var recent_item = list_item.item as Models.RecentItem; var path = recent_item.path; string basename = Path.get_basename (path); @@ -120,7 +116,7 @@ public class Spreadsheet.UI.WelcomeView : Gtk.Box { display_path = path.replace (Environment.get_home_dir (), "~"); } - var row = list_item.child as RecentListRow; + var row = list_item.child as Widgets.RecentListRow; row.icon_name = "x-office-spreadsheet"; row.filename = basename; row.path = display_path; diff --git a/src/Widgets/ActionBar.vala b/src/Widgets/ActionBar.vala index 3f6f2e7..345aceb 100644 --- a/src/Widgets/ActionBar.vala +++ b/src/Widgets/ActionBar.vala @@ -3,20 +3,18 @@ * SPDX-FileCopyrightText: 2017-2026 Spreadsheet Developers */ -using Spreadsheet.Services; - public class Spreadsheet.Widgets.ActionBar : Adw.Bin { private Gtk.Adjustment zoom_scale_adj; construct { - unowned var zoom_manager = ZoomManager.get_default (); + unowned var zoom_manager = Services.ZoomManager.get_default (); zoom_scale_adj = new Gtk.Adjustment ( - ZoomManager.ZOOM_LEVEL_DEFAULT, - ZoomManager.ZOOM_LEVEL_MIN, - ZoomManager.ZOOM_LEVEL_MAX, - ZoomManager.ZOOM_LEVEL_STEP, - ZoomManager.ZOOM_LEVEL_STEP, + Services.ZoomManager.ZOOM_LEVEL_DEFAULT, + Services.ZoomManager.ZOOM_LEVEL_MIN, + Services.ZoomManager.ZOOM_LEVEL_MAX, + Services.ZoomManager.ZOOM_LEVEL_STEP, + Services.ZoomManager.ZOOM_LEVEL_STEP, 0.0 ); diff --git a/src/Widgets/FunctionListRow.vala b/src/Widgets/FunctionListRow.vala index 8f35b13..3e05967 100644 --- a/src/Widgets/FunctionListRow.vala +++ b/src/Widgets/FunctionListRow.vala @@ -3,8 +3,6 @@ * SPDX-FileCopyrightText: 2017-2026 Spreadsheet Developers */ -using Spreadsheet.Models; - public class Spreadsheet.Widgets.FunctionListRow : Gtk.Box { public string name_text { get; set; } public string doc_text { get; set; } diff --git a/src/Widgets/Sheet.vala b/src/Widgets/Sheet.vala index d9adaca..01200d5 100644 --- a/src/Widgets/Sheet.vala +++ b/src/Widgets/Sheet.vala @@ -3,17 +3,13 @@ * SPDX-FileCopyrightText: 2017-2026 Spreadsheet Developers */ -using Spreadsheet.Models; -using Spreadsheet.Services; -using Spreadsheet.UI; - public class Spreadsheet.Widgets.Sheet : Gtk.DrawingArea { - public signal void selection_changed (Cell? new_selection); + public signal void selection_changed (Models.Cell? new_selection); public signal void clear_cell (); public signal void forward_input_text (string text); - public Page page { get; construct; } - public Cell? selected_cell { get; set; } + public Models.Page page { get; construct; } + public Models.Cell? selected_cell { get; set; } // Brand colors by elementary. See https://elementary.io/brand private const string BLUEBERRY_100 = "#8cd5ff"; @@ -50,15 +46,15 @@ public class Spreadsheet.Widgets.Sheet : Gtk.DrawingArea { private double padding; private double border; - private unowned ZoomManager zoom_manager; + private unowned Services.ZoomManager zoom_manager; private bool is_holding_ctrl = false; - public Sheet (Page page) { + public Sheet (Models.Page page) { Object ( page: page ); - zoom_manager = ZoomManager.get_default (); + zoom_manager = Services.ZoomManager.get_default (); focusable = true; focus_on_click = true; @@ -502,7 +498,7 @@ public class Spreadsheet.Widgets.Sheet : Gtk.DrawingArea { bg_color = selected_fill; } - if (bg_color != CellStyle.BG_COLOR_DEFAULT) { + if (bg_color != Models.CellStyle.BG_COLOR_DEFAULT) { cr.save (); Gdk.cairo_set_source_rgba (cr, bg_color); cr.rectangle (cell_x, cell_y, width, height); @@ -517,7 +513,7 @@ public class Spreadsheet.Widgets.Sheet : Gtk.DrawingArea { stroke_width = SELECTED_STROKE_WIDTH; } - if (stroke_color == CellStyle.STROKE_COLOR_DEFAULT) { + if (stroke_color == Models.CellStyle.STROKE_COLOR_DEFAULT) { stroke_color = default_cell_stroke; } @@ -534,7 +530,7 @@ public class Spreadsheet.Widgets.Sheet : Gtk.DrawingArea { color = selected_font_color; } - if (color == FontStyle.FONT_COLOR_DEFAULT) { + if (color == Models.FontStyle.FONT_COLOR_DEFAULT) { color = default_font_color; } diff --git a/src/Widgets/StyleModal.vala b/src/Widgets/StyleModal.vala index c808c3c..9bf0f4d 100644 --- a/src/Widgets/StyleModal.vala +++ b/src/Widgets/StyleModal.vala @@ -3,10 +3,8 @@ * SPDX-FileCopyrightText: 2017-2026 Spreadsheet Developers */ -using Spreadsheet.Models; - public class Spreadsheet.Widgets.StyleModal : Gtk.Grid { - public StyleModal (FontStyle font_style, CellStyle cell_style) { + public StyleModal (Models.FontStyle font_style, Models.CellStyle cell_style) { margin_top = 10; margin_bottom = 10; margin_start = 10; @@ -25,7 +23,7 @@ public class Spreadsheet.Widgets.StyleModal : Gtk.Grid { attach (style_stack, 0, 1, 1, 1); } - private Gtk.Grid create_fonts_grid (FontStyle font_style) { + private Gtk.Grid create_fonts_grid (Models.FontStyle font_style) { var style_header_label = new Granite.HeaderLabel (_("Style")); // TODO: Add a widget that can choose a font and its size @@ -114,7 +112,7 @@ public class Spreadsheet.Widgets.StyleModal : Gtk.Grid { color_reset_button, "sensitive", BindingFlags.SYNC_CREATE | BindingFlags.DEFAULT, (binding, _font_color, ref _sensitive) => { - _sensitive = !((Gdk.RGBA) _font_color).equal (FontStyle.FONT_COLOR_DEFAULT); + _sensitive = !((Gdk.RGBA) _font_color).equal (Models.FontStyle.FONT_COLOR_DEFAULT); return true; }); @@ -125,7 +123,7 @@ public class Spreadsheet.Widgets.StyleModal : Gtk.Grid { return fonts_grid; } - private Gtk.Grid create_cells_grid (CellStyle cell_style) { + private Gtk.Grid create_cells_grid (Models.CellStyle cell_style) { var bg_header_label = new Granite.HeaderLabel (_("Fill")); var bg_color_dialog = new Gtk.ColorDialog (); @@ -148,9 +146,9 @@ public class Spreadsheet.Widgets.StyleModal : Gtk.Grid { }; var stroke_width_spin = new Gtk.SpinButton.with_range ( - CellStyle.STROKE_WIDTH_MIN, - CellStyle.STROKE_WIDTH_MAX, - CellStyle.STROKE_WIDTH_STEP + Models.CellStyle.STROKE_WIDTH_MIN, + Models.CellStyle.STROKE_WIDTH_MAX, + Models.CellStyle.STROKE_WIDTH_STEP ) { halign = Gtk.Align.START, tooltip_text = _("Set the border width of a selected cell") @@ -188,21 +186,21 @@ public class Spreadsheet.Widgets.StyleModal : Gtk.Grid { bg_reset_button, "sensitive", BindingFlags.SYNC_CREATE | BindingFlags.DEFAULT, (binding, _bg_color, ref _sensitive) => { - _sensitive = !((Gdk.RGBA) _bg_color).equal (CellStyle.BG_COLOR_DEFAULT); + _sensitive = !((Gdk.RGBA) _bg_color).equal (Models.CellStyle.BG_COLOR_DEFAULT); return true; }); cell_style.bind_property ("stroke_color", stroke_reset_button, "sensitive", BindingFlags.SYNC_CREATE | BindingFlags.DEFAULT, (binding, _stroke_color, ref _sensitive) => { - _sensitive = !((Gdk.RGBA) _stroke_color).equal (CellStyle.STROKE_COLOR_DEFAULT); + _sensitive = !((Gdk.RGBA) _stroke_color).equal (Models.CellStyle.STROKE_COLOR_DEFAULT); return true; }); cell_style.bind_property ("stroke_color", stroke_width_spin, "sensitive", BindingFlags.SYNC_CREATE | BindingFlags.DEFAULT, (binding, _stroke_color, ref _sensitive) => { - _sensitive = !((Gdk.RGBA) _stroke_color).equal (CellStyle.STROKE_COLOR_DEFAULT); + _sensitive = !((Gdk.RGBA) _stroke_color).equal (Models.CellStyle.STROKE_COLOR_DEFAULT); return true; });