mirror of
https://github.com/chylex/Query.git
synced 2025-05-11 11:34:07 +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;
|
||||
}
|
||||
|
||||
string IApp.ProcessCommand(Command cmd) {
|
||||
string? IApp.ProcessCommand(Command cmd) {
|
||||
return ParseAndProcessExpression(cmd.Text);
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ public sealed class App : IApp {
|
||||
}
|
||||
|
||||
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) {
|
||||
throw new CommandException("Could not recognize conversion units.");
|
||||
|
@ -44,7 +44,7 @@ sealed class Length : DecimalUnitConverterSimple<Length.Units> {
|
||||
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) {
|
||||
return src;
|
||||
@ -53,7 +53,7 @@ sealed class Length : DecimalUnitConverterSimple<Length.Units> {
|
||||
int inchIndex = src.IndexOf(inchName, StringComparison.OrdinalIgnoreCase);
|
||||
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) {
|
||||
return src;
|
||||
|
@ -80,8 +80,8 @@ static class SI {
|
||||
}
|
||||
|
||||
internal sealed class ExtededProperties {
|
||||
public Predicate<int> FactorPredicate { get; init; }
|
||||
public Func<int, Func<decimal>> FromFunctionGenerator { get; init; }
|
||||
public Func<int, Func<decimal>> ToFunctionGenerator { get; init; }
|
||||
public required Predicate<int> FactorPredicate { get; init; }
|
||||
public required Func<int, Func<decimal>> FromFunctionGenerator { 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;
|
||||
}
|
||||
|
||||
public string ProcessCommand(Command cmd) {
|
||||
public string? ProcessCommand(Command 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);
|
||||
}
|
||||
|
||||
public string Handle(Command cmd) {
|
||||
if (!Substitutions.TryGetValue(cmd.Text, out string key)) {
|
||||
public string? Handle(Command cmd) {
|
||||
if (!Substitutions.TryGetValue(cmd.Text, out string? key)) {
|
||||
key = cmd.Text;
|
||||
}
|
||||
|
||||
|
@ -4,5 +4,5 @@ namespace AppSys;
|
||||
|
||||
interface IHandler {
|
||||
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 PotentialAppName {
|
||||
public string? PotentialAppName {
|
||||
get {
|
||||
int firstSpace = Text.IndexOf(' ');
|
||||
|
||||
|
@ -4,5 +4,5 @@ public interface IApp {
|
||||
string[] RecognizedNames { get; }
|
||||
|
||||
MatchConfidence GetConfidence(Command cmd);
|
||||
string ProcessCommand(Command cmd);
|
||||
string? ProcessCommand(Command cmd);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<LangVersion>12</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
|
@ -8,10 +8,10 @@ using Query.Core;
|
||||
namespace Query.Controls;
|
||||
|
||||
sealed partial class QueryTextBox : UserControl {
|
||||
public event EventHandler<CommandEventArgs> CommandRan;
|
||||
public event EventHandler<CommandEventArgs>? CommandRan;
|
||||
|
||||
private CommandHistory history;
|
||||
private Action<string> log;
|
||||
private CommandHistory history = null!;
|
||||
private Action<string> log = null!;
|
||||
|
||||
public QueryTextBox() {
|
||||
InitializeComponent();
|
||||
@ -39,8 +39,8 @@ sealed partial class QueryTextBox : UserControl {
|
||||
}
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e) {
|
||||
QueryTextBox input = (QueryTextBox) Parent;
|
||||
CommandHistory history = input!.history;
|
||||
QueryTextBox input = (QueryTextBox) Parent!;
|
||||
CommandHistory history = input.history;
|
||||
|
||||
Keys key = e.KeyCode;
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ sealed class CommandProcessor {
|
||||
private readonly Dictionary<string, IApp> appNames = new (8);
|
||||
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() {
|
||||
IApp app = new T();
|
||||
@ -20,12 +20,12 @@ sealed class CommandProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
public string Run(Command cmd) {
|
||||
cmd = cmd.ReplaceBrackets(match => Run(new Command(match.Groups[1].Value)));
|
||||
public string? Run(Command cmd) {
|
||||
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)..]));
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ using System.Windows.Forms;
|
||||
namespace Query.Core;
|
||||
|
||||
sealed class KeyboardHook {
|
||||
public event EventHandler Triggered;
|
||||
public event EventHandler? Triggered;
|
||||
|
||||
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
|
||||
private readonly NativeMethods.HookProc keyboardHookDelegate;
|
||||
|
@ -53,9 +53,11 @@ sealed partial class MainForm : Form {
|
||||
}
|
||||
}
|
||||
|
||||
private void MainForm_Shown(object sender, EventArgs e) {
|
||||
Rectangle screenRect = Screen.PrimaryScreen.WorkingArea;
|
||||
Location = new Point(screenRect.X + screenRect.Width - Width, screenRect.Y + screenRect.Height - Height);
|
||||
private void MainForm_Shown(object? sender, EventArgs e) {
|
||||
if (Screen.PrimaryScreen is {} primaryScreen) {
|
||||
Rectangle screenRect = primaryScreen.WorkingArea;
|
||||
Location = new Point(screenRect.X + screenRect.Width - Width, screenRect.Y + screenRect.Height - Height);
|
||||
}
|
||||
|
||||
if (!isLoaded) {
|
||||
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);
|
||||
}
|
||||
|
||||
private void MainForm_Disposed(object sender, EventArgs e) {
|
||||
private void MainForm_Disposed(object? sender, EventArgs e) {
|
||||
keyboardHook.StopHook();
|
||||
}
|
||||
|
||||
private void trayIcon_Click(object sender, EventArgs e) {
|
||||
private void trayIcon_Click(object? sender, EventArgs e) {
|
||||
if (((MouseEventArgs) e).Button == MouseButtons.Left) {
|
||||
SetShown(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void showToolStripMenuItem_Click(object sender, EventArgs e) {
|
||||
private void showToolStripMenuItem_Click(object? sender, EventArgs e) {
|
||||
SetShown(true);
|
||||
}
|
||||
|
||||
private void hookToolStripMenuItem_Click(object sender, EventArgs e) {
|
||||
private void hookToolStripMenuItem_Click(object? sender, EventArgs e) {
|
||||
keyboardHook.StopHook();
|
||||
keyboardHook.StartHook();
|
||||
}
|
||||
|
||||
private void exitToolStripMenuItem_Click(object sender, EventArgs e) {
|
||||
private void exitToolStripMenuItem_Click(object? sender, EventArgs e) {
|
||||
Application.Exit();
|
||||
}
|
||||
|
||||
private void keyboardHook_Triggered(object sender, EventArgs e) {
|
||||
private void keyboardHook_Triggered(object? sender, EventArgs e) {
|
||||
SetShown(!Visible);
|
||||
}
|
||||
|
||||
private void focusTimer_Tick(object sender, EventArgs e) {
|
||||
private void focusTimer_Tick(object? sender, EventArgs e) {
|
||||
WindowState = FormWindowState.Minimized;
|
||||
Show();
|
||||
Activate();
|
||||
@ -104,9 +106,9 @@ sealed partial class MainForm : Form {
|
||||
focusTimer.Stop();
|
||||
}
|
||||
|
||||
private void queryBox_CommandRan(object sender, CommandEventArgs e) {
|
||||
private void queryBox_CommandRan(object? sender, CommandEventArgs e) {
|
||||
try {
|
||||
string result = processor.Run(e.Command);
|
||||
string? result = processor.Run(e.Command);
|
||||
|
||||
if (result != null) {
|
||||
queryLog.AddEntry("> " + e.Command.Text, QueryHistoryLog.EntryType.UserInput);
|
||||
|
Loading…
Reference in New Issue
Block a user