aboutsummaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs
index 2a1e5ed..b5abb1e 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -1,3 +1,5 @@
+//! Home of the user configuratable content of graf karto, like keybindings and (TODO) colours etc.
+
use crate::button::*;
use ron::de::from_reader;
use ron::ser::{to_string_pretty, PrettyConfig};
@@ -6,6 +8,8 @@ use std::fs::File;
use std::io::{self, Write};
use std::path::Path;
+/// All configuration parameters the user can set are contained in this struct.
+#[allow(missing_docs)]
#[derive(Deserialize, Serialize)]
pub struct Config {
pub tool_activation_keys: ToolActivationKeys,
@@ -13,7 +17,10 @@ pub struct Config {
pub icon_keys: IconToolKeys,
}
+#[allow(missing_docs)]
#[derive(Deserialize, Serialize)]
+/// The keys used to activate the individual tools. These keystrokes will not be sent to the tools,
+/// but instead will be handled by the editor where the tools are registered.
pub struct ToolActivationKeys {
pub deletion: Button,
pub icon: Button,
@@ -24,21 +31,38 @@ pub struct ToolActivationKeys {
}
#[derive(Deserialize, Serialize)]
+/// Keys that are useful to most tools. These are packaged so that not every tool has the same n keys
+/// and then some more.
pub struct ToolGeneralKeys {
+ /// Keybinding to, where applicable, place a single node (usually a vertex) for the tool in
+ /// question.
pub place_single: Button,
+ /// Finish up whatever one is doing with the current tool, without removing information.
pub finish: Button,
+ /// Abort whatever one is doing with the current tool which means the last atomic action will not
+ /// be pushed into the map items.
pub abort: Button,
}
#[derive(Clone, Serialize, Deserialize)]
+/// Key bindings that are individually interesting to the icon tool.
pub struct IconToolKeys {
+ /// Key to change to the next icon of the icon list.
pub next: Button,
+ /// Key to change to the previous icon of the icon list.
pub previous: Button,
+ /// Rotate the working icon clockwise by a certain amount (currently 45 degrees)
pub rotate_clockwise: Button,
+ /// Rotate the working icon counterclockwise by a certain amount (currently 45 degrees)
pub rotate_counterclockwise: Button,
}
impl Config {
+ /// Try to parse a configuration from the file located at path.
+ ///
+ /// # Errors
+ /// If the file is not found or can not be read or parsed for a different reason, an IO-Error is
+ /// returned.
pub fn from_file<P: AsRef<Path>>(path: P) -> io::Result<Config> {
let file = File::open(&path)?;
match from_reader(file) {
@@ -47,6 +71,10 @@ impl Config {
}
}
+ /// Try to write the configuration to the file at path. If the file exists, it will be overwritten.
+ ///
+ /// # Errors
+ /// If the file can not be written, for example for lack of permissions, an IO-Error is returned.
pub fn write_file<P: AsRef<Path>>(&self, path: P) -> io::Result<()> {
let mut file = File::create(&path)?;