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; }
/************************************************* * * KDataToolAction * *************************************************/ KDataToolAction::KDataToolAction( const QString & text, const KDataToolInfo & info, const QString & command, QObject * parent, const char * name ) : KAction( text, info.iconName(), 0, parent, name ), m_command( command ), m_info( info ) { }
bool KBabelView::validateUsingTool( const KDataToolInfo & info, const QString &command ) { if(currentURL().isEmpty()) return false; KDataTool* tool = info.createTool(); if( !tool ) { kdWarning() << "Cannot create tool" << endl; return false; } bool result=_catalog->checkUsingTool(tool); emitEntryState(); QString checkName = *(info.userCommands().at( info.commands().findIndex(command) )); if(result) { KMessageBox::information(this ,i18n("No mismatch has been found.") ,checkName); } else { int index=0; DocPosition pos; if(!_catalog->hasError(0,pos)) index = _catalog->nextError(0,pos); if(index>=0) { kdDebug(KBABEL) << "Going to " << pos.item << ", " << pos.form << endl; gotoEntry(pos); } KMessageBox::error(this ,i18n("Some mismatches have been found.\n" "Please check the questionable entries by using " "Go->Next error") ,checkName); } delete tool; return result; }
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; }
void KBabelView::modifyUsingTool( const KDataToolInfo & info, const QString &command ) { KDataTool* tool = info.createTool(); if( !tool ) { kdWarning() << "Cannot create tool" << endl; return; } // do some stuff on all entries _catalog->modifyUsingTool(tool, command); delete tool; }
KDataToolInfo::KDataToolInfo( const KDataToolInfo& info ) { m_service = info.service(); m_instance = info.instance(); }