Compile Error for Plugin Example

This forum is for all Flare issues not related to any of the other categories.
Post Reply
Evetsm
Propeller Head
Posts: 90
Joined: Wed Apr 30, 2014 8:32 am

Compile Error for Plugin Example

Post by Evetsm »

Hi,

I hope this is the right place to post this question.

I'm working through the Plugin API examples, focusing on "How To Add A Custom ToolBar." The tutorial says to add the following, which I did:

Code: Select all

public class ButtonCommand : ICommand
{
  public bool CanExecute(object parameter)
  {
    return true;
  }

  public void Execute(object parameter)
  {
    MessageBox.Show("I got pressed!");
  }
}
But when I try to build the project, I get the following error:

Code: Select all

'FlarePlugin1.ButtonCommand' does not implement interface member 'System.Windows.Input.ICommand.CanExecuteChanged'
I googled the error but I haven't been able to find a solution. Has anyone else encountered this error? If so I would be really grateful if you could tell me how to implement the member because my event skills are pretty small. :)

Thanks,
Steve
Paulie
Sr. Propeller Head
Posts: 140
Joined: Sun Mar 01, 2015 3:01 pm

Re: Compile Error for Plugin Example

Post by Paulie »

Hi there,

I had the same problem when I was creating my first plugin. In my case, adding the following empty event handler to the ButtonCommand : ICommand class fixed the problem and allowed the dll to compile:

Code: Select all

public  event EventHandler CanExecuteChanged
        {
            add
            {
                
            }
            remove
            {
               
            }
        }
"In an ideal world, software should be simple, well designed, and completely intuitive to end users. In the real world, good documentation is king."
Evetsm
Propeller Head
Posts: 90
Joined: Wed Apr 30, 2014 8:32 am

Re: Compile Error for Plugin Example

Post by Evetsm »

Paulie,

Thanks! That did the trick. I also added all the other numerous references to the project and it built with no errors.

Now I will try using the plugin.

Many thanks!
Steve
Evetsm
Propeller Head
Posts: 90
Joined: Wed Apr 30, 2014 8:32 am

Re: Compile Error for Plugin Example

Post by Evetsm »

paulie,

I installed the dll in the Plugins folder as instructed and started Flare. The plugin is enabled, but I don't see a new toolbar in the UI.

I called the CreateCustombar function from the Initialize function. I've attached the class file that I'm using. Could you please take a look and tell me what I'm doing wrong?

Thanks!
You do not have the required permissions to view the files attached to this post.
Paulie
Sr. Propeller Head
Posts: 140
Joined: Sun Mar 01, 2015 3:01 pm

Re: Compile Error for Plugin Example

Post by Paulie »

Hi there,

I had a quick look. Your toolbar menu displayed correctly. If you didn't see it, it could be because the toolbar was hidden (You can hide or show toolbars from the View > Toolbars menu in Flare).

I've made a couple of quick changes to also enable the ribbon. The code is below (note I did this pretty quickly, so there may well be some repetition/redundant code - however it does compile and function as expected).

Code: Select all

using B3.PluginAPIKit;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using System;

namespace FlarePlugin1
{
    public class Class1 : IPlugin
    {
        private IHost mHost;
        private bool mActivated;

        public bool IsActivated
        {
            get { return mActivated; }
        }

        public string GetVersion()
        {
            return "1.0";
        }

        public string GetAuthor()
        {
            return "Bob Smith";
        }

        public string GetDescription()
        {
            return "Displays a message box.";
        }

        public string GetName()
        {
            return "DemoPlugin";
        }

        public void Initialize(IHost host)
        {
            mHost = host;
            CreateCustombar();
            CreatePluginRibbon();
        }

        public void Execute()
        {
            mActivated = true;
            MessageBox.Show(GetName() + " activated!");


        }

        public void Stop()
        {
            MessageBox.Show(GetName() + " deactivated!");
            mHost.Dispose();
            mActivated = false;
        }

        private void CreateCustombar()
        {
            try
            {
                INavContext mNav = mHost.GetNavContext();
                ICustomToolBar toolBar = mNav.CreateCustomToolBar("My ToolBar");
                toolBar.AddButton("My Button", new ButtonCommand());
                toolBar.AddSeparator();
                toolBar.AddMenuButton(RibbonViewModel.MenuData);
  
            
            }
            catch (Exception e)
            {
                MessageBox.Show("Error creating custom toolbar." + e.Message);
            }

        }

        private void CreatePluginRibbon()
        {
            INavContext mNav = mHost.GetNavContext();
            IRibbon ribbon = mNav.GetRibbon();
            IRibbonTab tab = ribbon.AddNewRibbonTab("PluginTab", "P");
            IRibbonGroup group = tab.AddNewRibbonGroup("PluginGroup");
            System.Windows.Controls.Button searchAndHighlightButton = group.AddRibbonButton(PluginViewModel.SearchHighlight);
            IRibbonComboBox comboMenu = group.AddRibbonCombobox(PluginViewModel.Fonts);
        }

    }

    public class ButtonCommand : ICommand
    {
        public bool CanExecute(object parameter)
        {
            return true;
        }


        public event EventHandler CanExecuteChanged
        {
            add
            {

            }
            remove
            {

            }
        }

        public void Execute(object parameter)
        {
            MessageBox.Show("I got pressed!");
        }

    }

    public static class RibbonViewModel
    {
        private static String iconPath = "C:\\local-work\\images\\limelight-icon.png";
        private static RibbonMenuData _menuData;
        public static RibbonMenuData MenuData
        {
            get
            {
                if (_menuData == null)
                {
                    BitmapImage image = new BitmapImage(new Uri(iconPath));
                    _menuData = new RibbonMenuData()
                    {
                        Label = "My Menu",
                        SmallImage = image,
                        KeyTip = "D"
                    };

                    _menuData.ControlDataCollection.Add(new RibbonControlData()
                    {
                        MenuLabel = "item1"
                    });
                    _menuData.ControlDataCollection.Add(new RibbonControlData()
                    {
                        MenuLabel = "item2"
                    });
                }
                return _menuData;
            }
        }
    }

    public static class PluginViewModel
    {
        private static RibbonControlData _searchHighlight;
        private static RibbonMenuData _fonts;

        public static RibbonControlData SearchHighlight
        {
            get
            {
                if (_searchHighlight == null)
                {
                    _searchHighlight = new RibbonControlData()
                    {
                        Label = "Search and Highlight",
                        Command = new ButtonCommand(),
                        KeyTip = "S"
                    };
                }
                return _searchHighlight;
            }
        }

        public static RibbonMenuData Fonts
        {
            get
            {
                if (_fonts == null)
                {
                    BitmapImage image = new BitmapImage(new Uri("C:\\local-work\\images\\limelight-icon.png"));
                    _fonts = new RibbonMenuData()
                    {
                        Label = "My Fonts",
                        LargeImage = image
                    };
                    _fonts.ControlDataCollection.Add(new RibbonControlData()
                    {
                        Label = "Arial"
                    });
                    _fonts.ControlDataCollection.Add(new RibbonControlData()
                    {
                        Label = "Helvetica"
                    });
                    _fonts.ControlDataCollection.Add(new RibbonControlData()
                    {
                        Label = "Times New Roman"
                    });
                }
                return _fonts;
            }
        }
    }

}
"In an ideal world, software should be simple, well designed, and completely intuitive to end users. In the real world, good documentation is king."
Evetsm
Propeller Head
Posts: 90
Joined: Wed Apr 30, 2014 8:32 am

Re: Compile Error for Plugin Example

Post by Evetsm »

Thank you. I haven't implemented the changes you so kindly did because I first want to locate the new toolbar.

I'm a relatively new Flare user and under the View ribbon I did not see an option to show toolbars. Can you tell me (1) where the option is and (2) where in your UI you see the toolbar that my code created?

I have Flare v11.

Thanks
Paulie
Sr. Propeller Head
Posts: 140
Joined: Sun Mar 01, 2015 3:01 pm

Re: Compile Error for Plugin Example

Post by Paulie »

Hi there,

Here is where your tool bar displays in my UI:

Image

From your terminology above, the issue might be that you are currently using the Flare ribbon UI, rather than the older toolbar UI. Your code only implemented a toolbar item, rather than a ribbon item, so you would need to change to the toolbar UI to see your new toolbar.

To do this, you click: File > Options, then select Tool Strip from the Interface tab.
"In an ideal world, software should be simple, well designed, and completely intuitive to end users. In the real world, good documentation is king."
Evetsm
Propeller Head
Posts: 90
Joined: Wed Apr 30, 2014 8:32 am

Re: Compile Error for Plugin Example

Post by Evetsm »

(First, thanks for helping me along with this.)

Ah, that was indeed the problem.

According to what I read in the tutorial, clicking item 1 or item 2 is supposed to display a dialog that says "I got pressed!"

Is that the behavior in your UI? It is not working for me.

Thanks!
Evetsm
Propeller Head
Posts: 90
Joined: Wed Apr 30, 2014 8:32 am

Re: Compile Error for Plugin Example

Post by Evetsm »

Oh actually it's when the user clicks "My Button."

Ignorant question: How do I return to the Ribbon view from the older toolbar UI?

I'll try to figure out how to associate a command with the item 1 and item 2.

Thanks again!
Paulie
Sr. Propeller Head
Posts: 140
Joined: Sun Mar 01, 2015 3:01 pm

Re: Compile Error for Plugin Example

Post by Paulie »

I have had a look. Currently, there are no commands associated with the menu items, so when you click the menu items nothing happens.

Here is the code to rewire the menu items to use the same command as the button (obviously, for a real plugin you would probably want to create more than one command, but for testing purposes this will work fine).

Note: This is the code that was added: Command = new ButtonCommand()

Code: Select all

public static class RibbonViewModel
    {
        private static String iconPath = "C:\\Programming\\Icons\\Free Ones From Web\\IconBuffet Studio Suite\\Icons\\Kyoto Studio\\PNGs\\arrow-forward_32.png";
        private static RibbonMenuData _menuData;
        public static RibbonMenuData MenuData
        {
            get
            {
                if (_menuData == null)
                {
                    BitmapImage image = new BitmapImage(new Uri(iconPath));
                    _menuData = new RibbonMenuData()
                    {
                        Label = "My Menu",
                        SmallImage = image,
                        KeyTip = "D"
                    };

                    _menuData.ControlDataCollection.Add(new RibbonControlData()
                    {
                        MenuLabel = "item1",
                       Command = new ButtonCommand(),
                    });
                    _menuData.ControlDataCollection.Add(new RibbonControlData()
                    {
                        MenuLabel = "item2",
                        Command = new ButtonCommand(),
                    });
                }
                return _menuData;
            }
        }
"In an ideal world, software should be simple, well designed, and completely intuitive to end users. In the real world, good documentation is king."
Paulie
Sr. Propeller Head
Posts: 140
Joined: Sun Mar 01, 2015 3:01 pm

Re: Compile Error for Plugin Example

Post by Paulie »

And to get back to the ribbon view, use Tools > Options on the menu.
"In an ideal world, software should be simple, well designed, and completely intuitive to end users. In the real world, good documentation is king."
Evetsm
Propeller Head
Posts: 90
Joined: Wed Apr 30, 2014 8:32 am

Re: Compile Error for Plugin Example

Post by Evetsm »

Thanks, Paulie. I've really appreciated your assistance.
Post Reply