Mercurial > projects > dwt-win
annotate dwt/program/Program.d @ 239:43b41c7fe84a
work on allow null strings and arrays
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Fri, 20 Jun 2008 16:27:36 +0200 |
parents | 36f5cb12e1a2 |
children | fd9c62a2998e |
rev | line source |
---|---|
191 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2007 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D Programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwt.program.Program; | |
14 | |
15 import dwt.DWT; | |
16 import dwt.graphics.Image; | |
17 import dwt.graphics.ImageData; | |
18 import dwt.internal.win32.OS; | |
19 | |
20 import dwt.dwthelper.utils; | |
21 static import tango.text.convert.Utf; | |
22 | |
23 /** | |
24 * Instances of this class represent programs and | |
25 * their associated file extensions in the operating | |
26 * system. | |
27 */ | |
28 public final class Program { | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
29 String name; |
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
30 String command; |
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
31 String iconName; |
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
32 String extension; |
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
33 static const String[] ARGUMENTS = ["%1"[], "%l", "%L"]; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
191 | 34 |
35 /** | |
36 * Prevents uninitialized instances from being created outside the package. | |
37 */ | |
38 this () { | |
39 } | |
40 | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
41 static String assocQueryString (int assocStr, TCHAR[] key, bool expand) { |
191 | 42 TCHAR[] pszOut = NewTCHARs(0, 1024); |
43 uint[1] pcchOut; | |
44 pcchOut[0] = pszOut.length; | |
213 | 45 int flags = OS.ASSOCF_NOTRUNCATE | OS.ASSOCF_INIT_IGNOREUNKNOWN; |
46 int result = OS.AssocQueryString (flags, assocStr, key.ptr, null, pszOut.ptr, pcchOut.ptr); | |
191 | 47 if (result is OS.E_POINTER) { |
48 pszOut = NewTCHARs(0, pcchOut [0]); | |
213 | 49 result = OS.AssocQueryString (flags, assocStr, key.ptr, null, pszOut.ptr, pcchOut.ptr); |
191 | 50 } |
51 if (result is 0) { | |
52 if (!OS.IsWinCE && expand) { | |
53 int length_ = OS.ExpandEnvironmentStrings (pszOut.ptr, null, 0); | |
54 if (length_ !is 0) { | |
55 TCHAR[] lpDst = NewTCHARs (0, length_); | |
56 OS.ExpandEnvironmentStrings (pszOut.ptr, lpDst.ptr, length_); | |
57 return tango.text.convert.Utf.toString( lpDst[ 0 .. Math.max (0, length_ - 1) ] ); | |
58 } else { | |
59 return ""; | |
60 } | |
61 } else { | |
62 return tango.text.convert.Utf.toString( pszOut[ 0 .. Math.max (0, pcchOut [0] - 1)]); | |
63 } | |
64 } | |
65 return null; | |
66 } | |
67 | |
68 /** | |
69 * Finds the program that is associated with an extension. | |
70 * The extension may or may not begin with a '.'. Note that | |
71 * a <code>Display</code> must already exist to guarantee that | |
72 * this method returns an appropriate result. | |
73 * | |
74 * @param extension the program extension | |
75 * @return the program or <code>null</code> | |
76 * | |
77 */ | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
78 public static Program findProgram (String extension) { |
239
43b41c7fe84a
work on allow null strings and arrays
Frank Benoit <benoit@tionex.de>
parents:
213
diff
changeset
|
79 // DWT extension: allow null string |
43b41c7fe84a
work on allow null strings and arrays
Frank Benoit <benoit@tionex.de>
parents:
213
diff
changeset
|
80 //if (extension is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); |
191 | 81 if (extension.length is 0) return null; |
82 if (extension.charAt (0) !is '.') extension = "." ~ extension; //$NON-NLS-1$ | |
83 /* Use the character encoding for the default locale */ | |
84 TCHAR[] key = StrToTCHARs (0, extension, true); | |
85 Program program = null; | |
86 if (OS.IsWinCE) { | |
87 void*[1] phkResult; | |
88 if (OS.RegOpenKeyEx ( cast(void*)OS.HKEY_CLASSES_ROOT, key.ptr, 0, OS.KEY_READ, phkResult.ptr) !is 0) { | |
89 return null; | |
90 } | |
91 uint [1] lpcbData; | |
92 int result = OS.RegQueryValueEx (phkResult [0], null, null, null, null, lpcbData.ptr); | |
93 if (result is 0) { | |
94 TCHAR[] lpData = NewTCHARs (0, lpcbData [0] / TCHAR.sizeof); | |
95 result = OS.RegQueryValueEx (phkResult [0], null, null, null, cast(ubyte*)lpData.ptr, lpcbData.ptr); | |
96 if (result is 0) program = getProgram ( TCHARzToStr( lpData.ptr ), extension); | |
97 } | |
98 OS.RegCloseKey (phkResult [0]); | |
99 } else { | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
100 String command = assocQueryString (OS.ASSOCSTR_COMMAND, key, true); |
191 | 101 if (command !is null) { |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
102 String name = null; |
191 | 103 if (name is null) name = assocQueryString (OS.ASSOCSTR_FRIENDLYDOCNAME, key, false); |
104 if (name is null) name = assocQueryString (OS.ASSOCSTR_FRIENDLYAPPNAME, key, false); | |
105 if (name is null) name = ""; | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
106 String iconName = assocQueryString (OS.ASSOCSTR_DEFAULTICON, key, true); |
191 | 107 if (iconName is null) iconName = ""; |
108 program = new Program (); | |
109 program.name = name; | |
110 program.command = command; | |
111 program.iconName = iconName; | |
112 program.extension = extension; | |
113 } | |
114 } | |
115 return program; | |
116 } | |
117 | |
118 /** | |
119 * Answer all program extensions in the operating system. Note | |
120 * that a <code>Display</code> must already exist to guarantee | |
121 * that this method returns an appropriate result. | |
122 * | |
123 * @return an array of extensions | |
124 */ | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
125 public static String [] getExtensions () { |
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
126 String [] extensions = new String [1024]; |
191 | 127 /* Use the character encoding for the default locale */ |
128 TCHAR[] lpName = NewTCHARs (0, 1024); | |
129 uint [1] lpcName; lpcName[0] = lpName.length; | |
130 FILETIME ft; | |
131 int dwIndex = 0, count = 0; | |
132 while (OS.RegEnumKeyEx ( cast(void*)OS.HKEY_CLASSES_ROOT, dwIndex, lpName.ptr, lpcName.ptr, null, null, null, &ft) !is OS.ERROR_NO_MORE_ITEMS) { | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
133 String extension = TCHARsToStr( lpName[0 .. lpcName[0] ]); |
191 | 134 lpcName [0] = lpName.length; |
135 if (extension.length > 0 && extension.charAt (0) is '.') { | |
136 if (count is extensions.length) { | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
137 String[] newExtensions = new String[]( extensions.length + 1024 ); |
191 | 138 System.arraycopy (extensions, 0, newExtensions, 0, extensions.length); |
139 extensions = newExtensions; | |
140 } | |
141 extensions [count++] = extension; | |
142 } | |
143 dwIndex++; | |
144 } | |
145 if (count !is extensions.length) { | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
146 String[] newExtension = new String[]( count ); |
191 | 147 System.arraycopy (extensions, 0, newExtension, 0, count); |
148 extensions = newExtension; | |
149 } | |
150 return extensions; | |
151 } | |
152 | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
153 static String getKeyValue (String string, bool expand) { |
191 | 154 /* Use the character encoding for the default locale */ |
155 TCHAR[] key = StrToTCHARs (0, string, true); | |
156 void* [1] phkResult; | |
157 if (OS.RegOpenKeyEx (cast(void*)OS.HKEY_CLASSES_ROOT, key.ptr, 0, OS.KEY_READ, phkResult.ptr) !is 0) { | |
158 return null; | |
159 } | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
160 String result = null; |
191 | 161 uint [1] lpcbData; |
162 if (OS.RegQueryValueEx (phkResult [0], null, null, null, null, lpcbData.ptr) is 0) { | |
163 result = ""; | |
164 int length_ = lpcbData [0] / TCHAR.sizeof; | |
165 if (length_ !is 0) { | |
166 /* Use the character encoding for the default locale */ | |
167 TCHAR[] lpData = NewTCHARs (0, length_); | |
168 if (OS.RegQueryValueEx (phkResult [0], null, null, null, cast(ubyte*)lpData.ptr, lpcbData.ptr) is 0) { | |
169 if (!OS.IsWinCE && expand) { | |
170 length_ = OS.ExpandEnvironmentStrings (lpData.ptr, null, 0); | |
171 if (length_ !is 0) { | |
172 TCHAR[] lpDst = NewTCHARs (0, length_); | |
173 OS.ExpandEnvironmentStrings (lpData.ptr, lpDst.ptr, length_); | |
174 result = tango.text.convert.Utf.toString ( lpDst[0 .. Math.max (0, length_ - 1) ] ); | |
175 } | |
176 } else { | |
177 length_ = Math.max (0, lpData.length - 1); | |
178 result = tango.text.convert.Utf.toString ( lpData[0 .. length_]); | |
179 } | |
180 } | |
181 } | |
182 } | |
183 if (phkResult [0] !is null) OS.RegCloseKey (phkResult [0]); | |
184 return result; | |
185 } | |
186 | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
187 static Program getProgram (String key, String extension) { |
191 | 188 |
189 /* Name */ | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
190 String name = getKeyValue (key, false); |
191 | 191 if (name is null || name.length is 0) { |
192 name = key; | |
193 } | |
194 | |
195 /* Command */ | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
196 String DEFAULT_COMMAND = "\\shell"; //$NON-NLS-1$ |
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
197 String defaultCommand = getKeyValue (key ~ DEFAULT_COMMAND, true); |
191 | 198 if (defaultCommand is null || defaultCommand.length is 0) defaultCommand = "open"; //$NON-NLS-1$ |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
199 String COMMAND = "\\shell\\" ~ defaultCommand ~ "\\command"; //$NON-NLS-1$ |
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
200 String command = getKeyValue (key ~ COMMAND, true); |
191 | 201 if (command is null || command.length is 0) return null; |
202 | |
203 /* Icon */ | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
204 String DEFAULT_ICON = "\\DefaultIcon"; //$NON-NLS-1$ |
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
205 String iconName = getKeyValue (key ~ DEFAULT_ICON, true); |
191 | 206 if (iconName is null) iconName = ""; //$NON-NLS-1$ |
207 | |
208 /* Program */ | |
209 Program program = new Program (); | |
210 program.name = name; | |
211 program.command = command; | |
212 program.iconName = iconName; | |
213 program.extension = extension; | |
214 return program; | |
215 } | |
216 | |
217 /** | |
218 * Answers all available programs in the operating system. Note | |
219 * that a <code>Display</code> must already exist to guarantee | |
220 * that this method returns an appropriate result. | |
221 * | |
222 * @return an array of programs | |
223 */ | |
224 public static Program [] getPrograms () { | |
225 Program [] programs = new Program [1024]; | |
226 /* Use the character encoding for the default locale */ | |
227 TCHAR[] lpName = NewTCHARs (0, 1024); | |
228 uint [1] lpcName; lpcName[0] = lpName.length; | |
229 FILETIME ft; | |
230 int dwIndex = 0, count = 0; | |
231 while (OS.RegEnumKeyEx (cast(void*)OS.HKEY_CLASSES_ROOT, dwIndex, lpName.ptr, lpcName.ptr, null, null, null, &ft) !is OS.ERROR_NO_MORE_ITEMS) { | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
232 String path = tango.text.convert.Utf.toString ( lpName[0 .. lpcName [0]]); |
191 | 233 lpcName [0] = lpName.length ; |
234 Program program = getProgram (path, null); | |
235 if (program !is null) { | |
236 if (count is programs.length) { | |
237 Program [] newPrograms = new Program [programs.length + 1024]; | |
238 System.arraycopy (programs, 0, newPrograms, 0, programs.length); | |
239 programs = newPrograms; | |
240 } | |
241 programs [count++] = program; | |
242 } | |
243 dwIndex++; | |
244 } | |
245 if (count !is programs.length) { | |
246 Program [] newPrograms = new Program [count]; | |
247 System.arraycopy (programs, 0, newPrograms, 0, count); | |
248 programs = newPrograms; | |
249 } | |
250 return programs; | |
251 } | |
252 | |
253 /** | |
213 | 254 * Launches the operating system executable associated with the file or |
255 * URL (http:// or https://). If the file is an executable then the | |
256 * executable is launched. Note that a <code>Display</code> must already | |
257 * exist to guarantee that this method returns an appropriate result. | |
191 | 258 * |
213 | 259 * @param fileName the file or program name or URL (http:// or https://) |
191 | 260 * @return <code>true</code> if the file is launched, otherwise <code>false</code> |
261 * | |
262 * @exception IllegalArgumentException <ul> | |
263 * <li>ERROR_NULL_ARGUMENT when fileName is null</li> | |
264 * </ul> | |
265 */ | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
266 public static bool launch (String fileName) { |
191 | 267 if (fileName is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); |
268 | |
269 /* Use the character encoding for the default locale */ | |
270 auto hHeap = OS.GetProcessHeap (); | |
271 TCHAR[] buffer = StrToTCHARs (0, fileName, true); | |
272 int byteCount = buffer.length * TCHAR.sizeof; | |
273 auto lpFile = cast(wchar*) OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); | |
274 OS.MoveMemory (lpFile, buffer.ptr, byteCount); | |
275 SHELLEXECUTEINFO info; | |
276 info.cbSize = SHELLEXECUTEINFO.sizeof; | |
277 info.lpFile = lpFile; | |
278 info.nShow = OS.SW_SHOW; | |
279 bool result = cast(bool) OS.ShellExecuteEx (&info); | |
280 if (lpFile !is null) OS.HeapFree (hHeap, 0, lpFile); | |
281 return result; | |
282 } | |
283 | |
284 /** | |
285 * Executes the program with the file as the single argument | |
286 * in the operating system. It is the responsibility of the | |
287 * programmer to ensure that the file contains valid data for | |
288 * this program. | |
289 * | |
290 * @param fileName the file or program name | |
291 * @return <code>true</code> if the file is launched, otherwise <code>false</code> | |
292 * | |
293 * @exception IllegalArgumentException <ul> | |
294 * <li>ERROR_NULL_ARGUMENT when fileName is null</li> | |
295 * </ul> | |
296 */ | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
297 public bool execute (String fileName) { |
191 | 298 if (fileName is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); |
299 int index = 0; | |
300 bool append = true; | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
301 String prefix = command, suffix = ""; //$NON-NLS-1$ |
191 | 302 while (index < ARGUMENTS.length) { |
303 int i = command.indexOf (ARGUMENTS [index]); | |
304 if (i !is -1) { | |
305 append = false; | |
306 prefix = command.substring (0, i); | |
307 suffix = command.substring (i + ARGUMENTS [index].length , command.length ); | |
308 break; | |
309 } | |
310 index++; | |
311 } | |
312 if (append) fileName = " \"" ~ fileName ~ "\""; | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
313 String commandLine = prefix ~ fileName ~ suffix; |
191 | 314 auto hHeap = OS.GetProcessHeap (); |
315 /* Use the character encoding for the default locale */ | |
316 TCHAR[] buffer = StrToTCHARs (0, commandLine, true); | |
317 int byteCount = buffer.length * TCHAR.sizeof; | |
318 auto lpCommandLine = cast(TCHAR*)OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); | |
319 OS.MoveMemory (lpCommandLine, buffer.ptr, byteCount); | |
320 STARTUPINFO lpStartupInfo; | |
321 lpStartupInfo.cb = STARTUPINFO.sizeof; | |
322 PROCESS_INFORMATION lpProcessInformation; | |
323 bool success = cast(bool) OS.CreateProcess (null, lpCommandLine, null, null, false, 0, null, null, &lpStartupInfo, &lpProcessInformation); | |
324 if (lpCommandLine !is null) OS.HeapFree (hHeap, 0, lpCommandLine); | |
325 if (lpProcessInformation.hProcess !is null) OS.CloseHandle (lpProcessInformation.hProcess); | |
326 if (lpProcessInformation.hThread !is null) OS.CloseHandle (lpProcessInformation.hThread); | |
327 return success; | |
328 } | |
329 | |
330 /** | |
331 * Returns the receiver's image data. This is the icon | |
332 * that is associated with the receiver in the operating | |
333 * system. | |
334 * | |
335 * @return the image data for the program, may be null | |
336 */ | |
337 public ImageData getImageData () { | |
338 if (extension !is null) { | |
339 SHFILEINFOW shfi; | |
340 int flags = OS.SHGFI_ICON | OS.SHGFI_SMALLICON | OS.SHGFI_USEFILEATTRIBUTES; | |
341 TCHAR[] pszPath = StrToTCHARs (0, extension, true); | |
342 OS.SHGetFileInfo (pszPath.ptr, OS.FILE_ATTRIBUTE_NORMAL, &shfi, SHFILEINFO.sizeof, flags); | |
343 if (shfi.hIcon !is null) { | |
344 Image image = Image.win32_new (null, DWT.ICON, shfi.hIcon); | |
345 ImageData imageData = image.getImageData (); | |
346 image.dispose (); | |
347 return imageData; | |
348 } | |
349 } | |
350 int nIconIndex = 0; | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
351 String fileName = iconName; |
191 | 352 int index = iconName.indexOf (','); |
353 if (index !is -1) { | |
354 fileName = iconName.substring (0, index); | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
355 String iconIndex = iconName.substring (index + 1, iconName.length ).trim (); |
191 | 356 try { |
357 nIconIndex = Integer.parseInt (iconIndex); | |
358 } catch (NumberFormatException e) {} | |
359 } | |
213 | 360 int length = fileName.length; |
361 if (length !is 0 && fileName.charAt (0) is '\"') { | |
362 if (fileName.charAt (length - 1) is '\"') { | |
363 fileName = fileName.substring (1, length - 1); | |
364 } | |
365 } | |
191 | 366 /* Use the character encoding for the default locale */ |
367 TCHAR[] lpszFile = StrToTCHARs (0, fileName, true); | |
368 HICON [1] phiconSmall, phiconLarge; | |
369 OS.ExtractIconEx (lpszFile.ptr, nIconIndex, phiconLarge.ptr, phiconSmall.ptr, 1); | |
370 if (phiconSmall [0] is null) return null; | |
371 Image image = Image.win32_new (null, DWT.ICON, phiconSmall [0]); | |
372 ImageData imageData = image.getImageData (); | |
373 image.dispose (); | |
374 return imageData; | |
375 } | |
376 | |
377 /** | |
378 * Returns the receiver's name. This is as short and | |
379 * descriptive a name as possible for the program. If | |
380 * the program has no descriptive name, this string may | |
381 * be the executable name, path or empty. | |
382 * | |
383 * @return the name of the program | |
384 */ | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
385 public String getName () { |
191 | 386 return name; |
387 } | |
388 | |
389 /** | |
390 * Compares the argument to the receiver, and returns true | |
391 * if they represent the <em>same</em> object using a class | |
392 * specific comparison. | |
393 * | |
394 * @param other the object to compare with this object | |
395 * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise | |
396 * | |
397 * @see #hashCode() | |
398 */ | |
399 public override int opEquals(Object other) { | |
400 if (this is other) return true; | |
401 if ( auto program = cast(Program)other ) { | |
402 return name.equals(program.name) && command.equals(program.command) | |
403 && iconName.equals(program.iconName); | |
404 } | |
405 return false; | |
406 } | |
407 | |
408 /** | |
409 * Returns an integer hash code for the receiver. Any two | |
410 * objects that return <code>true</code> when passed to | |
411 * <code>equals</code> must return the same value for this | |
412 * method. | |
413 * | |
414 * @return the receiver's hash | |
415 * | |
416 * @see #equals(Object) | |
417 */ | |
418 public override hash_t toHash() { | |
419 return .toHash(name) ^ .toHash(command) ^ .toHash(iconName); | |
420 } | |
421 | |
422 /** | |
423 * Returns a string containing a concise, human-readable | |
424 * description of the receiver. | |
425 * | |
426 * @return a string representation of the program | |
427 */ | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
428 public String toString () { |
191 | 429 return "Program {" ~ name ~ "}"; //$NON-NLS-1$ //$NON-NLS-2$ |
430 } | |
431 | |
432 } |