コード例 #1
0
        /// <summary>
        ///     Lists items and sub-directories within the directory.
        /// </summary>
        /// <param name="path">The directory path</param>
        private void ListDirectory(string path)
        {
            listView1.BeginUpdate();
            listView1.Items.Clear();

            IEnumerable <TagDatum> references;

            if (path == CachePath.CacheRoot)
            {
                references = scenarioView1.References;
            }
            else
            {
                references = scenarioView1.References.Where(
                    u => u.Path.StartsWith(path) || u.Path == path);
            }

            SortedSet <ListViewItem> items =
                new SortedSet <ListViewItem>(Comparer <ListViewItem> .Create((u, v) =>
            {
                var uType       = u.GetType();
                var vType       = v.GetType();
                var compareType = uType.Name.CompareTo(vType.Name);
                if (compareType != 0)
                {
                    return(compareType);
                }
                var compareName = u.Name.CompareTo(v.Name);
                return(compareName);
            }));

            foreach (var reference in references)
            {
                var tagPath   = reference.Path;
                var directory = CachePath.GetDirectoryName(tagPath) ?? string.Empty;

                // This item is a tag
                if (directory == path)
                {
                    items.Add(new TagReferenceListViewItem(reference));
                }
                // This item is a directory
                else
                {
                    directory = directory.Remove(0, path.Length);
                    var split = directory.Split(new[] { Path.DirectorySeparatorChar },
                                                StringSplitOptions.RemoveEmptyEntries);
                    if (split.Length < 1)
                    {
                        continue;
                    }
                    directory = split[0];
                    var fullPath = CachePath.Combine(path, directory);

                    items.Add(new DirectoryListViewItem(directory, fullPath, 1));
                }
            }
            listView1.Items.AddRange(items.ToArray( ));
            listView1.EndUpdate(  );
        }
コード例 #2
0
        public void SelectDirectoryNode(string path)
        {
            if (path == CachePath.CacheRoot)
            {
                SelectedNode = Nodes[0];
                return;
            }
            var collection = Nodes;

            BeginUpdate(  );
            TreeNode selectionNode = null;

            foreach (var directoryName in CachePath.ForeachDirectory(path))
            {
                if (!collection.ContainsKey(directoryName))
                {
                    return;
                }
                collection[directoryName].Expand(  );
                selectionNode = collection[directoryName];
                collection    = collection[directoryName].Nodes;
            }
            if (selectionNode != null)
            {
                SelectedNode = selectionNode;
            }
            EndUpdate(  );
        }
コード例 #3
0
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            var path   = AddressBox.Text;
            var levels = CachePath.GetDirectoryLevelCount(path);

            if (levels >= 1)
            {
                path = CachePath.GetDirectoryLevel(path, levels - 1);
            }
            AddressBox.Text = path;
            AddressSubmitted?.Invoke(sender, AddressBox.Text);
        }