Exemple #1
0
        public static bool Execute(OpenedFileManager openedFileManager)
        {
            var accessor = new ObjectAccessor();
            var objects  = accessor.GetObjects();

            var strToUrn = new Dictionary <string, Urn>();
            var items    = new List <Common.ChooseItem.Item>();

            foreach (var obj in objects)
            {
                strToUrn[obj.fullName] = obj.urn;
                var searchTerms = CreateSearchTerms(obj);
                items.Add(new Common.ChooseItem.Item(obj.fullName, obj.type, searchTerms));
            }

            string title  = "Choose object on " + accessor.ServerName();
            var    choose = new Common.ChooseItem(items.ToArray(), title);

            if (choose.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return(false);
            }

            string result    = choose.Result();
            Urn    resultUrn = strToUrn[result];
            string body      = accessor.GetObjectText(resultUrn);

            openedFileManager.Open(accessor.ServerName(), result, resultUrn, body);
            return(true);
        }
Exemple #2
0
        static public bool Execute(DTE2 application, OpenedFileManager openedFileManager)
        {
            Document doc = application.ActiveDocument;

            if (doc == null)
            {
                return(false);
            }
            TextDocument textDoc = doc.Object("TextDocument") as TextDocument;

            if (textDoc == null)
            {
                return(false);
            }

            var    editPoint = textDoc.StartPoint.CreateEditPoint();
            string text      = editPoint.GetText(textDoc.EndPoint);

            text = text.Replace(Environment.NewLine, "\n");

            int from = textDoc.Selection.ActivePoint.AbsoluteCharOffset - 1;

            while (from > 0 && IsId(text[from - 1]))
            {
                from -= 1;
            }
            int to = from;

            while (to < text.Length && IsId(text[to]))
            {
                to += 1;
            }
            if (from == to)
            {
                return(false);
            }
            string name = text.Substring(from, to - from);

            string database = Common.Connection.GetActiveDatabase(text, from);

            var accessor = new ObjectAccessor();

            ObjectAccessor.ObjectInfo info = accessor.FindObject(name, database);
            if (info == null)
            {
                return(false);
            }

            string body = accessor.GetObjectText(info.urn);

            openedFileManager.Open(accessor.ServerName(), info.fullName, info.urn, body);
            return(true);
        }
Exemple #3
0
        /// <summary>Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.</summary>
        /// <param term='application'>Root object of the host application.</param>
        /// <param term='connectMode'>Describes how the Add-in is being loaded.</param>
        /// <param term='addInInst'>Object representing this Add-in.</param>
        /// <seealso class='IDTExtensibility2' />
        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            _applicationObject = (DTE2)application;
            _addInInstance     = (AddIn)addInInst;
            _openedFileManager = new OpenedFileManager(_applicationObject);
            if (connectMode == ext_ConnectMode.ext_cm_UISetup)
            {
                object [] contextGUIDS  = new object[] { };
                Commands2 commands      = (Commands2)_applicationObject.Commands;
                string    toolsMenuName = "Tools";

                //Place the command on the tools menu.
                //Find the MenuBar command bar, which is the top-level command bar holding all the main menu items:
                Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["MenuBar"];

                //Find the Tools command bar on the MenuBar command bar:
                CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName];
                CommandBarPopup   toolsPopup   = (CommandBarPopup)toolsControl;

                //This try/catch block can be duplicated if you wish to add multiple commands to be handled by your Add-in,
                //  just make sure you also update the QueryStatus/Exec method to include the new command names.
                try
                {
                    //Add a command to the Commands collection:
                    Command command = commands.AddNamedCommand2(_addInInstance,
                                                                "QuickOpen", "Quick Open", "Shows quick open dialog",
                                                                true, 25,
                                                                ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    command.Bindings = new object[] { "Global::alt+shift+o", "Global::ctrl+shift+d" };

                    //Add a control for the command to the tools menu:
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 1);
                    }
                }
                catch (System.ArgumentException)
                {
                    //If we are here, then the exception is probably because a command with that name
                    //  already exists. If so there is no need to recreate the command and we can
                    //  safely ignore the exception.
                }

                //This try/catch block can be duplicated if you wish to add multiple commands to be handled by your Add-in,
                //  just make sure you also update the QueryStatus/Exec method to include the new command names.
                try
                {
                    //Add a command to the Commands collection:
                    Command command = commands.AddNamedCommand2(_addInInstance,
                                                                "GoTo", "Go to definition", "Opens defenition of object under cursor",
                                                                true, 39,
                                                                ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    command.Bindings = "Global::f12";

                    //Add a control for the command to the tools menu:
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 2);
                    }
                }
                catch (System.ArgumentException)
                {
                    //If we are here, then the exception is probably because a command with that name
                    //  already exists. If so there is no need to recreate the command and we can
                    //  safely ignore the exception.
                }
            }
        }