mirror of
https://github.com/vczh-libraries/Release.git
synced 2026-05-26 01:35:31 +08:00
Update GacUI_Controls\TextEditor demo
This commit is contained in:
@@ -77,7 +77,21 @@
|
||||
Input="DisplayYesNoCancel"
|
||||
Icon="IconQuestion"
|
||||
Title-eval="self.Text"
|
||||
Text="Do you want to save the file before closing this application?"
|
||||
Text="Do you want to save this file?"
|
||||
/>
|
||||
|
||||
<MessageDialog ref.Name="dialogCannotOpen"
|
||||
Input="DisplayOK"
|
||||
Icon="IconError"
|
||||
Title-eval="self.Text"
|
||||
Text="Cannot open the selected file."
|
||||
/>
|
||||
|
||||
<MessageDialog ref.Name="dialogCannotSave"
|
||||
Input="DisplayOK"
|
||||
Icon="IconError"
|
||||
Title-eval="self.Text"
|
||||
Text="Cannot save the selected file."
|
||||
/>
|
||||
|
||||
<OpenFileDialog ref.Name="dialogOpen"
|
||||
|
||||
@@ -40,6 +40,8 @@ namespace demo
|
||||
vl::presentation::controls::GuiToolstripCommand* commandFileOpenXml;
|
||||
vl::presentation::controls::GuiToolstripCommand* commandFileSave;
|
||||
vl::presentation::controls::GuiToolstripCommand* commandFileSaveAs;
|
||||
vl::presentation::controls::GuiMessageDialog* dialogCannotOpen;
|
||||
vl::presentation::controls::GuiMessageDialog* dialogCannotSave;
|
||||
vl::presentation::controls::GuiOpenFileDialog* dialogOpen;
|
||||
vl::presentation::controls::GuiMessageDialog* dialogQueryClose;
|
||||
vl::presentation::controls::GuiSaveFileDialog* dialogSave;
|
||||
@@ -67,6 +69,8 @@ namespace demo
|
||||
GUI_INSTANCE_REFERENCE(commandFileOpenXml);
|
||||
GUI_INSTANCE_REFERENCE(commandFileSave);
|
||||
GUI_INSTANCE_REFERENCE(commandFileSaveAs);
|
||||
GUI_INSTANCE_REFERENCE(dialogCannotOpen);
|
||||
GUI_INSTANCE_REFERENCE(dialogCannotSave);
|
||||
GUI_INSTANCE_REFERENCE(dialogOpen);
|
||||
GUI_INSTANCE_REFERENCE(dialogQueryClose);
|
||||
GUI_INSTANCE_REFERENCE(dialogSave);
|
||||
@@ -98,6 +102,8 @@ namespace demo
|
||||
,commandFileOpenXml(0)
|
||||
,commandFileSave(0)
|
||||
,commandFileSaveAs(0)
|
||||
,dialogCannotOpen(0)
|
||||
,dialogCannotSave(0)
|
||||
,dialogOpen(0)
|
||||
,dialogQueryClose(0)
|
||||
,dialogSave(0)
|
||||
|
||||
@@ -8,6 +8,8 @@ This file is generated by: Vczh GacUI Resource Code Generator
|
||||
|
||||
#include "Demo.h"
|
||||
|
||||
using namespace vl::stream;
|
||||
|
||||
namespace demo
|
||||
{
|
||||
// #region CLASS_MEMBER_GUIEVENT_HANDLER (DO NOT PUT OTHER CONTENT IN THIS #region.)
|
||||
@@ -18,14 +20,17 @@ namespace demo
|
||||
|
||||
void MainWindow::commandEditCopy_Executed(GuiGraphicsComposition* sender, vl::presentation::compositions::GuiEventArgs& arguments)
|
||||
{
|
||||
textBox->Copy();
|
||||
}
|
||||
|
||||
void MainWindow::commandEditCut_Executed(GuiGraphicsComposition* sender, vl::presentation::compositions::GuiEventArgs& arguments)
|
||||
{
|
||||
textBox->Cut();
|
||||
}
|
||||
|
||||
void MainWindow::commandEditDelete_Executed(GuiGraphicsComposition* sender, vl::presentation::compositions::GuiEventArgs& arguments)
|
||||
{
|
||||
textBox->SetSelectionText(L"");
|
||||
}
|
||||
|
||||
void MainWindow::commandEditFind_Executed(GuiGraphicsComposition* sender, vl::presentation::compositions::GuiEventArgs& arguments)
|
||||
@@ -34,54 +39,160 @@ namespace demo
|
||||
|
||||
void MainWindow::commandEditPaste_Executed(GuiGraphicsComposition* sender, vl::presentation::compositions::GuiEventArgs& arguments)
|
||||
{
|
||||
textBox->Paste();
|
||||
}
|
||||
|
||||
void MainWindow::commandEditRedo_Executed(GuiGraphicsComposition* sender, vl::presentation::compositions::GuiEventArgs& arguments)
|
||||
{
|
||||
textBox->Redo();
|
||||
}
|
||||
|
||||
void MainWindow::commandEditSelect_Executed(GuiGraphicsComposition* sender, vl::presentation::compositions::GuiEventArgs& arguments)
|
||||
{
|
||||
textBox->SelectAll();
|
||||
}
|
||||
|
||||
void MainWindow::commandEditUndo_Executed(GuiGraphicsComposition* sender, vl::presentation::compositions::GuiEventArgs& arguments)
|
||||
{
|
||||
textBox->Undo();
|
||||
}
|
||||
|
||||
void MainWindow::commandFileExit_Executed(GuiGraphicsComposition* sender, vl::presentation::compositions::GuiEventArgs& arguments)
|
||||
{
|
||||
if (CanCloseFile())
|
||||
{
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::commandFileNewText_Executed(GuiGraphicsComposition* sender, vl::presentation::compositions::GuiEventArgs& arguments)
|
||||
{
|
||||
if (CanCloseFile())
|
||||
{
|
||||
textBox->SetText(L"");
|
||||
textBox->ClearUndoRedo();
|
||||
SetupTextConfig();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::commandFileNewXml_Executed(GuiGraphicsComposition* sender, vl::presentation::compositions::GuiEventArgs& arguments)
|
||||
{
|
||||
if (CanCloseFile())
|
||||
{
|
||||
textBox->SetText(L"");
|
||||
textBox->ClearUndoRedo();
|
||||
SetupXmlConfig();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::commandFileOpenText_Executed(GuiGraphicsComposition* sender, vl::presentation::compositions::GuiEventArgs& arguments)
|
||||
{
|
||||
OpenFile(0);
|
||||
}
|
||||
|
||||
void MainWindow::commandFileOpenXml_Executed(GuiGraphicsComposition* sender, vl::presentation::compositions::GuiEventArgs& arguments)
|
||||
{
|
||||
OpenFile(1);
|
||||
}
|
||||
|
||||
void MainWindow::commandFileOpen_Executed(GuiGraphicsComposition* sender, vl::presentation::compositions::GuiEventArgs& arguments)
|
||||
{
|
||||
OpenFile(dialogOpen->GetFilterIndex());
|
||||
}
|
||||
|
||||
void MainWindow::commandFileSaveAs_Executed(GuiGraphicsComposition* sender, vl::presentation::compositions::GuiEventArgs& arguments)
|
||||
{
|
||||
SaveFile(true);
|
||||
}
|
||||
|
||||
void MainWindow::commandFileSave_Executed(GuiGraphicsComposition* sender, vl::presentation::compositions::GuiEventArgs& arguments)
|
||||
{
|
||||
SaveFile(false);
|
||||
}
|
||||
|
||||
// #endregion CLASS_MEMBER_GUIEVENT_HANDLER
|
||||
|
||||
bool MainWindow::CanCloseFile()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void MainWindow::OpenFile(vint filterIndex)
|
||||
{
|
||||
if (CanCloseFile())
|
||||
{
|
||||
dialogOpen->SetFilterIndex(filterIndex);
|
||||
if (dialogOpen->ShowDialog())
|
||||
{
|
||||
FileStream fileStream(dialogOpen->GetFileName(), FileStream::ReadOnly);
|
||||
if (fileStream.IsAvailable())
|
||||
{
|
||||
BomDecoder decoder;
|
||||
DecoderStream decoderStream(fileStream, decoder);
|
||||
StreamReader reader(decoderStream);
|
||||
textBox->SetText(reader.ReadToEnd());
|
||||
textBox->Select(TextPos(), TextPos());
|
||||
textBox->SetFocus();
|
||||
textBox->ClearUndoRedo();
|
||||
if (dialogOpen->GetFilterIndex() == 1)
|
||||
{
|
||||
SetupXmlConfig();
|
||||
}
|
||||
else
|
||||
{
|
||||
SetupTextConfig();
|
||||
}
|
||||
fileName = dialogOpen->GetFileName();
|
||||
}
|
||||
else
|
||||
{
|
||||
dialogCannotOpen->ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::SaveFile(bool saveAs)
|
||||
{
|
||||
if (saveAs || fileName == L"")
|
||||
{
|
||||
dialogSave->SetFilterIndex(isXml ? 1 : 0);
|
||||
if (dialogSave->ShowDialog())
|
||||
{
|
||||
fileName = dialogSave->GetFileName();
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
FileStream fileStream(fileName, FileStream::WriteOnly);
|
||||
if (fileStream.IsAvailable())
|
||||
{
|
||||
BomEncoder encoder(BomEncoder::Utf16);
|
||||
EncoderStream encoderStream(fileStream, encoder);
|
||||
StreamWriter writer(encoderStream);
|
||||
writer.WriteString(textBox->GetText());
|
||||
textBox->NotifyModificationSaved();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
dialogCannotSave->ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::SetupTextConfig()
|
||||
{
|
||||
isXml = false;
|
||||
}
|
||||
|
||||
void MainWindow::SetupXmlConfig()
|
||||
{
|
||||
isXml = true;
|
||||
}
|
||||
|
||||
MainWindow::MainWindow()
|
||||
{
|
||||
InitializeComponents();
|
||||
|
||||
@@ -38,6 +38,16 @@ namespace demo
|
||||
void commandFileSaveAs_Executed(GuiGraphicsComposition* sender, vl::presentation::compositions::GuiEventArgs& arguments);
|
||||
void commandFileSave_Executed(GuiGraphicsComposition* sender, vl::presentation::compositions::GuiEventArgs& arguments);
|
||||
// #endregion CLASS_MEMBER_GUIEVENT_HANDLER
|
||||
|
||||
private:
|
||||
WString fileName;
|
||||
bool isXml = false;
|
||||
|
||||
bool CanCloseFile();
|
||||
void OpenFile(vint filterIndex);
|
||||
void SaveFile(bool saveAs);
|
||||
void SetupTextConfig();
|
||||
void SetupXmlConfig();
|
||||
public:
|
||||
MainWindow();
|
||||
~MainWindow();
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user