/branches/Version13x/Scribus/scribus/plugins/scriptplugin/cmdutil.cpp |
---|
187,3 → 187,31 |
PyErr_SetString(NoDocOpenError, QString("Command does not make sense without an open document")); |
return false; |
} |
QStringList getSelectedItemsByName() |
{ |
QStringList names; |
QPtrListIterator<PageItem> it(Carrier->view->SelItem); |
for ( ; it.current() != 0 ; ++it) |
names.append(it.current()->itemName()); |
return names; |
} |
bool setSelectedItemsByName(QStringList& itemNames) |
{ |
Carrier->view->Deselect(); |
// For each named item |
for (QStringList::Iterator it = itemNames.begin() ; it != itemNames.end() ; it++) |
{ |
// Search for the named item |
PageItem* item = 0; |
for (uint j = 0; j < Carrier->doc->Items.count(); j++) |
if (*it == Carrier->doc->Items.at(j)->itemName()) |
item = Carrier->doc->Items.at(j); |
if (!item) |
return false; |
// and select it |
Carrier->view->SelectItemNr(item->ItemNr); |
} |
return true; |
} |
/branches/Version13x/Scribus/scribus/plugins/scriptplugin/cmdmani.cpp |
---|
171,14 → 171,18 |
if(!checkHaveDocument()) |
return NULL; |
uint ap = Carrier->doc->currentPage->PageNr; |
// If we were passed a list of items to group... |
if (il != 0) |
{ |
int len = PyList_Size(il); |
if (len == 0) |
if (len < 2) |
{ |
Py_INCREF(Py_None); |
return Py_None; |
// We can't very well group only one item |
PyErr_SetString(NoValidObjectError, QObject::tr("Can't group less than two items", "python error")); |
return NULL; |
} |
QStringList oldSelection = getSelectedItemsByName(); |
Carrier->view->Deselect(); |
for (int i = 0; i < len; i++) |
{ |
// FIXME: We might need to explicitly get this string as utf8 |
190,13 → 194,26 |
return NULL; |
Carrier->view->SelectItemNr(ic->ItemNr); |
} |
Carrier->GroupObj(); |
setSelectedItemsByName(oldSelection); |
} |
if (Carrier->view->SelItem.count() != 0) |
// or if no argument list was given but there is a selection... |
else if (Carrier->view->SelItem.count() != 0) |
{ |
if (Carrier->view->SelItem.count() < 2) |
{ |
// We can't very well group only one item |
PyErr_SetString(NoValidObjectError, QObject::tr("Can't group less than two items", "python error")); |
return NULL; |
} |
Carrier->GroupObj(); |
Carrier->view->Deselect(); |
Carrier->view->GotoPage(ap); |
} |
else |
{ |
PyErr_SetString(PyExc_TypeError, QObject::tr("Need selection or argument list of items to group", "python error")); |
return NULL; |
} |
Py_INCREF(Py_None); |
return Py_None; |
} |
/branches/Version13x/Scribus/scribus/plugins/scriptplugin/cmdutil.h |
---|
50,4 → 50,16 |
// 2004-11-12 Craig Ringer see cmdutil.cpp for description |
bool ItemExists(QString name); |
/*! |
* @brief Returns a list of the names of all selected PageItems |
*/ |
QStringList getSelectedItemsByName(); |
/*! |
* @brief Replaces the current selection by selecting all the items named in the passed QStringList |
* |
* Returns false if one or more items can't be selected, true if all were selected. |
* Selection state is undefined on failure. |
*/ |
bool setSelectedItemsByName(QStringList& itemNames); |
#endif |