void ProcessFile(string fileName) { if (Log.IsDebugEnabled) { Log.DebugFormat("Trying to load {0}", fileName); } if (PathEx.HasExtension(fileName, FileExtensions.Executable) || PathEx.HasExtension(fileName, FileExtensions.Shortcut) || PathEx.HasExtension(fileName, FileExtensions.ClickOnce)) { try { ApplicationModel model = ApplicationModel.FromFile(fileName, SelectedTab.Title, true); if (model == null) { return; } if (model.FilePath.StartsWith(@"C:\Windows", StringComparison.InvariantCultureIgnoreCase)) { return; // Don't add anything from the windows directory } if (!PathEx.HasExtension(model.FilePath, FileExtensions.Executable)) { return; // Only take executable files } if (model.Title.Contains("Install", StringComparison.InvariantCultureIgnoreCase)) { return; // Ignore installers } if (model.Title.Contains("Uninstall", StringComparison.InvariantCultureIgnoreCase)) { return; // Ignore uninstallers } ApplicationViewModel application = new ApplicationViewModel(model); if (Tabs.Any(obj => obj.Applications.Contains(application))) { return; // Ignore applications already added to the dock } AddApplication(new ApplicationViewModel(model)); } catch (Exception ex) { if (Log.IsDebugEnabled) { Log.DebugFormat("Failed to add file to search view - {0}", ex.Message); } } } }
void OnDrop(object sender, DragEventArgs e) { FrameworkElement element = sender as FrameworkElement; if (element != null) { TabViewModel tab = element.DataContext as TabViewModel; if (tab == null) { // TabViewModel not found it element, it's possible that the drop was done on the lastOpened 'Canvas' element. var tabControls = element.FindVisualChildren <TabControl>(); var menus = element.FindVisualChildren <Menu>(); var itemControls = element.FindVisualChildren <ItemsControl>(); if (tabControls.Count > 0 && tabControls[0].Visibility == Visibility.Visible) { // If currently in 'horizontal mode' add to the active tab. If there is no active tab // just add to the bottom tab. tab = tabControls[0].SelectedItem as TabViewModel; if (tab == null) { tab = tabControls[0].Items.GetItemAt(tabControls[0].Items.Count - 1) as TabViewModel; } } else if (menus.Count > 0 && menus[0].Visibility == Visibility.Visible) { // If currently in 'vertical mode' add to the default tab, there is no 'active' menu item after all. var tabs = menus[0].Items.SourceCollection as ObservableCollection <TabViewModel>; tab = tabs.SingleOrDefault(obj => obj.Title == Configuration.DefaultTab) ?? tabs.LastOrDefault(); } else if (itemControls.Count > 0 && itemControls[0].Visibility == Visibility.Visible) { var window = element.FindVisualParent <Window>(); if (window != null && window.DataContext is MainViewModel) { // Add the currently expanded tab. MainViewModel mainViewModel = (MainViewModel)window.DataContext; tab = mainViewModel.ExpandedTab; // If no tab is expanded, add to the default tab or the bottom tab. if (tab == null) { tab = mainViewModel.Tabs.SingleOrDefault(obj => obj.Title == Configuration.DefaultTab) ?? mainViewModel.Tabs.LastOrDefault(); } } } } if (tab != null) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { DispatcherHelper.UIDispatcher.BeginInvoke(new Action(() => { string[] droppedFilePaths = e.Data.GetData(DataFormats.FileDrop, true) as string[]; foreach (string fileName in droppedFilePaths) { try { ApplicationModel model = ApplicationModel.FromFile(fileName, tab.Title); ApplicationViewModel application = new ApplicationViewModel(model); Messenger.Default.Send <ApplicationMessage>(ApplicationMessage.Add(application, tab)); } catch (FileNotFoundException ex) { ServiceManager.GetService <IMessageBoxService>().Show( "Could not add application - " + ex.Message, "Astounding Dock", MessageIcon.Error); } } })); e.Handled = true; } else if (e.Data.GetDataPresent <ApplicationViewModel>()) { DispatcherHelper.UIDispatcher.BeginInvoke(new Action(() => { ApplicationViewModel application = e.Data.GetData <ApplicationViewModel>(); Messenger.Default.Send <ApplicationMessage>(ApplicationMessage.Move(application, tab)); })); e.Handled = true; } else { Debug.WriteLine("DragDropBehaviour: Unknown data droppped - " + String.Join(",", e.Data.GetFormats())); } } } }