Пример #1
0
        private List <FilesystemItem> GetFilesystemItems(List <string> paths)
        {
            var items = new List <FilesystemItem>();

            foreach (var path in paths)
            {
                FilesystemItem item;
                items.Add(item = new FilesystemItem(path));
                item.CompoundPresenter.Add(new SyncDelegatePresenter <Widget>(_ => {
                    if (item.IsMouseOverThisOrDescendant())
                    {
                        item.PrepareRendererState();
                        Renderer.DrawRect(Vector2.Zero, item.Size, Theme.Colors.DirectoryPickerItemHoveredBackground);
                    }
                }));
                item.Updating += (float delta) => {
                    if (item.Input.WasMouseReleased(0))
                    {
                        window.Close();
                        openPath(item.FilesystemPath);
                    }
                    else if (item.Input.WasMouseReleased(1))
                    {
                        SystemShellContextMenu.Instance.Show(item.FilesystemPath);
                    }
                };
            }
            return(items);
        }
Пример #2
0
 void InitializeWidgets()
 {
     RootWidget.AddChangeWatcher(() => selection.Version, Selection_Changed);
     ScrollView.Content.Layout = new FlowLayout(LayoutDirection.TopToBottom)
     {
         Spacing = 1.0f
     };
     ScrollView.Content.Padding = new Thickness(5.0f);
     ScrollView.Content.CompoundPostPresenter.Insert(0, new SyncDelegatePresenter <Widget>(RenderFilesWidgetRectSelection));
     ScrollView.Updated          += ScrollViewUpdated;
     ScrollView.Content.Presenter = new SyncDelegatePresenter <Widget>((w) => {
         w.PrepareRendererState();
         var wp = w.ParentWidget;
         var p  = wp.Padding;
         Renderer.DrawRect(-w.Position + Vector2.Zero - new Vector2(p.Left, p.Top),
                           -w.Position + wp.Size + new Vector2(p.Right, p.Bottom), Theme.Colors.WhiteBackground);
     });
     RootWidget.AddChangeWatcher(() => dragState, (ds) => Window.Current.Invalidate());
     RootWidget.AddChangeWatcher(() => dragEndPosition, WhenSelectionRectChanged);
     RootWidget.AddChangeWatcher(() => WidgetContext.Current.NodeUnderMouse, (value) => {
         if (value != null && ScrollView.Content == value.Parent)
         {
             Window.Current.Invalidate();
         }
     });
     RootWidget.AddChangeWatcher(() => model.CurrentPath, (p) => {
         var up  = RootWidget.Components.Get <ViewNodeComponent>().ViewNode as FSViewNode;
         up.Path = p;
         AddToNavHystory(p);
         selection.Clear();
         InvalidateView(p);
         InvalidateFSWatcher(p);
         preview.ClearTextureCache();
         lastKeyboardSelectedFilesystemItem = ScrollView.Content.FirstChild as FilesystemItem;
     });
     RootWidget.Layout = new VBoxLayout();
     RootWidget.AddNode((cookingRulesSplitter = new ThemedHSplitter {
         Nodes =
         {
             (new Widget {
                 Layout = new VBoxLayout(),
                 Nodes =
                 {
                     toolbar,
                     (selectionPreviewSplitter = new ThemedVSplitter{
                         Nodes =
                         {
                             ScrollView,
                             preview.RootWidget,
                         }
                     })
                 }
             }),
             crEditor.RootWidget,
         }
     }));
 }
Пример #3
0
 private void InvalidateView(string path)
 {
     scrollView.Content.Nodes.Clear();
     foreach (var item in model.EnumerateItems())
     {
         var fsItem = new FilesystemItem(item);
         scrollView.Content.AddNode(fsItem);
         fsItem.CompoundPresenter.Insert(0, new DelegatePresenter <FilesystemItem>(RenderFSItemSelection));
     }
 }
Пример #4
0
 private void InvalidateView(string path, SortType sortType, OrderType orderType)
 {
     ScrollView.Content.Nodes.Clear();
     foreach (var item in model.EnumerateItems(sortType, orderType))
     {
         var fsItem = new FilesystemItem(item);
         ScrollView.Content.AddNode(fsItem);
         fsItem.CompoundPresenter.Insert(0, new SyncDelegatePresenter <FilesystemItem>(RenderFSItemSelection));
     }
 }
Пример #5
0
        private void ProcessTypingNavigation()
        {
            var input = ScrollView.Input;

            if (string.IsNullOrEmpty(input.TextInput))
            {
                return;
            }
            if (typeNavigationTimeout <= 0.0f)
            {
                typeNavigationPrefix = string.Empty;
            }
            typeNavigationTimeout = typeNavigationInterval;
            var  prevPrefix = typeNavigationPrefix;
            bool offset     = false;

            if (prevPrefix == input.TextInput)
            {
                offset = true;
            }
            else
            {
                typeNavigationPrefix += input.TextInput;
            }
            var matches = ScrollView.Content.Nodes
                          .Select(i => i as FilesystemItem)
                          .Where(i => {
                var a = Path.GetFileName(i.FilesystemPath);
                var b = typeNavigationPrefix;
                return(a.StartsWith(b, true, CultureInfo.CurrentCulture));
            })
                          .ToList();

            if (matches.Count != 0)
            {
                var index = matches.IndexOf(lastKeyboardSelectedFilesystemItem);
                if (index == -1)
                {
                    index = 0;
                }
                if (offset)
                {
                    index = (index + 1) % matches.Count;
                }
                selection.Clear();
                selection.Select(matches[index].FilesystemPath);
                lastKeyboardSelectedFilesystemItem = matches[index];
                EnsureFSItemVisible(lastKeyboardSelectedFilesystemItem);
            }
        }
Пример #6
0
        private void ProcessChangeViewMode()
        {
            if (
                ScrollView.Input.IsKeyPressed(Key.Control) &&
                (ScrollView.Input.WasKeyPressed(Key.MouseWheelDown) || ScrollView.Input.WasKeyPressed(Key.MouseWheelUp))
                )
            {
                ScrollView.Unlink();
                if (ScrollView.Direction == ScrollDirection.Horizontal)
                {
                    ScrollView = new ThemedScrollView(ScrollDirection.Vertical)
                    {
                        TabTravesable = new TabTraversable(),
                    };
                    ScrollView.Content.Layout = new FlowLayout(LayoutDirection.LeftToRight)
                    {
                        Spacing = 1.0f
                    };
                }
                else
                {
                    ScrollView = new ThemedScrollView(ScrollDirection.Horizontal)
                    {
                        TabTravesable = new TabTraversable(),
                    };
                    ScrollView.Content.Layout = new FlowLayout(LayoutDirection.TopToBottom)
                    {
                        Spacing = 1.0f
                    };
                }

                ScrollView.Content.Padding = new Thickness(5.0f);
                ScrollView.Content.CompoundPostPresenter.Insert(0, new SyncDelegatePresenter <Widget>(RenderFilesWidgetRectSelection));
                ScrollView.Updated          += ScrollViewUpdated;
                ScrollView.Content.Presenter = new SyncDelegatePresenter <Widget>((w) => {
                    w.PrepareRendererState();
                    var wp = w.ParentWidget;
                    var p  = wp.Padding;
                    Renderer.DrawRect(-w.Position + Vector2.Zero - new Vector2(p.Left, p.Top),
                                      -w.Position + wp.Size + new Vector2(p.Right, p.Bottom), Theme.Colors.WhiteBackground);
                });

                InvalidateView(model.CurrentPath);
                lastKeyboardSelectedFilesystemItem = ScrollView.Content.FirstChild as FilesystemItem;

                selectionPreviewSplitter.Nodes.Insert(0, ScrollView);
            }
        }
Пример #7
0
        private void EnsureFSItemVisible(FilesystemItem fsItem)
        {
            float min    = 0;
            float offset = 0;
            var   pos    = fsItem.CalcPositionInSpaceOf(ScrollView);

            if (ScrollView.Direction == ScrollDirection.Vertical)
            {
                min    = pos.Y;
                offset = min + fsItem.Height - ScrollView.Height;
            }
            else if (ScrollView.Direction == ScrollDirection.Horizontal)
            {
                min    = pos.X;
                offset = min + fsItem.Width - ScrollView.Width;
            }
            EnsureRangeVisible(min, offset);
        }
Пример #8
0
 private void RenderFSItemSelection(FilesystemItem filesystemItem)
 {
     if (selection.Contains(filesystemItem.FilesystemPath))
     {
         filesystemItem.PrepareRendererState();
         Renderer.DrawRect(Vector2.Zero, filesystemItem.Size, Theme.Colors.SelectedBackground);
     }
     else if (filesystemItem.IsMouseOverThisOrDescendant())
     {
         filesystemItem.PrepareRendererState();
         Renderer.DrawRect(
             Vector2.Zero,
             filesystemItem.Size,
             Theme.Colors.HoveredBackground);
     }
     if (filesystemItem == lastKeyboardRangeSelectionEndFilesystemItem)
     {
         filesystemItem.PrepareRendererState();
         Renderer.DrawRectOutline(Vector2.Zero, filesystemItem.Size, Theme.Colors.SelectedBorder);
     }
 }
Пример #9
0
        private void EnsureFSItemVisible(FilesystemItem fsItem)
        {
            var y = fsItem.CalcPositionInSpaceOf(scrollView).Y;

            EnsureRangeVisible(y, y + fsItem.Height);
        }
Пример #10
0
        private void ProcessSelectionCommands()
        {
            int  indexDelta = 0;
            bool select     = false;
            bool toggle     = false;
            var  index      = 0;
            var  maxIndex   = scrollView.Content.Nodes.Count - 1;

            if (lastKeyboardSelectedFilesystemItem != null)
            {
                index = scrollView.Content.Nodes.IndexOf(lastKeyboardSelectedFilesystemItem);
            }
            int rangeSelectionIndex = index;

            if (lastKeyboardRangeSelectionEndFilesystemItem != null)
            {
                rangeSelectionIndex = scrollView.Content.Nodes.IndexOf(lastKeyboardRangeSelectionEndFilesystemItem);
            }
            var   flowLayout  = (scrollView.Content.Layout as FlowLayout);
            int   columnCount = flowLayout.ColumnCount(0);
            float rowHeight   = FilesystemItem.ItemPadding * 2 + FilesystemItem.IconSize;

            for (int navType = 0; navType < navCommands.Count; navType++)
            {
                for (int navOffset = 0; navOffset < navCommands[navType].Count; navOffset++)
                {
                    var cmd = navCommands[navType][navOffset];
                    if (cmd.Consume())
                    {
                        select = navType == 1;
                        toggle = navType == 2;
                        var sign = (navOffset % 2 == 0 ? -1 : 1);
                        switch (navOffset)
                        {
                        // Left, Right
                        case 0:
                        case 1: indexDelta = sign * 1; break;

                        // Up,  Down
                        case 2:
                        case 3:  indexDelta = sign * columnCount; break;

                        // PageUp, PageDown
                        case 4:
                        case 5: indexDelta = sign * columnCount * ((int)(scrollView.Size.Y / (rowHeight + flowLayout.Spacing)) - 1); break;

                        // Home
                        case 6: indexDelta = -rangeSelectionIndex; break;

                        // End
                        case 7: indexDelta = maxIndex - rangeSelectionIndex; break;
                        }
                    }
                }
            }
            if (indexDelta != 0)
            {
                if (select)
                {
                    int selectionEndIndex = lastKeyboardRangeSelectionEndFilesystemItem != null
                                                ? scrollView.Content.Nodes.IndexOf(lastKeyboardRangeSelectionEndFilesystemItem)
                                                : index;

                    int newIndex = selectionEndIndex + indexDelta;
                    if (newIndex >= 0 && newIndex <= maxIndex)
                    {
                        selection.Clear();
                        for (int i = Math.Min(index, newIndex); i <= Math.Max(index, newIndex); i++)
                        {
                            var path = (scrollView.Content.Nodes[i] as FilesystemItem).FilesystemPath;
                            selection.Select(path);
                        }
                        lastKeyboardRangeSelectionEndFilesystemItem = scrollView.Content.Nodes[newIndex] as FilesystemItem;
                        EnsureFSItemVisible(lastKeyboardRangeSelectionEndFilesystemItem);
                    }
                }
                else
                {
                    if (!toggle)
                    {
                        int newIndex = index + indexDelta;
                        if (newIndex >= 0 && newIndex <= maxIndex)
                        {
                            lastKeyboardSelectedFilesystemItem = scrollView.Content.Nodes[newIndex] as FilesystemItem;
                            var path = lastKeyboardSelectedFilesystemItem.FilesystemPath;
                            selection.Clear();
                            selection.Select(path);
                            lastKeyboardRangeSelectionEndFilesystemItem = null;
                            EnsureFSItemVisible(lastKeyboardSelectedFilesystemItem);
                        }
                    }
                    else
                    {
                        int selectionEndIndex = lastKeyboardRangeSelectionEndFilesystemItem != null
                                                        ? scrollView.Content.Nodes.IndexOf(lastKeyboardRangeSelectionEndFilesystemItem)
                                                        : index;

                        int newIndex = selectionEndIndex + indexDelta;
                        if (newIndex >= 0 && newIndex <= maxIndex)
                        {
                            lastKeyboardRangeSelectionEndFilesystemItem = scrollView.Content.Nodes[newIndex] as FilesystemItem;
                            EnsureFSItemVisible(lastKeyboardRangeSelectionEndFilesystemItem);
                            Window.Current.Invalidate();
                        }
                    }
                }
            }
        }
Пример #11
0
        private void ProcessInputOverFSItem()
        {
            // TODO: Ctrl + Shift, Shift clicks
            var nodeUnderMouse = WidgetContext.Current.NodeUnderMouse;

            if (
                nodeUnderMouse == null ||
                !(nodeUnderMouse is FilesystemItem ||
                  nodeUnderMouse.Parent is FilesystemItem)
                )
            {
                return;
            }
            var fsItem = nodeUnderMouse as FilesystemItem ?? nodeUnderMouse.Parent as FilesystemItem;
            var path   = fsItem.FilesystemPath;
            var input  = fsItem.Input;

            if (input.ConsumeKeyPress(Key.Mouse0DoubleClick))
            {
                scrollView.SetFocus();
                Open(path);
            }
            if (fsItem.Input.ConsumeKeyRelease(Key.Mouse1))
            {
                scrollView.SetFocus();
                if (!selection.Contains(path))
                {
                    selection.Clear();
                    selection.Select(path);
                }
                SystemShellContextMenu.Instance.Show(selection);
            }
            if (fsItem.Input.ConsumeKeyRelease(Key.Mouse0))
            {
                scrollView.SetFocus();
                if (!fsItem.IsMouseOver() || selection.Contains(path))
                {
                    if (dragState != DragState.Selecting && dragState != DragState.Dragging && !fsItem.Input.IsKeyPressed(Key.Control))
                    {
                        selection.Clear();
                    }
                    selection.Select(path);
                    lastKeyboardSelectedFilesystemItem = fsItem;
                }
                dragState = DragState.None;
            }
            if (fsItem.Input.WasKeyPressed(Key.Mouse0))
            {
                scrollView.SetFocus();
                input.ConsumeKey(Key.Mouse0);
                if (input.IsKeyPressed(Key.Control) && !input.IsKeyPressed(Key.Shift))
                {
                    input.ConsumeKey(Key.Control);
                    if (selection.Contains(path))
                    {
                        selection.Deselect(path);
                    }
                    else
                    {
                        selection.Select(path);
                    }
                }
                else
                {
                    if (selection.Contains(path))
                    {
                        dragState         = DragState.WaitingForDragging;
                        dragStartPosition = Window.Current.Input.MousePosition;
                        lastKeyboardSelectedFilesystemItem = fsItem;
                    }
                    else
                    {
                        if (!fsItem.IsMouseOver())
                        {
                            dragState         = DragState.WaitingForSelecting;
                            dragStartPosition = scrollView.Content.LocalMousePosition();
                        }
                        else
                        {
                            if (!selection.Contains(path))
                            {
                                selection.Clear();
                                selection.Select(path);
                            }
                            dragState         = DragState.WaitingForDragging;
                            dragStartPosition = Window.Current.Input.MousePosition;
                            lastKeyboardSelectedFilesystemItem = fsItem;
                        }
                    }
                }
                Window.Current?.Invalidate();
            }
        }
Пример #12
0
        private void ProcessInputOverFSItem()
        {
            // TODO: Ctrl + Shift clicks
            var nodeUnderMouse = WidgetContext.Current.NodeUnderMouse;

            if (
                nodeUnderMouse == null ||
                !(
                    nodeUnderMouse is FilesystemItem &&
                    nodeUnderMouse.Parent == ScrollView.Content ||
                    nodeUnderMouse.Parent is FilesystemItem &&
                    nodeUnderMouse.Parent.Parent == ScrollView.Content
                    )
                )
            {
                return;
            }
            var fsItem = nodeUnderMouse as FilesystemItem ?? nodeUnderMouse.Parent as FilesystemItem;
            var path   = fsItem.FilesystemPath;
            var input  = fsItem.Input;

            if (input.ConsumeKeyPress(Key.Mouse0DoubleClick))
            {
                ScrollView.SetFocus();
                Open(path);
            }
            if (fsItem.Input.ConsumeKeyRelease(Key.Mouse1))
            {
                ScrollView.SetFocus();
                if (!selection.Contains(path))
                {
                    selection.Clear();
                    selection.Select(path);
                }
                SystemShellContextMenu.Instance.Show(selection);
            }
            if (fsItem.Input.ConsumeKeyRelease(Key.Mouse0))
            {
                ScrollView.SetFocus();
                if (!fsItem.IsMouseOver() || selection.Contains(path))
                {
                    if (
                        dragState != DragState.Selecting &&
                        dragState != DragState.Dragging &&
                        !fsItem.Input.IsKeyPressed(Key.Control) &&
                        !fsItem.Input.IsKeyPressed(Key.Shift)
                        )
                    {
                        selection.Clear();
                    }
                    selection.Select(path);
                    lastKeyboardSelectedFilesystemItem = fsItem;
                }
                dragState = DragState.None;
            }
            if (fsItem.Input.WasKeyPressed(Key.Mouse0))
            {
                ScrollView.SetFocus();
                input.ConsumeKey(Key.Mouse0);
                if (input.IsKeyPressed(Key.Control) && !input.IsKeyPressed(Key.Shift))
                {
                    input.ConsumeKey(Key.Control);
                    if (selection.Contains(path))
                    {
                        selection.Deselect(path);
                    }
                    else
                    {
                        selection.Select(path);
                        lastSelected = path;
                    }
                }
                else if (!input.IsKeyPressed(Key.Control) && input.IsKeyPressed(Key.Shift))
                {
                    input.ConsumeKey(Key.Shift);
                    var items        = model.EnumerateItems(sortType, orderType).ToList();
                    var currentIndex = items.IndexOf(path);
                    int prevIndex;
                    if (lastSelected == default)
                    {
                        prevIndex = items.FindIndex(i => selection.Contains(i));
                    }
                    else
                    {
                        prevIndex = items.IndexOf(lastSelected);
                    }
                    selection.Clear();
                    if (prevIndex == -1)
                    {
                        selection.Select(path);
                        lastSelected = path;
                        return;
                    }
                    lastSelected = items[prevIndex];
                    for (int i = Math.Min(currentIndex, prevIndex); i <= Math.Max(currentIndex, prevIndex); ++i)
                    {
                        selection.Select(items[i]);
                    }
                    fsItem.Input.ConsumeKeyRelease(Key.Mouse0);
                }
                else
                {
                    if (selection.Contains(path))
                    {
                        dragState         = DragState.WaitingForDragging;
                        dragStartPosition = Window.Current.Input.MousePosition;
                        lastKeyboardSelectedFilesystemItem = fsItem;
                    }
                    else
                    {
                        if (!fsItem.IsMouseOver())
                        {
                            dragState         = DragState.WaitingForSelecting;
                            dragStartPosition = ScrollView.Content.LocalMousePosition();
                        }
                        else
                        {
                            if (!selection.Contains(path))
                            {
                                selection.Clear();
                                selection.Select(path);
                                lastSelected = path;
                            }
                            dragState         = DragState.WaitingForDragging;
                            dragStartPosition = Window.Current.Input.MousePosition;
                            lastKeyboardSelectedFilesystemItem = fsItem;
                        }
                    }
                }
                Window.Current?.Invalidate();
            }
        }