Skip to content

Commit

Permalink
Merge branch 'dev' into QuickSizeAdjust & Work around dotnet/wpf#6792
Browse files Browse the repository at this point in the history
  • Loading branch information
taooceros committed Sep 27, 2022
1 parent 01c9be3 commit 0baf04e
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 9 deletions.
11 changes: 11 additions & 0 deletions Flow.Launcher.Plugin/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,5 +197,16 @@ public ValueTask<bool> ExecuteAsync(ActionContext context)
{
return AsyncAction?.Invoke(context) ?? ValueTask.FromResult(Action?.Invoke(context) ?? false);
}

/// <summary>
/// Progress bar display. Providing an int value between 0-100 will trigger the progress bar to be displayed on the result
/// </summary>
public int? ProgressBar { get; set; }

/// <summary>
/// Optionally set the color of the progress bar
/// </summary>
/// <default>#26a0da (blue)</default>
public string ProgressBarColor { get; set; } = "#26a0da";
}
}
10 changes: 10 additions & 0 deletions Flow.Launcher/Flow.Launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,14 @@
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="taskkill /f /fi &quot;IMAGENAME eq Flow.Launcher.exe&quot;" />
</Target>

<Target Name="RemoveDuplicateAnalyzers" BeforeTargets="CoreCompile">
<!-- Work around https://github.com/dotnet/wpf/issues/6792 -->

<ItemGroup>
<FilteredAnalyzer Include="@(Analyzer->Distinct())" />
<Analyzer Remove="@(Analyzer)" />
<Analyzer Include="@(FilteredAnalyzer)" />
</ItemGroup>
</Target>
</Project>
1 change: 0 additions & 1 deletion Flow.Launcher/ReportWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ private Paragraph Hyperlink(string textBeforeUrl, string url)
};
link.Inlines.Add(url);
link.NavigateUri = new Uri(url);
link.RequestNavigate += (s, e) => SearchWeb.OpenInBrowserTab(e.Uri.ToString());
link.Click += (s, e) => SearchWeb.OpenInBrowserTab(url);

paragraph.Inlines.Add(textBeforeUrl);
Expand Down
6 changes: 5 additions & 1 deletion Flow.Launcher/ResultListBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@
<RowDefinition />
<RowDefinition x:Name="SubTitleRowDefinition" Height="Auto" />
</Grid.RowDefinitions>

<ProgressBar
x:Name="progressbarResult"
Foreground="{Binding Result.ProgressBarColor}"
Style="{DynamicResource ProgressBarResult}"
Value="{Binding Result.ProgressBar}" />
<TextBlock
x:Name="Title"
VerticalAlignment="Center"
Expand Down
15 changes: 15 additions & 0 deletions Flow.Launcher/Themes/Base.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@


<!-- Item Style -->
<Style x:Key="ProgressBarResult" TargetType="{x:Type ProgressBar}">
<Setter Property="Height" Value="18" />
<Setter Property="Margin" Value="0,0,0,4" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Maximum" Value="100" />
<Setter Property="Minimum" Value="0" />
<Setter Property="Visibility" Value="Visible" />
<Setter Property="Foreground" Value="#26a0da " />
<Style.Triggers>
<DataTrigger Binding="{Binding Result.ProgressBar}" Value="{x:Null}">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>

<Style x:Key="BaseItemTitleStyle" TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="#FFFFF8" />
<Setter Property="FontSize" Value="16" />
Expand Down
88 changes: 87 additions & 1 deletion Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,92 @@ internal static Result CreateFolderResult(string title, string subtitle, string
};
}

internal static Result CreateDriveSpaceDisplayResult(string path, bool windowsIndexed = false)
{
var progressBarColor = "#26a0da";
int? progressValue = null;
var title = string.Empty; // hide title when use progress bar,
var driveLetter = path.Substring(0, 1).ToUpper();
var driveName = driveLetter + ":\\";
DriveInfo drv = new DriveInfo(driveLetter);
var subtitle = toReadableSize(drv.AvailableFreeSpace, 2) + " free of " + toReadableSize(drv.TotalSize, 2);
double UsingSize = (Convert.ToDouble(drv.TotalSize) - Convert.ToDouble(drv.AvailableFreeSpace)) / Convert.ToDouble(drv.TotalSize) * 100;

progressValue = Convert.ToInt32(UsingSize);

if (progressValue >= 90)
progressBarColor = "#da2626";

return new Result
{
Title = title,
SubTitle = subtitle,
AutoCompleteText = GetPathWithActionKeyword(path, ResultType.Folder),
IcoPath = path,
Score = 500,
ProgressBar = progressValue,
ProgressBarColor = progressBarColor,
Action = c =>
{
Context.API.OpenDirectory(path);
return true;
},
TitleToolTip = path,
SubTitleToolTip = path,
ContextData = new SearchResult
{
Type = ResultType.Folder,
FullPath = path,
ShowIndexState = true,
WindowsIndexed = windowsIndexed
}
};
}

private static string toReadableSize(long pDrvSize, int pi)
{
int mok = 0;
double drvSize = pDrvSize;
string Space = "Byte";

while (drvSize > 1024.0)
{
drvSize /= 1024.0;
mok++;
}

if (mok == 1)
Space = "KB";
else if (mok == 2)
Space = " MB";
else if (mok == 3)
Space = " GB";
else if (mok == 4)
Space = " TB";

var returnStr = string.Format("{0}{1}", Convert.ToInt32(drvSize), Space);
if (mok != 0)
{
switch (pi)
{
case 1:
returnStr = string.Format("{0:F1}{1}", drvSize, Space);
break;
case 2:
returnStr = string.Format("{0:F2}{1}", drvSize, Space);
break;
case 3:
returnStr = string.Format("{0:F3}{1}", drvSize, Space);
break;
default:
returnStr = string.Format("{0}{1}", Convert.ToInt32(drvSize), Space);
break;
}
}

return returnStr;
}

internal static Result CreateOpenCurrentFolderResult(string path, bool windowsIndexed = false)
{
var retrievedDirectoryPath = FilesFolders.ReturnPreviousDirectoryIfIncompleteString(path);
Expand Down Expand Up @@ -208,4 +294,4 @@ public enum ResultType
Folder,
File
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,14 @@ public async Task<List<Result>> PathSearchAsync(Query query, CancellationToken t

var useIndexSearch = UseWindowsIndexForDirectorySearch(locationPath);

results.Add(ResultManager.CreateOpenCurrentFolderResult(locationPath, useIndexSearch));
if (locationPath.EndsWith(":\\"))
{
results.Add(ResultManager.CreateDriveSpaceDisplayResult(locationPath, useIndexSearch));
}
else
{
results.Add(ResultManager.CreateOpenCurrentFolderResult(locationPath, useIndexSearch));
}

token.ThrowIfCancellationRequested();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Flow.Launcher.Infrastructure.Logger;
using Flow.Launcher.Infrastructure.Logger;
using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks;
using Microsoft.Search.Interop;
using System;
Expand All @@ -17,7 +17,7 @@ internal static class IndexSearch
{

// Reserved keywords in oleDB
private const string reservedStringPattern = @"^[`\@\#\^,\&\/\\\$\%_;\[\]]+$";
private const string reservedStringPattern = @"^[`\@\@\#\#\*\^,\&\&\/\\\$\%_;\[\]]+$";

internal static async Task<List<Result>> ExecuteWindowsIndexSearchAsync(string indexQueryString, string connectionString, Query query, CancellationToken token)
{
Expand All @@ -29,7 +29,7 @@ internal static async Task<List<Result>> ExecuteWindowsIndexSearchAsync(string i
await using var conn = new OleDbConnection(connectionString);
await conn.OpenAsync(token);
token.ThrowIfCancellationRequested();

await using var command = new OleDbCommand(indexQueryString, conn);
// Results return as an OleDbDataReader.
await using var dataReaderResults = await command.ExecuteReaderAsync(token) as OleDbDataReader;
Expand Down
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "6.0.100",
"rollForward": "latestFeature"
"version": "6.0.*",
"rollForward": "latestPatch"
}
}

0 comments on commit 0baf04e

Please sign in to comment.