Scripting update
Anders Lund <[email protected]>
| Newsgroups | gmane.comp.kde.devel.kate |
|---|---|
| Organization | Saguaro |
| Message-ID | <[email protected]> |
Hi all, I have been working with Ian Geiser to enhance the scripting abilities of Kate. We have been making the kscript system work much better, * I changed the menu to not be a KSelectAction * I added a method int currentDocumentIfaceNumber() to KateMainWindow and to it's dcop interface * Ian got kscript to work with different script runners * Ian have been fixing the KTextEditor dcop interfaces to use "uint" rather than "unsigned int" and added more methods * I have written a perl script runner All in all, it is now possible to write a script that works on the current document in the first kate window (I still needs to add a dcop call to get the active window). To use the perl interface, you need * install or update kdebindings/dcopperl (I made it work with uints) * install kdenonbeta/kscriptperl (will be moved to kdebase or kdeaddons for next (3.2?) release. * update Kate as well as kdelibs/interfaces/ktexteditor - of cause:) The attached perl script shows how to use the interface. Put it along with the desktop file in $KDEDIR/share/apps/kate/scripts to try it out. The scripts converts the current document to lower case - in an undo-able way. Still TODO * add dcop interfaces for (some) remaining KTextEditor interfaces * add interfaces/dcop interfaces enough to make scripting merely worth it * release KDE 4, so that we can get to clean up those;) * add dcop interfaces for (some) Kate interfaces examples of missing stuff: - there is no way to get to know where a selection starts/ends - we should provide acces to editStart()/editEnd() for easy un/redoing Some notes: Since scripting Kate this way often will mean digging out the relevant of *many* interfaces, it is not very easy or logic at this point. Maybe using DCOPRef can enhance things a bit. The worst part is KTextEditor ***Extension classes, adding badly to the confusion. If we put viewcursor and selection interfaces in the views, and keeps them in the documents for backwards compability, things gets even more blurry. And where for "normal" purposes, you can use kdcop to copy the interface/method names and signatures, for kate with it's MDI that does not work directly, because you need to know the # of the document you wish to work with. -anders
tolowerperl.pl
(text/x-perl, 2 KB)
#!/usr/bin/perl =head1 Information This is a perl dcop script to convert the current document in a Kate window to lower case. Requires the DCOP perl module available in kdebindings/dcopperl This script is meant to be run by kscript. =head1 Author Anders Lund <[email protected]> =head1 Copyright Copyright (C) 2002, Anders Lund <[email protected]> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. =cut ### Obligatory for using DCOP use DCOP; my $client = new DCOP; $client->attach(); ### kscript feeds up the correct dcop identity my $app = shift @ARGV; ### convenience method:) sub interface( $$ ) { my ($interf, $number) = @_; $client->createObject( $app, "$interf#$number" ); } ### A kate.app.currentMainwindow is still needed! ### get the interfaces we need my $mw = $client->createObject( $app, "KateMainWindow0" ); my ($docNumber) = $mw->currentDocumentIfaceNumber(); my $editIF = interface( "EditInterface", $docNumber ); ### find the size of the text (i need to make sure i actually uses the correct values...) my ($newtext) = $editIF->text(); my ($lastLine) = $editIF->numLines(); my ($lltext) = $editIF->textLine($lastLine); my $lastCol = length $lltext; ### remove the old text and add the new one. (maybe we can add editStart() and editEnd() ??) $editIF->removeText( 0, 0, $lastLine, $lastCol ); $editIF->insertText( 0, 0, lc $newtext ); ### done, clean up $client->detach();
tolowerpl.desktop
(application/x-desktop, 123 B) - not displayed