KDataTool* KDataToolInfo::createTool( QObject* parent, const char* name ) const { if ( !m_service ) return 0; KDataTool* tool = KParts::ComponentFactory::createInstanceFromService<KDataTool>( m_service, parent, name ); if ( tool ) tool->setInstance( m_instance ); return tool; }
void KDataToolPluginView::slotToolActivated( const KDataToolInfo &info, const QString &command ) { KDataTool* tool = info.createTool( ); if ( !tool ) { kdWarning() << "Could not create Tool !" << endl; return; } QString text; if ( selectionInterface(m_view->document())->hasSelection() ) text = selectionInterface(m_view->document())->selection(); else text = m_wordUnderCursor; QString mimetype = "text/plain"; QString datatype = "QString"; // If unsupported (and if we have a single word indeed), try application/x-singleword if ( !info.mimeTypes().contains( mimetype ) && m_singleWord ) mimetype = "application/x-singleword"; kdDebug() << "Running tool with datatype=" << datatype << " mimetype=" << mimetype << endl; QString origText = text; if ( tool->run( command, &text, datatype, mimetype) ) { kdDebug() << "Tool ran. Text is now " << text << endl; if ( origText != text ) { uint line, col; viewCursorInterface(m_view)->cursorPositionReal(&line, &col); if ( ! selectionInterface(m_view->document())->hasSelection() ) { KTextEditor::SelectionInterface *si; si = KTextEditor::selectionInterface(m_view->document()); si->setSelection(m_singleWord_line, m_singleWord_start, m_singleWord_line, m_singleWord_end); } // replace selection with 'text' selectionInterface(m_view->document())->removeSelectedText(); viewCursorInterface(m_view)->cursorPositionReal(&line, &col); editInterface(m_view->document())->insertText(line, col, text); // fixme: place cursor at the end: /* No idea yet (Joseph Wenninger) for ( uint i = 0; i < text.length(); i++ ) { viewCursorInterface(m_view)->cursorRight(); } */ } } delete tool; }
void KBabelView::modifyCatalogUsingTool( const KDataToolInfo & info, const QString &command ) { KDataTool* tool = info.createTool(); if( !tool ) { kdWarning() << "Cannot create tool" << endl; return; } // do some stuff on the catalog tool->run(command, _catalog, "Catalog", "application/x-kbabel-catalog"); delete tool; }