Skip to content

Commit

Permalink
Run code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmetsait committed May 12, 2024
1 parent d9d082d commit a836fcb
Show file tree
Hide file tree
Showing 46 changed files with 1,695 additions and 1,727 deletions.
18 changes: 7 additions & 11 deletions Scintilla.NET/AutoCSelectionChangeEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ScintillaNET
{
Expand Down Expand Up @@ -30,10 +27,9 @@ public int Position
{
get
{
if (position == null)
position = scintilla.Lines.ByteToCharPosition(bytePosition);
this.position ??= this.scintilla.Lines.ByteToCharPosition(this.bytePosition);

return (int)position;
return (int)this.position;
}
}

Expand All @@ -45,16 +41,16 @@ public unsafe string Text
{
get
{
if (text == null)
if (this.text == null)
{
var len = 0;
while (((byte*)textPtr)[len] != 0)
int len = 0;
while (((byte*)this.textPtr)[len] != 0)
len++;

text = Helpers.GetString(textPtr, len, scintilla.Encoding);
this.text = Helpers.GetString(this.textPtr, len, this.scintilla.Encoding);
}

return text;
return this.text;
}
}

Expand Down
15 changes: 7 additions & 8 deletions Scintilla.NET/AutoCSelectionEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ public int Position
{
get
{
if (position == null)
position = scintilla.Lines.ByteToCharPosition(bytePosition);
this.position ??= this.scintilla.Lines.ByteToCharPosition(this.bytePosition);

return (int)position;
return (int)this.position;
}
}

Expand All @@ -50,16 +49,16 @@ public unsafe string Text
{
get
{
if (text == null)
if (this.text == null)
{
var len = 0;
while (((byte*)textPtr)[len] != 0)
int len = 0;
while (((byte*)this.textPtr)[len] != 0)
len++;

text = Helpers.GetString(textPtr, len, scintilla.Encoding);
this.text = Helpers.GetString(this.textPtr, len, this.scintilla.Encoding);
}

return text;
return this.text;
}
}

Expand Down
13 changes: 6 additions & 7 deletions Scintilla.NET/BeforeModificationEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ public int Position
{
get
{
if (CachedPosition == null)
CachedPosition = scintilla.Lines.ByteToCharPosition(bytePosition);
CachedPosition ??= this.scintilla.Lines.ByteToCharPosition(this.bytePosition);

return (int)CachedPosition;
}
Expand All @@ -42,22 +41,22 @@ public int Position
/// <returns>
/// The text about to be inserted or deleted.
/// </returns>
public unsafe virtual string Text
public virtual unsafe string Text
{
get
{
if (CachedText == null)
{
// For some reason the Scintilla overlords don't provide text in
// SC_MOD_BEFOREDELETE... but we can get it from the document.
if (textPtr == IntPtr.Zero)
if (this.textPtr == IntPtr.Zero)
{
var ptr = scintilla.DirectMessage(NativeMethods.SCI_GETRANGEPOINTER, new IntPtr(bytePosition), new IntPtr(byteLength));
CachedText = new string((sbyte*)ptr, 0, byteLength, scintilla.Encoding);
IntPtr ptr = this.scintilla.DirectMessage(NativeMethods.SCI_GETRANGEPOINTER, new IntPtr(this.bytePosition), new IntPtr(this.byteLength));
CachedText = new string((sbyte*)ptr, 0, this.byteLength, this.scintilla.Encoding);
}
else
{
CachedText = Helpers.GetString(textPtr, byteLength, scintilla.Encoding);
CachedText = Helpers.GetString(this.textPtr, this.byteLength, this.scintilla.Encoding);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Scintilla.NET/CallTipClickEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace ScintillaNET;
/// <summary>
/// Provides data for the <see cref="Scintilla.CallTipClick" /> event.
/// </summary>
public class CallTipClickEventArgs: EventArgs
public class CallTipClickEventArgs : EventArgs
{
private readonly Scintilla scintilla;

Expand Down
33 changes: 16 additions & 17 deletions Scintilla.NET/CaretStyle.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
namespace ScintillaNET;

/// <summary>
/// The caret visual style.
/// </summary>
public enum CaretStyle
{
/// <summary>
/// The caret visual style.
/// The caret is not displayed.
/// </summary>
public enum CaretStyle
{
/// <summary>
/// The caret is not displayed.
/// </summary>
Invisible = NativeMethods.CARETSTYLE_INVISIBLE,
Invisible = NativeMethods.CARETSTYLE_INVISIBLE,

/// <summary>
/// The caret is drawn as a vertical line.
/// </summary>
Line = NativeMethods.CARETSTYLE_LINE,

/// <summary>
/// The caret is drawn as a block.
/// </summary>
Block = NativeMethods.CARETSTYLE_BLOCK
}
/// <summary>
/// The caret is drawn as a vertical line.
/// </summary>
Line = NativeMethods.CARETSTYLE_LINE,

/// <summary>
/// The caret is drawn as a block.
/// </summary>
Block = NativeMethods.CARETSTYLE_BLOCK
}
4 changes: 0 additions & 4 deletions Scintilla.NET/ChangeHistory.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ScintillaNET;

Expand Down
4 changes: 2 additions & 2 deletions Scintilla.NET/Document.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public struct Document
/// <returns>true if <paramref name="obj" /> is an instance of <see cref="Document" /> and equals the value of this instance; otherwise, false.</returns>
public override bool Equals(object obj)
{
return (obj is IntPtr) && Value == ((Document)obj).Value;
return obj is IntPtr && this.Value == ((Document)obj).Value;
}

/// <summary>
Expand All @@ -34,7 +34,7 @@ public override bool Equals(object obj)
/// <returns>A 32-bit signed integer hash code.</returns>
public override int GetHashCode()
{
return Value.GetHashCode();
return this.Value.GetHashCode();
}

/// <summary>
Expand Down
7 changes: 3 additions & 4 deletions Scintilla.NET/DoubleClickEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ public int Position
{
get
{
if (position == null)
position = scintilla.Lines.ByteToCharPosition(bytePosition);
this.position ??= this.scintilla.Lines.ByteToCharPosition(this.bytePosition);

return (int)position;
return (int)this.position;
}
}

Expand All @@ -57,6 +56,6 @@ public DoubleClickEventArgs(Scintilla scintilla, Keys modifiers, int bytePositio
Line = line;

if (bytePosition == -1)
position = -1;
this.position = -1;
}
}
7 changes: 3 additions & 4 deletions Scintilla.NET/DwellEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ public int Position
{
get
{
if (position == null)
position = scintilla.Lines.ByteToCharPosition(bytePosition);
this.position ??= this.scintilla.Lines.ByteToCharPosition(this.bytePosition);

return (int)position;
return (int)this.position;
}
}

Expand Down Expand Up @@ -54,6 +53,6 @@ public DwellEventArgs(Scintilla scintilla, int bytePosition, int x, int y)

// The position is not over text
if (bytePosition < 0)
position = bytePosition;
this.position = bytePosition;
}
}
11 changes: 8 additions & 3 deletions Scintilla.NET/FlagsConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul
{
return Enum.ToObject(enumType, 0).ToString();
}

ulong bits = 0;
List<Enum> enums = [];
var items = Enum.GetValues(enumType).Cast<Enum>()
Expand All @@ -46,7 +47,7 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul
(x.item.bits < y.item.bits) ? -1 : (x.item.bits > y.item.bits ? 1 : 0) // With the highest integer value
);

var item = items[maxIndex];
(Enum @enum, ulong bits, byte bitCount) item = items[maxIndex];

if ((valueBits & item.bits) == item.bits && (bits & item.bits) != item.bits)
{
Expand All @@ -55,9 +56,11 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul
enums.Add(item.@enum);
}
}

enums.Sort();
return string.Join(" | ", enums);
}

return base.ConvertTo(context, culture, value, destinationType);
}

Expand All @@ -67,13 +70,15 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c
{
Type t = context.PropertyDescriptor.PropertyType;
ulong bits = 0;
var nameList = str.Split('|').Select(x => x.Trim());
foreach (var name in nameList)
IEnumerable<string> nameList = str.Split('|').Select(x => x.Trim());
foreach (string name in nameList)
{
bits |= Convert.ToUInt64(Enum.Parse(t, name));
}

return Enum.ToObject(t, bits);
}

return base.ConvertFrom(context, culture, value);
}
}
4 changes: 3 additions & 1 deletion Scintilla.NET/FlagsEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ public override object EditValue(ITypeDescriptorContext context, IServiceProvide
{
if (value is Enum e && context.PropertyDescriptor.Attributes.OfType<FlagsAttribute>().Any())
{
IWindowsFormsEditorService svc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
var svc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

var control = new FlagsEditorControl(svc, e);
svc.DropDownControl(control);
return control.Value;
}
else
{
return base.EditValue(context, provider, value);
}
}
}
Loading

0 comments on commit a836fcb

Please sign in to comment.