@@ -77,12 +77,53 @@ internal static Result CreateFolderResult(string title, string subtitle, string
77
77
} ;
78
78
}
79
79
80
+ internal static Result CreateDriveSpaceDisplayResult ( string path , bool windowsIndexed = false )
81
+ {
82
+ var progressBarColor = "#26a0da" ;
83
+ int ? progressValue = null ;
84
+ var title = string . Empty ; // hide title when use progress bar,
85
+ var driveLetter = path . Substring ( 0 , 1 ) . ToUpper ( ) ;
86
+ var driveName = driveLetter + ":\\ " ;
87
+ DriveInfo drv = new DriveInfo ( driveLetter ) ;
88
+ var subtitle = toReadableSize ( drv . AvailableFreeSpace , 2 ) + " free of " + toReadableSize ( drv . TotalSize , 2 ) ;
89
+ double UsingSize = ( Convert . ToDouble ( drv . TotalSize ) - Convert . ToDouble ( drv . AvailableFreeSpace ) ) / Convert . ToDouble ( drv . TotalSize ) * 100 ;
90
+
91
+ progressValue = Convert . ToInt32 ( UsingSize ) ;
92
+
93
+ if ( progressValue >= 90 )
94
+ progressBarColor = "#da2626" ;
95
+
96
+ return new Result
97
+ {
98
+ Title = title ,
99
+ SubTitle = subtitle ,
100
+ AutoCompleteText = GetPathWithActionKeyword ( path , ResultType . Folder ) ,
101
+ IcoPath = path ,
102
+ Score = 500 ,
103
+ ProgressBar = progressValue ,
104
+ ProgressBarColor = progressBarColor ,
105
+ Action = c =>
106
+ {
107
+ Context . API . OpenDirectory ( path ) ;
108
+ return true ;
109
+ } ,
110
+ TitleToolTip = path ,
111
+ SubTitleToolTip = path ,
112
+ ContextData = new SearchResult
113
+ {
114
+ Type = ResultType . Folder ,
115
+ FullPath = path ,
116
+ ShowIndexState = true ,
117
+ WindowsIndexed = windowsIndexed
118
+ }
119
+ } ;
120
+ }
121
+
80
122
private static string toReadableSize ( long pDrvSize , int pi )
81
123
{
82
124
int mok = 0 ;
83
125
double drvSize = pDrvSize ;
84
126
string Space = "Byte" ;
85
- string returnStr = "" ;
86
127
87
128
while ( drvSize > 1024.0 )
88
129
{
@@ -91,25 +132,33 @@ private static string toReadableSize(long pDrvSize, int pi)
91
132
}
92
133
93
134
if ( mok == 1 )
94
- Space = "KB" ;
135
+ Space = "KB" ;
95
136
else if ( mok == 2 )
96
137
Space = " MB" ;
97
138
else if ( mok == 3 )
98
139
Space = " GB" ;
99
140
else if ( mok == 4 )
100
141
Space = " TB" ;
101
142
143
+ var returnStr = string . Format ( "{0}{1}" , Convert . ToInt32 ( drvSize ) , Space ) ;
102
144
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 ) ;
145
+ {
146
+ switch ( pi )
147
+ {
148
+ case 1 :
149
+ returnStr = string . Format ( "{0:F1}{1}" , drvSize , Space ) ;
150
+ break ;
151
+ case 2 :
152
+ returnStr = string . Format ( "{0:F2}{1}" , drvSize , Space ) ;
153
+ break ;
154
+ case 3 :
155
+ returnStr = string . Format ( "{0:F3}{1}" , drvSize , Space ) ;
156
+ break ;
157
+ default :
158
+ returnStr = string . Format ( "{0}{1}" , Convert . ToInt32 ( drvSize ) , Space ) ;
159
+ break ;
160
+ }
161
+ }
113
162
114
163
return returnStr ;
115
164
}
@@ -123,28 +172,19 @@ internal static Result CreateOpenCurrentFolderResult(string path, bool windowsIn
123
172
Path . DirectorySeparatorChar
124
173
} , StringSplitOptions . None ) . Last ( ) ;
125
174
126
- var title = "Open current directory" ;
127
-
128
- if ( retrievedDirectoryPath != path )
129
- title = "Open " + folderName ;
130
-
131
- var subtitleFolderName = folderName ;
132
- var subtitle = $ "Use > to search within { subtitleFolderName } , " +
133
- $ "* to search for file extensions or >* to combine both searches.";
134
-
135
- int ? progressBar = null ;
136
175
if ( retrievedDirectoryPath . EndsWith ( ":\\ " ) )
137
176
{
138
- title = "" ; // hide title when use progress bar,
139
177
var driveLetter = path . Substring ( 0 , 1 ) . ToUpper ( ) ;
140
178
folderName = driveLetter + " drive" ;
141
- var driveName = driveLetter + ":\\ " ;
142
- DriveInfo drv = new DriveInfo ( driveLetter ) ;
143
- subtitle = toReadableSize ( drv . AvailableFreeSpace , 2 ) + " free of " + toReadableSize ( drv . TotalSize , 2 ) ;
144
- double UsingSize = ( ( Convert . ToDouble ( drv . TotalSize ) - Convert . ToDouble ( drv . AvailableFreeSpace ) ) / Convert . ToDouble ( drv . TotalSize ) * 100 ) ;
145
- progressBar = Convert . ToInt32 ( UsingSize ) ;
146
179
}
147
180
181
+ var title = "Open current directory" ;
182
+
183
+ if ( retrievedDirectoryPath != path )
184
+ title = "Open " + folderName ;
185
+
186
+
187
+ var subtitleFolderName = folderName ;
148
188
149
189
// ie. max characters can be displayed without subtitle cutting off: "Program Files (x86)"
150
190
if ( folderName . Length > 19 )
@@ -153,11 +193,11 @@ internal static Result CreateOpenCurrentFolderResult(string path, bool windowsIn
153
193
return new Result
154
194
{
155
195
Title = title ,
156
- SubTitle = subtitle ,
196
+ SubTitle = $ "Use > to search within { subtitleFolderName } , " +
197
+ $ "* to search for file extensions or >* to combine both searches.",
157
198
AutoCompleteText = GetPathWithActionKeyword ( retrievedDirectoryPath , ResultType . Folder ) ,
158
199
IcoPath = retrievedDirectoryPath ,
159
200
Score = 500 ,
160
- ProgressBar = progressBar ,
161
201
Action = c =>
162
202
{
163
203
Context . API . OpenDirectory ( retrievedDirectoryPath ) ;
0 commit comments