Commit 6e2fba79 authored by Victor Yacovlev's avatar Victor Yacovlev

Implemented copy console output to clipboard

parent cf2ba678
This diff is collapsed.
......@@ -120,13 +120,24 @@ QString Plugin::initialize(const QStringList & parameters, const ExtensionSystem
QToolButton * btnSaveTerm = new QToolButton(mainWindow_);
btnSaveTerm->setPopupMode(QToolButton::InstantPopup);
QMenu * menuSaveTerm = new QMenu(btnSaveTerm);
btnSaveTerm->setToolTip("Save console output");
btnSaveTerm->setToolTip(tr("Save console output"));
btnSaveTerm->setMenu(menuSaveTerm);
btnSaveTerm->setIcon(terminal_->actionSaveLast()->icon());
btnSaveTerm->setIcon(QIcon(qtcreatorIconsPath + "filesave.png"));
menuSaveTerm->addAction(terminal_->actionSaveLast());
menuSaveTerm->addAction(terminal_->actionSaveAll());
// mainWindow_->statusBar()->insertWidget(0, btnSaveTerm);
mainWindow_->statusBar_->addButtonToLeft(btnSaveTerm);
QToolButton * btnCopyTerm = new QToolButton(mainWindow_);
btnCopyTerm->setPopupMode(QToolButton::InstantPopup);
QMenu * menuCopyTerm = new QMenu(btnCopyTerm);
btnCopyTerm->setToolTip(tr("Copy to clipboard console output"));
btnCopyTerm->setMenu(menuCopyTerm);
btnCopyTerm->setIcon(QIcon(qtcreatorIconsPath + "editcopy.png"));
menuCopyTerm->addAction(terminal_->actionCopyLast());
menuCopyTerm->addAction(terminal_->actionCopyAll());
mainWindow_->statusBar_->addButtonToLeft(btnCopyTerm);
QToolButton * btnClearTerm = new QToolButton(mainWindow_);
terminal_->actionClear()->setIcon(cleanConsoleIcon);
btnClearTerm->setDefaultAction(terminal_->actionClear());
......
......@@ -52,9 +52,17 @@ Term::Term(QWidget *parent) :
.toString() + "/icons/from_oxygen/";
a_saveLast = new QAction(tr("Save last output"), this);
a_saveLast->setIcon(QIcon(oxygenIconsPath+"document-save.png"));
// a_saveLast->setIcon(QIcon(oxygenIconsPath+"document-save.png"));
a_saveLast->setEnabled(false);
connect(a_saveLast, SIGNAL(triggered()), this, SLOT(saveLast()));
a_copyLast = new QAction(tr("Copy last output"), this);
a_copyLast->setEnabled(false);
connect(a_copyLast, SIGNAL(triggered()), this, SLOT(copyLast()));
a_copyAll = new QAction(tr("Copy all output"), this);
a_copyAll->setEnabled(false);
connect(a_copyAll, SIGNAL(triggered()), this, SLOT(copyAll()));
// tb->addAction(a_saveLast);
a_editLast = new QAction(tr("Open last output in editor"), this);
......@@ -66,7 +74,7 @@ Term::Term(QWidget *parent) :
// tb->addSeparator();
a_saveAll = new QAction(tr("Save all output"), this);
a_saveAll->setIcon(QIcon(oxygenIconsPath+"document-save-all.png"));
// a_saveAll->setIcon(QIcon(oxygenIconsPath+"document-save-all.png"));
a_saveAll->setEnabled(false);
connect(a_saveAll, SIGNAL(triggered()), this, SLOT(saveAll()));
// tb->addAction(a_saveAll);
......@@ -186,12 +194,16 @@ void Term::changeGlobalState(ExtensionSystem::GlobalState , ExtensionSystem::Glo
if (current==ExtensionSystem::GS_Unlocked || current==ExtensionSystem::GS_Observe) {
a_saveAll->setEnabled(sessions_.size()>0);
a_saveLast->setEnabled(sessions_.size()>0);
a_copyAll->setEnabled(sessions_.size()>0);
a_copyLast->setEnabled(sessions_.size()>0);
a_editLast->setEnabled(sessions_.size()>0);
a_clear->setEnabled(sessions_.size()>0);
}
else {
a_saveAll->setEnabled(false);
a_saveLast->setEnabled(false);
a_copyAll->setEnabled(false);
a_copyLast->setEnabled(false);
a_editLast->setEnabled(false);
a_clear->setEnabled(false);
}
......@@ -390,6 +402,22 @@ void Term::saveLast()
saveText(suggestedFileName, sessions_.last()->plainText(false));
}
void Term::copyAll()
{
QString allText;
for (int i=0; i<sessions_.size(); i++) {
allText += sessions_[i]->plainText(true);
}
QClipboard * clipboard = QApplication::clipboard();
clipboard->setText(allText);
}
void Term::copyLast()
{
QClipboard * clipboard = QApplication::clipboard();
clipboard->setText(sessions_.last()->plainText(false));
}
void Term::saveText(const QString &suggestedFileName, const QString &text)
{
QString fileName = QFileDialog::getSaveFileName(
......
......@@ -33,10 +33,14 @@ public slots:
void input(const QString & format);
void saveLast();
void saveAll();
void copyLast();
void copyAll();
void editLast();
void changeGlobalState(ExtensionSystem::GlobalState old, ExtensionSystem::GlobalState current);
inline QAction * actionSaveAll() const { return a_saveAll; }
inline QAction * actionSaveLast() const { return a_saveLast; }
inline QAction * actionCopyAll() const { return a_copyAll; }
inline QAction * actionCopyLast() const { return a_copyLast; }
inline QAction * actionEditLast() const { return a_editLast; }
inline QAction * actionClear() const { return a_clear; }
......@@ -61,6 +65,8 @@ private:
class Plane * m_plane;
QAction * a_saveAll;
QAction * a_saveLast;
QAction * a_copyAll;
QAction * a_copyLast;
QAction * a_editLast;
QAction * a_clear;
// QToolBar * m_toolBar;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment