From 921f89cb62e2fa118ba16ea87bcec0ba41751a82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Mon, 17 Apr 2017 13:13:53 +0200 Subject: [PATCH] selecting the topmost klipper item should always set it as clipboard contents Without this, that wasn't always the case if the top item was only the mouse selection. This was presumably broken by 2e47d84772. Also explicitly check the popup item, since it's now owned by Klipper. BUG: 348390 BUG: 251222 --- klipper/history.cpp | 11 +++++++++++ klipper/history.h | 1 + klipper/klipper.cpp | 1 + klipper/klipperpopup.cpp | 7 +++++++ klipper/klipperpopup.h | 1 + 5 files changed, 21 insertions(+) diff --git a/klipper/history.cpp b/klipper/history.cpp index 9640c23b0..36b00e90e 100644 --- a/klipper/history.cpp +++ b/klipper/history.cpp @@ -140,8 +140,19 @@ void History::slotMoveToTop(QAction* action) { } void History::slotMoveToTop(const QByteArray& uuid) { + const QModelIndex item = m_model->indexOf(uuid); + if (item.isValid() && item.row() == 0) { + // The item is already at the top, but it still may be not be set as the actual clipboard + // contents, normally this happens if the item is only in the X11 mouse selection but + // not in the Ctrl+V clipboard. + emit topChanged(); + m_topIsUserSelected = true; + emit topIsUserSelectedSet(); + return; + } m_model->moveToTop(uuid); m_topIsUserSelected = true; + emit topIsUserSelectedSet(); } void History::setMaxSize( unsigned max_size ) { diff --git a/klipper/history.h b/klipper/history.h index 7690ffdc1..7001450fc 100644 --- a/klipper/history.h +++ b/klipper/history.h @@ -136,6 +136,7 @@ Q_SIGNALS: */ void topChanged(); + void topIsUserSelectedSet(); private: /** diff --git a/klipper/klipper.cpp b/klipper/klipper.cpp index 4703227ef..30f3e5815 100644 --- a/klipper/klipper.cpp +++ b/klipper/klipper.cpp @@ -117,6 +117,7 @@ Klipper::Klipper(QObject* parent, const KSharedConfigPtr& config, KlipperMode mo m_popup = new KlipperPopup(m_history); m_popup->setShowHelp(m_mode == KlipperMode::Standalone); connect(m_history, &History::changed, m_popup, &KlipperPopup::slotHistoryChanged); + connect(m_history, &History::topIsUserSelectedSet, m_popup, &KlipperPopup::slotTopIsUserSelectedSet); // we need that collection, otherwise KToggleAction is not happy :} m_collection = new KActionCollection( this ); diff --git a/klipper/klipperpopup.cpp b/klipper/klipperpopup.cpp index 12d3205d9..e0d35e56c 100644 --- a/klipper/klipperpopup.cpp +++ b/klipper/klipperpopup.cpp @@ -175,6 +175,13 @@ void KlipperPopup::rebuild( const QString& filter ) { m_dirty = false; } +void KlipperPopup::slotTopIsUserSelectedSet() { + if ( !m_dirty && m_nHistoryItems > 0 && history()->topIsUserSelected() ) { + actions().at(TOP_HISTORY_ITEM_INDEX)->setCheckable(true); + actions().at(TOP_HISTORY_ITEM_INDEX)->setChecked(true); + } +} + void KlipperPopup::plugAction( QAction* action ) { m_actions.append(action); } diff --git a/klipper/klipperpopup.h b/klipper/klipperpopup.h index 3ba3d97b3..cf70ab977 100644 --- a/klipper/klipperpopup.h +++ b/klipper/klipperpopup.h @@ -61,6 +61,7 @@ public: } public Q_SLOTS: void slotHistoryChanged() { m_dirty = true; } + void slotTopIsUserSelectedSet(); void slotAboutToShow(); /** * set the top history item active, to easy kb navigation