Example #1
0
        /// <summary>
        /// Loads library from the database file.
        /// </summary>
        void LoadLibrary()
        {
            if (File.Exists(ApplicationData.Current.LocalFolder.Path + @"\library.db"))
            {
                OldItems           = db.GetTracks().ToList();
                TracksCollection   = new GroupedObservableCollection <string, Mediafile>(t => t.Title, OldItems, t => t.Title);
                PlaylistCollection = new ThreadSafeObservableCollection <Playlist>(OldItems.SelectMany(t => t.Playlists).DistinctBy(t => t.Name).ToList());

                Options.Add(new ContextMenuCommand(AddToPlaylistCommand, "New Playlist"));
                foreach (var list in PlaylistCollection)
                {
                    var cmd = new ContextMenuCommand(AddToPlaylistCommand, list.Name);
                    Options.Add(cmd);
                    var Playlists = new Dictionary <Playlist, IEnumerable <Mediafile> >();
                    Playlists.Add(list, db.PlaylistSort(list.Name));
                    ShellVM.PlaylistsItems.Add(new SplitViewMenu.SimpleNavMenuItem
                    {
                        Arguments       = Playlists,
                        Label           = list.Name,
                        DestinationPage = typeof(PlaylistView),
                        Symbol          = Symbol.List
                    });
                    GC.Collect();
                }
            }
            else
            {
                PlaylistCollection = new ThreadSafeObservableCollection <Playlist>();
            }
        }
Example #2
0
        async Task <Dictionary <Playlist, IEnumerable <Mediafile> > > ShowAddPlaylistDialog()
        {
            var dialog = new InputDialog()
            {
                Title = "Name this playlist",
            };
            var Playlists = new Dictionary <Playlist, IEnumerable <Mediafile> >();

            if (await dialog.ShowAsync() == ContentDialogResult.Primary && dialog.Text != "")
            {
                if (!PlaylistCollection.Any(t => t.Name == dialog.Text))
                {
                    var pl = new Playlist()
                    {
                        Name = dialog.Text, Description = dialog.Description
                    };
                    Playlists.Add(pl, db.PlaylistSort(pl.Name));
                    var cmd = new ContextMenuCommand(AddToPlaylistCommand, pl.Name);
                    Options.Add(cmd);

                    ShellVM.PlaylistsItems.Add(new SplitViewMenu.SimpleNavMenuItem
                    {
                        Arguments       = Playlists,
                        Label           = dialog.Text,
                        DestinationPage = typeof(PlaylistView),
                        Symbol          = Symbol.List
                    });
                }


                return(Playlists);
            }
            return(Playlists);
        }
Example #3
0
        /// <summary>
        /// Creates a contextual menu and associates it to the left- or right-click command.  That method will bind a new
        /// <see cref="ObservableHierarchicalCommandObject"/> to the menu; essentially, you call this overload only when you want
        /// to provide you own template and style for the menu.  Otherwise, call the overload that takes a single argument, or pass
        /// a <see cref="StandardCommandContextMenu"/> which has all the templates it needs to build the menu correctly.
        /// </summary>
        /// <param name="mouseClickButton">Either <see cref="MouseButton.Left"/> or <see cref="MouseButton.Right"/>.  The contextual menu will
        /// be associated with that button's click event.</param>
        /// <param name="menu">A context menu.  By default, you should use <see cref="StandardCommandContextMenu"/>.</param>
        /// <exception cref="ArgumentException">Raised if <paramref name="mouseClickButton"/> is neither <see cref="MouseButton.Left"/> nor <see cref="MouseButton.Right"/>.</exception>
        /// <exception cref="ArgumentNullException">Raised if <paramref name="menu"/> is null.</exception>
        public ObservableHierarchicalCommandObject CreateHierarchicalMenu(MouseButton mouseClickButton, ContextMenu menu)
        {
            if (mouseClickButton != MouseButton.Left && mouseClickButton != MouseButton.Right)
            {
                throw new ArgumentException(string.Format("Mouse button {0} not supported.", mouseClickButton.ToString()));
            }

            if (menu == null)
            {
                throw new ArgumentNullException("menu");
            }

            ObservableHierarchicalCommandObject menuItems;
            ContextMenuCommand cmd;

            menu.Placement   = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
            cmd              = new ContextMenuCommand(menu);
            menuItems        = new ObservableHierarchicalCommandObject();
            menu.ItemsSource = menuItems.Children;

            if (mouseClickButton == MouseButton.Left)
            {
                _leftClickMenu        = menuItems;
                this.LeftClickCommand = cmd;
            }
            else
            {
                _rightClickMenu        = menuItems;
                this.RightClickCommand = cmd;
            }
            return(menuItems);
        }
Example #4
0
        static ContextMenu AnyAndRefreshContextMenu(ContextMenuCommand[] commands, Action any, Action refresh)
        {
            return(new ContextMenu()
            {
                List = new ObservableList <ContextMenuCommand>(commands),
                Renderer = delegate(IMenuItem menuItem, IHierarchyLevel menuLevel, long menuIndex)
                {
                    ContextMenuCommand command = (ContextMenuCommand)menuLevel.List[menuIndex];
                    menuItem.Text = command.Name;
                    menuItem.ImageClass = command.Image + "Icon";
                    if (command == refreshCommand)
                    {
                        menuItem.SeparatorBefore = true;
                    }
                },

                Execute = delegate(IHierarchyLevel menuLevel, long menuIndex)
                {
                    ContextMenuCommand command = (ContextMenuCommand)menuLevel.List[menuIndex];
                    if (command == refreshCommand)
                    {
                        refresh();
                    }
                    else
                    {
                        any();
                    }
                }
            });
        }
Example #5
0
        public DirectoryTree2()
        {
            #region ContextMenu
            this.AddHandler(TreeViewItem.MouseRightButtonUpEvent, new MouseButtonEventHandler(
                                (MouseButtonEventHandler) delegate(object sender, MouseButtonEventArgs args)
            {
                TreeViewItem sourceItem = UITools.GetParentTreeViewItem(args.OriginalSource as FrameworkElement);
                if (sourceItem != null)
                {
                    if (!sourceItem.IsSelected)
                    {
                        TreeViewItemAutomationPeer peer   = new TreeViewItemAutomationPeer(sourceItem);
                        ISelectionItemProvider invokeProv = peer.GetPattern(PatternInterface.SelectionItem) as ISelectionItemProvider;
                        invokeProv.Select();
                    }

                    if (sourceItem.IsSelected)
                    {
                        if (ContextMenuCommand != null && ContextMenuCommand.CanExecute(this.SelectedItem))
                        {
                            ContextMenuCommand.Execute(this.SelectedItem);
                        }
                    }
                }
            }));

            #endregion

            W7TreeViewItemUtils.SetIsEnabled(this, true);
        }
Example #6
0
        /// <summary>
        /// Context menu item is clicked
        /// </summary>
        void contextMenuItem_Click(object sender, RoutedEventArgs e)
        {
            MenuItem item = sender as MenuItem;

            if (item == null)
            {
                return;
            }

            ContextMenuCommand command = (ContextMenuCommand)item.Tag;

            switch (command)
            {
            case ContextMenuCommand.SelectAll:
                SelectAll();
                break;

            case ContextMenuCommand.UnselectAll:
                UnselectAll();
                break;

            case ContextMenuCommand.Delete:
                Delete();
                break;

            case ContextMenuCommand.DeleteAll:
                DeleteAll();
                break;

            case ContextMenuCommand.MoveToFront:
                MoveToFront();
                break;

            case ContextMenuCommand.MoveToBack:
                MoveToBack();
                break;

            case ContextMenuCommand.Undo:
                Undo();
                break;

            case ContextMenuCommand.Redo:
                Redo();
                break;

            case ContextMenuCommand.SerProperties:
                SetProperties();
                break;
            }
        }
Example #7
0
        public void AddPlaylist(Playlist Playlist)
        {
            var cmd = new ContextMenuCommand(AddToPlaylistCommand, Playlist.Name);

            OptionItems.Add(cmd);
            PlaylistsItems.Add(new SplitViewMenu.SimpleNavMenuItem
            {
                Arguments       = Playlist,
                Label           = Playlist.Name,
                DestinationPage = typeof(PlaylistView),
                Symbol          = Symbol.List,
                FontGlyph       = "\u0045"
            });
        }
Example #8
0
        private void RegisterContextMenus()
        {
            IEnumerable <object> items = ItemsSource.OfType <object>();

            if (EnableBasicContextMenu)
            {
                ContextMenuCommand.AddRange(GetContext(new BasicContextMenu <object>(items)));
            }

            if (EnableExporterContextMenu)
            {
                ContextMenuCommand.AddRange(GetContext(new ExporterContextMenu <object>()));
            }
        }
Example #9
0
            public static void RunReset(bool all = false)
            {
                RuntimeInfo.Config.Reset();

                // Computer\HKEY_CLASSES_ROOT\*\shell\SmartImage

                ContextMenuCommand.Remove();

                // will be added automatically if run again
                //Path.Remove();

                if (all)
                {
                    RuntimeInfo.Config.Reset();
                    RuntimeInfo.Config.WriteToFile();

                    CliOutput.WriteSuccess("Reset cfg");
                    return;
                }
            }
        public void AddPlaylist(Dictionary <Playlist, IEnumerable <Mediafile> > Playlists, string label, string description)
        {
            var pl = new Playlist()
            {
                Name = label, Description = description
            };

            Playlists.Add(pl, TracksCollection.Elements.Where(a => a.Playlists.All(t => t.Name == pl.Name) && a.Playlists.Count == 1));
            var cmd = new ContextMenuCommand(AddToPlaylistCommand, pl.Name);

            Options.Add(cmd);
            pl.Songs.AddRange(Playlists.Values.First());
            db.playlists.Insert(pl);
            ShellVM.PlaylistsItems.Add(new SplitViewMenu.SimpleNavMenuItem
            {
                Arguments       = Playlists,
                Label           = label,
                DestinationPage = typeof(PlaylistView),
                Symbol          = Symbol.List,
                FontGlyph       = "\ue823"
            });
        }
Example #11
0
        /// <summary>
        /// Show context menu.
        /// </summary>
        void ShowContextMenu(MouseButtonEventArgs e)
        {
            // Change current selection if necessary

            Point point = e.GetPosition(this);

            GraphicsBase o = null;

            for (int i = graphicsList.Count - 1; i >= 0; i--)
            {
                if (((GraphicsBase)graphicsList[i]).MakeHitTest(point) == 0)
                {
                    o = (GraphicsBase)graphicsList[i];
                    break;
                }
            }

            if (o != null)
            {
                if (!o.IsSelected)
                {
                    UnselectAll();
                }

                // Select clicked object
                o.IsSelected = true;
            }
            else
            {
                UnselectAll();
            }

            UpdateState();

            MenuItem item;

            /// Enable/disable menu items.
            foreach (object obj in contextMenu.Items)
            {
                item = obj as MenuItem;

                if (item != null)
                {
                    ContextMenuCommand command = (ContextMenuCommand)item.Tag;

                    switch (command)
                    {
                    case ContextMenuCommand.SelectAll:
                        item.IsEnabled = CanSelectAll;
                        break;

                    case ContextMenuCommand.UnselectAll:
                        item.IsEnabled = CanUnselectAll;
                        break;

                    case ContextMenuCommand.Delete:
                        item.IsEnabled = CanDelete;
                        break;

                    case ContextMenuCommand.DeleteAll:
                        item.IsEnabled = CanDeleteAll;
                        break;

                    case ContextMenuCommand.MoveToFront:
                        item.IsEnabled = CanMoveToFront;
                        break;

                    case ContextMenuCommand.MoveToBack:
                        item.IsEnabled = CanMoveToBack;
                        break;

                    case ContextMenuCommand.Undo:
                        item.IsEnabled = CanUndo;
                        break;

                    case ContextMenuCommand.Redo:
                        item.IsEnabled = CanRedo;
                        break;

                    case ContextMenuCommand.SerProperties:
                        item.IsEnabled = CanSetProperties;
                        break;
                    }
                }
            }

            contextMenu.IsOpen = true;
        }
Example #12
0
 private static void AddItemsToMenu(System.Collections.IList collection, System.Collections.Generic.List <MenuItemDescriptor> descriptors)
 {
     foreach (MenuItemDescriptor current in descriptors)
     {
         object obj = MenuService.CreateMenuItemFromDescriptor(current);
         if (obj is MenuRibbonPageCategory)
         {
             MenuService.Add(collection, obj);
             if (current.SubItems != null)
             {
                 MenuService.AddItemsToMenu(((MenuRibbonPageCategory)obj).Pages, MenuService.ToList(current.SubItems));
             }
         }
         else if (obj is MenuRibbonPage)
         {
             MenuService.Add(collection, obj);
             if (current.SubItems != null)
             {
                 MenuService.AddItemsToMenu(((MenuRibbonPage)obj).Groups, MenuService.ToList(current.SubItems));
             }
         }
         else
         {
             if (obj is MenuRibbonPageGroup)
             {
                 MenuRibbonPageGroup group = (MenuRibbonPageGroup)obj;
                 if (group != null)
                 {
                     Add(collection, group);
                     if (current.SubItems != null)
                     {
                         AddItemsToMenu(((MenuRibbonPageGroup)obj).ItemLinks, ToList(current.SubItems));
                     }
                 }
                 continue;
             }
             if (obj is MenuSubItemCommand)
             {
                 Add(collection, obj);
                 ((MenuSubItemCommand)obj).CreateItems();
                 continue;
             }
             //if (obj is MenuButtonGroupCommand)
             //{
             //    MenuService.Add(collection, obj);
             //    if (current.SubItems != null)
             //    {
             //        MenuService.AddItemsToMenu(((MenuButtonGroupCommand)obj).ItemLinks, MenuService.ToList(current.SubItems));
             //    }
             //}
             if (obj is BarItem)
             {
                 Add(collection, obj);
                 if (obj is IStatusUpdate)
                 {
                     ((IStatusUpdate)obj).UpdateStatus();
                     ((IStatusUpdate)obj).UpdateText();
                 }
                 continue;
             }
             if (obj is ContextMenuCommand)
             {
                 ContextMenuCommand command2 = obj as ContextMenuCommand;
                 if (command2 != null)
                 {
                     Add(collection, command2);
                 }
             }
         }
     }
 }
Example #13
0
        internal static ContextMenu FolderItemsContextMenu(FolderItems folderItems, ListItem listItem, Action delete)
        {
            ContextMenuCommands commands = folderItems.ParentFolder.ParentList.BaseType == BaseType.DocumentLibrary
                ? libraryCommands : listCommands;

            ContextMenuCommand[] menuItems = commands.None;
            if (listItem != null)
            {
                menuItems = listItem.FileSystemObjectType == FileSystemObjectType.Folder ? commands.Folder : commands.Item;
            }

            return(new ContextMenu()
            {
                List = new ObservableList <ContextMenuCommand>(menuItems),
                Execute = delegate(IHierarchyLevel menuLevel, long menuIndex)
                {
                    ContextMenuCommand command = (ContextMenuCommand)menuLevel.List[menuIndex];
                    switch (command.EditMode)
                    {
                    case EditMode.Refresh:
                        folderItems.Refresh();
                        break;

                    case EditMode.Edit:
                        ListItemEditor.Show(new EditAction()
                        {
                            EditMode = command.EditMode, ListItem = listItem, TargetList = listItem.ParentList
                        });
                        break;

                    case EditMode.Open:
                        HtmlWindow.Current.Open(listItem.AbsoluteUrl);
                        break;

                    case EditMode.Upload:
                        Uploader.Upload(folderItems.ParentFolder);
                        break;

                    case EditMode.AddItem:
                    case EditMode.AddFolder:
                        ListItemEditor.Show(new EditAction()
                        {
                            EditMode = command.EditMode,
                            TargetFolder = folderItems.ParentFolder,
                            TargetList = folderItems.ParentFolder.ParentList
                        });
                        break;


                    case EditMode.Copy:
                        ListItemEditor.Show(new EditAction()
                        {
                            EditMode = command.EditMode,
                            ListItem = listItem,
                            TargetFolder = folderItems.ParentFolder,
                            TargetList = folderItems.ParentFolder.ParentList
                        });
                        break;

                    default:
                        delete();
                        break;
                    }
                },
                Renderer = delegate(IMenuItem menuItem, IHierarchyLevel menuLevel, long menuIndex)
                {
                    ContextMenuCommand command = (ContextMenuCommand)menuLevel.List[menuIndex];
                    menuItem.Text = command.Name;
                    menuItem.ImageClass = command.Image + "Icon";
                    menuItem.SeparatorBefore = (command.EditMode == EditMode.Refresh || command.EditMode == EditMode.Delete || command.EditMode == EditMode.Copy);
                    switch (command.EditMode)
                    {
                    case EditMode.AddFolder:
                        menuItem.Enabled = folderItems.ParentFolder.IsRootFolder ||
                                           (folderItems.ParentFolder.Item.EffectiveBasePermissions & BasePermissions.AddListItems)
                                           == BasePermissions.AddListItems;
                        break;

                    case EditMode.AddItem:
                    case EditMode.Copy:
                        menuItem.Enabled = folderItems.ParentFolder.ParentList.BaseType != BaseType.DocumentLibrary &&
                                           (folderItems.ParentFolder.IsRootFolder ||
                                            (folderItems.ParentFolder.Item.EffectiveBasePermissions & BasePermissions.AddListItems)
                                            == BasePermissions.AddListItems);
                        break;

                    case EditMode.Delete:
                        menuItem.Enabled = (listItem.EffectiveBasePermissions & BasePermissions.DeleteListItems) == BasePermissions.DeleteListItems;
                        break;

                    case EditMode.Edit:
                        menuItem.Enabled = BasePermissions.EditListItems == (BasePermissions.EditListItems & listItem.EffectiveBasePermissions);
                        break;

                    case EditMode.Refresh:
                        menuItem.Enabled = folderItems.CanRefresh;
                        break;
                    }
                }
            });
        }
Example #14
0
        internal static ContextMenu FolderContextMenu(FolderNode folder)
        {
            ContextMenuCommands commands = folder.ParentList.BaseType == BaseType.DocumentLibrary
                ? libraryCommands : listCommands;

            return(new ContextMenu()
            {
                List = new ObservableList <ContextMenuCommand>(folder.IsRootFolder ? commands.List : commands.Folder),
                Execute = delegate(IHierarchyLevel menuLevel, long menuIndex)
                {
                    ContextMenuCommand command = (ContextMenuCommand)menuLevel.List[menuIndex];
                    switch (command.EditMode)
                    {
                    case EditMode.Refresh:
                        if (!folder.IsRootFolder)
                        {
                            folder.Refresh();
                        }
                        else
                        {
                            ((ListNode)folder.ParentList).Refresh();
                        }
                        break;

                    case EditMode.Edit:
                        ListItemEditor.Show(new EditAction()
                        {
                            EditMode = command.EditMode, ListItem = folder.Item, TargetList = folder.ParentList
                        });
                        break;

                    case EditMode.AddItem:
                        ListItemEditor.Show(new EditAction()
                        {
                            EditMode = command.EditMode, TargetFolder = folder, TargetList = folder.ParentList
                        });
                        break;

                    case EditMode.Upload:
                        Uploader.Upload(folder);
                        break;

                    case EditMode.AddFolder:
                        ListItemEditor.Show(new EditAction()
                        {
                            EditMode = command.EditMode, TargetFolder = folder, TargetList = folder.ParentList
                        });
                        break;

                    default:
                        if (folder.IsRootFolder)
                        {
                            throw new NotImplementedException("List deletion is not implemented yet.");
                        }

                        DeleteFolder(folder);
                        break;
                    }
                },
                Renderer = delegate(IMenuItem menuItem, IHierarchyLevel menuLevel, long menuIndex)
                {
                    ContextMenuCommand command = (ContextMenuCommand)menuLevel.List[menuIndex];
                    switch (command.EditMode)
                    {
                    case EditMode.AddFolder:
                    case EditMode.AddItem:
                        menuItem.Enabled = folder.IsRootFolder || (folder.Item.EffectiveBasePermissions & BasePermissions.AddListItems) == BasePermissions.AddListItems;
                        break;

                    case EditMode.Delete:
                        menuItem.Enabled = folder.IsRootFolder || (folder.Item.EffectiveBasePermissions & BasePermissions.DeleteListItems) == BasePermissions.DeleteListItems;
                        break;

                    case EditMode.Edit:
                        menuItem.Enabled = !folder.IsRootFolder || BasePermissions.EditListItems == (BasePermissions.EditListItems & folder.Item.EffectiveBasePermissions);
                        break;

                    case EditMode.Refresh:
                        menuItem.Enabled = true;
                        break;
                    }


                    menuItem.Text = command.Name;
                    menuItem.ImageClass = command.Image + "Icon";
                    menuItem.SeparatorBefore = (command.EditMode == EditMode.Refresh || command.EditMode == EditMode.Delete || command.EditMode == EditMode.AddItem);
                }
            });
        }
Example #15
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            SelectionHelper.SetEnableSelection(this, true);

            UpdateCollumnHeader();


            #region Update scroll position if scroll bar disappear
            ScrollViewer scrollView = UITools.FindVisualChild <ScrollViewer>(this);

            DependencyPropertyDescriptor vertScrollbarVisibilityDescriptor =
                DependencyPropertyDescriptor.FromProperty(
                    ScrollViewer.ComputedVerticalScrollBarVisibilityProperty, typeof(ScrollViewer));

            vertScrollbarVisibilityDescriptor.AddValueChanged
                (scrollView, delegate
            {
                if (scrollView.ComputedHorizontalScrollBarVisibility == System.Windows.Visibility.Collapsed)
                {
                    VirtualizingPanel panel = UITools.FindVisualChild <VirtualizingPanel>(this);
                    if (panel is IScrollInfo)
                    {
                        (panel as IScrollInfo).SetVerticalOffset(0);
                    }
                }
            });

            DependencyPropertyDescriptor horzScrollbarVisibilityDescriptor =
                DependencyPropertyDescriptor.FromProperty(
                    ScrollViewer.ComputedHorizontalScrollBarVisibilityProperty, typeof(ScrollViewer));

            horzScrollbarVisibilityDescriptor.AddValueChanged
                (scrollView, delegate
            {
                if (scrollView.ComputedHorizontalScrollBarVisibility == System.Windows.Visibility.Collapsed)
                {
                    VirtualizingPanel panel = UITools.FindVisualChild <VirtualizingPanel>(this);
                    if (panel is IScrollInfo)
                    {
                        (panel as IScrollInfo).SetHorizontalOffset(0);
                    }
                }
            });


            #endregion

            #region ContextMenu

            Point mouseDownPt = new Point(-100, -100);

            this.AddHandler(TreeViewItem.PreviewMouseRightButtonDownEvent, new MouseButtonEventHandler(
                                (MouseButtonEventHandler) delegate(object sender, MouseButtonEventArgs args)
            {
                mouseDownPt = args.GetPosition(this);
            }));
            this.AddHandler(TreeViewItem.MouseRightButtonUpEvent, new MouseButtonEventHandler(
                                (MouseButtonEventHandler) delegate(object sender, MouseButtonEventArgs args)
            {
                Point mouseUpPt = args.GetPosition(this);

                if ((Math.Abs(mouseDownPt.X - mouseUpPt.X) < 5) &&
                    (Math.Abs(mouseDownPt.Y - mouseUpPt.Y) < 5))
                {
                    args.Handled = true;
                    if (ContextMenuCommand != null && ContextMenuCommand.CanExecute(this.DataContext))
                    {
                        if (SelectedValue != null)
                        {
                            ContextMenuCommand.Execute(this.DataContext);
                        }
                    }
                }
            }));

            #endregion

            //Memory Leak
            //Unloaded += (o, e) =>
            //{
            //    SelectionHelper.SetEnableSelection(o as FileList2, false);
            //    (o as FileList2).View = null;

            //};
        }