kateconsole.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "kateconsole.h"
00022 #include "kateconsole.moc"
00023
00024 #include "katemain.h"
00025 #include "katemdi.h"
00026 #include "katemainwindow.h"
00027 #include "kateviewmanager.h"
00028
00029 #include <kate/view.h>
00030 #include <kate/document.h>
00031
00032 #include <kde_terminal_interface.h>
00033
00034 #include <kparts/part.h>
00035
00036 #include <kurl.h>
00037 #include <klibloader.h>
00038 #include <klocale.h>
00039 #include <kdebug.h>
00040 #include <kmessagebox.h>
00041
00042 KateConsole::KateConsole (KateMainWindow *mw, KateMDI::ToolView* parent)
00043 : QVBox (parent)
00044 , m_part (0)
00045 , m_mw (mw)
00046 , m_toolView (parent)
00047 {
00048 }
00049
00050 KateConsole::~KateConsole ()
00051 {
00052 disconnect ( m_part, SIGNAL(destroyed()), this, SLOT(slotDestroyed()) );
00053 }
00054
00055 void KateConsole::loadConsoleIfNeeded()
00056 {
00057 if (m_part) return;
00058
00059 if (!topLevelWidget() || !parentWidget()) return;
00060 if (!topLevelWidget() || !isVisibleTo(topLevelWidget())) return;
00061
00062 KLibFactory *factory = KLibLoader::self()->factory("libkonsolepart");
00063
00064 if (!factory) return;
00065
00066 m_part = static_cast<KParts::ReadOnlyPart *>(factory->create(this,"libkonsolepart", "KParts::ReadOnlyPart"));
00067
00068 if (!m_part) return;
00069
00070 setFocusProxy(m_part->widget());
00071
00072 KGlobal::locale()->insertCatalogue("konsole");
00073
00074 m_part->widget()->show();
00075
00076 connect ( m_part, SIGNAL(destroyed()), this, SLOT(slotDestroyed()) );
00077
00078 if (m_mw->viewManager()->activeView())
00079 if (m_mw->viewManager()->activeView()->getDoc()->url().isValid())
00080 cd(KURL( m_mw->viewManager()->activeView()->getDoc()->url().path() ));
00081 }
00082
00083 void KateConsole::slotDestroyed ()
00084 {
00085 m_part = 0;
00086
00087
00088 if (parentWidget())
00089 {
00090 m_mw->hideToolView (m_toolView);
00091 m_mw->centralWidget()->setFocus ();
00092 }
00093 }
00094
00095 void KateConsole::showEvent(QShowEvent *)
00096 {
00097 if (m_part) return;
00098
00099 loadConsoleIfNeeded();
00100 }
00101
00102 void KateConsole::cd (const KURL &url)
00103 {
00104 loadConsoleIfNeeded();
00105
00106 if (!m_part) return;
00107
00108 m_part->openURL (url);
00109 }
00110
00111 void KateConsole::sendInput( const QString& text )
00112 {
00113 loadConsoleIfNeeded();
00114
00115 if (!m_part) return;
00116
00117 TerminalInterface *t = static_cast<TerminalInterface*>( m_part->qt_cast( "TerminalInterface" ) );
00118
00119 if (!t) return;
00120
00121 t->sendInput (text);
00122 }
00123
00124 void KateConsole::slotPipeToConsole ()
00125 {
00126 if (KMessageBox::warningContinueCancel
00127 (m_mw
00128 , i18n ("Do you really want to pipe the text to the console? This will execute any contained commands with your user rights.")
00129 , i18n ("Pipe to Console?")
00130 , i18n("Pipe to Console"), "Pipe To Console Warning") != KMessageBox::Continue)
00131 return;
00132
00133 Kate::View *v = m_mw->viewManager()->activeView();
00134
00135 if (!v)
00136 return;
00137
00138 if (v->getDoc()->hasSelection ())
00139 sendInput (v->getDoc()->selection());
00140 else
00141 sendInput (v->getDoc()->text());
00142 }
|