~cszikszoy/do/do-fix-keybindings

« back to all changes in this revision

Viewing changes to Do.Platform.Linux/src/Do.Universe/ApplicationItem.cs

  • Committer: Chris S.
  • Date: 2009-06-18 06:18:12 UTC
  • mfrom: (1107.2.124 trunk)
  • Revision ID: chris@szikszoy.com-20090618061812-8ynmedlxpmvwkwe9
merge trunk & make properties public

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
                
73
73
                public static ApplicationItem MaybeCreateFromCmd (string cmd)
74
74
                {
75
 
                        ApplicationItem appItem = null;
76
 
                        
77
75
                        if (string.IsNullOrEmpty (cmd))
78
 
                                return appItem;
 
76
                                return null;
 
77
                        
 
78
                        List<ApplicationItem> appItems = new List<ApplicationItem> ();
79
79
                        
80
80
                        cmd = Regex.Escape (cmd);
81
81
                        Regex regex = new Regex (string .Format ("(^| ){0}( |)", cmd));
89
89
                                } catch { continue; }
90
90
                                
91
91
                                try {
92
 
                                        if ((!string.IsNullOrEmpty (path) && regex.IsMatch (path)) || 
93
 
                                            (!string.IsNullOrEmpty (item.Exec) && regex.IsMatch (item.Exec))) {
94
 
                                                appItem = item;
95
 
                                                if (item.IsAppropriateForCurrentDesktop && !item.Hidden)
96
 
                                                        break;
 
92
                                        if (!string.IsNullOrEmpty (path) && !string.IsNullOrEmpty (item.Exec) &&
 
93
                                            (regex.IsMatch (path) || regex.IsMatch (item.Exec))) {
 
94
                                                appItems.Add (item);
97
95
                                        }
98
96
                                } catch {
99
97
                                        // it failed, probably a null somewhere, we dont care really
100
98
                                }
101
99
                        }
102
100
                        
103
 
                        return appItem;
 
101
                        ApplicationItem bestMatch = null;
 
102
                        
 
103
                        foreach (ApplicationItem item in appItems) {
 
104
                                if (bestMatch == null) {
 
105
                                        bestMatch = item;
 
106
                                        continue;
 
107
                                }
 
108
                                if (!item.Hidden) {
 
109
                                        if (bestMatch.Hidden) {
 
110
                                                bestMatch = item;
 
111
                                                continue;
 
112
                                        }
 
113
                                        if (item.IsAppropriateForCurrentDesktop) {
 
114
                                                if (!bestMatch.IsAppropriateForCurrentDesktop || item.Exec.Length < bestMatch.Exec.Length)
 
115
                                                        bestMatch = item;
 
116
                                        }
 
117
                                }
 
118
                        }
 
119
                        
 
120
                        return bestMatch;
104
121
                }
105
122
 
106
123
                protected DesktopItem item;
107
124
                string name, description, icon, mimetype;
 
125
                IEnumerable<string> categories;
108
126
 
109
127
                /// <summary>
110
128
                /// Create an application item from a desktop file.
120
138
                                name = item.GetLocalestring ("Name");
121
139
                                description = item.GetLocalestring ("Comment");
122
140
                                icon = item.GetString ("Icon") ?? DefaultApplicationIcon;
 
141
                                
 
142
                                if (item.AttrExists ("Categories"))
 
143
                                        categories = item.GetString ("Categories").Split (';');
 
144
                                else
 
145
                                        categories = Enumerable.Empty<string> ();
123
146
                        } else {
124
147
                                name = Path.GetFileName (item.Location);
125
148
                                description =
126
149
                                        Catalog.GetString ("This application could not be indexed.");
127
150
                                icon = DefaultApplicationIcon;
 
151
                                categories = Enumerable.Empty<string> ();
128
152
                        }
129
153
                }
130
154
                
139
163
                public override string Icon {
140
164
                        get { return icon; }
141
165
                }
 
166
                
 
167
                public IEnumerable<string> Categories {
 
168
                        get { return categories; }
 
169
                }
142
170
 
143
171
                public bool NoDisplay {
144
172
                        get {