FormMain.cs
上传用户:hbhltzc
上传日期:2022-06-04
资源大小:1925k
文件大小:166k
源码类别:
xml/soap/webservice
开发平台:
Visual C++
- resources.ApplyResources(this.textAfterToolStripMenuItem, "textAfterToolStripMenuItem");
- this.textAfterToolStripMenuItem.Name = "textAfterToolStripMenuItem";
- this.textAfterToolStripMenuItem.Click += new System.EventHandler(this.textAfterToolStripMenuItem_Click);
- //
- // textChildToolStripMenuItem
- //
- resources.ApplyResources(this.textChildToolStripMenuItem, "textChildToolStripMenuItem");
- this.textChildToolStripMenuItem.Name = "textChildToolStripMenuItem";
- this.textChildToolStripMenuItem.Click += new System.EventHandler(this.textChildToolStripMenuItem_Click);
- //
- // commentToolStripMenuItem
- //
- resources.ApplyResources(this.commentToolStripMenuItem, "commentToolStripMenuItem");
- this.commentToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this.commentBeforeToolStripMenuItem,
- this.commentAfterToolStripMenuItem,
- this.commentChildToolStripMenuItem});
- this.commentToolStripMenuItem.Name = "commentToolStripMenuItem";
- //
- // commentBeforeToolStripMenuItem
- //
- resources.ApplyResources(this.commentBeforeToolStripMenuItem, "commentBeforeToolStripMenuItem");
- this.commentBeforeToolStripMenuItem.Name = "commentBeforeToolStripMenuItem";
- this.commentBeforeToolStripMenuItem.Click += new System.EventHandler(this.commentBeforeToolStripMenuItem_Click);
- //
- // commentAfterToolStripMenuItem
- //
- resources.ApplyResources(this.commentAfterToolStripMenuItem, "commentAfterToolStripMenuItem");
- this.commentAfterToolStripMenuItem.Name = "commentAfterToolStripMenuItem";
- this.commentAfterToolStripMenuItem.Click += new System.EventHandler(this.commentAfterToolStripMenuItem_Click);
- //
- // commentChildToolStripMenuItem
- //
- resources.ApplyResources(this.commentChildToolStripMenuItem, "commentChildToolStripMenuItem");
- this.commentChildToolStripMenuItem.Name = "commentChildToolStripMenuItem";
- this.commentChildToolStripMenuItem.Click += new System.EventHandler(this.commentChildToolStripMenuItem_Click);
- //
- // CDATAToolStripMenuItem
- //
- this.CDATAToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this.cdataBeforeToolStripMenuItem,
- this.cdataAfterToolStripMenuItem,
- this.cdataChildToolStripMenuItem});
- this.CDATAToolStripMenuItem.Name = "CDATAToolStripMenuItem";
- resources.ApplyResources(this.CDATAToolStripMenuItem, "CDATAToolStripMenuItem");
- //
- // cdataBeforeToolStripMenuItem
- //
- resources.ApplyResources(this.cdataBeforeToolStripMenuItem, "cdataBeforeToolStripMenuItem");
- this.cdataBeforeToolStripMenuItem.Name = "cdataBeforeToolStripMenuItem";
- this.cdataBeforeToolStripMenuItem.Click += new System.EventHandler(this.cdataBeforeToolStripMenuItem_Click);
- //
- // cdataAfterToolStripMenuItem
- //
- resources.ApplyResources(this.cdataAfterToolStripMenuItem, "cdataAfterToolStripMenuItem");
- this.cdataAfterToolStripMenuItem.Name = "cdataAfterToolStripMenuItem";
- this.cdataAfterToolStripMenuItem.Click += new System.EventHandler(this.cdataAfterToolStripMenuItem_Click);
- //
- // cdataChildToolStripMenuItem
- //
- resources.ApplyResources(this.cdataChildToolStripMenuItem, "cdataChildToolStripMenuItem");
- this.cdataChildToolStripMenuItem.Name = "cdataChildToolStripMenuItem";
- this.cdataChildToolStripMenuItem.Click += new System.EventHandler(this.cdataChildToolStripMenuItem_Click);
- //
- // PIToolStripMenuItem
- //
- this.PIToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this.PIBeforeToolStripMenuItem,
- this.PIAfterToolStripMenuItem,
- this.PIChildToolStripMenuItem});
- this.PIToolStripMenuItem.Name = "PIToolStripMenuItem";
- resources.ApplyResources(this.PIToolStripMenuItem, "PIToolStripMenuItem");
- //
- // PIBeforeToolStripMenuItem
- //
- resources.ApplyResources(this.PIBeforeToolStripMenuItem, "PIBeforeToolStripMenuItem");
- this.PIBeforeToolStripMenuItem.Name = "PIBeforeToolStripMenuItem";
- this.PIBeforeToolStripMenuItem.Click += new System.EventHandler(this.PIBeforeToolStripMenuItem_Click);
- //
- // PIAfterToolStripMenuItem
- //
- resources.ApplyResources(this.PIAfterToolStripMenuItem, "PIAfterToolStripMenuItem");
- this.PIAfterToolStripMenuItem.Name = "PIAfterToolStripMenuItem";
- this.PIAfterToolStripMenuItem.Click += new System.EventHandler(this.PIAfterToolStripMenuItem_Click);
- //
- // PIChildToolStripMenuItem
- //
- resources.ApplyResources(this.PIChildToolStripMenuItem, "PIChildToolStripMenuItem");
- this.PIChildToolStripMenuItem.Name = "PIChildToolStripMenuItem";
- this.PIChildToolStripMenuItem.Click += new System.EventHandler(this.PIChildToolStripMenuItem_Click);
- //
- // windowToolStripMenuItem
- //
- resources.ApplyResources(this.windowToolStripMenuItem, "windowToolStripMenuItem");
- this.windowToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this.newWindowToolStripMenuItem});
- this.windowToolStripMenuItem.Name = "windowToolStripMenuItem";
- //
- // newWindowToolStripMenuItem
- //
- resources.ApplyResources(this.newWindowToolStripMenuItem, "newWindowToolStripMenuItem");
- this.newWindowToolStripMenuItem.Name = "newWindowToolStripMenuItem";
- this.newWindowToolStripMenuItem.Click += new System.EventHandler(this.newWindowToolStripMenuItem_Click);
- //
- // helpToolStripMenuItem
- //
- resources.ApplyResources(this.helpToolStripMenuItem, "helpToolStripMenuItem");
- this.helpToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this.contentsToolStripMenuItem,
- this.indexToolStripMenuItem,
- this.toolStripMenuItem10,
- this.aboutXMLNotepadToolStripMenuItem});
- this.helpToolStripMenuItem.Name = "helpToolStripMenuItem";
- //
- // contentsToolStripMenuItem
- //
- resources.ApplyResources(this.contentsToolStripMenuItem, "contentsToolStripMenuItem");
- this.contentsToolStripMenuItem.Name = "contentsToolStripMenuItem";
- this.contentsToolStripMenuItem.Click += new System.EventHandler(this.contentsToolStripMenuItem_Click);
- //
- // indexToolStripMenuItem
- //
- resources.ApplyResources(this.indexToolStripMenuItem, "indexToolStripMenuItem");
- this.indexToolStripMenuItem.Name = "indexToolStripMenuItem";
- this.indexToolStripMenuItem.Click += new System.EventHandler(this.indexToolStripMenuItem_Click);
- //
- // toolStripMenuItem10
- //
- this.toolStripMenuItem10.Name = "toolStripMenuItem10";
- resources.ApplyResources(this.toolStripMenuItem10, "toolStripMenuItem10");
- //
- // aboutXMLNotepadToolStripMenuItem
- //
- resources.ApplyResources(this.aboutXMLNotepadToolStripMenuItem, "aboutXMLNotepadToolStripMenuItem");
- this.aboutXMLNotepadToolStripMenuItem.Name = "aboutXMLNotepadToolStripMenuItem";
- this.aboutXMLNotepadToolStripMenuItem.Click += new System.EventHandler(this.aboutXMLNotepadToolStripMenuItem_Click);
- //
- // toolStripMenuItemUpdate
- //
- resources.ApplyResources(this.toolStripMenuItemUpdate, "toolStripMenuItemUpdate");
- this.toolStripMenuItemUpdate.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
- this.toolStripMenuItemUpdate.BackColor = System.Drawing.Color.MediumAquamarine;
- this.toolStripMenuItemUpdate.Name = "toolStripMenuItemUpdate";
- //
- // toolStrip1
- //
- this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this.toolStripButtonNew,
- this.toolStripButtonOpen,
- this.toolStripButtonSave,
- this.toolStripButtonUndo,
- this.toolStripButtonRedo,
- this.toolStripButtonCut,
- this.toolStripButtonCopy,
- this.toolStripButtonPaste,
- this.toolStripButtonDelete,
- this.toolStripSeparator4,
- this.toolStripButtonNudgeUp,
- this.toolStripButtonNudgeDown,
- this.toolStripButtonNudgeLeft,
- this.toolStripButtonNudgeRight,
- this.toolStripSeparator1});
- resources.ApplyResources(this.toolStrip1, "toolStrip1");
- this.toolStrip1.Name = "toolStrip1";
- //
- // toolStripButtonNew
- //
- resources.ApplyResources(this.toolStripButtonNew, "toolStripButtonNew");
- this.toolStripButtonNew.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
- this.toolStripButtonNew.Name = "toolStripButtonNew";
- this.toolStripButtonNew.Click += new System.EventHandler(this.toolStripButtonNew_Click);
- //
- // toolStripButtonOpen
- //
- resources.ApplyResources(this.toolStripButtonOpen, "toolStripButtonOpen");
- this.toolStripButtonOpen.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
- this.toolStripButtonOpen.Name = "toolStripButtonOpen";
- this.toolStripButtonOpen.Click += new System.EventHandler(this.toolStripButtonOpen_Click);
- //
- // toolStripButtonSave
- //
- resources.ApplyResources(this.toolStripButtonSave, "toolStripButtonSave");
- this.toolStripButtonSave.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
- this.toolStripButtonSave.Name = "toolStripButtonSave";
- this.toolStripButtonSave.Click += new System.EventHandler(this.toolStripButtonSave_Click);
- //
- // toolStripButtonUndo
- //
- resources.ApplyResources(this.toolStripButtonUndo, "toolStripButtonUndo");
- this.toolStripButtonUndo.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
- this.toolStripButtonUndo.Name = "toolStripButtonUndo";
- this.toolStripButtonUndo.Click += new System.EventHandler(this.toolStripButtonUndo_Click);
- //
- // toolStripButtonRedo
- //
- resources.ApplyResources(this.toolStripButtonRedo, "toolStripButtonRedo");
- this.toolStripButtonRedo.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
- this.toolStripButtonRedo.Name = "toolStripButtonRedo";
- this.toolStripButtonRedo.Click += new System.EventHandler(this.toolStripButtonRedo_Click);
- //
- // toolStripButtonCut
- //
- resources.ApplyResources(this.toolStripButtonCut, "toolStripButtonCut");
- this.toolStripButtonCut.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
- this.toolStripButtonCut.Name = "toolStripButtonCut";
- this.toolStripButtonCut.Click += new System.EventHandler(this.toolStripButtonCut_Click);
- //
- // toolStripButtonCopy
- //
- resources.ApplyResources(this.toolStripButtonCopy, "toolStripButtonCopy");
- this.toolStripButtonCopy.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
- this.toolStripButtonCopy.Name = "toolStripButtonCopy";
- this.toolStripButtonCopy.Click += new System.EventHandler(this.toolStripButtonCopy_Click);
- //
- // toolStripButtonPaste
- //
- resources.ApplyResources(this.toolStripButtonPaste, "toolStripButtonPaste");
- this.toolStripButtonPaste.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
- this.toolStripButtonPaste.Name = "toolStripButtonPaste";
- this.toolStripButtonPaste.Click += new System.EventHandler(this.toolStripButtonPaste_Click);
- //
- // toolStripButtonDelete
- //
- resources.ApplyResources(this.toolStripButtonDelete, "toolStripButtonDelete");
- this.toolStripButtonDelete.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
- this.toolStripButtonDelete.Name = "toolStripButtonDelete";
- this.toolStripButtonDelete.Click += new System.EventHandler(this.toolStripButtonDelete_Click);
- //
- // toolStripSeparator4
- //
- this.toolStripSeparator4.Name = "toolStripSeparator4";
- resources.ApplyResources(this.toolStripSeparator4, "toolStripSeparator4");
- //
- // toolStripButtonNudgeUp
- //
- resources.ApplyResources(this.toolStripButtonNudgeUp, "toolStripButtonNudgeUp");
- this.toolStripButtonNudgeUp.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
- this.toolStripButtonNudgeUp.Name = "toolStripButtonNudgeUp";
- this.toolStripButtonNudgeUp.Click += new System.EventHandler(this.toolStripButtonNudgeUp_Click);
- //
- // toolStripButtonNudgeDown
- //
- resources.ApplyResources(this.toolStripButtonNudgeDown, "toolStripButtonNudgeDown");
- this.toolStripButtonNudgeDown.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
- this.toolStripButtonNudgeDown.Name = "toolStripButtonNudgeDown";
- this.toolStripButtonNudgeDown.Click += new System.EventHandler(this.toolStripButtonNudgeDown_Click);
- //
- // toolStripButtonNudgeLeft
- //
- resources.ApplyResources(this.toolStripButtonNudgeLeft, "toolStripButtonNudgeLeft");
- this.toolStripButtonNudgeLeft.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
- this.toolStripButtonNudgeLeft.Name = "toolStripButtonNudgeLeft";
- this.toolStripButtonNudgeLeft.Click += new System.EventHandler(this.toolStripButtonNudgeLeft_Click);
- //
- // toolStripButtonNudgeRight
- //
- resources.ApplyResources(this.toolStripButtonNudgeRight, "toolStripButtonNudgeRight");
- this.toolStripButtonNudgeRight.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
- this.toolStripButtonNudgeRight.Name = "toolStripButtonNudgeRight";
- this.toolStripButtonNudgeRight.Click += new System.EventHandler(this.toolStripButtonNudgeRight_Click);
- //
- // toolStripSeparator1
- //
- this.toolStripSeparator1.Name = "toolStripSeparator1";
- resources.ApplyResources(this.toolStripSeparator1, "toolStripSeparator1");
- //
- // tabPageTaskList
- //
- resources.ApplyResources(this.tabPageTaskList, "tabPageTaskList");
- this.tabPageTaskList.Name = "tabPageTaskList";
- //
- // tabPageDynamicHelp
- //
- resources.ApplyResources(this.tabPageDynamicHelp, "tabPageDynamicHelp");
- this.tabPageDynamicHelp.Name = "tabPageDynamicHelp";
- //
- // resizer
- //
- resources.ApplyResources(this.resizer, "resizer");
- this.resizer.Border3DStyle = System.Windows.Forms.Border3DStyle.Raised;
- this.resizer.Name = "resizer";
- this.resizer.Pane1 = null;
- this.resizer.Pane2 = null;
- this.resizer.PaneWidth = 5;
- this.resizer.Vertical = false;
- //
- // taskList
- //
- resources.ApplyResources(this.taskList, "taskList");
- this.taskList.Name = "taskList";
- //
- // dynamicHelpViewer
- //
- resources.ApplyResources(this.dynamicHelpViewer, "dynamicHelpViewer");
- this.dynamicHelpViewer.DefaultStylesheetResource = "XmlNotepad.DefaultSS.xslt";
- this.dynamicHelpViewer.Name = "dynamicHelpViewer";
- this.dynamicHelpViewer.ShowFileStrip = true;
- //
- // xsltViewer
- //
- resources.ApplyResources(this.xsltViewer, "xsltViewer");
- this.xsltViewer.DefaultStylesheetResource = "XmlNotepad.DefaultSS.xslt";
- this.xsltViewer.Name = "xsltViewer";
- this.xsltViewer.ShowFileStrip = true;
- //
- // tabControlViews
- //
- resources.ApplyResources(this.tabControlViews, "tabControlViews");
- this.tabControlViews.Controls.Add(this.tabPageTreeView);
- this.tabControlViews.Controls.Add(this.tabPageHtmlView);
- this.tabControlViews.Name = "tabControlViews";
- this.tabControlViews.SelectedIndex = 0;
- this.tabControlViews.SelectedTab = this.tabPageTreeView;
- this.tabControlViews.Selected += new XmlNotepad.NoBorderTabControlEventHandler(this.TabControlViews_Selected);
- //
- // tabPageTreeView
- //
- resources.ApplyResources(this.tabPageTreeView, "tabPageTreeView");
- this.tabPageTreeView.Controls.Add(this.xmlTreeView1);
- this.tabPageTreeView.Name = "tabPageTreeView";
- //
- // tabPageHtmlView
- //
- resources.ApplyResources(this.tabPageHtmlView, "tabPageHtmlView");
- this.tabPageHtmlView.Controls.Add(this.xsltViewer);
- this.tabPageHtmlView.Name = "tabPageHtmlView";
- //
- // comboBoxLocation
- //
- resources.ApplyResources(this.comboBoxLocation, "comboBoxLocation");
- this.comboBoxLocation.FormattingEnabled = true;
- this.comboBoxLocation.Name = "comboBoxLocation";
- //
- // FormMain
- //
- resources.ApplyResources(this, "$this");
- this.Controls.Add(this.comboBoxLocation);
- this.Controls.Add(this.tabControlViews);
- this.Controls.Add(this.toolStrip1);
- this.Controls.Add(this.statusBar1);
- this.Controls.Add(this.resizer);
- this.Controls.Add(this.menuStrip1);
- this.MainMenuStrip = this.menuStrip1;
- this.Name = "FormMain";
- ((System.ComponentModel.ISupportInitialize)(this.statusBarPanelMessage)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.statusBarPanelBusy)).EndInit();
- this.contextMenu1.ResumeLayout(false);
- this.menuStrip1.ResumeLayout(false);
- this.menuStrip1.PerformLayout();
- this.toolStrip1.ResumeLayout(false);
- this.toolStrip1.PerformLayout();
- this.tabControlViews.ResumeLayout(false);
- this.tabPageTreeView.ResumeLayout(false);
- this.tabPageHtmlView.ResumeLayout(false);
- this.ResumeLayout(false);
- this.PerformLayout();
- }
- protected virtual void TabControlViews_Selected(object sender, NoBorderTabControlEventArgs e) {
- if (e.TabPage == this.tabPageHtmlView) {
- this.DisplayXsltResults();
- }
- }
- #endregion
- void EnableFileMenu(){
- bool hasFile = (model.FileName != null);
- this.toolStripButtonSave.Enabled = this.saveToolStripMenuItem.Enabled = true;
- this.reloadToolStripMenuItem.Enabled = hasFile;
- this.saveAsToolStripMenuItem.Enabled = true;
- }
- public virtual void DisplayXsltResults() {
- this.xsltViewer.DisplayXsltResults();
- }
- void SelectTreeView() {
- if (tabControlViews.SelectedIndex != 0) {
- tabControlViews.SelectedIndex = 0;
- }
- if (!xmlTreeView1.ContainsFocus) {
- xmlTreeView1.Focus();
- }
- }
- public virtual void New(){
- SelectTreeView();
- if (!SaveIfDirty(true))
- return;
- model.Clear();
- includesExpanded = false;
- EnableFileMenu();
- this.settings["FileName"] = new Uri("/", UriKind.RelativeOrAbsolute);
- UpdateMenuState();
- }
- protected virtual IIntellisenseProvider CreateIntellisenseProvider(XmlCache model, ISite site) {
- return new XmlIntellisenseProvider(this.model, site);
- }
- protected override object GetService(Type service) {
- if (service == typeof(UndoManager)){
- return this.undoManager;
- } else if (service == typeof(SchemaCache)) {
- return this.model.SchemaCache;
- } else if (service == typeof(TreeView)) {
- XmlTreeView view = (XmlTreeView)GetService(typeof(XmlTreeView));
- return view.TreeView;
- } else if (service == typeof(XmlTreeView)) {
- if (this.xmlTreeView1 == null) {
- this.xmlTreeView1 = this.CreateTreeView();
- }
- return this.xmlTreeView1;
- } else if (service == typeof(XmlCache)) {
- if (null == this.model)
- {
- this.model = new XmlCache((IServiceProvider)this, (ISynchronizeInvoke)this);
- }
- return this.model;
- } else if (service == typeof(Settings)){
- return this.settings;
- } else if (service == typeof(IIntellisenseProvider)) {
- if (this.ip == null) this.ip = CreateIntellisenseProvider(this.model, this);
- return this.ip;
- } else if (service == typeof(HelpProvider)) {
- return this.helpProvider1;
- } else if (service == typeof(WebProxyService)) {
- if (this.proxyService == null)
- this.proxyService = new WebProxyService((IServiceProvider)this);
- return this.proxyService;
- } else if (service == typeof(UserSettings)) {
- return new UserSettings(this.settings);
- }
- return base.GetService (service);
- }
- public OpenFileDialog OpenFileDialog {
- get { return this.od; }
- }
- public virtual void Open() {
- SelectTreeView();
- if (!SaveIfDirty(true))
- return;
- if (od == null) od = new OpenFileDialog();
- if (model.FileName != null) {
- Uri uri = new Uri(model.FileName);
- if (uri.Scheme == "file"){
- od.FileName = model.FileName;
- }
- }
- string filter = SR.SaveAsFilter;
- od.Filter = filter;
- string[] parts = filter.Split('|');
- int index = -1;
- for (int i = 1, n = parts.Length; i < n; i += 2 ) {
- if (parts[i] == "*.*") {
- index = (i / 2)+1;
- break;
- }
- }
- od.FilterIndex = index;
- if (od.ShowDialog(this) == DialogResult.OK){
- Open(od.FileName);
- }
- }
- public virtual void ShowStatus(string msg) {
- this.statusBarPanelMessage.Text = msg;
- }
- public virtual void Open(string filename) {
- try {
- // Make sure you've called SaveIfDirty before calling this method.
- InternalOpen(filename);
- } catch (Exception e){
- if (MessageBox.Show(this,
- string.Format(SR.LoadErrorPrompt, filename, e.Message),
- SR.LoadErrorCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes) {
- OpenNotepad(filename);
- }
- }
- }
- private void InternalOpen(string filename) {
- includesExpanded = false;
- DateTime start = DateTime.Now;
- this.model.Load(filename);
- DateTime finish = DateTime.Now;
- TimeSpan diff = finish - start;
- string s = diff.ToString();
- this.settings["FileName"] = this.model.Location;
- this.UpdateCaption();
- ShowStatus(string.Format(SR.LoadedTimeStatus, s));
- EnableFileMenu();
- this.recentFiles.AddRecentFile(this.model.Location);
- SelectTreeView();
- }
- bool CheckXIncludes() {
- if (includesExpanded) {
- if (MessageBox.Show(this, SR.SaveExpandedIncludesPrompt, SR.SaveExpandedIncludesCaption,
- MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No) {
- return false;
- }
- includesExpanded = false;
- }
- return true;
- }
- public virtual bool SaveIfDirty(bool prompt) {
- if (model.Dirty){
- if (prompt){
- SelectTreeView();
- DialogResult rc = MessageBox.Show(this, SR.SaveChangesPrompt,
- SR.SaveChangesCaption, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation);
- if (rc == DialogResult.Cancel){
- return false;
- } else if (rc == DialogResult.Yes){
- return Save();
- }
- } else {
- return Save();
- }
- }
- return true;
- }
- public virtual bool Save() {
- this.xmlTreeView1.Commit();
- if (!CheckXIncludes()) return false;
- string fname = model.FileName;
- if (fname == null){
- SaveAs();
- } else {
- try {
- if (CheckReadOnly(fname)) {
- model.Save();
- ShowStatus(SR.SavedStatus);
- }
- } catch (Exception e){
- MessageBox.Show(this, e.Message, SR.SaveErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- return true;
- }
- public bool CheckReadOnly(string fname) {
- if (model.IsReadOnly(fname)) {
- SelectTreeView();
- if (MessageBox.Show(this, string.Format(SR.ReadOnly, fname),
- SR.ReadOnlyCaption, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation) == DialogResult.Yes) {
- model.MakeReadWrite(fname);
- return true;
- } else {
- return false;
- }
- }
- return true;
- }
- public virtual void Save(string newName) {
- this.xmlTreeView1.Commit();
- try {
- bool hasFile = (model.FileName != null);
- if (!hasFile && string.IsNullOrEmpty(newName)) {
- SaveAs();
- }
- if (CheckReadOnly(newName)) {
- model.Save(newName);
- UpdateCaption();
- ShowStatus(SR.SavedStatus);
- this.settings["FileName"] = model.Location;
- EnableFileMenu();
- }
- } catch (Exception e){
- MessageBox.Show(this, e.Message, SR.SaveErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- public virtual void SaveAs() {
- SelectTreeView();
- SaveFileDialog sd = new SaveFileDialog();
- if (model.IsFile) sd.FileName = model.FileName;
- sd.Filter = SR.SaveAsFilter;
- if (sd.ShowDialog(this) == DialogResult.OK){
- string fname = sd.FileName;
- if (CheckReadOnly(fname)) {
- Save(fname);
- }
- }
- }
- string caption = null;
- public string Caption {
- get {
- if (string.IsNullOrEmpty(caption))
- caption = SR.MainFormTitle;
- return caption; }
- set { caption = value; }
- }
- public virtual void UpdateCaption() {
- string caption = this.Caption + " - " + model.FileName;
- if (this.model.Dirty){
- caption += "*";
- }
- this.Text = caption;
- sourceToolStripMenuItem.Enabled = this.model.FileName != null;
- ShowStatus("");
- }
- void OnFileChanged(object sender, EventArgs e) {
- if (!prompting) OnFileChanged();
- }
- bool prompting = false;
- protected virtual void OnFileChanged() {
- prompting = true;
- try {
- if (this.WindowState == FormWindowState.Minimized) {
- this.WindowState = FormWindowState.Normal;
- }
- SelectTreeView();
- if (MessageBox.Show(this, SR.FileChagedOnDiskPrompt, SR.FileChagedOnDiskCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) {
- string location = this.model.Location.LocalPath;
- this.model.Clear();
- this.Open(location);
- }
- } finally {
- prompting = false;
- }
- }
- private void undoManager_StateChanged(object sender, EventArgs e) {
- this.ShowStatus("");
- this.undoToolStripMenuItem.Enabled = toolStripButtonUndo.Enabled = this.undoManager.CanUndo;
- this.redoToolStripMenuItem.Enabled = toolStripButtonRedo.Enabled = this.undoManager.CanRedo;
- Command cmd = this.undoManager.Peek();
- this.undoToolStripMenuItem.Text = this.undoLabel + " " + (cmd == null ? "" : cmd.Name);
- cmd = this.undoManager.Current;
- this.redoToolStripMenuItem.Text = this.redoLabel + " " + (cmd == null ? "" : cmd.Name);
- }
- public virtual string ConfigFile {
- get {
- string path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
- Debug.Assert(!string.IsNullOrEmpty(path));
- return path + @"MicrosoftXml NotepadXmlNotepad.settings";
- }
- }
- public virtual void LoadConfig() {
- string path = null;
- this.loading = true;
- if (this.args != null && this.args.Length > 0) {
- // When user passes arguments we skip the config file
- // This is for unit testing where we need consistent config!
- path = this.args[0];
- this.settings.FileName = this.ConfigFile;
- } else {
- if (File.Exists(this.ConfigFile)) {
- settings.Load(this.ConfigFile);
- Uri location = (Uri)this.settings["FileName"];
- // Load up the last file we were editing before - if it is local and still exists.
- if (location != null && location.OriginalString != "/" && location.IsFile && File.Exists(location.LocalPath)) {
- path = location.LocalPath;
- }
- }
- }
- this.loading = false;
- }
- public virtual void SaveConfig() {
- this.settings.StopWatchingFileChanges();
- Rectangle r = (this.WindowState == FormWindowState.Normal) ? this.Bounds : this.RestoreBounds;
- this.settings["WindowBounds"] = r;
- this.settings["Font"] = this.Font;
- this.settings["TaskListSize"] = this.tabControlLists.Height;
- this.settings["TreeViewSize"] = this.xmlTreeView1.ResizerPosition;
- this.settings["RecentFiles"] = this.recentFiles.ToArray();
- this.settings.Save(this.ConfigFile);
- }
- #region ISite implementation
- IComponent ISite.Component{
- get { return this; }
- }
- public static Type ResourceType { get { return typeof(SR); } }
- string ISite.Name {
- get { return this.Name; }
- set { this.Name = value; }
- }
- IContainer ISite.Container {
- get { return this.Container; }
- }
- bool ISite.DesignMode {
- get { return this.DesignMode;}
- }
- object IServiceProvider.GetService(Type serviceType) {
- return this.GetService(serviceType);
- }
- #endregion
- void OnModelChanged(object sender, ModelChangedEventArgs e) {
- if (e.ModelChangeType == ModelChangeType.Reloaded) {
- this.undoManager.Clear();
- this.taskList.Clear();
- }
- if (e.ModelChangeType == ModelChangeType.BeginBatchUpdate) {
- batch++;
- } else if (e.ModelChangeType == ModelChangeType.EndBatchUpdate) {
- batch--;
- }
- if (batch == 0) OnModelChanged();
- }
- protected virtual void OnModelChanged() {
- TaskHandler handler = new TaskHandler(this.taskList);
- handler.Start();
- this.model.ValidateModel(handler);
- handler.Finish();
- UpdateCaption();
- }
- private void settings_Changed(object sender, string name) {
- // Make sure it's on the right thread...
- ISynchronizeInvoke si = (ISynchronizeInvoke)this;
- if (si.InvokeRequired) {
- si.BeginInvoke(new SettingsEventHandler(OnSettingsChanged),
- new object[] { sender, name });
- } else {
- OnSettingsChanged(sender, name);
- }
- }
- protected virtual void OnSettingsChanged(object sender, string name) {
- switch (name){
- case "File":
- this.settings.Reload(); // just do it!!
- break;
- case "WindowBounds":
- if (loading) { // only if loading first time!
- Rectangle r = (Rectangle)this.settings["WindowBounds"];
- if (!r.IsEmpty) {
- Screen s = Screen.FromRectangle(r);
- if (s.Bounds.Contains(r)) {
- this.Bounds = r;
- this.StartPosition = FormStartPosition.Manual;
- }
- }
- }
- break;
- case "TreeViewSize":
- int pos = (int)this.settings["TreeViewSize"];
- if (pos != 0) {
- this.xmlTreeView1.ResizerPosition = pos;
- }
- break;
- case "TaskListSize":
- int height = (int)this.settings["TaskListSize"];
- if (height != 0) {
- this.tabControlLists.Height = height;
- }
- break;
- case "Font":
- this.Font = (Font)this.settings["Font"];
- break;
- case "RecentFiles":
- Uri[] files = (Uri[])this.settings["RecentFiles"];
- if (files != null) {
- this.recentFiles.SetFiles(files);
- }
- break;
- }
- }
- public void SaveErrors(string filename) {
- this.taskList.Save(filename);
- }
- void OnRecentFileSelected(object sender, RecentFileEventArgs e) {
- if (!this.SaveIfDirty(true))
- return;
- string fileName = e.FileName;
- Open(fileName);
- }
- private void treeView1_SelectionChanged(object sender, EventArgs e) {
- UpdateMenuState();
- DisplayHelp();
- }
- private void DisplayHelp() {
- // display documentation
- if (null == xmlTreeView1.SelectedNode) {
- this.dynamicHelpViewer.DisplayXsltResults(new XmlDocument());
- return;
- }
- XmlDocument xmlDoc = xmlTreeView1.SelectedNode.GetDocumentation();
- if (this.dynamicHelpViewer.Visible) {
- ShowStatus("");
- helpAvailableHint = false;
- if (null == xmlDoc) {
- xmlDoc = new XmlDocument();
- if (taskList.Count > 0) {
- xmlDoc.AppendChild(xmlDoc.CreateElement("errors"));
- } else {
- xmlDoc.AppendChild(xmlDoc.CreateElement("nothing"));
- }
- }
- this.dynamicHelpViewer.DisplayXsltResults(xmlDoc);
- } else if (helpAvailableHint && xmlDoc != null) {
- helpAvailableHint = false;
- ShowStatus(SR.DynamicHelpAvailable);
- }
- }
- private void treeView1_NodeChanged(object sender, NodeChangeEventArgs e) {
- UpdateMenuState();
- }
- protected virtual void UpdateMenuState() {
- XmlTreeNode node = this.xmlTreeView1.SelectedNode as XmlTreeNode;
- XmlNode xnode = (node != null) ? node.Node : null;
- bool hasSelection = node != null;
- bool hasXmlNode = xnode != null;
- this.toolStripButtonCut.Enabled = this.cutToolStripMenuItem.Enabled = this.ctxcutToolStripMenuItem.Enabled = hasXmlNode;
- this.toolStripButtonDelete.Enabled = this.deleteToolStripMenuItem.Enabled = hasSelection;
- this.toolStripButtonCopy.Enabled = this.copyToolStripMenuItem.Enabled = this.ctxMenuItemCopy.Enabled = hasXmlNode;
- this.duplicateToolStripMenuItem.Enabled = hasXmlNode;
- this.changeToAttributeContextMenuItem.Enabled = this.changeToAttributeToolStripMenuItem1.Enabled = hasSelection;
- this.changeToCDATAContextMenuItem.Enabled = this.changeToCDATAToolStripMenuItem1.Enabled = hasSelection;
- this.changeToCommentContextMenuItem.Enabled = this.changeToCommentToolStripMenuItem1.Enabled = hasSelection;
- this.changeToElementContextMenuItem.Enabled = this.changeToElementToolStripMenuItem1.Enabled = hasSelection;
- this.changeToProcessingInstructionContextMenuItem.Enabled = this.changeToProcessingInstructionToolStripMenuItem.Enabled = hasSelection;
- this.changeToTextContextMenuItem.Enabled = this.changeToTextToolStripMenuItem1.Enabled = hasSelection;
- this.toolStripButtonNudgeUp.Enabled = upToolStripMenuItem.Enabled = this.xmlTreeView1.CanNudgeNode((XmlTreeNode)this.xmlTreeView1.SelectedNode, NudgeDirection.Up);
- this.toolStripButtonNudgeDown.Enabled = downToolStripMenuItem.Enabled = this.xmlTreeView1.CanNudgeNode((XmlTreeNode)this.xmlTreeView1.SelectedNode, NudgeDirection.Down);
- this.toolStripButtonNudgeLeft.Enabled = leftToolStripMenuItem.Enabled = this.xmlTreeView1.CanNudgeNode((XmlTreeNode)this.xmlTreeView1.SelectedNode, NudgeDirection.Left);
- this.toolStripButtonNudgeRight.Enabled = rightToolStripMenuItem.Enabled = this.xmlTreeView1.CanNudgeNode((XmlTreeNode)this.xmlTreeView1.SelectedNode, NudgeDirection.Right);
- this.repeatToolStripMenuItem.Enabled = hasSelection && xnode != null && this.xmlTreeView1.CanInsertNode(InsertPosition.After, xnode.NodeType);
- this.undoToolStripMenuItem.Enabled = toolStripButtonUndo.Enabled = this.undoManager.CanUndo;
- this.redoToolStripMenuItem.Enabled = toolStripButtonRedo.Enabled = this.undoManager.CanRedo;
- EnableNodeItems(XmlNodeType.Element, this.ctxElementBeforeToolStripMenuItem, this.elementBeforeToolStripMenuItem,
- this.ctxElementAfterToolStripMenuItem, this.elementAfterToolStripMenuItem,
- this.ctxElementChildToolStripMenuItem, this.elementChildToolStripMenuItem);
- EnableNodeItems(XmlNodeType.Attribute, this.ctxAttributeBeforeToolStripMenuItem, this.attributeBeforeToolStripMenuItem,
- this.ctxAttributeAfterToolStripMenuItem, this.attributeAfterToolStripMenuItem,
- this.ctxAttributeChildToolStripMenuItem, this.attributeChildToolStripMenuItem);
- EnableNodeItems(XmlNodeType.Text, this.ctxTextBeforeToolStripMenuItem, this.textBeforeToolStripMenuItem,
- this.ctxTextAfterToolStripMenuItem, this.textAfterToolStripMenuItem,
- this.ctxTextChildToolStripMenuItem, this.textChildToolStripMenuItem);
- EnableNodeItems(XmlNodeType.CDATA, this.ctxCdataBeforeToolStripMenuItem, this.cdataBeforeToolStripMenuItem,
- this.ctxCdataAfterToolStripMenuItem, this.cdataAfterToolStripMenuItem,
- this.ctxCdataChildToolStripMenuItem, this.cdataChildToolStripMenuItem);
- EnableNodeItems(XmlNodeType.Comment, this.ctxCommentBeforeToolStripMenuItem, this.commentBeforeToolStripMenuItem,
- this.ctxCommentAfterToolStripMenuItem, this.commentAfterToolStripMenuItem,
- this.ctxCommentChildToolStripMenuItem, this.commentChildToolStripMenuItem);
- EnableNodeItems(XmlNodeType.ProcessingInstruction, this.ctxPIBeforeToolStripMenuItem, this.PIBeforeToolStripMenuItem,
- this.ctxPIAfterToolStripMenuItem, this.PIAfterToolStripMenuItem,
- this.ctxPIChildToolStripMenuItem, this.PIChildToolStripMenuItem);
- }
- void EnableNodeItems(XmlNodeType nt, ToolStripMenuItem c1, ToolStripMenuItem m1, ToolStripMenuItem c2, ToolStripMenuItem m2, ToolStripMenuItem c3, ToolStripMenuItem m3){
- c1.Enabled = m1.Enabled = this.xmlTreeView1.CanInsertNode(InsertPosition.Before, nt);
- c2.Enabled = m2.Enabled = this.xmlTreeView1.CanInsertNode(InsertPosition.After, nt);
- c3.Enabled = m3.Enabled = this.xmlTreeView1.CanInsertNode(InsertPosition.Child, nt);
- }
- protected virtual void OpenNotepad(string path) {
- if (this.SaveIfDirty(true)){
- string sysdir = Environment.SystemDirectory;
- string notepad = Path.Combine(sysdir, "notepad.exe");
- if (File.Exists(notepad)){
- ProcessStartInfo pi = new ProcessStartInfo(notepad, path);
- Process.Start(pi);
- }
- }
- }
- void treeView1_ClipboardChanged(object sender, EventArgs e) {
- CheckClipboard();
- }
- void CheckClipboard() {
- this.toolStripButtonPaste.Enabled = this.pasteToolStripMenuItem.Enabled = this.ctxMenuItemPaste.Enabled = TreeData.HasData;
- }
- protected override void OnActivated(EventArgs e) {
- CheckClipboard();
- if (firstActivate) {
- this.comboBoxLocation.Focus();
- firstActivate = false;
- }
- if (this.xmlTreeView1.TreeView.IsEditing) {
- this.xmlTreeView1.TreeView.Focus();
- } else if (this.xmlTreeView1.NodeTextView.IsEditing) {
- this.xmlTreeView1.NodeTextView.Focus();
- }
- }
- void taskList_Navigate(object sender, Task task) {
- XmlNode node = task.Data as XmlNode;
- if (node != null) {
- XmlTreeNode tn = this.xmlTreeView1.FindNode(node);
- if (tn != null) {
- this.xmlTreeView1.SelectedNode = tn;
- this.SelectTreeView();
- }
- }
- }
- private void Form1_DragOver(object sender, DragEventArgs e) {
- IDataObject data = e.Data;
- if (data.GetDataPresent(DataFormats.FileDrop) || data.GetDataPresent(this.urlFormat.Name)){
- e.Effect = DragDropEffects.Copy;
- }
- return;
- }
- private void Form1_DragDrop(object sender, DragEventArgs e) {
- IDataObject data = e.Data;
- if (data.GetDataPresent(DataFormats.FileDrop)){
- Array a = data.GetData(DataFormats.FileDrop) as Array;
- if (a != null){
- if (a.Length>0 && a.GetValue(0) is string){
- string filename = (string)a.GetValue(0);
- if (!this.SaveIfDirty(true))
- return;
- this.Open(filename);
- }
- }
- } else if (data.GetDataPresent(this.urlFormat.Name)){
- Stream stm = data.GetData(this.urlFormat.Name) as Stream;
- if (stm != null) {
- try {
- // Note: for some reason sr.ReadToEnd doesn't work right.
- StreamReader sr = new StreamReader(stm, Encoding.Unicode);
- StringBuilder sb = new StringBuilder();
- while (true) {
- int i = sr.Read();
- if (i != 0) {
- sb.Append(Convert.ToChar(i));
- } else {
- break;
- }
- }
- string url = sb.ToString();
- if (!this.SaveIfDirty(true))
- return;
- this.Open(url);
- } catch (Exception){
- }
- }
- }
- }
- private void newToolStripMenuItem_Click(object sender, EventArgs e) {
- this.xmlTreeView1.CancelEdit();
- New();
- }
- private void openToolStripMenuItem_Click(object sender, EventArgs e) {
- this.xmlTreeView1.CancelEdit();
- Open();
- }
- private void reloadToolStripMenuItem_Click(object sender, EventArgs e) {
- SelectTreeView();
- if (model.Dirty) {
- if (MessageBox.Show(this, SR.DiscardChanges, SR.DiscardChangesCaption,
- MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.Cancel) {
- return;
- }
- }
- Open(this.model.FileName);
- }
- private void saveToolStripMenuItem_Click(object sender, EventArgs e) {
- this.xmlTreeView1.Commit();
- Save();
- }
- private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) {
- this.xmlTreeView1.Commit();
- SaveAs();
- }
- private void menuItemRecentFiles_Click(object sender, EventArgs e) {
- }
- private void exitToolStripMenuItem_Click(object sender, EventArgs e) {
- this.xmlTreeView1.Commit();
- this.Close();
- }
- private void undoToolStripMenuItem_Click(object sender, EventArgs e) {
- try {
- this.xmlTreeView1.CancelEdit();
- this.undoManager.Undo();
- SelectTreeView();
- UpdateMenuState();
- } catch (Exception ex) {
- MessageBox.Show(this, ex.Message, SR.UndoError, MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- private void redoToolStripMenuItem_Click(object sender, EventArgs e) {
- try {
- if (this.xmlTreeView1.Commit())
- this.undoManager.Redo();
- SelectTreeView();
- UpdateMenuState();
- } catch (Exception ex) {
- MessageBox.Show(this, ex.Message, SR.RedoError, MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- private void cutToolStripMenuItem_Click(object sender, EventArgs e) {
- if (this.xmlTreeView1.Commit())
- this.xmlTreeView1.Cut();
- UpdateMenuState();
- SelectTreeView();
- }
- private void copyToolStripMenuItem_Click(object sender, EventArgs e) {
- this.xmlTreeView1.Commit();
- this.xmlTreeView1.Copy();
- SelectTreeView();
- }
- private void pasteToolStripMenuItem_Click(object sender, EventArgs e) {
- if (this.xmlTreeView1.Commit())
- this.xmlTreeView1.Paste(InsertPosition.Child);
- UpdateMenuState();
- SelectTreeView();
- }
- private void deleteToolStripMenuItem_Click(object sender, EventArgs e) {
- DeleteSelectedNode();
- }
- void DeleteSelectedNode() {
- this.xmlTreeView1.Commit();
- this.xmlTreeView1.Delete();
- UpdateMenuState();
- SelectTreeView();
- }
- private void repeatToolStripMenuItem_Click(object sender, EventArgs e) {
- this.RepeatSelectedNode();
- }
- void RepeatSelectedNode() {
- if (this.xmlTreeView1.Commit())
- this.xmlTreeView1.Insert();
- UpdateMenuState();
- SelectTreeView();
- }
- private void duplicateToolStripMenuItem_Click(object sender, EventArgs e) {
- DuplicateSelectedNode();
- }
- void DuplicateSelectedNode() {
- try {
- if (this.xmlTreeView1.Commit())
- this.xmlTreeView1.Duplicate();
- UpdateMenuState();
- SelectTreeView();
- } catch (Exception ex) {
- MessageBox.Show(this, ex.Message, SR.DuplicateErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- private void upToolStripMenuItem_Click(object sender, EventArgs e) {
- if (this.xmlTreeView1.Commit())
- this.xmlTreeView1.NudgeNode(this.xmlTreeView1.SelectedNode, NudgeDirection.Up);
- SelectTreeView();
- }
- private void downToolStripMenuItem_Click(object sender, EventArgs e) {
- if (this.xmlTreeView1.Commit())
- this.xmlTreeView1.NudgeNode(this.xmlTreeView1.SelectedNode, NudgeDirection.Down);
- SelectTreeView();
- }
- private void leftToolStripMenuItem_Click(object sender, EventArgs e) {
- if (this.xmlTreeView1.Commit())
- this.xmlTreeView1.NudgeNode(this.xmlTreeView1.SelectedNode, NudgeDirection.Left);
- SelectTreeView();
- }
- private void rightToolStripMenuItem_Click(object sender, EventArgs e) {
- if (this.xmlTreeView1.Commit())
- this.xmlTreeView1.NudgeNode(this.xmlTreeView1.SelectedNode, NudgeDirection.Right);
- SelectTreeView();
- }
- private void findToolStripMenuItem_Click(object sender, EventArgs e) {
- Search(false);
- }
- private void replaceToolStripMenuItem_Click(object sender, EventArgs e) {
- Search(true);
- }
- void Search(bool replace) {
- if (this.tabControlViews.SelectedTab == this.tabPageHtmlView) {
- this.xsltViewer.Find();
- return;
- }
- if (search == null || !search.Visible) {
- search = new FormSearch(search, (ISite)this);
- } else {
- search.Activate();
- }
- search.Target = new XmlTreeViewFindTarget(this.xmlTreeView1);
- search.ReplaceMode = replace;
- if (!search.Visible) {
- search.Show(this); // modeless
- }
- }
- private void expandToolStripMenuItem_Click(object sender, EventArgs e) {
- SelectTreeView();
- XmlTreeNode s = this.xmlTreeView1.SelectedNode;
- if (s != null) {
- s.ExpandAll();
- }
- }
- private void collapseToolStripMenuItem_Click(object sender, EventArgs e) {
- SelectTreeView();
- XmlTreeNode s = this.xmlTreeView1.SelectedNode;
- if (s != null) {
- s.CollapseAll();
- }
- }
- private void expandAllToolStripMenuItem_Click(object sender, EventArgs e) {
- SelectTreeView();
- this.xmlTreeView1.ExpandAll();
- }
- private void collapseAllToolStripMenuItem_Click(object sender, EventArgs e) {
- SelectTreeView();
- this.xmlTreeView1.CollapseAll();
- }
- private void statusBarToolStripMenuItem_Click(object sender, EventArgs e) {
- bool visible = !statusBarToolStripMenuItem.Checked;
- statusBarToolStripMenuItem.Checked = visible;
- int h = this.ClientSize.Height - this.toolStrip1.Bottom - 2;
- if (visible) {
- h -= this.statusBar1.Height;
- }
- this.tabControlViews.Height = h;
- this.statusBar1.Visible = visible;
- this.PerformLayout();
- }
- private void sourceToolStripMenuItem_Click(object sender, EventArgs e) {
- if (this.tabControlViews.SelectedTab == this.tabPageHtmlView) {
- this.xsltViewer.ViewSource();
- } else {
- OpenNotepad(this.model.FileName);
- }
- }
- private void optionsToolStripMenuItem_Click(object sender, EventArgs e) {
- string oldLocation = (string)settings["UpdateLocation"];
- FormOptions options = new FormOptions();
- options.Site = this;
- if (options.ShowDialog(this) == DialogResult.OK) {
- this.updater.OnUserChange(oldLocation);
- }
- }
- private void contentsToolStripMenuItem_Click(object sender, EventArgs e) {
- Help.ShowHelp(this, this.helpProvider1.HelpNamespace, HelpNavigator.TableOfContents);
- }
- private void indexToolStripMenuItem_Click(object sender, EventArgs e) {
- Help.ShowHelp(this, this.helpProvider1.HelpNamespace, HelpNavigator.Index);
- }
- private void aboutXMLNotepadToolStripMenuItem_Click(object sender, EventArgs e) {
- FormAbout frm = new FormAbout();
- frm.ShowDialog(this);
- }
- private void toolStripButtonNew_Click(object sender, EventArgs e) {
- this.xmlTreeView1.CancelEdit();
- this.New();
- }
- private void toolStripButtonOpen_Click(object sender, EventArgs e) {
- this.xmlTreeView1.CancelEdit();
- this.Open();
- }
- private void toolStripButtonSave_Click(object sender, EventArgs e) {
- this.xmlTreeView1.Commit();
- this.Save();
- }
- private void toolStripButtonUndo_Click(object sender, EventArgs e) {
- SelectTreeView();
- if (this.xmlTreeView1.Commit())
- this.undoManager.Undo();
- UpdateMenuState();
- }
- private void toolStripButtonRedo_Click(object sender, EventArgs e) {
- SelectTreeView();
- if (this.xmlTreeView1.Commit())
- this.undoManager.Redo();
- UpdateMenuState();
- }
- private void toolStripButtonCut_Click(object sender, EventArgs e) {
- SelectTreeView();
- this.xmlTreeView1.Cut();
- UpdateMenuState();
- }
- private void toolStripButtonCopy_Click(object sender, EventArgs e) {
- SelectTreeView();
- this.xmlTreeView1.Copy();
- }
- private void toolStripButtonPaste_Click(object sender, EventArgs e) {
- SelectTreeView();
- this.xmlTreeView1.Paste(InsertPosition.Child);
- UpdateMenuState();
- }
- private void toolStripButtonDelete_Click(object sender, EventArgs e) {
- SelectTreeView();
- this.xmlTreeView1.CancelEdit();
- this.xmlTreeView1.Delete();
- UpdateMenuState();
- }
- private void toolStripButtonNudgeUp_Click(object sender, EventArgs e) {
- this.upToolStripMenuItem_Click(sender, e);
- }
- private void toolStripButtonNudgeDown_Click(object sender, EventArgs e) {
- this.downToolStripMenuItem_Click(sender, e);
- }
- private void toolStripButtonNudgeLeft_Click(object sender, EventArgs e) {
- this.leftToolStripMenuItem_Click(sender, e);
- }
- private void toolStripButtonNudgeRight_Click(object sender, EventArgs e) {
- this.rightToolStripMenuItem_Click(sender, e);
- }
- // Insert Menu Items.
- private void elementAfterToolStripMenuItem_Click(object sender, EventArgs e) {
- SelectTreeView();
- if (this.xmlTreeView1.Commit())
- this.xmlTreeView1.InsertNode(InsertPosition.After, XmlNodeType.Element);
- }
- private void elementBeforeToolStripMenuItem_Click(object sender, EventArgs e) {
- SelectTreeView();
- if (this.xmlTreeView1.Commit())
- this.xmlTreeView1.InsertNode(InsertPosition.Before, XmlNodeType.Element);
- }
- private void elementChildToolStripMenuItem_Click(object sender, EventArgs e) {
- SelectTreeView();
- if (this.xmlTreeView1.Commit())
- this.xmlTreeView1.InsertNode(InsertPosition.Child, XmlNodeType.Element);
- }
- private void attributeBeforeToolStripMenuItem_Click(object sender, EventArgs e) {
- SelectTreeView();
- if (this.xmlTreeView1.Commit())
- this.xmlTreeView1.InsertNode(InsertPosition.Before, XmlNodeType.Attribute);
- }
- private void attributeAfterToolStripMenuItem_Click(object sender, EventArgs e) {
- SelectTreeView();
- if (this.xmlTreeView1.Commit())
- this.xmlTreeView1.InsertNode(InsertPosition.After, XmlNodeType.Attribute);
- }
- private void attributeChildToolStripMenuItem_Click(object sender, EventArgs e) {
- SelectTreeView();
- if (this.xmlTreeView1.Commit())
- this.xmlTreeView1.InsertNode(InsertPosition.Child, XmlNodeType.Attribute);
- }
- private void textBeforeToolStripMenuItem_Click(object sender, EventArgs e) {
- SelectTreeView();
- if (this.xmlTreeView1.Commit())
- this.xmlTreeView1.InsertNode(InsertPosition.Before, XmlNodeType.Text);
- }
- private void textAfterToolStripMenuItem_Click(object sender, EventArgs e) {
- SelectTreeView();
- if (this.xmlTreeView1.Commit())
- this.xmlTreeView1.InsertNode(InsertPosition.After, XmlNodeType.Text);
- }
- private void textChildToolStripMenuItem_Click(object sender, EventArgs e) {
- SelectTreeView();
- if (this.xmlTreeView1.Commit())
- this.xmlTreeView1.InsertNode(InsertPosition.Child, XmlNodeType.Text);
- }
- private void commentBeforeToolStripMenuItem_Click(object sender, EventArgs e) {
- SelectTreeView();
- if (this.xmlTreeView1.Commit())
- this.xmlTreeView1.InsertNode(InsertPosition.Before, XmlNodeType.Comment);
- }
- private void commentAfterToolStripMenuItem_Click(object sender, EventArgs e) {
- SelectTreeView();
- if (this.xmlTreeView1.Commit())
- this.xmlTreeView1.InsertNode(InsertPosition.After, XmlNodeType.Comment);
- }
- private void commentChildToolStripMenuItem_Click(object sender, EventArgs e) {
- SelectTreeView();
- if (this.xmlTreeView1.Commit())
- this.xmlTreeView1.InsertNode(InsertPosition.Child, XmlNodeType.Comment);
- }
- private void cdataBeforeToolStripMenuItem_Click(object sender, EventArgs e) {
- SelectTreeView();
- if (this.xmlTreeView1.Commit())
- this.xmlTreeView1.InsertNode(InsertPosition.Before, XmlNodeType.CDATA);
- }
- private void cdataAfterToolStripMenuItem_Click(object sender, EventArgs e) {
- SelectTreeView();
- if (this.xmlTreeView1.Commit())
- this.xmlTreeView1.InsertNode(InsertPosition.After, XmlNodeType.CDATA);
- }
- private void cdataChildToolStripMenuItem_Click(object sender, EventArgs e) {
- SelectTreeView();
- if (this.xmlTreeView1.Commit())
- this.xmlTreeView1.InsertNode(InsertPosition.Child, XmlNodeType.CDATA);
- }
- private void PIBeforeToolStripMenuItem_Click(object sender, EventArgs e) {
- SelectTreeView();
- if (this.xmlTreeView1.Commit())
- this.xmlTreeView1.InsertNode(InsertPosition.Before, XmlNodeType.ProcessingInstruction);
- }
- private void PIAfterToolStripMenuItem_Click(object sender, EventArgs e) {
- SelectTreeView();
- if (this.xmlTreeView1.Commit())
- this.xmlTreeView1.InsertNode(InsertPosition.After, XmlNodeType.ProcessingInstruction);
- }
- private void PIChildToolStripMenuItem_Click(object sender, EventArgs e) {
- SelectTreeView();
- if (this.xmlTreeView1.Commit())
- this.xmlTreeView1.InsertNode(InsertPosition.Child, XmlNodeType.ProcessingInstruction);
- }
- void Launch(string exeFileName, string args) {
- ProcessStartInfo info = new ProcessStartInfo();
- info.FileName = exeFileName;
- info.Arguments = "/offset " + args;
- Process p = new Process();
- p.StartInfo = info;
- if (!p.Start()) {
- MessageBox.Show(this, string.Format(SR.ErrorCreatingProcessPrompt, exeFileName), SR.LaunchErrorPrompt, MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- private void newWindowToolStripMenuItem_Click(object sender, EventArgs e){
- this.SaveIfDirty(true);
- this.OpenNewWindow(this.model.FileName);
- }
- private void schemasToolStripMenuItem_Click(object sender, EventArgs e) {
- FormSchemas frm = new FormSchemas();
- frm.Site = this;
- if (frm.ShowDialog(this) == DialogResult.OK) {
- OnModelChanged();
- }
- }
- private void nextErrorToolStripMenuItem_Click(object sender, EventArgs e) {
- this.taskList.NavigateNextError();
- }
- private void compareXMLFilesToolStripMenuItem_Click(object sender, EventArgs e) {
- SelectTreeView();
- OpenFileDialog ofd = new OpenFileDialog();
- ofd.Filter = SR.SaveAsFilter;
- if (ofd.ShowDialog(this) == DialogResult.OK) {
- string secondFile = ofd.FileName;
- try {
- DoCompare(secondFile);
- } catch (Exception ex) {
- MessageBox.Show(this, ex.Message, SR.XmlDiffErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
- /// <summary>
- /// The html header used by XmlNotepad.
- /// </summary>
- /// <param name="sourceXmlFile">name of baseline xml data</param>
- /// <param name="changedXmlFile">name of file being compared</param>
- /// <param name="resultHtml">Output file</param>
- private void SideBySideXmlNotepadHeader(
- string sourceXmlFile,
- string changedXmlFile,
- TextWriter resultHtml) {
- // this initializes the html
- resultHtml.WriteLine(SR.XmlDiffHeader);
- resultHtml.WriteLine(string.Format(SR.XmlDiffBody,
- System.IO.Path.GetDirectoryName(sourceXmlFile),
- System.IO.Path.GetFileName(sourceXmlFile),
- System.IO.Path.GetDirectoryName(changedXmlFile),
- System.IO.Path.GetFileName(changedXmlFile)
- ));
- }
- void CleanupTempFiles() {
- try {
- this.tempFiles.Delete();
- } catch {
- }
- }
- private void DoCompare(string changed) {
- CleanupTempFiles();
- XmlDocument original = this.model.Document;
- XmlDocument doc = new XmlDocument();
- XmlReaderSettings settings = model.GetReaderSettings();
- using (XmlReader reader = XmlReader.Create(changed, settings)) {
- doc.Load(reader);
- }
- string startupPath = Application.StartupPath;
- //output diff file.
- string diffFile = Path.Combine(Path.GetTempPath(),
- Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".xml");
- this.tempFiles.AddFile(diffFile, false);
- bool isEqual = false;
- XmlTextWriter diffWriter = new XmlTextWriter(diffFile, Encoding.UTF8);
- diffWriter.Formatting = Formatting.Indented;
- using (diffWriter) {
- XmlDiff diff = new XmlDiff();
- isEqual = diff.Compare(original, doc, diffWriter);
- diff.Options = XmlDiffOptions.None;
- }
- if (isEqual) {
- //This means the files were identical for given options.
- MessageBox.Show(this, SR.FilesAreIdenticalPrompt, SR.FilesAreIdenticalCaption,
- MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- return;
- }
- string tempFile = Path.Combine(Path.GetTempPath(),
- Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".htm");
- tempFiles.AddFile(tempFile, false);
- using (XmlReader diffGram = XmlReader.Create(diffFile, settings)) {
- XmlDiffView diffView = new XmlDiffView();
- diffView.Load(new XmlNodeReader(original), diffGram);
- using (TextWriter htmlWriter = new StreamWriter(tempFile)) {
- SideBySideXmlNotepadHeader(this.model.FileName, changed, htmlWriter);
- diffView.GetHtml(htmlWriter);
- }
- }
- Uri uri = new Uri(tempFile);
- WebBrowserForm browserForm = new WebBrowserForm(uri, "XmlDiff");
- browserForm.Show();
- }
- string ApplicationPath {
- get {
- string path = Application.ExecutablePath;
- if (path.EndsWith("vstesthost.exe", StringComparison.CurrentCultureIgnoreCase)) {
- // must be running UnitTests
- Uri baseUri = new Uri(this.GetType().Assembly.Location);
- Uri resolved = new Uri(baseUri, @"......ApplicationbindebugXmlNotepad.exe");
- path = resolved.LocalPath;
- }
- return path;
- }
- }
- public virtual void OpenNewWindow(string path){
- if (!string.IsNullOrEmpty(path)) {
- Uri uri = new Uri(path);
- if (uri.IsFile) {
- path = uri.LocalPath;
- if (!File.Exists(path)) {
- DialogResult dr = MessageBox.Show(
- String.Format(SR.CreateFile, path), SR.CreateNodeFileCaption,
- MessageBoxButtons.OKCancel);
- if (dr.Equals(DialogResult.OK)) {
- try {
- XmlDocument include = new XmlDocument();
- include.InnerXml = "<root/>";
- include.Save(path);
- } catch (Exception e) {
- MessageBox.Show(this, e.Message, SR.SaveErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
- return;
- }
- } else {
- return;
- }
- }
- }
- }
- Launch(this.ApplicationPath, """ + path + """);
- }
- private void GotoDefinition() {
- SelectTreeView();
- this.SaveIfDirty(true);
- XmlTreeNode node = xmlTreeView1.SelectedNode;
- if (node == null) return;
- string ipath = node.GetDefinition();
- if (!string.IsNullOrEmpty(ipath)) {
- OpenNewWindow(ipath);
- }
- }
- private void gotoDefinitionToolStripMenuItem_Click(object sender, EventArgs e) {
- this.GotoDefinition();
- }
- private void ctxGotoDefinitionToolStripMenuItem_Click(object sender, EventArgs e) {
- this.GotoDefinition();
- }
- private void expandXIncludesToolStripMenuItem_Click(object sender, EventArgs e) {
- SelectTreeView();
- this.model.ExpandIncludes();
- includesExpanded = true;
- }
- private void exportErrorsToolStripMenuItem_Click(object sender, EventArgs e) {
- SaveAsErrors();
- }
- void SaveAsErrors() {
- SaveFileDialog sd = new SaveFileDialog();
- sd.Filter = SR.SaveAsFilter;
- sd.Title = SR.SaveErrorsCaption;
- if (sd.ShowDialog(this) == DialogResult.OK) {
- string fname = sd.FileName;
- if (CheckReadOnly(fname)) {
- SaveErrors(fname);
- }
- }
- }
- private void changeToElementToolStripMenuItem1_Click(object sender, EventArgs e) {
- this.xmlTreeView1.ChangeTo(XmlNodeType.Element);
- }
- private void changeToAttributeToolStripMenuItem1_Click(object sender, EventArgs e) {
- this.xmlTreeView1.ChangeTo(XmlNodeType.Attribute);
- }
- private void changeToTextToolStripMenuItem1_Click(object sender, EventArgs e) {
- this.xmlTreeView1.ChangeTo(XmlNodeType.Text);
- }
- private void changeToCDATAToolStripMenuItem1_Click(object sender, EventArgs e) {
- this.xmlTreeView1.ChangeTo(XmlNodeType.CDATA);
- }
- private void changeToCommentToolStripMenuItem1_Click(object sender, EventArgs e) {
- this.xmlTreeView1.ChangeTo(XmlNodeType.Comment);
- }
- private void changeToProcessingInstructionToolStripMenuItem_Click(object sender, EventArgs e) {
- this.xmlTreeView1.ChangeTo(XmlNodeType.ProcessingInstruction);
- }
- private void changeToElementContextMenuItem_Click(object sender, EventArgs e) {
- this.xmlTreeView1.ChangeTo(XmlNodeType.Element);
- }
- private void changeToAttributeContextMenuItem_Click(object sender, EventArgs e) {
- this.xmlTreeView1.ChangeTo(XmlNodeType.Attribute);
- }
- private void changeToTextToolStripMenuItem_Click(object sender, EventArgs e) {
- this.xmlTreeView1.ChangeTo(XmlNodeType.Text);
- }
- private void changeToCDATAContextMenuItem_Click(object sender, EventArgs e) {
- this.xmlTreeView1.ChangeTo(XmlNodeType.CDATA);
- }
- private void changeToCommentContextMenuItem_Click(object sender, EventArgs e) {
- this.xmlTreeView1.ChangeTo(XmlNodeType.Comment);
- }
- private void changeToProcessingInstructionContextMenuItem_Click(object sender, EventArgs e) {
- this.xmlTreeView1.ChangeTo(XmlNodeType.ProcessingInstruction);
- }
- private void incrementalSearchToolStripMenuItem_Click(object sender, EventArgs e) {
- this.xmlTreeView1.StartIncrementalSearch();
- }
- private void renameToolStripMenuItem1_Click(object sender, EventArgs e) {
- this.xmlTreeView1.BeginEditNodeName();
- }
- private void renameToolStripMenuItem_Click(object sender, EventArgs e) {
- this.xmlTreeView1.BeginEditNodeName();
- }
- private void insertToolStripMenuItem1_Click(object sender, EventArgs e) {
- this.RepeatSelectedNode();
- }
- private void deleteToolStripMenuItem1_Click(object sender, EventArgs e) {
- this.DeleteSelectedNode();
- }
- private void duplicateToolStripMenuItem1_Click(object sender, EventArgs e) {
- this.DuplicateSelectedNode();
- }
- }
- }