diff options
Diffstat (limited to 'kate/insertcommand')
-rw-r--r-- | kate/insertcommand/Makefile.am | 21 | ||||
-rw-r--r-- | kate/insertcommand/kateinsertcommand.desktop | 119 | ||||
-rw-r--r-- | kate/insertcommand/plugin_kateinsertcommand.cpp | 417 | ||||
-rw-r--r-- | kate/insertcommand/plugin_kateinsertcommand.h | 170 | ||||
-rw-r--r-- | kate/insertcommand/ui.rc | 8 |
5 files changed, 735 insertions, 0 deletions
diff --git a/kate/insertcommand/Makefile.am b/kate/insertcommand/Makefile.am new file mode 100644 index 0000000..22fd871 --- /dev/null +++ b/kate/insertcommand/Makefile.am @@ -0,0 +1,21 @@ +INCLUDES = $(all_includes) +METASOURCES = AUTO + +# Install this plugin in the KDE modules directory +kde_module_LTLIBRARIES = kateinsertcommandplugin.la + +# This is all standard. Remove the LIB_KHTML reference if you are not +# using the KHTML Part +kateinsertcommandplugin_la_SOURCES = plugin_kateinsertcommand.cpp +kateinsertcommandplugin_la_LIBADD = -lkateinterfaces +kateinsertcommandplugin_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries) + +# Install the .rc file in the Part's directory (in this case, the part +# is KHTMLPart) +pluginsdir = $(kde_datadir)/kate/plugins/kateinsertcommand +plugins_DATA = ui.rc + +kde_services_DATA = kateinsertcommand.desktop + +messages: rc.cpp + $(XGETTEXT) *.cpp *.h -o $(podir)/kateinsertcommand.pot diff --git a/kate/insertcommand/kateinsertcommand.desktop b/kate/insertcommand/kateinsertcommand.desktop new file mode 100644 index 0000000..cfd0197 --- /dev/null +++ b/kate/insertcommand/kateinsertcommand.desktop @@ -0,0 +1,119 @@ +[Desktop Entry] +Type=Service +ServiceTypes=Kate/Plugin +X-KDE-Library=kateinsertcommandplugin +X-Kate-Version=2.5 +Name=Kate InsertCommand +Name[af]=Kate Invoeg-opdrag +Name[ca]=Inserció de comandaments per a Kate +Name[cy]=MewnosodGorchymyn Kate +Name[da]=Kate Indsætningskommando +Name[de]=Befehlsausgabe einfügen für Kate +Name[el]=Εισαγωγή εντολών του Kate +Name[eo]=Komandenmeto de Kodredaktilo +Name[es]=Insertar orden en Kate +Name[et]=Kate käsu-lisaja +Name[eu]=Kateren InsertCommand +Name[fi]=Kate lisäyskomento +Name[fo]=Kate innsetingarstýriboð +Name[fr]=Insertion de commande dans Kate +Name[gl]=Inserción de Comandos para Kate +Name[he]=הוספת פקודות ל־Kate +Name[hi]=के-एटीई इंसर्ट-कमांड +Name[hr]=Kate UmetniNaredbu +Name[hu]=Kate parancsbeszúró +Name[it]=InserisciComando di Kate +Name[ja]=Kate コマンド挿入 +Name[ka]=Kate ბრძანების ჩამატება +Name[kk]=Kate-те команда шығарлымын енгізу +Name[km]=ពាក្យបញ្ជាបញ្ចូលរបស់ Kate +Name[lt]=Kate įdėti komandą +Name[lv]=Kate IespraustKomandu +Name[mk]=ВметниКоманда за Кате +Name[ms]=Kate MasukkanArahan +Name[nds]=Kate-Befehlinfögen +Name[ne]=केट घुसाउने आदेश +Name[pa]=ਕੇਟ ਕਮਾਂਡ ਸ਼ਾਮਲ +Name[pl]=Polecenie wstawiania do Kate +Name[pt]=Inserção de Comandos do Kate +Name[pt_BR]=Inserir Comando do Kate +Name[ro]=Inserare comandă Kate +Name[ru]=Вставка вывода команды в Kate +Name[sr]=„Убацивање наредбе“ за Kate +Name[sr@Latn]=„Ubacivanje naredbe“ za Kate +Name[sv]=Kate - Infoga kommando +Name[ta]=கேட் சொருகு கட்டளை +Name[th]=คำสั่งแทรกของ Kate +Name[tr]=Kate KomutEkle +Name[uk]=Команда вставлення Kate +Name[ven]=Muthetho wo dzheniswaho wa Kate +Name[vi]=Chèn lệnh Kate +Name[xh]=IKate IfakaUmyalelo +Name[zh_CN]=Kate 插入命令 +Name[zh_TW]=Kate 插入命令 +Name[zu]=Faka Inkomba ka Kate +Comment=Insert shell command output into a document +Comment[af]=Voeg by tolk opdrag uitset binnein 'n dokument +Comment[ar]=أدخل مخرجات أمر من سطر الأوامر الى مستندك +Comment[az]=Qabıq əmrə yekununu sənədə daxil et +Comment[bg]=Вмъкване на резултата от изпълнението на дадена команда в документа +Comment[bs]=Dodaj izlaz shell komande u dokument +Comment[ca]=Insereix la sortida d'un comandament de l'intèrpret de comandaments en un document +Comment[cs]=Vloží výstup příkazu shellu do dokumentu +Comment[cy]=Mewnosod allbwn o orchymyn plisgyn i mewn i ddogfen +Comment[da]=Indsæt uddata fra skalkommando i et dokument +Comment[de]=Ausgabe eines Befehlszeilenprogramms einfügen +Comment[el]=Εισαγωγή εξόδου κάποιας εντολής σε ένα έγγραφο +Comment[eo]=Enmetas la eligon de ŝelprogramo en dokumenton +Comment[es]=Inserta la salida del intérprete de órdenes en un documento +Comment[et]=Shelli käsu väljundi lisamine dokumenti +Comment[eu]=Txertatu Shell komandoaren irteera dokumentu batean +Comment[fa]=درج خروجی فرمان پوستۀ درون یک سند +Comment[fi]=Lisää komentotulkin tuloste asiakirjaan +Comment[fo]=Innset úttak frá eitt stýriboð/forrit í eitt skjal. +Comment[fr]=Insertion de la sortie d'une commande shell dans un document +Comment[fy]=Set útfier fan shellkommando yn in dokumint +Comment[ga]=Ionsáigh aschur ó ordú blaoisce isteach i gcáipéis +Comment[gl]=Inserir o resultado da execución dun comando nun documento +Comment[he]=הוספת פלט של פקודות מעטפת לתוך מסמך +Comment[hi]=एक दस्तावेज़ में शेल कमांड आउटपुट प्रविष्ट करता है +Comment[hr]=Umetanje ispisa iz naredbene ljuske u dokument +Comment[hu]=Parancs kimenetének beillesztése +Comment[is]=Setja úttak skeljarskipunar inn í skjal +Comment[it]=Inserisce l'output di un comando della shell in un documento +Comment[ja]=文書にシェルコマンドの出力を挿入します +Comment[ka]=გარსის ბრძანების გამოტანის დოკუმენტში ჩამატება +Comment[kk]=Қоршау-орта командасының шығысын құжатқа енгізу +Comment[km]=បញ្ចូលលទ្ធផលពាក្យបញ្ជារបស់សែលទៅក្នុងឯកសារមួយ +Comment[lt]=Įdėti apvalkalo komandos išvestį į dokumentą +Comment[lv]=Iesprauž čaulas komandas izvadi dokumentā +Comment[mk]=Вметнува излез од команда од школката во документ +Comment[ms]=Memasukkan output arahan cengkerang kepada dokumen +Comment[mt]=Daħħal ir-riżultat ta' kmand tax-shell fid-dokument +Comment[nb]=Sett inn utfallet fra en skall-kommando i et dokument +Comment[nds]=Konsoolbefehl-Utgaav na en Dokment infögen +Comment[ne]=कागजातमा शेला आदेश निर्गत घुसाउनुहोस् +Comment[nl]=Voeg uitvoer van shellcommando in een document +Comment[nn]=Set inn resultatet av ein skalkommando i dokumentet +Comment[pa]=ਇੱਕ ਦਸਤਾਵੇਜ਼ ਵਿੱਚ ਇੱਕ ਸ਼ੈਲ ਕਮਾਂਡ ਆਉਟਪੁੱਟ ਦਿਓ +Comment[pl]=Wstaw wynik wykonania polecenia powłoki +Comment[pt]=Inserir o resultado da execução de um comando num documento +Comment[pt_BR]=Inserir comando de saída do shell dentro do documento +Comment[ro]=Inserează în document rezultatul comenzii de interpretor +Comment[ru]=Вставить вывод команды в документ +Comment[sk]=Vloží výstup príkazu shellu do dokumentu +Comment[sl]=Vstavi izhod lupinskega ukaza v dokument +Comment[sr]=Убаците излаз наредбе шкољке у документ +Comment[sr@Latn]=Ubacite izlaz naredbe školjke u dokument +Comment[sv]=Infoga utmatning från skalkommando till ett dokument +Comment[ta]=ஓட்டுக் கட்டளை வெளியீட்டை ஆவணத்தில் செருக உதவும் +Comment[tg]=Барқарор кардани баромади фармони лифофа дар санад +Comment[th]=แทรกผลส่งออกของคำสั่งเชลล์ไปยังเอกสาร +Comment[tr]=Kabuk komut çıktısını bir belgeye ekle +Comment[uk]=Вставити вивід команди оболонки в документ +Comment[ven]=Dzhenisani muthetho wa shele wa nnda u tshi ya kha dokhwumennte +Comment[vi]=Chèn kết xuất lệnh trình bao vào tài liệu +Comment[xh]=Faka iqokobhe lomyalelo wemveliso phakathi kuxwebhu +Comment[zh_CN]=将 Shell 命令的输出插入到文档中 +Comment[zh_TW]=在文件內嵌入 shell 命令輸出 +Comment[zu]=Faka igobodo lenkomba kwisiqephu diff --git a/kate/insertcommand/plugin_kateinsertcommand.cpp b/kate/insertcommand/plugin_kateinsertcommand.cpp new file mode 100644 index 0000000..eadbc02 --- /dev/null +++ b/kate/insertcommand/plugin_kateinsertcommand.cpp @@ -0,0 +1,417 @@ + /*************************************************************************** + plugin_kateinsertcommand.cpp - description + ------------------- + begin : THU Apr 19 2001 + copyright : (C) 2001 by Anders Lund + email : anders@alweb.dk + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +//BEGIN includes +#include "plugin_kateinsertcommand.h" +#include "plugin_kateinsertcommand.moc" + +#include <qbuttongroup.h> +#include <qcheckbox.h> +#include <qdir.h> +#include <qfile.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qradiobutton.h> +#include <qspinbox.h> +#include <qstringlist.h> +#include <qwhatsthis.h> +#include <qwidget.h> + +#include <kaction.h> +#include <kanimwidget.h> +#include <kconfig.h> +#include <kdebug.h> +#include <kfiledialog.h> +#include <kiconloader.h> +#include <klocale.h> +#include <kmessagebox.h> +#include <kprocess.h> +#include <kstandarddirs.h> +#include <kgenericfactory.h> +#include <kapplication.h> +//END includes + +K_EXPORT_COMPONENT_FACTORY( kateinsertcommandplugin, KGenericFactory<PluginKateInsertCommand>( "kateinsertcommand" ) ) + +//BEGIN obligatory stuff +class PluginView : public KXMLGUIClient +{ + friend class PluginKateInsertCommand; + + public: + Kate::MainWindow *win; +}; +//END + +//BEGIN PluginKateInsertCommand +PluginKateInsertCommand::PluginKateInsertCommand( QObject* parent, const char* name, const QStringList& ) + : Kate::Plugin ( (Kate::Application *)parent, name ), + kv ( 0 ), + sh ( 0 ) +{ + config = new KConfig("kateinsertcommandpluginrc"); + cmdhist = config->readListEntry("Command History"); + wdlg = 0; + workingdir = QDir::currentDirPath(); +} + +PluginKateInsertCommand::~PluginKateInsertCommand() +{ + // write config file + config->writeEntry("Command History", cmdhist); + config->writeEntry("Dialog Settings", dialogSettings); + config->sync(); + delete config; + delete sh; +} + +void PluginKateInsertCommand::addView(Kate::MainWindow *win) +{ + // TODO: doesn't this have to be deleted? + PluginView *view = new PluginView (); + + (void) new KAction ( i18n("Insert Command..."), "", 0, this, + SLOT( slotInsertCommand() ), view->actionCollection(), + "edit_insert_command" ); + + view->setInstance (new KInstance("kate")); + view->setXMLFile("plugins/kateinsertcommand/ui.rc"); + win->guiFactory()->addClient (view); + view->win = win; + + m_views.append (view); +} + +void PluginKateInsertCommand::removeView(Kate::MainWindow *win) +{ + for (uint z=0; z < m_views.count(); z++) + if (m_views.at(z)->win == win) + { + PluginView *view = m_views.at(z); + m_views.remove (view); + win->guiFactory()->removeClient (view); + delete view; + } +} + +void PluginKateInsertCommand::slotInsertCommand() +{ + if (!kapp->authorize("shell_access")) { + KMessageBox::sorry(0,i18n("You are not allowed to execute arbitrary external applications. If you want to be able to do this, contact your system administrator."),i18n("Access Restrictions")); + return; + } + if ( sh && sh->isRunning() ) { + KMessageBox::sorry (0, i18n("A process is currently being executed."), + i18n("Error")); + return; + } + + if (!application()->activeMainWindow() || !application()->activeMainWindow()->viewManager()->activeView()) + return; + + kv = application()->activeMainWindow()->viewManager()->activeView(); + + QString dir = workingdir; + QString docdir; + KURL docurl = kv->getDoc()->url(); + if (docurl.isLocalFile()) + docdir = docurl.directory(); + QString lwd( config->readPathEntry("Last WD") ); + switch ( (int)config->readNumEntry("Start In", 0) ) + { + case 1: + if ( ! docdir.isEmpty() ) dir = docdir; + break; + case 2: + if ( ! lwd.isEmpty() ) dir = lwd; + break; + default: + break; + } + dialogSettings = config->readNumEntry("Dialog Settings", 0); + CmdPrompt *d = new CmdPrompt((QWidget*)kv, 0, cmdhist, dir, + docdir, dialogSettings); + if ( d->exec() && ! d->command().isEmpty() ) { + if ( ! sh ) { + sh = new KShellProcess; + + connect ( sh, SIGNAL(receivedStdout(KProcess*, char*, int)), + this, SLOT(slotReceivedStdout(KProcess*, char*, int)) ); + connect ( sh, SIGNAL(receivedStderr(KProcess*, char*, int)), + this, SLOT(slotReceivedStderr(KProcess*, char*, int)) ); + connect ( sh, SIGNAL(processExited(KProcess*)), + this, SLOT(slotProcessExited(KProcess*)) ) ; + } + + sh->clearArguments(); + + bInsStdErr = d->insertStdErr(); + + if ( d->printCmd() ) { + if ( ! d->wd().isEmpty() ) + kv->insertText( d->wd() + ": "); + kv->insertText( d->command()+":\n" ); + } + if ( ! d->wd().isEmpty() ) { + *sh << "cd" << d->wd() << "&&"; + config->writePathEntry("Last WD", d->wd()); + } + *sh << QFile::encodeName(d->command()); + sh->start( KProcess::NotifyOnExit, KProcess::All ); + + // add command to history + if ( cmdhist.contains( d->command() ) ) { + cmdhist.remove( d->command() ); + } + cmdhist.prepend( d->command() ); + int cmdhistlen = config->readNumEntry("Command History Length", 20); + while ( (int)cmdhist.count() > cmdhistlen ) + cmdhist.remove( cmdhist.last() ); + // save dialog state + dialogSettings = 0; + if ( d->insertStdErr() ) + dialogSettings += 1; + if ( d->printCmd() ) + dialogSettings += 2; + + cmd = d->command(); + delete d; + // If process is still running, display a dialog to cancel... + slotShowWaitDlg(); + + config->writeEntry("Dialog Settings", dialogSettings); + config->sync(); + } +} + +void PluginKateInsertCommand::slotAbort() +{ + if ( sh->isRunning() ) + if (! sh->kill() ) + KMessageBox::sorry(0, i18n("Could not kill command."), i18n("Kill Failed")); +} + +void PluginKateInsertCommand::slotShowWaitDlg() +{ + if ( sh->isRunning() ) { + wdlg = new WaitDlg( (QWidget*)kv, i18n( + "Executing command:\n%1\n\nPress 'Cancel' to abort.").arg(cmd) ); + connect(wdlg, SIGNAL(cancelClicked()), this, SLOT(slotAbort()) ); + } + if ( sh->isRunning() ) // we may have finished while creating the dialog. + wdlg->show(); + else if (wdlg) { // process may have exited before the WaitDlg constructor returned. + delete wdlg; + wdlg = 0; + } +} + +void PluginKateInsertCommand::slotReceivedStdout( KProcess* /*p*/, char* text, + int len ) +{ + QString t = QString::fromLocal8Bit ( text ); + t.truncate(len); + kv->insertText( t ); +} + +void PluginKateInsertCommand::slotReceivedStderr( KProcess* p, char* text, + int len ) +{ + if ( bInsStdErr ) + slotReceivedStdout( p, text, len ); +} + +void PluginKateInsertCommand::slotProcessExited( KProcess* p ) +{ + if (wdlg) { + wdlg->hide(); + delete wdlg; + wdlg = 0; + } + if ( ! p->normalExit() ) + KMessageBox::sorry(0, i18n("Command exited with status %1"). + arg( p->exitStatus()), i18n("Oops!")); + kv->setFocus(); +} +//END PluginKateInsertCommand + +//BEGIN PluginConfigPage +Kate::PluginConfigPage* PluginKateInsertCommand::configPage (uint, + QWidget *w, const char */*name*/) +{ + InsertCommandConfigPage* p = new InsertCommandConfigPage(this, w); + initConfigPage( p ); + connect( p, SIGNAL(configPageApplyRequest(InsertCommandConfigPage*)), + this, SLOT(applyConfig(InsertCommandConfigPage*)) ); + return (Kate::PluginConfigPage*)p; +} + +void PluginKateInsertCommand::initConfigPage( InsertCommandConfigPage *p ) +{ + p->sb_cmdhistlen->setValue( config->readNumEntry("Command History Length", 20) ); + p->rg_startin->setButton( config->readNumEntry("Start In", 0) ); +} + +void PluginKateInsertCommand::applyConfig( InsertCommandConfigPage *p ) +{ + config->writeEntry( "Command History Length", p->sb_cmdhistlen->value() ); + // truncate the cmd hist if nessecary? + config->writeEntry( "Start In", p->rg_startin->id(p->rg_startin->selected()) ); + config->sync(); +} +//END PluginConfigPage + +//BEGIN CmdPrompt +// This is a simple dialog to retrieve a command and decide if +// stdErr should be included in the text inserted. +CmdPrompt::CmdPrompt(QWidget* parent, + const char* name, + const QStringList& cmdhist, + const QString& dir, + const QString& /*docdir*/, + int settings) + : KDialogBase (parent, name, true, i18n("Insert Command"), Ok|Cancel, Ok, true) +{ + QWidget *page = new QWidget( this ); + setMainWidget(page); + + QVBoxLayout *lo = new QVBoxLayout( page, 0, spacingHint() ); + + QLabel *l = new QLabel( i18n("Enter &command:"), page ); + lo->addWidget( l ); + cmb_cmd = new KHistoryCombo(true, page); + cmb_cmd->setHistoryItems(cmdhist, true); + cmb_cmd->setCurrentItem(0); + cmb_cmd->lineEdit()->setSelection(0, cmb_cmd->currentText().length()); + l->setBuddy(cmb_cmd); + cmb_cmd->setFocus(); + lo->addWidget(cmb_cmd); + connect( cmb_cmd->lineEdit(),SIGNAL(textChanged ( const QString & )), + this, SLOT( slotTextChanged(const QString &))); + + QLabel *lwd = new QLabel( i18n("Choose &working folder:"), page ); + lo->addWidget( lwd ); + wdreq = new KURLRequester( page ); + if ( ! dir.isEmpty() ) + wdreq->setURL( dir ); + wdreq->setMode( static_cast<KFile::Mode>(KFile::Directory|KFile::LocalOnly|KFile::ExistingOnly) ); + lwd->setBuddy( wdreq ); + lo->addWidget( wdreq ); + + //kdDebug()<<"settings: "<<settings<<endl; + cb_insStdErr = new QCheckBox( i18n("Insert Std&Err messages"), page ); + cb_insStdErr->setChecked(settings & 1); + lo->addWidget( cb_insStdErr ); + cb_printCmd = new QCheckBox( i18n("&Print command name"), page ); + cb_printCmd->setChecked(settings & 2); + lo->addWidget( cb_printCmd ); + + QWhatsThis::add( cmb_cmd, i18n( + "Enter the shell command, the output of which you want inserted into your " + "document. Feel free to use a pipe or two if you wish.") ); + QWhatsThis::add( wdreq, i18n( + "Sets the working folder of the command. The command executed is 'cd <dir> " + "&& <command>'") ); + QWhatsThis::add( cb_insStdErr, i18n( + "Check this if you want the error output from <command> inserted as well.\n" + "Some commands, such as locate, print everything to STDERR") ); + QWhatsThis::add( cb_printCmd, i18n( + "If you check this, the command string will be printed followed by a " + "newline before the output.") ); + slotTextChanged(cmb_cmd->lineEdit()->text()); +} + +CmdPrompt::~CmdPrompt() {} + +void CmdPrompt::slotTextChanged(const QString &text) +{ + enableButtonOK( !text.isEmpty()); +} +//END CmdPrompt + +//BEGIN WaitDlg implementation +// This is a dialog that is displayed while a command is running, +// with a cancel button to allow the user to kill the command +WaitDlg::WaitDlg(QWidget* parent, const QString& text, const QString& title) + : KDialogBase( parent, "wait dialog", true, title, Cancel, Cancel, true ) +{ + QWidget *page = new QWidget( this ); + setMainWidget( page ); + QHBoxLayout *lo = new QHBoxLayout( page, 0, spacingHint() ); + + KAnimWidget *aw = new KAnimWidget( QString::fromLatin1("kde"), 48, page ); + lo->addWidget(aw); + QLabel *l = new QLabel( text, page ); + lo->addWidget( l ); + + aw->start(); +} +WaitDlg::~WaitDlg() +{ +} +//END WaitDlg + +//BEGIN InsertCommandConfigPage +// This is the config page for this plugin. +InsertCommandConfigPage::InsertCommandConfigPage(QObject* /*parent*/, + QWidget *parentWidget) + : Kate::PluginConfigPage( parentWidget ) +{ + QVBoxLayout* lo = new QVBoxLayout( this ); + lo->setSpacing(KDialogBase::spacingHint()); + + // command history length + QHBox *hb1 = new QHBox( this ); + hb1->setSpacing(KDialogBase::spacingHint()); + (void) new QLabel( i18n("Remember"), hb1 ); + sb_cmdhistlen = new QSpinBox( hb1 ); + QLabel *l1 = new QLabel( sb_cmdhistlen, i18n("Co&mmands"), hb1); + hb1->setStretchFactor(l1, 1); + lo->addWidget( hb1 ); + + // dir history length + + // initial dir choice + rg_startin = new QButtonGroup( 1, Qt::Horizontal, i18n("Start In"), this ); + rg_startin->setRadioButtonExclusive( true ); + (void) new QRadioButton( i18n("Application &working folder"), rg_startin); + (void) new QRadioButton( i18n("&Document folder"), rg_startin); + (void) new QRadioButton( i18n("&Latest used working folder"), rg_startin); + lo->addWidget( rg_startin ); + // other? + + lo->addStretch(1); // look nice + + // Be helpfull! + QWhatsThis::add( sb_cmdhistlen, i18n( + "Sets the number of commands to remember. The command history is saved " + "over sessions.") ); + QWhatsThis::add( rg_startin, i18n( + "<qt><p>Decides what is suggested as <em>working folder</em> for the " + "command.</p><p><strong>Application Working Folder (default):</strong> " + "The folder from which you launched the application hosting the plugin, " + "usually your home folder.</p><p><strong>Document Folder:</strong> The " + "folder of the document. Used only for local documents.</p><p><strong>" + "Latest Working Folder:</strong> The folder used last time you used this " + "plugin.</p></qt>") ); +} + +void InsertCommandConfigPage::apply() +{ + emit configPageApplyRequest( this ); +} +//END InsertCommandConfigPage +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/insertcommand/plugin_kateinsertcommand.h b/kate/insertcommand/plugin_kateinsertcommand.h new file mode 100644 index 0000000..c948b38 --- /dev/null +++ b/kate/insertcommand/plugin_kateinsertcommand.h @@ -0,0 +1,170 @@ + /*************************************************************************** + plugin_kateinsertcommand.h - description + ------------------- + begin : THU Apr 19 2001 + copyright : (C) 2001 by Anders Lund + email : anders@alweb.dk + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef _PLUGIN_KATE_INSERT_COMMAND_H_ +#define _PLUGIN_KATE_INSERT_COMMAND_H_ + +#include <kate/application.h> +#include <kate/documentmanager.h> +#include <kate/document.h> +#include <kate/pluginconfiginterface.h> +#include <kate/pluginconfiginterfaceextension.h> +#include <kate/mainwindow.h> +#include <kate/plugin.h> +#include <kate/view.h> +#include <kate/viewmanager.h> + +#include <kcombobox.h> +#include <kdialogbase.h> +#include <klibloader.h> +#include <klocale.h> +#include <kurlrequester.h> +#include <qcheckbox.h> + + +class InsertCommandConfigPage; +namespace Kate { + class PluginConfigPage; + class PluginView; +} +class KConfig; +class KProcess; +class KShellProcess; +class QButtonGroup; +class QCheckBox; +class QSpinBox; +class QStringList; +class WaitDlg; + +class PluginKateInsertCommand : public Kate::Plugin, + Kate::PluginViewInterface, + Kate::PluginConfigInterfaceExtension +{ + Q_OBJECT + + public: + PluginKateInsertCommand( QObject* parent = 0, const char* name = 0, const QStringList& = QStringList() ); + virtual ~PluginKateInsertCommand(); + + void addView (Kate::MainWindow *win); + void removeView (Kate::MainWindow *win); + + Kate::View *kv; + + WaitDlg *wdlg; + QPtrList<class PluginView> m_views; + + uint configPages () const { return 1; } + Kate::PluginConfigPage *configPage (uint , QWidget *w, const char *name=0); + QString configPageName(uint) const { return i18n("Insert Command"); } + QString configPageFullName(uint) const { + return i18n("Configure Insert Command Plugin"); } + QPixmap configPagePixmap (uint /*number = 0*/, + int /*size = KIcon::SizeSmall*/) const + { return 0L; } + + private: + void initConfigPage( InsertCommandConfigPage* ); + + KShellProcess *sh; + QString workingdir; + QString cmd; + QStringList cmdhist; + bool bInsStdErr; + int dialogSettings; + KConfig *config; + + public slots: + void slotInsertCommand(); + void slotAbort(); + void applyConfig( InsertCommandConfigPage* ); + + private slots: + void slotReceivedStdout(KProcess*, char*, int); + void slotReceivedStderr(KProcess*, char*, int); + void slotProcessExited(KProcess*); + void slotShowWaitDlg(); +}; + +class CmdPrompt : public KDialogBase +{ +Q_OBJECT +public: + CmdPrompt(QWidget* parent=0, + const char* name=0, + const QStringList& cmdhist=QStringList(), + const QString& dir=QString::null, + const QString& docdir=QString::null, + int settings=0); + ~CmdPrompt(); + QString command()const { return cmb_cmd->currentText(); } + bool insertStdErr()const { return cb_insStdErr->isChecked(); } + bool printCmd()const { return cb_printCmd->isChecked(); } + QString wd()const { return wdreq->url(); } +private slots: + void slotTextChanged(const QString &text); + + + private: + KHistoryCombo *cmb_cmd; + KURLRequester *wdreq; + QCheckBox *cb_insStdErr; + QCheckBox *cb_printCmd; + +}; + +class WaitDlg : public KDialogBase +{ + public: + WaitDlg(QWidget* parent, + const QString& text=QString::null, + const QString& title=i18n("Please Wait")); + ~WaitDlg(); +}; + +/** Config page for the plugin. */ +class InsertCommandConfigPage : public Kate::PluginConfigPage +{ + Q_OBJECT + friend class PluginKateInsertCommand; + + public: + InsertCommandConfigPage(QObject* parent = 0L, QWidget *parentWidget = 0L); + ~InsertCommandConfigPage() {} + + /** Reimplemented from Kate::PluginConfigPage + * just emits configPageApplyRequest( this ). + */ + void apply(); + + void reset () { ; } + void defaults () { ; } + + signals: + /** Ask the plugin to set initial values */ + void configPageApplyRequest( InsertCommandConfigPage* ); + /** Ask the plugin to apply changes */ + void configPageInitRequest( InsertCommandConfigPage* ); + + protected: + QSpinBox *sb_cmdhistlen; + //QCheckBox *cb_startindocdir; + QButtonGroup *rg_startin; +}; + +#endif // _PLUGIN_KATE_INSERT_COMMAND_H_ +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/insertcommand/ui.rc b/kate/insertcommand/ui.rc new file mode 100644 index 0000000..49fb61b --- /dev/null +++ b/kate/insertcommand/ui.rc @@ -0,0 +1,8 @@ +<!DOCTYPE kpartgui> +<kpartplugin name="kateinsertcommand" library="libkateinsertcommandplugin" version="2"> +<MenuBar> + <Menu name="tools"><Text>&Tools</Text> + <Action name="edit_insert_command" /> + </Menu> +</MenuBar> +</kpartplugin> |