PATCH: numpad-5 centers current line

Discussion about CodeLite development process and patches
foxmuldr
CodeLite Expert
Posts: 120
Joined: Sun May 10, 2009 6:56 am
Contact:

PATCH: numpad-5 centers current line

Post by foxmuldr »

Pressing the numpad-5 key in non-numlock mode rolls the current line to center of visible window.

Says uploads are disabled right now. Go to SourceForge CodeLite patch page for download.

http://sourceforge.net/support/tracker.php?aid=3064703

- Rick
Best regards,
Rick C. Hodgin
www.Visual-FreePro.org
www.LibSF.org
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: PATCH: numpad-5 centers current line

Post by eranif »

The patch is too much hard coded.

Each key combination should be editable from the 'settings -> keyboard shortcuts..'

To achieve what you want you should have:
- Add new menu entry to one of the menus (e.g. Edit -> Center Editor Line) - this is done by editing the menu.xrc file:

add the following menu entry to the Edit menu in the menu.xrc file:

Code: Select all

<object class="wxMenuItem" name="center_line">
    <label>Center Editor L&ine</label>
</object>
- Next, add new entry to the global accelerator file (accelerators.conf.default), like this:

Code: Select all

center_line|Edit|Center Editor Line|CLEAR
Where:
center_line - is the identifier for the event, must be identical as the name attribute added to the menu.xrc file
Edit - is the parent menu holding the new menu entry
Center Line - is the menu entry name
CLEAR - it is the accelerator name for NumPad5 (when NumPad is Off)

By adding this line, codelite will automatically add an entry to the 'Keyboard Shortcuts...' dialog + it will add new menu entry to the 'Edit' menu.

Now all is left is to add event handler for the new menu entry, you should add this line to frame.cpp:

Code: Select all

EVT_MENU(XRCID("center_line"),              clMainFrame::DispatchCommandEvent)
EVT_UPDATE_UI(XRCID("center_line"),         clMainFrame::OnFileExistUpdateUI)
Add the actual code to the class EditHandler::ProcessCommandEvent, from file menu_event_handlers.cpp.


Eran
Make sure you have read the HOW TO POST thread
foxmuldr
CodeLite Expert
Posts: 120
Joined: Sun May 10, 2009 6:56 am
Contact:

Re: PATCH: numpad-5 centers current line

Post by foxmuldr »

eranif wrote:The patch is too much hard coded....
An excellent explanation. Thanks. On Ubuntu 10.04, the numpad-5 key is KP_BEGIN when numlock off.

I did all you say. I can't get the code in this patch to even execute my code in the function. Not even when I select it from the menu. If you get a chance to look it over, what did I do wrong?
You do not have the required permissions to view the files attached to this post.
Best regards,
Rick C. Hodgin
www.Visual-FreePro.org
www.LibSF.org
foxmuldr
CodeLite Expert
Posts: 120
Joined: Sun May 10, 2009 6:56 am
Contact:

Re: PATCH: numpad-5 centers current line

Post by foxmuldr »

foxmuldr wrote:I did all you say. I can't get the code in this patch to even execute my code in the function. Not even when I select it from the menu. If you get a chance to look it over, what did I do wrong?
Do you have a chance to look over it? The patch itself is pretty small.
Best regards,
Rick C. Hodgin
www.Visual-FreePro.org
www.LibSF.org
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: PATCH: numpad-5 centers current line

Post by eranif »

One line of code was missing:

in file menumanager.cpp:

Code: Select all

PushHandler(new EditHandler(XRCID("center_line")));
You needed to register the new command with the event handler.

Patch, applied

Eran
Make sure you have read the HOW TO POST thread
Post Reply