From kde-commits Sun Oct 16 07:55:40 2011 From: Esben Mose Hansen Date: Sun, 16 Oct 2011 07:55:40 +0000 To: kde-commits Subject: [kde-workspace] klipper: Fix and improve shortcuts "next history Message-Id: <20111016075540.EC0AAA60A6 () git ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=131914511518390 Git commit 4f3f5e0dff82289fce704999c647ee1ad2c219b7 by Esben Mose Hansen. Committed on 16/10/2011 at 09:43. Pushed by esben into branch 'master'. Fix and improve shortcuts "next history item" and "previous history item" i= n klipper, provided by Michal Seben REVIEW: 102672 (cherry picked from commit a6b69cb3781b4e3d6b39c8f391e08695a9cb9b75) M +39 -17 klipper/history.cpp M +10 -4 klipper/klipper.cpp http://commits.kde.org/kde-workspace/4f3f5e0dff82289fce704999c647ee1ad2c219= b7 diff --git a/klipper/history.cpp b/klipper/history.cpp index 48e81a1..5964c22 100644 --- a/klipper/history.cpp +++ b/klipper/history.cpp @@ -157,17 +157,28 @@ void History::cycleNext() { if (m_top && m_nextCycle && m_nextCycle !=3D m_top) { HistoryItem* prev =3D m_items[m_nextCycle->previous_uuid()]; HistoryItem* next =3D m_items[m_nextCycle->next_uuid()]; - HistoryItem* endofhist =3D m_items[m_top->previous_uuid()]; - HistoryItem* aftertop =3D m_items[m_top->next_uuid()]; - if (prev =3D=3D m_top) { - prev =3D m_nextCycle; - aftertop =3D m_top; + //if we have only two items in clipboard + if (prev =3D=3D next) { + m_top=3Dm_nextCycle; + } + else { + HistoryItem* endofhist =3D m_items[m_top->previous_uuid()]; + HistoryItem* aftertop =3D m_items[m_top->next_uuid()]; + if (prev =3D=3D m_top) { + prev =3D m_nextCycle; + aftertop =3D m_top; + } + else if (next =3D=3D m_top) { + next =3D m_nextCycle; + endofhist =3D m_top; + } + m_top->insertBetweeen(prev, next); + m_nextCycle->insertBetweeen(endofhist, aftertop); + m_top =3D m_nextCycle; + m_nextCycle =3D next; } - m_top->insertBetweeen(prev, next); - m_nextCycle->insertBetweeen(endofhist, aftertop); - m_top =3D m_nextCycle; - m_nextCycle =3D next; emit changed(); + emit topChanged(); } } = @@ -178,17 +189,28 @@ void History::cyclePrev() { return; } HistoryItem* prevprev =3D m_items[prev->previous_uuid()]; - HistoryItem* endofhist =3D m_items[m_top->previous_uuid()]; HistoryItem* aftertop =3D m_items[m_top->next_uuid()]; - if (prevprev =3D=3D m_top) { - prevprev =3D prev; - aftertop =3D m_top; + //if we have only two items in clipboard + if (m_nextCycle =3D=3D prevprev) { + m_top=3Daftertop; + } + else { + HistoryItem* endofhist =3D m_items[m_top->previous_uuid()]; + if (prevprev =3D=3D m_top) { + prevprev =3D prev; + aftertop =3D m_top; + } + else if (m_nextCycle =3D=3D m_top) { + m_nextCycle =3D aftertop; + endofhist =3D m_top; + } + m_top->insertBetweeen(prevprev,m_nextCycle); + prev->insertBetweeen(endofhist, aftertop); + m_nextCycle =3D m_top; + m_top =3D prev; } - m_top->insertBetweeen(prevprev,m_nextCycle); - prev->insertBetweeen(endofhist, aftertop); - m_nextCycle =3D m_top; - m_top =3D prev; emit changed(); + emit topChanged(); } } = diff --git a/klipper/klipper.cpp b/klipper/klipper.cpp index 006a7f0..a588462 100644 --- a/klipper/klipper.cpp +++ b/klipper/klipper.cpp @@ -1158,14 +1158,20 @@ void Klipper::slotAskClearHistory() = void Klipper::slotCycleNext() { - m_history->cycleNext(); - emit passivePopup(i18n("Clipboard history"), cycleText()); + //do cycle and show popup only if we have something in clipboard + if (m_history->first()) { + m_history->cycleNext(); + emit passivePopup(i18n("Clipboard history"), cycleText()); + } } = void Klipper::slotCyclePrev() { - m_history->cyclePrev(); - emit passivePopup(i18n("Clipboard history"), cycleText()); + //do cycle and show popup only if we have something in clipboard + if (m_history->first()) { + m_history->cyclePrev(); + emit passivePopup(i18n("Clipboard history"), cycleText()); + } } = QString Klipper::cycleText() const