Community
Showing results for 
Search instead for 
Do you mean 
Reply

Sample Plugin to add menu item

Copper Super Contributor
Posts: 88
Country: USA

Sample Plugin to add menu item

I'm a newbie and want to create a Plugin for ACT!2011. I would like to have a downloadable code sample (in vb.NET) that I could test and compile into a Plugin. I'd like to have a sample to create a Tab with buttons, and sample code for a new Menu item.

 

I've looked at the "Samples" plugin download, but it is written in C#.

 

Any code samples and/or suggestions?

 

Thanks!

 

Kim Kamper

Bronze Super Contributor
Posts: 1,231
Country: USA

Re: Sample Plugin to add menu item

[ Edited ]

Kim,

Attached is a simple VB plugin to create a new menu item. Download, unzip and open it with Visual Studio 2008 or better. Before running this example you need to re-attach the ACT dll reference.

 

To add a tab page you can use the ACT SDK function AddTabToCurrentLayout.

 

Dim MyTabPage As System.Windows.Forms.TabPage = NewSystem.Windows.Forms.TabPage

HostApplication.UILayoutDesignerManager.AddTabToCurrentLayout(MyTabPage)

 

BTW- You should check out this web site to convert VB to c# and C# to VB.

http://www.developerfusion.com/tools/convert/csharp-to-vb/

 

Hope this helps

-- Jim Durkin

Copper Super Contributor
Posts: 88
Country: USA

Re: Sample Plugin to add menu item

Thanks, Jim, for the code.

 

How do I get a button on the Menu item to activate an external program?

 

Two more things:

 

1.   Would you have sample code to add a Tab to ACT!

2.   How do I add buttons, text fields, etc. to the Tab - do I use a Form control?

 

Sorry - very basic stuff to you - I'm learning...

 

Thanks!

 

Kim

 

Bronze Super Contributor
Posts: 1,231
Country: USA

Re: Sample Plugin to add menu item

I posted an example on how to add a tab to the contact details view in a new thread for better exposure

 

http://community.act.com/t5/Sage-ACT-Developer-s-Forum/Sample-Plugin-to-add-a-Tab/m-p/150248#M4541

 

-- Jim Durkin

Copper Super Contributor
Posts: 88
Country: USA

Re: Sample Plugin to add menu item

Jim:

 

Thank you! Your Plugin works great, and now I have a starting point to work with.

 

Kim

 

PS  Any recommendations for resources for developing Plugins?

 

Thanks!

New Member
Posts: 14
Country: Australia

Re: Sample Plugin to add menu item

Hi Guys,

 

Thanks for this. I have been playing around with both examples and they are a great starting point however I am having some trouble converting the tab example to c#. I used the site above to convert the code and have created a new c# class library but when I try to build I get a few error.

 

Mainly from....

ACTAPP.Explorer.CommandBarCollection

 

Throws the error - 

Error 4 Non-invocable member 'Act.UI.Core.Explorer.CommandBarCollection' cannot be used like a method. C:\Users\Sentinal\Documents\Visual Studio 2010\Projects\cTabLibrary\cTabLibrary\Class1.cs 134 33 cTabLibrary

Employee
Posts: 1,163
Country: USA

Re: Sample Plugin to add menu item

Most likely a syntax issues. Post the code segment that is throwing the error and I or someone else may be able to spot the problem.

Matthew Wood
Act! SDK Support
Community Moderator
New Member
Posts: 14
Country: Australia

Re: Sample Plugin to add menu item

[ Edited ]

Its calling it a few times however it is all relevent to adding an option to the menu bar. I dont really want to do this, I just want to add the tab to the contacts view and have therefore commented it all out.

 

I now have a project that compiles however when I try to load the plugin Act throws an error and says to restart. I dont suppose you have the Tab example in C# to put up?

 

If not I now have a class1.cs as follows

 

namespace cTabLibrary
{
    public class Class1 : IPlugin
    {

        //Reference to the ACT! Application
        internal ActApplication HostApplication;
        //Reference to the ACT! Framework
        internal Act.Framework.ActFramework HostFramework;
        // Our unique menu
        public const string Example_URN_ViewName = "act-ui://com.act/application/menu/tools/ACTTabPluginVB";
        // Out Tab Page
        private TabPage MyTabPage;

        public void OnLoad(ActApplication App)
        {
            //-----------------------------------------------------------
            // Store a reference to ActApplication and ActFramework
            //-----------------------------------------------------------
            this.HostApplication = App;
            this.HostFramework = App.ActFramework;

            //-----------------------------------------------------------
            // Add the HostApplication Logon and LogOff Events 
            //-----------------------------------------------------------
            HostApplication.AfterLogon += HostApplicationAfterLogon;
            HostApplication.BeforeLogoff += HostApplicationBeforeLogoff;
            HostApplication.CurrentViewChanged += HostApplication_CurrentViewChanged;
            // Public 

        }

        public void OnUnLoad()
        {
            // Not used in the examples
        }

        private void HostApplicationAfterLogon(object Sender, System.EventArgs e)
        {
            //------------------------------------------------
            // Add our menu under the tools menu
            //------------------------------------------------
            //this.AddMenuItem(Example_URN_ViewName, "ACTTabPluginVB...", new global::Act.UI.CommandHandler(OpenAbout), this.HostApplication, 0, true, null);

        }

        private void HostApplicationBeforeLogoff(object Sender, System.EventArgs e)
        {
            //--------------------------------------------------
            // Remove our menu item
            //--------------------------------------------------
            //this.RemoveMenuItem(Example_URN_ViewName, this.HostApplication);

        }

        private void HostApplication_CurrentViewChanged(object Sender, System.EventArgs e)
        {
            // What View are we on in ACT UI
            // If it is the Contact Details View then add the tab
            if (HostApplication.CurrentViewName == "Act.UI.IContactDetailView")
            {
                this.AddTab();
            }
        }

        private void AddTab()
        {
            // If MyTabPage is nothing then this is the first time her
            // We do not want to add MyTabPage each time 
            // the user navigates to the contact details view
            if (MyTabPage == null)
            {
                // First Time here
                MyTabPage = new TabPage();
                MyTabPage.Text = "MyTabPage";
                UserControl1 UserControl1 = new UserControl1(this.HostApplication);
                UserControl1.Dock = DockStyle.Fill;
                MyTabPage.Controls.Add(UserControl1);
                HostApplication.UILayoutDesignerManager.AddTabToCurrentLayout(MyTabPage);
            }

        }

 

 and a form setup like in the descipriton...

namespace cTabLibrary
{
    public partial class UserControl1 : Form
    {
        private ActApplication HostApplication;
        /// <summary>
        /// UserControl
        /// </summary>
        /// <param name="HostApplication"></param>
        public UserControl1(ActApplication HostApplication)
        {
            // This call is required by the Windows Form Designer.
            InitializeComponent();

            // Add any initialization after the InitializeComponent() call.

            // Store a reference of the HostApplication in our control
            this.HostApplication = HostApplication;

            //------------------------------------------------------
            // Add a handler so we are notified when the contact changes
            //------------------------------------------------------
            HostApplication.CurrentContactChanged += HostApplication_CurrentContactChanged;

            //------------------------------------------------------
            // Update our tab page when we are initilaized
            //------------------------------------------------------
            this.UpdateTabPage();

        }

        private void HostApplication_CurrentContactChanged(object sender, System.EventArgs e)
        {
            //------------------------------------------------------
            // The current contact changed
            //------------------------------------------------------
            this.UpdateTabPage();

        }

        private void UpdateTabPage()
        {
            //------------------------------------------------------
            // We need to update some data on our tab page
            //------------------------------------------------------
            this.Label1.Text = this.HostApplication.ApplicationState.CurrentContact.FullName.ToString() + " custom tab page";

        }

        private void Button1_Click(System.Object sender, System.EventArgs e)
        {
            //------------------------------------------------------
            // Notify the user that they can click on a button proficiently 
            //------------------------------------------------------
            MessageBox.Show("Thank You");

            //------------------------------------------------------
            // Just having some fun now
            //------------------------------------------------------
            this.Button2.Visible = true;
        }

        private void Button2_MouseEnter(System.Object sender, System.EventArgs e)
        {
            this.Button2.Visible = false;
        }

        private void Button2_MouseLeave(System.Object sender, System.EventArgs e)
        {
            this.Button2.Visible = true;
        }


        private void Button2_Click(System.Object sender, System.EventArgs e)
        {
        }

 
    }
}

 

 

Thanks

Sam

New Member
Posts: 14
Country: Australia

Re: Sample Plugin to add menu item

Sorry about dumping so much code. Ive done a bit more testing and the issue is with the form I have made. Adding a blank tab is working fine so I will keep trying.... 

New Member
Posts: 14
Country: Australia

Re: Sample Plugin to add menu item

Also, I have been looking through the act!2009 SDK documentation. In the customisation cookbook it references zip files containing VS solutions however they are nowhere to be found. 

 

This is from the SDK....

  1. Locate the SamplePlugin.zip file you downloaded with the SDK in the Customization Cookbook folder, and unzip it.
  2. Open the SamplePlugin.sln file in Microsoft Visual Studio 2005 or later.

There are a few entries like this in the SDK docs but no zip files and no solutions files to match.

 

Any ideas?