Git commit 6367aa17b1716a2074c0675e4fbabbec3bc50c77 by Christoph Cullmann. Committed on 04/11/2012 at 18:19. Pushed by cullmann into branch 'master'.
GUI: "Clipboard History" menu in edit/popup allows you to paste the latest xx things you copied/cutted, atm history size 10 M +3 -1 part/data/katepartui.rc M +1 -3 part/document/katedocument.cpp M +1 -1 part/document/katedocument.h M +28 -1 part/utils/kateglobal.cpp M +26 -0 part/utils/kateglobal.h M +16 -4 part/view/kateview.cpp M +3 -2 part/view/kateview.h M +44 -0 part/view/kateviewhelpers.cpp M +16 -0 part/view/kateviewhelpers.h M +1 -1 part/view/kateviewinternal.cpp http://commits.kde.org/kate/6367aa17b1716a2074c0675e4fbabbec3bc50c77 diff --git a/part/data/katepartui.rc b/part/data/katepartui.rc index f5cdcb1..7e55a52 100644 --- a/part/data/katepartui.rc +++ b/part/data/katepartui.rc @@ -1,5 +1,5 @@ <!DOCTYPE kpartgui SYSTEM "kpartgui.dtd"> -<kpartgui name="KatePartView" version="65"> +<kpartgui name="KatePartView" version="66"> <MenuBar> <Menu name="file" noMerge="1"><text>&File</text> <Action name="file_save" group="save_merge" /> @@ -16,6 +16,7 @@ <Action name="edit_cut" group="edit_paste_merge" /> <Action name="edit_copy" group="edit_paste_merge" /> <Action name="edit_paste" group="edit_paste_merge" /> + <Action name="edit_paste_menu" group="edit_paste_merge" /> <Separator group="edit_paste_merge" /> <Action name="edit_select_all" group="edit_select_merge" /> <Action name="edit_deselect" group="edit_select_merge" /> @@ -130,6 +131,7 @@ <Action name="edit_cut" group="popup_operations" /> <Action name="edit_copy" group="popup_operations" /> <Action name="edit_paste" group="popup_operations" /> + <Action name="edit_paste_menu" group="popup_operations" /> <Separator group="popup_operations" /> <Action name="edit_select_all" group="popup_operations" /> <Action name="edit_deselect" group="popup_operations" /> diff --git a/part/document/katedocument.cpp b/part/document/katedocument.cpp index f9462b5..21e0a77 100644 --- a/part/document/katedocument.cpp +++ b/part/document/katedocument.cpp @@ -2825,10 +2825,8 @@ void KateDocument::del( KateView *view, const KTextEditor::Cursor& c ) } } -void KateDocument::paste ( KateView* view, QClipboard::Mode mode ) +void KateDocument::paste ( KateView* view, const QString &s ) { - QString s = QApplication::clipboard()->text(mode); - if (s.isEmpty()) return; diff --git a/part/document/katedocument.h b/part/document/katedocument.h index b7a97aa..327049c 100644 --- a/part/document/katedocument.h +++ b/part/document/katedocument.h @@ -725,7 +725,7 @@ Q_SIGNALS: void del( KateView *view, const KTextEditor::Cursor& ); void transpose( const KTextEditor::Cursor& ); - void paste ( KateView* view, QClipboard::Mode = QClipboard::Clipboard ); + void paste ( KateView* view, const QString &s ); public: void indent ( KTextEditor::Range range, int change ); diff --git a/part/utils/kateglobal.cpp b/part/utils/kateglobal.cpp index 36133ee..c4df0e8 100644 --- a/part/utils/kateglobal.cpp +++ b/part/utils/kateglobal.cpp @@ -49,8 +49,8 @@ #include <kiconloader.h> #include <QtCore/QPointer> - #include <QtGui/QBoxLayout> +#include <QApplication> KateGlobal *KateGlobal::s_self = 0; @@ -542,4 +542,31 @@ void KateGlobal::updateColorPalette() m_rendererConfig->updateConfig(); } +void KateGlobal::copyToClipboard (const QString &text) +{ + /** + * empty => nop + */ + if (text.isEmpty()) + return; + + /** + * move to clipboard + */ + QApplication::clipboard()->setText (text, QClipboard::Clipboard); + + /** + * remember in history + * cut after 10 entries + */ + m_clipboardHistory.prepend (text); + if (m_clipboardHistory.size () > 10) + m_clipboardHistory.removeLast (); + + /** + * notify about change + */ + emit clipboardHistoryChanged (); +} + // kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/part/utils/kateglobal.h b/part/utils/kateglobal.h index 0464de6..491e8f8 100644 --- a/part/utils/kateglobal.h +++ b/part/utils/kateglobal.h @@ -410,6 +410,27 @@ class KATEPART_TESTS_EXPORT KateGlobal : public KTextEditor::Editor, public KTex KTextEditor::TemplateScript* registerTemplateScript (QObject* owner, const QString& script); void unregisterTemplateScript(KTextEditor::TemplateScript* templateScript); + /** + * Copy text to clipboard an remember it in the history + * @param text text to copy to clipboard, does nothing if empty! + */ + void copyToClipboard (const QString &text); + + /** + * Clipboard history, filled with text we ever copied + * to clipboard via copyToClipboard. + */ + const QStringList &clipboardHistory () const + { + return m_clipboardHistory; + } + + Q_SIGNALS: + /** + * Emitted if the history of clipboard changes via copyToClipboard + */ + void clipboardHistoryChanged (); + private Q_SLOTS: void updateColorPalette(); @@ -535,6 +556,11 @@ class KATEPART_TESTS_EXPORT KateGlobal : public KTextEditor::Editor, public KTex * session config */ KSharedConfig::Ptr m_sessionConfig; + + /** + * clipboard history + */ + QStringList m_clipboardHistory; }; #endif diff --git a/part/view/kateview.cpp b/part/view/kateview.cpp index e9822d9..dafe153 100644 --- a/part/view/kateview.cpp +++ b/part/view/kateview.cpp @@ -346,7 +346,10 @@ void KateView::setupActions() m_copy = a = ac->addAction(KStandardAction::Copy, this, SLOT(copy())); a->setWhatsThis(i18n( "Use this command to copy the currently selected text to the system clipboard.")); - + + m_pasteMenu = ac->addAction("edit_paste_menu", new KatePasteMenu (i18n("Clipboard &History"), this)); + connect (KateGlobal::self(), SIGNAL(clipboardHistoryChanged()), this, SLOT(slotClipboardHistoryChanged())); + if (!m_doc->readOnly()) { a = ac->addAction(KStandardAction::Save, m_doc, SLOT(documentSave())); @@ -449,6 +452,7 @@ void KateView::setupActions() { m_cut->setEnabled (false); m_paste->setEnabled (false); + m_pasteMenu->setEnabled (false); m_editUndo = 0; m_editRedo = 0; } @@ -678,6 +682,7 @@ void KateView::setupActions() //widget and setting the shortcut context setupEditActions(); setupCodeFolding(); + slotClipboardHistoryChanged (); ac->addAssociatedWidget(m_viewInternal); @@ -1155,6 +1160,7 @@ void KateView::slotReadWriteChanged () m_cut->setEnabled (m_doc->isReadWrite() && (selection() || m_config->smartCopyCut())); m_paste->setEnabled (m_doc->isReadWrite()); + m_pasteMenu->setEnabled (m_doc->isReadWrite() && !KateGlobal::self()->clipboardHistory().isEmpty()); m_setEndOfLine->setEnabled (m_doc->isReadWrite()); QStringList l; @@ -1177,6 +1183,11 @@ void KateView::slotReadWriteChanged () m_searchBar->slotReadWriteChanged (); } +void KateView::slotClipboardHistoryChanged () +{ + m_pasteMenu->setEnabled (m_doc->isReadWrite() && !KateGlobal::self()->clipboardHistory().isEmpty()); +} + void KateView::slotUpdateUndo() { if (m_doc->readOnly()) @@ -2097,7 +2108,8 @@ void KateView::copy() const m_viewInternal->moveEdge(KateViewInternal::left, false); } - QApplication::clipboard()->setText(text); + // copy to clipboard and our history! + KateGlobal::self()->copyToClipboard (text); } void KateView::applyWordWrap () @@ -2272,9 +2284,9 @@ void KateView::sendCompletionAborted() emit completionAborted(this); } -void KateView::paste( ) +void KateView::paste(const QString *textToPaste) { - m_doc->paste( this ); + m_doc->paste( this, textToPaste ? *textToPaste : QApplication::clipboard()->text(QClipboard::Clipboard) ); emit selectionChanged (this); m_viewInternal->repaint(); } diff --git a/part/view/kateview.h b/part/view/kateview.h index 8ad8d4b..8d06906 100644 --- a/part/view/kateview.h +++ b/part/view/kateview.h @@ -114,8 +114,7 @@ class KATEPART_TESTS_EXPORT KateView : public KTextEditor::View, // KTextEditor::ClipboardInterface // public Q_SLOTS: - // TODO: Factor out of m_viewInternal - void paste(); + void paste(const QString *textToPaste = 0); void cut(); void copy() const; @@ -564,6 +563,7 @@ class KATEPART_TESTS_EXPORT KateView : public KTextEditor::View, void switchToCmdLine (); void switchToConsole (); void slotReadWriteChanged (); + void slotClipboardHistoryChanged (); Q_SIGNALS: void dropEventPass(QDropEvent*); @@ -594,6 +594,7 @@ class KATEPART_TESTS_EXPORT KateView : public KTextEditor::View, QList<QAction*> m_editActions; KAction* m_editUndo; KAction* m_editRedo; + KAction* m_pasteMenu; KRecentFilesAction* m_fileRecent; KToggleAction* m_toggleFoldingMarkers; KToggleAction* m_toggleIconBar; diff --git a/part/view/kateviewhelpers.cpp b/part/view/kateviewhelpers.cpp index a83f41b..626b611 100644 --- a/part/view/kateviewhelpers.cpp +++ b/part/view/kateviewhelpers.cpp @@ -2565,6 +2565,50 @@ void KateViewBar::hideEvent(QHideEvent* event) //END KateViewBar related classes +KatePasteMenu::KatePasteMenu (const QString& text, KateView *view) + : KActionMenu(text, view) + , m_view (view) +{ + connect(menu(),SIGNAL(aboutToShow()),this,SLOT(slotAboutToShow())); +} + +void KatePasteMenu::slotAboutToShow() +{ + menu()->clear (); + + /** + * insert complete paste history + */ + int i = 0; + Q_FOREACH (const QString &text, KateGlobal::self()->clipboardHistory()) { + /** + * get text for the menu ;) + */ + QString leftPart = text.left(48).replace ("\n", " "); + QAction *a=menu()->addAction ( leftPart + "...", this, SLOT(paste())); + a->setData(i++); + } +} + +void KatePasteMenu::paste () +{ + if (!sender()) + return; + + QAction *action = qobject_cast<QAction*>(sender()); + if (!action) + return; + + // get index + int i = action->data().toInt(); + if (i >= KateGlobal::self()->clipboardHistory().size()) + return; + + // paste + m_view->paste (&KateGlobal::self()->clipboardHistory()[i]); +} + + #include "kateviewhelpers.moc" // kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/part/view/kateviewhelpers.h b/part/view/kateviewhelpers.h index 670b3ba..88ec2e5 100644 --- a/part/view/kateviewhelpers.h +++ b/part/view/kateviewhelpers.h @@ -24,6 +24,7 @@ #include <kselectaction.h> #include <kencodingprober.h> #include <klineedit.h> +#include <KActionMenu> #include <QtGui/QPixmap> #include <QtGui/QColor> @@ -480,6 +481,21 @@ class KateCmdLineEdit : public KLineEdit QTimer *m_hideTimer; }; +class KatePasteMenu : public KActionMenu +{ + Q_OBJECT + + public: + KatePasteMenu (const QString& text, KateView *view); + + private: + KateView *m_view; + + private Q_SLOTS: + void slotAboutToShow(); + void paste (); +}; + #endif // kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/part/view/kateviewinternal.cpp b/part/view/kateviewinternal.cpp index 5551e06..d1f1a09 100644 --- a/part/view/kateviewinternal.cpp +++ b/part/view/kateviewinternal.cpp @@ -2825,7 +2825,7 @@ void KateViewInternal::mouseReleaseEvent( QMouseEvent* e ) if( doc()->isReadWrite() ) { - doc()->paste( m_view, QClipboard::Selection ); + doc()->paste( m_view, QApplication::clipboard()->text(QClipboard::Selection) ); repaint(); }