Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions Flow.Launcher.Core/Plugin/QueryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,31 @@ public static class QueryBuilder
public static Query Build(string text, Dictionary<string, PluginPair> nonGlobalPlugins)
{
// replace multiple white spaces with one white space
var terms = text.Split(new[] { Query.TermSeperater }, StringSplitOptions.RemoveEmptyEntries);
var terms = text.Split(Query.TermSeparator, StringSplitOptions.RemoveEmptyEntries);
if (terms.Length == 0)
{ // nothing was typed
return null;
}

var rawQuery = string.Join(Query.TermSeperater, terms);
var rawQuery = string.Join(Query.TermSeparator, terms);
string actionKeyword, search;
string possibleActionKeyword = terms[0];
List<string> actionParameters;
string[] searchTerms;

if (nonGlobalPlugins.TryGetValue(possibleActionKeyword, out var pluginPair) && !pluginPair.Metadata.Disabled)
{ // use non global plugin for query
actionKeyword = possibleActionKeyword;
actionParameters = terms.Skip(1).ToList();
search = actionParameters.Count > 0 ? rawQuery.Substring(actionKeyword.Length + 1) : string.Empty;
search = terms.Length > 1 ? rawQuery[(actionKeyword.Length + 1)..] : string.Empty;
searchTerms = terms[1..];
}
else
{ // non action keyword
actionKeyword = string.Empty;
search = rawQuery;
searchTerms = terms;
}

var query = new Query
{
Terms = terms,
RawQuery = rawQuery,
ActionKeyword = actionKeyword,
Search = search
};
var query = new Query(rawQuery, search,terms, searchTerms, actionKeyword);

return query;
}
Expand Down
55 changes: 29 additions & 26 deletions Flow.Launcher.Plugin/Query.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using JetBrains.Annotations;
using System;
using System.Collections.Generic;
using System.Linq;

Expand All @@ -11,65 +12,74 @@ public Query() { }
/// <summary>
/// to allow unit tests for plug ins
/// </summary>
public Query(string rawQuery, string search, string[] terms, string actionKeyword = "")
public Query(string rawQuery, string search, string[] terms, string[] searchTerms, string actionKeyword = "")
{
Search = search;
RawQuery = rawQuery;
Terms = terms;
SearchTerms = searchTerms;
ActionKeyword = actionKeyword;
}

/// <summary>
/// Raw query, this includes action keyword if it has
/// We didn't recommend use this property directly. You should always use Search property.
/// </summary>
public string RawQuery { get; internal set; }
public string RawQuery { get; internal init; }

/// <summary>
/// Search part of a query.
/// This will not include action keyword if exclusive plugin gets it, otherwise it should be same as RawQuery.
/// Since we allow user to switch a exclusive plugin to generic plugin,
/// so this property will always give you the "real" query part of the query
/// </summary>
public string Search { get; internal set; }
public string Search { get; internal init; }

/// <summary>
/// The raw query splited into a string array.
/// The search string split into a string array.
/// </summary>
public string[] Terms { get; set; }
public string[] SearchTerms { get; init; }

/// <summary>
/// The raw query split into a string array
/// </summary>
[Obsolete("It may or may not include action keyword, which can be confusing. Use SearchTerms instead")]
public string[] Terms { get; init; }

/// <summary>
/// Query can be splited into multiple terms by whitespace
/// </summary>
public const string TermSeperater = " ";
public const string TermSeparator = " ";

[Obsolete("Typo")]
public const string TermSeperater = TermSeparator;
/// <summary>
/// User can set multiple action keywords seperated by ';'
/// </summary>
public const string ActionKeywordSeperater = ";";
public const string ActionKeywordSeparator = ";";

[Obsolete("Typo")]
public const string ActionKeywordSeperater = ActionKeywordSeparator;


/// <summary>
/// '*' is used for System Plugin
/// </summary>
public const string GlobalPluginWildcardSign = "*";

public string ActionKeyword { get; set; }
public string ActionKeyword { get; init; }

/// <summary>
/// Return first search split by space if it has
/// </summary>
public string FirstSearch => SplitSearch(0);

private string _secondToEndSearch;

/// <summary>
/// strings from second search (including) to last search
/// </summary>
public string SecondToEndSearch
{
get
{
var index = string.IsNullOrEmpty(ActionKeyword) ? 1 : 2;
return string.Join(TermSeperater, Terms.Skip(index).ToArray());
}
}
public string SecondToEndSearch => SearchTerms.Length > 1 ? (_secondToEndSearch ??= string.Join(' ', SearchTerms[1..])) : "";

/// <summary>
/// Return second search split by space if it has
Expand All @@ -83,16 +93,9 @@ public string SecondToEndSearch

private string SplitSearch(int index)
{
try
{
return string.IsNullOrEmpty(ActionKeyword) ? Terms[index] : Terms[index + 1];
}
catch (IndexOutOfRangeException)
{
return string.Empty;
}
return index < SearchTerms.Length ? SearchTerms[index] : string.Empty;
}

public override string ToString() => RawQuery;
}
}
}
2 changes: 1 addition & 1 deletion Flow.Launcher/ActionKeywords.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public ActionKeywords(string pluginId, Settings settings, PluginViewModel plugin

private void ActionKeyword_OnLoaded(object sender, RoutedEventArgs e)
{
tbOldActionKeyword.Text = string.Join(Query.ActionKeywordSeperater, plugin.Metadata.ActionKeywords.ToArray());
tbOldActionKeyword.Text = string.Join(Query.ActionKeywordSeparator, plugin.Metadata.ActionKeywords.ToArray());
tbAction.Focus();
}

Expand Down
2 changes: 1 addition & 1 deletion Flow.Launcher/ViewModel/PluginViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public bool PluginState
public Visibility ActionKeywordsVisibility => PluginPair.Metadata.ActionKeywords.Count == 1 ? Visibility.Visible : Visibility.Collapsed;
public string InitilizaTime => PluginPair.Metadata.InitTime.ToString() + "ms";
public string QueryTime => PluginPair.Metadata.AvgQueryTime + "ms";
public string ActionKeywordsText => string.Join(Query.ActionKeywordSeperater, PluginPair.Metadata.ActionKeywords);
public string ActionKeywordsText => string.Join(Query.ActionKeywordSeparator, PluginPair.Metadata.ActionKeywords);
public int Priority => PluginPair.Metadata.Priority;

public void ChangeActionKeyword(string newActionKeyword, string oldActionKeyword)
Expand Down
6 changes: 3 additions & 3 deletions Plugins/Flow.Launcher.Plugin.PluginIndicator/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public List<Result> Query(Query query)
{
// if query contains more than one word, eg. github tips
// user has decided to type something else rather than wanting to see the available action keywords
if (query.Terms.Length > 1)
if (query.SearchTerms.Length > 1)
return new List<Result>();

var results = from keyword in PluginManager.NonGlobalPlugins.Keys
where keyword.StartsWith(query.Terms[0])
where keyword.StartsWith(query.SearchTerms[0])
let metadata = PluginManager.NonGlobalPlugins[keyword].Metadata
where !metadata.Disabled
select new Result
Expand All @@ -27,7 +27,7 @@ where keyword.StartsWith(query.Terms[0])
IcoPath = metadata.IcoPath,
Action = c =>
{
context.API.ChangeQuery($"{keyword}{Plugin.Query.TermSeperater}");
context.API.ChangeQuery($"{keyword}{Plugin.Query.TermSeparator}");
return false;
}
};
Expand Down
4 changes: 1 addition & 3 deletions Plugins/Flow.Launcher.Plugin.ProcessKiller/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ public void Init(PluginInitContext context)

public List<Result> Query(Query query)
{
var termToSearch = query.Terms.Length <= 1
? null
: string.Join(Plugin.Query.TermSeperater, query.Terms.Skip(1)).ToLower();
var termToSearch = query.Search;

var processlist = processHelper.GetMatchingProcesses(termToSearch);

Expand Down
2 changes: 1 addition & 1 deletion Plugins/Flow.Launcher.Plugin.Shell/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ bool API_GlobalKeyboardEvent(int keyevent, int vkcode, SpecialKeyState state)

private void OnWinRPressed()
{
context.API.ChangeQuery($"{context.CurrentPluginMetadata.ActionKeywords[0]}{Plugin.Query.TermSeperater}");
context.API.ChangeQuery($"{context.CurrentPluginMetadata.ActionKeywords[0]}{Plugin.Query.TermSeparator}");

// show the main window and set focus to the query box
Window mainWindow = Application.Current.MainWindow;
Expand Down