mirror of
https://github.com/vczh-libraries/Release.git
synced 2026-03-27 09:29:42 +08:00
Update GacUI_Controls\TextEditor demo
This commit is contained in:
@@ -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">
|
||||
|
||||
@@ -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()
|
||||
|
||||
BIN
Tutorial/GacUI_Controls/TextEditor/UI/a.txt
Normal file
BIN
Tutorial/GacUI_Controls/TextEditor/UI/a.txt
Normal file
Binary file not shown.
BIN
Tutorial/GacUI_Controls/TextEditor/UI/a.xml
Normal file
BIN
Tutorial/GacUI_Controls/TextEditor/UI/a.xml
Normal file
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user