Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TruffleMenu"/> class.
        /// Adds our command handlers for menu (commands must exist in the command table file)
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        private TruffleMenu(Package package)
        {
            if (package == null)
            {
                throw new ArgumentNullException("package");
            }

            this.package = (TrufflePackage)package;

            compile = this.createMenuItem(CompileCommandId, this.CompileCallback);
            migrate = this.createMenuItem(MigrateCommandId, this.MigrateCallback);
            test    = this.createMenuItem(TestCommandId, this.TestCallback);

            initializeProject = this.createMenuItem(InitializeProjectId, this.InitializeProjectCallback);

            installTruffle = this.createMenuItem(InstallTruffleId, this.InstallTruffleCallback);
            installTestRPC = this.createMenuItem(InstallTestRPCId, this.InstallTestRPCCallback);

            startTestRPC = this.createMenuItem(StartTestRPCId, this.StartTestRPCCallback);
            stopTestRPC  = this.createMenuItem(StopTestRPCId, this.StopTestRPCCallback);

            about = this.createMenuItem(AboutCommandId, this.ShowAboutCallback);

            // Add items to project only menus list
            projectOnlyMenuItems.Add(compile);
            projectOnlyMenuItems.Add(migrate);
            projectOnlyMenuItems.Add(test);

            ((TrufflePackage)this.package).OnOpen  += HandleProjectEnvironmentChange;
            ((TrufflePackage)this.package).OnClose += HandleProjectEnvironmentChange;
        }
Exemple #2
0
        private void HandleProjectEnvironmentChange()
        {
            TrufflePackage package = ((TrufflePackage)this.package);

            // If we're not in a solution, hide everything.
            if (package.InSolution == false)
            {
                allMenuItems.ForEach(delegate(OleMenuCommand menuItem)
                {
                    menuItem.Visible = false;
                });

                return;
            }

            // We're in a solution. Now check environment related items.
            allMenuItems.ForEach(delegate(OleMenuCommand menuItem)
            {
                bool isProjectMenuItem = projectOnlyMenuItems.Contains(menuItem);

                if (menuItem == installTruffle)
                {
                    menuItem.Visible = !package.TruffleInstalled;
                }
                else if (menuItem == installTestRPC)
                {
                    // menuItem.Visible = !package.TestRPCInstalled;
                    menuItem.Visible = false; // TestRPC is a dependency of Truffle. TODO: Remove this item.
                }
                else if (menuItem == startTestRPC)
                {
                    menuItem.Visible = package.TestRPCInstalled && !package.CheckTestRPCRunning();
                }
                else if (menuItem == stopTestRPC)
                {
                    menuItem.Visible = package.TestRPCInstalled && package.CheckTestRPCRunning();
                }
                else if (menuItem == initializeProject)
                {
                    menuItem.Visible = package.TruffleInstalled && !package.TruffleProjectInitialized;
                }
                else
                {
                    menuItem.Visible = true;
                }


                if (isProjectMenuItem == true)
                {
                    menuItem.Enabled = package.TruffleInstalled && package.TruffleProjectInitialized;
                }
                else
                {
                    menuItem.Enabled = true;
                }
            });
        }