Skip to content

Commit

Permalink
feat: Add internal support for choosing default tool
Browse files Browse the repository at this point in the history
  • Loading branch information
liferooter committed Oct 24, 2022
1 parent c915fac commit bc89ea9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 25 deletions.
37 changes: 13 additions & 24 deletions data/com.github.liferooter.textpieces.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,58 +11,47 @@ SPDX-License-Identifier: GPL-3.0-or-later
<key name="style-scheme" type="s">
<default>'Adwaita-dark'</default>
<summary>Style scheme</summary>
<description>
Which style scheme to use for application interface and editor.
</description>
<description>Which style scheme to use for application interface and editor.</description>
</key>
<key name="font-name" type="s">
<default>'Monospace'</default>
<summary>Font name</summary>
<description>
Name of font used in editor
</description>
<description>Name of font used in editor</description>
</key>
<key name="wrap-lines" type="b">
<default>true</default>
<summary>Wrap lines</summary>
<description>
Whether to wrap long lines
</description>
<description>Whether to wrap long lines</description>
</key>
<key name="tabs-to-spaces" type="b">
<default>false</default>
<summary>Tabs to spaces</summary>
<description>
Whether to insert spaces instead of tab
</description>
<description>Whether to insert spaces instead of tab</description>
</key>
<key name="spaces-in-tab" type="i">
<default>4</default>
<summary>Spaces in tab</summary>
<description>
Tab width in spaces
</description>
<description>Tab width in spaces</description>
</key>
<key name="window-width" type="i">
<default>800</default>
<summary>Window width</summary>
<description>
Saved width of application window
</description>
<description>Saved width of application window</description>
</key>
<key name="window-height" type="i">
<default>500</default>
<summary>Window height</summary>
<description>
Saved height of the window
</description>
<description>Saved height of the window</description>
</key>
<key name="is-maximized" type="b">
<default>false</default>
<summary>Is maximized</summary>
<description>
Whether the application window is maximized
</description>
<description>Whether the application window is maximized</description>
</key>
<key name="default-tool" type="s">
<default>''</default>
<summary>Default tool</summary>
<description>Tool to select on start. Its value must be a name of tool's script.</description>
</key>
</schema>
</schemalist>
28 changes: 28 additions & 0 deletions src/ToolsController.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Window.vala
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ namespace TextPieces {
/* Initialize selected
tool property and run
its callback */
selected_tool = null;
selected_tool = Application.tools.default_tool;
}

/**
Expand Down

0 comments on commit bc89ea9

Please sign in to comment.