Example #1
0
        public void AddTab(string fpath, string fname)
        {
            fpath = FixPath(fpath);

            if (Path.GetExtension(fname) == ".dst")
            {
                if (tabview.TabPages.ContainsKey(fname))
                {
                    return;
                }

                TabPage page = new TabPage();

                var x = new XmlEditor()
                {
                    AllowXmlFormatting = true, Text = File.ReadAllText(fpath)
                };
                //XmlEditor.FormatXml(x.GetTextBox());
                page.Controls.Add(x);
                page.Controls[0].Dock = DockStyle.Fill;
                page.Name             = fpath;
                page.Text             = fname;

                tabview.TabPages.Add(page);
                tabview.SelectTab(fpath);
            }
        }
        public override void Save()
        {
            if (!this.Valid)
            {
                return;
            }

            XmlEditor      xe      = this.Editor as XmlEditor;
            TreeNode       parent  = this.TableNodeHandler.Node.Parent;
            UDTNodeHandler udtNode = parent.Tag as UDTNodeHandler;

            if (udtNode == null && parent.Parent != null)
            {
                udtNode = parent.Parent.Tag as UDTNodeHandler;
            }

            if (udtNode == null)
            {
                throw new Exception("節點錯誤, 找不到所屬 UDTNodeHandler.");
            }

            udtNode.UDTHandler.UpdateSchema(xe.Xml);

            this.Table.OnSave(this);

            this.OnDataSaved();
        }
Example #3
0
        internal static void ShowXmlEditor(Form1 form)
        {
            CustomRichTextBox pageTextBox = ProgramUtil.GetPageTextBox(form.pagesTabControl.SelectedTabPage);

            if (String.IsNullOrEmpty(pageTextBox.Text))
            {
                ShowInfoBox(form, LanguageUtil.GetCurrentLanguageString("TextEmpty", className));
                return;
            }

            String error;

            if (!XmlValidator.Validate(form, false, ValidationType.Schema, null, out error))
            {
                ShowAlertBox(form, error);
                return;
            }

            XmlEditor fileRename = new XmlEditor {
                Owner = form
            };

            fileRename.InitializeForm();
            fileRename.Show(form);
        }
        public override void Run()
        {
            string clipboardText = Clipboard.GetText();

            if (clipboardText == null)
            {
                clipboardText = String.Empty;
            }
            InputDialog dialog = new InputDialog("Enter text", clipboardText, "Enter the value to search");

            if (dialog.ShowDialog() == CustomDialogResult.Ok)
            {
                XmlEditor editor = this.Owner as XmlEditor;
                if (editor == null)
                {
                    return;
                }
                SingleDirectionData currentData = editor.SingleDirectionData;
                currentData.ShowAttributes = true;
                currentData.ShowValues     = true;
                string tempXPath = string.Format("//*[text() = \"{0}\"]", dialog.InputString);
                if (XmlUtils.IsXPathValid(tempXPath))
                {
                    XPathData xpath = new XPathData();
                    xpath.XPath = tempXPath;
                    currentData.HighlightedXPath = xpath;
                }
            }
        }
Example #5
0
        // 供GetBackColor(region)、GetTextColor(region)、GetBorderColor(region)调的私有函数
        // parameters:
        //      region        枚举值,取哪个区域
        //      valueStyle    枚举值,取哪种类型的值
        // return:
        //      Color对象
        Color GetColor(ItemRegion region, ValueStyle valueStyle)
        {
            XmlEditor editor = this.m_document;

            if (editor.VisualCfg == null)
            {
                goto END1;
            }

            VisualStyle style = editor.VisualCfg.GetVisualStyle(this, region);

            if (style == null)
            {
                goto END1;
            }

            if (valueStyle == ValueStyle.BackColor)
            {
                return(style.BackColor);
            }
            else if (valueStyle == ValueStyle.TextColor)
            {
                return(style.TextColor);
            }
            else if (valueStyle == ValueStyle.BorderColor)
            {
                return(style.BorderColor);
            }

END1:
            //缺省值
            if (valueStyle == ValueStyle.BackColor)
            {
                if (region == ItemRegion.Text)
                {
                    return(editor.BackColorDefaultForEditable);
                }
                else if (this is AttrItem)
                {
                    return(editor.AttrBackColorDefault);
                }
                else
                {
                    return(editor.BackColorDefault);
                }
            }
            else if (valueStyle == ValueStyle.TextColor)
            {
                return(editor.TextColorDefault);
            }
            else if (valueStyle == ValueStyle.BorderColor)
            {
                return(editor.BorderColorDefault);
            }
            else
            {
                return(Color.Red);
            }
        }
Example #6
0
        public override void Save()
        {
            XmlEditor xe = this.Editor as XmlEditor;

            ServiceDAL.SetDefinition(this.ServiceNodeHandler.ContractName, this.ServiceNodeHandler.PackageName, this.ServiceNodeHandler.ServiceName, xe.Xml);

            this.OnDataSaved();
        }
Example #7
0
        public static void Editor()
        {
            IDocumentEditor editor = new XmlEditor(PATH);

            editor.AddTextValue();
            editor.AddComplexTypeElement();
            editor.AddAttribute();
            editor.RemoveAttribute();
            editor.AddComplex();
            editor.SaveDocument();
        }
        public void Read_Patent_Parsed_As_Expected()
        {
            // Arrange
            var xmlEditor = new XmlEditor(PatentEntityPath);

            // Act
            var result = xmlEditor.Read();

            // Assert
            result.Count.ShouldBe(1);
            CheckExpectedEntity(result.First() as Patent);
        }
        public void Read_Optional_Field_Works_As_Expected()
        {
            // Arrange
            var xmlEditor = new XmlEditor(OptionalFieldNumberReadPath);

            // Act
            var result = xmlEditor.Read();

            // Assert
            result.Count.ShouldBe(1);
            var newspaper = result.First() as Newspaper;

            newspaper.Number.ShouldBeNull();
        }
Example #10
0
        // 初始化小编辑控件
        // parameters:
        //      xmlEditor   XmlEditor对象
        // return:
        //      -1  出错
        //      0   成功
        public int Initial(XmlEditor xmlEditor,
                           out string strError)
        {
            strError       = "";
            this.XmlEditor = xmlEditor;

            this.ImeMode     = ImeMode.Off;
            this.BorderStyle = BorderStyle.None;
            this.BackColor   = this.XmlEditor.BackColorDefaultForEditable;
            this.Font        = this.XmlEditor.FontTextDefault;
            this.Multiline   = true;
            this.XmlEditor.Controls.Add(this);
            return(0);
        }
        public void Read_Library_Parsed_As_Expected()
        {
            // Arrange
            var xmlEditor = new XmlEditor(LibraryEntityPath);

            // Act
            var result = xmlEditor.Read();

            // Assert
            result.Count.ShouldBe(3);
            CheckExpectedEntity(result.First() as Book);
            CheckExpectedEntity(result.ElementAt(1) as Newspaper);
            CheckExpectedEntity(result.Last() as Patent);
        }
Example #12
0
        public override void Paint(PaintEventArgs pe,
                                   int nBaseX,
                                   int nBaseY,
                                   PaintMember paintMember)
        {
            Rectangle rectPaint = new Rectangle(nBaseX + this.Rect.X,
                                                nBaseY + this.Rect.Y,
                                                this.Rect.Width,
                                                this.Rect.Height);

            Color backColor = this.BackColor;

            using (Brush brush = new SolidBrush(this.BackColor))
            {
                pe.Graphics.FillRectangle(brush, rectPaint);
            }

            Item      item   = this.GetItem();
            XmlEditor editor = null;

            if (item != null)
            {
                editor = item.m_document;
            }

            if (editor != null && editor.VisualCfg == null)
            {
            }
            else
            {
                //调DrawLines画边框
                this.DrawLines(rectPaint,
                               this.TopBorderHeight,
                               this.BottomBorderHeight,
                               this.LeftBorderWidth,
                               this.RightBorderWidth,
                               this.BorderColor);
            }

            int nWidth = (this.Rect.Width
                          - this.LeftBlank
                          - this.RightBlank);

            PaintButton(pe.Graphics,
                        rectPaint.X + this.LeftBlank,
                        rectPaint.Y,
                        nWidth,
                        this.expandIconStyle);
        }
Example #13
0
        public MainPage()
        {
            this.InitializeComponent();

            // Register for changes to Editor text or position.
            XmlEditor.RegisterPropertyChangedCallback(CodeEditor.TextProperty, XmlEditor_TextChanged);
            XmlEditor.RegisterPropertyChangedCallback(CodeEditor.SelectedRangeProperty, XmlEditor_RangeChanged);

            // Load example file
            using (var stream = GetType().Assembly.GetManifestResourceStream("XmlSyntaxVisualizerUwp.ExampleDocument.xml"))
                using (var reader = new StreamReader(stream))
                {
                    XmlEditor.Text = reader.ReadToEnd();
                }
        }
        public override void Save()
        {
            try
            {
                XmlEditor xe  = this.Editor as XmlEditor;
                string    xml = xe.XmlText;
                Contract.SetDefinition(xe.Xml, this);

                MessageBox.Show("儲存完畢!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.OnDataSaved();
            }
            catch (Exception ex)
            {
                MessageBox.Show("儲存失敗!" + ex.Message, "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public void Write_When_File_Is_Empty_Template()
        {
            // Arrange
            var xmlEditor = new XmlEditor(EmptyTemplatePath);

            // Act
            xmlEditor.Write(null);

            // Assert
            File.Exists(EmptyTemplatePath).ShouldBeTrue();
            var doc = XDocument.Load(EmptyTemplatePath);

            doc.Declaration.ShouldNotBeNull();
            doc.Root.HasElements.ShouldBeFalse();
            doc.Root.Name.ShouldBe(TagName.Library);
        }
Example #16
0
        public override Item newItem(XmlNode node,
                                     XmlEditor document)
        {
            Item item = null;

            if (node.NodeType == XmlNodeType.Element)
            {
                item = new ElementItem(document);
            }
            else if (node.NodeType == XmlNodeType.Attribute)
            {
                item = new AttrItem(document);
            }
            else if (node.NodeType == XmlNodeType.Text)
            {
                item = new TextItem(document);
            }
            else if (node.NodeType == XmlNodeType.ProcessingInstruction)
            {
                item = new ProcessingInstructionItem(document);
            }
            else if (node.NodeType == XmlNodeType.XmlDeclaration)
            {
                item = new DeclarationItem(document);
            }
            else if (node.NodeType == XmlNodeType.Comment)
            {
                item = new CommentItem(document);
            }
            else if (node.NodeType == XmlNodeType.CDATA)
            {
                item = new CDATAItem(document);
            }
            else if (node.NodeType == XmlNodeType.DocumentType)
            {
                item = new DocumentTypeItem(document);
            }
            else if (node.NodeType == XmlNodeType.EntityReference)
            {
                item = new EntityReferenceItem(document);
            }

            //item.m_document = document;
            return(item);
        }
Example #17
0
        // 注,测属性及其它非element节点,观察.net
        public XmlEditorNavigator(Item item)
        {
            //StreamUtil.WriteText("I:\\debug.txt","进到 构造函数XmlEditorNavigator(editor)里\r\n");

            Debug.Assert(item != null, "item不能为null");

            XmlEditor document = item.m_document;

            Debug.Assert(document != null, "document不能为null");

            this.m_navigatorState             = new NavigatorState();
            this.m_navigatorState.CurItem     = item;    //把当前节点设为虚根
            this.m_navigatorState.DocRoot     = document.docRoot;
            this.m_navigatorState.VirtualRoot = document.VirtualRoot;

            this.m_nametable = new NameTable();
            this.m_nametable.Add(String.Empty);
        }
Example #18
0
        /// <summary>
        /// This function just provides a bit of info about the Xml Node that's at the caret position in the Editor.
        /// </summary>
        private async void UpdateCurrentInfo()
        {
            // Figure out where we are.
            CurrentPosition = await XmlEditor.GetPositionAsync();

            if (CurrentPosition == null)
            {
                return;
            }

            // Break this down to convert between the Monaco editor and the index our Xml Parser knows about.
            var index = XmlEditor.Text.GetCharacterIndex((int)CurrentPosition.LineNumber, (int)CurrentPosition.Column);

            if (index == -1)
            {
                return;
            }

            // Use the caret position (as index) to find the corresponding Xml Node from our parsed tree.
            var           raw_node = _lastRoot.FindNode(index + 1);
            var           node     = XmlSyntaxData.FromNode(raw_node, false); // Translate to our UI-Friendly object
            XmlSyntaxData parent   = null;

            if (raw_node.Parent != null)
            {
                parent = XmlSyntaxData.FromNode(raw_node.Parent, false); // Do the same for the Parent (if we have one)
            }

            TreeView_ScrollNode(raw_node); // Show Item in Tree

            if (node != null)
            {
                // Refetch proper line/col from start of token (as it may start earlier than where the caret is)
                var(line_s, col_s) = XmlEditor.Text.GetLineColumnIndex(node.SpanStart);  // Translate from Xml Parser to Monaco positions.
                var(line_e, col_e) = XmlEditor.Text.GetLineColumnIndex(node.SpanEnd - 1);

                // Provide info in our UI box.
                ElementInfo  = node.Text + Environment.NewLine;
                ElementInfo += node.Type + Environment.NewLine;
                ElementInfo += "Parent:" + parent?.Type + Environment.NewLine;
                ElementInfo += "Parent Element:" + raw_node?.ParentElement?.Name + Environment.NewLine;
            }
        }
        public void Write_When_Newspaper_Is_Added()
        {
            // Arrange
            var entities = new List <EntityBase>
            {
                _newspaper
            };

            var xmlEditor = new XmlEditor(NewspaperXmlPath);

            // Act
            xmlEditor.Write(entities);

            // Assert
            File.Exists(NewspaperXmlPath).ShouldBeTrue();
            var doc = XDocument.Load(NewspaperXmlPath);

            doc.Declaration.ShouldNotBeNull();
            doc.Root.HasElements.ShouldBeTrue();
            CheckExpectedNewspaperElement(doc.Root.Elements().First());
        }
Example #20
0
        // 得到字体
        // parameters:
        //      region  枚举值,哪个区域的字体
        // return:
        //      Font对象
        public Font GetFont(ItemRegion region)
        {
            XmlEditor editor = this.m_document;

            if (editor.VisualCfg == null)
            {
                goto END1;
            }

            VisualStyle style = editor.VisualCfg.GetVisualStyle(this, region);

            if (style == null)
            {
                goto END1;
            }

            return(style.Font);

END1:
            return(editor.FontTextDefault);
        }
Example #21
0
        public bool IsValid(object owner, ICSharpCode.Core.Condition condition)
        {
            if (!condition.Properties.Contains(NodeTypeKey))
            {
                return(false);
            }

            string    nodeTypeString = condition.Properties[NodeTypeKey];
            XmlEditor editor         = owner as XmlEditor;

            if (editor == null)
            {
                return(false);
            }

            XmlViewSingleContent view = LogicalTreeHelper.FindLogicalNode(editor, "xmlView") as XmlViewSingleContent;

            if (view == null || view.ActiveViewer == null)
            {
                return(false);
            }
            XmlNode targetNode = view.ActiveViewer.GetCaretNode();

            if (targetNode == null)
            {
                return(false);
            }
            if (nodeTypeString.Equals("LeafElement"))
            {
                if (targetNode.NodeType == XmlNodeType.Element && targetNode.ChildNodes.Count == 1 && targetNode.FirstChild.NodeType == XmlNodeType.Text)
                {
                    return(true);
                }
                return(false);
            }
            else
            {
                return(targetNode.NodeType.ToString().Equals(nodeTypeString));
            }
        }
        public void Write_Optional_Field_Works_As_Expected()
        {
            // Arrange
            _newspaper.Number = null;
            var entities = new List <EntityBase>
            {
                _newspaper
            };

            var xmlEditor = new XmlEditor(OptionalFieldNumberWritePath);

            // Act
            xmlEditor.Write(entities);

            // Assert
            File.Exists(OptionalFieldNumberWritePath).ShouldBeTrue();
            var doc = XDocument.Load(OptionalFieldNumberWritePath);

            doc.Declaration.ShouldNotBeNull();
            doc.Root.HasElements.ShouldBeTrue();
            doc.Root.Elements(TagName.Number).FirstOrDefault().ShouldBeNull();
        }
        private void StartTraining()
        {
            if (Properties.Settings.Default.verbsFilePath == "")
            {
                MessageBox.Show(this, "Please create a list of irregular verbs and save it using the \"Edit Verbs List\" button.", this.Text + " - Attention",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                editVerbsBtn.Focus();
                return;
            }

            if (trainer != null)
            {
                trainer.Dispose();
            }
            trainer = new Trainer(XmlEditor.ReadDictionnaryInFile(Properties.Settings.Default.verbsFilePath), GatherParamsToOptionArgs());

            ClearAnswerAndCorrection();

            trainer.Start();

            NextQuestion();
        }
Example #24
0
        public EditVerbsForm(EditRequest editRequest = EditRequest.Default)
        {
            InitializeComponent();
            this.Dock   = DockStyle.Fill;
            UserHasEdit = false;

            if (!File.Exists(Properties.Settings.Default.verbsFilePath) && Properties.Settings.Default.verbsFilePath != "")
            {
                MessageBox.Show(this, "Your last file \"" + Path.GetFileName(Properties.Settings.Default.verbsFilePath)
                                + "\" could not be found. Relocate it or create a new one trough the Edit window.", this.Text + " - File could not be located",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);

                Properties.Settings.Default.verbsFilePath = "";
                Properties.Settings.Default.Save();
            }

            if (editRequest == EditRequest.CreateNewFile)
            {
                ParseDictionaryInGrid(null);
            }
            else if (editRequest == EditRequest.OpenFile)
            {
                OpenFileBtn_Click(null, null);
            }
            else
            {
                if (Properties.Settings.Default.verbsFilePath == "") // If no stored file path, start a new File
                {
                    ParseDictionaryInGrid(null);
                }
                else
                {
                    ParseDictionaryInGrid(XmlEditor.ReadDictionnaryInFile(Properties.Settings.Default.verbsFilePath));
                }
            }

            UpdateTitleWithFileName();
        }
        public void Write_When_Different_Entities_Were_Added()
        {
            // Arrange
            var entities = new List <EntityBase>
            {
                _book, _newspaper, _patent
            };

            var xmlEditor = new XmlEditor(XmlPath);

            // Act
            xmlEditor.Write(entities);

            // Assert
            File.Exists(XmlPath).ShouldBeTrue();
            var doc = XDocument.Load(XmlPath);

            doc.Declaration.ShouldNotBeNull();
            doc.Root.Elements().Count().ShouldBe(3);
            CheckExpectedBookElement(doc.Root.Elements().First());
            CheckExpectedNewspaperElement(doc.Root.Elements().ElementAt(1));
            CheckExpectedPatentElement(doc.Root.Elements().Last());
        }
Example #26
0
File: Label.cs Project: zszqwe/dp2
        public override void Paint(PaintEventArgs pe,
                                   int nBaseX,
                                   int nBaseY,
                                   PaintMember paintMember)
        {
            if (this.Rect.Width == 0 ||
                this.Rect.Height == 0)
            {
                return;
            }

            Rectangle rectPaint = new Rectangle(nBaseX + this.Rect.X,
                                                nBaseY + this.Rect.Y,
                                                this.Rect.Width,
                                                this.Rect.Height);

            //背景色
            Item      item         = this.GetItem();
            Object    colorDefault = null;
            XmlEditor editor       = item.m_document;

            if (editor != null && editor.VisualCfg != null)
            {
                colorDefault = editor.VisualCfg.transparenceColor;
            }
            if (colorDefault != null)
            {
                if (((Color)colorDefault).Equals(BackColor) == true)
                {
                    goto SKIPDRAWBACK;
                }
            }

            Color backColor = this.BackColor;

            // 如果对象的父亲 是 活动的Item 加亮显示
            if (editor != null)
            {
                if (item == editor.m_selectedItem)
                {
                    backColor = ControlPaint.Light(backColor);
                }
            }

            using (Brush brush = new SolidBrush(backColor))
            {
                pe.Graphics.FillRectangle(brush, rectPaint);
            }

SKIPDRAWBACK:

            //调DrawLines画边框
            if (editor != null && editor.VisualCfg == null)
            {
            }
            else
            {
                this.DrawLines(rectPaint,
                               this.TopBorderHeight,
                               this.BottomBorderHeight,
                               this.LeftBorderWidth,
                               this.RightBorderWidth,
                               this.BorderColor);
            }

            //内容区域
            rectPaint = new Rectangle(nBaseX + this.Rect.X + this.LeftResWidth /*LeftBlank*/,
                                      nBaseY + this.Rect.Y + this.TopResHeight /*this.TopBlank*/,
                                      this.Rect.Width - this.TotalRestWidth /*this.LeftBlank - this.RightBlank*/,
                                      this.Rect.Height - this.TotalRestHeight /*this.TopBlank - this.BottomBlank*/);

            Font font1 = this.GetFont();

            using (Font font = new Font(font1.Name, font1.Size))
                using (Brush brush = new SolidBrush(TextColor))
                {
                    pe.Graphics.DrawString(Text,
                                           font,
                                           brush,
                                           rectPaint,
                                           new StringFormat());
                }
        }
Example #27
0
 internal DeclarationItem(XmlEditor document)
 {
     this.Name       = "#Declaration";
     this.m_document = document;
 }
Example #28
0
 public virtual Item newItem(XmlNode node,
                             XmlEditor document)
 {
     return(null);
 }
Example #29
0
        // 初始visual函数
        public override void InitialVisual()
        {
            ElementItem item   = (ElementItem)this.GetItem();
            XmlEditor   editor = item.m_document;

            if (item == null)
            {
                return;
            }

            if (item.m_childrenExpand == ExpandStyle.Collapse)
            {
                this.childrenVisual = null;

                this.MyText.container = this.container;
                this.MyText.Name      = "content";

                this.MyText.Text = "尚未初始化";
                // 使用初始item时,赋的值
                //this.MyText.Text = item.strInnerXml;	// m_strContentXml专门用来传递处于收缩状态的element的下级汇总Xml信息


                //把本对象从父亲哪里删除,把m_text加进父亲,
                //实现了实质的替换,不知道以后这个没人管的content跑到哪里了?
                ((Box)this.container).AddChildVisual(this.MyText);
                ((Box)this.container).childrenVisual.Remove(this);

                item.Flush();
            }
            else if (item.m_childrenExpand == ExpandStyle.Expand)
            {
                // 把原初始设好
                foreach (Item child in item.children)
                {
                    if (!(child is ElementItem))
                    {
                        Debug.Assert(child.GetValue() != null, "准备值不能为null");
                        child.m_paraValue1 = child.GetValue();
                    }
                }

                if (this.childrenVisual != null)
                {
                    this.childrenVisual.Clear();
                }

                this.LayoutStyle = LayoutStyle.Vertical;

                foreach (Item child in item.children)
                {
                    //设子元素的style样式与父亲相同
                    child.LayoutStyle = item.LayoutStyle;

                    //把child加到content里作为ChildVisual
                    child.container = this;
                    this.AddChildVisual(child);


                    //实现嵌归
                    child.InitialVisual();
                }
            }
            else
            {
                Debug.Assert(false, "");
            }
        }
Example #30
0
        /// <summary>
        /// Save performance.
        /// </summary>
        /// <param name="model"></param>
        private static void SavePerformance(string fileName, PerformanceModel model)
        {
            XmlEditor xmlEditor = new XmlEditor(XmlUtils.GetPath(fileName), Constants.PerformanceRootNodeName);

            xmlEditor.AddNode(Constants.PerformanceRootNodeName, XmlSerialization.Serialize(model));
        }