Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to set itemID #5

Open
defaultbr opened this issue Feb 4, 2016 · 6 comments
Open

Ability to set itemID #5

defaultbr opened this issue Feb 4, 2016 · 6 comments

Comments

@defaultbr
Copy link

i saw that the is generated using the number of items, is there any way to make a setItemId?

why:

in my nav drawer, user can create ITEMS (categories) and than add some items to this categories, in this way that the Sublime do, all the time will have a new ID if i delete or add another item, this make a big mess in the categories, since its linked produts -> itemID(categorie)

@vikramkakkar
Copy link
Owner

SublimeMenu requires that its menu items should hold unique IDs - even the Separator items have unique IDs.

If I do add the option for setting item ID, how will you ensure its uniqueness?

@defaultbr
Copy link
Author

im not really checking it, i generate the ID from a random btw 10000000 and 9999999, since each user in my case will generate at the maximum of 10, so the risk is the minimum

i understand what are you saying! maybe you could add somekind of "TAG" like normal views .setTag

thank you

@danbrough
Copy link

My menu model has unique id's that I'd like to use as menu-item ids.
Couldn't you just throw an error if they aren't unique?
Otherwise I'll have to maintain a map to translate the generated menu-item id to the id in my menu model so I know which menu was clicked on.

@danbrough
Copy link

If I could attach a click listener to a menu-item that would work.

@vikramkakkar
Copy link
Owner

@danbrough I like your suggestion of throwing an exception in case the given ID isn't unique.

If I understand you correctly, this would mean all the add* methods would be overloaded to provide an additional argument - the ID. API would be:

  • the add* methods without the ID argument would use SublimeMenu.generateUniqueItemID() method
  • the add* methods with the ID argument would throw an exception if the given ID already exists. Current implementation stores the MenuItems in an ArrayList. This would require a traversal on every add* operation. Perhaps SublimeMenu should maintain a Map to store IDs - all add* and remove* methods will require changes in this case

Do these changes meet your requirement?

@danbrough
Copy link

It would work, but it would be nasty to resolve if one of my id's conflicted with a generated id.
I can always explicitly set every id rather than let some be generated and then get caught out trying to use an id that conflicts with one that was generated.
I can already do this if I use xml to define the MenuItems.
So it would make sense to do as you suggested and make the protected methods public so I can do this programmatically.
thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants