Index: addons/konsole/kateconsole.h =================================================================== --- addons/konsole/kateconsole.h +++ addons/konsole/kateconsole.h @@ -137,10 +137,16 @@ * synchronize the konsole with the current document (cd to the directory) */ void slotSync(KTextEditor::View *view = 0); + /** * When syncing is done by the user, also show the terminal if it is hidden */ void slotManualSync(); + + /** + * run the current document in the konsole + */ + void slotRun(); private Q_SLOTS: /** @@ -208,6 +214,8 @@ {} private: class QCheckBox *cbAutoSyncronize; + class QCheckBox *cbRemoveExtension; + class QLineEdit *lePrefix; class QCheckBox *cbSetEditor; KateKonsolePlugin *mPlugin; }; Index: addons/konsole/kateconsole.cpp =================================================================== --- addons/konsole/kateconsole.cpp +++ addons/konsole/kateconsole.cpp @@ -39,6 +39,8 @@ #include #include #include +#include +#include #include #include @@ -136,6 +138,10 @@ a = actionCollection()->addAction(QStringLiteral("katekonsole_tools_sync")); a->setText(i18nc("@action", "S&ynchronize Terminal with Current Document")); connect(a, SIGNAL(triggered()), this, SLOT(slotManualSync())); + + a = actionCollection()->addAction(QStringLiteral("katekonsole_tools_run")); + a->setText(i18nc("@action", "Run Current Document")); + connect(a, SIGNAL(triggered()), this, SLOT(slotRun())); a = actionCollection()->addAction(QStringLiteral("katekonsole_tools_toggle_focus")); a->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal"))); @@ -293,6 +299,36 @@ if ( ! m_part || ! m_part->widget()->isVisible() ) m_mw->showToolView( parentWidget() ); } + +void KateConsole::slotRun() +{ + if ( m_mw->activeView() ) { + QUrl u = m_mw->activeView()->document()->url(); + if ( u.isValid() && u.isLocalFile() ) { + // ensure that file is saved + if ( m_mw->activeView()->document()->isModified() ) { + m_mw->activeView()->document()->save(); + } + // echo to terminal + // prefix first + sendInput( KConfigGroup(KSharedConfig::openConfig(), "Konsole").readEntry("RunPrefix", "") ); + // then filename + if ( KConfigGroup(KSharedConfig::openConfig(), "Konsole").readEntry("RemoveExtension", true) ) { + // send filename without extension (i.e. keep only the basename) + sendInput( QFileInfo( m_mw->activeView()->document()->url().path() ).baseName() + + QLatin1Char('\n') ); + } else { + // send filename to the terminal + sendInput( QFileInfo( m_mw->activeView()->document()->url().path() ).fileName() + + QLatin1Char('\n') ); + } + } else if ( !m_mw->activeView()->document()->url().isEmpty() ) { + sendInput( QStringLiteral("### ") + + i18n("Sorry, can not run '%1'", m_mw->activeView()->document()->url().path() ) + QLatin1Char('\n') ); + } + } +} + void KateConsole::slotToggleFocus() { QAction *action = actionCollection()->action(QStringLiteral("katekonsole_tools_toggle_focus")); @@ -340,6 +376,21 @@ cbAutoSyncronize = new QCheckBox( i18n("&Automatically synchronize the terminal with the current document when possible"), this ); lo->addWidget( cbAutoSyncronize ); + + QVBoxLayout *vbox = new QVBoxLayout; + QGroupBox *group = new QGroupBox( i18n("Run in terminal"), this ); + cbRemoveExtension = new QCheckBox( i18n("&Remove extension"), this ); + vbox->addWidget( cbRemoveExtension ); + QFrame *frame = new QFrame( this ); + QHBoxLayout *hbox = new QHBoxLayout( frame ); + QLabel *label = new QLabel( i18n("Prefix:"), frame ); + hbox->addWidget( label ); + lePrefix = new QLineEdit( frame ); + hbox->addWidget( lePrefix ); + vbox->addWidget( frame ); + group->setLayout( vbox ); + lo->addWidget( group ); + cbSetEditor = new QCheckBox( i18n("Set &EDITOR environment variable to 'kate -b'"), this ); lo->addWidget( cbSetEditor ); QLabel *tmp = new QLabel(this); @@ -348,6 +399,8 @@ reset(); lo->addStretch(); connect( cbAutoSyncronize, SIGNAL(stateChanged(int)), SIGNAL(changed()) ); + connect( cbRemoveExtension, SIGNAL(stateChanged(int)), SIGNAL(changed()) ); + connect( lePrefix, SIGNAL(stateChanged(int)), SIGNAL(changed()) ); connect( cbSetEditor, SIGNAL(stateChanged(int)), SIGNAL(changed()) ); } @@ -370,6 +423,8 @@ { KConfigGroup config(KSharedConfig::openConfig(), "Konsole"); config.writeEntry("AutoSyncronize", cbAutoSyncronize->isChecked()); + config.writeEntry("RemoveExtension", cbRemoveExtension->isChecked()); + config.writeEntry("RunPrefix", lePrefix->text()); config.writeEntry("SetEditor", cbSetEditor->isChecked()); config.sync(); mPlugin->readConfig(); @@ -379,6 +434,8 @@ { KConfigGroup config(KSharedConfig::openConfig(), "Konsole"); cbAutoSyncronize->setChecked(config.readEntry("AutoSyncronize", false)); + cbRemoveExtension->setChecked(config.readEntry("RemoveExtension", false)); + lePrefix->setText(config.readEntry("RunPrefix", "")); cbSetEditor->setChecked(config.readEntry("SetEditor", false)); } Index: addons/konsole/ui.rc =================================================================== --- addons/konsole/ui.rc +++ addons/konsole/ui.rc @@ -6,6 +6,7 @@ &Tools +