BMessage* Copy::Do(PDocument *doc, BMessage *settings) { BMessage *clip = NULL; BMessage *node = NULL; BMessage *from = NULL; BMessage *to = NULL; bool fselect = false; bool tselect = false; BMessage *copyMessage = new BMessage(); BList *selected = doc->GetSelected(); BList *allConnections = doc->GetAllConnections(); int32 i = 0; Indexer *indexer = new Indexer(doc); if (doc->Lock()) { for (i=0;i<selected->CountItems();i++) { if (node=(BMessage *)selected->ItemAt(i)) { if (node->what != P_C_CONNECTION_TYPE) copyMessage->AddMessage("node",indexer->IndexNode(node)); } } for (i=0;i<allConnections->CountItems();i++ ) { node = (BMessage *)allConnections->ItemAt(i); if ( (node->FindPointer("From",(void **)&from) == B_OK) && (node->FindPointer("To",(void **)&to) == B_OK) ) { if ((from->FindBool("selected",&fselect)==B_OK) && (to->FindBool("selected",&tselect) == B_OK) ) { if (fselect && tselect) copyMessage->AddMessage("node",indexer->IndexConnection(node,true)); else if (fselect || tselect) copyMessage->AddMessage("node",indexer->IndexConnection(node)); } } } doc->Unlock(); } if (be_clipboard->Lock()) { be_clipboard->Clear(); if (clip = be_clipboard->Data()) { clip->AddData("application/x-vnd.projectconceptor-document", B_MIME_TYPE, copyMessage, sizeof(copyMessage)); clip->AddMessage("test",copyMessage); PRINT_OBJECT(*clip); be_clipboard->Commit(); } be_clipboard->Unlock(); } settings = PCommand::Do(doc,settings); return settings; }
status_t PDocument::Archive(BMessage* archive, bool deep) const { TRACE(); BLooper::Archive(archive, deep); Indexer *indexer = new Indexer((PDocument *)this); int32 i = 0; BMessage *commandManage = new BMessage(); BMessage *tmpNode = NULL; BMessage *allNodesMessage = new BMessage(); BMessage *allConnectionsMessage = new BMessage(); BMessage *selectedMessage = new BMessage(); archive->AddMessage("PDocument::documentSetting",documentSetting); //save all Nodes for (i=0; i<allNodes->CountItems();i++) { tmpNode=(BMessage *)allNodes->ItemAt(i); allNodesMessage->AddMessage("node",indexer->IndexNode(tmpNode)); } archive->AddMessage("PDocument::allNodes",allNodesMessage); //save all Connections for (i=0; i<allConnections->CountItems();i++) { tmpNode=(BMessage *)allConnections->ItemAt(i); allConnectionsMessage->AddMessage("node",indexer->IndexConnection(tmpNode)); } archive->AddMessage("PDocument::allConnections",allConnectionsMessage); //save the selected List for (i=0; i<selected->CountItems();i++) { selectedMessage->AddPointer("node",selected->ItemAt(i)); } archive->AddMessage("PDocument::selected",selectedMessage); //save all Command related Stuff like Undo/Makor // commandManager->Archive(commandManage); for (i=0;i<(commandManager->GetUndoList())->CountItems();i++) { commandManage->AddMessage("undo",indexer->IndexMacroCommand((BMessage *)(commandManager->GetUndoList())->ItemAt(i))); } for (i=0;i<(commandManager->GetMacroList())->CountItems();i++) { commandManage->AddMessage("macro",(BMessage *)(commandManager->GetMacroList())->ItemAt(i)); } commandManage->AddInt32("undoStatus",commandManager->GetUndoIndex()); archive->AddMessage("PDocument::commandManager", commandManage); delete indexer; delete commandManage; //delete tmpNode; delete allNodesMessage; delete allConnectionsMessage; delete selectedMessage; return B_OK; }
void PDocument::PushToStream(BPositionIO *pushTo) { Indexer *indexer = new Indexer((PDocument *)this); BMessage *tmpNode = NULL; BMessage *commandManage = new BMessage(); BMessage *selectedMessage = new BMessage(); int i = 0; //**security check if the passed BPositionIO ok is documentSetting->Flatten(pushTo); for (i=0; i<allNodes->CountItems();i++) { tmpNode=(BMessage *)allNodes->ItemAt(i); BMessage *indexed = indexer->IndexNode(tmpNode); indexed->Flatten(pushTo); } for (i=0; i<allConnections->CountItems();i++) { tmpNode=(BMessage *)allConnections->ItemAt(i); BMessage *indexed = indexer->IndexConnection(tmpNode); indexed->Flatten(pushTo); } for (i=0; i<selected->CountItems();i++) { selectedMessage->AddPointer("node",selected->ItemAt(i)); } selectedMessage->Flatten(pushTo); for (i=0;i<(commandManager->GetMacroList())->CountItems();i++) { BMessage *macro =(BMessage *)(commandManager->GetMacroList()->ItemAt(i)); macro->Flatten(pushTo); } for (i=0;i<(commandManager->GetUndoList())->CountItems();i++) { BMessage *indexed = indexer->IndexMacroCommand((BMessage *)(commandManager->GetUndoList()->ItemAt(i))); indexed->Flatten(pushTo); } //**add the UndoIndex commandManage->AddInt32("undoStatus",commandManager->GetUndoIndex()); //add the commandManage commandManage->Flatten(pushTo); delete indexer; delete commandManage; delete selectedMessage; }