2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2012-03-12 17:38:54 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2012-03-12 17:38:54 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2012-03-12 17:38:54 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-03-12 17:38:54 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2012-03-12 17:38:54 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2012-03-12 17:38:54 +01:00
|
|
|
|
|
|
|
|
#include "circularclipboardassist.h"
|
2014-09-04 00:04:18 +02:00
|
|
|
#include "codeassist/assistinterface.h"
|
2012-03-12 17:38:54 +01:00
|
|
|
#include "codeassist/iassistprocessor.h"
|
|
|
|
|
#include "codeassist/iassistproposal.h"
|
2014-09-04 00:04:18 +02:00
|
|
|
#include "codeassist/assistproposalitem.h"
|
|
|
|
|
#include "codeassist/genericproposalmodel.h"
|
2012-03-12 17:38:54 +01:00
|
|
|
#include "codeassist/genericproposal.h"
|
2014-09-26 09:14:03 +02:00
|
|
|
#include "texteditor.h"
|
2012-03-12 17:38:54 +01:00
|
|
|
#include "circularclipboard.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/coreconstants.h>
|
2015-11-23 16:41:54 +01:00
|
|
|
#include <coreplugin/coreicons.h>
|
2014-02-17 19:23:20 +02:00
|
|
|
|
2012-03-12 17:38:54 +01:00
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QClipboard>
|
|
|
|
|
|
|
|
|
|
namespace TextEditor {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2014-09-04 00:04:18 +02:00
|
|
|
class ClipboardProposalItem: public AssistProposalItem
|
|
|
|
|
{
|
2012-03-12 17:38:54 +01:00
|
|
|
public:
|
|
|
|
|
enum { maxLen = 80 };
|
|
|
|
|
|
2014-09-04 00:04:18 +02:00
|
|
|
ClipboardProposalItem(QSharedPointer<const QMimeData> mimeData)
|
|
|
|
|
: m_mimeData(mimeData)
|
2012-03-12 17:38:54 +01:00
|
|
|
{
|
|
|
|
|
QString text = mimeData->text().simplified();
|
|
|
|
|
if (text.length() > maxLen) {
|
|
|
|
|
text.truncate(maxLen);
|
|
|
|
|
text.append(QLatin1String("..."));
|
|
|
|
|
}
|
|
|
|
|
setText(text);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-02 10:58:20 +01:00
|
|
|
~ClipboardProposalItem() Q_DECL_NOEXCEPT {}
|
|
|
|
|
|
2016-01-19 14:54:59 +01:00
|
|
|
void apply(TextDocumentManipulatorInterface &manipulator, int /*basePosition*/) const override
|
2012-03-12 17:38:54 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
//Move to last in circular clipboard
|
|
|
|
|
if (CircularClipboard * clipboard = CircularClipboard::instance()) {
|
|
|
|
|
clipboard->collect(m_mimeData);
|
|
|
|
|
clipboard->toLastCollect();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Copy the selected item
|
2014-01-14 09:50:12 +01:00
|
|
|
QApplication::clipboard()->setMimeData(
|
2014-09-26 11:37:54 +02:00
|
|
|
TextEditorWidget::duplicateMimeData(m_mimeData.data()));
|
2012-03-12 17:38:54 +01:00
|
|
|
|
|
|
|
|
//Paste
|
2016-01-19 14:54:59 +01:00
|
|
|
manipulator.paste();
|
2012-03-12 17:38:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QSharedPointer<const QMimeData> m_mimeData;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ClipboardAssistProcessor: public IAssistProcessor
|
|
|
|
|
{
|
|
|
|
|
public:
|
2015-06-03 15:31:41 +02:00
|
|
|
IAssistProposal *perform(const AssistInterface *interface) override
|
2012-03-12 17:38:54 +01:00
|
|
|
{
|
|
|
|
|
if (!interface)
|
|
|
|
|
return 0;
|
2015-10-05 14:30:24 +02:00
|
|
|
const QScopedPointer<const AssistInterface> AssistInterface(interface);
|
2012-03-12 17:38:54 +01:00
|
|
|
|
2015-11-23 16:41:54 +01:00
|
|
|
QIcon icon = QIcon::fromTheme(QLatin1String("edit-paste"), Core::Icons::PASTE.icon()).pixmap(16);
|
2012-03-12 17:38:54 +01:00
|
|
|
CircularClipboard * clipboard = CircularClipboard::instance();
|
2016-02-01 14:51:01 +01:00
|
|
|
QList<AssistProposalItemInterface *> items;
|
2012-03-12 17:38:54 +01:00
|
|
|
for (int i = 0; i < clipboard->size(); ++i) {
|
|
|
|
|
QSharedPointer<const QMimeData> data = clipboard->next();
|
|
|
|
|
|
2014-09-04 00:04:18 +02:00
|
|
|
AssistProposalItem *item = new ClipboardProposalItem(data);
|
2012-03-12 17:38:54 +01:00
|
|
|
item->setIcon(icon);
|
|
|
|
|
item->setOrder(clipboard->size() - 1 - i);
|
|
|
|
|
items.append(item);
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-13 02:22:24 +02:00
|
|
|
return new GenericProposal(interface->position(), items);
|
2012-03-12 17:38:54 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2015-04-30 11:58:20 +02:00
|
|
|
IAssistProvider::RunType ClipboardAssistProvider::runType() const
|
2013-09-17 13:25:39 +02:00
|
|
|
{
|
2015-04-30 11:58:20 +02:00
|
|
|
return Synchronous;
|
2013-09-17 13:25:39 +02:00
|
|
|
}
|
|
|
|
|
|
2014-07-01 11:08:26 +02:00
|
|
|
bool ClipboardAssistProvider::supportsEditor(Core::Id /*editorId*/) const
|
2012-03-12 17:38:54 +01:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IAssistProcessor *ClipboardAssistProvider::createProcessor() const
|
|
|
|
|
{
|
|
|
|
|
return new ClipboardAssistProcessor;
|
|
|
|
|
}
|
2014-09-04 00:04:18 +02:00
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace TextEditor
|