Page 1 of 1

PATCH: numpad-5 centers current line

Posted: Sun Sep 12, 2010 3:35 pm
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

Re: PATCH: numpad-5 centers current line

Posted: Sun Sep 12, 2010 8:07 pm
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

Re: PATCH: numpad-5 centers current line

Posted: Mon Sep 13, 2010 4:44 pm
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?

Re: PATCH: numpad-5 centers current line

Posted: Sun Sep 19, 2010 12:19 pm
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.

Re: PATCH: numpad-5 centers current line

Posted: Wed Sep 22, 2010 5:50 pm
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