Skip to content

Commit

Permalink
Merge pull request #32 from fastfinge/gui-work
Browse files Browse the repository at this point in the history
work to add a settings GUI.
  • Loading branch information
fastfinge authored Feb 6, 2024
2 parents 86960ea + 25ebfc3 commit 5d36886
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 11 deletions.
32 changes: 26 additions & 6 deletions adispeak/Adispeak.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ 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;
private int CurPos;
private bool SayTopic;
private bool SayTopicSetBy;
private Config config;
private ConfigGui Gui;
private string oldtext;


public void Initialize(IPluginHost host)
{
Expand All @@ -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.");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -230,7 +243,7 @@ private void BrailleIdentifierHandler(RegisteredIdentifierArgs argument)
argument.ReturnString = "false";
}
}

private void SpeakingIdentifierHandler(RegisteredIdentifierArgs argument)
{
if (Tolk.IsSpeaking())
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
Expand Down
46 changes: 41 additions & 5 deletions adispeak/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@

namespace adispeak
{
class Config
public class Config
{
private Dictionary<string, Dictionary<string, bool>> Settings = new Dictionary<string, Dictionary<string, bool>>
private Dictionary<string, bool> WindowList = new Dictionary<string, bool> {};
private Dictionary<string, Dictionary<string, bool>> Settings = new Dictionary<string, Dictionary<string, bool>>
{
{"global", new Dictionary<string, bool>
{
Expand Down Expand Up @@ -98,6 +99,7 @@ public void SetGlobal(string setting, bool value)
{
Settings["global"][setting] = value;
}


public bool GetWindow(string windowName, string setting)
{
Expand All @@ -111,16 +113,41 @@ public bool GetWindow(string windowName, string setting)
}
}

public Dictionary <string, bool> 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<string, bool>();
}

public void RemoveWindow(string WindowName)
{
if (WindowName != "global")
{
Settings[WindowName] = null;
}
}

public bool ContainsWindow(string windowName)
{
return Settings.ContainsKey(windowName);
Expand All @@ -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))
Expand Down
10 changes: 10 additions & 0 deletions adispeak/adispeak.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
Expand All @@ -67,12 +68,21 @@
<ItemGroup>
<Compile Include="Adispeak.cs" />
<Compile Include="Config.cs" />
<Compile Include="gui.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json">
<Version>13.0.3</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<None Include="README.md" />
</ItemGroup>
<ItemGroup>
<Content Include="changelog.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

0 comments on commit 5d36886

Please sign in to comment.