private void dockPanel_ActiveDocumentChanged(object sender, EventArgs e) { if (this.dockPanel.ActiveDocument != null) { Editor editor = (Editor)this.dockPanel.ActiveDocument.DockHandler.Form; CEManager.SetActiveDocument(editor); StatusManager.SetLineColumn(CEManager.ActiveDocument.codeEditor.TextArea.Caret.Line, CEManager.ActiveDocument.codeEditor.TextArea.Caret.Column); this.saveToolStripMenuItem.Text = string.Format(LanguageManager.GetText(LanguageEnum.MainMenuItemFileSave), Path.GetFileName(editor.FilePath)); this.savesAsToolStripMenuItem.Text = string.Format(LanguageManager.GetText(LanguageEnum.MainMenuItemFileSaveAs), Path.GetFileName(editor.FilePath)); this.SetMenuStatus(true, false); } else { CEManager.SetActiveDocument(null); this.SetMenuStatus(false, false); StatusManager.SetLineColumn(0, 0); this.saveToolStripMenuItem.Text = string.Format(LanguageManager.GetText(LanguageEnum.MainMenuItemFileSave), "Selected Item"); this.savesAsToolStripMenuItem.Text = string.Format(LanguageManager.GetText(LanguageEnum.MainMenuItemFileSaveAs), "Selected Item"); } }
private void saveAllToolStripMenuItem_Click(object sender, EventArgs e) { foreach (Editor editor in CEManager.ToList().Values) { editor.Save(); } }
private void projectFiles_DoubleClick(object sender, EventArgs e) { if (File.Exists(this.projectFiles.SelectedNode.Name) == true) { CEManager.Open(this.projectFiles.SelectedNode.Name, true); } CEManager.SetActiveDocument(this.projectFiles.SelectedNode.Name, true); }
/// <summary> /// Close all project files. /// </summary> /// <returns>Returns <c>true</c> if cancel button is not pressed, <c>false</c> otherwise.</returns> public static bool Close() { bool cancelPressed = CEManager.CloseAll(true); if (cancelPressed == false) { try { treeView.Nodes.Clear(); XmlDocument xmlFile = new XmlDocument(); xmlFile.LoadXml(File.ReadAllText(xmlPath)); XmlNode xmlDocument = xmlFile.DocumentElement; // Let's delete the old 'File' nodes. XmlNodeList xmlNodes = xmlFile.SelectNodes("//File"); foreach (XmlNode xmlNode in xmlNodes) { xmlDocument.RemoveChild(xmlNode); } // Let's create new 'File' nodes. XmlNode xmlElement; foreach (Editor editor in CEManager.ToList().Values) { xmlElement = xmlFile.CreateElement("File"); xmlElement.InnerText = editor.FilePath; if (editor == CEManager.ActiveDocument) { XmlNode xmlAttribute = xmlFile.CreateNode(XmlNodeType.Attribute, "Active", string.Empty); xmlAttribute.Value = "1"; xmlElement.Attributes.SetNamedItem(xmlAttribute); } xmlDocument.AppendChild(xmlElement); } // All done, let's save the XML. xmlFile.Save(xmlPath); } catch (Exception) { // TODO: Write the exception to log file. } IsOpen = false; } return(cancelPressed); }
private void openFileToolStripMenuItem_Click(object sender, EventArgs e) { this.openFileDialog.Filter = "PAWN File|*.pwn|Include file|*.inc"; DialogResult dialogResult = this.openFileDialog.ShowDialog(); if (dialogResult == DialogResult.OK) { CEManager.Open(this.openFileDialog.FileName); } }
private void Main_Load(object sender, EventArgs e) { if (File.Exists(this.layoutPath) == true) { this.dockPanel.LoadFromXml(this.layoutPath, dockContentLayout); } else { Stream xmlStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("PawnPlus.Resources.DefaultLayout.xml"); this.dockPanel.LoadFromXml(xmlStream, dockContentLayout); xmlStream.Close(); } CEManager.Construct(this.dockPanel); StatusManager.Construct(this.statusBar, this.statusLabel, this.lineLabel, this.columnLabel); this.SetLanguageText(); }
private void Main_FormClosing(object sender, FormClosingEventArgs e) { // Let's check if project is open and let's close files from project. After that let's close all files. if ((ProjectManager.IsOpen == true && ProjectManager.Close() == true) || (ProjectManager.IsOpen == false && CEManager.CloseAll(false) == true)) { e.Cancel = true; return; } if (Directory.Exists(Path.GetDirectoryName(this.layoutPath)) == false) // Check if path exist, if not create it. { Directory.CreateDirectory(Path.GetDirectoryName(this.layoutPath)); } if (File.Exists(this.layoutPath) == true) // Check if the "Layout.xml" already exist, if it exist let's delete it. { File.Delete(this.layoutPath); } dockPanel.SaveAsXml(this.layoutPath); Application.ExitThread(); // Close the entire application. }
/// <summary> /// Open a project. /// </summary> /// <param name="projectPath">Path to the project file.</param> /// <returns>Returns true if the project was opened with success, false otherwise.</returns> public static bool Open(string projectPath) { if (projectPath == null || System.IO.Path.GetExtension(projectPath) != Extension) { return(false); } xmlPath = projectPath; bool isActive = false; string filePath = string.Empty, activeFile = string.Empty; using (XmlTextReader projectReader = new XmlTextReader(projectPath)) { while (projectReader.Read()) { switch (projectReader.Name.ToString()) { case "Name": { Name = projectReader.ReadString(); break; } case "File": { try { isActive = Convert.ToBoolean(Convert.ToInt32(projectReader.GetAttribute("Active"))); // Get the attribute first. filePath = projectReader.ReadString(); if (isActive == true) { activeFile = filePath; } CEManager.Open(filePath, true); } catch (Exception) { // File dosen't exist. // TODO: Write the exception to log file. } break; } } } } if (activeFile != string.Empty) { CEManager.SetActiveDocument(activeFile, true); } Path = System.IO.Path.GetDirectoryName(projectPath); // Set the project path. LoadDirectory(Path); IsOpen = true; return(true); }