From 25ebfc3ddaebe0198cc666fdb4b7609ddc56f687 Mon Sep 17 00:00:00 2001 From: Samuel Proulx Date: Tue, 6 Feb 2024 00:40:46 -0500 Subject: [PATCH] work to add a settings GUI. --- adispeak/Adispeak.cs | 32 ++++++++++++++++++++++------ adispeak/Config.cs | 46 +++++++++++++++++++++++++++++++++++----- adispeak/adispeak.csproj | 10 +++++++++ 3 files changed, 77 insertions(+), 11 deletions(-) diff --git a/adispeak/Adispeak.cs b/adispeak/Adispeak.cs index aebc37f..06cd6df 100644 --- a/adispeak/Adispeak.cs +++ b/adispeak/Adispeak.cs @@ -25,7 +25,7 @@ public class AdiSpeakPlugin : IPlugin public string PluginName => "Adispeak"; public string PluginDescription => "Makes AdiIrc speak via multiple screen readers using the tolk library."; public string PluginAuthor => "fastfinge and arfy"; - public string PluginVersion => "0.2"; + public string PluginVersion => "0.3"; public string PluginEmail => "samuel@interfree.ca or arfy32@gmail.com"; private IPluginHost _host; private ITools _tools; @@ -33,6 +33,9 @@ public class AdiSpeakPlugin : IPlugin private bool SayTopic; private bool SayTopicSetBy; private Config config; + private ConfigGui Gui; + private string oldtext; + public void Initialize(IPluginHost host) { @@ -44,7 +47,7 @@ public void Initialize(IPluginHost host) config = new Config(); config.Read("speech.json"); - + if (!_host.HookCommand("/speak", SpeakCommandHandler)) { _host.ActiveIWindow.OutputText("Could not create the /speak command."); @@ -80,6 +83,11 @@ public void Initialize(IPluginHost host) _host.ActiveIWindow.OutputText("Could not create the /savespeech command."); } + if (!_host.HookCommand("/speechgui", SpeechguiCommandHandler)) + { + _host.ActiveIWindow.OutputText("Could not create the /speechgui command."); + } + _host.HookIdentifier("screenreader", ScreenreaderIdentifierHandler); _host.HookIdentifier("speech", SpeechIdentifierHandler); _host.HookIdentifier("braille", BrailleIdentifierHandler); @@ -202,7 +210,12 @@ private void LoadspeechCommandHandler(RegisteredCommandArgs argument) Tolk.Output("Settings loaded."); } - private void ScreenreaderIdentifierHandler(RegisteredIdentifierArgs argument) + private void SpeechguiCommandHandler(RegisteredCommandArgs argument) + { + Gui = new ConfigGui(config); + } + + private void ScreenreaderIdentifierHandler(RegisteredIdentifierArgs argument) { argument.ReturnString = Tolk.DetectScreenReader(); } @@ -230,7 +243,7 @@ private void BrailleIdentifierHandler(RegisteredIdentifierArgs argument) argument.ReturnString = "false"; } } - + private void SpeakingIdentifierHandler(RegisteredIdentifierArgs argument) { if (Tolk.IsSpeaking()) @@ -289,11 +302,16 @@ private void OnEditboxKeyDown(EditboxKeyDownArgs argument) } } + if (argument.KeyEventArgs.KeyCode == Keys.F7) + { + Gui = new ConfigGui(config); + } if (argument.KeyEventArgs.Alt && argument.KeyEventArgs.Shift && argument.KeyEventArgs.KeyCode == Keys.Up) { argument.KeyEventArgs.SuppressKeyPress = true; argument.KeyEventArgs.Handled = true; + oldtext = _host.ActiveIWindow.Editbox.Text; CurPos = CurPos - 1; if (CurPos <= 0) { @@ -302,13 +320,15 @@ private void OnEditboxKeyDown(EditboxKeyDownArgs argument) } _host.ActiveIWindow.TextView.ScrollTo(CurPos); Tolk.Output(_tools.Strip(_host.ActiveIWindow.TextView.GetLine(CurPos))); - _host.ActiveIWindow.Editbox.Text = ""; + _host.ActiveIWindow.Editbox.Text = oldtext; } if (argument.KeyEventArgs.Alt && argument.KeyEventArgs.Shift && argument.KeyEventArgs.KeyCode == Keys.Down) { argument.KeyEventArgs.SuppressKeyPress = true; argument.KeyEventArgs.Handled = true; + oldtext = _host.ActiveIWindow.Editbox.Text; + CurPos = CurPos + 1; if (CurPos == _host.ActiveIWindow.TextView.Lines.Count) { @@ -317,7 +337,7 @@ private void OnEditboxKeyDown(EditboxKeyDownArgs argument) } _host.ActiveIWindow.TextView.ScrollTo(CurPos); Tolk.Output(_tools.Strip(_host.ActiveIWindow.TextView.GetLine(CurPos))); - _host.ActiveIWindow.Editbox.Text = ""; + _host.ActiveIWindow.Editbox.Text = oldtext; } if (argument.KeyEventArgs.Alt && argument.KeyEventArgs.Shift && argument.KeyEventArgs.KeyCode == Keys.Home) diff --git a/adispeak/Config.cs b/adispeak/Config.cs index 5db0a3d..3e7c94b 100644 --- a/adispeak/Config.cs +++ b/adispeak/Config.cs @@ -8,9 +8,10 @@ namespace adispeak { - class Config + public class Config { - private Dictionary> Settings = new Dictionary> + private Dictionary WindowList = new Dictionary {}; + private Dictionary> Settings = new Dictionary> { {"global", new Dictionary { @@ -98,6 +99,7 @@ public void SetGlobal(string setting, bool value) { Settings["global"][setting] = value; } + public bool GetWindow(string windowName, string setting) { @@ -111,16 +113,41 @@ public bool GetWindow(string windowName, string setting) } } + public Dictionary GetWindowList() + { + foreach (var item in Settings) + { + WindowList[item.Key] = true; + } + return WindowList; + } + public void SetWindow(string windowName, string setting, bool value) { + if (Settings.ContainsKey(windowName)) + { Settings[windowName][setting] = value; - } + } + else + { + AddWindow(windowName); + Settings[windowName][setting] = value; + } + } public void AddWindow(string windowName) { Settings[windowName] = new Dictionary(); } + public void RemoveWindow(string WindowName) + { + if (WindowName != "global") + { + Settings[WindowName] = null; + } + } + public bool ContainsWindow(string windowName) { return Settings.ContainsKey(windowName); @@ -139,9 +166,18 @@ public void Read(string filename) } } - public void Write(string filename) + public void Write(string filename) + { + + foreach (var item in Settings) { - JsonSerializer serializer = new JsonSerializer(); + if (item.Key.Count() == 0) + { + RemoveWindow(item.Key); + } + } + + JsonSerializer serializer = new JsonSerializer(); serializer.Formatting = Formatting.Indented; using (StreamWriter sw = new StreamWriter(filename)) using (JsonTextWriter writer = new JsonTextWriter(sw)) diff --git a/adispeak/adispeak.csproj b/adispeak/adispeak.csproj index 2d384b3..06d1d44 100644 --- a/adispeak/adispeak.csproj +++ b/adispeak/adispeak.csproj @@ -53,6 +53,7 @@ + @@ -67,6 +68,9 @@ + + Form + @@ -74,5 +78,11 @@ 13.0.3 + + + + + + \ No newline at end of file