FormMain.cs
上传用户:hbhltzc
上传日期:2022-06-04
资源大小:1925k
文件大小:166k
源码类别:

xml/soap/webservice

开发平台:

Visual C++

  1.             resources.ApplyResources(this.textAfterToolStripMenuItem, "textAfterToolStripMenuItem");
  2.             this.textAfterToolStripMenuItem.Name = "textAfterToolStripMenuItem";
  3.             this.textAfterToolStripMenuItem.Click += new System.EventHandler(this.textAfterToolStripMenuItem_Click);
  4.             // 
  5.             // textChildToolStripMenuItem
  6.             // 
  7.             resources.ApplyResources(this.textChildToolStripMenuItem, "textChildToolStripMenuItem");
  8.             this.textChildToolStripMenuItem.Name = "textChildToolStripMenuItem";
  9.             this.textChildToolStripMenuItem.Click += new System.EventHandler(this.textChildToolStripMenuItem_Click);
  10.             // 
  11.             // commentToolStripMenuItem
  12.             // 
  13.             resources.ApplyResources(this.commentToolStripMenuItem, "commentToolStripMenuItem");
  14.             this.commentToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
  15.             this.commentBeforeToolStripMenuItem,
  16.             this.commentAfterToolStripMenuItem,
  17.             this.commentChildToolStripMenuItem});
  18.             this.commentToolStripMenuItem.Name = "commentToolStripMenuItem";
  19.             // 
  20.             // commentBeforeToolStripMenuItem
  21.             // 
  22.             resources.ApplyResources(this.commentBeforeToolStripMenuItem, "commentBeforeToolStripMenuItem");
  23.             this.commentBeforeToolStripMenuItem.Name = "commentBeforeToolStripMenuItem";
  24.             this.commentBeforeToolStripMenuItem.Click += new System.EventHandler(this.commentBeforeToolStripMenuItem_Click);
  25.             // 
  26.             // commentAfterToolStripMenuItem
  27.             // 
  28.             resources.ApplyResources(this.commentAfterToolStripMenuItem, "commentAfterToolStripMenuItem");
  29.             this.commentAfterToolStripMenuItem.Name = "commentAfterToolStripMenuItem";
  30.             this.commentAfterToolStripMenuItem.Click += new System.EventHandler(this.commentAfterToolStripMenuItem_Click);
  31.             // 
  32.             // commentChildToolStripMenuItem
  33.             // 
  34.             resources.ApplyResources(this.commentChildToolStripMenuItem, "commentChildToolStripMenuItem");
  35.             this.commentChildToolStripMenuItem.Name = "commentChildToolStripMenuItem";
  36.             this.commentChildToolStripMenuItem.Click += new System.EventHandler(this.commentChildToolStripMenuItem_Click);
  37.             // 
  38.             // CDATAToolStripMenuItem
  39.             // 
  40.             this.CDATAToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
  41.             this.cdataBeforeToolStripMenuItem,
  42.             this.cdataAfterToolStripMenuItem,
  43.             this.cdataChildToolStripMenuItem});
  44.             this.CDATAToolStripMenuItem.Name = "CDATAToolStripMenuItem";
  45.             resources.ApplyResources(this.CDATAToolStripMenuItem, "CDATAToolStripMenuItem");
  46.             // 
  47.             // cdataBeforeToolStripMenuItem
  48.             // 
  49.             resources.ApplyResources(this.cdataBeforeToolStripMenuItem, "cdataBeforeToolStripMenuItem");
  50.             this.cdataBeforeToolStripMenuItem.Name = "cdataBeforeToolStripMenuItem";
  51.             this.cdataBeforeToolStripMenuItem.Click += new System.EventHandler(this.cdataBeforeToolStripMenuItem_Click);
  52.             // 
  53.             // cdataAfterToolStripMenuItem
  54.             // 
  55.             resources.ApplyResources(this.cdataAfterToolStripMenuItem, "cdataAfterToolStripMenuItem");
  56.             this.cdataAfterToolStripMenuItem.Name = "cdataAfterToolStripMenuItem";
  57.             this.cdataAfterToolStripMenuItem.Click += new System.EventHandler(this.cdataAfterToolStripMenuItem_Click);
  58.             // 
  59.             // cdataChildToolStripMenuItem
  60.             // 
  61.             resources.ApplyResources(this.cdataChildToolStripMenuItem, "cdataChildToolStripMenuItem");
  62.             this.cdataChildToolStripMenuItem.Name = "cdataChildToolStripMenuItem";
  63.             this.cdataChildToolStripMenuItem.Click += new System.EventHandler(this.cdataChildToolStripMenuItem_Click);
  64.             // 
  65.             // PIToolStripMenuItem
  66.             // 
  67.             this.PIToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
  68.             this.PIBeforeToolStripMenuItem,
  69.             this.PIAfterToolStripMenuItem,
  70.             this.PIChildToolStripMenuItem});
  71.             this.PIToolStripMenuItem.Name = "PIToolStripMenuItem";
  72.             resources.ApplyResources(this.PIToolStripMenuItem, "PIToolStripMenuItem");
  73.             // 
  74.             // PIBeforeToolStripMenuItem
  75.             // 
  76.             resources.ApplyResources(this.PIBeforeToolStripMenuItem, "PIBeforeToolStripMenuItem");
  77.             this.PIBeforeToolStripMenuItem.Name = "PIBeforeToolStripMenuItem";
  78.             this.PIBeforeToolStripMenuItem.Click += new System.EventHandler(this.PIBeforeToolStripMenuItem_Click);
  79.             // 
  80.             // PIAfterToolStripMenuItem
  81.             // 
  82.             resources.ApplyResources(this.PIAfterToolStripMenuItem, "PIAfterToolStripMenuItem");
  83.             this.PIAfterToolStripMenuItem.Name = "PIAfterToolStripMenuItem";
  84.             this.PIAfterToolStripMenuItem.Click += new System.EventHandler(this.PIAfterToolStripMenuItem_Click);
  85.             // 
  86.             // PIChildToolStripMenuItem
  87.             // 
  88.             resources.ApplyResources(this.PIChildToolStripMenuItem, "PIChildToolStripMenuItem");
  89.             this.PIChildToolStripMenuItem.Name = "PIChildToolStripMenuItem";
  90.             this.PIChildToolStripMenuItem.Click += new System.EventHandler(this.PIChildToolStripMenuItem_Click);
  91.             // 
  92.             // windowToolStripMenuItem
  93.             // 
  94.             resources.ApplyResources(this.windowToolStripMenuItem, "windowToolStripMenuItem");
  95.             this.windowToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
  96.             this.newWindowToolStripMenuItem});
  97.             this.windowToolStripMenuItem.Name = "windowToolStripMenuItem";
  98.             // 
  99.             // newWindowToolStripMenuItem
  100.             // 
  101.             resources.ApplyResources(this.newWindowToolStripMenuItem, "newWindowToolStripMenuItem");
  102.             this.newWindowToolStripMenuItem.Name = "newWindowToolStripMenuItem";
  103.             this.newWindowToolStripMenuItem.Click += new System.EventHandler(this.newWindowToolStripMenuItem_Click);
  104.             // 
  105.             // helpToolStripMenuItem
  106.             // 
  107.             resources.ApplyResources(this.helpToolStripMenuItem, "helpToolStripMenuItem");
  108.             this.helpToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
  109.             this.contentsToolStripMenuItem,
  110.             this.indexToolStripMenuItem,
  111.             this.toolStripMenuItem10,
  112.             this.aboutXMLNotepadToolStripMenuItem});
  113.             this.helpToolStripMenuItem.Name = "helpToolStripMenuItem";
  114.             // 
  115.             // contentsToolStripMenuItem
  116.             // 
  117.             resources.ApplyResources(this.contentsToolStripMenuItem, "contentsToolStripMenuItem");
  118.             this.contentsToolStripMenuItem.Name = "contentsToolStripMenuItem";
  119.             this.contentsToolStripMenuItem.Click += new System.EventHandler(this.contentsToolStripMenuItem_Click);
  120.             // 
  121.             // indexToolStripMenuItem
  122.             // 
  123.             resources.ApplyResources(this.indexToolStripMenuItem, "indexToolStripMenuItem");
  124.             this.indexToolStripMenuItem.Name = "indexToolStripMenuItem";
  125.             this.indexToolStripMenuItem.Click += new System.EventHandler(this.indexToolStripMenuItem_Click);
  126.             // 
  127.             // toolStripMenuItem10
  128.             // 
  129.             this.toolStripMenuItem10.Name = "toolStripMenuItem10";
  130.             resources.ApplyResources(this.toolStripMenuItem10, "toolStripMenuItem10");
  131.             // 
  132.             // aboutXMLNotepadToolStripMenuItem
  133.             // 
  134.             resources.ApplyResources(this.aboutXMLNotepadToolStripMenuItem, "aboutXMLNotepadToolStripMenuItem");
  135.             this.aboutXMLNotepadToolStripMenuItem.Name = "aboutXMLNotepadToolStripMenuItem";
  136.             this.aboutXMLNotepadToolStripMenuItem.Click += new System.EventHandler(this.aboutXMLNotepadToolStripMenuItem_Click);
  137.             // 
  138.             // toolStripMenuItemUpdate
  139.             // 
  140.             resources.ApplyResources(this.toolStripMenuItemUpdate, "toolStripMenuItemUpdate");
  141.             this.toolStripMenuItemUpdate.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
  142.             this.toolStripMenuItemUpdate.BackColor = System.Drawing.Color.MediumAquamarine;
  143.             this.toolStripMenuItemUpdate.Name = "toolStripMenuItemUpdate";
  144.             // 
  145.             // toolStrip1
  146.             // 
  147.             this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
  148.             this.toolStripButtonNew,
  149.             this.toolStripButtonOpen,
  150.             this.toolStripButtonSave,
  151.             this.toolStripButtonUndo,
  152.             this.toolStripButtonRedo,
  153.             this.toolStripButtonCut,
  154.             this.toolStripButtonCopy,
  155.             this.toolStripButtonPaste,
  156.             this.toolStripButtonDelete,
  157.             this.toolStripSeparator4,
  158.             this.toolStripButtonNudgeUp,
  159.             this.toolStripButtonNudgeDown,
  160.             this.toolStripButtonNudgeLeft,
  161.             this.toolStripButtonNudgeRight,
  162.             this.toolStripSeparator1});
  163.             resources.ApplyResources(this.toolStrip1, "toolStrip1");
  164.             this.toolStrip1.Name = "toolStrip1";
  165.             // 
  166.             // toolStripButtonNew
  167.             // 
  168.             resources.ApplyResources(this.toolStripButtonNew, "toolStripButtonNew");
  169.             this.toolStripButtonNew.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
  170.             this.toolStripButtonNew.Name = "toolStripButtonNew";
  171.             this.toolStripButtonNew.Click += new System.EventHandler(this.toolStripButtonNew_Click);
  172.             // 
  173.             // toolStripButtonOpen
  174.             // 
  175.             resources.ApplyResources(this.toolStripButtonOpen, "toolStripButtonOpen");
  176.             this.toolStripButtonOpen.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
  177.             this.toolStripButtonOpen.Name = "toolStripButtonOpen";
  178.             this.toolStripButtonOpen.Click += new System.EventHandler(this.toolStripButtonOpen_Click);
  179.             // 
  180.             // toolStripButtonSave
  181.             // 
  182.             resources.ApplyResources(this.toolStripButtonSave, "toolStripButtonSave");
  183.             this.toolStripButtonSave.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
  184.             this.toolStripButtonSave.Name = "toolStripButtonSave";
  185.             this.toolStripButtonSave.Click += new System.EventHandler(this.toolStripButtonSave_Click);
  186.             // 
  187.             // toolStripButtonUndo
  188.             // 
  189.             resources.ApplyResources(this.toolStripButtonUndo, "toolStripButtonUndo");
  190.             this.toolStripButtonUndo.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
  191.             this.toolStripButtonUndo.Name = "toolStripButtonUndo";
  192.             this.toolStripButtonUndo.Click += new System.EventHandler(this.toolStripButtonUndo_Click);
  193.             // 
  194.             // toolStripButtonRedo
  195.             // 
  196.             resources.ApplyResources(this.toolStripButtonRedo, "toolStripButtonRedo");
  197.             this.toolStripButtonRedo.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
  198.             this.toolStripButtonRedo.Name = "toolStripButtonRedo";
  199.             this.toolStripButtonRedo.Click += new System.EventHandler(this.toolStripButtonRedo_Click);
  200.             // 
  201.             // toolStripButtonCut
  202.             // 
  203.             resources.ApplyResources(this.toolStripButtonCut, "toolStripButtonCut");
  204.             this.toolStripButtonCut.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
  205.             this.toolStripButtonCut.Name = "toolStripButtonCut";
  206.             this.toolStripButtonCut.Click += new System.EventHandler(this.toolStripButtonCut_Click);
  207.             // 
  208.             // toolStripButtonCopy
  209.             // 
  210.             resources.ApplyResources(this.toolStripButtonCopy, "toolStripButtonCopy");
  211.             this.toolStripButtonCopy.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
  212.             this.toolStripButtonCopy.Name = "toolStripButtonCopy";
  213.             this.toolStripButtonCopy.Click += new System.EventHandler(this.toolStripButtonCopy_Click);
  214.             // 
  215.             // toolStripButtonPaste
  216.             // 
  217.             resources.ApplyResources(this.toolStripButtonPaste, "toolStripButtonPaste");
  218.             this.toolStripButtonPaste.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
  219.             this.toolStripButtonPaste.Name = "toolStripButtonPaste";
  220.             this.toolStripButtonPaste.Click += new System.EventHandler(this.toolStripButtonPaste_Click);
  221.             // 
  222.             // toolStripButtonDelete
  223.             // 
  224.             resources.ApplyResources(this.toolStripButtonDelete, "toolStripButtonDelete");
  225.             this.toolStripButtonDelete.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
  226.             this.toolStripButtonDelete.Name = "toolStripButtonDelete";
  227.             this.toolStripButtonDelete.Click += new System.EventHandler(this.toolStripButtonDelete_Click);
  228.             // 
  229.             // toolStripSeparator4
  230.             // 
  231.             this.toolStripSeparator4.Name = "toolStripSeparator4";
  232.             resources.ApplyResources(this.toolStripSeparator4, "toolStripSeparator4");
  233.             // 
  234.             // toolStripButtonNudgeUp
  235.             // 
  236.             resources.ApplyResources(this.toolStripButtonNudgeUp, "toolStripButtonNudgeUp");
  237.             this.toolStripButtonNudgeUp.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
  238.             this.toolStripButtonNudgeUp.Name = "toolStripButtonNudgeUp";
  239.             this.toolStripButtonNudgeUp.Click += new System.EventHandler(this.toolStripButtonNudgeUp_Click);
  240.             // 
  241.             // toolStripButtonNudgeDown
  242.             // 
  243.             resources.ApplyResources(this.toolStripButtonNudgeDown, "toolStripButtonNudgeDown");
  244.             this.toolStripButtonNudgeDown.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
  245.             this.toolStripButtonNudgeDown.Name = "toolStripButtonNudgeDown";
  246.             this.toolStripButtonNudgeDown.Click += new System.EventHandler(this.toolStripButtonNudgeDown_Click);
  247.             // 
  248.             // toolStripButtonNudgeLeft
  249.             // 
  250.             resources.ApplyResources(this.toolStripButtonNudgeLeft, "toolStripButtonNudgeLeft");
  251.             this.toolStripButtonNudgeLeft.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
  252.             this.toolStripButtonNudgeLeft.Name = "toolStripButtonNudgeLeft";
  253.             this.toolStripButtonNudgeLeft.Click += new System.EventHandler(this.toolStripButtonNudgeLeft_Click);
  254.             // 
  255.             // toolStripButtonNudgeRight
  256.             // 
  257.             resources.ApplyResources(this.toolStripButtonNudgeRight, "toolStripButtonNudgeRight");
  258.             this.toolStripButtonNudgeRight.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
  259.             this.toolStripButtonNudgeRight.Name = "toolStripButtonNudgeRight";
  260.             this.toolStripButtonNudgeRight.Click += new System.EventHandler(this.toolStripButtonNudgeRight_Click);
  261.             // 
  262.             // toolStripSeparator1
  263.             // 
  264.             this.toolStripSeparator1.Name = "toolStripSeparator1";
  265.             resources.ApplyResources(this.toolStripSeparator1, "toolStripSeparator1");
  266.             // 
  267.             // tabPageTaskList
  268.             // 
  269.             resources.ApplyResources(this.tabPageTaskList, "tabPageTaskList");
  270.             this.tabPageTaskList.Name = "tabPageTaskList";
  271.             // 
  272.             // tabPageDynamicHelp
  273.             // 
  274.             resources.ApplyResources(this.tabPageDynamicHelp, "tabPageDynamicHelp");
  275.             this.tabPageDynamicHelp.Name = "tabPageDynamicHelp";
  276.             // 
  277.             // resizer
  278.             // 
  279.             resources.ApplyResources(this.resizer, "resizer");
  280.             this.resizer.Border3DStyle = System.Windows.Forms.Border3DStyle.Raised;
  281.             this.resizer.Name = "resizer";
  282.             this.resizer.Pane1 = null;
  283.             this.resizer.Pane2 = null;
  284.             this.resizer.PaneWidth = 5;
  285.             this.resizer.Vertical = false;
  286.             // 
  287.             // taskList
  288.             // 
  289.             resources.ApplyResources(this.taskList, "taskList");
  290.             this.taskList.Name = "taskList";
  291.             // 
  292.             // dynamicHelpViewer
  293.             // 
  294.             resources.ApplyResources(this.dynamicHelpViewer, "dynamicHelpViewer");
  295.             this.dynamicHelpViewer.DefaultStylesheetResource = "XmlNotepad.DefaultSS.xslt";
  296.             this.dynamicHelpViewer.Name = "dynamicHelpViewer";
  297.             this.dynamicHelpViewer.ShowFileStrip = true;
  298.             // 
  299.             // xsltViewer
  300.             // 
  301.             resources.ApplyResources(this.xsltViewer, "xsltViewer");
  302.             this.xsltViewer.DefaultStylesheetResource = "XmlNotepad.DefaultSS.xslt";
  303.             this.xsltViewer.Name = "xsltViewer";
  304.             this.xsltViewer.ShowFileStrip = true;
  305.             // 
  306.             // tabControlViews
  307.             // 
  308.             resources.ApplyResources(this.tabControlViews, "tabControlViews");
  309.             this.tabControlViews.Controls.Add(this.tabPageTreeView);
  310.             this.tabControlViews.Controls.Add(this.tabPageHtmlView);
  311.             this.tabControlViews.Name = "tabControlViews";
  312.             this.tabControlViews.SelectedIndex = 0;
  313.             this.tabControlViews.SelectedTab = this.tabPageTreeView;
  314.             this.tabControlViews.Selected += new XmlNotepad.NoBorderTabControlEventHandler(this.TabControlViews_Selected);
  315.             // 
  316.             // tabPageTreeView
  317.             // 
  318.             resources.ApplyResources(this.tabPageTreeView, "tabPageTreeView");
  319.             this.tabPageTreeView.Controls.Add(this.xmlTreeView1);
  320.             this.tabPageTreeView.Name = "tabPageTreeView";
  321.             // 
  322.             // tabPageHtmlView
  323.             // 
  324.             resources.ApplyResources(this.tabPageHtmlView, "tabPageHtmlView");
  325.             this.tabPageHtmlView.Controls.Add(this.xsltViewer);
  326.             this.tabPageHtmlView.Name = "tabPageHtmlView";
  327.             // 
  328.             // comboBoxLocation
  329.             // 
  330.             resources.ApplyResources(this.comboBoxLocation, "comboBoxLocation");
  331.             this.comboBoxLocation.FormattingEnabled = true;
  332.             this.comboBoxLocation.Name = "comboBoxLocation";
  333.             // 
  334.             // FormMain
  335.             // 
  336.             resources.ApplyResources(this, "$this");
  337.             this.Controls.Add(this.comboBoxLocation);
  338.             this.Controls.Add(this.tabControlViews);
  339.             this.Controls.Add(this.toolStrip1);
  340.             this.Controls.Add(this.statusBar1);
  341.             this.Controls.Add(this.resizer);
  342.             this.Controls.Add(this.menuStrip1);
  343.             this.MainMenuStrip = this.menuStrip1;
  344.             this.Name = "FormMain";
  345.             ((System.ComponentModel.ISupportInitialize)(this.statusBarPanelMessage)).EndInit();
  346.             ((System.ComponentModel.ISupportInitialize)(this.statusBarPanelBusy)).EndInit();
  347.             this.contextMenu1.ResumeLayout(false);
  348.             this.menuStrip1.ResumeLayout(false);
  349.             this.menuStrip1.PerformLayout();
  350.             this.toolStrip1.ResumeLayout(false);
  351.             this.toolStrip1.PerformLayout();
  352.             this.tabControlViews.ResumeLayout(false);
  353.             this.tabPageTreeView.ResumeLayout(false);
  354.             this.tabPageHtmlView.ResumeLayout(false);
  355.             this.ResumeLayout(false);
  356.             this.PerformLayout();
  357.         }
  358.         protected virtual void TabControlViews_Selected(object sender, NoBorderTabControlEventArgs e) {
  359.             if (e.TabPage == this.tabPageHtmlView) {
  360.                 this.DisplayXsltResults();
  361.             }
  362.         }
  363.         #endregion
  364.         void EnableFileMenu(){
  365.             bool hasFile = (model.FileName != null);
  366.             this.toolStripButtonSave.Enabled = this.saveToolStripMenuItem.Enabled = true;
  367.             this.reloadToolStripMenuItem.Enabled = hasFile;
  368.             this.saveAsToolStripMenuItem.Enabled = true;
  369.         }
  370.         public virtual void DisplayXsltResults() {
  371.             this.xsltViewer.DisplayXsltResults();
  372.         }
  373.         void SelectTreeView() {
  374.             if (tabControlViews.SelectedIndex != 0) {
  375.                 tabControlViews.SelectedIndex = 0;
  376.             }
  377.             if (!xmlTreeView1.ContainsFocus) {
  378.                 xmlTreeView1.Focus();
  379.             }
  380.         }
  381.         public virtual void New(){
  382.             SelectTreeView();
  383.             if (!SaveIfDirty(true))
  384.                 return;  
  385.             model.Clear();
  386.             includesExpanded = false;
  387.             EnableFileMenu();
  388.             this.settings["FileName"] = new Uri("/", UriKind.RelativeOrAbsolute);
  389.             UpdateMenuState();
  390.         }
  391.         protected virtual IIntellisenseProvider CreateIntellisenseProvider(XmlCache model, ISite site) {
  392.             return new XmlIntellisenseProvider(this.model, site);
  393.         }
  394.         protected override object GetService(Type service) {
  395.             if (service == typeof(UndoManager)){
  396.                 return this.undoManager;
  397.             } else if (service == typeof(SchemaCache)) {
  398.                 return this.model.SchemaCache;
  399.             } else if (service == typeof(TreeView)) {
  400.                 XmlTreeView view = (XmlTreeView)GetService(typeof(XmlTreeView));
  401.                 return view.TreeView;
  402.             } else if (service == typeof(XmlTreeView)) {
  403.                 if (this.xmlTreeView1 == null) {
  404.                     this.xmlTreeView1 = this.CreateTreeView();
  405.                 }
  406.                 return this.xmlTreeView1;
  407.             } else if (service == typeof(XmlCache)) {
  408.                 if (null == this.model)
  409.                 {
  410.                     this.model = new XmlCache((IServiceProvider)this, (ISynchronizeInvoke)this);
  411.                 }
  412.                 return this.model;
  413.             } else if (service == typeof(Settings)){
  414.                 return this.settings;
  415.             } else if (service == typeof(IIntellisenseProvider)) {
  416.                 if (this.ip == null) this.ip = CreateIntellisenseProvider(this.model, this);
  417.                 return this.ip;
  418.             } else if (service == typeof(HelpProvider)) {
  419.                 return this.helpProvider1;
  420.             } else if (service == typeof(WebProxyService)) {
  421.                 if (this.proxyService == null)
  422.                     this.proxyService = new WebProxyService((IServiceProvider)this);
  423.                 return this.proxyService;
  424.             } else if (service == typeof(UserSettings)) {
  425.                 return new UserSettings(this.settings);
  426.             }
  427.             return base.GetService (service);
  428.         }
  429.         public OpenFileDialog OpenFileDialog {
  430.             get { return this.od; }
  431.         }
  432.         public virtual void Open() {
  433.             SelectTreeView();
  434.             if (!SaveIfDirty(true))
  435.                 return;
  436.             if (od == null) od = new OpenFileDialog();
  437.             if (model.FileName != null) {
  438.                 Uri uri = new Uri(model.FileName);
  439.                 if (uri.Scheme == "file"){
  440.                     od.FileName = model.FileName;
  441.                 }
  442.             }
  443.             string filter = SR.SaveAsFilter;
  444.             od.Filter = filter;
  445.             string[] parts = filter.Split('|');
  446.             int index = -1;
  447.             for (int i = 1, n = parts.Length; i < n; i += 2 ) {
  448.                 if (parts[i] == "*.*") {
  449.                     index = (i / 2)+1;
  450.                     break;
  451.                 }
  452.             }
  453.             od.FilterIndex = index;
  454.             if (od.ShowDialog(this) == DialogResult.OK){
  455.                 Open(od.FileName);
  456.             }
  457.         }
  458.         public virtual void ShowStatus(string msg) {
  459.             this.statusBarPanelMessage.Text = msg;
  460.         }
  461.         public virtual void Open(string filename) {
  462.             try {
  463.                 // Make sure you've called SaveIfDirty before calling this method.
  464.                 InternalOpen(filename);             
  465.             } catch (Exception e){
  466.                 if (MessageBox.Show(this,
  467.                     string.Format(SR.LoadErrorPrompt, filename, e.Message),
  468.                     SR.LoadErrorCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes) {
  469.                     OpenNotepad(filename);
  470.                 }
  471.             }
  472.         }
  473.         private void InternalOpen(string filename) {
  474.             includesExpanded = false;
  475.             DateTime start = DateTime.Now;            
  476.             this.model.Load(filename);
  477.             DateTime finish = DateTime.Now;
  478.             TimeSpan diff = finish - start;
  479.             string s = diff.ToString();
  480.             this.settings["FileName"] = this.model.Location;
  481.             this.UpdateCaption();
  482.             ShowStatus(string.Format(SR.LoadedTimeStatus, s));
  483.             EnableFileMenu();
  484.             this.recentFiles.AddRecentFile(this.model.Location);
  485.             SelectTreeView();
  486.         }
  487.         bool CheckXIncludes() {
  488.             if (includesExpanded) {
  489.                 if (MessageBox.Show(this, SR.SaveExpandedIncludesPrompt, SR.SaveExpandedIncludesCaption,
  490.                     MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No) {
  491.                     return false;
  492.                 }
  493.                 includesExpanded = false;
  494.             }
  495.             return true;
  496.         }
  497.         public virtual bool SaveIfDirty(bool prompt) {
  498.             if (model.Dirty){
  499.                 if (prompt){
  500.                     SelectTreeView();
  501.                     DialogResult rc = MessageBox.Show(this, SR.SaveChangesPrompt,
  502.                         SR.SaveChangesCaption, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation);                
  503.                     if (rc == DialogResult.Cancel){
  504.                         return false;
  505.                     } else if (rc == DialogResult.Yes){
  506.                         return Save();
  507.                     }
  508.                 } else {
  509.                     return Save();
  510.                 }
  511.             }
  512.             return true;
  513.         }
  514.         public virtual bool Save() {
  515.             this.xmlTreeView1.Commit();
  516.             if (!CheckXIncludes()) return false;                
  517.             string fname = model.FileName;
  518.             if (fname == null){
  519.                 SaveAs();
  520.             } else {
  521.                 try {
  522.                     if (CheckReadOnly(fname)) {
  523.                         model.Save();
  524.                         ShowStatus(SR.SavedStatus);
  525.                     }
  526.                 } catch (Exception e){
  527.                     MessageBox.Show(this, e.Message, SR.SaveErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
  528.                 }     
  529.             }
  530.             return true;
  531.         }
  532.         public bool CheckReadOnly(string fname) {
  533.             if (model.IsReadOnly(fname)) {
  534.                 SelectTreeView();
  535.                 if (MessageBox.Show(this, string.Format(SR.ReadOnly, fname),
  536.                     SR.ReadOnlyCaption, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation) == DialogResult.Yes) {
  537.                     model.MakeReadWrite(fname);
  538.                     return true;
  539.                 } else {
  540.                     return false;
  541.                 }
  542.             }
  543.             return true;    
  544.         }
  545.         public virtual void Save(string newName) {
  546.             this.xmlTreeView1.Commit();
  547.             try {
  548.                 bool hasFile = (model.FileName != null);
  549.                 if (!hasFile && string.IsNullOrEmpty(newName)) {
  550.                     SaveAs();
  551.                 }
  552.                 if (CheckReadOnly(newName)) {
  553.                     model.Save(newName);
  554.                     UpdateCaption();
  555.                     ShowStatus(SR.SavedStatus);
  556.                     this.settings["FileName"] = model.Location;
  557.                     EnableFileMenu();
  558.                 }
  559.             } catch (Exception e){
  560.                 MessageBox.Show(this, e.Message, SR.SaveErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);                
  561.             }
  562.         }
  563.         public virtual void SaveAs() {
  564.             SelectTreeView();
  565.             SaveFileDialog sd = new SaveFileDialog();
  566.             if (model.IsFile) sd.FileName = model.FileName;
  567.             sd.Filter = SR.SaveAsFilter;
  568.             if (sd.ShowDialog(this) == DialogResult.OK){
  569.                 string fname = sd.FileName;
  570.                 if (CheckReadOnly(fname)) {
  571.                     Save(fname);
  572.                 }
  573.             }
  574.         }
  575.         string caption = null;
  576.         public string Caption {
  577.             get {
  578.                 if (string.IsNullOrEmpty(caption))
  579.                     caption = SR.MainFormTitle;
  580.                 return caption; }
  581.             set { caption = value; }
  582.         }
  583.         public virtual void UpdateCaption() {
  584.             string caption = this.Caption + " - " + model.FileName;
  585.             if (this.model.Dirty){
  586.                 caption += "*";
  587.             }            
  588.             this.Text = caption;
  589.             sourceToolStripMenuItem.Enabled = this.model.FileName != null;
  590.             ShowStatus("");
  591.         }
  592.         void OnFileChanged(object sender, EventArgs e) {
  593.             if (!prompting) OnFileChanged();
  594.         }
  595.         bool prompting = false;
  596.         protected virtual void OnFileChanged() {
  597.             prompting = true;
  598.             try {
  599.                 if (this.WindowState == FormWindowState.Minimized) {
  600.                     this.WindowState = FormWindowState.Normal;
  601.                 }
  602.                 SelectTreeView();
  603.                 if (MessageBox.Show(this, SR.FileChagedOnDiskPrompt, SR.FileChagedOnDiskCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) {
  604.                     string location = this.model.Location.LocalPath;
  605.                     this.model.Clear();
  606.                     this.Open(location);                                                     
  607.                 }
  608.             } finally {
  609.                 prompting = false;
  610.             }
  611.         }
  612.         private void undoManager_StateChanged(object sender, EventArgs e) {
  613.             this.ShowStatus("");
  614.             this.undoToolStripMenuItem.Enabled = toolStripButtonUndo.Enabled = this.undoManager.CanUndo;
  615.             this.redoToolStripMenuItem.Enabled = toolStripButtonRedo.Enabled = this.undoManager.CanRedo;
  616.             Command cmd = this.undoManager.Peek();
  617.             this.undoToolStripMenuItem.Text = this.undoLabel + " " + (cmd == null ? "" : cmd.Name);
  618.             cmd = this.undoManager.Current;
  619.             this.redoToolStripMenuItem.Text = this.redoLabel + " " + (cmd == null ? "" : cmd.Name);
  620.         }
  621.         public virtual string ConfigFile {
  622.             get { 
  623.                 string path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
  624.                 Debug.Assert(!string.IsNullOrEmpty(path));
  625.                 return path + @"MicrosoftXml NotepadXmlNotepad.settings";
  626.             }
  627.         }
  628.         public virtual void LoadConfig() {
  629.             string path = null;
  630.             this.loading = true;
  631.             if (this.args != null && this.args.Length > 0) {
  632.                 // When user passes arguments we skip the config file
  633.                 // This is for unit testing where we need consistent config!
  634.                 path = this.args[0];
  635.                 this.settings.FileName = this.ConfigFile;
  636.             } else {
  637.                 if (File.Exists(this.ConfigFile)) {
  638.                     settings.Load(this.ConfigFile);                    
  639.                     Uri location = (Uri)this.settings["FileName"];
  640.                     // Load up the last file we were editing before - if it is local and still exists.
  641.                     if (location != null && location.OriginalString != "/" && location.IsFile && File.Exists(location.LocalPath)) {
  642.                         path = location.LocalPath;
  643.                     }
  644.                 }
  645.             }            
  646.             this.loading = false;
  647.         }
  648.         public virtual void SaveConfig() {
  649.             this.settings.StopWatchingFileChanges();
  650.             Rectangle r = (this.WindowState == FormWindowState.Normal) ? this.Bounds : this.RestoreBounds;
  651.             this.settings["WindowBounds"] = r;
  652.             this.settings["Font"] = this.Font;
  653.             this.settings["TaskListSize"] = this.tabControlLists.Height;
  654.             this.settings["TreeViewSize"] = this.xmlTreeView1.ResizerPosition;
  655.             this.settings["RecentFiles"] = this.recentFiles.ToArray();
  656.             this.settings.Save(this.ConfigFile);
  657.         }
  658.         #region  ISite implementation
  659.         IComponent ISite.Component{
  660.             get { return this; }
  661.         }
  662.         public static Type ResourceType { get { return typeof(SR); } }
  663.         string ISite.Name {
  664.             get { return this.Name; }
  665.             set { this.Name = value; } 
  666.         }
  667.         IContainer ISite.Container {
  668.             get { return this.Container; }
  669.         }
  670.         bool ISite.DesignMode {
  671.             get { return this.DesignMode;}
  672.         }
  673.         object IServiceProvider.GetService(Type serviceType) {
  674.             return this.GetService(serviceType);
  675.         }
  676.         #endregion
  677.         void OnModelChanged(object sender, ModelChangedEventArgs e) {
  678.             if (e.ModelChangeType == ModelChangeType.Reloaded) {
  679.                 this.undoManager.Clear();
  680.                 this.taskList.Clear();
  681.             }
  682.             if (e.ModelChangeType == ModelChangeType.BeginBatchUpdate) {
  683.                 batch++;
  684.             } else if (e.ModelChangeType == ModelChangeType.EndBatchUpdate) {
  685.                 batch--;
  686.             }
  687.             if (batch == 0) OnModelChanged();
  688.         }
  689.         protected virtual void OnModelChanged() {
  690.             TaskHandler handler = new TaskHandler(this.taskList);
  691.             handler.Start();
  692.             this.model.ValidateModel(handler);
  693.             handler.Finish();
  694.             UpdateCaption();
  695.         }
  696.         private void settings_Changed(object sender, string name) {
  697.             // Make sure it's on the right thread...
  698.             ISynchronizeInvoke si = (ISynchronizeInvoke)this;
  699.             if (si.InvokeRequired) {
  700.                 si.BeginInvoke(new SettingsEventHandler(OnSettingsChanged),
  701.                     new object[] { sender, name });
  702.             } else {
  703.                 OnSettingsChanged(sender, name);
  704.             }
  705.         }
  706.         protected virtual void OnSettingsChanged(object sender, string name) {        
  707.             switch (name){
  708.                 case "File":
  709.                     this.settings.Reload(); // just do it!!                    
  710.                     break;
  711.                 case "WindowBounds":
  712.                     if (loading) { // only if loading first time!
  713.                         Rectangle r = (Rectangle)this.settings["WindowBounds"];
  714.                         if (!r.IsEmpty) {
  715.                             Screen s = Screen.FromRectangle(r);
  716.                             if (s.Bounds.Contains(r)) {
  717.                                 this.Bounds = r;
  718.                                 this.StartPosition = FormStartPosition.Manual;
  719.                             }
  720.                         }
  721.                     }
  722.                     break;
  723.                 case "TreeViewSize":
  724.                     int pos = (int)this.settings["TreeViewSize"];
  725.                     if (pos != 0) {
  726.                         this.xmlTreeView1.ResizerPosition = pos;
  727.                     }
  728.                     break;
  729.                 case "TaskListSize":
  730.                     int height = (int)this.settings["TaskListSize"];
  731.                     if (height != 0) {
  732.                         this.tabControlLists.Height = height;
  733.                     } 
  734.                     break;
  735.                 case "Font":
  736.                     this.Font = (Font)this.settings["Font"];
  737.                     break;
  738.                 case "RecentFiles":
  739.                     Uri[] files = (Uri[])this.settings["RecentFiles"];
  740.                     if (files != null) {
  741.                         this.recentFiles.SetFiles(files);
  742.                     }
  743.                     break;
  744.             }
  745.         }
  746.         public void SaveErrors(string filename) {
  747.             this.taskList.Save(filename);
  748.         }
  749.         void OnRecentFileSelected(object sender, RecentFileEventArgs e) {
  750.             if (!this.SaveIfDirty(true))
  751.                 return;                                       
  752.             string fileName = e.FileName;
  753.             Open(fileName);
  754.         }
  755.         private void treeView1_SelectionChanged(object sender, EventArgs e) {
  756.             UpdateMenuState();
  757.             DisplayHelp();
  758.         }
  759.         private void DisplayHelp() {
  760.             // display documentation
  761.             if (null == xmlTreeView1.SelectedNode) {
  762.                 this.dynamicHelpViewer.DisplayXsltResults(new XmlDocument());
  763.                 return;
  764.             }
  765.             XmlDocument xmlDoc = xmlTreeView1.SelectedNode.GetDocumentation();
  766.             if (this.dynamicHelpViewer.Visible) {
  767.                 ShowStatus("");
  768.                 helpAvailableHint = false;
  769.                 if (null == xmlDoc) {
  770.                     xmlDoc = new XmlDocument();
  771.                     if (taskList.Count > 0) {
  772.                         xmlDoc.AppendChild(xmlDoc.CreateElement("errors"));
  773.                     } else {
  774.                         xmlDoc.AppendChild(xmlDoc.CreateElement("nothing"));
  775.                     }
  776.                 }
  777.                 this.dynamicHelpViewer.DisplayXsltResults(xmlDoc);
  778.             } else if (helpAvailableHint && xmlDoc != null) {
  779.                 helpAvailableHint = false;
  780.                 ShowStatus(SR.DynamicHelpAvailable);
  781.             }
  782.         }
  783.         private void treeView1_NodeChanged(object sender, NodeChangeEventArgs e) {
  784.             UpdateMenuState();
  785.         }
  786.         protected virtual void UpdateMenuState() {
  787.             XmlTreeNode node = this.xmlTreeView1.SelectedNode as XmlTreeNode;
  788.             XmlNode xnode = (node != null) ? node.Node : null;
  789.             bool hasSelection = node != null;
  790.             bool hasXmlNode = xnode != null;
  791.             this.toolStripButtonCut.Enabled = this.cutToolStripMenuItem.Enabled = this.ctxcutToolStripMenuItem.Enabled = hasXmlNode;
  792.             this.toolStripButtonDelete.Enabled = this.deleteToolStripMenuItem.Enabled = hasSelection;
  793.             this.toolStripButtonCopy.Enabled = this.copyToolStripMenuItem.Enabled = this.ctxMenuItemCopy.Enabled = hasXmlNode;
  794.             this.duplicateToolStripMenuItem.Enabled = hasXmlNode;
  795.             this.changeToAttributeContextMenuItem.Enabled = this.changeToAttributeToolStripMenuItem1.Enabled = hasSelection;
  796.             this.changeToCDATAContextMenuItem.Enabled = this.changeToCDATAToolStripMenuItem1.Enabled = hasSelection;
  797.             this.changeToCommentContextMenuItem.Enabled = this.changeToCommentToolStripMenuItem1.Enabled = hasSelection;
  798.             this.changeToElementContextMenuItem.Enabled = this.changeToElementToolStripMenuItem1.Enabled = hasSelection;
  799.             this.changeToProcessingInstructionContextMenuItem.Enabled = this.changeToProcessingInstructionToolStripMenuItem.Enabled = hasSelection;
  800.             this.changeToTextContextMenuItem.Enabled = this.changeToTextToolStripMenuItem1.Enabled = hasSelection;
  801.             this.toolStripButtonNudgeUp.Enabled = upToolStripMenuItem.Enabled = this.xmlTreeView1.CanNudgeNode((XmlTreeNode)this.xmlTreeView1.SelectedNode, NudgeDirection.Up);
  802.             this.toolStripButtonNudgeDown.Enabled = downToolStripMenuItem.Enabled = this.xmlTreeView1.CanNudgeNode((XmlTreeNode)this.xmlTreeView1.SelectedNode, NudgeDirection.Down);
  803.             this.toolStripButtonNudgeLeft.Enabled = leftToolStripMenuItem.Enabled = this.xmlTreeView1.CanNudgeNode((XmlTreeNode)this.xmlTreeView1.SelectedNode, NudgeDirection.Left);
  804.             this.toolStripButtonNudgeRight.Enabled = rightToolStripMenuItem.Enabled = this.xmlTreeView1.CanNudgeNode((XmlTreeNode)this.xmlTreeView1.SelectedNode, NudgeDirection.Right);
  805.             this.repeatToolStripMenuItem.Enabled = hasSelection && xnode != null && this.xmlTreeView1.CanInsertNode(InsertPosition.After, xnode.NodeType);
  806.             this.undoToolStripMenuItem.Enabled = toolStripButtonUndo.Enabled = this.undoManager.CanUndo;
  807.             this.redoToolStripMenuItem.Enabled = toolStripButtonRedo.Enabled = this.undoManager.CanRedo;
  808.             EnableNodeItems(XmlNodeType.Element, this.ctxElementBeforeToolStripMenuItem, this.elementBeforeToolStripMenuItem,
  809.                 this.ctxElementAfterToolStripMenuItem, this.elementAfterToolStripMenuItem,
  810.                 this.ctxElementChildToolStripMenuItem, this.elementChildToolStripMenuItem);
  811.             EnableNodeItems(XmlNodeType.Attribute, this.ctxAttributeBeforeToolStripMenuItem, this.attributeBeforeToolStripMenuItem,
  812.                 this.ctxAttributeAfterToolStripMenuItem, this.attributeAfterToolStripMenuItem,
  813.                 this.ctxAttributeChildToolStripMenuItem, this.attributeChildToolStripMenuItem);
  814.             EnableNodeItems(XmlNodeType.Text, this.ctxTextBeforeToolStripMenuItem, this.textBeforeToolStripMenuItem,
  815.                 this.ctxTextAfterToolStripMenuItem, this.textAfterToolStripMenuItem,
  816.                 this.ctxTextChildToolStripMenuItem, this.textChildToolStripMenuItem);
  817.             EnableNodeItems(XmlNodeType.CDATA, this.ctxCdataBeforeToolStripMenuItem, this.cdataBeforeToolStripMenuItem,
  818.                 this.ctxCdataAfterToolStripMenuItem, this.cdataAfterToolStripMenuItem,
  819.                 this.ctxCdataChildToolStripMenuItem, this.cdataChildToolStripMenuItem);
  820.             EnableNodeItems(XmlNodeType.Comment, this.ctxCommentBeforeToolStripMenuItem, this.commentBeforeToolStripMenuItem,
  821.                 this.ctxCommentAfterToolStripMenuItem, this.commentAfterToolStripMenuItem,
  822.                 this.ctxCommentChildToolStripMenuItem, this.commentChildToolStripMenuItem);
  823.             EnableNodeItems(XmlNodeType.ProcessingInstruction, this.ctxPIBeforeToolStripMenuItem, this.PIBeforeToolStripMenuItem,
  824.                 this.ctxPIAfterToolStripMenuItem, this.PIAfterToolStripMenuItem,
  825.                 this.ctxPIChildToolStripMenuItem, this.PIChildToolStripMenuItem);
  826.         }
  827.         void EnableNodeItems(XmlNodeType nt, ToolStripMenuItem c1, ToolStripMenuItem m1, ToolStripMenuItem c2, ToolStripMenuItem m2, ToolStripMenuItem c3, ToolStripMenuItem m3){
  828.             c1.Enabled = m1.Enabled = this.xmlTreeView1.CanInsertNode(InsertPosition.Before, nt);
  829.             c2.Enabled = m2.Enabled = this.xmlTreeView1.CanInsertNode(InsertPosition.After, nt);
  830.             c3.Enabled = m3.Enabled = this.xmlTreeView1.CanInsertNode(InsertPosition.Child, nt);
  831.         }
  832.         protected virtual void OpenNotepad(string path) {
  833.             if (this.SaveIfDirty(true)){
  834.                 string sysdir = Environment.SystemDirectory;
  835.                 string notepad = Path.Combine(sysdir, "notepad.exe");
  836.                 if (File.Exists(notepad)){
  837.                     ProcessStartInfo pi = new ProcessStartInfo(notepad, path);
  838.                     Process.Start(pi);
  839.                 }
  840.             }
  841.         }
  842. void treeView1_ClipboardChanged(object sender, EventArgs e) {
  843. CheckClipboard();
  844. }
  845. void CheckClipboard() {
  846.             this.toolStripButtonPaste.Enabled = this.pasteToolStripMenuItem.Enabled = this.ctxMenuItemPaste.Enabled = TreeData.HasData;
  847. }
  848. protected override void OnActivated(EventArgs e) {
  849. CheckClipboard();
  850.             if (firstActivate) {
  851.                 this.comboBoxLocation.Focus();
  852.                 firstActivate = false;
  853.             }
  854.             if (this.xmlTreeView1.TreeView.IsEditing) {
  855.                 this.xmlTreeView1.TreeView.Focus();
  856.             } else if (this.xmlTreeView1.NodeTextView.IsEditing) {
  857.                 this.xmlTreeView1.NodeTextView.Focus();
  858.             }
  859. }
  860.         void taskList_Navigate(object sender, Task task) {
  861.             XmlNode node = task.Data as XmlNode;
  862.             if (node != null) {
  863.                 XmlTreeNode tn = this.xmlTreeView1.FindNode(node);
  864.                 if (tn != null) {
  865.                     this.xmlTreeView1.SelectedNode = tn;
  866.                     this.SelectTreeView();
  867.                 }
  868.             }
  869.         }
  870.         private void Form1_DragOver(object sender, DragEventArgs e) {
  871.             IDataObject data = e.Data;
  872.             if (data.GetDataPresent(DataFormats.FileDrop) || data.GetDataPresent(this.urlFormat.Name)){
  873.                 e.Effect = DragDropEffects.Copy;
  874.             }
  875.             return;
  876.         }
  877.         private void Form1_DragDrop(object sender, DragEventArgs e) {
  878.             IDataObject data = e.Data;
  879.             if (data.GetDataPresent(DataFormats.FileDrop)){
  880.                 Array a = data.GetData(DataFormats.FileDrop) as Array;
  881.                 if (a != null){
  882.                     if (a.Length>0 && a.GetValue(0) is string){
  883.                         string filename = (string)a.GetValue(0);
  884.                         if (!this.SaveIfDirty(true))
  885.                             return;
  886.                         this.Open(filename);
  887.                     }
  888.                 }
  889.             } else if (data.GetDataPresent(this.urlFormat.Name)){
  890.                 Stream stm = data.GetData(this.urlFormat.Name) as Stream;
  891.                 if (stm != null) {
  892.                     try {
  893.                         // Note: for some reason sr.ReadToEnd doesn't work right.
  894.                         StreamReader sr = new StreamReader(stm, Encoding.Unicode);
  895.                         StringBuilder sb = new StringBuilder();
  896.                         while (true) {
  897.                             int i = sr.Read();
  898.                             if (i != 0) {
  899.                                 sb.Append(Convert.ToChar(i));
  900.                             } else {
  901.                                 break;
  902.                             }
  903.                         }
  904.                         string url = sb.ToString();
  905.                         if (!this.SaveIfDirty(true))
  906.                             return;
  907.                         this.Open(url);
  908.                     } catch (Exception){
  909.                     }
  910.                 }
  911.             }
  912.         }
  913.         private void newToolStripMenuItem_Click(object sender, EventArgs e) {
  914.             this.xmlTreeView1.CancelEdit();
  915.             New();
  916.         }
  917.         private void openToolStripMenuItem_Click(object sender, EventArgs e) {
  918.             this.xmlTreeView1.CancelEdit();
  919.             Open();
  920.         }
  921.         private void reloadToolStripMenuItem_Click(object sender, EventArgs e) {
  922.             SelectTreeView(); 
  923.             if (model.Dirty) {                
  924.                 if (MessageBox.Show(this, SR.DiscardChanges, SR.DiscardChangesCaption,
  925.                     MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.Cancel) {
  926.                     return;
  927.                 }                    
  928.             }
  929.             Open(this.model.FileName);
  930.         }
  931.         private void saveToolStripMenuItem_Click(object sender, EventArgs e) {
  932.             this.xmlTreeView1.Commit();
  933.             Save();
  934.         }
  935.         private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) {
  936.             this.xmlTreeView1.Commit();
  937.             SaveAs();
  938.         }
  939.         private void menuItemRecentFiles_Click(object sender, EventArgs e) {
  940.         }
  941.         private void exitToolStripMenuItem_Click(object sender, EventArgs e) {
  942.             this.xmlTreeView1.Commit();
  943.             this.Close();
  944.         }
  945.         private void undoToolStripMenuItem_Click(object sender, EventArgs e) {
  946.             try {
  947.                 this.xmlTreeView1.CancelEdit();
  948.                 this.undoManager.Undo();
  949.                 SelectTreeView();
  950.                 UpdateMenuState();
  951.             } catch (Exception ex) {
  952.                 MessageBox.Show(this, ex.Message, SR.UndoError, MessageBoxButtons.OK, MessageBoxIcon.Error);
  953.             }
  954.         }
  955.         private void redoToolStripMenuItem_Click(object sender, EventArgs e) {
  956.             try {
  957.                 if (this.xmlTreeView1.Commit())
  958.                     this.undoManager.Redo();
  959.                 SelectTreeView();
  960.                 UpdateMenuState();
  961.             } catch (Exception ex) {
  962.                 MessageBox.Show(this, ex.Message, SR.RedoError, MessageBoxButtons.OK, MessageBoxIcon.Error);
  963.             }
  964.         }
  965.         private void cutToolStripMenuItem_Click(object sender, EventArgs e) {
  966.             if (this.xmlTreeView1.Commit()) 
  967.                 this.xmlTreeView1.Cut();
  968.             UpdateMenuState();
  969.             SelectTreeView();
  970.         }
  971.         private void copyToolStripMenuItem_Click(object sender, EventArgs e) {
  972.             this.xmlTreeView1.Commit();
  973.             this.xmlTreeView1.Copy();
  974.             SelectTreeView();
  975.         }
  976.         private void pasteToolStripMenuItem_Click(object sender, EventArgs e) {
  977.             if (this.xmlTreeView1.Commit())
  978.                 this.xmlTreeView1.Paste(InsertPosition.Child);
  979.             UpdateMenuState();
  980.             SelectTreeView();
  981.         }
  982.         private void deleteToolStripMenuItem_Click(object sender, EventArgs e) {
  983.             DeleteSelectedNode();
  984.         }
  985.         void DeleteSelectedNode() {
  986.             this.xmlTreeView1.Commit();
  987.             this.xmlTreeView1.Delete();
  988.             UpdateMenuState();
  989.             SelectTreeView();
  990.         }
  991.         private void repeatToolStripMenuItem_Click(object sender, EventArgs e) {
  992.             this.RepeatSelectedNode();
  993.         }
  994.         void RepeatSelectedNode() {
  995.             if (this.xmlTreeView1.Commit())
  996.                 this.xmlTreeView1.Insert();
  997.             UpdateMenuState();
  998.             SelectTreeView();
  999.         }
  1000.         private void duplicateToolStripMenuItem_Click(object sender, EventArgs e) {
  1001.             DuplicateSelectedNode();
  1002.         }
  1003.         void DuplicateSelectedNode() {
  1004.             try {
  1005.                 if (this.xmlTreeView1.Commit())
  1006.                     this.xmlTreeView1.Duplicate();
  1007.                 UpdateMenuState();
  1008.                 SelectTreeView();
  1009.             } catch (Exception ex) {
  1010.                 MessageBox.Show(this, ex.Message, SR.DuplicateErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
  1011.             }            
  1012.         }
  1013.         private void upToolStripMenuItem_Click(object sender, EventArgs e) {
  1014.             if (this.xmlTreeView1.Commit())                    
  1015.                 this.xmlTreeView1.NudgeNode(this.xmlTreeView1.SelectedNode, NudgeDirection.Up);
  1016.             SelectTreeView();
  1017.         }
  1018.         private void downToolStripMenuItem_Click(object sender, EventArgs e) {
  1019.             if (this.xmlTreeView1.Commit())
  1020.                 this.xmlTreeView1.NudgeNode(this.xmlTreeView1.SelectedNode, NudgeDirection.Down);
  1021.             SelectTreeView();
  1022.         }
  1023.         private void leftToolStripMenuItem_Click(object sender, EventArgs e) {
  1024.             if (this.xmlTreeView1.Commit())
  1025.                 this.xmlTreeView1.NudgeNode(this.xmlTreeView1.SelectedNode, NudgeDirection.Left);
  1026.             SelectTreeView();
  1027.         }
  1028.         private void rightToolStripMenuItem_Click(object sender, EventArgs e) {
  1029.             if (this.xmlTreeView1.Commit())
  1030.                 this.xmlTreeView1.NudgeNode(this.xmlTreeView1.SelectedNode, NudgeDirection.Right);
  1031.             SelectTreeView();
  1032.         }
  1033.         private void findToolStripMenuItem_Click(object sender, EventArgs e) {            
  1034.             Search(false);
  1035.         }
  1036.         private void replaceToolStripMenuItem_Click(object sender, EventArgs e) {
  1037.             Search(true);
  1038.         }
  1039.         void Search(bool replace) {
  1040.             if (this.tabControlViews.SelectedTab == this.tabPageHtmlView) {
  1041.                 this.xsltViewer.Find();
  1042.                 return;
  1043.             }
  1044.             if (search == null || !search.Visible) {
  1045.                 search = new FormSearch(search, (ISite)this);
  1046.             } else {
  1047.                 search.Activate();
  1048.             }
  1049.             search.Target = new XmlTreeViewFindTarget(this.xmlTreeView1);
  1050.             search.ReplaceMode = replace;
  1051.             if (!search.Visible) {
  1052.                 search.Show(this); // modeless
  1053.             }
  1054.         }
  1055.         private void expandToolStripMenuItem_Click(object sender, EventArgs e) {
  1056.             SelectTreeView();
  1057.             XmlTreeNode s = this.xmlTreeView1.SelectedNode;
  1058.             if (s != null) {
  1059.                 s.ExpandAll();
  1060.             }
  1061.         }
  1062.         private void collapseToolStripMenuItem_Click(object sender, EventArgs e) {
  1063.             SelectTreeView();
  1064.             XmlTreeNode s = this.xmlTreeView1.SelectedNode;
  1065.             if (s != null) {
  1066.                 s.CollapseAll();
  1067.             }
  1068.         }
  1069.         private void expandAllToolStripMenuItem_Click(object sender, EventArgs e) {
  1070.             SelectTreeView();
  1071.             this.xmlTreeView1.ExpandAll();
  1072.         }
  1073.         private void collapseAllToolStripMenuItem_Click(object sender, EventArgs e) {
  1074.             SelectTreeView();
  1075.             this.xmlTreeView1.CollapseAll();
  1076.         }
  1077.         private void statusBarToolStripMenuItem_Click(object sender, EventArgs e) {
  1078.             bool visible = !statusBarToolStripMenuItem.Checked;
  1079.             statusBarToolStripMenuItem.Checked = visible;
  1080.             int h = this.ClientSize.Height - this.toolStrip1.Bottom - 2;
  1081.             if (visible) {
  1082.                 h -= this.statusBar1.Height;
  1083.             }
  1084.             this.tabControlViews.Height = h;
  1085.             this.statusBar1.Visible = visible;
  1086.             this.PerformLayout();
  1087.         }
  1088.         private void sourceToolStripMenuItem_Click(object sender, EventArgs e) {
  1089.             if (this.tabControlViews.SelectedTab == this.tabPageHtmlView) {
  1090.                 this.xsltViewer.ViewSource();
  1091.             } else {
  1092.                 OpenNotepad(this.model.FileName);
  1093.             }
  1094.         }
  1095.         private void optionsToolStripMenuItem_Click(object sender, EventArgs e) {
  1096.             string oldLocation = (string)settings["UpdateLocation"];
  1097.             FormOptions options = new FormOptions();
  1098.             options.Site = this;
  1099.             if (options.ShowDialog(this) == DialogResult.OK) {
  1100.                 this.updater.OnUserChange(oldLocation);
  1101.             }
  1102.         }
  1103.         private void contentsToolStripMenuItem_Click(object sender, EventArgs e) {
  1104.             Help.ShowHelp(this, this.helpProvider1.HelpNamespace, HelpNavigator.TableOfContents);
  1105.         }
  1106.         private void indexToolStripMenuItem_Click(object sender, EventArgs e) {
  1107.             Help.ShowHelp(this, this.helpProvider1.HelpNamespace, HelpNavigator.Index);
  1108.         }
  1109.         private void aboutXMLNotepadToolStripMenuItem_Click(object sender, EventArgs e) {
  1110.             FormAbout frm = new FormAbout();
  1111.             frm.ShowDialog(this);
  1112.         }
  1113.         private void toolStripButtonNew_Click(object sender, EventArgs e) {
  1114.             this.xmlTreeView1.CancelEdit();
  1115.             this.New();
  1116.         }
  1117.         private void toolStripButtonOpen_Click(object sender, EventArgs e) {
  1118.             this.xmlTreeView1.CancelEdit();
  1119.             this.Open();
  1120.         }
  1121.         private void toolStripButtonSave_Click(object sender, EventArgs e) {
  1122.             this.xmlTreeView1.Commit();
  1123.             this.Save();
  1124.         }
  1125.         private void toolStripButtonUndo_Click(object sender, EventArgs e) {
  1126.             SelectTreeView();
  1127.             if (this.xmlTreeView1.Commit())
  1128.                 this.undoManager.Undo();
  1129.             UpdateMenuState();
  1130.         }
  1131.         private void toolStripButtonRedo_Click(object sender, EventArgs e) {
  1132.             SelectTreeView();
  1133.             if (this.xmlTreeView1.Commit())
  1134.                 this.undoManager.Redo();
  1135.             UpdateMenuState();
  1136.         }
  1137.         private void toolStripButtonCut_Click(object sender, EventArgs e) {
  1138.             SelectTreeView();
  1139.             this.xmlTreeView1.Cut();
  1140.             UpdateMenuState();
  1141.         }
  1142.         private void toolStripButtonCopy_Click(object sender, EventArgs e) {
  1143.             SelectTreeView();
  1144.             this.xmlTreeView1.Copy();
  1145.         }
  1146.         private void toolStripButtonPaste_Click(object sender, EventArgs e) {
  1147.             SelectTreeView();
  1148.             this.xmlTreeView1.Paste(InsertPosition.Child);
  1149.             UpdateMenuState();
  1150.         }
  1151.         private void toolStripButtonDelete_Click(object sender, EventArgs e) {
  1152.             SelectTreeView();
  1153.             this.xmlTreeView1.CancelEdit();
  1154.             this.xmlTreeView1.Delete();
  1155.             UpdateMenuState();
  1156.         }
  1157.         private void toolStripButtonNudgeUp_Click(object sender, EventArgs e) {
  1158.             this.upToolStripMenuItem_Click(sender, e);
  1159.         }
  1160.         private void toolStripButtonNudgeDown_Click(object sender, EventArgs e) {
  1161.             this.downToolStripMenuItem_Click(sender, e);
  1162.         }
  1163.         private void toolStripButtonNudgeLeft_Click(object sender, EventArgs e) {
  1164.             this.leftToolStripMenuItem_Click(sender, e);
  1165.         }
  1166.         private void toolStripButtonNudgeRight_Click(object sender, EventArgs e) {
  1167.             this.rightToolStripMenuItem_Click(sender, e);
  1168.         }
  1169.         // Insert Menu Items.
  1170.         private void elementAfterToolStripMenuItem_Click(object sender, EventArgs e) {
  1171.             SelectTreeView();
  1172.             if (this.xmlTreeView1.Commit())
  1173.                 this.xmlTreeView1.InsertNode(InsertPosition.After, XmlNodeType.Element);
  1174.         }
  1175.         private void elementBeforeToolStripMenuItem_Click(object sender, EventArgs e) {
  1176.             SelectTreeView();
  1177.             if (this.xmlTreeView1.Commit())
  1178.                 this.xmlTreeView1.InsertNode(InsertPosition.Before, XmlNodeType.Element);
  1179.         }
  1180.         private void elementChildToolStripMenuItem_Click(object sender, EventArgs e) {
  1181.             SelectTreeView();
  1182.             if (this.xmlTreeView1.Commit())
  1183.                 this.xmlTreeView1.InsertNode(InsertPosition.Child, XmlNodeType.Element);
  1184.         }
  1185.         private void attributeBeforeToolStripMenuItem_Click(object sender, EventArgs e) {
  1186.             SelectTreeView();
  1187.             if (this.xmlTreeView1.Commit())
  1188.                 this.xmlTreeView1.InsertNode(InsertPosition.Before, XmlNodeType.Attribute);
  1189.         }
  1190.         private void attributeAfterToolStripMenuItem_Click(object sender, EventArgs e) {
  1191.             SelectTreeView();
  1192.             if (this.xmlTreeView1.Commit())
  1193.                 this.xmlTreeView1.InsertNode(InsertPosition.After, XmlNodeType.Attribute);
  1194.         }
  1195.         private void attributeChildToolStripMenuItem_Click(object sender, EventArgs e) {
  1196.             SelectTreeView();
  1197.             if (this.xmlTreeView1.Commit())
  1198.                 this.xmlTreeView1.InsertNode(InsertPosition.Child, XmlNodeType.Attribute);
  1199.         }
  1200.         private void textBeforeToolStripMenuItem_Click(object sender, EventArgs e) {
  1201.             SelectTreeView();
  1202.             if (this.xmlTreeView1.Commit())
  1203.                 this.xmlTreeView1.InsertNode(InsertPosition.Before, XmlNodeType.Text);
  1204.         }
  1205.         private void textAfterToolStripMenuItem_Click(object sender, EventArgs e) {
  1206.             SelectTreeView();
  1207.             if (this.xmlTreeView1.Commit())
  1208.                 this.xmlTreeView1.InsertNode(InsertPosition.After, XmlNodeType.Text);
  1209.         }
  1210.         private void textChildToolStripMenuItem_Click(object sender, EventArgs e) {
  1211.             SelectTreeView();
  1212.             if (this.xmlTreeView1.Commit())
  1213.                 this.xmlTreeView1.InsertNode(InsertPosition.Child, XmlNodeType.Text);
  1214.         }
  1215.         private void commentBeforeToolStripMenuItem_Click(object sender, EventArgs e) {
  1216.             SelectTreeView();
  1217.             if (this.xmlTreeView1.Commit())
  1218.                 this.xmlTreeView1.InsertNode(InsertPosition.Before, XmlNodeType.Comment);
  1219.         }
  1220.         private void commentAfterToolStripMenuItem_Click(object sender, EventArgs e) {
  1221.             SelectTreeView();
  1222.             if (this.xmlTreeView1.Commit())
  1223.                 this.xmlTreeView1.InsertNode(InsertPosition.After, XmlNodeType.Comment);
  1224.         }
  1225.         private void commentChildToolStripMenuItem_Click(object sender, EventArgs e) {
  1226.             SelectTreeView();
  1227.             if (this.xmlTreeView1.Commit())
  1228.                 this.xmlTreeView1.InsertNode(InsertPosition.Child, XmlNodeType.Comment);
  1229.         }
  1230.         private void cdataBeforeToolStripMenuItem_Click(object sender, EventArgs e) {
  1231.             SelectTreeView();
  1232.             if (this.xmlTreeView1.Commit())
  1233.                 this.xmlTreeView1.InsertNode(InsertPosition.Before, XmlNodeType.CDATA);
  1234.         }
  1235.         private void cdataAfterToolStripMenuItem_Click(object sender, EventArgs e) {
  1236.             SelectTreeView();
  1237.             if (this.xmlTreeView1.Commit())
  1238.                 this.xmlTreeView1.InsertNode(InsertPosition.After, XmlNodeType.CDATA);
  1239.         }
  1240.         private void cdataChildToolStripMenuItem_Click(object sender, EventArgs e) {
  1241.             SelectTreeView();
  1242.             if (this.xmlTreeView1.Commit())
  1243.                 this.xmlTreeView1.InsertNode(InsertPosition.Child, XmlNodeType.CDATA);
  1244.         }
  1245.         private void PIBeforeToolStripMenuItem_Click(object sender, EventArgs e) {
  1246.             SelectTreeView();
  1247.             if (this.xmlTreeView1.Commit())
  1248.                 this.xmlTreeView1.InsertNode(InsertPosition.Before, XmlNodeType.ProcessingInstruction);
  1249.         }
  1250.         private void PIAfterToolStripMenuItem_Click(object sender, EventArgs e) {
  1251.             SelectTreeView();
  1252.             if (this.xmlTreeView1.Commit())
  1253.                 this.xmlTreeView1.InsertNode(InsertPosition.After, XmlNodeType.ProcessingInstruction);
  1254.         }
  1255.         private void PIChildToolStripMenuItem_Click(object sender, EventArgs e) {
  1256.             SelectTreeView();
  1257.             if (this.xmlTreeView1.Commit())
  1258.                 this.xmlTreeView1.InsertNode(InsertPosition.Child, XmlNodeType.ProcessingInstruction);
  1259.         }
  1260.         void Launch(string exeFileName, string args) {
  1261.             ProcessStartInfo info = new ProcessStartInfo();
  1262.             info.FileName = exeFileName;
  1263.             info.Arguments = "/offset " + args;
  1264.             Process p = new Process();
  1265.             p.StartInfo = info;
  1266.             if (!p.Start()) {
  1267.                 MessageBox.Show(this, string.Format(SR.ErrorCreatingProcessPrompt, exeFileName), SR.LaunchErrorPrompt, MessageBoxButtons.OK, MessageBoxIcon.Error);
  1268.             }            
  1269.         }
  1270.         private void newWindowToolStripMenuItem_Click(object sender, EventArgs e){
  1271.             this.SaveIfDirty(true);
  1272.             this.OpenNewWindow(this.model.FileName);
  1273.         }
  1274.         private void schemasToolStripMenuItem_Click(object sender, EventArgs e) {
  1275.             FormSchemas frm = new FormSchemas();
  1276.             frm.Site = this;
  1277.             if (frm.ShowDialog(this) == DialogResult.OK) {
  1278.                 OnModelChanged();
  1279.             }
  1280.         }
  1281.         private void nextErrorToolStripMenuItem_Click(object sender, EventArgs e) {
  1282.             this.taskList.NavigateNextError();
  1283.         }
  1284.         private void compareXMLFilesToolStripMenuItem_Click(object sender, EventArgs e) {
  1285.             SelectTreeView();
  1286.             OpenFileDialog ofd = new OpenFileDialog();
  1287.             ofd.Filter = SR.SaveAsFilter;
  1288.             if (ofd.ShowDialog(this) == DialogResult.OK) {
  1289.                 string secondFile = ofd.FileName;
  1290.                 try {
  1291.                     DoCompare(secondFile);
  1292.                 } catch (Exception ex) {
  1293.                     MessageBox.Show(this, ex.Message, SR.XmlDiffErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
  1294.                 }
  1295.             }
  1296.         }
  1297.         /// <summary>
  1298.         /// The html header used by XmlNotepad.
  1299.         /// </summary>
  1300.         /// <param name="sourceXmlFile">name of baseline xml data</param>
  1301.         /// <param name="changedXmlFile">name of file being compared</param>
  1302.         /// <param name="resultHtml">Output file</param>
  1303.         private void SideBySideXmlNotepadHeader(
  1304.             string sourceXmlFile,
  1305.             string changedXmlFile,
  1306.             TextWriter resultHtml) {
  1307.             // this initializes the html
  1308.             resultHtml.WriteLine(SR.XmlDiffHeader);
  1309.             resultHtml.WriteLine(string.Format(SR.XmlDiffBody,
  1310.                     System.IO.Path.GetDirectoryName(sourceXmlFile),
  1311.                     System.IO.Path.GetFileName(sourceXmlFile),
  1312.                     System.IO.Path.GetDirectoryName(changedXmlFile),
  1313.                     System.IO.Path.GetFileName(changedXmlFile)
  1314.             ));
  1315.         }
  1316.         void CleanupTempFiles() {
  1317.             try {
  1318.                 this.tempFiles.Delete();
  1319.             } catch {
  1320.             }
  1321.         }
  1322.         private void DoCompare(string changed) {
  1323.             CleanupTempFiles();
  1324.             XmlDocument original = this.model.Document;
  1325.             XmlDocument doc = new XmlDocument();
  1326.             XmlReaderSettings settings = model.GetReaderSettings();
  1327.             using (XmlReader reader = XmlReader.Create(changed, settings)) {
  1328.                 doc.Load(reader);
  1329.             }
  1330.             string startupPath = Application.StartupPath;
  1331.             //output diff file.
  1332.             string diffFile = Path.Combine(Path.GetTempPath(),
  1333.                 Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".xml");
  1334.             this.tempFiles.AddFile(diffFile, false);
  1335.             bool isEqual = false;
  1336.             XmlTextWriter diffWriter = new XmlTextWriter(diffFile, Encoding.UTF8);
  1337.             diffWriter.Formatting = Formatting.Indented;
  1338.             using (diffWriter) {
  1339.                 XmlDiff diff = new XmlDiff();
  1340.                 isEqual = diff.Compare(original, doc, diffWriter);
  1341.                 diff.Options = XmlDiffOptions.None;
  1342.             }
  1343.             if (isEqual) {
  1344.                 //This means the files were identical for given options.
  1345.                 MessageBox.Show(this, SR.FilesAreIdenticalPrompt, SR.FilesAreIdenticalCaption,
  1346.                     MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  1347.                 return; 
  1348.             }
  1349.             string tempFile = Path.Combine(Path.GetTempPath(),
  1350.                 Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".htm");
  1351.             tempFiles.AddFile(tempFile, false);
  1352.             
  1353.             using (XmlReader diffGram = XmlReader.Create(diffFile, settings)) {
  1354.                 XmlDiffView diffView = new XmlDiffView();
  1355.                 diffView.Load(new XmlNodeReader(original), diffGram);
  1356.                 using (TextWriter htmlWriter = new StreamWriter(tempFile)) {
  1357.                     SideBySideXmlNotepadHeader(this.model.FileName, changed, htmlWriter);
  1358.                     diffView.GetHtml(htmlWriter);
  1359.                 }
  1360.             }
  1361.             Uri uri = new Uri(tempFile);
  1362.             WebBrowserForm browserForm = new WebBrowserForm(uri, "XmlDiff");
  1363.             browserForm.Show();
  1364.         }        
  1365.         string ApplicationPath {
  1366.             get {
  1367.                 string path = Application.ExecutablePath;
  1368.                 if (path.EndsWith("vstesthost.exe", StringComparison.CurrentCultureIgnoreCase)) {
  1369.                     // must be running UnitTests
  1370.                     Uri baseUri = new Uri(this.GetType().Assembly.Location);
  1371.                     Uri resolved = new Uri(baseUri, @"......ApplicationbindebugXmlNotepad.exe");
  1372.                     path = resolved.LocalPath;
  1373.                 }
  1374.                 return path;
  1375.             }
  1376.         }
  1377.         public virtual void OpenNewWindow(string path){
  1378.             if (!string.IsNullOrEmpty(path)) {
  1379.                 Uri uri = new Uri(path);
  1380.                 if (uri.IsFile) {
  1381.                     path = uri.LocalPath;
  1382.                     if (!File.Exists(path)) {
  1383.                         DialogResult dr = MessageBox.Show(
  1384.                             String.Format(SR.CreateFile, path), SR.CreateNodeFileCaption,
  1385.                             MessageBoxButtons.OKCancel);
  1386.                         if (dr.Equals(DialogResult.OK)) {
  1387.                             try {
  1388.                                 XmlDocument include = new XmlDocument();
  1389.                                 include.InnerXml = "<root/>";
  1390.                                 include.Save(path);
  1391.                             } catch (Exception e) {
  1392.                                 MessageBox.Show(this, e.Message, SR.SaveErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
  1393.                                 return;
  1394.                             }
  1395.                         } else {
  1396.                             return;
  1397.                         }
  1398.                     }
  1399.                 }
  1400.             }
  1401.             Launch(this.ApplicationPath, """ + path + """);
  1402.         }
  1403.         private void GotoDefinition() {
  1404.             SelectTreeView();
  1405.             this.SaveIfDirty(true);
  1406.             XmlTreeNode node = xmlTreeView1.SelectedNode;
  1407.             if (node == null) return;
  1408.             string ipath = node.GetDefinition();
  1409.             if (!string.IsNullOrEmpty(ipath)) {
  1410.                 OpenNewWindow(ipath);
  1411.             }
  1412.             
  1413.         }
  1414.         private void gotoDefinitionToolStripMenuItem_Click(object sender, EventArgs e) {
  1415.             this.GotoDefinition();
  1416.         }
  1417.         private void ctxGotoDefinitionToolStripMenuItem_Click(object sender, EventArgs e) {
  1418.             this.GotoDefinition();
  1419.         }
  1420.         private void expandXIncludesToolStripMenuItem_Click(object sender, EventArgs e) {
  1421.             SelectTreeView();
  1422.             this.model.ExpandIncludes();
  1423.             includesExpanded = true;
  1424.         }
  1425.         private void exportErrorsToolStripMenuItem_Click(object sender, EventArgs e) {
  1426.             SaveAsErrors();
  1427.         }
  1428.         void SaveAsErrors() {
  1429.             SaveFileDialog sd = new SaveFileDialog();
  1430.             sd.Filter = SR.SaveAsFilter;
  1431.             sd.Title = SR.SaveErrorsCaption;
  1432.             if (sd.ShowDialog(this) == DialogResult.OK) {
  1433.                 string fname = sd.FileName;
  1434.                 if (CheckReadOnly(fname)) {
  1435.                     SaveErrors(fname);
  1436.                 }
  1437.             }
  1438.         }
  1439.         private void changeToElementToolStripMenuItem1_Click(object sender, EventArgs e) {
  1440.             this.xmlTreeView1.ChangeTo(XmlNodeType.Element);
  1441.         }
  1442.         private void changeToAttributeToolStripMenuItem1_Click(object sender, EventArgs e) {
  1443.             this.xmlTreeView1.ChangeTo(XmlNodeType.Attribute);
  1444.         }
  1445.         private void changeToTextToolStripMenuItem1_Click(object sender, EventArgs e) {
  1446.             this.xmlTreeView1.ChangeTo(XmlNodeType.Text);
  1447.         }
  1448.         private void changeToCDATAToolStripMenuItem1_Click(object sender, EventArgs e) {
  1449.             this.xmlTreeView1.ChangeTo(XmlNodeType.CDATA);
  1450.         }
  1451.         private void changeToCommentToolStripMenuItem1_Click(object sender, EventArgs e) {
  1452.             this.xmlTreeView1.ChangeTo(XmlNodeType.Comment);
  1453.         }
  1454.         private void changeToProcessingInstructionToolStripMenuItem_Click(object sender, EventArgs e) {
  1455.             this.xmlTreeView1.ChangeTo(XmlNodeType.ProcessingInstruction);
  1456.         }
  1457.         private void changeToElementContextMenuItem_Click(object sender, EventArgs e) {
  1458.             this.xmlTreeView1.ChangeTo(XmlNodeType.Element);
  1459.         }
  1460.         private void changeToAttributeContextMenuItem_Click(object sender, EventArgs e) {
  1461.             this.xmlTreeView1.ChangeTo(XmlNodeType.Attribute);
  1462.         }
  1463.         private void changeToTextToolStripMenuItem_Click(object sender, EventArgs e) {
  1464.             this.xmlTreeView1.ChangeTo(XmlNodeType.Text);
  1465.         }
  1466.         private void changeToCDATAContextMenuItem_Click(object sender, EventArgs e) {
  1467.             this.xmlTreeView1.ChangeTo(XmlNodeType.CDATA);
  1468.         }
  1469.         private void changeToCommentContextMenuItem_Click(object sender, EventArgs e) {
  1470.             this.xmlTreeView1.ChangeTo(XmlNodeType.Comment);
  1471.         }
  1472.         private void changeToProcessingInstructionContextMenuItem_Click(object sender, EventArgs e) {
  1473.             this.xmlTreeView1.ChangeTo(XmlNodeType.ProcessingInstruction);
  1474.         }
  1475.         private void incrementalSearchToolStripMenuItem_Click(object sender, EventArgs e) {
  1476.             this.xmlTreeView1.StartIncrementalSearch();
  1477.         }
  1478.         private void renameToolStripMenuItem1_Click(object sender, EventArgs e) {
  1479.             this.xmlTreeView1.BeginEditNodeName();
  1480.         }
  1481.         private void renameToolStripMenuItem_Click(object sender, EventArgs e) {
  1482.             this.xmlTreeView1.BeginEditNodeName();
  1483.         }
  1484.         private void insertToolStripMenuItem1_Click(object sender, EventArgs e) {
  1485.             this.RepeatSelectedNode();
  1486.         }
  1487.         private void deleteToolStripMenuItem1_Click(object sender, EventArgs e) {
  1488.             this.DeleteSelectedNode();
  1489.         }
  1490.         private void duplicateToolStripMenuItem1_Click(object sender, EventArgs e) {
  1491.             this.DuplicateSelectedNode();
  1492.         }
  1493.     }
  1494. }