KDevelop API Documentation

parts/filter/filterpart.cpp

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * Copyright (C) 2002 by Bernd Gehrmann * 00003 * bernd@kdevelop.org * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 ***************************************************************************/ 00011 00012 #include "filterpart.h" 00013 00014 #include <kaction.h> 00015 #include <kdebug.h> 00016 #include <klocale.h> 00017 #include <kparts/part.h> 00018 #include <ktexteditor/editinterface.h> 00019 #include <ktexteditor/selectioninterface.h> 00020 #include <ktexteditor/viewcursorinterface.h> 00021 00022 #include "kdevcore.h" 00023 #include "kdevpartcontroller.h" 00024 #include "shellfilterdlg.h" 00025 #include "shellinsertdlg.h" 00026 #include "kdevfilterIface.h" 00027 00028 static const KAboutData data("kdevfilter", I18N_NOOP("Execute shell command"), "1.0"); 00029 K_EXPORT_COMPONENT_FACTORY( libkdevfilter, FilterFactory( &data ) ) 00030 00031 FilterPart::FilterPart(QObject *parent, const char *name, const QStringList &) 00032 : KDevPlugin("Filter", "filter", parent, name ? name : "FilterPart") 00033 { 00034 setInstance(FilterFactory::instance()); 00035 setXMLFile("kdevfilter.rc"); 00036 00037 KAction *action; 00038 00039 action = new KAction( i18n("Execute Command..."), 0, 00040 this, SLOT(slotShellInsert()), 00041 actionCollection(), "tools_insertshell" ); 00042 action->setToolTip(i18n("Execute shell command")); 00043 action->setWhatsThis(i18n("<b>Execute shell command</b><p>Executes a shell command and outputs it's result into the current document.")); 00044 00045 action = new KAction( i18n("Filter Selection Through Command..."), 0, 00046 this, SLOT(slotShellFilter()), 00047 actionCollection(), "tools_filtershell" ); 00048 action->setToolTip(i18n("Filter selection trough a shell command")); 00049 action->setWhatsThis(i18n("<b>Filter selection trough shell command</b><p>Filters selection trough a shell command and outputs it's result into the current document.")); 00050 00051 m_insertDialog = 0; 00052 m_filterDialog = 0; 00053 00054 new KDevFilterIface( this ); 00055 // (void) dcopClient(); 00056 } 00057 00058 00059 FilterPart::~FilterPart() 00060 { 00061 delete m_insertDialog; 00062 delete m_filterDialog; 00063 } 00064 00065 00066 void FilterPart::slotShellInsert() 00067 { 00069 00070 KParts::ReadWritePart *part 00071 = dynamic_cast<KParts::ReadWritePart*>(partController()->activePart()); 00072 QWidget *view = partController()->activeWidget(); 00073 if (!part || !view) { 00074 kdDebug(9029) << "no rw part" << endl; 00075 return; 00076 } 00077 00078 KTextEditor::EditInterface *editiface 00079 = dynamic_cast<KTextEditor::EditInterface*>(part); 00080 if (!editiface) { 00081 kdDebug(9029) << "no edit" << endl; 00082 return; 00083 } 00084 00085 KTextEditor::ViewCursorInterface *cursoriface 00086 = dynamic_cast<KTextEditor::ViewCursorInterface*>(view); 00087 if (!cursoriface) { 00088 kdDebug(9029) << "no viewcursor" << endl; 00089 return; 00090 } 00091 00092 if (!m_insertDialog) 00093 { 00094 m_insertDialog = new ShellInsertDialog(); 00095 m_insertDialog->setCaption(i18n("Execute Command")); 00096 } 00097 if (m_insertDialog->exec()) { 00098 uint line, col; 00099 cursoriface->cursorPositionReal(&line, &col); 00100 editiface->insertText(line, col, m_insertDialog->text()); 00101 } 00102 } 00103 00104 00105 void FilterPart::slotShellFilter() 00106 { 00108 00109 KParts::ReadWritePart *part 00110 = dynamic_cast<KParts::ReadWritePart*>(partController()->activePart()); 00111 QWidget *view = partController()->activeWidget(); 00112 if (!part || !view) { 00113 kdDebug(9029) << "no rw part" << endl; 00114 return; 00115 } 00116 00117 KTextEditor::EditInterface *editiface 00118 = dynamic_cast<KTextEditor::EditInterface*>(part); 00119 if (!editiface) { 00120 kdDebug(9029) << "no edit" << endl; 00121 return; 00122 } 00123 00124 KTextEditor::ViewCursorInterface *cursoriface 00125 = dynamic_cast<KTextEditor::ViewCursorInterface*>(view); 00126 if (!cursoriface) { 00127 kdDebug(9029) << "no viewcursor" << endl; 00128 return; 00129 } 00130 00131 KTextEditor::SelectionInterface *selectioniface 00132 = dynamic_cast<KTextEditor::SelectionInterface*>(part); 00133 if (!selectioniface) { 00134 kdDebug(9029) << "no selection" << endl; 00135 return; 00136 } 00137 00138 if (!m_filterDialog) 00139 { 00140 m_filterDialog = new ShellFilterDialog(); 00141 m_filterDialog->setCaption(i18n("Filter Selection Through Command")); 00142 } 00143 00144 kdDebug(9029) << "Old text: " << selectioniface->selection()<< endl; 00145 00146 m_filterDialog->setText(selectioniface->selection()); 00147 00148 if (m_filterDialog->exec()) { 00149 uint line, col; 00150 // OUCH: KTextEditor doesn't allow to find out 00151 // where the selection is 00152 selectioniface->removeSelectedText(); 00153 cursoriface->cursorPositionReal(&line, &col); 00154 kdDebug(9029) << "New text: " << m_filterDialog->text() << endl; 00155 editiface->insertText(line, col, m_filterDialog->text()); 00156 } 00157 } 00158 00159 #include "filterpart.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.0.4.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Oct 19 08:01:52 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003