Skip to content

Commit 4fa07eb

Browse files
committed
xrEProps: TextEdit – done.
1 parent 816b080 commit 4fa07eb

File tree

5 files changed

+140
-15
lines changed

5 files changed

+140
-15
lines changed

src/editors/xrECore/Props/TextEdit.cpp

Lines changed: 105 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,81 @@ System::Void TextEdit::buttonClear_Click(System::Object^ sender, System::EventAr
1717

1818
System::Void TextEdit::textBox1_SelectionChanged(System::Object^ sender, System::EventArgs^ e)
1919
{
20+
buttonOk->Enabled = textBox1->Modified;
21+
2022
auto line = textBox1->GetLineFromCharIndex(textBox1->SelectionStart);
2123
auto currline = textBox1->GetFirstCharIndexOfCurrentLine();
2224
auto charpos = textBox1->SelectionStart - currline;
2325
toolStripStatusLabel1->Text = (line + 1) + " : " + (charpos + 1);
2426
}
2527

28+
System::Void TextEdit::buttonApply_Click(System::Object^ sender, System::EventArgs^ e)
29+
{
30+
if (!onApplyClick->empty())
31+
{
32+
msclr::interop::marshal_context ctx;
33+
if ((*onApplyClick)(ctx.marshal_as<pcstr>(textBox1->Text)))
34+
{
35+
*m_text = ctx.marshal_as<pcstr>(textBox1->Text);
36+
}
37+
}
38+
else
39+
{
40+
msclr::interop::marshal_context ctx;
41+
*m_text = ctx.marshal_as<pcstr>(textBox1->Text);
42+
}
43+
textBox1->Modified = false;
44+
buttonOk->Enabled = false;
45+
toolStripStatusLabel3->Text = "Successful save";
46+
}
47+
48+
System::Void TextEdit::textBox1_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e)
49+
{
50+
if (!onCodeInsight->empty() && e->KeyChar == (Char)Keys::Space
51+
&& textBox1->ModifierKeys == (Keys::Control & Keys::Shift))
52+
{
53+
xr_string src_line, hint;
54+
src_line = textBox1->GetLineFromCharIndex(textBox1->SelectionStart);
55+
bool result = true;
56+
(*onCodeInsight)(src_line, hint, result);
57+
if (result)
58+
{
59+
toolStripStatusLabel3->Text = gcnew String((xr_string("Hint: ") + hint).c_str());
60+
toolStripStatusLabel3->ToolTipText = gcnew String(hint.c_str());
61+
}
62+
else
63+
{
64+
toolStripStatusLabel3->Text = gcnew String((xr_string("Error: ") + hint).c_str());
65+
toolStripStatusLabel3->ToolTipText = gcnew String(hint.c_str());
66+
}
67+
}
68+
else if (e->KeyChar == (Char)Keys::Enter && textBox1->ModifierKeys == Keys::Control)
69+
{
70+
buttonOk->PerformClick();
71+
}
72+
}
73+
74+
TextEdit::TextEdit(xr_string& text, pcstr caption, bool read_only, int lim, pcstr apply_name, TOnApplyClick on_apply, TOnCloseClick on_close, TOnCodeInsight on_insight)
75+
{
76+
Text = gcnew String(caption);
77+
m_text = &text;
78+
textBox1->ReadOnly = read_only;
79+
textBox1->Text = gcnew String(text.c_str());
80+
textBox1->MaxLength = lim;
81+
82+
buttonApply->Text = gcnew String(apply_name);
83+
84+
onApplyClick = &on_apply;
85+
onCloseClick = &on_close;
86+
onCodeInsight = &on_insight;
87+
88+
textBox1_SelectionChanged(nullptr, nullptr);
89+
Show();
90+
}
91+
2692
bool TextEdit::Run(xr_string& text, pcstr caption, bool read_only, int lim,
27-
pcstr apply_name, TOnApplyClick^ on_apply, TOnCloseClick^ on_close,
28-
TOnCodeInsight^ on_insight)
93+
pcstr apply_name, TOnApplyClick on_apply, TOnCloseClick on_close,
94+
TOnCodeInsight on_insight)
2995
{
3096
Text = gcnew String(caption);
3197
m_text = &text;
@@ -34,8 +100,12 @@ bool TextEdit::Run(xr_string& text, pcstr caption, bool read_only, int lim,
34100
textBox1->MaxLength = lim;
35101

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

104+
onApplyClick = &on_apply;
105+
onCloseClick = &on_close;
106+
onCodeInsight = &on_insight;
107+
108+
textBox1_SelectionChanged(nullptr, nullptr);
39109
return ShowDialog() == Windows::Forms::DialogResult::OK;
40110
}
41111

@@ -44,6 +114,38 @@ System::Void TextEdit::buttonOk_Click(System::Object^ sender, System::EventArgs^
44114
msclr::interop::marshal_context ctx;
45115
*m_text = ctx.marshal_as<pcstr>(textBox1->Text);
46116
}
117+
118+
System::Void TextEdit::buttonLoad_Click(System::Object^ sender, System::EventArgs^ e)
119+
{
120+
xr_string fn;
121+
if (EFS.GetOpenName(_import_, fn, false, NULL, 2))
122+
{
123+
xr_string buf;
124+
IReader* F = FS.r_open(fn.c_str());
125+
F->r_stringZ(buf);
126+
textBox1->Text = gcnew String(buf.c_str());
127+
FS.r_close(F);
128+
buttonOk->Enabled = true;
129+
}
130+
else
131+
toolStripStatusLabel3->Text = "Error: can't load file";
132+
}
133+
134+
System::Void TextEdit::buttonSave_Click(System::Object^ sender, System::EventArgs^ e)
135+
{
136+
xr_string fn;
137+
if (EFS.GetSaveName(_import_, fn, NULL, 2))
138+
{
139+
CMemoryWriter F;
140+
msclr::interop::marshal_context ctx;
141+
F.w_stringZ(ctx.marshal_as<pcstr>(textBox1->Text));
142+
if (!F.save_to(fn.c_str()))
143+
Log("!Can't save text file:", fn.c_str());
144+
}
145+
else
146+
toolStripStatusLabel3->Text = "Error: can't save file";
147+
148+
}
47149
} // namespace Props
48150
} // namespace ECore
49151
} // namespace XRay

src/editors/xrECore/Props/TextEdit.h

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
#pragma once
2+
namespace XRay
3+
{
4+
namespace ECore
5+
{
6+
namespace Props
7+
{
8+
ref class TextEdit;
9+
}
10+
}
11+
}
212

313
namespace XRay
414
{
@@ -15,12 +25,19 @@ using namespace System::Drawing;
1525

1626
public ref class TextEdit : public System::Windows::Forms::Form
1727
{
28+
using TOnApplyClick = fastdelegate::FastDelegate1<pcstr, bool>;
29+
using TOnCloseClick = fastdelegate::FastDelegate0<bool>;
30+
using TOnCodeInsight = fastdelegate::FastDelegate3<const xr_string&, xr_string&, bool&>;
31+
1832
public:
1933
TextEdit(void)
2034
{
2135
InitializeComponent();
2236
}
2337

38+
TextEdit(xr_string& text, pcstr caption, bool read_only, int lim, pcstr apply_name,
39+
TOnApplyClick on_apply, TOnCloseClick on_close, TOnCodeInsight on_insight);
40+
2441
protected:
2542
~TextEdit()
2643
{
@@ -32,18 +49,22 @@ public ref class TextEdit : public System::Windows::Forms::Form
3249

3350
private:
3451
xr_string* m_text;
35-
delegate void TOnApplyClick(pcstr, bool);
36-
delegate void TOnCloseClick(bool);
37-
delegate void TOnCodeInsight(const xr_string&, xr_string&, bool&);
52+
TOnApplyClick* onApplyClick;
53+
TOnCloseClick* onCloseClick;
54+
TOnCodeInsight* onCodeInsight;
3855

3956
public:
4057
bool Run(xr_string& text, pcstr caption, bool read_only, int lim,
41-
pcstr apply_name, TOnApplyClick^ on_apply, TOnCloseClick^ on_close,
42-
TOnCodeInsight^ on_insight);
43-
58+
pcstr apply_name, TOnApplyClick on_apply, TOnCloseClick on_close,
59+
TOnCodeInsight on_insight);
4460

4561
private: System::Void buttonOk_Click(System::Object^ sender, System::EventArgs^ e);
4662
private: System::Void buttonClear_Click(System::Object^ sender, System::EventArgs^ e);
63+
private: System::Void buttonApply_Click(System::Object^ sender, System::EventArgs^ e);
64+
private: System::Void buttonLoad_Click(System::Object^ sender, System::EventArgs^ e);
65+
private: System::Void buttonSave_Click(System::Object^ sender, System::EventArgs^ e);
66+
67+
private: System::Void textBox1_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e);
4768
private: System::Void textBox1_SelectionChanged(System::Object^ sender, System::EventArgs^ e);
4869

4970
private: System::Windows::Forms::Button^ buttonOk;
@@ -93,6 +114,7 @@ private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusLabel3;
93114
this->textBox1->TabIndex = 0;
94115
this->textBox1->Text = L"";
95116
this->textBox1->SelectionChanged += gcnew System::EventHandler(this, &TextEdit::textBox1_SelectionChanged);
117+
this->textBox1->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &TextEdit::textBox1_KeyPress);
96118
this->buttonOk->Anchor = System::Windows::Forms::AnchorStyles::Top;
97119
this->buttonOk->AutoSizeMode = System::Windows::Forms::AutoSizeMode::GrowAndShrink;
98120
this->buttonOk->DialogResult = System::Windows::Forms::DialogResult::OK;
@@ -118,20 +140,23 @@ private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusLabel3;
118140
this->buttonApply->TabIndex = 3;
119141
this->buttonApply->Text = L"Apply";
120142
this->buttonApply->UseVisualStyleBackColor = true;
143+
this->buttonApply->Click += gcnew System::EventHandler(this, &TextEdit::buttonApply_Click);
121144
this->buttonLoad->Anchor = System::Windows::Forms::AnchorStyles::Top;
122145
this->buttonLoad->Location = System::Drawing::Point(222, 0);
123146
this->buttonLoad->Name = L"buttonLoad";
124147
this->buttonLoad->Size = System::Drawing::Size(75, 23);
125148
this->buttonLoad->TabIndex = 4;
126149
this->buttonLoad->Text = L"Load";
127150
this->buttonLoad->UseVisualStyleBackColor = true;
151+
this->buttonLoad->Click += gcnew System::EventHandler(this, &TextEdit::buttonLoad_Click);
128152
this->buttonSave->Anchor = System::Windows::Forms::AnchorStyles::Top;
129153
this->buttonSave->Location = System::Drawing::Point(296, 0);
130154
this->buttonSave->Name = L"buttonSave";
131155
this->buttonSave->Size = System::Drawing::Size(75, 23);
132156
this->buttonSave->TabIndex = 5;
133157
this->buttonSave->Text = L"Save";
134158
this->buttonSave->UseVisualStyleBackColor = true;
159+
this->buttonSave->Click += gcnew System::EventHandler(this, &TextEdit::buttonSave_Click);
135160
this->buttonClear->Anchor = System::Windows::Forms::AnchorStyles::Top;
136161
this->buttonClear->Location = System::Drawing::Point(370, 0);
137162
this->buttonClear->Name = L"buttonClear";
@@ -169,9 +194,8 @@ private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusLabel3;
169194
this->toolStripStatusLabel2->Size = System::Drawing::Size(0, 17);
170195
this->toolStripStatusLabel3->BorderStyle = System::Windows::Forms::Border3DStyle::RaisedInner;
171196
this->toolStripStatusLabel3->Name = L"toolStripStatusLabel3";
172-
this->toolStripStatusLabel3->Size = System::Drawing::Size(376, 17);
197+
this->toolStripStatusLabel3->Size = System::Drawing::Size(345, 17);
173198
this->toolStripStatusLabel3->Spring = true;
174-
this->toolStripStatusLabel3->Text = L"Description";
175199
this->AcceptButton = this->buttonOk;
176200
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
177201
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;

src/editors/xrECore/pch.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#pragma once
22

33
#include "Common/Common.hpp"
4+
#include "Common/FSMacros.hpp"
45
#include "xrCore/xrCore.h"

src/editors/xrECore/xrECore.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
<ConformanceMode>true</ConformanceMode>
5959
<PrecompiledHeaderFile>pch.hpp</PrecompiledHeaderFile>
6060
<AdditionalOptions>/Zc:twoPhase- %(AdditionalOptions)</AdditionalOptions>
61-
<LanguageStandard >stdcpp17</LanguageStandard>
61+
<LanguageStandard>stdcpp17</LanguageStandard>
6262
<PreprocessorDefinitions>XRECORE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
6363
</ClCompile>
6464
</ItemDefinitionGroup>

src/editors/xrECore/xrEProps.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@ bool TextEditRun(xr_string& text, pcstr caption /*= "Text"*/, bool read_only /*=
3636
TOnCodeInsight on_insight /*= 0*/)
3737
{
3838
auto form = gcnew TextEdit();
39-
return false;
40-
//return form->Run(text, caption, read_only, lim, apply_name, on_apply, on_close, on_insight);
39+
return form->Run(text, caption, read_only, lim, apply_name, on_apply, on_close, on_insight);
4140
}
42-
4341
} // namespace Props
4442
} // namespace ECore
4543
} // namespace XRay

0 commit comments

Comments
 (0)