1
0
mirror of synced 2024-11-12 02:00:50 +01:00

Add SHIFT JIS encoding to text editor encoding menu

This commit is contained in:
KillzXGaming 2020-04-05 11:16:16 -04:00
parent 259f681940
commit af07359579
2 changed files with 67 additions and 25 deletions

View File

@ -32,13 +32,13 @@
this.stContextMenuStrip1 = new Toolbox.Library.Forms.STMenuStrip();
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.viewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.wordWrapToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.searchToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.findToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.encodingToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.findAllResultsPanel1 = new ScintillaNET_FindReplaceDialog.FindAllResults.FindAllResultsPanel();
this.splitter1 = new System.Windows.Forms.Splitter();
this.viewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.wordWrapToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.stContextMenuStrip1.SuspendLayout();
this.SuspendLayout();
//
@ -60,6 +60,7 @@
//
// stContextMenuStrip1
//
this.stContextMenuStrip1.HighlightSelectedTab = false;
this.stContextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.fileToolStripMenuItem,
this.viewToolStripMenuItem,
@ -86,6 +87,22 @@
this.saveToolStripMenuItem.Text = "Save";
this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click);
//
// viewToolStripMenuItem
//
this.viewToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.wordWrapToolStripMenuItem});
this.viewToolStripMenuItem.Name = "viewToolStripMenuItem";
this.viewToolStripMenuItem.Size = new System.Drawing.Size(44, 20);
this.viewToolStripMenuItem.Text = "View";
//
// wordWrapToolStripMenuItem
//
this.wordWrapToolStripMenuItem.CheckOnClick = true;
this.wordWrapToolStripMenuItem.Name = "wordWrapToolStripMenuItem";
this.wordWrapToolStripMenuItem.Size = new System.Drawing.Size(134, 22);
this.wordWrapToolStripMenuItem.Text = "Word Wrap";
this.wordWrapToolStripMenuItem.Click += new System.EventHandler(this.wordWrapToolStripMenuItem_Click);
//
// searchToolStripMenuItem
//
this.searchToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
@ -126,22 +143,6 @@
this.splitter1.TabIndex = 5;
this.splitter1.TabStop = false;
//
// viewToolStripMenuItem
//
this.viewToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.wordWrapToolStripMenuItem});
this.viewToolStripMenuItem.Name = "viewToolStripMenuItem";
this.viewToolStripMenuItem.Size = new System.Drawing.Size(44, 20);
this.viewToolStripMenuItem.Text = "View";
//
// wordWrapToolStripMenuItem
//
this.wordWrapToolStripMenuItem.CheckOnClick = true;
this.wordWrapToolStripMenuItem.Name = "wordWrapToolStripMenuItem";
this.wordWrapToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.wordWrapToolStripMenuItem.Text = "Word Wrap";
this.wordWrapToolStripMenuItem.Click += new System.EventHandler(this.wordWrapToolStripMenuItem_Click);
//
// TextEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

View File

@ -9,6 +9,7 @@ using System.Threading.Tasks;
using System.Windows.Forms;
using ScintillaNET;
using ScintillaNET_FindReplaceDialog;
using Toolbox.Library.IO;
namespace Toolbox.Library.Forms
{
@ -25,6 +26,8 @@ namespace Toolbox.Library.Forms
FindReplace findReplaceDialog;
public static Encoding TextEncoding = Encoding.Default;
private void ResetTypes()
{
IsYAML = false;
@ -172,6 +175,8 @@ namespace Toolbox.Library.Forms
return Color.FromArgb(255, (byte)(rgb >> 16), (byte)(rgb >> 8), (byte)rgb);
}
public List<Encoding> EncodingOptions = new List<Encoding>();
public TextEditor()
{
InitializeComponent();
@ -189,16 +194,34 @@ namespace Toolbox.Library.Forms
findAllResultsPanel1.ForeColor = FormThemes.BaseTheme.TextForeColor;
findAllResultsPanel1.Scintilla.SetWhitespaceBackColor(true, Color.FromArgb(50, 50, 50));
// foreach (var encoding in Encoding.GetEncodings())
// encodingToolStripMenuItem.DropDownItems.Add(encoding.DisplayName);
EncodingOptions.Add(Encoding.Default);
EncodingOptions.Add(Encoding.GetEncoding("shift_jis"));
foreach (var encoding in EncodingOptions) {
var toolstrip = new ToolStripMenuItem(encoding.EncodingName, null, encodingMenuClick);
encodingToolStripMenuItem.DropDownItems.Add(toolstrip);
}
ReloadEncodingMenuToggle();
FillEditor("");
}
private void ReloadEncodingMenuToggle()
{
foreach (ToolStripMenuItem encoding in encodingToolStripMenuItem.DropDownItems)
{
if (encoding.Text == TextEncoding.EncodingName)
encoding.Checked = true;
else
encoding.Checked = false;
}
}
private Color BACK_COLOR = Color.FromArgb(30, 30, 30);
private Color FORE_COLOR = Color.White;
public void AddContextMenu(STToolStripItem menu, EventHandler handler)
public void AddContextMenu(STToolStripItem menu)
{
foreach (ToolStripItem item in stContextMenuStrip1.Items)
if (item.Text == menu.Text)
@ -232,15 +255,17 @@ namespace Toolbox.Library.Forms
return scintilla1.Text;
}
private byte[] Data;
public void FillEditor(System.IO.Stream data)
{
using (var stringReader = new System.IO.StreamReader(data, true))
FillEditor(stringReader.ReadToEnd());
Data = data.ToBytes();
ReloadText();
}
public void FillEditor(byte[] Data)
public void FillEditor(byte[] data)
{
FillEditor(Encoding.Default.GetString(Data));
Data = data;
ReloadText();
}
public void FillEditor(string Text)
@ -417,5 +442,21 @@ namespace Toolbox.Library.Forms
else
scintilla1.WrapMode = WrapMode.None;
}
private void encodingMenuClick(object sender, EventArgs e)
{
var menu = (ToolStripMenuItem)sender;
var index = encodingToolStripMenuItem.DropDownItems.IndexOf(menu);
if (index != -1)
{
TextEncoding = EncodingOptions[index];
ReloadEncodingMenuToggle();
ReloadText();
}
}
private void ReloadText() {
FillEditor(TextEncoding.GetString(Data));
}
}
}