Beispiel #1
0
        public void OnSelectFile(FileEntryComponent item)
        {
            switch (ProcessSelection(item, ref _lastSelectTime, _selectedFiles, ref _primarySelectedFile, DoubleClickWindow, Multiselect))
            {
            case SelectResult.Activate:
                if (item.Entry.Type == FileItemType.File)
                {
                    // Confirm.
                    List <string> filenames = new List <string>();
                    foreach (string filename in Filenames)
                    {
                        filenames.Add(filename);
                    }

                    if (ValidateFiles(filenames))
                    {
                        NotifyDone(new CancelEventArgs(false));
                    }
                }
                else
                {
                    CurrentLocation = item.Entry;
                    Location        = item.Entry.FullName;
                }
                break;

            default:
                // Update file name.
                UpdateFilenameDisplayFromSelection();
                NotifyChange("Filename", Filename);
                // NotifyChange("Filenames", Filename);
                break;
            }
        }
Beispiel #2
0
        public void OnSelectLocation(FileEntryComponent item)
        {
            if (_selectedLocation != null && _selectedLocation.Highlight != null)
            {
                _selectedLocation.Highlight.enabled = false;
            }

            _selectedLocation = item;
            if (_selectedLocation != null)
            {
                CurrentLocation = item.Entry;
                Location        = item.Entry.FullName;
                if (_selectedLocation.Highlight != null)
                {
                    _selectedLocation.Highlight.enabled = true;
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Called to the main view to display the given items.
        /// </summary>
        /// <param name="items">The items to display.</param>
        public void ShowItems(FileSystemEntry location, IEnumerable <FileSystemEntry> items)
        {
            CurrentLocation = location;
            SuppressEvents  = true;
            Location        = location.FullName;
            SuppressEvents  = false;
            FilenameDisplay = string.Empty;
            bool horizontal = DisplayMode == FileDisplayMode.Large;
            int  itemCount  = PopulateScrollRect(_filesView, _iconItems[(int)DisplayMode], items, _iconSet,
                                                 _iconModeWidths[(int)DisplayMode], horizontal);

            if (_filesView != null)
            {
                FileEntryComponent initialSelection = null;
                // Bind selection events. Can't be done easily in static code.
                for (int i = 0; i < _filesView.content.childCount; ++i)
                {
                    FileEntryComponent itemUI = _filesView.content.GetChild(i).GetComponent <FileEntryComponent>();
                    foreach (Button button in itemUI.GetComponentsInChildren <Button>())
                    {
                        button.onClick.AddListener(delegate() { this.OnSelectFile(itemUI); });
                        if (!string.IsNullOrEmpty(_pendingSelection) &&
                            itemUI.Entry.FullName.CompareTo(_pendingSelection) == 0)
                        {
                            initialSelection = itemUI;
                        }
                    }
                }

                // Make initial selection.
                if (initialSelection)
                {
                    OnSelectFile(initialSelection);
                }
            }

            if (itemCount != 0 && isActiveAndEnabled)
            {
                StartCoroutine(FixSizeAtEndOfFrame(_filesView, _iconItems[(int)DisplayMode], horizontal));
            }

            _pendingSelection = null;
        }
Beispiel #4
0
        /// <summary>
        /// Called to update the links view to display the given items.
        /// For example, the <paramref name="locations"/> may specify a list of drives.
        /// </summary>
        /// <param name="locations">The locations items.</param>
        public void ShowLinks(IEnumerable <FileSystemEntry> locations)
        {
            int itemCount = PopulateScrollRect(_locationView, _iconItems[(int)FileDisplayMode.Large], locations, _iconSet,
                                               0, true);

            if (_locationView != null)
            {
                // Bind selection events. Can't be done easily in static code.
                for (int i = 0; i < _locationView.content.childCount; ++i)
                {
                    FileEntryComponent itemUI = _locationView.content.GetChild(i).GetComponent <FileEntryComponent>();
                    foreach (Button button in itemUI.GetComponentsInChildren <Button>())
                    {
                        button.onClick.AddListener(delegate() { this.OnSelectLocation(itemUI); });
                    }
                }
            }

            if (itemCount != 0)
            {
                StartCoroutine(FixSizeAtEndOfFrame(_locationView, _iconItems[(int)FileDisplayMode.Large], true));
            }
        }
Beispiel #5
0
        /// <summary>
        /// Resolves selection logic.
        /// </summary>
        /// <param name="item">The item to (de)select.</param>
        /// <param name="lastSelectTime">The last time something was selected. Updated to now if item is selected.</param>
        /// <param name="selectionList">Optional: the list of active selections. Only required for multi-selection support.</param>
        /// <param name="primarySelection">The primary selected item.</param>
        /// <param name="activationWindow">The time window for double click style activation (seconds)</param>
        /// <returns>The selection result.</returns>
        /// <remarks>
        /// Handles multi or single selection. Requires <paramref name="selectionList"/> for multi-select support.
        /// </remarks>
        protected SelectResult ProcessSelection(FileEntryComponent item, ref float lastSelectTime,
                                                List <FileEntryComponent> selectionList,
                                                ref FileEntryComponent primarySelection,
                                                float activationWindow, bool multiselect)
        {
            float selectDelta     = Time.time - lastSelectTime;
            int   selectionIndex  = (selectionList != null) ? selectionList.IndexOf(item) : -1;
            bool  alreadySelected = primarySelection == item || selectionIndex >= 0;

            if (selectDelta <= activationWindow && alreadySelected)
            {
                // Already selected, and we are in the activation windows. Activate.
                return(SelectResult.Activate);
            }

            SelectResult sres = SelectResult.Select;

            if (selectionList != null)
            {
                if (multiselect && AddSelectionActive)
                {
                    // Add selection mode: toggle selection of item.
                    // Try remove from the current selection.
                    if (selectionIndex >= 0)
                    {
                        item.Highlight.enabled = false;
                        _selectedFiles.RemoveAt(selectionIndex);
                        if (primarySelection == item)
                        {
                            if (selectionList.Count != 0)
                            {
                                primarySelection = selectionList[selectionList.Count - 1];
                            }
                            else
                            {
                                primarySelection = null;
                            }
                        }
                        // Removed. We are done here.
                        return(SelectResult.Unselect);
                    }
                    // else don't remove from the current selection.
                    sres = SelectResult.SelectAdd;
                }
                // TODO: Extend selection mode.
                //else if (multiselect && ExtendSelectionActive)
                //{
                //  sres = SelectResult.SelectExtend;
                //}
                else
                {
                    // Clear the current selection. We'll replace it with this item.
                    foreach (FileEntryComponent entry in _selectedFiles)
                    {
                        if (entry.Highlight != null)
                        {
                            entry.Highlight.enabled = false;
                        }
                    }

                    _selectedFiles.Clear();
                }

                sres = SelectResult.Select;
                selectionList.Add(item);
                if (primarySelection != null)
                {
                    primarySelection = item;
                }
            }

            primarySelection = item;

            // Highlight the item.
            if (item.Highlight != null)
            {
                item.Highlight.enabled = true;
            }

            lastSelectTime = Time.time;
            return(sres);
        }
Beispiel #6
0
        protected int PopulateScrollRect(ScrollRect scroll, GameObject template, IEnumerable <FileSystemEntry> items,
                                         FileIconSet icons, int targetWidth, bool startHorizontal)
        {
            if (scroll == null)
            {
                return(0);
            }

            ClearScrollRect(scroll);

            if (template == null)
            {
                return(0);
            }

            // We modify the template width because it's the the simplest way to implement this feature.
            if (targetWidth > 0)
            {
                // Resize the icon.
                RectTransform rect = template.transform as RectTransform;
                if (rect != null)
                {
                    var sd = rect.sizeDelta;
                    sd.x           = targetWidth;
                    rect.sizeDelta = sd;
                }
            }

            GridLayoutGroup layoutGrid = scroll.content.GetComponent <GridLayoutGroup>();

            if (layoutGrid != null)
            {
                layoutGrid.startAxis = (startHorizontal) ? GridLayoutGroup.Axis.Horizontal : GridLayoutGroup.Axis.Vertical;
            }

            // Create and position each item.
            int itemCount = 0;

            // Dodgy way to simulate many items for testing.
            foreach (FileSystemEntry item in items)
            {
                // Create item
                GameObject         itemUI   = GameObject.Instantiate(template);
                Text               itemText = itemUI.GetComponentInChildren <Text>();
                FileEntryComponent entry    = itemUI.GetComponent <FileEntryComponent>();
                Sprite             sprite   = (icons != null) ? icons.GetIcon(item) : null;
                ToolTipInfo        toolTip  = itemUI.GetComponentInChildren <ToolTipInfo>();

                // We are only allowed to modify an empty tool tip.
                if (toolTip != null && toolTip.ToolTip.Length > 0)
                {
                    toolTip = null;
                }

                // Ensure tag
                if (entry == null)
                {
                    entry = itemUI.AddComponent <FileEntryComponent>();
                }

                entry.Entry = item;

                // We expect the item to have two images; an icon image and an disabled highlight.
                // We can expect that the highlight is disabled, to hide it for now, and must come
                // first because of Unity uGUI draw order/hierarchy constraints.
                // For simplicity, we assume the first image is the highlight, the second image is
                // the icon. The icon image is optional.
                foreach (Image image in itemUI.GetComponentsInChildren <Image>())
                {
                    if (entry.Highlight == null)
                    {
                        entry.Highlight = image;
                    }
                    else if (entry.Icon == null)
                    {
                        // All done if we are here.
                        entry.Icon = image;
                        break;
                    }
                }

                // Set text.
                if (itemText != null)
                {
                    itemText.text = item.Name;
                    if (toolTip != null)
                    {
                        toolTip.ToolTip = item.Name;
                    }
                }

                if (entry.Highlight)
                {
                    entry.Highlight.enabled = false;
                }

                // Set image
                if (entry.Icon != null && sprite != null)
                {
                    entry.Icon.sprite = sprite;
                }

                itemUI.transform.SetParent(scroll.content, false);
                ++itemCount;
            }

            return(itemCount);
        }