SORU
10 HAZİRAN 2010, PERŞEMBE


Visual Studio 2010 Plug-in Ekleyerek bir bağlam menüsü Çözüm Gezgini

Belirli bir dosya türü için Visual Studio 2010 solution explorer içerik menüsüne yeni bir seçenek eklemek istiyorum. Yani, örneğin, bir *sağ tıklayarak.cs dosyanın varolan bağlam menüsünü gösterecektir artı "yeni seçenek".

Kod gibi görünecektir; ve visual studio eklentileri geliştirmek için iyi bir başvuru için bir işaretçi aşk nasıl olacağını merak ediyorum. Görüyorum referanslar/öğreticiler bariz korkunç.

Teşekkürler!

CEVAP
14 HAZİRAN 2010, PAZARTESİ


Bana yaklaşık 5 saat bunu yapmak için aldı.

Orada 2 seçenek, Visual studio eklentisi (ya da paylaşılan Eklenti) vs Visual studio paketi.

Paket çok daha çok daha fazla kontrol sağlamak için karmaşık, ama çözüm Gezgini içerik menüsü için gerekli değildir.

Proje -^ yeni . Diğer Proje Türleri ->- ^Genişletebilme . Visual Studio eklentisi.

İşte-yürümek - Link

Ayrıca Bu bir Link takip ettim

Tavsiye ederim bırakın seçeneği eklemek için Araçlar menüsü kadar menü çalışma, ya da sağlamak için bir yere koymak bir Ayarları iletişim eğer bir yazma Aracı->seçenekleri sayfa.

İşte bağlantı kodu:

  _applicationObject = (DTE2)application;
        _addInInstance = (AddIn)addInInst;
        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;
            // get popUp command bars where commands will be registered.
            CommandBars cmdBars = (CommandBars)(_applicationObject.CommandBars);
            CommandBar vsBarItem = cmdBars["Item"]; //the pop up for clicking a project Item
            CommandBar vsBarWebItem = cmdBars["Web Item"];
            CommandBar vsBarMultiItem = cmdBars["Cross Project Multi Item"];
            CommandBar vsBarFolder = cmdBars["Folder"];
            CommandBar vsBarWebFolder = cmdBars["Web Folder"];
            CommandBar vsBarProject = cmdBars["Project"]; //the popUpMenu for right clicking a project
            CommandBar vsBarProjectNode = cmdBars["Project Node"];

            //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, "HintPaths", "HintPaths", "Executes the command for HintPaths", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported   (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                //Add a control for the command to the tools menu:
                if ((command != null) && (toolsPopup != null))
                {
                    //command.AddControl(toolsPopup.CommandBar, 1);
                    command.AddControl(vsBarProject); 
                }
            }
            catch (System.ArgumentException argEx)
            {
                System.Diagnostics.Debug.Write("Exception in HintPaths:"   argEx.ToString());
                //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.
            }
        }
    }

Bu kod, Kullanıcının seçtiği örnek bir proje olup olmadığını denetler:

  private Project GetProject()
    {
        if (_applicationObject.Solution == null || _applicationObject.Solution.Projects == null || _applicationObject.Solution.Projects.Count < 1)
            return null;
        if (_applicationObject.SelectedItems.Count == 1 && _applicationObject.SelectedItems.Item(1).Project != null)
            return _applicationObject.SelectedItems.Item(1).Project;
        return null;
    }

Kodunuzda belirli dize adları var ve ben bunu dün yaptım, henüz çok emin değilim unutmayın.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • efaustus9

    efaustus9

    16 HAZİRAN 2006
  • Jaclyn W

    Jaclyn W

    5 Mayıs 2006
  • Random Act of Kindness Video Contest

    Random Act o

    18 EYLÜL 2012