From 3a3a05484c9276d7cb9749e1c392e90f5b39af03 Mon Sep 17 00:00:00 2001 From: Zihan Chen Date: Mon, 2 Apr 2018 03:51:43 -0700 Subject: [PATCH] ... --- .../TextEditor/UI/MainWindow.xml | 3 ++ .../TextEditor/UI/Source/DemoReflection.cpp | 1 + .../TextEditor/UI/Source/MainWindow.cpp | 51 ++++++++++++------- .../TextEditor/UI/Source/MainWindow.h | 1 + 4 files changed, 37 insertions(+), 19 deletions(-) diff --git a/Tutorial/GacUI_Controls/TextEditor/UI/MainWindow.xml b/Tutorial/GacUI_Controls/TextEditor/UI/MainWindow.xml index 46b1b92e..47ed403a 100644 --- a/Tutorial/GacUI_Controls/TextEditor/UI/MainWindow.xml +++ b/Tutorial/GacUI_Controls/TextEditor/UI/MainWindow.xml @@ -6,6 +6,9 @@ SetText(reader.ReadToEnd()); + textBox->Select(TextPos(), TextPos()); + textBox->SetFocus(); + textBox->ClearUndoRedo(); + + fileName = dialogOpen->GetFileName(); + if (INVLOC.EndsWith(fileName, L".xml", Locale::IgnoreCase)) + { + SetupXmlConfig(); + } + else + { + SetupTextConfig(); + } + return true; + } + else + { + return false; + } + } + USERIMPL(/* ::demo::MainWindow */) bool MainWindow::OpenFile(::vl::vint filterIndex) { @@ -66,26 +97,8 @@ namespace demo dialogOpen->SetFilterIndex(filterIndex); if (dialogOpen->ShowDialog()) { - stream::FileStream fileStream(dialogOpen->GetFileName(), stream::FileStream::ReadOnly); - if (fileStream.IsAvailable()) + if (LoadFile(dialogOpen->GetFileName())) { - stream::BomDecoder decoder; - stream::DecoderStream decoderStream(fileStream, decoder); - stream::StreamReader reader(decoderStream); - textBox->SetText(reader.ReadToEnd()); - textBox->Select(TextPos(), TextPos()); - textBox->SetFocus(); - textBox->ClearUndoRedo(); - - fileName = dialogOpen->GetFileName(); - if (INVLOC.EndsWith(fileName, L".xml", Locale::IgnoreCase)) - { - SetupXmlConfig(); - } - else - { - SetupTextConfig(); - } return true; } else diff --git a/Tutorial/GacUI_Controls/TextEditor/UI/Source/MainWindow.h b/Tutorial/GacUI_Controls/TextEditor/UI/Source/MainWindow.h index 050df45d..665b208b 100644 --- a/Tutorial/GacUI_Controls/TextEditor/UI/Source/MainWindow.h +++ b/Tutorial/GacUI_Controls/TextEditor/UI/Source/MainWindow.h @@ -68,6 +68,7 @@ namespace demo #endif public: bool CanCloseFile(); + bool LoadFile(const ::vl::WString& path); bool OpenFile(::vl::vint filterIndex); bool SaveFile(bool saveAs); void SetupTextConfig();