Gui: allow SelectionSingleton::hasSubSelection() check for sub-element
This is used by relative link command activation for sub-element selection
This commit is contained in:
@@ -437,7 +437,7 @@ bool SelectionSingleton::hasSelection(const char* doc, bool resolve) const
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SelectionSingleton::hasSubSelection(const char* doc) const
|
||||
bool SelectionSingleton::hasSubSelection(const char* doc, bool subElement) const
|
||||
{
|
||||
App::Document *pcDoc = 0;
|
||||
if(!doc || strcmp(doc,"*")!=0) {
|
||||
@@ -446,11 +446,14 @@ bool SelectionSingleton::hasSubSelection(const char* doc) const
|
||||
return false;
|
||||
}
|
||||
for(auto &sel : _SelList) {
|
||||
if((!pcDoc || pcDoc == sel.pDoc)
|
||||
&& sel.pObject != sel.pResolvedObject)
|
||||
{
|
||||
if(pcDoc && pcDoc != sel.pDoc)
|
||||
continue;
|
||||
if(sel.SubName.empty())
|
||||
continue;
|
||||
if(subElement && sel.SubName.back()!='.')
|
||||
return true;
|
||||
if(sel.pObject != sel.pResolvedObject)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -1794,7 +1797,7 @@ PyMethodDef SelectionSingleton::Methods[] = {
|
||||
{"hasSelection", (PyCFunction) SelectionSingleton::sHasSelection, METH_VARARGS,
|
||||
"hasSelection(docName=None, resolve=False) -- check if there is any selection\n"},
|
||||
{"hasSubSelection", (PyCFunction) SelectionSingleton::sHasSubSelection, METH_VARARGS,
|
||||
"hasSubSelection(docName=None) -- check if there is any selection with subname\n"},
|
||||
"hasSubSelection(docName=None,subElement=False) -- check if there is any selection with subname\n"},
|
||||
{"getSelectionFromStack",(PyCFunction) SelectionSingleton::sGetSelectionFromStack, METH_VARARGS,
|
||||
"getSelectionFromStack(docName=None,resolve=1,index=0) -- Return a list of SelectionObjects from selection stack\n"
|
||||
"\ndocName - document name. None means the active document, and '*' means all document"
|
||||
@@ -2271,11 +2274,13 @@ PyObject *SelectionSingleton::sHasSelection(PyObject * /*self*/, PyObject *args)
|
||||
PyObject *SelectionSingleton::sHasSubSelection(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
const char *doc = 0;
|
||||
if (!PyArg_ParseTuple(args, "|s",&doc))
|
||||
PyObject *subElement = Py_False;
|
||||
if (!PyArg_ParseTuple(args, "|sO!",&doc,&PyBool_Type,&subElement))
|
||||
return NULL; // NULL triggers exception
|
||||
|
||||
PY_TRY {
|
||||
return Py::new_reference_to(Py::Boolean(Selection().hasSubSelection(doc)));
|
||||
return Py::new_reference_to(
|
||||
Py::Boolean(Selection().hasSubSelection(doc,PyObject_IsTrue(subElement))));
|
||||
} PY_CATCH;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user