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

Update A ColumnMenu's Items #150

Open
ItsErikSquared opened this issue Jan 31, 2021 · 7 comments
Open

Update A ColumnMenu's Items #150

ItsErikSquared opened this issue Jan 31, 2021 · 7 comments

Comments

@ItsErikSquared
Copy link

Hello,

I was attempting to update a ColumnMenu's items.
I couldn't find a function to update/add/remove the items in a ColumnMenu though it is completely possible I just missed it (if so please forgive me). I know I could just keep rebuilding it over and over again, but I don't feel that's really a good answer to the problem.

I've tried a couple different ways of doing this but the one that has been most successful is below, however the menu appears when its added, then disappears when you focus on the menu, and will reappear when you lose focus, and then focus again, so it's not ideal at all.

var SelectedWindowMenu = new ColumnMenu({
    parent: AnotherCoolWindow,
    x: 1,
    y: 12,
    width: 20,
    height: AnotherCoolWindow.length - 12,
    items: [
      { content: '^G+ Create', value: 'create', contentHasMarkup: true },
      { content: '^G+ Join', value: 'join', contentHasMarkup: true },
      { content: '', disabled: true, internalRole: 'separator' }
    ]
  })

...

client.on('join', s => {
    SelectedWindowMenu.itemsDef.push({content: s.name, value: s.id})
    SelectedWindowMenu.autoWidth = true
    SelectedWindowMenu.onParentResize()
})

So please tell me, is there a function that is already implemented that I missed, or is there a workaround (other than destroying and rebuilding it every time there's an item that has to be added or removed), or is this just isn't currently possible?

I appreciate any help and/or suggestions.

@cronvel
Copy link
Owner

cronvel commented Feb 17, 2021

@ItsErikSquared Try menu.setItem( itemValue , itemDef ), e.g.: menu.setItem( 'join' , { content: '^R+ JOIN' } ).
I just added it and published it as of v1.48.0, so tell me if it does the job! ;)

cronvel added a commit that referenced this issue Feb 18, 2021
@ItsErikSquared
Copy link
Author

@cronvel While this will definitely be useful in my project (thank you so much), I was wondering if it is possible to append and remove items to the menu.
The setItem method does edit existing items, but not add or remove them.

@cronvel
Copy link
Owner

cronvel commented Feb 19, 2021

@ItsErikSquared What are you trying to achieve? (your use-case)
If a menu was changing that much, I would probably just recreate it from scratch.

@ItsErikSquared
Copy link
Author

@cronvel Essentially, I am creating an alternative chat client. Basically, a user can join or leave a room. Rooms are able to be joined/created/removed during the usage of the application. If you recommend I just rebuild the menu each time, I'll do that.
My goal was to add and remove entries.

ex:
menu.addItem('channel1', { content: 'Channel 1'}) - Add to the end of the menu
menu.removeItem('channel1') - Remove from the menu
menu.addItemAtIndex(2, 'channel1', { content: 'Channel 1') - Insert the entry at index 2 (like an array)
menu.removeItemAtIndex(2) - Remove the entry at index 2 (like an array)

After rereading what I requested, I can see the complications this may entail, so rebuilding the menu may be a better option.

I do appreciate you taking the time to look into this. :)

@cronvel
Copy link
Owner

cronvel commented Feb 20, 2021

@ItsErikSquared When you write a lib, you never know which kind of use-cases will pop up! ^^
Now it seems that it should be supported by the ColumnMenu. I will look into it once I got some free-time.

@cronvel
Copy link
Owner

cronvel commented Feb 23, 2021

@ItsErikSquared What kind of API would it looks like? I see little value in sending all the menu params vs recreating the menu. But append a menu item or delete an item seems legit.

@ItsErikSquared
Copy link
Author

@cronvel Sorry about the delayed reply (life happens). I am unsure what you mean by the question?

If you mean method-wise, just append(name, options) or remove(name) seems ok to me.

I may be interpreting the question incorrectly, however.

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

2 participants