selection

Post here any ideas/problems/suggestions you have regarding CodeLite's ExternalTools plugin
User avatar
kspes
CodeLite Enthusiast
Posts: 41
Joined: Sat Jan 30, 2010 2:18 am
Genuine User: Yes
IDE Question: C++
Contact:

selection

Post 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?
User avatar
eranif
CodeLite Plugin
Posts: 6367
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: selection

Post 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
Make sure you have read the HOW TO POST thread
User avatar
kspes
CodeLite Enthusiast
Posts: 41
Joined: Sat Jan 30, 2010 2:18 am
Genuine User: Yes
IDE Question: C++
Contact:

Re: selection

Post by kspes »

Cool, thanks.
User avatar
kspes
CodeLite Enthusiast
Posts: 41
Joined: Sat Jan 30, 2010 2:18 am
Genuine User: Yes
IDE Question: C++
Contact:

Re: selection

Post 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()
{

}
------
User avatar
eranif
CodeLite Plugin
Posts: 6367
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: selection

Post 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
Make sure you have read the HOW TO POST thread
User avatar
kspes
CodeLite Enthusiast
Posts: 41
Joined: Sat Jan 30, 2010 2:18 am
Genuine User: Yes
IDE Question: C++
Contact:

Re: selection

Post 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
User avatar
kspes
CodeLite Enthusiast
Posts: 41
Joined: Sat Jan 30, 2010 2:18 am
Genuine User: Yes
IDE Question: C++
Contact:

Re: selection

Post 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!
You do not have the required permissions to view the files attached to this post.
User avatar
eranif
CodeLite Plugin
Posts: 6367
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: selection

Post 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
Make sure you have read the HOW TO POST thread
Post Reply