kate
kateconsole.cpp
Go to the documentation of this file.00001
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 if (m_part)
00053 disconnect ( m_part, SIGNAL(destroyed()), this, SLOT(slotDestroyed()) );
00054 }
00055
00056 void KateConsole::loadConsoleIfNeeded()
00057 {
00058 if (m_part) return;
00059
00060 if (!topLevelWidget() || !parentWidget()) return;
00061 if (!topLevelWidget() || !isVisibleTo(topLevelWidget())) return;
00062
00063 KLibFactory *factory = KLibLoader::self()->factory("libkonsolepart");
00064
00065 if (!factory) return;
00066
00067 m_part = static_cast<KParts::ReadOnlyPart *>(factory->create(this,"libkonsolepart", "KParts::ReadOnlyPart"));
00068
00069 if (!m_part) return;
00070
00071 setFocusProxy(m_part->widget());
00072
00073 KGlobal::locale()->insertCatalogue("konsole");
00074
00075 m_part->widget()->show();
00076
00077 connect ( m_part, SIGNAL(destroyed()), this, SLOT(slotDestroyed()) );
00078
00079 if (m_mw->viewManager()->activeView())
00080 if (m_mw->viewManager()->activeView()->getDoc()->url().isValid())
00081 cd(KURL( m_mw->viewManager()->activeView()->getDoc()->url().path() ));
00082 }
00083
00084 void KateConsole::slotDestroyed ()
00085 {
00086 m_part = 0;
00087
00088
00089 if (parentWidget())
00090 {
00091 m_mw->hideToolView (m_toolView);
00092 m_mw->centralWidget()->setFocus ();
00093 }
00094 }
00095
00096 void KateConsole::showEvent(QShowEvent *)
00097 {
00098 if (m_part) return;
00099
00100 loadConsoleIfNeeded();
00101 }
00102
00103 void KateConsole::cd (const KURL &url)
00104 {
00105 loadConsoleIfNeeded();
00106
00107 if (!m_part) return;
00108
00109 m_part->openURL (url);
00110 }
00111
00112 void KateConsole::sendInput( const QString& text )
00113 {
00114 loadConsoleIfNeeded();
00115
00116 if (!m_part) return;
00117
00118 TerminalInterface *t = static_cast<TerminalInterface*>( m_part->qt_cast( "TerminalInterface" ) );
00119
00120 if (!t) return;
00121
00122 t->sendInput (text);
00123 }
00124
00125 void KateConsole::slotPipeToConsole ()
00126 {
00127 if (KMessageBox::warningContinueCancel
00128 (m_mw
00129 , i18n ("Do you really want to pipe the text to the console? This will execute any contained commands with your user rights.")
00130 , i18n ("Pipe to Console?")
00131 , i18n("Pipe to Console"), "Pipe To Console Warning") != KMessageBox::Continue)
00132 return;
00133
00134 Kate::View *v = m_mw->viewManager()->activeView();
00135
00136 if (!v)
00137 return;
00138
00139 if (v->getDoc()->hasSelection ())
00140 sendInput (v->getDoc()->selection());
00141 else
00142 sendInput (v->getDoc()->text());
00143 }