Skip to content

Commit f387afe

Browse files
committed
xrEProps: ItemList work in progress
1 parent d622b6e commit f387afe

File tree

8 files changed

+1158
-6
lines changed

8 files changed

+1158
-6
lines changed

src/editors/xrECore/Props/FolderLib.cpp

Lines changed: 850 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#pragma once
2+
3+
using namespace System;
4+
using namespace System::Windows::Forms;
5+
6+
using TFindObjectByName = fastdelegate::FastDelegate2<pcstr, bool&>;
7+
8+
class CFolderHelper
9+
{
10+
inline TreeNode^ LL_CreateFolder(TreeNode^ parent, const xr_string& name, bool force_icon)
11+
{
12+
auto node = gcnew TreeNode();
13+
node->Tag = (u32)TYPE_FOLDER;
14+
node->Name = gcnew String(name.c_str());
15+
parent->Nodes->Add(node);
16+
UNUSED(force_icon);
17+
return node;
18+
}
19+
20+
inline TreeNode^ LL_CreateFolder(TreeNode^ parent, String^ name, bool force_icon)
21+
{
22+
auto node = gcnew TreeNode();
23+
node->Tag = (u32)TYPE_FOLDER;
24+
node->Name = name;
25+
parent->Nodes->Add(node);
26+
UNUSED(force_icon);
27+
return node;
28+
}
29+
30+
inline TreeNode^ LL_CreateObject(TreeNode^ parent, const xr_string& name)
31+
{
32+
auto node = gcnew TreeNode();
33+
node->Tag = (u32)TYPE_OBJECT;
34+
node->Name = gcnew String(name.c_str());
35+
parent->Nodes->Add(node);
36+
return node;
37+
}
38+
39+
inline TreeNode^ LL_CreateObject(TreeNode^ parent, String^ name)
40+
{
41+
auto node = gcnew TreeNode();
42+
node->Tag = (u32)TYPE_OBJECT;
43+
node->Name = name;
44+
parent->Nodes->Add(node);
45+
return node;
46+
}
47+
48+
public:
49+
inline bool IsFolder(TreeNode^ node) { return node ? (TYPE_FOLDER == (u32)node->Tag) : TYPE_INVALID; }
50+
inline bool IsObject(TreeNode^ node) { return node ? (TYPE_OBJECT == (u32)node->Tag) : TYPE_INVALID; }
51+
bool MakeFullName(TreeNode^ begin_item, TreeNode^ end_item, xr_string& folder);
52+
bool MakeName(TreeNode^ begin_item, TreeNode^ end_item, xr_string& folder, bool bOnlyFolder);
53+
TreeNode^ FindItemInFolder(TreeView^ tv, TreeNode^ start_folder, const xr_string& name);
54+
TreeNode^ FindItemInFolder(EItemType type, TreeView^ tv, TreeNode^ start_folder, const xr_string& name);
55+
TreeNode^ AppendFolder(TreeView^ tv, xr_string full_name, bool force_icon);
56+
TreeNode^ AppendObject(TreeView^ tv, xr_string full_name, bool allow_duplicate, bool force_icon);
57+
TreeNode^ FindObject(
58+
TreeView^ tv, xr_string full_name, TreeNode^* last_valid_node = 0, int* last_valid_idx = 0);
59+
TreeNode^ FindFolder(
60+
TreeView^ tv, xr_string full_name, TreeNode^* last_valid_node = 0, int* last_valid_idx = 0);
61+
TreeNode^ FindItem(
62+
TreeView^ tv, xr_string full_name, TreeNode^* last_valid_node = 0, int* last_valid_idx = 0);
63+
void GenerateFolderName(
64+
TreeView^ tv, TreeNode^ node, xr_string& name, xr_string pref = "folder", bool num_first = false);
65+
void GenerateObjectName(
66+
TreeView^ tv, TreeNode^ node, xr_string& name, xr_string pref = "object", bool num_first = false);
67+
xr_string GetFolderName(const xr_string& full_name, xr_string& dest);
68+
xr_string GetObjectName(const xr_string& full_name, xr_string& dest);
69+
xr_string ReplacePart(xr_string old_name, xr_string ren_part, int level, pstr dest);
70+
bool RenameItem(TreeView^ tv, TreeNode^ node, xr_string& new_text, TOnItemRename OnRenameItem);
71+
void CreateNewFolder(TreeView^ tv, bool bEditAfterCreate);
72+
bool RemoveItem(
73+
TreeView^ tv, TreeNode^ pNode, TOnItemRemove OnRemoveItem, TOnItemAfterRemove OnAfterRemoveItem = 0);
74+
// drag'n'drop
75+
/*void __fastcall DragDrop(Object^ Sender, Object^ Source, int X, int Y, TOnItemRename after_drag);
76+
void __fastcall DragOver(Object^ Sender, Object^ Source, int X, int Y, TDragState State, bool& Accept);
77+
void __fastcall StartDrag(Object^ Sender, TDragObject*& DragObject);*/
78+
// void __fastcall StartDragNoFolder (TObject *Sender, TDragObject *&DragObject);
79+
// name edit
80+
bool NameAfterEdit(TreeNode^ node, xr_string value, xr_string& N);
81+
// last selection
82+
TreeNode^ RestoreSelection(TreeView^ tv, TreeNode^ node, bool bLeaveSel);
83+
TreeNode^ RestoreSelection(TreeView^ tv, xr_string full_name, bool bLeaveSel);
84+
TreeNode^ ExpandItem(TreeView^ tv, TreeNode^ node);
85+
TreeNode^ ExpandItem(TreeView^ tv, xr_string full_name);
86+
87+
bool DrawThumbnail(HDC hdc, const Irect& R, u32* data, u32 w, u32 h);
88+
void FillRect(HDC hdc, const Irect& r, u32 color);
89+
90+
xr_string GenerateName(pcstr pref, int dgt_cnt, TFindObjectByName cb, bool allow_pref_name, bool allow_);
91+
//------------------------------------------------------------------------------
92+
};
93+
94+
extern XR_EPROPS_API CFolderHelper FHelper;
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,120 @@
11
#include "pch.hpp"
22
#include "ItemList.h"
3+
#include "xrServerEntities/ItemListTypes.h"
4+
#include "FolderLib.h"
5+
6+
#include <sstream>
7+
8+
namespace XRay
9+
{
10+
namespace ECore
11+
{
12+
namespace Props
13+
{
14+
void ItemList::AssignItems(ListItemsVec& new_items, bool full_expand, bool full_sort /*= false*/)
15+
{
16+
/*// begin fill mode
17+
viewItems->BeginUpdate();
18+
// clear values
19+
// if (tvItems->Selected) FHelper.MakeFullName(tvItems->Selected,0,last_selected_item);
20+
//if (!items->empty())
21+
// ClearParams();
22+
// fill values
23+
items = &new_items;
24+
for (auto& prop : *items)
25+
{
26+
if (prop->Key.size() && (prop->Key[prop->Key.size() - 1] == '\\'))
27+
{
28+
prop->Item = FHelper.AppendFolder(viewItems, prop->Key.c_str(), !flags->is(ilSuppressIcon));
29+
auto prop_item = prop->Item;
30+
prop_item->CheckBoxEnabled = false;
31+
prop_item->UseStyles = true;
32+
prop_item->MainStyle->TextColor = prop->prop_color;
33+
prop_item->MainStyle->OwnerProps = true;
34+
prop_item->MainStyle->Style = ElhsOwnerDraw;
35+
}
36+
else
37+
{
38+
prop->Item = FHelper.AppendObject(viewItems, prop->Key.c_str(), false, !flags->is(ilSuppressIcon));
39+
if (!prop->Item)
40+
{
41+
Msg("#!Duplicate item name found: '%s'", prop->Key.c_str());
42+
break;
43+
}
44+
TElTreeItem* prop_item = (TElTreeItem*)prop->Item;
45+
prop_item->ImageIndex = prop->icon_index;
46+
prop_item->Tag = (int)prop;
47+
prop_item->UseStyles = true;
48+
prop_item->CheckBoxEnabled = prop->m_Flags.is(ListItem::flShowCB);
49+
prop_item->ShowCheckBox = prop->m_Flags.is(ListItem::flShowCB);
50+
prop_item->CheckBoxState = (TCheckBoxState)prop->m_Flags.is(ListItem::flCBChecked);
51+
52+
// set flags
53+
if (prop->m_Flags.is(ListItem::flDrawThumbnail))
54+
{
55+
prop_item->Height = 64;
56+
prop_item->OwnerHeight = !miDrawThumbnails->Checked;
57+
}
58+
// set style
59+
prop_item->MainStyle->OwnerProps = true;
60+
prop_item->MainStyle->Style = ElhsOwnerDraw;
61+
}
62+
}
63+
64+
// end fill mode
65+
if (full_expand)
66+
viewItems->ExpandAll();
67+
68+
// folder restore
69+
if (flags->is(ilFolderStore) && !FolderStore.empty())
70+
{
71+
for (TElTreeItem* item = tvItems->Items->GetFirstNode(); item; item = item->GetNext())
72+
{
73+
if (item->ChildrenCount)
74+
{
75+
xr_string nm;
76+
FHelper.MakeFullName(item, nullptr, nm);
77+
FolderStorePairIt it = FolderStore.find(nm);
78+
if (it != FolderStore.end())
79+
{
80+
SFolderStore& st_item = it->second;
81+
if (st_item.expand)
82+
item->Expand(false);
83+
else
84+
item->Collapse(false);
85+
}
86+
}
87+
}
88+
}
89+
90+
// sorting
91+
if (full_sort)
92+
{
93+
viewItems->Sort();
94+
}
95+
else
96+
{
97+
for (auto& prop : *items)
98+
{
99+
if (prop->m_Flags.is(ListItem::flSorted))
100+
((TElTreeItem*)prop->Item)->Sort(true);
101+
}
102+
}
103+
104+
// expand sel items
105+
for (RStringVecIt s_it = last_selected_items.begin(); s_it != last_selected_items.end(); s_it++)
106+
FHelper.ExpandItem(tvItems, **s_it);
107+
108+
viewItems->EndUpdate();
109+
110+
// restore selection
111+
viewItems->SelectedNode = nullptr;
112+
113+
for (RStringVecIt s_it = last_selected_items.begin(); s_it != last_selected_items.end(); s_it++)
114+
FHelper.RestoreSelection(tvItems, **s_it, true);
115+
116+
toolStripStatusLabel2->Text = items->size().ToString();*/
117+
}
118+
} // namespace Props
119+
} // namespace ECore
120+
} // namespace XRay

src/editors/xrECore/Props/ItemList.h

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ ref class ItemList;
1111
}
1212
}
1313

14+
class ListItem;
15+
using ListItemsVec = xr_vector<ListItem*>;
16+
1417
namespace XRay
1518
{
1619
namespace ECore
@@ -24,6 +27,22 @@ using namespace System::Windows::Forms;
2427
using namespace System::Data;
2528
using namespace System::Drawing;
2629

30+
enum
31+
{
32+
// set
33+
ilEditMenu = (1 << 0),
34+
ilMultiSelect = (1 << 1),
35+
ilDragAllowed = (1 << 2),
36+
ilDragCustom = (1 << 3),
37+
ilFolderStore = (1 << 4),
38+
ilSuppressIcon = (1 << 5),
39+
ilSuppressStatus = (1 << 6),
40+
41+
// internal
42+
ilRT_FullExpand = (1 << 30),
43+
// ilRT_UpdateLocked=(1<<31),
44+
};
45+
2746
public ref class ItemList : public System::Windows::Forms::Form
2847
{
2948
public:
@@ -41,20 +60,61 @@ public ref class ItemList : public System::Windows::Forms::Form
4160
}
4261
}
4362

63+
public:
64+
void AssignItems(ListItemsVec& new_items, bool full_expand, bool full_sort);
65+
66+
private:
67+
Flags32* flags;
68+
ListItemsVec* items;
69+
70+
private: System::Windows::Forms::StatusStrip^ statusStrip1;
71+
private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusLabel1;
72+
private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusLabel2;
73+
private: System::Windows::Forms::TreeView^ viewItems;
74+
4475
private:
45-
System::ComponentModel::Container ^components;
76+
System::ComponentModel::Container^ components;
4677

4778
#pragma region Windows Form Designer generated code
4879
void InitializeComponent(void)
4980
{
81+
this->statusStrip1 = (gcnew System::Windows::Forms::StatusStrip());
82+
this->toolStripStatusLabel1 = (gcnew System::Windows::Forms::ToolStripStatusLabel());
83+
this->toolStripStatusLabel2 = (gcnew System::Windows::Forms::ToolStripStatusLabel());
84+
this->viewItems = (gcnew System::Windows::Forms::TreeView());
85+
this->statusStrip1->SuspendLayout();
5086
this->SuspendLayout();
87+
this->statusStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {
88+
this->toolStripStatusLabel1,
89+
this->toolStripStatusLabel2
90+
});
91+
this->statusStrip1->Location = System::Drawing::Point(0, 242);
92+
this->statusStrip1->Name = L"statusStrip1";
93+
this->statusStrip1->Size = System::Drawing::Size(284, 22);
94+
this->statusStrip1->TabIndex = 0;
95+
this->statusStrip1->Text = L"statusStrip1";
96+
this->toolStripStatusLabel1->Name = L"toolStripStatusLabel1";
97+
this->toolStripStatusLabel1->Size = System::Drawing::Size(78, 17);
98+
this->toolStripStatusLabel1->Text = L"Items count:";
99+
this->toolStripStatusLabel2->Name = L"toolStripStatusLabel2";
100+
this->toolStripStatusLabel2->Size = System::Drawing::Size(0, 17);
101+
this->viewItems->Dock = System::Windows::Forms::DockStyle::Fill;
102+
this->viewItems->Location = System::Drawing::Point(0, 0);
103+
this->viewItems->Name = L"viewItems";
104+
this->viewItems->Size = System::Drawing::Size(284, 242);
105+
this->viewItems->TabIndex = 1;
51106
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
52107
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
53108
this->ClientSize = System::Drawing::Size(284, 264);
109+
this->Controls->Add(this->viewItems);
110+
this->Controls->Add(this->statusStrip1);
54111
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::SizableToolWindow;
55112
this->Name = L"ItemList";
56113
this->Text = L"Item List";
114+
this->statusStrip1->ResumeLayout(false);
115+
this->statusStrip1->PerformLayout();
57116
this->ResumeLayout(false);
117+
this->PerformLayout();
58118

59119
}
60120
#pragma endregion

src/editors/xrECore/Props/ItemList.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,7 @@
117117
<resheader name="writer">
118118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120+
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
121+
<value>17, 17</value>
122+
</metadata>
120123
</root>

src/editors/xrECore/Props/SelectItem.h

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
#pragma once
22

3+
namespace XRay
4+
{
5+
namespace ECore
6+
{
7+
namespace Props
8+
{
9+
ref class SelectItem;
10+
}
11+
}
12+
}
13+
314
namespace XRay
415
{
516
namespace ECore
@@ -29,20 +40,25 @@ public ref class SelectItem : public System::Windows::Forms::Form
2940
delete components;
3041
}
3142
}
43+
private: System::Windows::Forms::Panel^ panel1;
3244

3345
private:
34-
System::ComponentModel::Container ^components;
46+
System::ComponentModel::Container^ components;
3547

3648
#pragma region Windows Form Designer generated code
3749
void InitializeComponent(void)
3850
{
51+
this->panel1 = (gcnew System::Windows::Forms::Panel());
3952
this->SuspendLayout();
40-
//
41-
// SelectItem
42-
//
53+
this->panel1->Dock = System::Windows::Forms::DockStyle::Left;
54+
this->panel1->Location = System::Drawing::Point(0, 0);
55+
this->panel1->Name = L"panel1";
56+
this->panel1->Size = System::Drawing::Size(200, 371);
57+
this->panel1->TabIndex = 0;
4358
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
4459
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
45-
this->ClientSize = System::Drawing::Size(284, 264);
60+
this->ClientSize = System::Drawing::Size(532, 371);
61+
this->Controls->Add(this->panel1);
4662
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::SizableToolWindow;
4763
this->Name = L"SelectItem";
4864
this->Text = L"Select Item";

src/editors/xrECore/xrECore.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
<ClCompile Include="pch.cpp">
8383
<PrecompiledHeader>Create</PrecompiledHeader>
8484
</ClCompile>
85+
<ClCompile Include="Props\FolderLib.cpp" />
8586
<ClCompile Include="Props\GameType.cpp" />
8687
<ClCompile Include="Props\ItemList.cpp" />
8788
<ClCompile Include="Props\NumericVector.cpp" />
@@ -93,6 +94,7 @@
9394
</ItemGroup>
9495
<ItemGroup>
9596
<ClInclude Include="pch.hpp" />
97+
<ClInclude Include="Props\FolderLib.h" />
9698
<ClInclude Include="Props\GameType.h">
9799
<FileType>CppForm</FileType>
98100
</ClInclude>

0 commit comments

Comments
 (0)