This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Open text files by paths from a text inside kate

Tags: None
(comma "," separated)
User avatar
smartalgorithm
Registered Member
Posts
30
Karma
1
OS
Hi there :)
At work we are using Nedit (http://www.nedit.org/) text editor. The main reason for that is its ability to open a text file which path is given in opened text.
For example if we have this part of text

Code: Select all
.include "/directory/textfile.cpp"


then selecting /directory/textfile.cpp text from that document and then pressing CNTRL+Y key combination we will open textfile.cpp document in a new tab.
This is a very helpful feature especially when you always have to open those documents, look inside and change them...

So my question is this: Is it possible to do the same thing in Kate text editor?

Thanks
User avatar
scummos
Global Moderator
Posts
1175
Karma
7
OS
I don't think it exists right now, but you can probably easily write a python plugin or something, or even hack a 3-line shellscript with the dbus interface.

Greetings,
Sven


I'm working on the KDevelop IDE.
User avatar
smartalgorithm
Registered Member
Posts
30
Karma
1
OS
well im not a python programmer,,, :-\
User avatar
scummos
Global Moderator
Posts
1175
Karma
7
OS
Then you can of course also write the feature in C++ ;)

Or submit a wish on bugs.kde.org.


I'm working on the KDevelop IDE.
User avatar
smartalgorithm
Registered Member
Posts
30
Karma
1
OS
heheee,,, it is easy to say ahahahha yes i do program on c++ but i never participated in big projects like this,,, :)

let see what others will say...
thank you very much for your reply o)
User avatar
smartalgorithm
Registered Member
Posts
30
Karma
1
OS
Well.... according to Kate mailing list http://lists.kde.org/?l=kwrite-devel&r=1&w=2 where i've sent the same question all we have to do is this: http://lists.kde.org/?l=kwrite-devel&m=139276606403545&w=2 (BIG THANKS TO Philipp A)

whit some fixes (replacing commentary.py with source and changing the error message 'File {0} doesn't exist in {1}.' to "File {0} does not exist in {1}.") i've got this

Code: Select all
from PyKDE4.kdecore import  KUrl
import kate

@kate.action(text='Open selected', shortcut='Ctrl+Y', menu='Edit', icon='document-open')
def open_this():
    source = kate.activeView().selectionText()
    direc = kate.QtCore.QDir(kate.activeDocument().url().directory())

    if direc.exists(source):
        url = KUrl(direc.filePath(source))
        kate.mainInterfaceWindow().openUrl(url)
    else:
   kate.gui.popup("File {0} does not exist in {1}.".format(source, direc.absolutePath()), 3)


this is a python file with any name you like in the directory ~/.kde4/share/apps/kate/pate/
NOTE you have to enable python plugins (see pictures below)
Image
...
Image

It works nice,,, hope to see this kind of functionality built-in :-)
Thank you very much :)
User avatar
Hans
Administrator
Posts
3304
Karma
24
OS
Nice, thanks for sharing the solution you found!


Problem solved? Please click on "Accept this answer" below the post with the best answer to mark your topic as solved.

10 things you might want to do in KDE | Open menu with Super key | Mouse shortcuts
User avatar
smartalgorithm
Registered Member
Posts
30
Karma
1
OS


Bookmarks



Who is online

Registered users: abc72656, Bing [Bot], daret, Google [Bot], lockheed, Sogou [Bot], Yahoo [Bot]