This commit is contained in:
Zihan Chen
2018-04-02 03:51:43 -07:00
parent 13842387a3
commit 3a3a05484c
4 changed files with 37 additions and 19 deletions
@@ -6,6 +6,9 @@
<![CDATA[
@cpp:UserImpl
func CanCloseFile() : bool {}
@cpp:UserImpl
func LoadFile(path : string) : bool {}
@cpp:UserImpl
func OpenFile(filterIndex : int) : bool {}
@@ -105,6 +105,7 @@ namespace vl
BEGIN_CLASS_MEMBER(::demo::MainWindow)
CLASS_MEMBER_CONSTRUCTOR(::demo::MainWindow*(), NO_PARAMETER)
CLASS_MEMBER_METHOD(CanCloseFile, NO_PARAMETER)
CLASS_MEMBER_METHOD(LoadFile, { L"path" })
CLASS_MEMBER_METHOD(OpenFile, { L"filterIndex" })
CLASS_MEMBER_METHOD(SaveFile, { L"saveAs" })
CLASS_MEMBER_METHOD(SetupTextConfig, NO_PARAMETER)
@@ -58,6 +58,37 @@ namespace demo
}
}
USERIMPL(/* ::demo::MainWindow */)
bool MainWindow::LoadFile(const ::vl::WString& path)
{
stream::FileStream fileStream(path, stream::FileStream::ReadOnly);
if (fileStream.IsAvailable())
{
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
{
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
@@ -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();