forked from teamnwah/openmw-tes3coop
added extended versions of revert and delete
This commit is contained in:
parent
48468b7d0c
commit
7d1ecea20c
4 changed files with 146 additions and 0 deletions
|
@ -1,6 +1,10 @@
|
||||||
|
|
||||||
#include "commanddispatcher.hpp"
|
#include "commanddispatcher.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include <components/misc/stringops.hpp>
|
||||||
|
|
||||||
#include "../doc/document.hpp"
|
#include "../doc/document.hpp"
|
||||||
|
|
||||||
#include "idtable.hpp"
|
#include "idtable.hpp"
|
||||||
|
@ -88,6 +92,13 @@ void CSMWorld::CommandDispatcher::setEditLock (bool locked)
|
||||||
void CSMWorld::CommandDispatcher::setSelection (const std::vector<std::string>& selection)
|
void CSMWorld::CommandDispatcher::setSelection (const std::vector<std::string>& selection)
|
||||||
{
|
{
|
||||||
mSelection = selection;
|
mSelection = selection;
|
||||||
|
std::for_each (mSelection.begin(), mSelection.end(), Misc::StringUtils::toLower);
|
||||||
|
std::sort (mSelection.begin(), mSelection.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSMWorld::CommandDispatcher::setExtendedTypes (const std::vector<UniversalId>& types)
|
||||||
|
{
|
||||||
|
mExtendedTypes = types;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CSMWorld::CommandDispatcher::canDelete() const
|
bool CSMWorld::CommandDispatcher::canDelete() const
|
||||||
|
@ -106,6 +117,20 @@ bool CSMWorld::CommandDispatcher::canRevert() const
|
||||||
return getRevertableRecords().size()!=0;
|
return getRevertableRecords().size()!=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<CSMWorld::UniversalId> CSMWorld::CommandDispatcher::getExtendedTypes() const
|
||||||
|
{
|
||||||
|
std::vector<CSMWorld::UniversalId> tables;
|
||||||
|
|
||||||
|
if (mId==UniversalId::Type_Cells)
|
||||||
|
{
|
||||||
|
tables.push_back (mId);
|
||||||
|
tables.push_back (UniversalId::Type_References);
|
||||||
|
/// \todo add other cell-specific types
|
||||||
|
}
|
||||||
|
|
||||||
|
return tables;
|
||||||
|
}
|
||||||
|
|
||||||
void CSMWorld::CommandDispatcher::executeDelete()
|
void CSMWorld::CommandDispatcher::executeDelete()
|
||||||
{
|
{
|
||||||
if (mLocked)
|
if (mLocked)
|
||||||
|
@ -163,3 +188,80 @@ void CSMWorld::CommandDispatcher::executeRevert()
|
||||||
if (rows.size()>1)
|
if (rows.size()>1)
|
||||||
mDocument.getUndoStack().endMacro();
|
mDocument.getUndoStack().endMacro();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSMWorld::CommandDispatcher::executeExtendedDelete()
|
||||||
|
{
|
||||||
|
if (mExtendedTypes.size()>1)
|
||||||
|
mDocument.getUndoStack().beginMacro (tr ("Extended delete of multiple records"));
|
||||||
|
|
||||||
|
for (std::vector<UniversalId>::const_iterator iter (mExtendedTypes.begin());
|
||||||
|
iter!=mExtendedTypes.end(); ++iter)
|
||||||
|
{
|
||||||
|
if (*iter==mId)
|
||||||
|
executeDelete();
|
||||||
|
else if (*iter==UniversalId::Type_References)
|
||||||
|
{
|
||||||
|
IdTable& model = dynamic_cast<IdTable&> (
|
||||||
|
*mDocument.getData().getTableModel (*iter));
|
||||||
|
|
||||||
|
const RefCollection& collection = mDocument.getData().getReferences();
|
||||||
|
|
||||||
|
int size = collection.getSize();
|
||||||
|
|
||||||
|
for (int i=size-1; i>=0; --i)
|
||||||
|
{
|
||||||
|
const Record<CellRef>& record = collection.getRecord (i);
|
||||||
|
|
||||||
|
if (record.mState==RecordBase::State_Deleted)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!std::binary_search (mSelection.begin(), mSelection.end(),
|
||||||
|
Misc::StringUtils::lowerCase (record.get().mCell)))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
mDocument.getUndoStack().push (
|
||||||
|
new CSMWorld::DeleteCommand (model, record.get().mId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mExtendedTypes.size()>1)
|
||||||
|
mDocument.getUndoStack().endMacro();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSMWorld::CommandDispatcher::executeExtendedRevert()
|
||||||
|
{
|
||||||
|
if (mExtendedTypes.size()>1)
|
||||||
|
mDocument.getUndoStack().beginMacro (tr ("Extended revert of multiple records"));
|
||||||
|
|
||||||
|
for (std::vector<UniversalId>::const_iterator iter (mExtendedTypes.begin());
|
||||||
|
iter!=mExtendedTypes.end(); ++iter)
|
||||||
|
{
|
||||||
|
if (*iter==mId)
|
||||||
|
executeRevert();
|
||||||
|
else if (*iter==UniversalId::Type_References)
|
||||||
|
{
|
||||||
|
IdTable& model = dynamic_cast<IdTable&> (
|
||||||
|
*mDocument.getData().getTableModel (*iter));
|
||||||
|
|
||||||
|
const RefCollection& collection = mDocument.getData().getReferences();
|
||||||
|
|
||||||
|
int size = collection.getSize();
|
||||||
|
|
||||||
|
for (int i=size-1; i>=0; --i)
|
||||||
|
{
|
||||||
|
const Record<CellRef>& record = collection.getRecord (i);
|
||||||
|
|
||||||
|
if (!std::binary_search (mSelection.begin(), mSelection.end(),
|
||||||
|
Misc::StringUtils::lowerCase (record.get().mCell)))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
mDocument.getUndoStack().push (
|
||||||
|
new CSMWorld::RevertCommand (model, record.get().mId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mExtendedTypes.size()>1)
|
||||||
|
mDocument.getUndoStack().endMacro();
|
||||||
|
}
|
|
@ -22,6 +22,7 @@ namespace CSMWorld
|
||||||
CSMDoc::Document& mDocument;
|
CSMDoc::Document& mDocument;
|
||||||
UniversalId mId;
|
UniversalId mId;
|
||||||
std::vector<std::string> mSelection;
|
std::vector<std::string> mSelection;
|
||||||
|
std::vector<UniversalId> mExtendedTypes;
|
||||||
|
|
||||||
std::vector<std::string> getDeletableRecords() const;
|
std::vector<std::string> getDeletableRecords() const;
|
||||||
|
|
||||||
|
@ -37,16 +38,31 @@ namespace CSMWorld
|
||||||
|
|
||||||
void setSelection (const std::vector<std::string>& selection);
|
void setSelection (const std::vector<std::string>& selection);
|
||||||
|
|
||||||
|
void setExtendedTypes (const std::vector<UniversalId>& types);
|
||||||
|
///< Set record lists selected by the user for extended operations.
|
||||||
|
|
||||||
bool canDelete() const;
|
bool canDelete() const;
|
||||||
|
|
||||||
bool canRevert() const;
|
bool canRevert() const;
|
||||||
|
|
||||||
|
/// Return IDs of the record collection that can also be affected when
|
||||||
|
/// operating on the record collection this dispatcher is used for.
|
||||||
|
///
|
||||||
|
/// \note The returned collection contains the ID of the record collection this
|
||||||
|
/// dispatcher is used for. However if that record collection does not support
|
||||||
|
/// the extended mode, the returned vector will be empty instead.
|
||||||
|
std::vector<UniversalId> getExtendedTypes() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void executeDelete();
|
void executeDelete();
|
||||||
|
|
||||||
void executeRevert();
|
void executeRevert();
|
||||||
|
|
||||||
|
void executeExtendedDelete();
|
||||||
|
|
||||||
|
void executeExtendedRevert();
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,10 @@ void CSVWorld::Table::contextMenuEvent (QContextMenuEvent *event)
|
||||||
|
|
||||||
mDispatcher->setSelection (records);
|
mDispatcher->setSelection (records);
|
||||||
|
|
||||||
|
std::vector<CSMWorld::UniversalId> extendedTypes = mDispatcher->getExtendedTypes();
|
||||||
|
|
||||||
|
mDispatcher->setExtendedTypes (extendedTypes);
|
||||||
|
|
||||||
// create context menu
|
// create context menu
|
||||||
QMenu menu (this);
|
QMenu menu (this);
|
||||||
|
|
||||||
|
@ -63,11 +67,21 @@ void CSVWorld::Table::contextMenuEvent (QContextMenuEvent *event)
|
||||||
menu.addAction (mCreateAction);
|
menu.addAction (mCreateAction);
|
||||||
|
|
||||||
if (mDispatcher->canRevert())
|
if (mDispatcher->canRevert())
|
||||||
|
{
|
||||||
menu.addAction (mRevertAction);
|
menu.addAction (mRevertAction);
|
||||||
|
|
||||||
|
if (!extendedTypes.empty())
|
||||||
|
menu.addAction (mExtendedRevertAction);
|
||||||
|
}
|
||||||
|
|
||||||
if (mDispatcher->canDelete())
|
if (mDispatcher->canDelete())
|
||||||
|
{
|
||||||
menu.addAction (mDeleteAction);
|
menu.addAction (mDeleteAction);
|
||||||
|
|
||||||
|
if (!extendedTypes.empty())
|
||||||
|
menu.addAction (mExtendedDeleteAction);
|
||||||
|
}
|
||||||
|
|
||||||
if (mModel->getFeatures() & CSMWorld::IdTable::Feature_ReorderWithinTopic)
|
if (mModel->getFeatures() & CSMWorld::IdTable::Feature_ReorderWithinTopic)
|
||||||
{
|
{
|
||||||
/// \todo allow reordering of multiple rows
|
/// \todo allow reordering of multiple rows
|
||||||
|
@ -203,6 +217,18 @@ CSVWorld::Table::Table (const CSMWorld::UniversalId& id,
|
||||||
connect (mPreviewAction, SIGNAL (triggered()), this, SLOT (previewRecord()));
|
connect (mPreviewAction, SIGNAL (triggered()), this, SLOT (previewRecord()));
|
||||||
addAction (mPreviewAction);
|
addAction (mPreviewAction);
|
||||||
|
|
||||||
|
/// \todo add a user option, that redirects the extended action to an input panel (in
|
||||||
|
/// the bottom bar) that lets the user select which record collections should be
|
||||||
|
/// modified.
|
||||||
|
|
||||||
|
mExtendedDeleteAction = new QAction (tr ("Extended Delete Record"), this);
|
||||||
|
connect (mExtendedDeleteAction, SIGNAL (triggered()), mDispatcher, SLOT (executeExtendedDelete()));
|
||||||
|
addAction (mExtendedDeleteAction);
|
||||||
|
|
||||||
|
mExtendedRevertAction = new QAction (tr ("Extended Revert Record"), this);
|
||||||
|
connect (mExtendedRevertAction, SIGNAL (triggered()), mDispatcher, SLOT (executeExtendedRevert()));
|
||||||
|
addAction (mExtendedRevertAction);
|
||||||
|
|
||||||
connect (mProxyModel, SIGNAL (rowsInserted (const QModelIndex&, int, int)),
|
connect (mProxyModel, SIGNAL (rowsInserted (const QModelIndex&, int, int)),
|
||||||
this, SLOT (tableSizeUpdate()));
|
this, SLOT (tableSizeUpdate()));
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,8 @@ namespace CSVWorld
|
||||||
QAction *mMoveDownAction;
|
QAction *mMoveDownAction;
|
||||||
QAction *mViewAction;
|
QAction *mViewAction;
|
||||||
QAction *mPreviewAction;
|
QAction *mPreviewAction;
|
||||||
|
QAction *mExtendedDeleteAction;
|
||||||
|
QAction *mExtendedRevertAction;
|
||||||
CSMWorld::IdTableProxyModel *mProxyModel;
|
CSMWorld::IdTableProxyModel *mProxyModel;
|
||||||
CSMWorld::IdTable *mModel;
|
CSMWorld::IdTable *mModel;
|
||||||
int mRecordStatusDisplay;
|
int mRecordStatusDisplay;
|
||||||
|
|
Loading…
Reference in a new issue