@@ -77,12 +77,53 @@ internal static Result CreateFolderResult(string title, string subtitle, string
7777 } ;
7878 }
7979
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+
80122 private static string toReadableSize ( long pDrvSize , int pi )
81123 {
82124 int mok = 0 ;
83125 double drvSize = pDrvSize ;
84126 string Space = "Byte" ;
85- string returnStr = "" ;
86127
87128 while ( drvSize > 1024.0 )
88129 {
@@ -91,25 +132,33 @@ private static string toReadableSize(long pDrvSize, int pi)
91132 }
92133
93134 if ( mok == 1 )
94- Space = "KB" ;
135+ Space = "KB" ;
95136 else if ( mok == 2 )
96137 Space = " MB" ;
97138 else if ( mok == 3 )
98139 Space = " GB" ;
99140 else if ( mok == 4 )
100141 Space = " TB" ;
101142
143+ var returnStr = string . Format ( "{0}{1}" , Convert . ToInt32 ( drvSize ) , Space ) ;
102144 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+ }
113162
114163 return returnStr ;
115164 }
@@ -123,28 +172,19 @@ internal static Result CreateOpenCurrentFolderResult(string path, bool windowsIn
123172 Path . DirectorySeparatorChar
124173 } , StringSplitOptions . None ) . Last ( ) ;
125174
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 ;
136175 if ( retrievedDirectoryPath . EndsWith ( ":\\ " ) )
137176 {
138- title = "" ; // hide title when use progress bar,
139177 var driveLetter = path . Substring ( 0 , 1 ) . ToUpper ( ) ;
140178 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 ) ;
146179 }
147180
181+ var title = "Open current directory" ;
182+
183+ if ( retrievedDirectoryPath != path )
184+ title = "Open " + folderName ;
185+
186+
187+ var subtitleFolderName = folderName ;
148188
149189 // ie. max characters can be displayed without subtitle cutting off: "Program Files (x86)"
150190 if ( folderName . Length > 19 )
@@ -153,11 +193,11 @@ internal static Result CreateOpenCurrentFolderResult(string path, bool windowsIn
153193 return new Result
154194 {
155195 Title = title ,
156- SubTitle = subtitle ,
196+ SubTitle = $ "Use > to search within { subtitleFolderName } , " +
197+ $ "* to search for file extensions or >* to combine both searches.",
157198 AutoCompleteText = GetPathWithActionKeyword ( retrievedDirectoryPath , ResultType . Folder ) ,
158199 IcoPath = retrievedDirectoryPath ,
159200 Score = 500 ,
160- ProgressBar = progressBar ,
161201 Action = c =>
162202 {
163203 Context . API . OpenDirectory ( retrievedDirectoryPath ) ;
0 commit comments