Page 1 of 1
selection
Posted: Tue Feb 16, 2010 6:23 pm
by kspes
Is there a way I can pass an argument to a script that will indicate what I have currently selected?
eg, selected character index in file and last selected character index?
Re: selection
Posted: Tue Feb 16, 2010 7:24 pm
by eranif
In the trunk version of codelite there is an option to use
$(CurrentSelection) macro this returns the currently selected text in the active editor
If you need anything else, you can add it to macrosmanager.cpp and provide a patch for it.
Eran
Re: selection
Posted: Tue Feb 16, 2010 7:32 pm
by kspes
Cool, thanks.
Re: selection
Posted: Tue Feb 16, 2010 8:24 pm
by kspes
Ok, I figured it out, it's actually quite a simple piece of code in macromanager.cpp
There is a potential problem with $(CurrentSelection) [ Codelite revision 3765 ]
it just pastes the selected text into the command line, which will work fine for simple words, but if you want to select more text, with whitespace and newlines, you get a nightmare.
I'll try and make a patch with the following changes in the following days:
1) $(SelectionIndexStart)
2) $(SelectionIndexEnd)
this way, a script can parse a file and get the selected text without ease.
what I'm trying to do is (mostly for fun):
to make a python script that'll replace function prototypes with implementation bases, eg:
selected:
------
class A
{
void fn1();
void fn2();
};
-----
replaced with:
void A::fn1()
{
}
void A::fn2()
{
}
------
Re: selection
Posted: Tue Feb 16, 2010 10:16 pm
by eranif
kspes wrote:to make a python script that'll replace function prototypes with implementation bases, eg:
selected:
------
class A
{
void fn1();
void fn2();
};
-----
replaced with:
void A::fn1()
{
}
void A::fn2()
{
}
------
right click inside the class, and select 'Code Generation / Refactoring -> Implement all un-implemented methods' and you will have it
Eran
Re: selection
Posted: Tue Feb 16, 2010 11:57 pm
by kspes
Lol, i figured there was something like that. But regardless, the selection indices could be useful so i'll see what i can contribute there
Re: selection
Posted: Tue Feb 23, 2010 7:55 pm
by kspes
Hi Eran, I've played arround with the code a bit and made this feature (patch attached in this post and to the patch tracker:
https://sourceforge.net/tracker/?func=d ... tid=979962)
Functionality
$(CurrentSelectionRange) gives you start:end indexes of the selected text, eg. 150:200 means a selection that starts at the 150th character and selects 50 characters.
Why
Because $(CurrentSelection) expands to the exact selected text which causes problems if spaces, quotes or newlines are selected, $(CurrentSelection) is useful for selecting single words while $(CurrentSelectionRange) is for selecting more text
How
In short, I've added the macro to macromanager.cpp and definition in macrosdlg.cpp.
I had to add two functions to IEditor interface: GetSelectionStart and GetSelectionEnd as pure virtual functions and their implementations in LEditor which call the respective functions of wxScintilla.
Notes
As I'm still familiarizing myself with the code, please review the patch thoroughly (it's not long), I don't want to introduce new bugs
I'm not sure if LEditor is the only class that inherits IEditor and if not, do those other classes need implementations of these functions.
Also, you may want to review doxygen code I wrote in IEditor
Also I'd like to add that CodeLite's code is quite readable, I found my way arround it quite quickly and easily, Kudo to you!
Re: selection
Posted: Tue Feb 23, 2010 8:14 pm
by eranif
kspes wrote:LEditor is the only class that inherits IEditor and if not, do those other classes need
Yes. LEditor is the class used by the main application exe, while IEditor is the interface exposed to the plugins
I will have a look at this patch as soon as I will find some time
Eran