Skip to content

Commit

Permalink
Added Support for ANSI as UTF-8
Browse files Browse the repository at this point in the history
  • Loading branch information
Pascal-Krenckel committed May 26, 2022
1 parent dc3d2d3 commit 672d3f5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 14 deletions.
31 changes: 23 additions & 8 deletions NppGZipFileViewer/Forms/SettingsDialog.Designer.cs

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

3 changes: 2 additions & 1 deletion NppGZipFileViewer/Forms/SettingsDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ public Preferences Preferences
{
get
{
return new Preferences(chk_DecompressAll.Checked, lst_Suffixes.Items.Cast<string>());
return new Preferences(chk_DecompressAll.Checked, chk_OpenAsUTF8.Checked,lst_Suffixes.Items.Cast<string>());
}
set
{
chk_DecompressAll.Checked = value.DecompressAll;
chk_OpenAsUTF8.Checked = value.OpenAsUTF8;
lst_Suffixes.Items.AddRange(value.Extensions.ToArray());
}
}
Expand Down
14 changes: 12 additions & 2 deletions NppGZipFileViewer/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Main
public static void OnNotification(ScNotification notification)
{
switch (notification.Header.Code)
{
{
case (uint)NppMsg.NPPN_FILEOPENED:
if (Preferences.DecompressAll || Preferences.HasGZipSuffix(nppGateway.GetFullPathFromBufferId(notification.Header.IdFrom)))
TryDecompress(notification);
Expand Down Expand Up @@ -174,16 +174,26 @@ private static void TryDecompress(ScNotification notification)
{
using var decodedContentStream = NppGZipFileViewerHelper.Decode(gzContentStream);
NppGZipFileViewerHelper.SetText(decodedContentStream);

var encoding = nppGateway.GetBufferEncoding(notification.Header.IdFrom);


if (encoding == 0 && Preferences.OpenAsUTF8)
Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_MENUCOMMAND, 0, (int)NppMenuCmd.IDM_FORMAT_AS_UTF_8);

Win32.SendMessage(PluginBase.GetCurrentScintilla(), SciMsg.SCI_GOTOPOS, 0, 0);
Win32.SendMessage(PluginBase.GetCurrentScintilla(), SciMsg.SCI_EMPTYUNDOBUFFER, 0, 0);
Win32.SendMessage(PluginBase.GetCurrentScintilla(), SciMsg.SCI_SETSAVEPOINT, 0, 0);

fileTracker.Include(notification.Header.IdFrom, path);
}
catch (InvalidDataException ex)
{
if (Preferences.HasGZipSuffix(path))
fileTracker.Include(notification.Header.IdFrom, path);
}
var endoging = nppGateway.GetBufferEncoding(notification.Header.IdFrom);
var ret = Win32.SendMessage(PluginBase.GetCurrentScintilla(), SciMsg.SCI_GETCODEPAGE, 0, 0).ToInt64();

}
internal static void CommandMenuInit()
Expand All @@ -203,7 +213,7 @@ internal static void CommandMenuInit()
}
catch (Exception ex)
{
Preferences = new Preferences(false, ".gz");
Preferences = new Preferences(false, false,".gz");
}

PluginBase.SetCommand(0, "Toogle Compression", ToogleCompress, false);
Expand Down
9 changes: 6 additions & 3 deletions NppGZipFileViewer/Preferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ namespace NppGZipFileViewer
public class Preferences
{
public bool DecompressAll { get; set; }

public bool OpenAsUTF8 { get; set; }
public List<string> Extensions { get; set; }


public Preferences() : this(false) { }
public Preferences(bool decompressAll, IEnumerable<string> exts)
public Preferences() : this(false,false) { }
public Preferences(bool decompressAll,bool openAsUTF8 ,IEnumerable<string> exts)
{
Extensions = exts.ToList();
DecompressAll = decompressAll;
OpenAsUTF8 = openAsUTF8;
}
public Preferences(bool decompressAll, params string[] exts) : this(decompressAll, (IEnumerable<string>)exts)
public Preferences(bool decompressAll,bool openAsUTF8, params string[] exts) : this(decompressAll,openAsUTF8, (IEnumerable<string>)exts)
{
}

Expand Down

0 comments on commit 672d3f5

Please sign in to comment.