36
36
namespace MonoDevelop.Ide.Desktop
38
public struct DesktopApplication
38
public abstract class DesktopApplication
44
public DesktopApplication (string id, string displayName, string command)
40
public DesktopApplication (string id, string displayName, bool isDefault)
47
this.displayName = displayName;
48
this.command = command;
42
if (string.IsNullOrEmpty (displayName))
43
throw new ArgumentException ("displayName cannot be empty");
44
if (string.IsNullOrEmpty (id))
45
throw new ArgumentException ("id cannot be empty");
46
this.DisplayName = displayName;
48
this.IsDefault = isDefault;
51
public string DisplayName {
52
get { return displayName; }
55
public string Command {
56
get { return command; }
59
public void Launch (params string[] files)
62
throw new InvalidOperationException ("DesktopApplication is invalid");
64
// TODO: implement all other cases
65
if (command.IndexOf ("%f") != -1) {
66
foreach (string s in files) {
67
string cmd = command.Replace ("%f", "\"" + s + "\"");
71
else if (command.IndexOf ("%F") != -1) {
72
string[] fs = new string [files.Length];
73
for (int n=0; n<files.Length; n++) {
74
fs [n] = "\"" + files [n] + "\"";
76
string cmd = command.Replace ("%F", string.Join (" ", fs));
79
foreach (string s in files) {
80
Process.Start (command, "\"" + s + "\"");
87
return !string.IsNullOrEmpty (command) && !string.IsNullOrEmpty (displayName);
51
public string DisplayName { get; private set; }
54
/// Used to uniquely identify the application or command.
56
public string Id { get; private set; }
58
public bool IsDefault { get; private set; }
60
public abstract void Launch (params string[] files);
62
public override int GetHashCode ()
64
return Id.GetHashCode ();
67
public override bool Equals (object obj)
69
var other = obj as DesktopApplication;
70
return other != null && other.Id == Id;