} else if (theId == "INSERT_FOLDER_CMD") {
insertFeatureFolder();
} else if (theId == "ADD_TO_FOLDER_BEFORE_CMD") {
- insertToFolderBefore();
+ insertToFolder(true);
} else if (theId == "ADD_TO_FOLDER_AFTER_CMD") {
- insertToFolderAfter();
+ insertToFolder(false);
} else if (theId == "SELECT_RESULT_CMD") {
//setViewerSelectionMode(-1);
//IMP: an attempt to use result selection with other selection modes
aMgr->finishOperation();
}
-void XGUI_Workshop::insertToFolderBefore()
+
+void XGUI_Workshop::insertToFolder(bool isBefore)
{
QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
if (aObjects.isEmpty())
return;
-}
-void XGUI_Workshop::insertToFolderAfter()
-{
- QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
- if (aObjects.isEmpty())
+ std::list<FeaturePtr> aFeatures;
+ foreach(ObjectPtr aObj, aObjects) {
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
+ if (aFeature.get())
+ aFeatures.push_back(aFeature);
+ }
+ if (aFeatures.empty())
+ return;
+
+ SessionPtr aMgr = ModelAPI_Session::get();
+ DocumentPtr aDoc = aMgr->activeDocument();
+
+ FolderPtr aFolder = isBefore? aDoc->findFolderAbove(aFeatures):
+ aDoc->findFolderBelow(aFeatures);
+ if (!aFolder.get())
return;
+
+ aMgr->startOperation();
+ aDoc->moveToFolder(aFeatures, aFolder);
+ aMgr->finishOperation();
}
/// Insert folder object before currently selected feature
void insertFeatureFolder();
- /// Insert an object to a folder above
- void insertToFolderBefore();
-
- /// Insert an object to a folder below
- void insertToFolderAfter();
+ /// Insert an object to a folder above or below
+ void insertToFolder(bool isBefore);
private slots:
/// SLOT, that is called after the operation is started. Update workshop state according to