From 02fda552c09012be7934e7d344e80919037ffe2c Mon Sep 17 00:00:00 2001 From: Ima Mechanique Date: Tue, 23 Oct 2012 16:19:43 +0000 Subject: [PATCH] Forces note-cards to save as UTF-8. Also renamed open/save dialog properties. --- trunk/EditForm.cs | 31 +++++++++++++- trunk/Editor/SyntaxRichTextBox.cs | 44 ++++++++++++-------- trunk/LSLEditorForm.Designer.cs | 24 +++++------ trunk/LSLEditorForm.cs | 69 +++++++++++++++++-------------- 4 files changed, 105 insertions(+), 63 deletions(-) diff --git a/trunk/EditForm.cs b/trunk/EditForm.cs index 63b22d2..919dfb2 100644 --- a/trunk/EditForm.cs +++ b/trunk/EditForm.cs @@ -45,6 +45,7 @@ using System; using System.IO; using System.Xml; using System.Drawing; +using System.Text; using System.Windows.Forms; using LSLEditor.Docking; using LSLEditor.Helpers; @@ -59,6 +60,7 @@ namespace LSLEditor private Guid m_Guid; // private bool sOutline = true; public LSLEditorForm parent; + public Encoding encodedAs = null; private const int WM_NCACTIVATE = 0x0086; protected override void WndProc(ref Message m) @@ -317,12 +319,37 @@ namespace LSLEditor public void SaveCurrentFile(string strPath) { this.FullPathName = strPath; - this.numberedTextBoxUC1.TextBox.SaveCurrentFile(strPath); + Encoding encodeAs = this.encodedAs; + if (this.IsScript && encodeAs == null) + { + switch (Properties.Settings.Default.OutputFormat) + { + case "UTF8": + encodeAs = Encoding.UTF8; + break; + case "Unicode": + encodeAs = Encoding.Unicode; + break; + case "BigEndianUnicode": + encodeAs = Encoding.BigEndianUnicode; + break; + default: + encodeAs = Encoding.Default; + break; + } + } + else if (encodeAs == null) + { + encodeAs = Encoding.UTF8; + } + + this.numberedTextBoxUC1.TextBox.SaveCurrentFile(strPath, encodeAs); + this.encodedAs = encodeAs; } public void SaveCurrentFile() { - this.numberedTextBoxUC1.TextBox.SaveCurrentFile(this.FullPathName); + this.SaveCurrentFile(this.FullPathName); } public bool Dirty diff --git a/trunk/Editor/SyntaxRichTextBox.cs b/trunk/Editor/SyntaxRichTextBox.cs index ced5ebf..0e24d0b 100644 --- a/trunk/Editor/SyntaxRichTextBox.cs +++ b/trunk/Editor/SyntaxRichTextBox.cs @@ -2176,28 +2176,38 @@ namespace LSLEditor return result; } - public void SaveCurrentFile(string strPath) + public void SaveCurrentFile(string strPath, Encoding enc) { try { - Encoding enc = null; + //Encoding enc = null; if (!Directory.Exists(Path.GetDirectoryName(strPath))) Directory.CreateDirectory(Path.GetDirectoryName(strPath)); - switch (Properties.Settings.Default.OutputFormat) - { - case "UTF8": - enc = Encoding.UTF8; - break; - case "Unicode": - enc = Encoding.Unicode; - break; - case "BigEndianUnicode": - enc = Encoding.BigEndianUnicode; - break; - default: - enc = Encoding.Default; - break; - } + + /* + { + switch (Properties.Settings.Default.OutputFormat) + { + case "UTF8": + enc = Encoding.UTF8; + break; + case "Unicode": + enc = Encoding.Unicode; + break; + case "BigEndianUnicode": + enc = Encoding.BigEndianUnicode; + break; + default: + enc = Encoding.Default; + break; + } + } + else + { + enc = Encoding.UTF8; + } + * */ + StreamWriter sw; if (enc != Encoding.UTF8) { diff --git a/trunk/LSLEditorForm.Designer.cs b/trunk/LSLEditorForm.Designer.cs index d6b9feb..420db44 100644 --- a/trunk/LSLEditorForm.Designer.cs +++ b/trunk/LSLEditorForm.Designer.cs @@ -132,16 +132,16 @@ namespace LSLEditor this.toolStripSeparator12 = new System.Windows.Forms.ToolStripSeparator(); this.releaseNotesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.openFileDialog0 = new System.Windows.Forms.OpenFileDialog(); - this.saveFileDialog0 = new System.Windows.Forms.SaveFileDialog(); - this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); - this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog(); + this.openNoteFilesDialog = new System.Windows.Forms.OpenFileDialog(); + this.saveNoteFilesDialog = new System.Windows.Forms.SaveFileDialog(); + this.openScriptFilesDialog = new System.Windows.Forms.OpenFileDialog(); + this.saveScriptFilesDialog = new System.Windows.Forms.SaveFileDialog(); this.statusStrip1 = new System.Windows.Forms.StatusStrip(); this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel(); this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); this.closeTabToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.pageSetupDialog1 = new System.Windows.Forms.PageSetupDialog(); - this.openFileDialog2 = new System.Windows.Forms.OpenFileDialog(); + this.openSolutionFilesDialog = new System.Windows.Forms.OpenFileDialog(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.dockPanel = new LSLEditor.Docking.DockPanel(); this.menuStrip1.SuspendLayout(); @@ -874,7 +874,7 @@ namespace LSLEditor // // openFileDialog1 // - this.openFileDialog1.FileName = "openFileDialog1"; + this.openScriptFilesDialog.FileName = "openFileDialog1"; // // statusStrip1 // @@ -907,7 +907,7 @@ namespace LSLEditor // // openFileDialog2 // - this.openFileDialog2.FileName = "openFileDialog2"; + this.openSolutionFilesDialog.FileName = "openFileDialog2"; // // dockPanel // @@ -1025,10 +1025,10 @@ namespace LSLEditor private System.Windows.Forms.ToolStripSeparator toolStripSeparator7; private System.Windows.Forms.ToolStripMenuItem formatDocumentToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem startToolStripMenuItem; - private System.Windows.Forms.OpenFileDialog openFileDialog0; - private System.Windows.Forms.SaveFileDialog saveFileDialog0; - private System.Windows.Forms.OpenFileDialog openFileDialog1; - private System.Windows.Forms.SaveFileDialog saveFileDialog1; + private System.Windows.Forms.OpenFileDialog openNoteFilesDialog; + private System.Windows.Forms.SaveFileDialog saveNoteFilesDialog; + private System.Windows.Forms.OpenFileDialog openScriptFilesDialog; + private System.Windows.Forms.SaveFileDialog saveScriptFilesDialog; private System.Windows.Forms.ToolStripMenuItem indexToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem aboutToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem formatSelectedTextToolStripMenuItem; @@ -1079,7 +1079,7 @@ namespace LSLEditor private System.Windows.Forms.ToolStripMenuItem pageSettingsToolStripMenuItem; private System.Windows.Forms.PageSetupDialog pageSetupDialog1; private System.Windows.Forms.ToolStripMenuItem SaveAllToolStripMenuItem; - private System.Windows.Forms.OpenFileDialog openFileDialog2; + private System.Windows.Forms.OpenFileDialog openSolutionFilesDialog; private System.Windows.Forms.ToolStripMenuItem notecardToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem8; private System.Windows.Forms.ToolTip toolTip1; diff --git a/trunk/LSLEditorForm.cs b/trunk/LSLEditorForm.cs index edc2481..01b84c5 100644 --- a/trunk/LSLEditorForm.cs +++ b/trunk/LSLEditorForm.cs @@ -303,27 +303,27 @@ namespace LSLEditor this.ConfLSL = GetXmlFromResource(Properties.Settings.Default.ConfLSL); this.ConfCSharp = GetXmlFromResource(Properties.Settings.Default.ConfCSharp); - this.openFileDialog0.FileName = ""; - this.openFileDialog0.InitialDirectory = Properties.Settings.Default.WorkingDirectory; - this.openFileDialog0.Filter = fileFilterNotes; + this.openNoteFilesDialog.FileName = ""; + this.openNoteFilesDialog.Filter = fileFilterNotes; + this.openNoteFilesDialog.InitialDirectory = Properties.Settings.Default.WorkingDirectory; - this.saveFileDialog0.FileName = ""; - this.saveFileDialog0.InitialDirectory = Properties.Settings.Default.WorkingDirectory; - this.saveFileDialog0.Filter = fileFilterNotes; + this.saveNoteFilesDialog.FileName = ""; + this.saveNoteFilesDialog.Filter = fileFilterNotes; + this.saveNoteFilesDialog.InitialDirectory = Properties.Settings.Default.WorkingDirectory; - this.openFileDialog1.FileName = ""; - this.openFileDialog1.InitialDirectory = Properties.Settings.Default.WorkingDirectory; - this.openFileDialog1.Filter = fileFilterScripts; + this.openScriptFilesDialog.FileName = ""; + this.openScriptFilesDialog.Filter = fileFilterScripts; + this.openScriptFilesDialog.InitialDirectory = Properties.Settings.Default.WorkingDirectory; - this.saveFileDialog1.FileName = ""; - this.saveFileDialog1.InitialDirectory = Properties.Settings.Default.WorkingDirectory; - this.saveFileDialog1.Filter = fileFilterScripts; + this.saveScriptFilesDialog.FileName = ""; + this.saveScriptFilesDialog.Filter = fileFilterScripts; + this.saveScriptFilesDialog.InitialDirectory = Properties.Settings.Default.WorkingDirectory; - this.openFileDialog2.Multiselect = false; - this.openFileDialog2.FileName = ""; - this.openFileDialog2.Filter = fileFilterSolutions; - this.openFileDialog2.InitialDirectory = Properties.Settings.Default.ProjectLocation; + this.openSolutionFilesDialog.FileName = ""; + this.openSolutionFilesDialog.Filter = fileFilterSolutions; + this.openSolutionFilesDialog.InitialDirectory = Properties.Settings.Default.ProjectLocation; + this.openSolutionFilesDialog.Multiselect = false; Version version = Assembly.GetExecutingAssembly().GetName().Version; @@ -582,10 +582,10 @@ namespace LSLEditor private void ReadNoteFiles() { - this.openFileDialog0.Multiselect = true; - if (this.openFileDialog0.ShowDialog() == DialogResult.OK) + this.openNoteFilesDialog.Multiselect = true; + if (this.openNoteFilesDialog.ShowDialog() == DialogResult.OK) { - foreach (string strFileName in this.openFileDialog0.FileNames) + foreach (string strFileName in this.openNoteFilesDialog.FileNames) { if (File.Exists(strFileName)) { @@ -598,10 +598,10 @@ namespace LSLEditor private void ReadScriptFiles() { - this.openFileDialog1.Multiselect = true; - if (this.openFileDialog1.ShowDialog() == DialogResult.OK) + this.openScriptFilesDialog.Multiselect = true; + if (this.openScriptFilesDialog.ShowDialog() == DialogResult.OK) { - foreach (string strFileName in this.openFileDialog1.FileNames) + foreach (string strFileName in this.openScriptFilesDialog.FileNames) { if (File.Exists(strFileName)) { @@ -623,12 +623,12 @@ namespace LSLEditor DialogResult dialogresult = DialogResult.OK; if (editForm.FullPathName == Properties.Settings.Default.ExampleName || blnSaveAs) { - this.saveFileDialog1.FileName = editForm.FullPathName; + SaveFileDialog saveDialog = editForm.IsScript ? this.saveScriptFilesDialog : this.saveNoteFilesDialog; + saveDialog.FileName = editForm.FullPathName; string strExtension = Path.GetExtension(editForm.FullPathName); - this.saveFileDialog1.Filter = "Secondlife script files (*" + strExtension + ")|*" + strExtension + "|All files (*.*)|*.*"; - dialogresult = this.saveFileDialog1.ShowDialog(); - if (dialogresult == DialogResult.OK) - editForm.FullPathName = this.saveFileDialog1.FileName; + dialogresult = saveDialog.ShowDialog(); + if (dialogresult == DialogResult.OK) + editForm.FullPathName = saveDialog.FileName; } if (dialogresult == DialogResult.OK) { @@ -646,7 +646,9 @@ namespace LSLEditor if (editForm == null) return false; // save as!! - return SaveFile(editForm,true); + // TODO: Refactor saveDialog to be a property of the form + SaveFileDialog saveDialog = editForm.IsScript ? this.saveScriptFilesDialog : this.saveNoteFilesDialog; + return SaveFile(editForm, true); } @@ -1067,9 +1069,12 @@ namespace LSLEditor } if (dialogResult == DialogResult.Yes) { + // TODO: Refactor saveDialog to be a property of the form + SaveFileDialog saveDialog = editForm.IsScript ? this.saveScriptFilesDialog : this.saveNoteFilesDialog; if(!SaveFile(editForm, false)) return false; } + if (dialogResult == DialogResult.No) { editForm.Dirty = false; @@ -1613,12 +1618,12 @@ namespace LSLEditor #region SolutionExplorer private void openProjectSolutionToolStripMenuItem_Click(object sender, EventArgs e) { - if (this.openFileDialog2.ShowDialog(this) == DialogResult.OK) + if (this.openSolutionFilesDialog.ShowDialog(this) == DialogResult.OK) { - if (File.Exists(this.openFileDialog2.FileName)) + if (File.Exists(this.openSolutionFilesDialog.FileName)) { if(CloseAllOpenWindows()) - this.SolutionExplorer.OpenSolution(this.openFileDialog2.FileName); + this.SolutionExplorer.OpenSolution(this.openSolutionFilesDialog.FileName); } } } @@ -1822,7 +1827,7 @@ namespace LSLEditor if (editForm != null) { this.saveToolStripMenuItem.Text = "Save " + editForm.ScriptName; - this.saveFileDialog1.FileName = editForm.ScriptName; + this.saveScriptFilesDialog.FileName = editForm.ScriptName; this.saveToolStripMenuItem.Enabled = editForm.Dirty; this.closeFileToolStripMenuItem.Enabled = true; }