diff --git a/Scintilla.NET.TestApp/FormMain.Designer.cs b/Scintilla.NET.TestApp/FormMain.Designer.cs index 138f53d..906d137 100644 --- a/Scintilla.NET.TestApp/FormMain.Designer.cs +++ b/Scintilla.NET.TestApp/FormMain.Designer.cs @@ -59,6 +59,7 @@ private void InitializeComponent() this.scintilla._ScintillaManagedDragDrop = true; this.scintilla.BorderStyle = ScintillaNET.BorderStyle.Fixed3DVisualStyles; this.scintilla.CaretLineBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(232)))), ((int)(((byte)(232)))), ((int)(((byte)(255))))); + this.scintilla.ChangeHistory = ((ScintillaNET.ChangeHistory)((ScintillaNET.ChangeHistory.Enabled | ScintillaNET.ChangeHistory.Markers))); this.scintilla.Dock = System.Windows.Forms.DockStyle.Fill; this.scintilla.FoldLineStripColor = System.Drawing.Color.Gray; this.scintilla.Font = new System.Drawing.Font("Consolas", 10.2F); @@ -68,6 +69,8 @@ private void InitializeComponent() this.scintilla.ScrollWidth = 1; this.scintilla.Size = new System.Drawing.Size(914, 426); this.scintilla.TabIndex = 2; + this.scintilla.SavePointLeft += new System.EventHandler(this.scintilla_SavePointLeft); + this.scintilla.SavePointReached += new System.EventHandler(this.scintilla_SavePointReached); this.scintilla.TextChanged += new System.EventHandler(this.scintilla_TextChanged); this.scintilla.KeyDown += new System.Windows.Forms.KeyEventHandler(this.scintilla_KeyDown); // @@ -188,6 +191,10 @@ private void InitializeComponent() this.lexersToolStripMenuItem.Size = new System.Drawing.Size(64, 24); this.lexersToolStripMenuItem.Text = "Lexers"; // + // saveFileDialog + // + this.saveFileDialog.Filter = "All Files|*.*"; + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(120F, 120F); diff --git a/Scintilla.NET.TestApp/FormMain.cs b/Scintilla.NET.TestApp/FormMain.cs index fb8a774..d2cb6d6 100644 --- a/Scintilla.NET.TestApp/FormMain.cs +++ b/Scintilla.NET.TestApp/FormMain.cs @@ -10,14 +10,38 @@ namespace ScintillaNET.TestApp; public partial class FormMain : Form { + string baseTitle; + string? currentFileName = null; + + public string? CurrentFileName + { + get => this.currentFileName; + set + { + BaseTitle = Path.GetFileName(this.currentFileName = value); + } + } + + public string BaseTitle + { + get => this.baseTitle; + set + { + this.Text = (this.baseTitle = value) + (scintilla.Modified ? " *" : ""); + } + } + public FormMain() { InitializeComponent(); + baseTitle = this.Text; + scintilla.LexerName = "cpp"; SetScintillaStyles(scintilla); AdjustLineNumberMargin(scintilla); + AdjustMarkerMargin(scintilla); AdjustFoldMargin(scintilla); Version scintillaNetVersion = scintilla.GetType().Assembly.GetName().Version; @@ -119,6 +143,16 @@ private static void AdjustLineNumberMargin(Scintilla scintilla) maxLineNumberCharLengthMap[scintilla] = maxLineNumberCharLength; } + private static void AdjustMarkerMargin(Scintilla scintilla) + { + scintilla.Margins[1].Width = 16; + scintilla.Margins[1].Sensitive = false; + //scintilla.Markers[Marker.HistoryRevertedToModified].SetForeColor(Color.Orange); + //scintilla.Markers[Marker.HistoryRevertedToModified].SetBackColor(scintilla.Margins[1].BackColor); + //scintilla.Markers[Marker.HistoryRevertedToOrigin].SetForeColor(Color.Orange); + //scintilla.Markers[Marker.HistoryRevertedToOrigin].SetBackColor(scintilla.Margins[1].BackColor); + } + private static void AdjustFoldMargin(Scintilla scintilla) { // Instruct the lexer to calculate folding @@ -147,22 +181,28 @@ private static void AdjustFoldMargin(Scintilla scintilla) scintilla.Markers[Marker.FolderTail].Symbol = MarkerSymbol.LCorner; // Enable automatic folding - scintilla.AutomaticFold = (AutomaticFold.Show | AutomaticFold.Click | AutomaticFold.Change); + scintilla.AutomaticFold = AutomaticFold.Show | AutomaticFold.Click | AutomaticFold.Change; } private void openToolStripMenuItem_Click(object sender, EventArgs e) { if (openFileDialog.ShowDialog(this) == DialogResult.OK) { - scintilla.Text = File.ReadAllText(openFileDialog.FileName, Encoding.UTF8); + CurrentFileName = openFileDialog.FileName; + scintilla.Text = File.ReadAllText(CurrentFileName, Encoding.UTF8); + scintilla.ClearChangeHistory(); + scintilla.SetSavePoint(); } } private void saveToolStripMenuItem_Click(object sender, EventArgs e) { - if (saveFileDialog.ShowDialog(this) == DialogResult.OK) + if (CurrentFileName is null && saveFileDialog.ShowDialog(this) == DialogResult.OK) + CurrentFileName = saveFileDialog.FileName; + + if (CurrentFileName is not null) { - File.WriteAllText(saveFileDialog.FileName, scintilla.Text, Encoding.UTF8); + File.WriteAllText(CurrentFileName, scintilla.Text, Encoding.UTF8); scintilla.SetSavePoint(); } } @@ -195,4 +235,14 @@ private void scintilla_TextChanged(object sender, EventArgs e) { AdjustLineNumberMargin(scintilla); } + + private void scintilla_SavePointLeft(object sender, EventArgs e) + { + Text = BaseTitle + " *"; + } + + private void scintilla_SavePointReached(object sender, EventArgs e) + { + Text = BaseTitle; + } } diff --git a/Scintilla.NET.TestApp/Scintilla.NET.TestApp.csproj b/Scintilla.NET.TestApp/Scintilla.NET.TestApp.csproj index 6c8810d..08a1be7 100644 --- a/Scintilla.NET.TestApp/Scintilla.NET.TestApp.csproj +++ b/Scintilla.NET.TestApp/Scintilla.NET.TestApp.csproj @@ -13,6 +13,7 @@ AnyCPU app.manifest ScintillaNET.TestApp + enable