//=====================================================================
        private void treeView1_MouseClick(object sender, MouseEventArgs e)
        {
            foreach (ToolStripItem contextItem in contextMenuStrip1.Items)
            {
                contextItem.Enabled = false;
                contextItem.Visible = false;
            }

            if (e.Button == MouseButtons.Right)
            {
                if ((treeView1.SelectedNode != null) && (treeView1.SelectedNode.Tag != null) && (treeView1.SelectedNode.Tag is TAFTreeViewColumnTag))
                {
                    TAFTreeViewColumnTag treeViewColTag = this.treeView1.SelectedNode.Tag as TAFTreeViewColumnTag;
                    TAFTreeViewColumnTag treeParentTag  = null;
                    if (this.treeView1.SelectedNode.Parent != null)
                    {
                        treeParentTag = this.treeView1.SelectedNode.Parent.Tag as TAFTreeViewColumnTag;
                    }

                    //delete option
                    deleteToolStripMenuItem1.Enabled = (treeParentTag != null) && (treeParentTag.TypedValue.count() > 0) && (treeParentTag.TypedValue.isArray());
                    deleteToolStripMenuItem1.Visible = (treeParentTag != null) && (treeParentTag.TypedValue.isArray());
                    //add options
                    if (treeViewColTag.TypedValue.isArray())
                    {
                        addToolStripMenuItem.Enabled = true;
                        addToolStripMenuItem.Visible = true;
                    }
                }
            }
        }
        //=====================================================================
        /// <summary>
        /// richtextbox on leave handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void richTextBox1_Leave(object sender, EventArgs e)
        {
            saveChanges();
            richTextBox1.Visible = false;

            if ((this.treeView1.SelectedNode != null) && (this.treeView1.SelectedNode.Tag != null))
            {
                TAFTreeViewColumnTag objTag = this.treeView1.SelectedNode.Tag as TAFTreeViewColumnTag;
                objTag.Value = richTextBox1.Text;
            }
            this.treeView1.Refresh();
        }
示例#3
0
 //=======================================================================
 /// <summary>
 /// Called from the tree when arrays are resized.
 /// Using the selected node, just recreate it's child nodes.
 /// </summary>
 //=======================================================================
 private void afTreeViewColumns1_reloadTreeEvent()
 {
     if (afTreeViewColumns1.TreeView.SelectedNode != null)
     {
         TAFTreeViewColumnTag changedValue = (TAFTreeViewColumnTag)afTreeViewColumns1.TreeView.SelectedNode.Tag;
         afTreeViewColumns1.TreeView.BeginUpdate();
         afTreeViewColumns1.TreeView.SelectedNode.Nodes.Clear();
         addTreeModelNode(afTreeViewColumns1.TreeView.SelectedNode, changedValue.TypedValue.Name, changedValue.TypedValue);
         afTreeViewColumns1.TreeView.SelectedNode.Expand();
         afTreeViewColumns1.TreeView.EndUpdate();
     }
 }
        //=====================================================================
        private void addToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if ((treeView1.SelectedNode != null) && (treeView1.SelectedNode.Tag != null) && (treeView1.SelectedNode.Tag is TAFTreeViewColumnTag))
            {
                TAFTreeViewColumnTag treeViewColTag = this.treeView1.SelectedNode.Tag as TAFTreeViewColumnTag;

                if (treeViewColTag.TypedValue.isArray())
                {
                    treeViewColTag.TypedValue.setElementCount(treeViewColTag.TypedValue.count() + 1);

                    TreeNode currentTreeNode = treeView1.SelectedNode;

                    if (reloadTreeEvent != null)
                    {
                        reloadTreeEvent();      //expects as a minimum a redraw of the selected node
                    }
                    selectNode(treeView1.Nodes, currentTreeNode);
                }
            }
        }
        //=====================================================================
        /// <summary>
        /// save changes to tree node
        /// </summary>
        private void saveChanges()
        {
            TreeNode selectedNode = this.treeView1.SelectedNode;

            if (selectedNode != null)
            {
                TAFTreeViewColumnTag objTAF = selectedNode.Tag as TAFTreeViewColumnTag;

                ListView.SelectedListViewItemCollection jj = this.listView1.SelectedItems;

                if (!objTAF.Value.Equals(richTextBox1.Text))
                {
                    richTextBox1.Text = objTAF.updateValue(richTextBox1.Text);
                    if (saveChangesEvent != null)
                    {
                        saveChangesEvent();
                    }
                }
            }
        }
        //=====================================================================
        /// <summary>
        /// display the text editor to update the list view control
        /// </summary>
        private void displayEditor()
        {
            if (AllowEdit)
            {
                TreeNode treeNode = this.treeView1.SelectedNode;
                if (treeNode != null)
                {
                    TAFTreeViewColumnTag o = treeNode.Tag as TAFTreeViewColumnTag;

                    if ((!o.TypedValue.isArray()) && (!o.TypedValue.isRecord()))
                    {
                        int  iValColumnWidth = 150;
                        int  spos            = 0;
                        int  epos            = this.listView1.Columns[0].Width;
                        int  i      = 0;
                        bool lFound = false;
                        while ((i < this.listView1.Columns.Count) && (!lFound))
                        {
                            if (this.listView1.Columns[i].Text.ToLower().Equals(_editColumn))
                            {
                                lFound          = true;
                                iValColumnWidth = this.listView1.Columns[i].Width;
                            }
                            else
                            {
                                spos  = epos;
                                epos += this.listView1.Columns[i].Width;
                            }
                            i++;
                        }

                        richTextBox1.Size     = new System.Drawing.Size(iValColumnWidth, 20);
                        richTextBox1.Location = new System.Drawing.Point(spos + 3, treeNode.Bounds.Y + treeNode.Bounds.Height + 3);
                        richTextBox1.Text     = o.Value;
                        richTextBox1.Show();
                        richTextBox1.SelectAll();
                        richTextBox1.Focus();
                    }
                }
            }
        }
        //=====================================================================
        private void deleteToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if ((treeView1.SelectedNode != null) && (treeView1.SelectedNode.Tag != null) && (treeView1.SelectedNode.Tag is TAFTreeViewColumnTag))
            {
                TAFTreeViewColumnTag treeViewColTag = this.treeView1.SelectedNode.Tag as TAFTreeViewColumnTag;

                TreeNode parentNode = treeView1.SelectedNode.Parent;

                if ((parentNode != null) && (parentNode.Tag is TAFTreeViewColumnTag))
                {
                    TAFTreeViewColumnTag parentTreeViewColTag = parentNode.Tag as TAFTreeViewColumnTag;
                    parentTreeViewColTag.TypedValue.deleteElement(this.treeView1.SelectedNode.Index + 1);

                    if (reloadTreeEvent != null)
                    {
                        selectNode(treeView1.Nodes, parentNode);    //this means that is the parent only is being refilled it will work correctly
                        reloadTreeEvent();
                    }

                    selectNode(treeView1.Nodes, parentNode);
                }
            }
        }
        //=====================================================================
        /// <summary>
        /// on draw of the tree node - populate the listview columns
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e)
        {
            if (!NoRedraw)
            {
                e.DrawDefault = true;

                Rectangle rect = e.Bounds;

                if ((e.State & TreeNodeStates.Selected) != 0)
                {
                    if ((e.State & TreeNodeStates.Focused) != 0)
                    {
                        e.Graphics.FillRectangle(SystemBrushes.Highlight, rect);
                    }
                    else
                    {
                        e.Graphics.FillRectangle(SystemBrushes.Control, rect);
                    }
                }
                else
                {
                    e.Graphics.FillRectangle(Brushes.White, rect);
                }

                e.Graphics.DrawRectangle(SystemPens.Control, rect);

                for (int intColumn = 1; intColumn < this.listView1.Columns.Count; intColumn++)
                {
                    rect.Offset(this.listView1.Columns[intColumn - 1].Width, 0);
                    rect.Width = this.listView1.Columns[intColumn].Width;

                    e.Graphics.DrawRectangle(SystemPens.Control, rect);

                    string strColumnText;

                    TAFTreeViewColumnTag objTag = e.Node.Tag as TAFTreeViewColumnTag;

                    if (objTag != null)
                    {
                        if (getColValueEvent != null)   //if the host class has implemented a handler
                        {
                            strColumnText = getColValueEvent(objTag, intColumn);
                        }
                        else
                        {
                            strColumnText = objTag.getValueAtColumn(intColumn);
                        }
                    }
                    else
                    {
                        strColumnText = intColumn + " " + e.Node.Text; // dummy
                    }
                    TextFormatFlags flags = TextFormatFlags.EndEllipsis;
                    switch (this.listView1.Columns[intColumn].TextAlign)
                    {
                    case HorizontalAlignment.Center:
                        flags |= TextFormatFlags.HorizontalCenter;
                        break;

                    case HorizontalAlignment.Left:
                        flags |= TextFormatFlags.Left;
                        break;

                    case HorizontalAlignment.Right:
                        flags |= TextFormatFlags.Right;
                        break;

                    default:
                        break;
                    }

                    rect.Y++;
                    if ((e.State & TreeNodeStates.Selected) != 0 &&
                        (e.State & TreeNodeStates.Focused) != 0)
                    {
                        TextRenderer.DrawText(e.Graphics, strColumnText, treeView1.Font, rect, SystemColors.HighlightText, flags);
                    }
                    else
                    {
                        TextRenderer.DrawText(e.Graphics, strColumnText, treeView1.Font, rect, treeView1.ForeColor, treeView1.BackColor, flags);
                    }
                    rect.Y--;
                }
            }
        }