Answered

Extend WidgetContextMenu if widget is not locked

  • 13 May 2020
  • 6 replies
  • 1123 views

Hello,

I am trying to add a button to WidgetContextMenu if the selected widget is a Sticker and it is not locked.

I can get the type of widget from the widget object, but it is not clear where i can garner if the widget has been locked or not. This leads to my button being accessible on locked objects, as shown:

Can you please offer any guidance on how to tell whether the widget is locked from within the plugin code?

Hope this is clear and thanks in advance.

Oliver.

icon

Best answer by Boris Borodyansky 13 May 2020, 17:32

View original

6 replies

Userlevel 4
Badge +1

hey!

Unfortunately there’s no way right now to understand whether widget is locked or not.

Will add it to our backlog :muscle:

Userlevel 2
Badge +2

@Boris Borodyansky gave an answer in another thread on how to add an icon to a widget:

https://community.miro.com/developer-forum-57/add-icon-to-widgetcontextmenu-393?postid=1253#post1253

But i have not yet found out, how the onClick Callback retrieves any info on the widget that was clicked. The callback from the SDK does not deliver anything.

t.prototype.callMenuItemClickListener = function(t) {
this.menuItemsClickListeners["widgetMenuItems_" + t]()
}

I am afraid, that we have to get the info about the items that contextmenu is supposed to work on, from the current selection. But we might have to catch it in the outer widgets context method and not give it as a parameter in the onClick method. 

Any thoughts or ideas? 

 

Falk

Yes i have successfully added the button using the following (apologies for the formatting, it seems to be broken):

 miro.onReady(() => {
miro.initialize({
extensionPoints: {
getWidgetMenuItems: async (widgets) => {
if (widgets[0]['type'] == 'STICKER') {
return Promise.resolve({
tooltip: 'tooltip',
svgIcon: icon,
onClick: (widgets) => {
doStuff(widgets)
}

})
}
}
}
})
})

Getting the information that contextmenu is supposed to work on from the current selection should not be an issue here, as the resulting action (doStuff() in the above code) acts on the current selection anyway.

But we might have to catch it in the outer widgets context method and not give it as a parameter in the onClick method. 

I am sorry but i’m not sure I understand this part. In essence I suppose I am asking is it possible to distinguish if a widget is locked from the context of a web plugin?

Userlevel 2
Badge +2

Just remove the parameter widgets in the onClick method and then it should work:

...
onClick: () => {
doStuff(widgets)
}
...

Since the widgets will not be given as a parameter to the onClick callback, but stay in the context of the getWidgetMenuItems context, you can still access the widgets there, if you do not put them as a parameter in the callback function.

Have fun!

Falk 

I appreciate the guidance @Falk Kühnel, howewer I am afraid the issue persists.

My updated code is here if it’s of interest:

https://github.com/Pheels/miro-underline-text/blob/master/index.html

 

Userlevel 2
Badge +2

Hi @olivermcpheely !

 

I just made a few changes, that should help you to continue.

https://github.com/Pheels/miro-underline-text/pull/1/commits/1419c26630b0844385467e9fc4cdab09840128e0

Best regards

Falk

Reply