Changeset 2442
- Timestamp:
- 3/11/2012 8:42:01 AM (15 months ago)
- Location:
- trunk/eraser
- Files:
-
- 3 edited
-
Eraser.Util/ExtensionMethods/IO.cs (modified) (1 diff)
-
Eraser.Util/ExtensionMethods/PathUtil.cs (modified) (2 diffs)
-
Eraser/TaskPropertiesForm.cs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/eraser/Eraser.Util/ExtensionMethods/IO.cs
r2329 r2442 198 198 public static string GetCompactPath(this FileSystemInfo info, int newWidth, Font drawFont) 199 199 { 200 using (Control ctrl = new Control()) 201 { 202 //First check if the source string is too long. 203 Graphics g = ctrl.CreateGraphics(); 204 string longPath = info.FullName; 205 int width = g.MeasureString(longPath, drawFont).ToSize().Width; 206 if (width <= newWidth) 207 return longPath; 208 209 //It is, shorten it. 210 int aveCharWidth = width / longPath.Length; 211 int charCount = newWidth / aveCharWidth; 212 StringBuilder builder = new StringBuilder(); 213 builder.Append(longPath); 214 builder.EnsureCapacity(charCount); 215 216 while (g.MeasureString(builder.ToString(), drawFont).Width > newWidth) 217 { 218 if (!NativeMethods.PathCompactPathEx(builder, longPath, 219 (uint)charCount--, 0)) 220 { 221 return string.Empty; 222 } 223 } 224 225 return builder.ToString(); 226 } 200 return PathUtil.GetCompactPath(info.FullName, newWidth, drawFont); 227 201 } 228 202 -
trunk/eraser/Eraser.Util/ExtensionMethods/PathUtil.cs
r2322 r2442 25 25 using System.Text; 26 26 using System.IO; 27 using System.Drawing; 28 using System.Windows.Forms; 27 29 28 30 namespace Eraser.Util.ExtensionMethods … … 110 112 return true; 111 113 } 114 115 /// <summary> 116 /// Compacts the file path, fitting in the given width. 117 /// </summary> 118 /// <param name="longPath">The path to compact.</param> 119 /// <param name="newWidth">The target width of the text.</param> 120 /// <param name="drawFont">The font used for drawing the text.</param> 121 /// <returns>The compacted file path.</returns> 122 public static string GetCompactPath(string longPath, int newWidth, Font drawFont) 123 { 124 using (Control ctrl = new Control()) 125 using (Graphics g = ctrl.CreateGraphics()) 126 { 127 //First check if the source string is too long. 128 int width = g.MeasureString(longPath, drawFont).ToSize().Width; 129 if (width <= newWidth) 130 return longPath; 131 132 //It is, shorten it. 133 int aveCharWidth = width / longPath.Length; 134 int charCount = newWidth / aveCharWidth; 135 StringBuilder builder = new StringBuilder(); 136 builder.Append(longPath); 137 builder.EnsureCapacity(charCount); 138 139 while (g.MeasureString(builder.ToString(), drawFont).Width > newWidth) 140 { 141 if (!NativeMethods.PathCompactPathEx(builder, longPath, 142 (uint)charCount--, 0)) 143 { 144 return string.Empty; 145 } 146 } 147 148 return builder.ToString(); 149 } 150 } 151 152 /// <summary> 153 /// Compacts the file path, fitting in the given width. 154 /// </summary> 155 /// <param name="longPath">The path to compact.</param> 156 /// <param name="newWidth">The target width of the text.</param> 157 /// <param name="control">The control on which this text is drawn. This is used 158 /// for font information.</param> 159 /// <returns>The compacted file path.</returns> 160 public static string GetCompactPath(string longPath, int newWidth, Control control) 161 { 162 return GetCompactPath(longPath, newWidth, control.Font); 163 } 112 164 } 113 165 } -
trunk/eraser/Eraser/TaskPropertiesForm.cs
r2324 r2442 207 207 { 208 208 ErasureTarget target = task.Targets[e.ItemIndex]; 209 FileInfo info = new FileInfo(target.UIText);210 e.Item = new ListViewItem(info.GetCompactPath(data.Columns[0].Width, data.Font));209 e.Item = new ListViewItem(PathUtil.GetCompactPath(target.UIText, 210 data.Columns[0].Width, data.Font)); 211 211 e.Item.ToolTipText = target.UIText; 212 212
Note: See TracChangeset
for help on using the changeset viewer.
