private void TextBlock_Drop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(typeof(Category))) { TextBlock dropBlock = sender as TextBlock; Category replacedCategory = dropBlock.DataContext as Category; System.Diagnostics.Debug.WriteLine(e.Data.GetData(typeof(Category)).ToString()); Category dropData = e.Data.GetData(typeof(Category)) as Category; CategoryList parent = replacedCategory.ParentCategoryList; int initialIndex = parent.IndexOf(dropData); int dropIndex = parent.IndexOf(replacedCategory); parent.Move(initialIndex, dropIndex); } else if (e.Data.GetDataPresent(typeof(ApplicationInfo))) { if (((sender as TextBlock).DataContext as Category).Name == "Quick Launch") { e.Effects = DragDropEffects.Copy; } else { e.Effects = DragDropEffects.Move; } ApplicationInfo dropData = e.Data.GetData(typeof(ApplicationInfo)) as ApplicationInfo; Category dropCollection = (sender as TextBlock).DataContext as Category; if (e.Effects == DragDropEffects.Move) { (sourceView.ItemsSource as IList <ApplicationInfo>).Remove(dropData); if ((sourceView.ItemsSource as Category).Name != "Quick Launch") { dropCollection.Add(dropData); } } else if (e.Effects == DragDropEffects.Copy) { ApplicationInfo dropClone = dropData.Clone(); // Do not duplicate entries if (!dropCollection.Contains(dropClone)) { dropCollection.Add(dropClone); } } sourceView = null; } isDragging = false; }
private void CategoryButtonClicked(object sender, RoutedEventArgs e) { Button button = sender as Button; Category actionableCategory = button.CommandParameter as Category; CategoryList catList = actionableCategory.ParentCategoryList; switch (button.Content as String) { case "5": catList.MoveCategory(actionableCategory, -1); break; case "6": catList.MoveCategory(actionableCategory, 1); break; case "r": //Don't allow removal of special category if (actionableCategory.Type > 0) { return; } Category uncategorized = catList.GetSpecialCategory(AppCategoryType.Uncategorized); for (int i = actionableCategory.Count - 1; i >= 0; i--) { ApplicationInfo app = actionableCategory[i]; actionableCategory.RemoveAt(i); uncategorized.Add(app); } catList.Remove(actionableCategory); break; } }
private void TextBlock_Drop(object sender, DragEventArgs e) { TextBlock dropBlock = sender as TextBlock; Category dropCategory = dropBlock.DataContext as Category; if (e.Data.GetDataPresent(typeof(Category))) { CairoLogger.Instance.Debug(e.Data.GetData(typeof(Category)).ToString()); Category dropData = e.Data.GetData(typeof(Category)) as Category; CategoryList parent = dropCategory.ParentCategoryList; int initialIndex = parent.IndexOf(dropData); int dropIndex = parent.IndexOf(dropCategory); parent.Move(initialIndex, dropIndex); } else if (e.Data.GetDataPresent(typeof(ApplicationInfo))) { ApplicationInfo dropData = e.Data.GetData(typeof(ApplicationInfo)) as ApplicationInfo; if (dropCategory.Type == AppCategoryType.QuickLaunch) { e.Effects = DragDropEffects.Copy; // Do not duplicate entries if (!dropCategory.Contains(dropData)) { ApplicationInfo dropClone = dropData.Clone(); dropCategory.Add(dropClone); dropClone.Icon = null; // icon may differ depending on category dropClone.IconPath = null; } } else if (sourceView != null) { e.Effects = DragDropEffects.Move; (sourceView.ItemsSource as Category).Remove(dropData); if ((sourceView.ItemsSource as Category).Type != AppCategoryType.QuickLaunch) { dropCategory.Add(dropData); } } sourceView = null; } isDragging = false; }
private void goPage2() { bdrMain.Visibility = Visibility.Collapsed; bdrPage2.Visibility = Visibility.Visible; // Grab the Programs CategoryList catList = appGrabber.CategoryList; // Get the Uncategorized category Category uncat = catList.GetSpecialCategory(AppCategoryType.Uncategorized); // Get the Quick Launch category Category quicklaunch = catList.GetSpecialCategory(AppCategoryType.QuickLaunch); // Add apps to category if they haven't been added to one yet. foreach (ApplicationInfo app in programsMenuAppsCollection) { if (app.Category == null) { string cat; if (app.IsStoreApp) { cat = autoCategorizeByName(app.Name); } else { cat = autoCategorizeByName(Path.GetFileNameWithoutExtension(app.Path)); } if (cat != "") { // Get the category - create it if it doesn't exist. Category categoryToAdd = catList.GetCategory(cat); if (categoryToAdd == null) { categoryToAdd = new Category(cat, true); catList.Add(categoryToAdd); } categoryToAdd.Add(app); } else { // not a known app, add to Uncategorized if (uncat != null) { uncat.Add(app); } } } } categoryView.ItemsSource = catList; categoryView.Visibility = Visibility.Visible; }
public void AddToQuickLaunch(ApplicationInfo app) { Category quickLaunch = CategoryList.GetSpecialCategory(3); if (!quickLaunch.Contains(app)) { ApplicationInfo appClone = app.Clone(); appClone.Icon = null; appClone.IconPath = null; quickLaunch.Add(appClone); Save(); } }
private void CategoryButtonClicked(object sender, RoutedEventArgs e) { Button button = sender as Button; Category actionableCategory = button.CommandParameter as Category; CategoryList catList = actionableCategory.ParentCategoryList; switch (button.Content as String) { case "<": catList.MoveCategory(actionableCategory, -1); break; case ">": catList.MoveCategory(actionableCategory, 1); break; case "X": //Don't allow removal of uncategorized or quick launch if (actionableCategory.Name == "Quick Launch") { return; } if (actionableCategory.Name == "Uncategorized") { return; } Category uncategorized = catList.GetCategory("Uncategorized"); for (int i = actionableCategory.Count - 1; i >= 0; i--) { ApplicationInfo app = actionableCategory[i]; actionableCategory.RemoveAt(i); uncategorized.Add(app); } catList.Remove(actionableCategory); break; } }
private void ListView_Drop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(typeof(ApplicationInfo))) { CairoLogger.Instance.Debug(e.Data.GetData(typeof(ApplicationInfo)).ToString()); ApplicationInfo dropData = e.Data.GetData(typeof(ApplicationInfo)) as ApplicationInfo; ListView dropTarget = sender as ListView; if (dropTarget.ItemsSource is Category) { Category target = dropTarget.ItemsSource as Category; if (target.Type == AppCategoryType.QuickLaunch) { e.Effects = DragDropEffects.Copy; // Do not duplicate entries if (!target.Contains(dropData)) { ApplicationInfo dropClone = dropData.Clone(); if (e.OriginalSource != null && e.OriginalSource is FrameworkElement && (e.OriginalSource as FrameworkElement).DataContext != null && (e.OriginalSource as FrameworkElement).DataContext is ApplicationInfo) { target.Insert(target.IndexOf((e.OriginalSource as FrameworkElement).DataContext as ApplicationInfo), dropClone); } else { target.Add(dropClone); } dropClone.Icon = null; // icon may differ depending on category dropClone.IconPath = null; } else { // reorder existing if (e.OriginalSource != null && e.OriginalSource is FrameworkElement && (e.OriginalSource as FrameworkElement).DataContext != null && (e.OriginalSource as FrameworkElement).DataContext is ApplicationInfo) { target.Move(target.IndexOf(dropData), target.IndexOf((e.OriginalSource as FrameworkElement).DataContext as ApplicationInfo)); } } } else if (sourceView != null && sourceView != sender) { e.Effects = DragDropEffects.Move; Category source = sourceView.ItemsSource as Category; source.Remove(dropData); if (source.Type != AppCategoryType.QuickLaunch) { target.Add(dropData); // if coming from quick launch, simply remove from quick launch if (dropTarget.Items.Contains(dropData)) { dropTarget.ScrollIntoView(dropTarget.Items[dropTarget.Items.IndexOf(dropData)]); } } } } else { e.Effects = DragDropEffects.Move; (sourceView.ItemsSource as IList <ApplicationInfo>).Remove(dropData); (dropTarget.ItemsSource as IList <ApplicationInfo>).Add(dropData); if (dropTarget.Items.Contains(dropData)) { dropTarget.ScrollIntoView(dropTarget.Items[dropTarget.Items.IndexOf(dropData)]); } } } else if (e.Data.GetDataPresent(DataFormats.FileDrop)) { string[] fileNames = e.Data.GetData(DataFormats.FileDrop) as string[]; if (fileNames != null) { ListView dropTarget = sender as ListView; if (!(dropTarget.ItemsSource is Category)) { foreach (String fileName in fileNames) { CairoLogger.Instance.Debug(fileName); if (Shell.Exists(fileName)) { ApplicationInfo customApp = AppGrabber.PathToApp(fileName, false, false); if (!object.ReferenceEquals(customApp, null)) { (dropTarget.ItemsSource as IList <ApplicationInfo>).Add(customApp); if (dropTarget.Items.Contains(customApp)) { dropTarget.ScrollIntoView(dropTarget.Items[dropTarget.Items.IndexOf(customApp)]); } } } } } } } sourceView = null; isDragging = false; }