コード例 #1
0
        //respond to an item dropped in my treeview
        protected override void OnDragDrop(DragEventArgs e)
        {
            base.OnDragDrop(e);
            TmTreeNode destinationTreeNode = NodeAtEvent(e);
            TmNode destinationNode = null;

            if (destinationTreeNode != null)
                destinationNode = destinationTreeNode.TmNode;

            // TmNodeList drop
            if (e.Data.GetDataPresent("TmNodeList", false))
            {
                List<TmNode> nodes = e.Data.GetData("TmNodeList") as List<TmNode>;
                if (nodes != null && nodes.Count() > 0)
                {
                    foreach (TmNode node in nodes)
                    {
                        if (e.Effect == DragDropEffects.Move)
                            MoveNode(destinationNode, node);
                        if (e.Effect == DragDropEffects.Copy)
                            CopyNode(destinationNode, node);
                    }

                    if (e.Effect != DragDropEffects.None)
                    {
                        //SelectNode(destinationTreeNode);
                        destinationTreeNode.Expand();
                        return;
                    }
                }
            }

            // TmNode drop
            if (e.Data.GetDataPresent("TmNode", false))
            {
                // e.Effect == none for illeagal drops. 
                TmNode oldNode = e.Data.GetData("TmNode") as TmNode;
                Debug.Assert(oldNode != null, "Could not reserialize node from clipboard");
                if (oldNode != null)
                {
                    if (e.Effect == DragDropEffects.Move)
                        MoveNode(destinationNode, oldNode);
                    if (e.Effect == DragDropEffects.Copy)
                        CopyNode(destinationNode, oldNode);
                    if (e.Effect != DragDropEffects.None)
                    {
                        //SelectNode(destinationTreeNode);
                        destinationTreeNode.Expand();
                        return;
                    }
                }
            }

            // FileDrop
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
                TmTreeNode newTreeNode = null;
                foreach (string file in files)
                {
                    //FIXME - determine if this is a Theme or a ThemeList
                    //currently assuming it is a theme.
                    TmNode newNode = new ThemeNode(Path.GetFileNameWithoutExtension(file), file);
                    try
                    {
                        // May need to load to query arc objects which could throw any number of exceptions.
                        newNode.Reload();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Unable to load the theme properties" + ex);
                    }

                    if (destinationNode == null)
                        newTreeNode = Add(newNode);
                    else
                        destinationNode.Add(newNode);
                }
                if (newTreeNode != null)
                    SelectNode(newTreeNode);
                else
                {
                    SelectNode(destinationTreeNode);
                    destinationTreeNode.Expand();
                }
                return;
            }

            // Text Drop
            if (e.Data.GetDataPresent(DataFormats.Text))
            {
                string txt = (string)e.Data.GetData(DataFormats.Text);

                TmNode newNode = new CategoryNode(txt);
                if (destinationNode == null)
                    SelectNode(Add(newNode));
                else
                {
                    destinationNode.Add(newNode);
                    SelectNode(destinationTreeNode);
                    destinationTreeNode.Expand();
                }
            }
        }
コード例 #2
0
 //Also called from the search form.
 internal void DisplaySearchResults(SearchParameters searchParams, IEnumerable<TmNode> results)
 {
     //I need to cache the enumeration for two reasons:
     // 1: I access the enumeration to get the count, and to access the nodes.
     //    A new search is done each time the enumeration is iterated (even for counting).
     // 2: The enumeration searches the treeviews _selected nodes.
     //    I clear the searchtrees selected node when I create the results, 
     //    therefore no results are returned if the search was done on the search tree.
     IList<TmNode> nodes = results.ToList();
     if (nodes == null || nodes.Count == 0)
         MessageBox.Show(string.Format("Sorry, your search for '{0}' in {1} has no results.",
                                       searchParams.Description, searchParams.Location));
     else
     {
         string resultsNodeLabel = string.Format("{0} result{1} for '{2}' in {3}",
             nodes.Count, nodes.Count == 1 ? "" : "s", searchParams.Label, searchParams.Location);
         searchTreeView.BeginUpdate();
         searchTreeView.ClearSelectedNodes();
         TmNode catNode = new CategoryNode(resultsNodeLabel);
         TmTreeNode newNode = searchTreeView.Add(catNode);
         if (newNode == null)
         {
             MessageBox.Show("Unable to add results to display");
             return;
         }
         foreach (TmNode node in nodes)
             catNode.Add(node.DeepCopy());
         searchTreeView.SelectNode(newNode);
         newNode.Expand();
         searchTreeView.EndUpdate();
         CurrentTreeView = searchTreeView;
     }
 }
コード例 #3
0
        private void PopulateCategoryPropertyPanel(PropertiesForm form, CategoryNode node)
        {
            Debug.Assert(node.Metadata != null, "TMNode node has no metadata object");
            
            form.categoryName.DataBindings.Clear();
            form.categoryMetadata.DataBindings.Clear();
            form.categoryDescription.DataBindings.Clear();

            form.categoryName.DataBindings.Add(new Binding("Text", node, "Name"));
            form.categoryMetadata.DataBindings.Add(new Binding("Text", node.Metadata, "Path"));
            form.categoryDescription.DataBindings.Add(new Binding("Text", node, "Description"));
        }
コード例 #4
0
        private void LoadTreeFromXML(XElement xele, TmTreeView tv)
        {
            TmNode node;
            foreach (XElement xnode in xele.Elements(ThemeListNode.TypeString))
            {
                node = new ThemeListNode();
                node.Load(xnode, false); // Add only the first node
                tv.Add(node);
            }

            foreach (XElement xnode in xele.Elements(CategoryNode.TypeString))
            {
                node = new CategoryNode();
                node.BeginUpdate();
                node.Load(xnode, true); // Add entire branch
                node.UpdateAge();
                node.EndUpdate();
                tv.Add(node);
            }

            foreach (XElement xnode in xele.Elements(ThemeNode.TypeString))
            {
                node = new ThemeNode();
                node.BeginUpdate();
                node.Load(xnode, true); // Add entire branch
                node.UpdateAge();
                node.EndUpdate();
                tv.Add(node);
            }
            tv.TextSortInit((string)xele.Attribute("sortorder"));
        }
コード例 #5
0
        public void Load(XElement xele, bool recurse)
        {
            if (xele == null)
                throw new ArgumentNullException("xele");

            //Kind was already set when node was created.  Set all other properties
            Name = (string)xele.Attribute("name");
            XElement data = xele.Element("tags");
            Tags = data == null ? null : data.Value;
            data = xele.Element("summary");
            Summary = data == null ? null : data.Value;
            data = xele.Element("description");
            Description = data == null ? null : data.Value;
            data = xele.Element("pubdate");
            if (data != null)
            {
                DateTime temp;
                if (DateTime.TryParse(data.Value, out temp))
                    if (this is ThemeNode)
                        ((ThemeNode)this).PubDate = temp;
            }

            data = xele.Element("data");
            if (data != null)
            {
                // Ignore data elements for themelists.
                var themeNode = this as ThemeNode;
                if (themeNode != null)
                    (themeNode).Data = ThemeData.Load(data);
                var themeListNode = this as ThemeListNode;
                if (themeListNode != null)
                    (themeListNode).FilePath = data.Value;
            }

            data = xele.Element("metadata");
            if (data != null)
                Metadata = Metadata.Load(data);

            if (recurse)
            {
                TmNode childNode;

                foreach (XElement xnode in xele.Elements(CategoryNode.TypeString))
                {
                    childNode = new CategoryNode();
                    Add(childNode);
                    childNode.Load(xnode);
                }

                foreach (XElement xnode in xele.Elements(ThemeNode.TypeString))
                {
                    if (this is SubThemeNode || this is ThemeNode)
                        childNode = new SubThemeNode();
                    else
                        childNode = new ThemeNode();
                    Add(childNode);
                    childNode.Load(xnode);
                }
            }
        }