mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 11:12:36 +01:00
Work on webbrowser text box
This commit is contained in:
parent
3077417749
commit
9ff9940bcf
@ -1,9 +1,9 @@
|
||||
using Nikse.SubtitleEdit.Core.Common;
|
||||
using Nikse.SubtitleEdit.Controls.WebBrowser;
|
||||
using Nikse.SubtitleEdit.Core.Common;
|
||||
using Nikse.SubtitleEdit.Logic;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using Nikse.SubtitleEdit.Controls.WebBrowser;
|
||||
|
||||
namespace Nikse.SubtitleEdit.Controls
|
||||
{
|
||||
@ -59,7 +59,6 @@ namespace Nikse.SubtitleEdit.Controls
|
||||
oldEnabled = _htmlBox.Enabled;
|
||||
}
|
||||
|
||||
|
||||
BorderStyle = BorderStyle.None;
|
||||
Padding = new Padding(1);
|
||||
BackColor = SystemColors.WindowFrame;
|
||||
@ -75,7 +74,6 @@ namespace Nikse.SubtitleEdit.Controls
|
||||
_richTextBoxTemp = null;
|
||||
if (useSyntaxColoring)
|
||||
{
|
||||
|
||||
if (_useWebBrowser)
|
||||
{
|
||||
_uiTextBox = null;
|
||||
@ -83,19 +81,13 @@ namespace Nikse.SubtitleEdit.Controls
|
||||
Controls.Add(_htmlBox);
|
||||
_htmlBox.Dock = DockStyle.Fill;
|
||||
_htmlBox.Initialize();
|
||||
|
||||
_htmlBox.TextChanged += TextChangedHighlight;
|
||||
_htmlBox.Enter += (sender, args) => { BackColor = SystemColors.Highlight; };
|
||||
_htmlBox.Leave += (sender, args) => { BackColor = SystemColors.WindowFrame; };
|
||||
_htmlBox.TextChanged += (sender, args) => { TextChanged?.Invoke(sender, args); };
|
||||
_htmlBox.KeyDown += (sender, args) => { KeyDown?.Invoke(sender, args); };
|
||||
_htmlBox.KeyUp += (sender, args) => { KeyUp?.Invoke(sender, args); };
|
||||
_htmlBox.MouseClick += (sender, args) => { MouseClick?.Invoke(sender, args); };
|
||||
_htmlBox.MouseMove += (sender, args) => { MouseMove?.Invoke(sender, args); };
|
||||
|
||||
//TODO?
|
||||
//textBox.MouseDown += SETextBox_MouseDown;
|
||||
//textBox.MouseUp += SETextBox_MouseUp;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -496,7 +488,7 @@ namespace Nikse.SubtitleEdit.Controls
|
||||
{
|
||||
return _uiTextBox.Enabled;
|
||||
}
|
||||
|
||||
|
||||
if (_htmlBox != null)
|
||||
{
|
||||
return _htmlBox.Enabled;
|
||||
|
@ -3,6 +3,7 @@ using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
|
||||
@ -71,7 +72,38 @@ namespace Nikse.SubtitleEdit.Controls.WebBrowser
|
||||
}
|
||||
|
||||
var text = (Document.InvokeScript("getText") ?? string.Empty).ToString();
|
||||
return string.Join(Environment.NewLine, text.SplitToLines());
|
||||
var sb = new StringBuilder();
|
||||
int max = text.Length;
|
||||
int i = 0;
|
||||
var isNewLine = false;
|
||||
while (i < max)
|
||||
{
|
||||
var ch = text[i];
|
||||
if (ch == '\r')
|
||||
{
|
||||
//continue
|
||||
}
|
||||
else if (ch == '\n')
|
||||
{
|
||||
i++;
|
||||
if (!isNewLine)
|
||||
{
|
||||
sb.Append(Environment.NewLine);
|
||||
}
|
||||
|
||||
isNewLine = !isNewLine;
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append(ch);
|
||||
isNewLine = false;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
var result = sb.ToString();
|
||||
return result;
|
||||
}
|
||||
set
|
||||
{
|
||||
@ -100,8 +132,7 @@ namespace Nikse.SubtitleEdit.Controls.WebBrowser
|
||||
Document.InvokeScript("setTextDirection", new object[] { code });
|
||||
}
|
||||
|
||||
var text = string.Join("\n", value.SplitToLines());
|
||||
Document.InvokeScript("setText", new object[] { text });
|
||||
Document.InvokeScript("setText", new object[] { value });
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -246,11 +277,6 @@ namespace Nikse.SubtitleEdit.Controls.WebBrowser
|
||||
Leave?.Invoke(this, new KeyEventArgs(0));
|
||||
}
|
||||
|
||||
public void ClientChanged()
|
||||
{
|
||||
TextChanged?.Invoke(this, new KeyEventArgs(0));
|
||||
}
|
||||
|
||||
public void ClientKeyUp(int keyCode, bool ctrlKey, bool shiftKey, bool altKey)
|
||||
{
|
||||
var keyData = (Keys)keyCode;
|
||||
@ -268,11 +294,13 @@ namespace Nikse.SubtitleEdit.Controls.WebBrowser
|
||||
}
|
||||
|
||||
KeyUp?.Invoke(this, new KeyEventArgs(keyData));
|
||||
TextChanged?.Invoke(this, new KeyEventArgs(0));
|
||||
}
|
||||
|
||||
public void ClientClick()
|
||||
{
|
||||
MouseClick?.Invoke(this, new MouseEventArgs(MouseButtons.Left, 1, 1, 1, 1));
|
||||
TextChanged?.Invoke(this, new KeyEventArgs(0));
|
||||
}
|
||||
|
||||
public void ClientMouseMove()
|
||||
|
@ -83,10 +83,6 @@
|
||||
window.external.ClientKeyUp(e.keyCode, e.ctrlKey, e.shiftKey, e.altKey);
|
||||
});
|
||||
|
||||
getById("myContent").addEventListener("change", function (e) {
|
||||
window.external.ClientChanged();
|
||||
});
|
||||
|
||||
getById("myContent").addEventListener("click", function (e) {
|
||||
window.external.ClientClick();
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user