예제 #1
0
        private static void UpdateTreeViewItemText(NTreeViewItem item)
        {
            NElementInfo elementInfo = item.Tag as NElementInfo;

            if (elementInfo == null)
            {
                return;
            }

            string text = elementInfo.Name;

            if (elementInfo.Attributes.Count > 0)
            {
                // Iterate through the attributes and append them to the text
                StringBuilder sb = new StringBuilder(text);
                INIterator <NKeyValuePair <string, string> > iter = elementInfo.Attributes.GetIterator();
                while (iter.MoveNext())
                {
                    sb.Append(" ");
                    sb.Append(iter.Current.Key);
                    sb.Append("=\"");
                    sb.Append(iter.Current.Value);
                    sb.Append("\"");
                }

                text = sb.ToString();
            }

            // Update the text of the given tree view item
            ((NLabel)item.Header.Content).Text = text;
        }
예제 #2
0
        private static NXmlNode SerializeTreeViewItem(NTreeViewItem item)
        {
            NElementInfo elementInfo = (NElementInfo)item.Tag;

            if (elementInfo == null)
            {
                string text = ((NLabel)item.Header.Content).Text;
                return(new NXmlTextNode(ENXmlNodeType.Text, text));
            }

            // Create an XML element for the current tree view item
            NXmlElement element = new NXmlElement(elementInfo.Name);

            if (elementInfo.Attributes.Count > 0)
            {
                // Set the element's attributes
                INIterator <NKeyValuePair <string, string> > iter = elementInfo.Attributes.GetIterator();
                while (iter.MoveNext())
                {
                    element.SetAttribute(iter.Current.Key, iter.Current.Value);
                }
            }

            // Loop through the item's children
            for (int i = 0, childCount = item.Items.Count; i < childCount; i++)
            {
                element.AddChild(SerializeTreeViewItem(item.Items[i]));
            }

            return(element);
        }
예제 #3
0
        private void OnAddAttributeButtonClick(NEventArgs arg)
        {
            NTopLevelWindow dialog = NApplication.CreateTopLevelWindow();

            dialog.SetupDialogWindow("Enter attribute's name and value", false);

            NTableFlowPanel table = new NTableFlowPanel();

            table.Direction   = ENHVDirection.LeftToRight;
            table.ColFillMode = ENStackFillMode.Last;
            table.ColFitMode  = ENStackFitMode.Last;
            table.MaxOrdinal  = 2;

            NLabel nameLabel = new NLabel("Name:");

            table.Add(nameLabel);

            NTextBox nameTextBox = new NTextBox();

            table.Add(nameTextBox);

            NLabel valueLabel = new NLabel("Value:");

            table.Add(valueLabel);

            NTextBox valueTextBox = new NTextBox();

            table.Add(valueTextBox);

            table.Add(new NWidget());

            NButtonStrip buttonStrip = new NButtonStrip();

            buttonStrip.InitOKCancelButtonStrip();
            table.Add(buttonStrip);

            dialog.Content = table;

            dialog.Opened += delegate(NEventArgs args) {
                nameTextBox.Focus();
            };

            dialog.Closed += delegate(NEventArgs args) {
                if (dialog.Result == ENWindowResult.OK)
                {
                    NElementInfo elementInfo = (NElementInfo)m_TreeView.SelectedItem.Tag;
                    elementInfo.Attributes.Set(nameTextBox.Text, valueTextBox.Text);
                    UpdateTreeViewItemText(m_TreeView.SelectedItem);

                    if (m_RemoveAttributeButton.Enabled == false)
                    {
                        m_RemoveAttributeButton.Enabled = true;
                    }
                }
            };

            dialog.Open();
        }
예제 #4
0
        private void OnRemoveAttributeButtonClick(NEventArgs arg)
        {
            NTopLevelWindow dialog = NApplication.CreateTopLevelWindow();

            dialog.SetupDialogWindow("Select an Attribute to Remove", false);

            NListBox     listBox     = new NListBox();
            NElementInfo elementInfo = (NElementInfo)m_TreeView.SelectedItem.Tag;
            INIterator <NKeyValuePair <string, string> > iter = elementInfo.Attributes.GetIterator();

            while (iter.MoveNext())
            {
                listBox.Items.Add(new NListBoxItem(iter.Current.Key));
            }

            NButtonStrip buttonStrip = new NButtonStrip();

            buttonStrip.InitOKCancelButtonStrip();

            NPairBox pairBox = new NPairBox(listBox, buttonStrip, ENPairBoxRelation.Box1AboveBox2);

            pairBox.Spacing = NDesign.VerticalSpacing;
            dialog.Content  = pairBox;

            dialog.Opened += delegate(NEventArgs args) {
                listBox.Focus();
            };

            dialog.Closed += delegate(NEventArgs args) {
                if (dialog.Result == ENWindowResult.OK)
                {
                    // Remove the selected attribute
                    NListBoxItem selectedItem = listBox.Selection.FirstSelected;
                    if (selectedItem != null)
                    {
                        string name = ((NLabel)selectedItem.Content).Text;
                        elementInfo.Attributes.Remove(name);
                        UpdateTreeViewItemText(m_TreeView.SelectedItem);

                        if (elementInfo.Attributes.Count == 0)
                        {
                            m_RemoveAttributeButton.Enabled = false;
                        }
                    }
                }
            };

            dialog.Open();
        }
예제 #5
0
        private void OnTreeViewSelectedPathChanged(NValueChangeEventArgs arg)
        {
            NTreeViewItem selectItem = m_TreeView.SelectedItem;

            if (selectItem == null)
            {
                m_AddChildItemButton.Enabled       = false;
                m_RemoveSelectedItemButton.Enabled = false;
                m_AddAttributeButton.Enabled       = false;
                m_RemoveAttributeButton.Enabled    = false;
                return;
            }

            m_AddChildItemButton.Enabled       = true;
            m_RemoveSelectedItemButton.Enabled = selectItem != DocumentItem;

            NElementInfo elementInfo = selectItem.Tag as NElementInfo;

            m_AddAttributeButton.Enabled    = elementInfo != null;
            m_RemoveAttributeButton.Enabled = elementInfo != null && elementInfo.Attributes.Count > 0;
        }