Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #105: Implement change history #120

Merged
merged 6 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Use change history features in test app
  • Loading branch information
ahmetsait committed May 9, 2024
commit 34dcd5190691604684cd2d4fe98afb790cd2764c
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
Loading