Ejemplo n.º 1
0
        public override void Run(dynamic declaration)
        {
            // note: does not work. http://stackoverflow.com/q/31954364/1188513
            //var app = Application.GetType();
            //app.InvokeMember(qualifiedMemberName.MemberName, BindingFlags.InvokeMethod | BindingFlags.Default, null, Application, null);
            //Application.Run(qualifiedMemberName.ToString());

            //note: this will work, but not implemented yet http://stackoverflow.com/questions/31954364#36889671
            //TaskItem taskitem = Application.CreateItem(OlItemType.olTaskItem);
            //taskitem.Subject = "Rubberduck";
            //taskitem.Body = qualifiedMemberName.MemberName;

            try
            {
                var               app = Application;
                var               exp = app.ActiveExplorer();
                CommandBar        cb  = exp.CommandBars.Add("RubberduckCallbackProxy", Temporary: true);
                CommandBarControl btn = cb.Controls.Add(MsoControlType.msoControlButton, 1);
                btn.OnAction = declaration.QualifiedName.ToString();
                btn.Execute();
                cb.Delete();
            }
            catch {
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Deletes the old toolbar.
        /// </summary>
        public static void DeleteOldToolbar(CommandBar toolbar)
        {
            //Globals.ThisAddIn.PushOldTemplateAndSetCustom();

            if (toolbar == null)
            {
                return;
            }

            foreach (CommandBarButton cmdButton in toolbar.Controls)
            {
                try
                {
                    cmdButton.Delete(false);
                }
                catch (Exception ex)
                {
                    LogHelper.DebugException("", ex);
                }
            }

            try
            {
                toolbar.Delete();
            }
            catch (Exception ex)
            {
                LogHelper.DebugException("", ex);
            }
            //Globals.ThisAddIn.PopOldTemplate();
        }
Ejemplo n.º 3
0
        void IDTExtensibility2.OnDisconnection(ext_DisconnectMode RemoveMode, ref Array custom)
        {
            Debug.WriteLine("OnDisconnection");

            if (RemoveMode == ext_DisconnectMode.ext_dm_UserClosed)
            {
                StringDictionary commandBarNames = new StringDictionary();

                // Remove all commands and collect their command bar names
                foreach (VsCommand vsCommand in this.vsCommands.Values)
                {
                    string commandBarName = vsCommand.CommandBarName;
                    if (!String.IsNullOrEmpty(commandBarName) && !commandBarNames.ContainsKey(commandBarName))
                    {
                        commandBarNames.Add(commandBarName, commandBarName);
                    }
                    RemoveIdeCommand(vsCommand);
                }

                // Delete the command bars which are empty now.
                foreach (string commandBarName in commandBarNames.Keys)
                {
                    CommandBar commandBar = GetCommandBar(commandBarName);
                    if (commandBar != null && !commandBar.BuiltIn && commandBar.Controls.Count == 0)
                    {
                        commandBar.Delete();
                        Debug.WriteLine("Deleting Command-Bars");
                    }
                }
            }
        }
Ejemplo n.º 4
0
 public void DeleteOldGitExtMainMenuBar()
 {
     try
     {
         CommandBarControl control =
             GetMenuBar()
             .Controls.Cast <CommandBarControl>()
             .FirstOrDefault(c => c.Caption == OldGitMainMenuName);
         if (control != null)
         {
             control.Delete(false);
         }
         control =
             GetMenuBar()
             .Controls.Cast <CommandBarControl>()
             .FirstOrDefault(c => c.Caption == OldGitExtMainMenuName);
         if (control != null)
         {
             control.Delete(false);
         }
         CommandBar cb =
             CommandBars.Cast <CommandBar>()
             .FirstOrDefault(c => c.Name == OldGitMainMenuName);
         if (cb != null && !cb.BuiltIn)
         {
             cb.Delete();
         }
     }
     catch (Exception)
     {
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Deletes the command.
        /// </summary>
        /// <param name="commandName">Name of the command.</param>
        protected void DeleteCommand(string commandName)
        {
            TraceService.WriteLine("CommandManager::DeleteCommand commandName=" + commandName);

            try
            {
                Commands2       commands       = (Commands2)this.VsInstance.ApplicationObject.Commands;
                CommandBarPopup toolsMenuPopUp = this.VsInstance.ApplicationObject.GetToolsMenuPopUp();

                CommandBar commandBar = null;

                for (int i = 1; i <= toolsMenuPopUp.CommandBar.Controls.Count; i++)
                {
                    if (toolsMenuPopUp.CommandBar.Controls[i].Caption == commandName)
                    {
                        TraceService.WriteLine("CommandManager::DeleteCommand commandFound in collection commandName=" + commandName);
                        CommandBarPopup commandBarPopup = (CommandBarPopup)toolsMenuPopUp.CommandBar.Controls[i];

                        commandBar = commandBarPopup.CommandBar;
                        break;
                    }
                }

                if (commandBar != null)
                {
                    TraceService.WriteLine("Command found and will be deleted ommandName=" + commandName);
                    commandBar.Delete();
                }
            }
            catch (Exception exception)
            {
                TraceService.WriteError("exception=" + exception.Message);
                TraceService.WriteError("stackTrace=" + exception.StackTrace);
            }
        }
Ejemplo n.º 6
0
        public void DeleteGitExtCommandBar()
        {
            CommandBar cb =
                CommandBars.Cast <CommandBar>()
                .FirstOrDefault(c => c.Name == PluginHelpers.GitCommandBarName);

            cb?.Delete();
        }
Ejemplo n.º 7
0
        public void DeleteGitExtCommandBar()
        {
            CommandBar cb =
                CommandBars.Cast <CommandBar>()
                .FirstOrDefault(c => c.Name == GitCommandBarName);

            if (cb != null)
            {
                cb.Delete();
            }
        }
Ejemplo n.º 8
0
        /// <summary>Implements the OnDisconnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being unloaded.</summary>
        /// <param term='disconnectMode'>Describes how the Add-in is being unloaded.</param>
        /// <param term='custom'>Array of parameters that are host application specific.</param>
        /// <seealso class='IDTExtensibility2' />
        public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array custom)
        {
            try
            {
                if ((disconnectMode == ext_DisconnectMode.ext_dm_HostShutdown) || (disconnectMode == ext_DisconnectMode.ext_dm_UserClosed))
                {
                    if (_debugHook != null)
                    {
                        _debugHook.UnHook();
                    }

                    AddinController.NotifyPluginUnloaded();

                    foreach (var control in _controlsCreated)
                    {
                        try
                        {
                            control.Delete(true);
                        }
                        catch
                        {
                        }
                    }

                    if (managerToolbar != null)
                    {
                        try
                        {
                            if (managerToolbar.Position != null)
                            {
                                _settingsManager.DsmSettings.ToolBarPosition = managerToolbar.Position.ToString();
                            }
                            _settingsManager.DsmSettings.ToolBarRowIndex = managerToolbar.RowIndex;
                            _settingsManager.DsmSettings.ToolBarVisible  = managerToolbar.Visible;
                            _settingsManager.DsmSettings.ToolBarTop      = managerToolbar.Top;
                            _settingsManager.DsmSettings.ToolBarLeft     = managerToolbar.Left;
                            //_settingsManager.DsmSettings.ToolBarWidth = managerToolbar.Width;
                            //_settingsManager.DsmSettings.ToolBarHeight = managerToolbar.Height;

                            _settingsManager.SaveSettings();
                        }
                        finally
                        {
                            managerToolbar.Delete();
                            managerToolbar = null;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _exceptionManager.HandleException(ex);
            }
        }
Ejemplo n.º 9
0
        public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array custom)
        {
            try
            {
                switch (disconnectMode)
                {
                case ext_DisconnectMode.ext_dm_HostShutdown:
                case ext_DisconnectMode.ext_dm_UserClosed:

                    // Delete buttons on built-in commandbars
                    if ((_myStandardCommandBarButton != null))
                    {
                        _myStandardCommandBarButton.Delete();
                    }

                    if ((_myCodeWindowCommandBarButton != null))
                    {
                        _myCodeWindowCommandBarButton.Delete();
                    }

                    if ((_myToolsCommandBarButton != null))
                    {
                        _myToolsCommandBarButton.Delete();
                    }

                    // Disconnect event handlers
                    _myToolBarButton          = null;
                    _myCommandBarPopup1Button = null;
                    _myCommandBarPopup2Button = null;

                    // Delete commandbars created by the add-in
                    if ((_myToolbar != null))
                    {
                        _myToolbar.Delete();
                    }

                    if ((_myCommandBarPopup1 != null))
                    {
                        _myCommandBarPopup1.Delete();
                    }

                    if ((_myCommandBarPopup2 != null))
                    {
                        _myCommandBarPopup2.Delete();
                    }

                    break;
                }
            }
            catch (System.Exception e)
            {
                System.Windows.Forms.MessageBox.Show(e.Message);
            }
        }
Ejemplo n.º 10
0
        /// <summary>This method destroys the command bar object added
        /// in the CreateCommandBar method.</summary>
        /// <param name="visioApplication">Current vision application.</param>
        /// <param name="commandBarName">Bar name to be removed.</param>
        public static void DestroyCommandBar(Application visioApplication, string commandBarName)
        {
            CommandBar commandBar = GetCommandBar(visioApplication, commandBarName);

            if (commandBar != null)
            {
                // Delete the command bar object.
                commandBar.Delete();
                Marshal.ReleaseComObject(commandBar);
            }
        }
Ejemplo n.º 11
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposing)
            {
                return;
            }

            _refreshButton.Click          -= _refreshButton_Click;
            _quickFixButton.Click         -= _quickFixButton_Click;
            _navigatePreviousButton.Click -= _navigatePreviousButton_Click;
            _navigateNextButton.Click     -= _navigateNextButton_Click;

            _toolbar.Delete();
        }
Ejemplo n.º 12
0
        public void Dispose()
        {
            if (_isDisposed)
            {
                return;
            }

            _state.StateChanged -= State_StateChanged;

            _refreshButton.Delete();
            _selectionButton.Delete();
            _statusButton.Delete();
            _commandbar.Delete();

            _isDisposed = true;
        }
Ejemplo n.º 13
0
        public void RegisterToolbar()
        {
            m_toolBar = null;

            // Remove the toolbar if it exists
            try
            {
                CommandBars bars = (CommandBars)m_applicationObject.CommandBars;
                m_toolBar = bars[TOOL_BAR_NAME];                // it seems this will never execute
                if (m_toolBar != null)
                {
                    m_toolBar.Delete();
                    m_toolBar = null;
                }
            } catch { }

            // Create the toolbar
            if (m_toolBar == null)
            {
                CommandBars bars = (CommandBars)m_applicationObject.CommandBars;
                m_toolBar = bars.Add(TOOL_BAR_NAME, MsoBarPosition.msoBarTop, System.Type.Missing, true);

                // Load saved toolbar settings
                m_toolBar.Visible  = m_addInSettings.ToolBarVisible;
                m_toolBar.Position = m_addInSettings.ToolBarPosition;
                if (m_addInSettings.ToolBarTop.HasValue)
                {
                    m_toolBar.Top = m_addInSettings.ToolBarTop.Value;
                }
                if (m_addInSettings.ToolBarLeft.HasValue)
                {
                    m_toolBar.Left = m_addInSettings.ToolBarLeft.Value;
                }
                if (m_addInSettings.ToolBarRowIndex.HasValue)
                {
                    m_toolBar.RowIndex = m_addInSettings.ToolBarRowIndex.Value;
                }
            }

            // Add the buttons to the toolbar
            foreach (AddInCommandBase cmd in m_commands)
            {
                cmd.InitToolbars(m_toolBar);
            }
        }
Ejemplo n.º 14
0
        public void Dispose()
        {
            if (_isDisposed)
            {
                return;
            }

            _state.StateChanged -= State_StateChanged;

            _sinks.ProjectRemoved     -= ProjectRemoved;
            _sinks.ComponentActivated -= ComponentActivated;
            _sinks.ComponentSelected  -= ComponentSelected;

            _refreshButton.Delete();
            _selectionButton.Delete();
            _statusButton.Delete();
            _commandbar.Delete();

            _isDisposed = true;
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Releases unmanaged resources help by the event sink.
        /// </summary>
        public void Dispose()
        {
            foreach (Event e in _events)
            {
                e.Delete();
                Marshal.ReleaseComObject(e);
            }

            _events = null;


            string     commandBarName = Resources.GetString(ResourceTokens.CommandBarName);
            CommandBar commandBar     = VisioUtils.GetCommandBar(Application, commandBarName);

            if (commandBar != null)
            {
                commandBar.Delete();
                Marshal.ReleaseComObject(_exportXMLButton);
                Marshal.ReleaseComObject(_validateButton);

                _validateButton  = null;
                _exportXMLButton = null;
            }
        }
Ejemplo n.º 16
0
        void IDTExtensibility2.OnConnection(object oApplication, Extensibility.ext_ConnectMode cmConnectMode, object oAddInInstance, ref System.Array arrCustom)
        {
            _pApplication   = ( _DTE )oApplication;
            _pAddInInstance = (EnvDTE.AddIn)oAddInInstance;

            _pf         = new ProfilerForm();
            _pf.Owner   = null;
            _pf.Closed += new EventHandler(_pf_Closed);

            // Hook up to run events
            Command cmdDebug;

            cmdDebug         = _pApplication.Commands.Item("Debug.Start", 1);
            _cmdevDebugStart = _pApplication.Events.get_CommandEvents(cmdDebug.Guid, cmdDebug.ID);
            _cmdevDebugStart.BeforeExecute += new EnvDTE._dispCommandEvents_BeforeExecuteEventHandler(OnBeforeRun);
            _cmdevDebugStart.AfterExecute  += new EnvDTE._dispCommandEvents_AfterExecuteEventHandler(OnAfterRun);

            cmdDebug           = _pApplication.Commands.Item("Debug.StartWithoutDebugging", 1);
            _cmdevNoDebugStart = _pApplication.Events.get_CommandEvents(cmdDebug.Guid, cmdDebug.ID);
            _cmdevNoDebugStart.BeforeExecute += new EnvDTE._dispCommandEvents_BeforeExecuteEventHandler(OnBeforeRun);
            _cmdevNoDebugStart.AfterExecute  += new EnvDTE._dispCommandEvents_AfterExecuteEventHandler(OnAfterRun);

            if (cmConnectMode == Extensibility.ext_ConnectMode.ext_cm_UISetup)
            {
                object[] contextGUIDS = new object[] { };
                foreach (Command cmd in _pApplication.Commands)
                {
                    try
                    {
                        if (cmd.Name != null && cmd.Name.StartsWith("NProf.Connect"))
                        {
                            cmd.Delete();
                        }
                    }
                    catch (Exception)
                    {
                    }
                }

                try
                {
                    CommandBar barNProf = _pApplication.CommandBars["nprof Profiling"];
                    if (barNProf != null)
                    {
                        barNProf.Delete();
                    }
                }
                catch (Exception)
                {
                }

                Command command = _pApplication.Commands.AddNamedCommand(
                    _pAddInInstance,
                    "Enable",
                    "Enable nprof",
                    "Toggle nprof integration",
                    true,
                    0,
                    ref contextGUIDS,
                    (int)vsCommandStatus.vsCommandStatusUnsupported);

                CommandBar barTools = ( CommandBar )_pApplication.CommandBars["Tools"];
                CommandBar barMenu  = ( CommandBar )_pApplication.Commands.AddCommandBar("nprof Profiling", vsCommandBarType.vsCommandBarTypeMenu, barTools, 1);

                CommandBarControl cbc = command.AddControl(barMenu, 1);
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Call VBA script from an Outlook application.
        /// </summary>
        /// <param name="processName">Name of the process being executed</param>
        /// <param name="officeAppName">One of the office app names</param>
        /// <param name="filePath">File path with the VBA script to be executed</param>
        /// <param name="macroName">VBA script name with module/procedure name</param>
        /// <param name="showAlerts">Boolean status to show alerts on open application</param>
        /// <param name="visibleApp">Boolean status to show open application</param>
        /// <param name="saveFile">Boolean status to save or not the file</param>
        /// <param name="stw">Stream writer object to output message to stream buffer</param>
        /// <returns>Returned string from VBA Main Function</returns>
        private static string _RunVBAonOutlook(string processName, string officeAppName, string filePath, string macroName, bool showAlerts = false, bool visibleApp = false, bool saveFile = false, StreamWriter stw = null)
        {
            Outlook.Application _otApp = new Outlook.Application();

            if (_otApp == null)
            {
                throw new ApplicationException("Outlook could not be started. Check if Office Outlook is properly installed in your machine/server. If the error persists, contact XPress robot developers and show a printscreen of this log.");
            }
            else
            {
                string message = DateTime.Now + " [INFO] " + officeAppName + " opened successfully!";
                if (stw != null)
                {
                    stw.WriteLine(message + "\n\r");
                }
                Console.WriteLine(message);

                message = DateTime.Now + " [INFO] " + processName + " is running at " + officeAppName + "...";
                if (stw != null)
                {
                    stw.WriteLine(message + "\n\r");
                }
                Console.WriteLine(message);

                Outlook.MailItem _otSI;
                // Start outlook and mailItem
                if (filePath != null)
                {
                    _otSI = _otApp.Session.OpenSharedItem(filePath) as Outlook.MailItem;
                }
                else
                {
                    _otSI = _otApp.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem;
                }

                if (visibleApp)
                {
                    _otSI.Display();
                }

                string _result = null;
                // Run the macros by supplying the necessary arguments
                // @Read: https://stackoverflow.com/questions/50878070/execute-vba-outlook-macro-from-powershell-or-c-sharp-console-app
                try
                {
                    // TODO: Test this workaround to run macros on outlook
                    Outlook.Explorer  _otExp = _otApp.ActiveExplorer();
                    CommandBar        _otCb  = _otExp.CommandBars.Add(macroName + "Proxy", Temporary: true);
                    CommandBarControl _otBtn = _otCb.Controls.Add(MsoControlType.msoControlButton, 1);
                    _otBtn.OnAction = macroName;
                    _otBtn.Execute();
                    _otCb.Delete();
                    ObjectService.ReleaseObject(_otCb);
                    ObjectService.ReleaseObject(_otExp);
                    _result = " [INFO] " + officeAppName + " script executed. Check manually if it was executed successfully.";
                }
                catch (Exception)
                {
                    _result = "ERROR | Something wrong in the " + officeAppName + " script happened. Contact XPress robot developers and show a printscreen of this log.";
                }


                if (filePath != null)
                {
                    // Clean-up: Close the mail item
                    if (!saveFile)
                    {
                        _otSI.Close(Outlook.OlInspectorClose.olDiscard);
                    }
                    else
                    {
                        _otSI.Close(Outlook.OlInspectorClose.olSave);
                    }
                    ObjectService.ReleaseObject(_otSI);
                }

                // Clean-up: Close the excel application
                _otApp.Quit();
                ObjectService.ReleaseObject(_otApp);

                return(_result);
            }
        }
Ejemplo n.º 18
0
 public void Delete()
 {
     _bar.Delete();
 }