~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Ide/MonoDevelop.Ide.Desktop/DesktopApplication.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
 
36
36
namespace MonoDevelop.Ide.Desktop
37
37
{
38
 
        public struct DesktopApplication
 
38
        public abstract class DesktopApplication
39
39
        {
40
 
                internal string id;
41
 
                string displayName;
42
 
                string command;
43
 
                
44
 
                public DesktopApplication (string id, string displayName, string command)
 
40
                public DesktopApplication (string id, string displayName, bool isDefault)
45
41
                {
46
 
                        this.id = id;
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;
 
47
                        this.Id = id;
 
48
                        this.IsDefault = isDefault;
49
49
                }
50
50
 
51
 
                public string DisplayName {
52
 
                        get { return displayName; }
53
 
                }
54
 
                
55
 
                public string Command {
56
 
                        get { return command; }
57
 
                }
58
 
                
59
 
                public void Launch (params string[] files)
60
 
                {
61
 
                        if (!IsValid)
62
 
                                throw new InvalidOperationException ("DesktopApplication is invalid");
63
 
                        
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 + "\"");
68
 
                                        Process.Start (cmd);
69
 
                                }
70
 
                        }
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] + "\"";
75
 
                                }
76
 
                                string cmd = command.Replace ("%F", string.Join (" ", fs));
77
 
                                Process.Start (cmd);
78
 
                        } else {
79
 
                                foreach (string s in files) {
80
 
                                        Process.Start (command, "\"" + s + "\"");
81
 
                                }
82
 
                        }
83
 
                }
84
 
                
85
 
                public bool IsValid {
86
 
                        get {
87
 
                                return !string.IsNullOrEmpty (command) && !string.IsNullOrEmpty (displayName); 
88
 
                        }
 
51
                public string DisplayName { get; private set; }
 
52
                
 
53
                /// <summary>
 
54
                /// Used to uniquely identify the application or command.
 
55
                /// </summary>
 
56
                public string Id { get; private set; }
 
57
                
 
58
                public bool IsDefault { get; private set; }
 
59
                
 
60
                public abstract void Launch (params string[] files);
 
61
                
 
62
                public override int GetHashCode ()
 
63
                {
 
64
                        return Id.GetHashCode ();
 
65
                }
 
66
                
 
67
                public override bool Equals (object obj)
 
68
                {
 
69
                        var other = obj as DesktopApplication;
 
70
                        return other != null && other.Id == Id;
89
71
                }
90
72
        }
91
73
}