mirror of
https://github.com/chylex/Query.git
synced 2025-05-28 07:34:05 +02:00
Enable nullable checks
This commit is contained in:
parent
4e950b73a3
commit
54200a9304
@ -34,7 +34,7 @@ public sealed partial class App : IApp {
|
|||||||
return RegexValidCharacters.IsMatch(cmd.Text) ? MatchConfidence.Possible : MatchConfidence.None;
|
return RegexValidCharacters.IsMatch(cmd.Text) ? MatchConfidence.Possible : MatchConfidence.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
string IApp.ProcessCommand(Command cmd) {
|
string? IApp.ProcessCommand(Command cmd) {
|
||||||
return ParseAndProcessExpression(cmd.Text);
|
return ParseAndProcessExpression(cmd.Text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ public sealed class App : IApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
string result = string.Empty;
|
string result = string.Empty;
|
||||||
IUnitType used = Processors.FirstOrDefault(processor => processor.TryProcess(src, dst, out result));
|
IUnitType? used = Processors.FirstOrDefault(processor => processor.TryProcess(src, dst, out result));
|
||||||
|
|
||||||
if (used == null) {
|
if (used == null) {
|
||||||
throw new CommandException("Could not recognize conversion units.");
|
throw new CommandException("Could not recognize conversion units.");
|
||||||
|
@ -44,7 +44,7 @@ sealed class Length : DecimalUnitConverterSimple<Length.Units> {
|
|||||||
updatedStr = updatedStr.Replace("&", " ");
|
updatedStr = updatedStr.Replace("&", " ");
|
||||||
updatedStr = updatedStr.Replace(",", " ");
|
updatedStr = updatedStr.Replace(",", " ");
|
||||||
|
|
||||||
string inchName = NamesInch.FirstOrDefault(name => src.Contains(name, StringComparison.OrdinalIgnoreCase));
|
string? inchName = NamesInch.FirstOrDefault(name => src.Contains(name, StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
if (inchName == null) {
|
if (inchName == null) {
|
||||||
return src;
|
return src;
|
||||||
@ -53,7 +53,7 @@ sealed class Length : DecimalUnitConverterSimple<Length.Units> {
|
|||||||
int inchIndex = src.IndexOf(inchName, StringComparison.OrdinalIgnoreCase);
|
int inchIndex = src.IndexOf(inchName, StringComparison.OrdinalIgnoreCase);
|
||||||
updatedStr = updatedStr.Remove(inchIndex, inchName.Length).Insert(inchIndex, new string(' ', inchName.Length));
|
updatedStr = updatedStr.Remove(inchIndex, inchName.Length).Insert(inchIndex, new string(' ', inchName.Length));
|
||||||
|
|
||||||
string footName = NamesFoot.FirstOrDefault(name => updatedStr.Contains(name, StringComparison.OrdinalIgnoreCase));
|
string? footName = NamesFoot.FirstOrDefault(name => updatedStr.Contains(name, StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
if (footName == null) {
|
if (footName == null) {
|
||||||
return src;
|
return src;
|
||||||
|
@ -80,8 +80,8 @@ static class SI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal sealed class ExtededProperties {
|
internal sealed class ExtededProperties {
|
||||||
public Predicate<int> FactorPredicate { get; init; }
|
public required Predicate<int> FactorPredicate { get; init; }
|
||||||
public Func<int, Func<decimal>> FromFunctionGenerator { get; init; }
|
public required Func<int, Func<decimal>> FromFunctionGenerator { get; init; }
|
||||||
public Func<int, Func<decimal>> ToFunctionGenerator { get; init; }
|
public required Func<int, Func<decimal>> ToFunctionGenerator { get; init; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ public sealed class App : IApp {
|
|||||||
return Handlers.Any(handler => handler.Matches(cmd)) ? MatchConfidence.Full : MatchConfidence.None;
|
return Handlers.Any(handler => handler.Matches(cmd)) ? MatchConfidence.Full : MatchConfidence.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string ProcessCommand(Command cmd) {
|
public string? ProcessCommand(Command cmd) {
|
||||||
return Handlers.First(handler => handler.Matches(cmd)).Handle(cmd);
|
return Handlers.First(handler => handler.Matches(cmd)).Handle(cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,8 +47,8 @@ sealed class HandlerApps : IHandler {
|
|||||||
return Mappings.ContainsKey(cmd.Text) || Substitutions.ContainsKey(cmd.Text);
|
return Mappings.ContainsKey(cmd.Text) || Substitutions.ContainsKey(cmd.Text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Handle(Command cmd) {
|
public string? Handle(Command cmd) {
|
||||||
if (!Substitutions.TryGetValue(cmd.Text, out string key)) {
|
if (!Substitutions.TryGetValue(cmd.Text, out string? key)) {
|
||||||
key = cmd.Text;
|
key = cmd.Text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,5 +4,5 @@ namespace AppSys;
|
|||||||
|
|
||||||
interface IHandler {
|
interface IHandler {
|
||||||
bool Matches(Command cmd);
|
bool Matches(Command cmd);
|
||||||
string Handle(Command cmd);
|
string? Handle(Command cmd);
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ public sealed class Command(string text) {
|
|||||||
|
|
||||||
public string Text { get; } = text;
|
public string Text { get; } = text;
|
||||||
|
|
||||||
public string PotentialAppName {
|
public string? PotentialAppName {
|
||||||
get {
|
get {
|
||||||
int firstSpace = Text.IndexOf(' ');
|
int firstSpace = Text.IndexOf(' ');
|
||||||
|
|
||||||
|
@ -4,5 +4,5 @@ public interface IApp {
|
|||||||
string[] RecognizedNames { get; }
|
string[] RecognizedNames { get; }
|
||||||
|
|
||||||
MatchConfidence GetConfidence(Command cmd);
|
MatchConfidence GetConfidence(Command cmd);
|
||||||
string ProcessCommand(Command cmd);
|
string? ProcessCommand(Command cmd);
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<LangVersion>12</LangVersion>
|
<LangVersion>12</LangVersion>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
|
@ -8,10 +8,10 @@ using Query.Core;
|
|||||||
namespace Query.Controls;
|
namespace Query.Controls;
|
||||||
|
|
||||||
sealed partial class QueryTextBox : UserControl {
|
sealed partial class QueryTextBox : UserControl {
|
||||||
public event EventHandler<CommandEventArgs> CommandRan;
|
public event EventHandler<CommandEventArgs>? CommandRan;
|
||||||
|
|
||||||
private CommandHistory history;
|
private CommandHistory history = null!;
|
||||||
private Action<string> log;
|
private Action<string> log = null!;
|
||||||
|
|
||||||
public QueryTextBox() {
|
public QueryTextBox() {
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@ -39,8 +39,8 @@ sealed partial class QueryTextBox : UserControl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnKeyDown(KeyEventArgs e) {
|
protected override void OnKeyDown(KeyEventArgs e) {
|
||||||
QueryTextBox input = (QueryTextBox) Parent;
|
QueryTextBox input = (QueryTextBox) Parent!;
|
||||||
CommandHistory history = input!.history;
|
CommandHistory history = input.history;
|
||||||
|
|
||||||
Keys key = e.KeyCode;
|
Keys key = e.KeyCode;
|
||||||
bool handled = false;
|
bool handled = false;
|
||||||
@ -116,7 +116,7 @@ sealed partial class QueryTextBox : UserControl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CustomTextBox_TextChanged(object sender, EventArgs e) {
|
private void CustomTextBox_TextChanged(object? sender, EventArgs e) {
|
||||||
ResetHistoryMemory();
|
ResetHistoryMemory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ sealed class CommandProcessor {
|
|||||||
private readonly Dictionary<string, IApp> appNames = new (8);
|
private readonly Dictionary<string, IApp> appNames = new (8);
|
||||||
private readonly HashSet<IApp> appSet = [];
|
private readonly HashSet<IApp> appSet = [];
|
||||||
|
|
||||||
public Func<string, bool> SingleTokenProcessor { get; init; }
|
public Func<string, bool>? SingleTokenProcessor { get; init; }
|
||||||
|
|
||||||
public void AddApp<T>() where T : IApp, new() {
|
public void AddApp<T>() where T : IApp, new() {
|
||||||
IApp app = new T();
|
IApp app = new T();
|
||||||
@ -20,12 +20,12 @@ sealed class CommandProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Run(Command cmd) {
|
public string? Run(Command cmd) {
|
||||||
cmd = cmd.ReplaceBrackets(match => Run(new Command(match.Groups[1].Value)));
|
cmd = cmd.ReplaceBrackets(match => Run(new Command(match.Groups[1].Value))!);
|
||||||
|
|
||||||
string appName = cmd.PotentialAppName;
|
string? appName = cmd.PotentialAppName;
|
||||||
|
|
||||||
if (appName != null && appNames.TryGetValue(appName.ToLowerInvariant(), out IApp app)) {
|
if (appName != null && appNames.TryGetValue(appName.ToLowerInvariant(), out var app)) {
|
||||||
return app.ProcessCommand(new Command(cmd.Text[(appName.Length + 1)..]));
|
return app.ProcessCommand(new Command(cmd.Text[(appName.Length + 1)..]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ using System.Windows.Forms;
|
|||||||
namespace Query.Core;
|
namespace Query.Core;
|
||||||
|
|
||||||
sealed class KeyboardHook {
|
sealed class KeyboardHook {
|
||||||
public event EventHandler Triggered;
|
public event EventHandler? Triggered;
|
||||||
|
|
||||||
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
|
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
|
||||||
private readonly NativeMethods.HookProc keyboardHookDelegate;
|
private readonly NativeMethods.HookProc keyboardHookDelegate;
|
||||||
|
@ -53,9 +53,11 @@ sealed partial class MainForm : Form {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MainForm_Shown(object sender, EventArgs e) {
|
private void MainForm_Shown(object? sender, EventArgs e) {
|
||||||
Rectangle screenRect = Screen.PrimaryScreen.WorkingArea;
|
if (Screen.PrimaryScreen is {} primaryScreen) {
|
||||||
Location = new Point(screenRect.X + screenRect.Width - Width, screenRect.Y + screenRect.Height - Height);
|
Rectangle screenRect = primaryScreen.WorkingArea;
|
||||||
|
Location = new Point(screenRect.X + screenRect.Width - Width, screenRect.Y + screenRect.Height - Height);
|
||||||
|
}
|
||||||
|
|
||||||
if (!isLoaded) {
|
if (!isLoaded) {
|
||||||
isLoaded = true;
|
isLoaded = true;
|
||||||
@ -63,38 +65,38 @@ sealed partial class MainForm : Form {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MainForm_Deactivate(object sender, EventArgs e) {
|
private void MainForm_Deactivate(object? sender, EventArgs e) {
|
||||||
SetShown(false);
|
SetShown(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MainForm_Disposed(object sender, EventArgs e) {
|
private void MainForm_Disposed(object? sender, EventArgs e) {
|
||||||
keyboardHook.StopHook();
|
keyboardHook.StopHook();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void trayIcon_Click(object sender, EventArgs e) {
|
private void trayIcon_Click(object? sender, EventArgs e) {
|
||||||
if (((MouseEventArgs) e).Button == MouseButtons.Left) {
|
if (((MouseEventArgs) e).Button == MouseButtons.Left) {
|
||||||
SetShown(true);
|
SetShown(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showToolStripMenuItem_Click(object sender, EventArgs e) {
|
private void showToolStripMenuItem_Click(object? sender, EventArgs e) {
|
||||||
SetShown(true);
|
SetShown(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hookToolStripMenuItem_Click(object sender, EventArgs e) {
|
private void hookToolStripMenuItem_Click(object? sender, EventArgs e) {
|
||||||
keyboardHook.StopHook();
|
keyboardHook.StopHook();
|
||||||
keyboardHook.StartHook();
|
keyboardHook.StartHook();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void exitToolStripMenuItem_Click(object sender, EventArgs e) {
|
private void exitToolStripMenuItem_Click(object? sender, EventArgs e) {
|
||||||
Application.Exit();
|
Application.Exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void keyboardHook_Triggered(object sender, EventArgs e) {
|
private void keyboardHook_Triggered(object? sender, EventArgs e) {
|
||||||
SetShown(!Visible);
|
SetShown(!Visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void focusTimer_Tick(object sender, EventArgs e) {
|
private void focusTimer_Tick(object? sender, EventArgs e) {
|
||||||
WindowState = FormWindowState.Minimized;
|
WindowState = FormWindowState.Minimized;
|
||||||
Show();
|
Show();
|
||||||
Activate();
|
Activate();
|
||||||
@ -104,9 +106,9 @@ sealed partial class MainForm : Form {
|
|||||||
focusTimer.Stop();
|
focusTimer.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void queryBox_CommandRan(object sender, CommandEventArgs e) {
|
private void queryBox_CommandRan(object? sender, CommandEventArgs e) {
|
||||||
try {
|
try {
|
||||||
string result = processor.Run(e.Command);
|
string? result = processor.Run(e.Command);
|
||||||
|
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
queryLog.AddEntry("> " + e.Command.Text, QueryHistoryLog.EntryType.UserInput);
|
queryLog.AddEntry("> " + e.Command.Text, QueryHistoryLog.EntryType.UserInput);
|
||||||
|
Loading…
Reference in New Issue
Block a user