Skip to content

Commit

Permalink
Use change history features in test app
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmetsait committed May 9, 2024
1 parent d808357 commit 34dcd51
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
7 changes: 7 additions & 0 deletions Scintilla.NET.TestApp/FormMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 54 additions & 4 deletions Scintilla.NET.TestApp/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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;
}
}
1 change: 1 addition & 0 deletions Scintilla.NET.TestApp/Scintilla.NET.TestApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<ApplicationManifest>app.manifest</ApplicationManifest>
<RootNamespace>ScintillaNET.TestApp</RootNamespace>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Update="FormMain.cs">
Expand Down

0 comments on commit 34dcd51

Please sign in to comment.