Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
weblate committed Jan 4, 2017
2 parents 859cc34 + 6f29037 commit 8b545ef
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 31 deletions.
32 changes: 6 additions & 26 deletions src/gui/clipboardbrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,10 +705,11 @@ QVariantMap ClipboardBrowser::copyIndexes(const QModelIndexList &indexes, bool s

int ClipboardBrowser::removeIndexes(const QModelIndexList &indexes)
{
if ( indexes.isEmpty() )
Q_ASSERT(m_itemLoader);

if ( indexes.isEmpty() || !m_itemLoader->canRemoveItems(indexes) )
return -1;

Q_ASSERT(m_itemLoader);
m_itemLoader->itemsRemovedByUser(indexes);

QList<int> rows;
Expand Down Expand Up @@ -1269,24 +1270,6 @@ void ClipboardBrowser::showItemContent()
}
}

void ClipboardBrowser::removeRow(int row)
{
const QModelIndex indexToRemove = index(row);
if ( !indexToRemove.isValid() )
return;

bool removingCurrent = indexToRemove == currentIndex();

Q_ASSERT(m_itemLoader);
m_itemLoader->itemsRemovedByUser(QList<QModelIndex>() << indexToRemove);
m.removeRow(row);

delayedSaveItems();

if (removingCurrent)
setCurrentIndex( index(qMin(row, length() - 1)) );
}

void ClipboardBrowser::editNotes()
{
QModelIndex ind = currentIndex();
Expand Down Expand Up @@ -1525,12 +1508,9 @@ void ClipboardBrowser::editSelected()
void ClipboardBrowser::remove()
{
const QModelIndexList toRemove = selectedIndexes();
Q_ASSERT(m_itemLoader);
if ( !toRemove.isEmpty() && m_itemLoader->canRemoveItems(toRemove) ) {
const int lastRow = removeIndexes(toRemove);
if (lastRow != -1)
setCurrent(lastRow);
}
const int currentRow = removeIndexes(toRemove);
if (currentRow != -1)
setCurrent(currentRow);
}

bool ClipboardBrowser::select(uint itemHash, SelectActions selectActions)
Expand Down
4 changes: 1 addition & 3 deletions src/gui/clipboardbrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class ClipboardBrowser : public QListView

QVariantMap copyIndexes(const QModelIndexList &indexes, bool serializeItems = true) const;

/** Remove items and return row number of last removed item. */
/** Remove items and return smallest row number (new current item if selection was removed). */
int removeIndexes(const QModelIndexList &indexes);

/** Paste items. */
Expand Down Expand Up @@ -198,8 +198,6 @@ class ClipboardBrowser : public QListView
/** Add items. */
void addItems(const QStringList &items);

void removeRow(int row);

/** Set current item. */
void setCurrent(
int row, //!< Row of the item.
Expand Down
19 changes: 17 additions & 2 deletions src/scriptable/scriptableproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,24 @@ void ScriptableProxyHelper::browserRemoveRows(QList<int> rows)

qSort( rows.begin(), rows.end(), qGreater<int>() );

QModelIndexList indexes;
indexes.reserve(rows.size());

ClipboardBrowser::Lock lock(c);
foreach (int row, rows)
c->removeRow(row);
foreach (int row, rows) {
const QModelIndex indexToRemove = c->index(row);
if ( indexToRemove.isValid() )
indexes.append(indexToRemove);
}

const QPersistentModelIndex currentIndex = c->currentIndex();

const int lastRow = c->removeIndexes(indexes);

if ( !currentIndex.isValid() ) {
const int currentRow = qMin(lastRow, c->length() - 1);
c->setCurrent(currentRow);
}
}

void ScriptableProxyHelper::browserEditRow(int arg1)
Expand Down

0 comments on commit 8b545ef

Please sign in to comment.