2 #include "ConfigTreeCtrl.h"
5 #include "ValueListCtrl.h"
7 enum {CFGNEWKEY
=100, CFGNEWSTRING
, CFGNEWUINT
, CFGNEWBINARY
, CFGNEWSUBMENU
, CFGFIND
, CFGDELETE
, CFGRENAME
, CFGCOPYKEYNAME
};
10 BEGIN_EVENT_TABLE(ConfigTreeCtrl
, wxTreeCtrl
)
11 EVT_RIGHT_DOWN(ConfigTreeCtrl::OnRightDown
)
12 EVT_RIGHT_UP(ConfigTreeCtrl::OnRightUp
)
13 EVT_MENU(CFGNEWKEY
, ConfigTreeCtrl::OnNewKey
)
14 EVT_MENU(CFGNEWSTRING
, ConfigTreeCtrl::OnNewString
)
15 EVT_MENU(CFGNEWUINT
, ConfigTreeCtrl::OnNewUINT
)
16 EVT_MENU(CFGNEWBINARY
, ConfigTreeCtrl::OnNewBinary
)
17 EVT_MENU(CFGFIND
, ConfigTreeCtrl::OnFind
)
18 EVT_MENU(CFGDELETE
, ConfigTreeCtrl::OnDelete
)
19 EVT_TREE_SEL_CHANGED(FRAME_TREE
, ConfigTreeCtrl::OnSelChanged
)
23 ConfigTreeCtrl::ConfigTreeCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
, const wxString
& name
)
24 : wxTreeCtrl(parent
, id
, pos
, size
, style
, validator
, name
)
30 ConfigTreeCtrl::~ConfigTreeCtrl()
34 void ConfigTreeCtrl::LoadTree()
36 m_pConfig
= MainFrame::Instance()->GetpConfig();
37 const ACE_Configuration_Section_Key
& Key
= m_pConfig
->root_section();
38 wxTreeItemId Root
= AppendItem(GetRootItem(), "Root");
39 LoadSection(Root
, Key
);
42 void ConfigTreeCtrl::LoadSection(wxTreeItemId
& ParentItem
, const ACE_Configuration_Section_Key
& Key
)
46 while(!m_pConfig
->enumerate_sections(Key
, Index
, Name
))
48 wxTreeItemId Item
= AppendItem(ParentItem
, Name
.fast_rep());
49 ACE_Configuration_Section_Key Child
;
50 m_pConfig
->open_section(Key
, Name
.fast_rep(), 0, Child
);
51 LoadSection( Item
, Child
);
56 void ConfigTreeCtrl::OnRightDown(wxMouseEvent
& event
)
59 int Flags
= wxTREE_HITTEST_ONITEMLABEL
| wxTREE_HITTEST_ONITEMICON
;
60 long ItemID
= HitTest(wxPoint(event
.m_x
, event
.m_y
), Flags
);
64 void ConfigTreeCtrl::OnRightUp(wxMouseEvent
& event
)
66 wxTreeItemId ItemID
= GetSelection();
68 wxMenu
* pMenu
= new wxMenu
;
69 wxMenu
* pNewMenu
= new wxMenu
;
70 pNewMenu
->Append(CFGNEWKEY
, "Key");
71 pNewMenu
->AppendSeparator();
72 pNewMenu
->Append(CFGNEWSTRING
, "String");
73 pNewMenu
->Append(CFGNEWUINT
, "Unsigned Int");
74 //pNewMenu->Append(CFGNEWBINARY, "Binary");
75 pMenu
->Append(CFGNEWSUBMENU
, "New", pNewMenu
);
76 pMenu
->Append(CFGFIND
, "Find");
77 pMenu
->AppendSeparator();
78 pMenu
->Append(CFGDELETE
, "Delete");
79 //pMenu->Append(CFGRENAME, "Rename"); // not supported
80 //pMenu->AppendSeparator();
81 //pMenu->Append(CFGCOPYKEYNAME, "Copy Key Name"); // not supported
82 PopupMenu(pMenu
, event
.m_x
, event
.m_y
);
86 void ConfigTreeCtrl::ResolveKey(wxTreeItemId Item
, ACE_Configuration_Section_Key
& Key
)
88 wxTreeItemId OriginalItem
= Item
;
91 while(Item
!= GetRootItem())
93 wxString Text
= GetItemText(Item
);
101 Item
= GetParent(Item
);
105 m_pConfig
->expand_path(m_pConfig
->root_section(), Path
, Key
, 0);
109 Key
= m_pConfig
->root_section();
114 void ConfigTreeCtrl::OnNewKey(wxCommandEvent
& event
)
116 wxTextEntryDialog
Dlg(this, "Test", "Key Name");
117 if(Dlg
.ShowModal() != wxID_OK
)
122 wxString Value
= Dlg
.GetValue();
124 // Get the key for this node
125 wxTreeItemId ItemID
= GetSelection();
126 ACE_Configuration_Section_Key Key
, NewKey
;
127 ResolveKey(ItemID
, Key
);
128 m_pConfig
->open_section(Key
, Value
, 1, NewKey
);
129 wxTreeItemId NewItemID
= AppendItem(ItemID
, Value
);
130 EnsureVisible(NewItemID
);
133 void ConfigTreeCtrl::OnNewString(wxCommandEvent
& event
)
135 ValueDlg
Dlg(this, true);
136 if(Dlg
.ShowModal() != wxID_OK
)
141 ACE_TString Value
= Dlg
.GetStringValue();
142 ACE_TString Name
= Dlg
.GetName();
144 // Get the key for this node
145 wxTreeItemId ItemID
= GetSelection();
146 ACE_Configuration_Section_Key Key
;
147 ResolveKey(ItemID
, Key
);
148 m_pConfig
->set_string_value(Key
, Name
.fast_rep(), Value
);
149 m_pListCtrl
->DisplaySection(Key
);
152 void ConfigTreeCtrl::OnNewUINT(wxCommandEvent
& event
)
154 ValueDlg
Dlg(this, false);
155 if(Dlg
.ShowModal() != wxID_OK
)
160 u_int Value
= Dlg
.GetUINTValue();
161 ACE_TString Name
= Dlg
.GetName();
163 // Get the key for this node
164 wxTreeItemId ItemID
= GetSelection();
165 ACE_Configuration_Section_Key Key
;
166 ResolveKey(ItemID
, Key
);
167 m_pConfig
->set_integer_value(Key
, Name
.fast_rep(), Value
);
168 m_pListCtrl
->DisplaySection(Key
);
171 void ConfigTreeCtrl::OnNewBinary(wxCommandEvent
& event
)
175 ValueDlg Dlg(this, true);
176 if(Dlg.ShowModal() != wxID_OK)
181 ACE_TString Value = Dlg.GetStringValue();
182 ACE_TString Name = Dlg.GetName();
184 // Get the key for this node
185 wxTreeItemId ItemID = GetSelection();
186 ACE_Configuration_Section_Key Key;
187 ResolveKey(ItemID, Key);
188 m_pConfig->set_string_value(Key, Name.fast_rep(), Value);
189 m_pListCtrl->DisplaySection(Key);
193 void ConfigTreeCtrl::OnSelChanged(wxTreeEvent
& event
)
195 wxTreeItemId ItemID
= GetSelection();
196 ACE_Configuration_Section_Key Key
;
197 ResolveKey(ItemID
, Key
);
198 m_pListCtrl
->DisplaySection(Key
);
201 void ConfigTreeCtrl::OnFind(wxCommandEvent
& event
)
205 void ConfigTreeCtrl::OnDelete(wxCommandEvent
& event
)
207 wxTreeItemId ItemID
= GetSelection();
208 wxTreeItemId Parent
= GetParent(ItemID
);
209 ACE_Configuration_Section_Key Key
;
210 ResolveKey(Parent
, Key
);
211 wxMessageDialog
Dlg(this, "Are you sure you want to delete this section?", "Confirm Section Delete", wxYES_NO
| wxICON_EXCLAMATION
);
212 if(Dlg
.ShowModal() != wxID_YES
)
216 wxString Text
= GetItemText(ItemID
);
217 m_pConfig
->remove_section(Key
, Text
, 1);
222 void ConfigTreeCtrl::ChangeConfig(ACE_Configuration
* pConfig
)