[done] Customize tab menus

Request Features and Feature Changes

[done] Customize tab menus

Postby seb » Fri Feb 26, 2010 11:34 am

Hi Cody,

I'm back with another feature request, hoping not annoying you :)

So far so good, I've been able to customize context menu in a buffer. But while using IDE, I've surprised myself (...) right-click on tab label, instead of buffer content, in order to select one of my custom actions. This is because these actions are related to the whole file, not part of the content, so instinctively I clicked on the tab.

So, I'd now like to customize tab menus. I've found no way to do this with current version. I had a look at ed_msg, and found EDMSG_MENU, but it doesn't seem to be used. I then patched ed_pages, (see attachment, probably refactoring needed) in order to post message when right-clicking on a tab. Maybe an EDMSG_TAB_MENU message would be more appropriate, as I don't know what's the meaning behind EDMSG_MENU (might be too general).

What do you think about this ?

PS: ideally, I'd also like to customize context menu in CodeBrowser too. Are you ok if I provide patches too ?


Cheers,
Seb
Attachments
ed_pages.patch
(1.65 KiB) Downloaded 81 times
seb
Power User
 
Posts: 51
Joined: Mon Feb 01, 2010 4:19 pm

Re: Customize tab menus

Postby cody » Fri Feb 26, 2010 2:21 pm

Hi,

Yea, lets not duplicate code from one place to another. I would prefer to see a helper class created that is responsible for managing the handler methods and sending out the menu updates.

Also the message EDMSG_MENU is a base root message and should not be sent directly, a new message should be created that derives from the component it belongs to. In this case its the notebook so something like,

EDMSG_UI_NB_CONTEXT_MENU = EDMSG_UI_NB + ("contextmenu",)


Cody
User avatar
cody
Site Admin
 
Posts: 1301
Joined: Mon Oct 09, 2006 2:49 am
Location: United States

Re: Customize tab menus

Postby seb » Fri Feb 26, 2010 5:03 pm

Here's another patch, trying to follow your guidelines:

- "HandlerDispatch" helper in util.py, as the refactored code (sorry, I'm not able to send out the menu updates, from a helper class as you want, I just don't have a "big enough" picture)
- ed_editv.py calling this helper.
- ed_msg.py contains a new message
- ed_pages deals with tab context menu

It might not be as clean as required...

Cheers,
Seb
Attachments
tabmenu.patch
(3.74 KiB) Downloaded 84 times
seb
Power User
 
Posts: 51
Joined: Mon Feb 01, 2010 4:19 pm

Re: Customize tab menus

Postby cody » Sat Feb 27, 2010 4:24 am

Hello,

Thanks, but I decided to do it a bit different. You will have to update your handler for the buffers context menu as well but I think it is a little easier to use api now.

The message will have a ContextMenuManager object as its data.

Code: Select all
def OnMessage(self, msg):
    data = msg.GetData()
    menu = data.GetMenu()
    data.AddHandler(ID_MENU_ID, self.OnMenu)


The message for the Tab menu is EDMSG_UI_NB_TABMENU.


Cody
User avatar
cody
Site Admin
 
Posts: 1301
Joined: Mon Oct 09, 2006 2:49 am
Location: United States

Re: Customize tab menus

Postby seb » Sat Feb 27, 2010 8:28 am

Hi Cody,

This looks great and more user-friendly !

I tried to migrate my code, but got troubles with context menu from EdEditorView. I can't find the buffer anymore. Shouldn't it be added as a user-data, so it can be retrieved with GetUserData("buff") ? This RCLICK_MENU may not be a class attribute anymore, since it's buffer dependent (correct me if I'm wrong).

Cheers,
Seb
seb
Power User
 
Posts: 51
Joined: Mon Feb 01, 2010 4:19 pm

Re: Customize tab menus

Postby cody » Sat Feb 27, 2010 2:14 pm

Sorry, somehow missed that that was part of the original message data.

You can get it now with 'GetUserData('buffer')'



Cody
User avatar
cody
Site Admin
 
Posts: 1301
Joined: Mon Oct 09, 2006 2:49 am
Location: United States

Re: Customize tab menus

Postby seb » Sat Feb 27, 2010 6:14 pm

Thanks !

Can you also add "tab" user-data when right-clicking on a tab ? This would be the equivalent of buffer, which gives clues about the context when the click occured. (self._menu.AddUserData("page",ctab)).

Basically, I use this to determine what is the language contained in the tab, and enrich menu or not.

Code: Select all
    def OnTabContextMessage(self,msg):
        data = msg.GetData()
        menu = data.GetMenu()
        page = data.GetUserData('page')
        if page.GetLangId() != synglob.ID_LANG_JAL:
            return


Cheers,
Seb
seb
Power User
 
Posts: 51
Joined: Mon Feb 01, 2010 4:19 pm

Re: Customize tab menus

Postby cody » Sat Feb 27, 2010 6:55 pm

sure, done
User avatar
cody
Site Admin
 
Posts: 1301
Joined: Mon Oct 09, 2006 2:49 am
Location: United States


Return to Feature Requests

Who is online

Users browsing this forum: No registered users and 0 guests

cron