question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[QUESTION]: New toolbar button works only for new added components and not for existing ones

See original GitHub issue

Hi everybody, can somebody explain me please why when I create a new custom toolbar button this button shows only when I add a new component and not an existing one even this components are the same. I was thinking that might be something about the editor initiation that I’m not including. @artf What am I missing to make it work on init? Here is an example of how I’m adding the button.

const scriptTypesSupport = ['default','wrapper','text','textnode','image','video','svg','link'];
scriptTypesSupport && scriptTypesSupport.forEach(type => {
    const typeOpt = dc.getType(type).model;
    dc.addType(type, {
        model: {
            initToolbar() {
                typeOpt.prototype.initToolbar.apply(this, arguments);
                const tb = this.get('toolbar');
                const tbExists = tb.some(item => item.command === 'edit-component');
 
                if (!tbExists) {
                    tb.unshift({ // unshift to be the first and push to be the last
                        command: 'edit-component',
                        label: '<i class="fa fa-code"></i>',
                    });
                    this.set('toolbar', tb);
                }
            }
        }
    });
})

It works perfectly but like I said only for new components added and not for existing ones (example, if I init the editor with some code inside the gjs container the components won’t have this new option in the toolbar) Above you can see when I add a second link the toolbar have the new button (pencil) but the existing one doens’t. chrome-capture

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
Ju99ernautcommented, Sep 27, 2020

Probably the editor doesn’t change a component during runtime when it’s model is changed, so the component on the canvas was created before the model was modified therefore it wont show the changes to the toolbar.

1reaction
Ju99ernautcommented, Oct 1, 2020

I’ve gotten around this by loading the canvas after loading all components and component modifications, but I guess depending on storage setup running editor.load() might fix that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular2: Display different "toolbar" components depending ...
What I want to achieve is that the toolbar is displaying different components, depending on the component/view that is rendered in the content ......
Read more >
Customize the Quick Access Toolbar - Microsoft Support
The customizable Quick Access Toolbar contains a set of commands that are independent of the currently displayed tab on the ribbon. You can...
Read more >
IC Toolbar z-button handling - SAP Blogs
During the latest project I realized that there is already new possibility to add a logic for z-button handling in IC toolbar.
Read more >
How to Use Tool Bars (The Java™ Tutorials > Creating a GUI ...
Here is the code that adds the new components: //fourth button button = new JButton("Another button"); ... toolBar.add(button); //fifth component is NOT ......
Read more >
Add a button to the toolbar - Mozilla - MDN Web Docs
Toolbar buttons are one of the main UI components available to extensions. Toolbar buttons live in the main browser toolbar and contain an ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found