/// <summary> /// Given an absolute path to a directory, scan that directory for /// .desktop files, creating an ApplicationItem for each desktop file /// found and adding the ApplicationItem to the list of /// ApplicationItems. /// </summary> /// <param name="dir"> /// A <see cref="System.String"/> containing an absolute path to a /// directory /// where .desktop files can be found. /// </param> IEnumerable <KeyValuePair <string, ApplicationItem> > LoadDesktopFiles(string dir) { return(GetDesktopFiles(dir) .Where(ShouldUseDesktopFile) .Select(f => new KeyValuePair <string, ApplicationItem> (f, ApplicationItem.MaybeCreateFromDesktopItem(f))) .Where(a => a.Value != null) .Where(a => a.Value.ShouldShow)); }
void OnFileRenamed(object sender, RenamedEventArgs e) { Item disappearingItem = null; ApplicationItem newItem = null; lock (app_items) { if (app_items.ContainsKey(e.OldFullPath)) { Log <ApplicationItemSource> .Debug("Desktop file {0} moved away", e.OldFullPath); disappearingItem = app_items[e.OldFullPath]; app_items.Remove(e.OldFullPath); } if (e.FullPath.EndsWith(".desktop", StringComparison.Ordinal)) { Log <ApplicationItemSource> .Debug("Desktop file {0} moved into watched directory", e.FullPath); newItem = ApplicationItem.MaybeCreateFromDesktopItem(e.FullPath); if (newItem == null) { Log.Error("Found new Desktop file {0} but unable to create an item in the Universe", e.FullPath); } else { app_items [e.FullPath] = newItem; } } } if (disappearingItem != null) { RaiseItemsUnavailable(new ItemsUnavailableEventArgs() { unavailableItems = new Item[] { disappearingItem } }); } if (newItem != null) { RaiseItemsAvailable(new ItemsAvailableEventArgs() { newItems = new Item[] { newItem } }); } }
void OnFileCreated(object sender, FileSystemEventArgs e) { Log <ApplicationItemSource> .Debug("New Desktop file found: {0}", e.FullPath); var newItem = ApplicationItem.MaybeCreateFromDesktopItem(e.FullPath); if (newItem == null) { Log.Error("Found new Desktop file {0} but unable to create an item in the Universe", e.FullPath); return; } lock (app_items) { if (app_items.ContainsKey(e.FullPath)) { Log.Error("Attempting to add duplicate ApplicationItem {0} to Universe", e.FullPath); return; } app_items[e.FullPath] = newItem; } RaiseItemsAvailable(new ItemsAvailableEventArgs() { newItems = new Item[] { newItem } }); }