Skip to content

Commit

Permalink
修复 应用名称不显示
Browse files Browse the repository at this point in the history
修复 命令执行
优化 命令执行项目出现逻辑
优化 搜索逻辑
  • Loading branch information
MakesYT committed Apr 28, 2024
1 parent 5a4d7c5 commit 0d2caf0
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 23 deletions.
11 changes: 11 additions & 0 deletions Core.Window/SearchItemTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ public void OpenFile(SearchViewItem? searchViewItem)
case FileType.自定义:
searchViewItem.Action?.Invoke(searchViewItem);
break;
case FileType.命令:
{
Process.Start(new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = $"/c {searchViewItem.OnlyKey} & pause",
UseShellExecute = false,
CreateNoWindow = false,
});
break;
}
case FileType.文件夹:
{
if (searchViewItem.Arguments == null)
Expand Down
53 changes: 32 additions & 21 deletions Core/ViewModel/SearchWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ public partial class SearchWindowViewModel : ObservableRecipient

[ObservableProperty] private int? _selectedIndex = -1;

private string[] knownCommand =
[
"cmd", "powershell", "wsl", "bash", "ping", "ipconfig", "nslookup", "tracert", "netstat", "arp", "route",
"telnet", "ftp", "ssh", "scp", "sftp", "rsync", "nmap", "nc", "curl", "wget", "git", "svn", "hg", "docker",
"docker-compose", "kubectl", "helm", "minikube"
];


private bool nowInSelectMode = false;
private Action<SearchViewItem?>? selectAction;
Expand Down Expand Up @@ -219,7 +226,7 @@ private void LoadLast()
{
Log.Debug("加载历史");
var sortedDict = ConfigManger.Config.lastOpens.OrderByDescending(p => p.Value)
.ToDictionary(p => p.Key, p => p.Value);
.ToDictionary(p => p.Key, p => p.Value);
foreach (var (key, value) in sortedDict)
{
if (limit >= ConfigManger.Config.maxHistory)
Expand Down Expand Up @@ -268,9 +275,10 @@ partial void OnSearchChanged(string? value)
nameof(SearchViewItem.Keys),
nameof(SearchViewItem.CharMatchResults),true);
}

//Log.Debug("搜索");
_searchDelayAction.Debounce(ConfigManger.Config.inputSmoothingMilliseconds, _scheduler, () =>
{
//Log.Debug("搜索开始");
if (string.IsNullOrEmpty(Search))
{
LoadLast();
Expand Down Expand Up @@ -298,7 +306,7 @@ partial void OnSearchChanged(string? value)

#endregion
string originalValue = Search;
value = Search.ToLowerInvariant().Split(" ").First();
value = Search.ToLowerInvariant();
var pluginItem = 0;
foreach (var searchAction in PluginOverall.SearchActions)
{
Expand Down Expand Up @@ -422,13 +430,13 @@ partial void OnSearchChanged(string? value)
{
if (ConfigManger.Config.lastOpens.TryGetValue(sorted[i].Source.OnlyKey, out var open))
{
nowHasLastOpens.Add((SearchViewItem)sorted[i].Source, open);
nowHasLastOpens.Add((SearchViewItem)sorted[i].Source, (int)(sorted[i].Weight));
sorted.RemoveAt(i);
}
}

var sortedDict = nowHasLastOpens.OrderByDescending(p => p.Value)
.ToDictionary(p => p.Key, p => p.Value);
.ToDictionary(p => p.Key, p => p.Value);
foreach (var (searchViewItem, i) in sortedDict)
{
//Log.Debug("添加搜索结果" + searchViewItem.OnlyKey);
Expand Down Expand Up @@ -582,29 +590,32 @@ partial void OnSearchChanged(string? value)
};
Items.Add(searchViewItem);


var item = new SearchViewItem()
{
ItemDisplayName = "执行命令:" + value,
FileType = FileType.命令,
OnlyKey = value,
Icon = null,
IconSymbol = 61039,
IsVisible = true
};
Items.Add(item);



}
}
}

var strings = Search.Split(" ");
if (strings.Length > 1)
var first = value.Split(" ").First();
foreach (var se in knownCommand)
{
for (var index = 1; index < strings.Length; index++)
if (se.Equals(first))
{
ReSearch(strings[index]);
var item = new SearchViewItem()
{
ItemDisplayName = "执行命令:" + value,
FileType = FileType.命令,
OnlyKey = value,
Icon = null,
IconSymbol = 61039,
IsVisible = true
};
Items.Insert(0,item);
}
}


});
}

Expand Down
3 changes: 2 additions & 1 deletion KitopiaAvalonia/Converter/SearchWindow/ItemNameMatchCtr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ public class ItemNameMatchCtr : IValueConverter
return new InlineCollection();
}
InlineCollection list = new();
if (str.CharMatchResults.Length !=str.SplitWords.Length)
if (str.CharMatchResults.Length !=str.SplitWords.Length|| str.CharMatchResults.Length==0)
{
list.Add(new Run(str.ItemDisplayName));
return list;
}


for (int i = 0; i < str.SplitWords.Length; i++)
{

Expand Down
3 changes: 2 additions & 1 deletion KitopiaAvalonia/Windows/SearchWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
ShowInTaskbar="False"
ExtendClientAreaToDecorationsHint="True"
Width="800"

SizeToContent="Height"
ExtendClientAreaChromeHints="SystemChrome"
SystemDecorations="BorderOnly"
Expand Down Expand Up @@ -56,7 +57,7 @@
IsOpen="{Binding EverythingIsOk, Converter={StaticResource ReverseBool}}"
IsVisible="{Binding EverythingIsOk}"
IsClosable="False" />
<ListBox Name="dataGrid" MaxHeight="415"
<ListBox Name="dataGrid" MaxHeight="427"
ItemsSource="{Binding Items,Mode=OneWay }"
KeyDown="DataGrid_OnKeyDown"
PointerMoved="DataGrid_OnPointerMoved"
Expand Down

0 comments on commit 0d2caf0

Please sign in to comment.