[Scummvm-cvs-logs] SF.net SVN: scummvm: [27930] scummex/branches/gsoc2007-gameresbrowser

zbychs at users.sourceforge.net zbychs at users.sourceforge.net
Thu Jul 5 20:08:40 CEST 2007


Revision: 27930
          http://scummvm.svn.sourceforge.net/scummvm/?rev=27930&view=rev
Author:   zbychs
Date:     2007-07-05 11:08:39 -0700 (Thu, 05 Jul 2007)

Log Message:
-----------
Cleanup of the ExplorationTree.

Modified Paths:
--------------
    scummex/branches/gsoc2007-gameresbrowser/src/gui/DirectoryPresenter.cpp
    scummex/branches/gsoc2007-gameresbrowser/src/gui/ExplorationTree.cpp
    scummex/branches/gsoc2007-gameresbrowser/src/gui/ExplorationTree.h
    scummex/branches/gsoc2007-gameresbrowser/src/gui/MainForm.cpp
    scummex/branches/gsoc2007-gameresbrowser/src/gui/Test1.cpp
    scummex/branches/gsoc2007-gameresbrowser/src/gui/VirtualNode.cpp
    scummex/branches/gsoc2007-gameresbrowser/src/plugins/ftregistry.cpp
    scummex/branches/gsoc2007-gameresbrowser/wxdev/Browser.layout

Modified: scummex/branches/gsoc2007-gameresbrowser/src/gui/DirectoryPresenter.cpp
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/gui/DirectoryPresenter.cpp	2007-07-05 17:36:41 UTC (rev 27929)
+++ scummex/branches/gsoc2007-gameresbrowser/src/gui/DirectoryPresenter.cpp	2007-07-05 18:08:39 UTC (rev 27930)
@@ -36,27 +36,16 @@
 
 	VirtualNode* node = _inodeprovider->getNode();
 	ExplorationTree::get()->registerDirectoryPresenter(node, this);
-	ExplorationTree::_getTree()->SetItemHasChildren(node, true);
+	//ExplorationTree::get()->setItemHasChildren(node, true);
 
-	wxTreeItemId dummyTreeItem = ExplorationTree::_getTree()->
-		AppendItem(node->getTreeItem(), _T("Dummy"), -1, -1, NULL);
+	wxTreeItemId dummyTreeItem = ExplorationTree::get()->appendItem(
+		node->getTreeItem(), _T("Dummy"));
 
 	_expanded = false;
 
 	return true;
 }
 
-void recDel(wxTreeCtrl* tree, const wxTreeItemId& item) {
-	wxTreeItemIdValue cookie;
-	while (true) {
-		wxTreeItemId child = tree->GetFirstChild(item, cookie);
-		if (!child.IsOk())
-			break;
-		recDel(tree, child);
-	}
-	tree->Delete(item);
-}
-
 void DirectoryPresenter::doUnrealize(ObjectChain* ochain) {
 	ASSERT(_inodeprovider && _inodeprovider->getNode());
 	std::cout << "DirectoryPresenter::unrealize(): "
@@ -70,12 +59,7 @@
 
 	//is this in the right place? after the kids unrealisation? probably.
 	VirtualNode* node = _inodeprovider->getNode();
-	if (! node->getTreeItem().IsOk())
-		std::cout << "ERROR: DirectoryPresenter::unrealize(): bad tree item." << std::endl;
-	else {
-		//ExplorationTree::_getTree()->DeleteChildren( node->getTreeItem() );
-		recDel(ExplorationTree::_getTree(), node->getTreeItem());
-	}
+	ExplorationTree::get()->deleteChildren(node->getTreeItem());
 
 	_expanded = false;
 	_idirectory = NULL;
@@ -151,15 +135,12 @@
 	for (j = subdirs.begin(); j != subdirs.end(); ++j) {
 		IDirectory* idirectory = *j;
 
-		wxTreeItemId kidTreeItem = ExplorationTree::_getTree()->
-			AppendItem(parent->getTreeItem(),
-					   wxString(idirectory->getName().c_str(), wxConvUTF8),
-					   -1, -1, NULL);
+		wxTreeItemId kidTreeItem = ExplorationTree::get()->appendItem(
+			parent->getTreeItem(), idirectory->getName());
 
 		RCPtr<VirtualNode> virtualDir( new VirtualDirectory(kidTreeItem, idirectory) );
 
-		ExplorationTree::_getTree()->SetItemData(kidTreeItem,
-			new VirtualNodeItemData( virtualDir.get() ) );
+		ExplorationTree::get()->setItemData(kidTreeItem, new VirtualNodeItemData( virtualDir.get() ) );
 
 		prepareKidChain(virtualDir, false);
 	}
@@ -169,15 +150,12 @@
 	for (i = files.begin(); i != files.end(); ++i) {
 		IFile* ifile = *i;
 
-		wxTreeItemId kidTreeItem = ExplorationTree::_getTree()->
-			AppendItem(parent->getTreeItem(),
-					   wxString(ifile->getName().c_str(), wxConvUTF8),
-					   -1, -1, NULL);
+		wxTreeItemId kidTreeItem = ExplorationTree::get()->appendItem(
+			parent->getTreeItem(), ifile->getName());
 
 		RCPtr<VirtualNode> virtualFile( new VirtualFile(kidTreeItem, ifile) );
 
-		ExplorationTree::_getTree()->SetItemData(kidTreeItem,
-			new VirtualNodeItemData( virtualFile.get() ) );
+		ExplorationTree::get()->setItemData(kidTreeItem, new VirtualNodeItemData( virtualFile.get() ) );
 
 		prepareKidChain(virtualFile, true);
 	}

Modified: scummex/branches/gsoc2007-gameresbrowser/src/gui/ExplorationTree.cpp
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/gui/ExplorationTree.cpp	2007-07-05 17:36:41 UTC (rev 27929)
+++ scummex/branches/gsoc2007-gameresbrowser/src/gui/ExplorationTree.cpp	2007-07-05 18:08:39 UTC (rev 27930)
@@ -176,14 +176,75 @@
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
 
-/*static*/ wxTreeCtrl* ExplorationTree::_getTree() {
+/*static*/ /*wxTreeCtrl* ExplorationTree::_getTree() {
 	return get()->getTree();
 }
 
 wxTreeCtrl* ExplorationTree::getTree() {
 	return _explorationTree;
+}*/
+
+wxTreeItemId ExplorationTree::appendItem(const wxTreeItemId& parent, std::string title) {
+	ASSERT_VALID_TREE_ITEM(parent);
+	wxTreeItemId item = _explorationTree->AppendItem(parent, wxString(title.c_str(), wxConvUTF8), -1, -1, NULL);
+	ASSERT_VALID_TREE_ITEM(item);
+	return item;
 }
 
+void ExplorationTree::_recDel(const wxTreeItemId& item) {
+	ASSERT_VALID_TREE_ITEM(item);
+	wxTreeItemIdValue cookie;
+	while (true) {
+		wxTreeItemId child = _explorationTree->GetFirstChild(item, cookie);
+		if (!child.IsOk())
+			break;
+		_recDel(child);
+	}
+	_explorationTree->Delete(item);
+}
+
+void ExplorationTree::deleteChildren(const wxTreeItemId& parent) {
+	ASSERT_VALID_TREE_ITEM(parent);
+	//ExplorationTree::_getTree()->DeleteChildren( node->getTreeItem() );
+	_recDel(parent);
+}
+
+void ExplorationTree::setItemData(const wxTreeItemId& item, wxTreeItemData* data) {
+	ASSERT_VALID_TREE_ITEM(item);
+	_explorationTree->SetItemData(item, data);
+}
+
+wxTreeItemData* ExplorationTree::getItemData(const wxTreeItemId& item) {
+	ASSERT_VALID_TREE_ITEM(item);
+	return _explorationTree->GetItemData(item);
+}
+
+wxTreeItemId ExplorationTree::getItemParent(const wxTreeItemId& item) {
+	ASSERT_VALID_TREE_ITEM(item);
+	wxTreeItemId parent = _explorationTree->GetItemParent(item);
+	ASSERT_VALID_TREE_ITEM(parent);
+	return parent;
+}
+
+wxString ExplorationTree::getItemText(const wxTreeItemId& item) {
+	ASSERT_VALID_TREE_ITEM(item);
+	return _explorationTree->GetItemText(item);
+}
+
+
+wxTreeItemId ExplorationTree::addRoot(std::string title) {
+	wxTreeItemId item = _explorationTree->AddRoot(title, -1, -1, NULL);
+	ASSERT_VALID_TREE_ITEM(item);
+	return item;
+}
+
+void ExplorationTree::deleteAllItems() {
+	_explorationTree->DeleteAllItems();
+}
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
 ObjectChain* ExplorationTree::getRootObjectChain() {
 	return _rootObjectChain;
 }

Modified: scummex/branches/gsoc2007-gameresbrowser/src/gui/ExplorationTree.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/gui/ExplorationTree.h	2007-07-05 17:36:41 UTC (rev 27929)
+++ scummex/branches/gsoc2007-gameresbrowser/src/gui/ExplorationTree.h	2007-07-05 18:08:39 UTC (rev 27930)
@@ -15,6 +15,9 @@
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
 
+#define ASSERT_VALID_TREE_ITEM(item) \
+	ASSERT(item.IsOk())
+
 struct PanelInfo;
 struct PanelMap;
 struct DirMap;
@@ -48,8 +51,17 @@
 
 	static void initialize(wxTreeCtrl* explorationTree, wxNotebook* panelNotebook);
 
-	static wxTreeCtrl* _getTree();
-	wxTreeCtrl* getTree();
+	//static wxTreeCtrl* _getTree();
+	//wxTreeCtrl* getTree();
+	wxTreeItemId appendItem(const wxTreeItemId& parent, std::string title);
+	void _recDel(const wxTreeItemId& item); //HACK
+	void deleteChildren(const wxTreeItemId& parent);
+	void setItemData(const wxTreeItemId& item, wxTreeItemData* data);
+	wxTreeItemData* getItemData(const wxTreeItemId& item);
+	wxTreeItemId getItemParent(const wxTreeItemId& item);
+	wxString getItemText(const wxTreeItemId& item);
+	wxTreeItemId addRoot(std::string title);
+	void deleteAllItems();
 
 	ObjectChain* getRootObjectChain();
 

Modified: scummex/branches/gsoc2007-gameresbrowser/src/gui/MainForm.cpp
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/gui/MainForm.cpp	2007-07-05 17:36:41 UTC (rev 27929)
+++ scummex/branches/gsoc2007-gameresbrowser/src/gui/MainForm.cpp	2007-07-05 18:08:39 UTC (rev 27930)
@@ -189,10 +189,3 @@
 #endif
 }
 
-/*
- * OnTest0
- */
-void MainForm::OnTest0(wxCommandEvent& event)
-{
-	// insert your code here
-}

Modified: scummex/branches/gsoc2007-gameresbrowser/src/gui/Test1.cpp
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/gui/Test1.cpp	2007-07-05 17:36:41 UTC (rev 27929)
+++ scummex/branches/gsoc2007-gameresbrowser/src/gui/Test1.cpp	2007-07-05 18:08:39 UTC (rev 27930)
@@ -62,22 +62,68 @@
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
 
+void MainForm::OnTest0(wxCommandEvent& event) {
+
+	OnTest1Cleanup(event);
+
+	std::cout << "Registering Test1 Plugin." << std::endl;
+	ObjectRegistry::get()->registerPlugin( &getTest1Plugin, false );
+
+	wxTreeItemId rootItem = ExplorationTree::get()->addRoot(_T("RootDirectory"));
+
+	RCPtr<RootDirectory> rootDir( new RootDirectory(rootItem) );
+
+	ExplorationTree::get()->setItemData(rootItem, new VirtualNodeItemData( rootDir.get() ) );
+
+
+	wxFileName doll(_T("data"), _T("lalka.bmp"));
+	wxFileName dog(_T("data"), _T("pies.bmp"));
+	wxFileName foxes(_T("data"), _T("lisy.bmp"));
+
+	if (doll.IsOk() && doll.FileExists() && doll.IsFileReadable())
+		rootDir->addFile("Doll", toString(doll.GetFullPath()));
+
+	if (dog.IsOk() && dog.FileExists() && dog.IsFileReadable())
+		rootDir->addFile("Dog", toString(dog.GetFullPath()));
+
+	if (foxes.IsOk() && foxes.FileExists() && foxes.IsFileReadable())
+		rootDir->addFile("Foxes", toString(foxes.GetFullPath()));
+
+
+	ObjectChain* rootChain = ExplorationTree::get()->getRootObjectChain();
+	rootChain->addObject(rootDir);
+
+	//RCPtr<BMPParser> bmp(new BMPParser());
+	//RCPtr<ImagePresenter> pres(new ImagePresenter( MainPanel::get() ));
+	//rootChain->addObject(pres);
+
+	rootChain->complete();
+
+	bool res = rootChain->realize();
+
+	if (!res) {
+		wxMessageBox(_T("ObjectChain realisation failed."), _T("Test0 Failed"),
+			wxOK | wxICON_ERROR, this);
+	}
+}
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
 void MainForm::OnTest1(wxCommandEvent& event) {
 
 	OnTest1Cleanup(event);
 	
 	std::cout << "Registering Test1 Plugin." << std::endl;
-	ObjectRegistry::get()->registerPlugin( &getTest1Plugin, true );
+	ObjectRegistry::get()->registerPlugin( &getTest1Plugin, false );
 	
 #ifndef NO_BOBJECTS
 
-	wxTreeItemId rootItem = ExplorationTree::_getTree()->
-		AddRoot(_T("RootDirectory"), -1, -1, NULL);
+	wxTreeItemId rootItem = ExplorationTree::get()->addRoot(_T("RootDirectory"));
 
 	RCPtr<RootDirectory> rootDir( new RootDirectory(rootItem) );
 
-	ExplorationTree::_getTree()->SetItemData(rootItem,
-		new VirtualNodeItemData( rootDir.get() ) );
+	ExplorationTree::get()->setItemData(rootItem, new VirtualNodeItemData( rootDir.get() ) );
 
 
 	wxFileName doll(_T("data"), _T("lalka.bmp"));
@@ -98,11 +144,6 @@
 
 	ObjectChain* rootChain = ExplorationTree::get()->getRootObjectChain();
 	rootChain->addObject(rootDir);
-
-	//RCPtr<BMPParser> bmp(new BMPParser());
-	//RCPtr<ImagePresenter> pres(new ImagePresenter( MainPanel::get() ));
-	//rootChain->addObject(pres);
-
 	rootChain->complete();
 
 	bool res = rootChain->realize();
@@ -112,7 +153,6 @@
 			wxOK | wxICON_ERROR, this);
 	}
 
-	//Layout();
 #endif
 
 }
@@ -121,8 +161,9 @@
 /////////////////////////////////////////////////////////////////////////////
 
 void MainForm::OnTest1Cleanup(wxCommandEvent& event) {
+	std::cout << "Test1 Cleanup." << std::endl;
 #ifndef NO_BOBJECTS
-	ExplorationTree::_getTree()->DeleteAllItems();
+	ExplorationTree::get()->deleteAllItems();
 	ObjectChain* rootChain = ExplorationTree::get()->getRootObjectChain();
 	rootChain->removeAllObjects();
 #endif

Modified: scummex/branches/gsoc2007-gameresbrowser/src/gui/VirtualNode.cpp
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/gui/VirtualNode.cpp	2007-07-05 17:36:41 UTC (rev 27929)
+++ scummex/branches/gsoc2007-gameresbrowser/src/gui/VirtualNode.cpp	2007-07-05 18:08:39 UTC (rev 27930)
@@ -24,7 +24,7 @@
 	if (!item.IsOk())
 		return NULL;
 	VirtualNodeItemData* data = static_cast<VirtualNodeItemData*>
-		(ExplorationTree::_getTree()->GetItemData(item));
+		(ExplorationTree::get()->getItemData(item));
 	if (!data)
 		return NULL;
 	return data->_node;
@@ -53,13 +53,13 @@
 
 VirtualNode* VirtualNode::getParent() {
 	ASSERT(_mineTreeItem.IsOk());
-	wxTreeItemId parentTreeItem = ExplorationTree::_getTree()->GetItemParent(_mineTreeItem);
+	wxTreeItemId parentTreeItem = ExplorationTree::get()->getItemParent(_mineTreeItem);
 	return VirtualNodeItemData::getNode(parentTreeItem);
 }
 
 wxString VirtualNode::getTreeItemName() {
 	ASSERT(_mineTreeItem.IsOk());
-	wxString name = ExplorationTree::_getTree()->GetItemText(_mineTreeItem);
+	wxString name = ExplorationTree::get()->getItemText(_mineTreeItem);
 	return name;
 }
 

Modified: scummex/branches/gsoc2007-gameresbrowser/src/plugins/ftregistry.cpp
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/plugins/ftregistry.cpp	2007-07-05 17:36:41 UTC (rev 27929)
+++ scummex/branches/gsoc2007-gameresbrowser/src/plugins/ftregistry.cpp	2007-07-05 18:08:39 UTC (rev 27930)
@@ -39,11 +39,13 @@
 /////////////////////////////////////////////////////////////////////////////
 // Plugin registration
 
+//TODO: don't insert duplicates
 void FileTypeRegistry::registerRecognizerPlugin(const ObjectPlugin* oplugin) {
 	RCPtr<BObject> recognizer( oplugin->newInstance() );
 	_recognizers.push_back(recognizer);
 }
 
+//TODO: don't insert duplicates
 void FileTypeRegistry::registerResolverPlugin(const ObjectPlugin* oplugin) {
 	RCPtr<BObject> resolver( oplugin->newInstance() );
 	_resolvers.push_back(resolver);

Modified: scummex/branches/gsoc2007-gameresbrowser/wxdev/Browser.layout
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/wxdev/Browser.layout	2007-07-05 17:36:41 UTC (rev 27929)
+++ scummex/branches/gsoc2007-gameresbrowser/wxdev/Browser.layout	2007-07-05 18:08:39 UTC (rev 27930)
@@ -1,7 +1,7 @@
 [Editor_4]
-CursorCol=42
+CursorCol=3
 CursorRow=51
-TopLine=40
+TopLine=52
 LeftChar=1
 Open=1
 Top=0


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list