Merge branch 'dev' into clock

This commit is contained in:
DB p 2022-09-29 17:04:44 +09:00
commit e4fddab306
7 changed files with 131 additions and 12 deletions

View file

@ -197,5 +197,16 @@ 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";
}
}

View file

@ -77,7 +77,6 @@ namespace Flow.Launcher
};
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);

View file

@ -30,7 +30,7 @@
<ListBox.ItemTemplate>
<DataTemplate>
<Button>
<Button HorizontalAlignment="Stretch">
<Button.Template>
<ControlTemplate>
<ContentPresenter Content="{TemplateBinding Button.Content}" />
@ -39,7 +39,7 @@
<Button.Content>
<Grid
Margin="0"
HorizontalAlignment="Left"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Cursor="Hand"
UseLayoutRounding="False">
@ -50,7 +50,7 @@
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="60" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="9*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel
@ -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"
@ -129,12 +133,9 @@
<TextBlock
x:Name="SubTitle"
Grid.Row="1"
MinWidth="750"
Style="{DynamicResource ItemSubTitleStyle}"
Text="{Binding Result.SubTitle}"
ToolTip="{Binding ShowSubTitleToolTip}">
</TextBlock>
ToolTip="{Binding ShowSubTitleToolTip}" />
</Grid>

View file

@ -1621,7 +1621,7 @@
Margin="0,0,18,0"
IsMoveToPointEnabled="True"
IsSnapToTickEnabled="True"
Maximum="900"
Maximum="1920"
Minimum="400"
TickFrequency="10"
Value="{Binding WindowWidthSize, Mode=TwoWay}" />

View file

@ -158,6 +158,21 @@
</Style>
<!-- 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" />

View file

@ -77,6 +77,92 @@ 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";
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);
@ -208,4 +294,4 @@ namespace Flow.Launcher.Plugin.Explorer.Search
Folder,
File
}
}
}

View file

@ -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();