From bc89ea944ab5e76721ffe9bc93da891af4e18fea Mon Sep 17 00:00:00 2001 From: Gleb Smirnov Date: Sun, 23 Oct 2022 15:32:16 +0300 Subject: [PATCH] feat: Add internal support for choosing default tool --- ...m.github.liferooter.textpieces.gschema.xml | 37 +++++++------------ src/ToolsController.vala | 28 ++++++++++++++ src/Window.vala | 2 +- 3 files changed, 42 insertions(+), 25 deletions(-) diff --git a/data/com.github.liferooter.textpieces.gschema.xml b/data/com.github.liferooter.textpieces.gschema.xml index 77bd3ec..3164a75 100644 --- a/data/com.github.liferooter.textpieces.gschema.xml +++ b/data/com.github.liferooter.textpieces.gschema.xml @@ -11,58 +11,47 @@ SPDX-License-Identifier: GPL-3.0-or-later 'Adwaita-dark' Style scheme - - Which style scheme to use for application interface and editor. - + Which style scheme to use for application interface and editor. 'Monospace' Font name - - Name of font used in editor - + Name of font used in editor true Wrap lines - - Whether to wrap long lines - + Whether to wrap long lines false Tabs to spaces - - Whether to insert spaces instead of tab - + Whether to insert spaces instead of tab 4 Spaces in tab - - Tab width in spaces - + Tab width in spaces 800 Window width - - Saved width of application window - + Saved width of application window 500 Window height - - Saved height of the window - + Saved height of the window false Is maximized - - Whether the application window is maximized - + Whether the application window is maximized + + + '' + Default tool + Tool to select on start. Its value must be a name of tool's script. diff --git a/src/ToolsController.vala b/src/ToolsController.vala index cae1e49..31d3cb8 100644 --- a/src/ToolsController.vala +++ b/src/ToolsController.vala @@ -56,6 +56,34 @@ namespace TextPieces { get; private set; default = new ListStore (typeof (Tool)); } + /** + * Default tool + */ + public Tool? default_tool { + owned get { + var default_tool_script = Application.settings.get_string ("default-tool"); + + if (default_tool_script != "") { + for (uint i = 0; i < all_tools.get_n_items (); i++) { + var tool = (Tool) all_tools.get_item (i); + if (tool.script == default_tool_script) { + return tool; + } + } + + message ("Default tool is not found, so will be reset"); + default_tool = null; + } + + return null; + } set { + Application.settings.set_string ( + "default-tool", + value?.script ?? "" + ); + } + } + /** * Queue of deleted tools * pending script removal diff --git a/src/Window.vala b/src/Window.vala index edfe97b..ff043e3 100644 --- a/src/Window.vala +++ b/src/Window.vala @@ -139,7 +139,7 @@ namespace TextPieces { /* Initialize selected tool property and run its callback */ - selected_tool = null; + selected_tool = Application.tools.default_tool; } /**