mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
allow progress bar customisation via plugin
This commit is contained in:
parent
b62ab1d0aa
commit
e23eb94caf
5 changed files with 88 additions and 65 deletions
|
|
@ -198,6 +198,15 @@ namespace Flow.Launcher.Plugin
|
||||||
return AsyncAction?.Invoke(context) ?? ValueTask.FromResult(Action?.Invoke(context) ?? false);
|
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; }
|
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";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Globalization;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows.Data;
|
|
||||||
using System.Windows.Media;
|
|
||||||
|
|
||||||
namespace Flow.Launcher.Converters
|
|
||||||
{
|
|
||||||
public class ProgressForegroundConverter : IValueConverter
|
|
||||||
{
|
|
||||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
||||||
{
|
|
||||||
double progress = (double)value;
|
|
||||||
string foreground = "#26a0da";
|
|
||||||
|
|
||||||
if (progress >= 90)
|
|
||||||
{
|
|
||||||
foreground = "#da2626";
|
|
||||||
}
|
|
||||||
|
|
||||||
return foreground;
|
|
||||||
}
|
|
||||||
|
|
||||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -46,7 +46,6 @@
|
||||||
<Grid.Resources>
|
<Grid.Resources>
|
||||||
<converter:HighlightTextConverter x:Key="HighlightTextConverter" />
|
<converter:HighlightTextConverter x:Key="HighlightTextConverter" />
|
||||||
<converter:OrdinalConverter x:Key="OrdinalConverter" />
|
<converter:OrdinalConverter x:Key="OrdinalConverter" />
|
||||||
<converter:ProgressForegroundConverter x:Key="ProgressForegroundConverter" />
|
|
||||||
<converter:OpenResultHotkeyVisibilityConverter x:Key="OpenResultHotkeyVisibilityConverter" />
|
<converter:OpenResultHotkeyVisibilityConverter x:Key="OpenResultHotkeyVisibilityConverter" />
|
||||||
</Grid.Resources>
|
</Grid.Resources>
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
|
|
@ -114,7 +113,7 @@
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
x:Name="progressbarResult"
|
x:Name="progressbarResult"
|
||||||
Foreground="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Value, Converter={StaticResource ProgressForegroundConverter}}"
|
Foreground="{Binding Result.ProgressBarColor}"
|
||||||
Style="{DynamicResource ProgressBarResult}"
|
Style="{DynamicResource ProgressBarResult}"
|
||||||
Value="{Binding Result.ProgressBar}" />
|
Value="{Binding Result.ProgressBar}" />
|
||||||
<TextBlock
|
<TextBlock
|
||||||
|
|
|
||||||
|
|
@ -77,12 +77,53 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
private static string toReadableSize(long pDrvSize, int pi)
|
||||||
{
|
{
|
||||||
int mok = 0;
|
int mok = 0;
|
||||||
double drvSize = pDrvSize;
|
double drvSize = pDrvSize;
|
||||||
string Space = "Byte";
|
string Space = "Byte";
|
||||||
string returnStr = "";
|
|
||||||
|
|
||||||
while (drvSize > 1024.0)
|
while (drvSize > 1024.0)
|
||||||
{
|
{
|
||||||
|
|
@ -91,7 +132,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mok == 1)
|
if (mok == 1)
|
||||||
Space = "KB";
|
Space = "KB";
|
||||||
else if (mok == 2)
|
else if (mok == 2)
|
||||||
Space = " MB";
|
Space = " MB";
|
||||||
else if (mok == 3)
|
else if (mok == 3)
|
||||||
|
|
@ -99,17 +140,25 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
||||||
else if (mok == 4)
|
else if (mok == 4)
|
||||||
Space = " TB";
|
Space = " TB";
|
||||||
|
|
||||||
|
var returnStr = string.Format("{0}{1}", Convert.ToInt32(drvSize), Space);
|
||||||
if (mok != 0)
|
if (mok != 0)
|
||||||
if (pi == 1)
|
{
|
||||||
returnStr = string.Format("{0:F1}{1}", drvSize, Space);
|
switch (pi)
|
||||||
else if (pi == 2)
|
{
|
||||||
returnStr = string.Format("{0:F2}{1}", drvSize, Space);
|
case 1:
|
||||||
else if (pi == 3)
|
returnStr = string.Format("{0:F1}{1}", drvSize, Space);
|
||||||
returnStr = string.Format("{0:F3}{1}", drvSize, Space);
|
break;
|
||||||
else
|
case 2:
|
||||||
returnStr = string.Format("{0}{1}", Convert.ToInt32(drvSize), Space);
|
returnStr = string.Format("{0:F2}{1}", drvSize, Space);
|
||||||
else
|
break;
|
||||||
returnStr = string.Format("{0}{1}", Convert.ToInt32(drvSize), Space);
|
case 3:
|
||||||
|
returnStr = string.Format("{0:F3}{1}", drvSize, Space);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
returnStr = string.Format("{0}{1}", Convert.ToInt32(drvSize), Space);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return returnStr;
|
return returnStr;
|
||||||
}
|
}
|
||||||
|
|
@ -123,28 +172,19 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
||||||
Path.DirectorySeparatorChar
|
Path.DirectorySeparatorChar
|
||||||
}, StringSplitOptions.None).Last();
|
}, StringSplitOptions.None).Last();
|
||||||
|
|
||||||
|
if (retrievedDirectoryPath.EndsWith(":\\"))
|
||||||
|
{
|
||||||
|
var driveLetter = path.Substring(0, 1).ToUpper();
|
||||||
|
folderName = driveLetter + " drive";
|
||||||
|
}
|
||||||
|
|
||||||
var title = "Open current directory";
|
var title = "Open current directory";
|
||||||
|
|
||||||
if (retrievedDirectoryPath != path)
|
if (retrievedDirectoryPath != path)
|
||||||
title = "Open " + folderName;
|
title = "Open " + folderName;
|
||||||
|
|
||||||
|
|
||||||
var subtitleFolderName = folderName;
|
var subtitleFolderName = folderName;
|
||||||
var subtitle = $"Use > to search within {subtitleFolderName}, " +
|
|
||||||
$"* to search for file extensions or >* to combine both searches.";
|
|
||||||
|
|
||||||
int? progressBar = null;
|
|
||||||
if (retrievedDirectoryPath.EndsWith(":\\"))
|
|
||||||
{
|
|
||||||
title = ""; // hide title when use progress bar,
|
|
||||||
var driveLetter = path.Substring(0, 1).ToUpper();
|
|
||||||
folderName = driveLetter + " drive";
|
|
||||||
var driveName = driveLetter + ":\\";
|
|
||||||
DriveInfo drv = new DriveInfo(driveLetter);
|
|
||||||
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);
|
|
||||||
progressBar = Convert.ToInt32(UsingSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ie. max characters can be displayed without subtitle cutting off: "Program Files (x86)"
|
// ie. max characters can be displayed without subtitle cutting off: "Program Files (x86)"
|
||||||
if (folderName.Length > 19)
|
if (folderName.Length > 19)
|
||||||
|
|
@ -153,11 +193,11 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
||||||
return new Result
|
return new Result
|
||||||
{
|
{
|
||||||
Title = title,
|
Title = title,
|
||||||
SubTitle = subtitle,
|
SubTitle = $"Use > to search within {subtitleFolderName}, " +
|
||||||
|
$"* to search for file extensions or >* to combine both searches.",
|
||||||
AutoCompleteText = GetPathWithActionKeyword(retrievedDirectoryPath, ResultType.Folder),
|
AutoCompleteText = GetPathWithActionKeyword(retrievedDirectoryPath, ResultType.Folder),
|
||||||
IcoPath = retrievedDirectoryPath,
|
IcoPath = retrievedDirectoryPath,
|
||||||
Score = 500,
|
Score = 500,
|
||||||
ProgressBar = progressBar,
|
|
||||||
Action = c =>
|
Action = c =>
|
||||||
{
|
{
|
||||||
Context.API.OpenDirectory(retrievedDirectoryPath);
|
Context.API.OpenDirectory(retrievedDirectoryPath);
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,14 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
||||||
|
|
||||||
var useIndexSearch = UseWindowsIndexForDirectorySearch(locationPath);
|
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();
|
token.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue