Skip to content

Commit

Permalink
xrEProps: TextEdit – done.
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Mar 2, 2018
1 parent 816b080 commit 4fa07eb
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 15 deletions.
108 changes: 105 additions & 3 deletions src/editors/xrECore/Props/TextEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,81 @@ System::Void TextEdit::buttonClear_Click(System::Object^ sender, System::EventAr

System::Void TextEdit::textBox1_SelectionChanged(System::Object^ sender, System::EventArgs^ e)
{
buttonOk->Enabled = textBox1->Modified;

auto line = textBox1->GetLineFromCharIndex(textBox1->SelectionStart);
auto currline = textBox1->GetFirstCharIndexOfCurrentLine();
auto charpos = textBox1->SelectionStart - currline;
toolStripStatusLabel1->Text = (line + 1) + " : " + (charpos + 1);
}

System::Void TextEdit::buttonApply_Click(System::Object^ sender, System::EventArgs^ e)
{
if (!onApplyClick->empty())
{
msclr::interop::marshal_context ctx;
if ((*onApplyClick)(ctx.marshal_as<pcstr>(textBox1->Text)))
{
*m_text = ctx.marshal_as<pcstr>(textBox1->Text);
}
}
else
{
msclr::interop::marshal_context ctx;
*m_text = ctx.marshal_as<pcstr>(textBox1->Text);
}
textBox1->Modified = false;
buttonOk->Enabled = false;
toolStripStatusLabel3->Text = "Successful save";
}

System::Void TextEdit::textBox1_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e)
{
if (!onCodeInsight->empty() && e->KeyChar == (Char)Keys::Space
&& textBox1->ModifierKeys == (Keys::Control & Keys::Shift))
{
xr_string src_line, hint;
src_line = textBox1->GetLineFromCharIndex(textBox1->SelectionStart);
bool result = true;
(*onCodeInsight)(src_line, hint, result);
if (result)
{
toolStripStatusLabel3->Text = gcnew String((xr_string("Hint: ") + hint).c_str());
toolStripStatusLabel3->ToolTipText = gcnew String(hint.c_str());
}
else
{
toolStripStatusLabel3->Text = gcnew String((xr_string("Error: ") + hint).c_str());
toolStripStatusLabel3->ToolTipText = gcnew String(hint.c_str());
}
}
else if (e->KeyChar == (Char)Keys::Enter && textBox1->ModifierKeys == Keys::Control)
{
buttonOk->PerformClick();
}
}

TextEdit::TextEdit(xr_string& text, pcstr caption, bool read_only, int lim, pcstr apply_name, TOnApplyClick on_apply, TOnCloseClick on_close, TOnCodeInsight on_insight)
{
Text = gcnew String(caption);
m_text = &text;
textBox1->ReadOnly = read_only;
textBox1->Text = gcnew String(text.c_str());
textBox1->MaxLength = lim;

buttonApply->Text = gcnew String(apply_name);

onApplyClick = &on_apply;
onCloseClick = &on_close;
onCodeInsight = &on_insight;

textBox1_SelectionChanged(nullptr, nullptr);
Show();
}

bool TextEdit::Run(xr_string& text, pcstr caption, bool read_only, int lim,
pcstr apply_name, TOnApplyClick^ on_apply, TOnCloseClick^ on_close,
TOnCodeInsight^ on_insight)
pcstr apply_name, TOnApplyClick on_apply, TOnCloseClick on_close,
TOnCodeInsight on_insight)
{
Text = gcnew String(caption);
m_text = &text;
Expand All @@ -34,8 +100,12 @@ bool TextEdit::Run(xr_string& text, pcstr caption, bool read_only, int lim,
textBox1->MaxLength = lim;

buttonApply->Text = gcnew String(apply_name);
//buttonApply->Click += gcnew EventHandler(on_apply);

onApplyClick = &on_apply;
onCloseClick = &on_close;
onCodeInsight = &on_insight;

textBox1_SelectionChanged(nullptr, nullptr);
return ShowDialog() == Windows::Forms::DialogResult::OK;
}

Expand All @@ -44,6 +114,38 @@ System::Void TextEdit::buttonOk_Click(System::Object^ sender, System::EventArgs^
msclr::interop::marshal_context ctx;
*m_text = ctx.marshal_as<pcstr>(textBox1->Text);
}

System::Void TextEdit::buttonLoad_Click(System::Object^ sender, System::EventArgs^ e)
{
xr_string fn;
if (EFS.GetOpenName(_import_, fn, false, NULL, 2))
{
xr_string buf;
IReader* F = FS.r_open(fn.c_str());
F->r_stringZ(buf);
textBox1->Text = gcnew String(buf.c_str());
FS.r_close(F);
buttonOk->Enabled = true;
}
else
toolStripStatusLabel3->Text = "Error: can't load file";
}

System::Void TextEdit::buttonSave_Click(System::Object^ sender, System::EventArgs^ e)
{
xr_string fn;
if (EFS.GetSaveName(_import_, fn, NULL, 2))
{
CMemoryWriter F;
msclr::interop::marshal_context ctx;
F.w_stringZ(ctx.marshal_as<pcstr>(textBox1->Text));
if (!F.save_to(fn.c_str()))
Log("!Can't save text file:", fn.c_str());
}
else
toolStripStatusLabel3->Text = "Error: can't save file";

}
} // namespace Props
} // namespace ECore
} // namespace XRay
40 changes: 32 additions & 8 deletions src/editors/xrECore/Props/TextEdit.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
#pragma once
namespace XRay
{
namespace ECore
{
namespace Props
{
ref class TextEdit;
}
}
}

namespace XRay
{
Expand All @@ -15,12 +25,19 @@ using namespace System::Drawing;

public ref class TextEdit : public System::Windows::Forms::Form
{
using TOnApplyClick = fastdelegate::FastDelegate1<pcstr, bool>;
using TOnCloseClick = fastdelegate::FastDelegate0<bool>;
using TOnCodeInsight = fastdelegate::FastDelegate3<const xr_string&, xr_string&, bool&>;

public:
TextEdit(void)
{
InitializeComponent();
}

TextEdit(xr_string& text, pcstr caption, bool read_only, int lim, pcstr apply_name,
TOnApplyClick on_apply, TOnCloseClick on_close, TOnCodeInsight on_insight);

protected:
~TextEdit()
{
Expand All @@ -32,18 +49,22 @@ public ref class TextEdit : public System::Windows::Forms::Form

private:
xr_string* m_text;
delegate void TOnApplyClick(pcstr, bool);
delegate void TOnCloseClick(bool);
delegate void TOnCodeInsight(const xr_string&, xr_string&, bool&);
TOnApplyClick* onApplyClick;
TOnCloseClick* onCloseClick;
TOnCodeInsight* onCodeInsight;

public:
bool Run(xr_string& text, pcstr caption, bool read_only, int lim,
pcstr apply_name, TOnApplyClick^ on_apply, TOnCloseClick^ on_close,
TOnCodeInsight^ on_insight);

pcstr apply_name, TOnApplyClick on_apply, TOnCloseClick on_close,
TOnCodeInsight on_insight);

private: System::Void buttonOk_Click(System::Object^ sender, System::EventArgs^ e);
private: System::Void buttonClear_Click(System::Object^ sender, System::EventArgs^ e);
private: System::Void buttonApply_Click(System::Object^ sender, System::EventArgs^ e);
private: System::Void buttonLoad_Click(System::Object^ sender, System::EventArgs^ e);
private: System::Void buttonSave_Click(System::Object^ sender, System::EventArgs^ e);

private: System::Void textBox1_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e);
private: System::Void textBox1_SelectionChanged(System::Object^ sender, System::EventArgs^ e);

private: System::Windows::Forms::Button^ buttonOk;
Expand Down Expand Up @@ -93,6 +114,7 @@ private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusLabel3;
this->textBox1->TabIndex = 0;
this->textBox1->Text = L"";
this->textBox1->SelectionChanged += gcnew System::EventHandler(this, &TextEdit::textBox1_SelectionChanged);
this->textBox1->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &TextEdit::textBox1_KeyPress);
this->buttonOk->Anchor = System::Windows::Forms::AnchorStyles::Top;
this->buttonOk->AutoSizeMode = System::Windows::Forms::AutoSizeMode::GrowAndShrink;
this->buttonOk->DialogResult = System::Windows::Forms::DialogResult::OK;
Expand All @@ -118,20 +140,23 @@ private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusLabel3;
this->buttonApply->TabIndex = 3;
this->buttonApply->Text = L"Apply";
this->buttonApply->UseVisualStyleBackColor = true;
this->buttonApply->Click += gcnew System::EventHandler(this, &TextEdit::buttonApply_Click);
this->buttonLoad->Anchor = System::Windows::Forms::AnchorStyles::Top;
this->buttonLoad->Location = System::Drawing::Point(222, 0);
this->buttonLoad->Name = L"buttonLoad";
this->buttonLoad->Size = System::Drawing::Size(75, 23);
this->buttonLoad->TabIndex = 4;
this->buttonLoad->Text = L"Load";
this->buttonLoad->UseVisualStyleBackColor = true;
this->buttonLoad->Click += gcnew System::EventHandler(this, &TextEdit::buttonLoad_Click);
this->buttonSave->Anchor = System::Windows::Forms::AnchorStyles::Top;
this->buttonSave->Location = System::Drawing::Point(296, 0);
this->buttonSave->Name = L"buttonSave";
this->buttonSave->Size = System::Drawing::Size(75, 23);
this->buttonSave->TabIndex = 5;
this->buttonSave->Text = L"Save";
this->buttonSave->UseVisualStyleBackColor = true;
this->buttonSave->Click += gcnew System::EventHandler(this, &TextEdit::buttonSave_Click);
this->buttonClear->Anchor = System::Windows::Forms::AnchorStyles::Top;
this->buttonClear->Location = System::Drawing::Point(370, 0);
this->buttonClear->Name = L"buttonClear";
Expand Down Expand Up @@ -169,9 +194,8 @@ private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusLabel3;
this->toolStripStatusLabel2->Size = System::Drawing::Size(0, 17);
this->toolStripStatusLabel3->BorderStyle = System::Windows::Forms::Border3DStyle::RaisedInner;
this->toolStripStatusLabel3->Name = L"toolStripStatusLabel3";
this->toolStripStatusLabel3->Size = System::Drawing::Size(376, 17);
this->toolStripStatusLabel3->Size = System::Drawing::Size(345, 17);
this->toolStripStatusLabel3->Spring = true;
this->toolStripStatusLabel3->Text = L"Description";
this->AcceptButton = this->buttonOk;
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
Expand Down
1 change: 1 addition & 0 deletions src/editors/xrECore/pch.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once

#include "Common/Common.hpp"
#include "Common/FSMacros.hpp"
#include "xrCore/xrCore.h"
2 changes: 1 addition & 1 deletion src/editors/xrECore/xrECore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.hpp</PrecompiledHeaderFile>
<AdditionalOptions>/Zc:twoPhase- %(AdditionalOptions)</AdditionalOptions>
<LanguageStandard >stdcpp17</LanguageStandard>
<LanguageStandard>stdcpp17</LanguageStandard>
<PreprocessorDefinitions>XRECORE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
Expand Down
4 changes: 1 addition & 3 deletions src/editors/xrECore/xrEProps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ bool TextEditRun(xr_string& text, pcstr caption /*= "Text"*/, bool read_only /*=
TOnCodeInsight on_insight /*= 0*/)
{
auto form = gcnew TextEdit();
return false;
//return form->Run(text, caption, read_only, lim, apply_name, on_apply, on_close, on_insight);
return form->Run(text, caption, read_only, lim, apply_name, on_apply, on_close, on_insight);
}

} // namespace Props
} // namespace ECore
} // namespace XRay

0 comments on commit 4fa07eb

Please sign in to comment.