1 /////////////////////////////////////////////////////////////////////////////
2 // Name: configtooldoc.h
3 // Purpose: Document class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "configtooldoc.h"
22 #include "wx/config.h"
23 #include "wx/textfile.h"
24 #include "wx/process.h"
25 #include "wx/mimetype.h"
26 #include "wx/process.h"
27 #include "wx/wfstream.h"
33 #include "configtooldoc.h"
34 #include "configtoolview.h"
35 #include "configtree.h"
36 #include "mainframe.h"
38 #include "wxconfigtool.h"
39 #include "htmlparser.h"
41 IMPLEMENT_DYNAMIC_CLASS(ctConfigToolDoc
, wxDocument
)
44 ctConfigToolDoc::ctConfigToolDoc()
47 m_clipboardItem
= NULL
;
51 ctConfigToolDoc::~ctConfigToolDoc()
55 if (GetCommandProcessor())
56 GetCommandProcessor()->SetEditMenu(NULL
);
59 // Delete all the items not already deleted
60 void ctConfigToolDoc::DeleteItems()
67 /// Clears the clipboard item.
68 void ctConfigToolDoc::ClearClipboard()
71 delete m_clipboardItem
;
72 m_clipboardItem
= NULL
;
75 /// Sets the clipboard item.
76 void ctConfigToolDoc::SetClipboardItem(ctConfigItem
* item
)
79 delete m_clipboardItem
;
80 m_clipboardItem
= item
;
84 // Closes and clears the document
85 bool ctConfigToolDoc::OnCloseDocument()
87 if (wxDocument::OnCloseDocument())
89 ctConfigToolHint
hint(NULL
, ctClear
);
90 UpdateAllViews (NULL
, & hint
);
102 bool ctConfigToolDoc::Save()
106 if (!IsModified() && m_savedYet
) return TRUE
;
107 if (m_documentFile
== wxT("") || !m_savedYet
)
110 ret
= OnSaveDocument(m_documentFile
);
112 SetDocumentSaved(TRUE
);
116 // Create the document
117 bool ctConfigToolDoc::OnCreate(const wxString
& path
, long flags
)
119 GetCommandProcessor()->SetEditMenu(wxGetApp().GetMainFrame()->GetEditMenu());
120 GetCommandProcessor()->Initialize();
121 GetCommandProcessor()->ClearCommands();
123 // wxGetApp().m_currentDoc = this;
125 if (flags
& wxDOC_NEW
)
127 ctConfigItem
* rootItem
= new ctConfigItem(NULL
, ctTypeGroup
, _T("Configuration"));
128 //rootItem->InitProperties();
129 rootItem
->GetProperties().AddProperty(
131 wxT("The item description."),
132 wxVariant(wxT(""), wxT("description")),
135 rootItem
->SetPropertyString(_T("description"),
136 _T("<B>This is the top-level configuration item.</B>"));
139 SetTopItem(rootItem
);
142 SetDocumentSaved(FALSE
);
144 wxString
rootName(wxT("untitled"));
145 wxStripExtension(rootName
);
146 SetFilename(wxGetApp().GetSettings().GenerateFilename(rootName
));
149 // Creates the view, so do any view updating after this
150 bool success
= wxDocument::OnCreate(path
, flags
);
154 if (flags
& wxDOC_NEW
)
158 ctConfigToolHint
hint(NULL
, ctInitialUpdate
);
159 UpdateAllViews (NULL
, & hint
);
161 SetFilename(GetFilename(), TRUE
);
168 bool ctConfigToolDoc::OnSaveDocument(const wxString
& filename
)
172 const wxString
strOldPath(GetFilename());
174 // Do some backing up first
176 // This is the backup filename
177 wxString
backupFilename(filename
);
178 backupFilename
+= wxT(".bak");
180 // This is the temporary copy of the backup
181 wxString
tempFilename(filename
);
182 tempFilename
+= wxT(".tmp");
183 if (wxFileExists(tempFilename
))
184 wxRemoveFile(tempFilename
);
186 bool leaveBackup
= TRUE
;
188 bool saved
= DoSave(tempFilename
);
192 // Remove the old .bak file
193 if (wxFileExists(backupFilename
))
195 wxRemoveFile(backupFilename
);
198 // Copy the old file to the .bak
202 if (wxFileExists(filename
))
204 if (!wxRenameFile(filename
, backupFilename
))
206 wxCopyFile(filename
, backupFilename
);
207 wxRemoveFile(filename
);
213 if (wxFileExists(filename
))
214 wxRemoveFile(filename
);
217 // Finally, copy the temporary file to the proper filename
218 if (!wxRenameFile(tempFilename
, filename
))
220 wxCopyFile(tempFilename
, filename
);
221 wxRemoveFile(tempFilename
);
225 ((ctConfigToolView
*)GetFirstView())->OnChangeFilename();
226 SetDocumentSaved(TRUE
);
227 SetFilename(filename
);
228 wxGetApp().GetSettings().m_lastFilename
= filename
;
231 SetFilename(strOldPath
);
233 wxGetApp().GetMainFrame()->UpdateFrameTitle();
238 bool ctConfigToolDoc::OnOpenDocument(const wxString
& filename
)
242 bool opened
= DoOpen(filename
);
246 SetFilename(filename
);
247 wxGetApp().GetSettings().m_lastFilename
= filename
;
249 ((ctConfigToolView
*)GetFirstView())->OnChangeFilename();
251 RefreshDependencies();
253 // ctConfigToolHint hint(NULL, ctFilenameChanged);
254 ctConfigToolHint
hint(NULL
, ctInitialUpdate
);
255 UpdateAllViews (NULL
, & hint
);
258 SetDocumentSaved(TRUE
); // Necessary or it will pop up the Save As dialog
263 /// Save the settings file
264 bool ctConfigToolDoc::DoSave(const wxString
& filename
)
266 wxFileOutputStream
stream(filename
);
270 stream
<< wxT("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
271 stream
<< wxT("<settings xmlns=\"http://www.wxwindows.org/wxs\" version=\"2.5.0.1\">");
273 DoSave(m_topItem
, stream
, 1);
275 stream
<< wxT("\n</settings>\n");
280 inline static void OutputIndentation(wxOutputStream
& stream
, int indent
)
282 wxString str
= wxT("\n");
283 for (int i
= 0; i
< indent
; i
++)
284 str
<< wxT(' ') << wxT(' ');
288 /// Recursive helper function for file saving
289 bool ctConfigToolDoc::DoSave(ctConfigItem
* item
, wxOutputStream
& stream
, int indent
)
291 OutputIndentation(stream
, indent
*2);
293 wxString
name(item
->GetName());
296 if (item
->GetType() == ctTypeGroup
)
297 typeStr
= wxT("group");
298 else if (item
->GetType() == ctTypeCheckGroup
)
299 typeStr
= wxT("check-group");
300 else if (item
->GetType() == ctTypeRadioGroup
)
301 typeStr
= wxT("radio-group");
302 else if (item
->GetType() == ctTypeString
)
303 typeStr
= wxT("string");
304 else if (item
->GetType() == ctTypeBoolCheck
)
305 typeStr
= wxT("bool-check");
306 else if (item
->GetType() == ctTypeBoolRadio
)
307 typeStr
= wxT("bool-radio");
308 else if (item
->GetType() == ctTypeInteger
)
309 typeStr
= wxT("integer");
311 typeStr
= wxT("unknown");
313 stream
<< wxT("<setting type=\"") << typeStr
<< wxT("\">");
317 OutputIndentation(stream
, indent
*2);
318 if (item
->IsActive())
319 stream
<< wxT("<active>1</active>");
321 stream
<< wxT("<active>0</active>");
322 OutputIndentation(stream
, indent
*2);
323 if (item
->IsEnabled())
324 stream
<< wxT("<enabled>1</enabled>");
326 stream
<< wxT("<enabled>0</enabled>");
329 wxNode
* node
= item
->GetProperties().GetList().GetFirst();
332 ctProperty
* prop
= (ctProperty
*) node
->GetData();
333 OutputIndentation(stream
, indent
*2);
334 stream
<< wxT("<") << prop
->GetName() ;
336 if (prop
->IsCustom())
338 stream
<< wxT(" custom=\"true\"");
339 stream
<< wxT(" type=\"") << prop
->GetVariant().GetType() << wxT("\"");
340 stream
<< wxT(" editor-type=\"") << prop
->GetEditorType() << wxT("\"");
341 stream
<< wxT(" description=\"") << prop
->GetDescription() << wxT("\"");
342 if (prop
->GetChoices().GetCount() > 0)
345 ctConfigItem::ArrayToString(prop
->GetChoices(), choices
);
346 stream
<< wxT(" choices=\"") << choices
<< wxT("\"");
352 stream
<< ctEscapeHTMLCharacters(prop
->GetVariant().GetString()) ;
353 stream
<< wxT("</") << prop
->GetName() << wxT(">");
355 node
= node
->GetNext();
359 node
= item
->GetChildren().GetFirst();
362 ctConfigItem
* child
= (ctConfigItem
*) node
->GetData();
363 DoSave(child
, stream
, indent
);
365 node
= node
->GetNext();
370 OutputIndentation(stream
, indent
*2);
371 stream
<< wxT("</setting>");
376 /// Open the settings file
377 bool ctConfigToolDoc::DoOpen(const wxString
& filename
)
379 wxSimpleHtmlParser parser
;
380 if (parser
.ParseFile(filename
))
382 ctConfigToolHint
hint(NULL
, ctClear
);
383 UpdateAllViews (NULL
, & hint
);
386 if (parser
.GetTopLevelTag()->GetChildren())
388 wxSimpleHtmlTag
* settingsTag
= parser
.GetTopLevelTag()->GetChildren()->FindTag(wxT("settings"));
389 if (settingsTag
&& settingsTag
->GetChildren())
391 wxSimpleHtmlTag
* firstSettingTag
= settingsTag
->GetChildren();
393 DoOpen(firstSettingTag
, NULL
);
402 static bool GetHtmlBoolValue(const wxString
& value
)
404 if (value
== wxT("true") || value
== wxT("TRUE") || value
== wxT("1"))
410 static int GetHtmlIntegerValue(const wxString
& value
)
412 return wxAtoi(value
);
415 static double GetHtmlDoubleValue(const wxString
& value
)
417 return wxAtof(value
);
420 bool ctConfigToolDoc::DoOpen(wxSimpleHtmlTag
* tag
, ctConfigItem
* parent
)
422 ctConfigItem
* newItem
= NULL
;
423 if (tag
->NameIs(wxT("setting")))
425 wxSimpleHtmlAttribute
* attr
= tag
->FindAttribute(wxT("type"));
428 ctConfigType type
= ctTypeUnknown
;
429 wxString
typeStr(attr
->GetValue());
430 if (typeStr
== wxT("group"))
432 else if (typeStr
== wxT("option-group") || typeStr
== wxT("check-group"))
433 type
= ctTypeCheckGroup
;
434 else if (typeStr
== wxT("radio-group"))
435 type
= ctTypeRadioGroup
;
436 else if (typeStr
== wxT("bool-check"))
437 type
= ctTypeBoolCheck
;
438 else if (typeStr
== wxT("bool-radio"))
439 type
= ctTypeBoolRadio
;
440 else if (typeStr
== wxT("string"))
442 else if (typeStr
== wxT("integer"))
443 type
= ctTypeInteger
;
446 wxLogError(wxT("Unknown type %s"), (const wxChar
*) typeStr
);
448 if (type
!= ctTypeUnknown
)
450 newItem
= new ctConfigItem(parent
, type
, wxT(""));
451 newItem
->InitProperties();
457 wxSimpleHtmlTag
* childTag
= tag
->GetChildren();
461 if (childTag
->GetType() == wxSimpleHtmlTag_Open
)
463 if (childTag
->GetName() == wxT("setting"))
465 DoOpen(childTag
, newItem
);
467 else if (childTag
->GetName() == wxT("name"))
471 wxString
name(childTag
->GetNext()->GetTagText());
472 newItem
->SetName(name
);
475 else if (childTag
->GetName() == wxT("active"))
478 newItem
->SetActive(GetHtmlBoolValue(childTag
->GetNext()->GetTagText()));
480 else if (childTag
->GetName() == wxT("enabled"))
483 newItem
->Enable(GetHtmlBoolValue(childTag
->GetNext()->GetTagText()));
489 ctProperty
* prop
= newItem
->GetProperties().FindProperty(childTag
->GetName());
492 // A custom property, else an obsolete
493 // property that we should ignore.
495 if (childTag
->GetAttributeValue(isCustom
, wxT("custom")) &&
496 isCustom
== wxT("true"))
498 prop
= new ctProperty
;
500 wxString
name(childTag
->GetName());
501 wxString
type(wxT("string"));
503 wxString
editorType(wxT("string"));
504 wxString
description(wxT(""));
505 childTag
->GetAttributeValue(type
, wxT("type"));
506 childTag
->GetAttributeValue(type
, wxT("editor-type"));
507 childTag
->GetAttributeValue(type
, wxT("choices"));
508 childTag
->GetAttributeValue(description
, wxT("description"));
510 if (type
== wxT("bool"))
511 prop
->GetVariant() = wxVariant((bool) FALSE
, name
);
512 else if (type
== wxT("double"))
513 prop
->GetVariant() = wxVariant((double) 0.0, name
);
514 else if (type
== wxT("long"))
515 prop
->GetVariant() = wxVariant((long) 0, name
);
517 prop
->GetVariant() = wxVariant(wxT(""), name
);
518 prop
->SetDescription(description
);
519 prop
->SetCustom(TRUE
);
520 prop
->SetEditorType(editorType
);
521 if (!choices
.IsEmpty())
524 ctConfigItem::StringToArray(choices
, arr
);
525 prop
->SetChoices(arr
);
527 newItem
->GetProperties().AddProperty(prop
);
532 if (prop
->GetVariant().GetType() == wxT("string"))
533 prop
->GetVariant() = childTag
->GetNext()->GetTagText();
534 else if (prop
->GetVariant().GetType() == wxT("long"))
535 prop
->GetVariant() = (long) GetHtmlIntegerValue(childTag
->GetNext()->GetTagText());
536 else if (prop
->GetVariant().GetType() == wxT("bool"))
537 prop
->GetVariant() = (bool) GetHtmlBoolValue(childTag
->GetNext()->GetTagText());
538 else if (prop
->GetVariant().GetType() == wxT("double"))
539 prop
->GetVariant() = (double) GetHtmlDoubleValue(childTag
->GetNext()->GetTagText());
544 childTag
= childTag
->GetNext();
549 /// Clear dependencies
550 void ctConfigToolDoc::ClearDependencies(ctConfigItem
* item
)
555 item
->GetDependents().Clear();
556 for ( wxNode
* node
= item
->GetChildren().GetFirst(); node
; node
= node
->GetNext() )
558 ctConfigItem
* child
= (ctConfigItem
*) node
->GetData();
559 ClearDependencies(child
);
563 /// Refresh dependencies
564 void ctConfigToolDoc::RefreshDependencies()
566 ClearDependencies(GetTopItem());
567 RefreshDependencies(GetTopItem());
570 /// Refresh dependencies
571 void ctConfigToolDoc::RefreshDependencies(ctConfigItem
* item
)
573 wxArrayString requiresArr
;
574 wxString
requires = item
->GetPropertyString(wxT("requires"));
575 wxString precludes
= item
->GetPropertyString(wxT("precludes"));
576 wxString enabledIf
= item
->GetPropertyString(wxT("enabled-if"));
577 wxString enabledIfNot
= item
->GetPropertyString(wxT("enabled-if-not"));
578 wxString context
= item
->GetPropertyString(wxT("context"));
580 if (!requires.IsEmpty())
581 item
->StringToArray(requires, requiresArr
);
583 if (!precludes
.IsEmpty())
584 item
->StringToArray(precludes
, requiresArr
);
586 if (!enabledIfNot
.IsEmpty())
587 item
->StringToArray(enabledIfNot
, requiresArr
);
589 if (!enabledIf
.IsEmpty())
590 item
->StringToArray(enabledIf
, requiresArr
);
592 // Add the parent to the list of dependencies, if the
593 // parent is a check or radio group.
594 ctConfigItem
* parent
= item
->GetParent();
596 (parent
->GetType() == ctTypeCheckGroup
||
597 parent
->GetType() == ctTypeRadioGroup
))
598 requiresArr
.Add(parent
->GetName());
600 // Also look in 'context' since these items
601 // are another kind of dependency (switching to
602 // a different platform may cause the dependencies
603 // to be evaluated differently).
604 if (!context
.IsEmpty())
605 item
->StringToArray(context
, requiresArr
);
608 for (i
= 0; i
< requiresArr
.GetCount(); i
++)
610 wxString
itemName(requiresArr
[i
]);
611 ctConfigItem
* otherItem
= GetTopItem()->FindItem(itemName
);
612 if (otherItem
&& !otherItem
->GetDependents().Member(item
))
614 otherItem
->GetDependents().Append(item
);
617 for ( wxNode
* node
= item
->GetChildren().GetFirst(); node
; node
= node
->GetNext() )
619 ctConfigItem
* child
= (ctConfigItem
*) node
->GetData();
620 RefreshDependencies(child
);
624 /// Generate the text of a setup.h
625 wxString
ctConfigToolDoc::GenerateSetup()
628 str
<< wxT("/*\n * setup.h\n * Generated by wxConfigTool\n *\n */\n\n");
630 GenerateSetup(GetTopItem(), str
);
636 void ctConfigToolDoc::GenerateSetup(ctConfigItem
* item
, wxString
& str
)
638 // Generate the setup.h entries for this item
639 wxString name
= item
->GetName();
641 // We don't process the platform choice
642 if (item
->GetName() == wxT("Target"))
645 if (item
->IsInActiveContext() &&
646 (item
->GetType() == ctTypeCheckGroup
||
647 item
->GetType() == ctTypeRadioGroup
||
648 item
->GetType() == ctTypeBoolCheck
||
649 item
->GetType() == ctTypeBoolRadio
))
651 // TODO: write description
652 wxString name
= item
->GetName();
653 if (name
.Left(6) == wxT("wxUSE_") ||
654 name
== wxT("REMOVE_UNUSED_ARG") || // Hack alert: change to wxUSE_UNUSED_ARG_REMOVAL
655 name
.Find(wxT("COMPATIBILITY")) != wxNOT_FOUND
)
657 str
<< wxT("#define ") << name
;
658 if (item
->IsEnabled())
666 for ( wxNode
* node
= item
->GetChildren().GetFirst(); node
; node
= node
->GetNext() )
668 ctConfigItem
* child
= (ctConfigItem
*) node
->GetData();
669 GenerateSetup(child
, str
);
674 /// Generate a configure command
675 wxString
ctConfigToolDoc::GenerateConfigureCommand()
678 str
<< wxT("# configurewx\n# Generated by wxConfigTool\n\n");
680 wxString path
= GetFrameworkDir(TRUE
);
681 bool makeUnix
= TRUE
;
687 path
+= wxFILE_SEP_PATH
;
690 str
<< path
<< wxT("configure");
692 // Find the target to use
693 ctConfigItem
* platformsFolder
= GetTopItem()->FindItem(wxT("Target"));
696 for ( wxNode
* node
= platformsFolder
->GetChildren().GetFirst(); node
; node
= node
->GetNext() )
698 ctConfigItem
* child
= (ctConfigItem
*) node
->GetData();
699 if (child
->GetType() == ctTypeBoolRadio
&& child
->IsEnabled())
701 wxString configureCommand
= child
->GetPropertyString(wxT("configure-command"));
702 if (!configureCommand
.IsEmpty())
703 str
<< wxT(" ") << configureCommand
;
708 GenerateConfigureCommand(GetTopItem(), str
);
713 void ctConfigToolDoc::GenerateConfigureCommand(ctConfigItem
* item
, wxString
& str
)
715 // We don't process the platform group, since we've
717 if (item
->GetName() == wxT("Target"))
720 if (item
->IsInActiveContext() &&
721 (item
->GetType() == ctTypeCheckGroup
||
722 item
->GetType() == ctTypeRadioGroup
||
723 item
->GetType() == ctTypeBoolCheck
||
724 item
->GetType() == ctTypeBoolRadio
))
726 wxString name
= item
->GetName();
727 wxString configureCommand
= item
->GetPropertyString(wxT("configure-command"));
728 if (!configureCommand
.IsEmpty())
730 if (!item
->IsEnabled())
732 // Replace 'enable' with 'disable' if this
734 configureCommand
.Replace(wxT("--enable-"), wxT("--disable-"));
735 configureCommand
.Replace(wxT("--with-"), wxT("--without-"));
737 ctProperty
* prop
= item
->GetProperties().FindProperty(wxT("builtin"));
738 if (prop
&& prop
->GetVariant().GetType() == wxT("bool"))
740 bool builtin
= prop
->GetVariant().GetBool();
741 str
<< wxT(" ") << configureCommand
;
743 str
<< wxT("=builtin");
749 ctProperty
* prop
= item
->GetProperties().FindProperty(wxT("value"));
750 if (prop
&& prop
->GetVariant().GetType() == wxT("string"))
752 wxString val
= prop
->GetVariant().GetString();
753 if (item
->IsEnabled() && !val
.IsEmpty())
755 str
<< wxT(" ") << configureCommand
;
756 str
<< wxT("=\"") << val
<< wxT("\"");
758 // If the string is empty, ignore this parameter,
759 // since it's obviously intended to be supplied
760 // only if there's a string to use and it's enabled.
764 str
<< wxT(" ") << configureCommand
;
770 for ( wxNode
* node
= item
->GetChildren().GetFirst(); node
; node
= node
->GetNext() )
772 ctConfigItem
* child
= (ctConfigItem
*) node
->GetData();
773 GenerateConfigureCommand(child
, str
);
777 /// Gets the current framework directory
778 wxString
ctConfigToolDoc::GetFrameworkDir(bool makeUnix
)
780 wxString path
= wxGetApp().GetSettings().m_frameworkDir
;
781 if (wxGetApp().GetSettings().m_useEnvironmentVariable
)
783 // Should probably allow other variables
784 // to be used, and maybe expand variables within m_frameworkDir
785 path
= wxGetenv(wxT("WXWIN"));
788 path
.Replace(wxT("\\"), wxT("/"));
794 /// Finds the next item in the tree
795 ctConfigItem
* ctConfigToolDoc::FindNextItem(ctConfigItem
* item
, bool wrap
)
800 // First, try to find the first child
801 if (item
->GetChildCount() > 0)
803 return item
->GetChild(0);
807 ctConfigItem
* p
= item
;
810 ctConfigItem
* toFind
= FindNextSibling(p
);
817 // Finally, wrap around to the root.
824 /// Finds the next sibling in the tree
825 ctConfigItem
* ctConfigToolDoc::FindNextSibling(ctConfigItem
* item
)
827 if (item
->GetParent())
829 wxNode
* node
= item
->GetParent()->GetChildren().Member(item
);
830 if (node
&& node
->GetNext())
832 ctConfigItem
* nextItem
= (ctConfigItem
*) node
->GetNext()->GetData();
841 * Implements a document editing command.
844 ctConfigCommand::ctConfigCommand(const wxString
& name
, int cmdId
,
845 ctConfigItem
* activeState
, ctConfigItem
* savedState
,
846 ctConfigItem
* parent
, ctConfigItem
* insertBefore
,
847 bool ignoreFirstTime
): wxCommand(TRUE
, name
)
849 m_activeState
= activeState
;
850 m_savedState
= savedState
;
851 m_ignoreThis
= ignoreFirstTime
;
855 m_insertBefore
= insertBefore
;
858 ctConfigCommand::ctConfigCommand(const wxString
& name
, int cmdId
,
859 ctConfigItem
* activeState
, ctProperties
* properties
,
860 bool ignoreFirstTime
): wxCommand(TRUE
, name
)
862 m_activeState
= activeState
;
864 m_properties
= properties
;
865 m_ignoreThis
= ignoreFirstTime
;
867 m_properties
= properties
;
869 m_insertBefore
= NULL
;
872 ctConfigCommand::~ctConfigCommand()
880 bool ctConfigCommand::Do()
882 return DoAndUndo(TRUE
);
885 bool ctConfigCommand::Undo()
887 return DoAndUndo(FALSE
);
890 // Combine Do and Undo into one
891 bool ctConfigCommand::DoAndUndo(bool doCmd
)
899 wxASSERT(m_savedState
== NULL
);
900 wxASSERT(m_activeState
!= NULL
);
902 ctConfigItem
* newItem
= m_activeState
->DeepClone();
903 ctConfigToolDoc
* doc
= m_activeState
->GetDocument();
905 // This will delete the old clipboard contents, if any.
906 doc
->SetClipboardItem(newItem
);
908 m_parent
= m_activeState
->GetParent();
909 m_insertBefore
= m_activeState
->FindNextSibling();
911 m_activeState
->Detach();
912 m_savedState
= m_activeState
;
913 m_activeState
= NULL
;
915 m_savedState
->GetDocument()->Modify(TRUE
);
916 ctConfigToolView
* view
= (ctConfigToolView
*) m_savedState
->GetDocument()->GetFirstView();
917 view
->OnChangeFilename();
921 wxASSERT(m_savedState
!= NULL
);
922 wxASSERT(m_activeState
== NULL
);
924 m_savedState
->GetDocument()->Modify(TRUE
);
925 m_savedState
->Attach(m_parent
, m_insertBefore
);
926 ctConfigToolView
* view
= (ctConfigToolView
*) m_savedState
->GetDocument()->GetFirstView();
927 view
->AddItems(wxGetApp().GetMainFrame()->GetConfigTreeCtrl(), m_savedState
);
928 m_activeState
= m_savedState
;
931 m_insertBefore
= NULL
;
932 view
->OnChangeFilename();
940 wxASSERT(m_savedState
!= NULL
);
941 wxASSERT(m_activeState
== NULL
);
943 m_savedState
->GetDocument()->Modify(TRUE
);
944 m_savedState
->Attach(m_parent
, m_insertBefore
);
945 ctConfigToolView
* view
= (ctConfigToolView
*) m_savedState
->GetDocument()->GetFirstView();
946 view
->AddItems(wxGetApp().GetMainFrame()->GetConfigTreeCtrl(), m_savedState
);
947 wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->SelectItem(m_savedState
->GetTreeItemId());
948 m_activeState
= m_savedState
;
950 view
->OnChangeFilename();
954 wxASSERT(m_savedState
== NULL
);
955 wxASSERT(m_activeState
!= NULL
);
957 m_activeState
->GetDocument()->Modify(TRUE
);
958 ctConfigToolView
* view
= (ctConfigToolView
*) m_activeState
->GetDocument()->GetFirstView();
959 m_activeState
->Detach();
960 m_savedState
= m_activeState
;
961 m_activeState
= NULL
;
962 view
->OnChangeFilename();
966 case ctCMD_NEW_ELEMENT
:
970 wxASSERT(m_savedState
!= NULL
);
971 wxASSERT(m_activeState
== NULL
);
973 m_savedState
->GetDocument()->Modify(TRUE
);
974 m_savedState
->Attach(m_parent
, m_insertBefore
);
975 ctConfigToolView
* view
= (ctConfigToolView
*) m_savedState
->GetDocument()->GetFirstView();
976 view
->AddItems(wxGetApp().GetMainFrame()->GetConfigTreeCtrl(), m_savedState
);
977 wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->SelectItem(m_savedState
->GetTreeItemId());
979 m_activeState
= m_savedState
;
984 wxASSERT(m_savedState
== NULL
);
985 wxASSERT(m_activeState
!= NULL
);
987 m_activeState
->GetDocument()->Modify(TRUE
);
988 m_activeState
->Detach();
989 m_savedState
= m_activeState
;
990 m_activeState
= NULL
;
994 case ctCMD_APPLY_PROPERTY
:
996 wxASSERT(m_properties
!= NULL
);
997 wxASSERT(m_activeState
!= NULL
);
999 // Don't update the properties editor first time
1000 // around since it will be done one property at a time
1001 // initially (and no property editor update required)
1004 // Just swap the saved and current properties.
1005 ctProperties propsTemp
= m_activeState
->GetProperties() ;
1006 m_activeState
->GetProperties() = (* m_properties
);
1007 (* m_properties
) = propsTemp
;
1009 // Apply only those that need applying
1010 // (those properties in activeState that are not in propsTemp)
1011 wxNode
* node
= m_activeState
->GetProperties().GetList().GetFirst();
1014 ctProperty
* prop
= (ctProperty
*) node
->GetData();
1015 ctProperty
* otherProp
= propsTemp
.FindProperty(prop
->GetName());
1016 if (otherProp
&& ((*prop
) != (*otherProp
)))
1018 m_activeState
->ApplyProperty(prop
, otherProp
->GetVariant());
1020 node
= node
->GetNext();
1022 m_activeState
->GetDocument()->Modify(TRUE
);
1023 ctConfigToolView
* view
= (ctConfigToolView
*) m_activeState
->GetDocument()->GetFirstView();
1026 ctConfigToolHint
hint(NULL
, ctValueChanged
);
1027 m_activeState
->GetDocument()->UpdateAllViews (NULL
, & hint
);
1030 m_ignoreThis
= FALSE
;