|
Lines 326-345
namespace Search.Tiles {
Link Here
|
| 326 |
|
326 |
|
| 327 |
protected void OpenFromMime (Hit hit) |
327 |
protected void OpenFromMime (Hit hit) |
| 328 |
{ |
328 |
{ |
| 329 |
OpenFromMime (hit, null, null, false); |
329 |
string command = null, item; |
| 330 |
} |
330 |
bool expects_uris = false; |
| 331 |
|
|
|
| 332 |
protected void OpenFromMime (Hit hit, string command_fallback, |
| 333 |
string args_fallback, bool expects_uris_fallback) |
| 334 |
{ |
| 335 |
string argument; |
| 336 |
string command = command_fallback; |
| 337 |
bool expects_uris = expects_uris_fallback; |
| 338 |
|
331 |
|
| 339 |
// FIXME: This is evil. Nautilus should be handling |
332 |
// FIXME: This is evil. Nautilus should be handling |
| 340 |
// inode/directory, not just x-directory/normal |
333 |
// inode/directory, not just x-directory/normal |
| 341 |
if (hit.MimeType == "inode/directory") |
334 |
if (hit.MimeType == "inode/directory") |
| 342 |
hit.MimeType = "x-directory/normal"; |
335 |
hit.MimeType = "x-directory/normal"; |
|
|
336 |
|
| 343 |
#if ENABLE_DESKTOP_LAUNCH |
337 |
#if ENABLE_DESKTOP_LAUNCH |
| 344 |
command = "desktop-launch"; |
338 |
command = "desktop-launch"; |
| 345 |
expects_uris = true; |
339 |
expects_uris = true; |
|
Lines 356-394
namespace Search.Tiles {
Link Here
|
| 356 |
return; |
350 |
return; |
| 357 |
} |
351 |
} |
| 358 |
|
352 |
|
| 359 |
if (args_fallback != null) |
353 |
if (expects_uris) |
| 360 |
argument = args_fallback; |
354 |
item = UriFu.UriToSerializableString (hit.Uri); |
| 361 |
else |
355 |
else |
| 362 |
argument = ""; |
356 |
item = hit.Path; |
| 363 |
|
|
|
| 364 |
if (expects_uris) { |
| 365 |
argument = String.Format ("{0} '{1}'", argument, |
| 366 |
UriFu.UriToSerializableString(hit.Uri)); |
| 367 |
} else { |
| 368 |
argument = String.Format ("{0} {1}", argument, hit.PathQuoted); |
| 369 |
} |
| 370 |
|
357 |
|
| 371 |
// Sometimes the command is 'quoted' |
358 |
// Sometimes the command is 'quoted' |
| 372 |
if (command.IndexOf ('\'') == 0 && command.LastIndexOf ('\'') == command.Length - 1) |
359 |
if (command.IndexOf ('\'') == 0 && command.LastIndexOf ('\'') == command.Length - 1) |
| 373 |
command = command.Trim ('\''); |
360 |
command = command.Trim ('\''); |
| 374 |
|
361 |
|
| 375 |
// This won't work if a program really has a space in |
362 |
// This won't work if a program really has a space in |
| 376 |
// the filename, but I think other things would break |
363 |
// the command filename, but I think other things would |
| 377 |
// with that too, and in practice it doesn't seem to |
364 |
// break with that too, and in practice it doesn't seem to |
| 378 |
// happen. |
365 |
// happen. |
|
|
366 |
// |
| 367 |
// A bigger issue is that the arguments are split up by |
| 368 |
// spaces, so quotation marks used to indicate a single |
| 369 |
// entry in the argv won't work. This probably should |
| 370 |
// be fixed. |
| 371 |
string[] arguments = null; |
| 379 |
int idx = command.IndexOf (' '); |
372 |
int idx = command.IndexOf (' '); |
| 380 |
if (idx != -1) { |
373 |
if (idx != -1) { |
| 381 |
argument = String.Format ("{0} {1}", command.Substring (idx + 1), argument); |
374 |
arguments = command.Substring (idx + 1).Split (' '); |
| 382 |
command = command.Substring (0, idx); |
375 |
command = command.Substring (0, idx); |
| 383 |
} |
376 |
} |
| 384 |
|
377 |
|
|
|
378 |
string[] argv; |
| 379 |
if (arguments == null) |
| 380 |
argv = new string [] { command, item }; |
| 381 |
else { |
| 382 |
argv = new string [arguments.Length + 2]; |
| 383 |
argv [0] = command; |
| 384 |
argv [argv.Length - 1] = item; |
| 385 |
Array.Copy (arguments, 0, argv, 1, arguments.Length); |
| 386 |
} |
| 387 |
|
| 385 |
Console.WriteLine ("Cmd: {0}", command); |
388 |
Console.WriteLine ("Cmd: {0}", command); |
| 386 |
Console.WriteLine ("Arg: {0}", argument); |
389 |
Console.WriteLine ("Arg: {0}", String.Join (" ", argv, 1, argv.Length - 2)); |
|
|
390 |
Console.WriteLine ("Itm: {0}", item); |
| 387 |
|
391 |
|
| 388 |
Process p = new Process (); |
392 |
SafeProcess p = new SafeProcess (); |
| 389 |
p.StartInfo.UseShellExecute = false; |
393 |
p.Arguments = argv; |
| 390 |
p.StartInfo.FileName = command; |
|
|
| 391 |
p.StartInfo.Arguments = argument; |
| 392 |
|
394 |
|
| 393 |
try { |
395 |
try { |
| 394 |
p.Start (); |
396 |
p.Start (); |
|
Lines 405-414
namespace Search.Tiles {
Link Here
|
| 405 |
public void OpenFromUri (string uri) |
407 |
public void OpenFromUri (string uri) |
| 406 |
{ |
408 |
{ |
| 407 |
#if ENABLE_DESKTOP_LAUNCH |
409 |
#if ENABLE_DESKTOP_LAUNCH |
| 408 |
Process p = new Process (); |
410 |
SafeProcess p = new SafeProcess (); |
| 409 |
p.StartInfo.UseShellExecute = false; |
411 |
p.Arguments = new string[] { "desktop-launch", uri }; |
| 410 |
p.StartInfo.FileName = "desktop-launch"; |
|
|
| 411 |
p.StartInfo.Arguments = uri; |
| 412 |
|
412 |
|
| 413 |
try { |
413 |
try { |
| 414 |
p.Start (); |
414 |
p.Start (); |