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);
|
||||
}
|
||||
|
||||
/// <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";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
<converter:HighlightTextConverter x:Key="HighlightTextConverter" />
|
||||
<converter:OrdinalConverter x:Key="OrdinalConverter" />
|
||||
<converter:ProgressForegroundConverter x:Key="ProgressForegroundConverter" />
|
||||
<converter:OpenResultHotkeyVisibilityConverter x:Key="OpenResultHotkeyVisibilityConverter" />
|
||||
</Grid.Resources>
|
||||
<Grid.ColumnDefinitions>
|
||||
|
|
@ -114,7 +113,7 @@
|
|||
</Grid.RowDefinitions>
|
||||
<ProgressBar
|
||||
x:Name="progressbarResult"
|
||||
Foreground="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Value, Converter={StaticResource ProgressForegroundConverter}}"
|
||||
Foreground="{Binding Result.ProgressBarColor}"
|
||||
Style="{DynamicResource ProgressBarResult}"
|
||||
Value="{Binding Result.ProgressBar}" />
|
||||
<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)
|
||||
{
|
||||
int mok = 0;
|
||||
double drvSize = pDrvSize;
|
||||
string Space = "Byte";
|
||||
string returnStr = "";
|
||||
|
||||
while (drvSize > 1024.0)
|
||||
{
|
||||
|
|
@ -91,7 +132,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
|||
}
|
||||
|
||||
if (mok == 1)
|
||||
Space = "KB";
|
||||
Space = "KB";
|
||||
else if (mok == 2)
|
||||
Space = " MB";
|
||||
else if (mok == 3)
|
||||
|
|
@ -99,17 +140,25 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
|||
else if (mok == 4)
|
||||
Space = " TB";
|
||||
|
||||
var returnStr = string.Format("{0}{1}", Convert.ToInt32(drvSize), Space);
|
||||
if (mok != 0)
|
||||
if (pi == 1)
|
||||
returnStr = string.Format("{0:F1}{1}", drvSize, Space);
|
||||
else if (pi == 2)
|
||||
returnStr = string.Format("{0:F2}{1}", drvSize, Space);
|
||||
else if (pi == 3)
|
||||
returnStr = string.Format("{0:F3}{1}", drvSize, Space);
|
||||
else
|
||||
returnStr = string.Format("{0}{1}", Convert.ToInt32(drvSize), Space);
|
||||
else
|
||||
returnStr = string.Format("{0}{1}", Convert.ToInt32(drvSize), Space);
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
|
@ -123,28 +172,19 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
|||
Path.DirectorySeparatorChar
|
||||
}, StringSplitOptions.None).Last();
|
||||
|
||||
if (retrievedDirectoryPath.EndsWith(":\\"))
|
||||
{
|
||||
var driveLetter = path.Substring(0, 1).ToUpper();
|
||||
folderName = driveLetter + " drive";
|
||||
}
|
||||
|
||||
var title = "Open current directory";
|
||||
|
||||
if (retrievedDirectoryPath != path)
|
||||
title = "Open " + 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)"
|
||||
if (folderName.Length > 19)
|
||||
|
|
@ -153,11 +193,11 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
|||
return new Result
|
||||
{
|
||||
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),
|
||||
IcoPath = retrievedDirectoryPath,
|
||||
Score = 500,
|
||||
ProgressBar = progressBar,
|
||||
Action = c =>
|
||||
{
|
||||
Context.API.OpenDirectory(retrievedDirectoryPath);
|
||||
|
|
|
|||
|
|
@ -123,7 +123,14 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
|||
|
||||
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();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue