Update GacUI_Controls\TextEditor demo

This commit is contained in:
vczh
2016-01-09 15:53:29 -08:00
parent f824c1b643
commit 4615740ccf
7 changed files with 139 additions and 7 deletions

View File

@@ -27470,6 +27470,12 @@ GuiTextBoxCommonInterface
void GuiTextBoxCommonInterface::SetColorizer(Ptr<GuiTextBoxColorizerBase> value)
{
if (!filledDefaultColors)
{
filledDefaultColors = true;
CopyFrom(defaultColors, GetTextElement()->GetColors());
}
if(colorizer)
{
DetachTextEditCallback(colorizer);
@@ -27480,6 +27486,11 @@ GuiTextBoxCommonInterface
AttachTextEditCallback(colorizer);
GetTextElement()->SetColors(colorizer->GetColors());
}
else
{
GetTextElement()->SetColors(defaultColors);
GetTextElement()->ResetTextColorIndex(0);
}
}
//================ auto complete
@@ -39000,6 +39011,21 @@ GuiColorizedTextElement
}
}
void GuiColorizedTextElement::ResetTextColorIndex(vint index)
{
vint lineCount = lines.GetCount();
for (vint i = 0; i < lineCount; i++)
{
auto& line = lines.GetLine(i);
line.lexerFinalState = -1;
line.contextFinalState = -1;
for (vint j = 0; j < line.dataLength; j++)
{
line.att[j].colorIndex = index;
}
}
}
const FontProperties& GuiColorizedTextElement::GetFont()
{
return font;

View File

@@ -5307,6 +5307,11 @@ Colorized Plain Text (element)
/// <param name="value">The color table to bind.</param>
void SetColors(const ColorArray& value);
/// <summary>
/// Reset color of all characters
/// </summary>
/// <param name="index">Color index of all characters.</param>
void ResetTextColorIndex(vint index);
/// <summary>
/// Get the font configuration for all characters.
/// </summary>
/// <returns>The font configuration.</returns>
@@ -13974,6 +13979,7 @@ Common Interface
/// <summary>Common interface for text box controls.</summary>
class GuiTextBoxCommonInterface abstract : public Description<GuiTextBoxCommonInterface>
{
typedef collections::Array<elements::text::ColorEntry> ColorArray;
protected:
class ICallback : public virtual IDescriptable, public Description<ICallback>
{
@@ -14016,6 +14022,9 @@ Common Interface
Ptr<GuiTextBoxAutoCompleteBase> autoComplete;
Ptr<GuiTextBoxUndoRedoProcessor> undoRedoProcessor;
bool filledDefaultColors = false;
ColorArray defaultColors;
SpinLock elementModifyLock;
collections::List<Ptr<ICommonTextEditCallback>> textEditCallbacks;
Ptr<compositions::GuiShortcutKeyManager> internalShortcutKeyManager;

View File

@@ -45,21 +45,27 @@
</ToolstripCommand>
<ToolstripCommand ref.Name="commandEditUndo" Text="Undo" Image-uri="res://Images/EditUndo.png" ShortcutBuilder="Ctrl+Z">
<att.Enabled-bind>textBox.observe as _(_.CanUndo() on _.SelectionChanged)</att.Enabled-bind>
<ev.Executed>commandEditUndo_Executed</ev.Executed>
</ToolstripCommand>
<ToolstripCommand ref.Name="commandEditRedo" Text="Redo" Image-uri="res://Images/EditRedo.png" ShortcutBuilder="Ctrl+Y">
<att.Enabled-bind>textBox.observe as _(_.CanRedo() on _.SelectionChanged)</att.Enabled-bind>
<ev.Executed>commandEditRedo_Executed</ev.Executed>
</ToolstripCommand>
<ToolstripCommand ref.Name="commandEditCut" Text="Cut" Image-uri="res://Images/EditCut.png" ShortcutBuilder="Ctrl+X">
<att.Enabled-bind>textBox.observe as _(_.CanCut() on _.SelectionChanged)</att.Enabled-bind>
<ev.Executed>commandEditCut_Executed</ev.Executed>
</ToolstripCommand>
<ToolstripCommand ref.Name="commandEditCopy" Text="Copy" Image-uri="res://Images/EditCopy.png" ShortcutBuilder="Ctrl+C">
<att.Enabled-bind>textBox.observe as _(_.CanCopy() on _.SelectionChanged)</att.Enabled-bind>
<ev.Executed>commandEditCopy_Executed</ev.Executed>
</ToolstripCommand>
<ToolstripCommand ref.Name="commandEditPaste" Text="Paste" Image-uri="res://Images/EditPaste.png" ShortcutBuilder="Ctrl+V">
<att.Enabled-bind>textBox.observe as _(_.CanPaste() on self.ClipboardUpdated)</att.Enabled-bind>
<ev.Executed>commandEditPaste_Executed</ev.Executed>
</ToolstripCommand>
<ToolstripCommand ref.Name="commandEditDelete" Text="Delete" Image-uri="res://Images/EditDelete.png">
<att.Enabled-bind>textBox.SelectionText != ''</att.Enabled-bind>
<ev.Executed>commandEditDelete_Executed</ev.Executed>
</ToolstripCommand>
<ToolstripCommand ref.Name="commandEditSelect" Text="Select All" ShortcutBuilder="Ctrl+A">

View File

@@ -10,6 +10,78 @@ This file is generated by: Vczh GacUI Resource Code Generator
using namespace vl::stream;
namespace demo
{
class XmlColorizer : public GuiTextBoxRegexColorizer
{
public:
XmlColorizer()
{
text::ColorEntry entry=GetCurrentTheme()->GetDefaultTextBoxColorEntry();
SetDefaultColor(entry);
entry.normal.text=Color(0, 128, 0);
AddToken(L"/<!--([^/-]|-[^/-]|--[^>])*--/>", entry);
entry.normal.text=Color(128, 0, 255);
AddToken(L"/<!/[CDATA/[([^/]]|/][^/]]|/]/][^>])*/]/]/>", entry);
entry.normal.text=Color(0, 0, 0);
AddToken(L"\"[^\"]*\"", entry);
entry.normal.text=Color(0, 0, 255);
AddToken(L"[<>=]", entry);
entry.normal.text=Color(255, 0, 0);
AddToken(L"[a-zA-Z0-9_/-:]+", entry);
entry.normal.text=Color(163, 21, 21);
AddExtraToken(entry);
Setup();
}
void ColorizeTokenContextSensitive(int lineIndex, const wchar_t* text, vint start, vint length, vint& token, int& contextState)override
{
// 0 < 1 name 2 att > 0
switch(token)
{
case 3:
if(length==1)
{
switch(text[start])
{
case '<':
contextState=1;
break;
case '>':
contextState=0;
break;
}
}
break;
case 4:
switch(contextState)
{
case 0:
token=-1;
break;
case 1:
token=5;
contextState=2;
break;
}
break;
}
}
vint GetContextStartState()override
{
return 0;
}
};
}
namespace demo
{
// #region CLASS_MEMBER_GUIEVENT_HANDLER (DO NOT PUT OTHER CONTENT IN THIS #region.)
@@ -134,7 +206,9 @@ namespace demo
textBox->Select(TextPos(), TextPos());
textBox->SetFocus();
textBox->ClearUndoRedo();
if (dialogOpen->GetFilterIndex() == 1)
fileName = dialogOpen->GetFileName();
if (INVLOC.EndsWith(fileName, L".xml", Locale::IgnoreCase))
{
SetupXmlConfig();
}
@@ -142,7 +216,6 @@ namespace demo
{
SetupTextConfig();
}
fileName = dialogOpen->GetFileName();
}
else
{
@@ -154,12 +227,13 @@ namespace demo
void MainWindow::SaveFile(bool saveAs)
{
if (saveAs || fileName == L"")
WString targetFileName = fileName;
if (saveAs || targetFileName == L"")
{
dialogSave->SetFilterIndex(isXml ? 1 : 0);
if (dialogSave->ShowDialog())
{
fileName = dialogSave->GetFileName();
targetFileName = dialogSave->GetFileName();
}
else
{
@@ -167,7 +241,7 @@ namespace demo
}
}
FileStream fileStream(fileName, FileStream::WriteOnly);
FileStream fileStream(targetFileName, FileStream::WriteOnly);
if (fileStream.IsAvailable())
{
BomEncoder encoder(BomEncoder::Utf16);
@@ -176,6 +250,15 @@ namespace demo
writer.WriteString(textBox->GetText());
textBox->NotifyModificationSaved();
fileName = targetFileName;
if (INVLOC.EndsWith(fileName, L".xml", Locale::IgnoreCase))
{
SetupXmlConfig();
}
else
{
SetupTextConfig();
}
}
else
{
@@ -185,12 +268,20 @@ namespace demo
void MainWindow::SetupTextConfig()
{
isXml = false;
if (isXml == true)
{
isXml = false;
textBox->SetColorizer(nullptr);
}
}
void MainWindow::SetupXmlConfig()
{
isXml = true;
if (isXml == false)
{
isXml = true;
textBox->SetColorizer(new XmlColorizer);
}
}
MainWindow::MainWindow()

Binary file not shown.

Binary file not shown.