Skip to content

Commit 4bc3367

Browse files
committed
- Add 'Free Space in drive'
- when Type "d:\", showing graph with free space.
1 parent fabb396 commit 4bc3367

File tree

4 files changed

+82
-14
lines changed

4 files changed

+82
-14
lines changed

Flow.Launcher.Plugin/Result.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,5 +197,7 @@ public ValueTask<bool> ExecuteAsync(ActionContext context)
197197
{
198198
return AsyncAction?.Invoke(context) ?? ValueTask.FromResult(Action?.Invoke(context) ?? false);
199199
}
200+
201+
public int? ProgressBar { get; set; }
200202
}
201203
}

Flow.Launcher/ResultListBox.xaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@
111111
<RowDefinition />
112112
<RowDefinition x:Name="SubTitleRowDefinition" Height="Auto" />
113113
</Grid.RowDefinitions>
114-
114+
<ProgressBar
115+
x:Name="progressbarResult"
116+
Style="{DynamicResource ProgressBarResult}"
117+
Value="{Binding Result.ProgressBar}" />
115118
<TextBlock
116119
x:Name="Title"
117120
VerticalAlignment="Center"
@@ -132,9 +135,7 @@
132135
MinWidth="750"
133136
Style="{DynamicResource ItemSubTitleStyle}"
134137
Text="{Binding Result.SubTitle}"
135-
ToolTip="{Binding ShowSubTitleToolTip}">
136-
137-
</TextBlock>
138+
ToolTip="{Binding ShowSubTitleToolTip}" />
138139

139140
</Grid>
140141

Flow.Launcher/Themes/Base.xaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,21 @@
8181

8282

8383
<!-- Item Style -->
84+
<Style x:Key="ProgressBarResult" TargetType="{x:Type ProgressBar}">
85+
<Setter Property="Height" Value="18" />
86+
<Setter Property="Margin" Value="0,0,0,4" />
87+
<Setter Property="VerticalAlignment" Value="Center" />
88+
<Setter Property="Maximum" Value="100" />
89+
<Setter Property="Minimum" Value="0" />
90+
<Setter Property="Visibility" Value="Visible" />
91+
<Setter Property="Foreground" Value="#26a0da " />
92+
<Style.Triggers>
93+
<DataTrigger Binding="{Binding Result.ProgressBar}" Value="{x:Null}">
94+
<Setter Property="Visibility" Value="Collapsed" />
95+
</DataTrigger>
96+
</Style.Triggers>
97+
</Style>
98+
8499
<Style x:Key="BaseItemTitleStyle" TargetType="{x:Type TextBlock}">
85100
<Setter Property="Foreground" Value="#FFFFF8" />
86101
<Setter Property="FontSize" Value="16" />

Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,43 @@ internal static Result CreateFolderResult(string title, string subtitle, string
7777
};
7878
}
7979

80+
private static string toReadableSize(long pDrvSize, int pi)
81+
{
82+
int mok = 0;
83+
double drvSize = pDrvSize;
84+
string Space = "Byte";
85+
string returnStr = "";
86+
87+
while (drvSize > 1024.0)
88+
{
89+
drvSize /= 1024.0;
90+
mok++;
91+
}
92+
93+
if (mok == 1)
94+
Space = "KB";
95+
else if (mok == 2)
96+
Space = " MB";
97+
else if (mok == 3)
98+
Space = " GB";
99+
else if (mok == 4)
100+
Space = " TB";
101+
102+
if (mok != 0)
103+
if (pi == 1)
104+
returnStr = string.Format("{0:F1}{1}", drvSize, Space);
105+
else if (pi == 2)
106+
returnStr = string.Format("{0:F2}{1}", drvSize, Space);
107+
else if (pi == 3)
108+
returnStr = string.Format("{0:F3}{1}", drvSize, Space);
109+
else
110+
returnStr = string.Format("{0}{1}", Convert.ToInt32(drvSize), Space);
111+
else
112+
returnStr = string.Format("{0}{1}", Convert.ToInt32(drvSize), Space);
113+
114+
return returnStr;
115+
}
116+
80117
internal static Result CreateOpenCurrentFolderResult(string path, bool windowsIndexed = false)
81118
{
82119
var retrievedDirectoryPath = FilesFolders.ReturnPreviousDirectoryIfIncompleteString(path);
@@ -86,19 +123,32 @@ internal static Result CreateOpenCurrentFolderResult(string path, bool windowsIn
86123
Path.DirectorySeparatorChar
87124
}, StringSplitOptions.None).Last();
88125

89-
if (retrievedDirectoryPath.EndsWith(":\\"))
90-
{
91-
var driveLetter = path.Substring(0, 1).ToUpper();
92-
folderName = driveLetter + " drive";
93-
}
94-
95126
var title = "Open current directory";
96127

97128
if (retrievedDirectoryPath != path)
98129
title = "Open " + folderName;
99130

100-
101131
var subtitleFolderName = folderName;
132+
var subtitle = $"Use > to search within {subtitleFolderName}, " +
133+
$"* to search for file extensions or >* to combine both searches.";
134+
135+
136+
137+
138+
139+
int? progressBar = null;
140+
if (retrievedDirectoryPath.EndsWith(":\\"))
141+
{
142+
title = ""; // hide title when use progress bar,
143+
var driveLetter = path.Substring(0, 1).ToUpper();
144+
folderName = driveLetter + " drive";
145+
var driveName = driveLetter + ":\\";
146+
DriveInfo drv = new DriveInfo(driveLetter);
147+
subtitle = toReadableSize(drv.AvailableFreeSpace, 2) + " free of " + toReadableSize(drv.TotalSize, 2);
148+
double UsingSize = ((Convert.ToDouble(drv.TotalSize) - Convert.ToDouble(drv.AvailableFreeSpace)) / Convert.ToDouble(drv.TotalSize) * 100);
149+
progressBar = Convert.ToInt32(UsingSize);
150+
}
151+
102152

103153
// ie. max characters can be displayed without subtitle cutting off: "Program Files (x86)"
104154
if (folderName.Length > 19)
@@ -107,11 +157,11 @@ internal static Result CreateOpenCurrentFolderResult(string path, bool windowsIn
107157
return new Result
108158
{
109159
Title = title,
110-
SubTitle = $"Use > to search within {subtitleFolderName}, " +
111-
$"* to search for file extensions or >* to combine both searches.",
160+
SubTitle = subtitle,
112161
AutoCompleteText = GetPathWithActionKeyword(retrievedDirectoryPath, ResultType.Folder),
113162
IcoPath = retrievedDirectoryPath,
114163
Score = 500,
164+
ProgressBar = progressBar,
115165
Action = c =>
116166
{
117167
Context.API.OpenDirectory(retrievedDirectoryPath);
@@ -208,4 +258,4 @@ public enum ResultType
208258
Folder,
209259
File
210260
}
211-
}
261+
}

0 commit comments

Comments
 (0)