1 /////////////////////////////////////////////////////////////////////////////
2 // Name: configtooldoc.h
3 // Purpose: Document class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _CT_CONFIGTOOLDOC_H_
13 #define _CT_CONFIGTOOLDOC_H_
15 #include "wx/docview.h"
16 #include "wx/cmdproc.h"
18 #include "configitem.h"
20 class wxSimpleHtmlTag
;
21 class ctConfiguration
;
27 class ctConfigToolDoc
: public wxDocument
29 DECLARE_DYNAMIC_CLASS(ctConfigToolDoc
)
35 virtual bool OnCreate(const wxString
& path
, long flags
);
36 virtual bool OnOpenDocument(const wxString
& filename
);
37 virtual bool OnSaveDocument(const wxString
& filename
);
38 virtual bool OnNewDocument() { return true; }
39 virtual bool OnCloseDocument() ;
40 virtual bool Save(); // Overridden only to correct bug in wxWidgets, docview.cpp
44 /// Returns the top item.
45 ctConfigItem
* GetTopItem() const { return m_topItem
; }
47 /// Sets the top item.
48 void SetTopItem(ctConfigItem
* item
) { m_topItem
= item
; }
50 /// Returns the clipboard item.
51 ctConfigItem
* GetClipboardItem() const { return m_clipboardItem
; }
53 /// Sets the clipboard item.
54 void SetClipboardItem(ctConfigItem
* item
) ;
56 /// Clears the clipboard item.
57 void ClearClipboard() ;
59 /// Gets the current framework directory
60 wxString
GetFrameworkDir(bool makeUnix
);
70 /// Save the settings file
71 bool DoSave(const wxString
& filename
);
73 /// Recursive helper function for file saving
74 bool DoSave(ctConfigItem
* item
, wxOutputStream
& stream
, int indent
);
76 /// Open the settings file
77 bool DoOpen(const wxString
& filename
);
79 /// Helper for file opening.
80 bool DoOpen(wxSimpleHtmlTag
* tag
, ctConfigItem
* parent
);
82 /// Refresh dependencies
83 void RefreshDependencies();
84 void RefreshDependencies(ctConfigItem
* item
);
86 /// Clear dependencies
87 void ClearDependencies(ctConfigItem
* item
);
89 /// Generate the text of a setup.h
90 wxString
GenerateSetup();
93 void GenerateSetup(ctConfigItem
* item
, wxString
& str
);
95 /// Generate a configure command
96 wxString
GenerateConfigureCommand();
99 void GenerateConfigureCommand(ctConfigItem
* item
, wxString
& str
);
101 /// Finds the next item in the tree
102 ctConfigItem
* FindNextItem(ctConfigItem
* item
, bool wrap
);
104 /// Finds the next sibling in the tree
105 ctConfigItem
* FindNextSibling(ctConfigItem
* item
);
108 ctConfigItem
* m_topItem
;
109 ctConfigItem
* m_clipboardItem
;
113 * ctConfiguration is a configuration or a place-holder node within the
114 * hierarchy of configurations.
117 class ctConfiguration
: public wxObject
121 ctConfiguration(ctConfiguration
* parent
, const wxString
& name
);
125 /// Copy constructor.
126 ctConfiguration(const ctConfiguration
& configuration
) : wxObject()
128 (*this) = configuration
;
133 /// Assignment operator.
134 void operator= (const ctConfiguration
& configuration
);
137 ctConfiguration
* Clone()
139 ctConfiguration
* configuration
= new ctConfiguration
;
140 *configuration
= *this;
141 return configuration
;
144 /// Create a clone of this and children
145 ctConfiguration
* DeepClone();
151 void AddChild(ctConfiguration
* config
);
153 /// Remove (but don't delete) a child
154 void RemoveChild(ctConfiguration
* config
);
156 /// Find an item in this hierarchy
157 ctConfiguration
* FindConfiguration(const wxString
& name
);
159 /// Find the next sibling
160 ctConfiguration
* FindNextSibling();
162 /// Find the previous sibling
163 ctConfiguration
* FindPreviousSibling();
165 /// Detach: remove from parent, and remove tree items
168 /// Attach: insert before the given position
169 void Attach(ctConfiguration
* parent
, ctConfiguration
* insertbefore
);
171 void DetachFromTree();
175 /// Returns the top-level item.
176 ctConfigItem
* GetTopItem() const { return m_topItem
; }
178 /// Sets the top-level item.
179 void SetTopItem(ctConfigItem
* item
) { m_topItem
= item
; }
181 /// Returns the name.
182 wxString
GetName() const { return m_name
; }
185 void SetName(const wxString
& name
) { m_name
= name
; }
188 wxString
GetDescription() const { return m_description
; }
191 void SetDescription(const wxString
& descr
) { m_description
= descr
; }
193 /// Set the tree item id
194 void SetTreeItem(wxTreeItemId id
) { m_treeItemId
= id
; }
197 wxTreeItemId
GetTreeItemId() const { return m_treeItemId
; }
199 /// Get the list of children
200 wxList
& GetChildren() { return m_children
; }
202 /// Get the nth child
203 ctConfiguration
* GetChild(int n
) const;
205 /// Get the child count
206 int GetChildCount() const;
209 ctConfiguration
* GetParent() const { return m_parent
; }
212 void SetParent(ctConfiguration
* parent
) { m_parent
= parent
; }
214 /// Get the associated document (currently, assumes
215 /// there's only ever one document active)
216 ctConfigToolDoc
* GetDocument() ;
220 /// The corresponding tree item
221 wxTreeItemId m_treeItemId
;
223 /// The list of children.
226 /// The parent config item
227 ctConfiguration
* m_parent
;
233 wxString m_description
;
235 /// The top-level item of this description, if any
236 ctConfigItem
* m_topItem
;
238 DECLARE_CLASS(ctConfiguration
)
243 * Implements a document editing command.
244 * We only need to store one state at a time,
245 * since we don't have (or need) multiple selection.
248 #define ctCMD_NEW_ELEMENT 1
249 #define ctCMD_PASTE 2
251 #define ctCMD_APPLY_PROPERTY 4
253 class ctConfigCommand
: public wxCommand
256 ctConfigCommand(const wxString
& name
, int cmdId
,
257 ctConfigItem
* activeState
, ctConfigItem
* savedState
,
258 ctConfigItem
* parent
= NULL
, ctConfigItem
* insertBefore
= NULL
,
259 bool ignoreFirstTime
= false);
260 ctConfigCommand(const wxString
& name
, int cmdId
,
261 ctConfigItem
* activeState
, ctProperties
* properties
,
262 bool ignoreFirstTime
= false);
267 bool DoAndUndo(bool doCmd
); // Combine Do and Undo into one
270 ctConfigItem
* m_activeState
;
271 ctConfigItem
* m_savedState
;
272 ctProperties
* m_properties
;
273 bool m_ignoreThis
; // Ignore 1st Do because we already did it
275 ctConfigItem
* m_parent
;
276 ctConfigItem
* m_insertBefore
;
281 // _CT_CONFIGTOOLDOC_H_