Skip to content

Commit 17f3205

Browse files
committed
Mouse console input
1 parent 2c2fa65 commit 17f3205

File tree

6 files changed

+19
-44
lines changed

6 files changed

+19
-44
lines changed

SmartImage.Lib/SearchClient.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,9 @@ public ImageResult[] GetDirectResults(int count = 5)
259259

260260
if (count == 1) {
261261
images = new List<ImageResult>
262-
{ query.FirstOrDefault(x => x.CheckDirect(DirectImageCriterion.Binary)) };
262+
{
263+
query.FirstOrDefault(x => x.CheckDirect(DirectImageCriterion.Binary))
264+
};
263265

264266
}
265267
else {

SmartImage/Core/AppInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public static void Setup()
110110
}
111111

112112
if (!IsAppFolderInPath) {
113-
AppIntegration.HandlePath(IntegrationOption.Add);
113+
AppIntegration.HandlePath(true);
114114
}
115115

116116
Debug.WriteLine($"Cli utilities: {ImageHelper.Utilities.QuickJoin()}", C_INFO);

SmartImage/Core/AppIntegration.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@
1919

2020
namespace SmartImage.Core
2121
{
22-
public enum IntegrationOption
23-
{
24-
Add,
25-
Remove
26-
}
22+
2723

2824
/// <summary>
2925
/// Program OS integrations
@@ -38,14 +34,14 @@ public static class AppIntegration
3834

3935

4036
/// <returns><c>true</c> if operation succeeded; <c>false</c> otherwise</returns>
41-
public static bool HandleContextMenu(IntegrationOption option)
37+
public static bool HandleContextMenu(bool option)
4238
{
4339
/*
4440
* New context menu
4541
*/
4642

4743
switch (option) {
48-
case IntegrationOption.Add:
44+
case true:
4945

5046
RegistryKey regMenu = null;
5147
RegistryKey regCmd = null;
@@ -71,7 +67,7 @@ public static bool HandleContextMenu(IntegrationOption option)
7167
}
7268

7369
break;
74-
case IntegrationOption.Remove:
70+
case false:
7571

7672
try {
7773
var reg = Registry.CurrentUser.OpenSubKey(REG_SHELL_CMD);
@@ -104,10 +100,10 @@ public static bool HandleContextMenu(IntegrationOption option)
104100

105101
}
106102

107-
public static void HandlePath(IntegrationOption option)
103+
public static void HandlePath(bool option)
108104
{
109105
switch (option) {
110-
case IntegrationOption.Add:
106+
case true:
111107
{
112108
string oldValue = FileSystem.GetEnvironmentPath();
113109
string appFolder = AppInfo.AppFolder;
@@ -130,7 +126,7 @@ public static void HandlePath(IntegrationOption option)
130126

131127
break;
132128
}
133-
case IntegrationOption.Remove:
129+
case false:
134130
FileSystem.RemoveFromPath(AppInfo.AppFolder);
135131
break;
136132
default:
@@ -144,7 +140,7 @@ public static void ResetIntegrations()
144140
// Computer\HKEY_CLASSES_ROOT\*\shell\SmartImage
145141

146142
if (IsContextMenuAdded) {
147-
HandleContextMenu(IntegrationOption.Remove);
143+
HandleContextMenu(false);
148144
}
149145

150146
Trace.WriteLine("Reset config");

SmartImage/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ private static async Task<bool> HandleArguments()
271271
private static void OnSearchCompleted(object sender, SearchCompletedEventArgs eventArgs,
272272
CancellationTokenSource cts)
273273
{
274+
274275
Native.FlashConsoleWindow();
275276

276277
cts.Cancel();

SmartImage/UI/AppInterface.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ internal static partial class AppInterface
6464

6565
CreateConfigOption(propertyof(() => AppIntegration.IsContextMenuAdded), "Context menu", 6,
6666
added => AppIntegration.HandleContextMenu(
67-
added ? IntegrationOption.Remove : IntegrationOption.Add)),
67+
added ? false : true)),
6868

6969
new()
7070
{
@@ -99,14 +99,14 @@ internal static partial class AppInterface
9999
Console.WriteLine($"In path: {AppInfo.IsAppFolderInPath}");
100100

101101
Console.WriteLine();
102-
Console.WriteLine(Strings.Separator);
102+
Console.WriteLine(StringConstants.Separator);
103103

104104
foreach (var utility in ImageHelper.UtilitiesMap) {
105105
Console.WriteLine(utility);
106106
}
107107

108108
Console.WriteLine();
109-
Console.WriteLine(Strings.Separator);
109+
Console.WriteLine(StringConstants.Separator);
110110

111111
var dependencies = ReflectionHelper.DumpDependencies();
112112

SmartImage/UI/NConsoleFactory.cs

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ internal static NConsoleOption CreateConfigOption(PropertyInfo member, string na
6565
{
6666
bool initVal = (bool) member.GetValue(Program.Config);
6767

68-
return new NConsoleOption()
68+
return new NConsoleOption
6969
{
7070
Name = AppInterface.Elements.GetName(name, initVal),
7171
Function = () =>
@@ -91,7 +91,7 @@ internal static NConsoleOption CreateConfigOption(string m, string name, int i)
9191
{
9292
bool initVal = (bool) (Program.Config).GetType().GetAnyResolvedField(m).GetValue(Program.Config);
9393

94-
return new NConsoleOption()
94+
return new NConsoleOption
9595
{
9696
Name = AppInterface.Elements.GetName(name, initVal),
9797
Function = () =>
@@ -118,9 +118,7 @@ internal static NConsoleOption CreateResultOption(SearchResult result)
118118

119119
var option = new NConsoleOption
120120
{
121-
122-
123-
Functions = new Dictionary<ConsoleModifiers, NConsoleFunction>()
121+
Functions = new Dictionary<ConsoleModifiers, NConsoleFunction>
124122
{
125123
[NC_FN_MAIN] = CreateOpenFunction(result.PrimaryResult is { Url: { } }
126124
? result.PrimaryResult.Url
@@ -243,27 +241,5 @@ internal static NConsoleFunction CreateOpenFunction(Uri url)
243241
return null;
244242
};
245243
}
246-
247-
internal static NConsoleFunction CreateDownloadFunction(ImageResult result)
248-
{
249-
return () =>
250-
{
251-
Trace.WriteLine($"Downloading");
252-
var direct = result.Direct;
253-
254-
255-
if (direct != null) {
256-
var path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
257-
258-
var file = ImageHelper.Download(direct, path);
259-
260-
FileSystem.ExploreFile(file);
261-
262-
Debug.WriteLine($"Download: {file}", LogCategories.C_INFO);
263-
}
264-
265-
return null;
266-
};
267-
}
268244
}
269245
}

0 commit comments

Comments
 (0)