Simple Visual Studio Add in
Along the way to the office, I am curious about visual studio add in , so i try to make and find the useful Link resources about this, one of them is mztools.com which make the mztool that i mention on previous post.
so just a straight and simple one, I would like to open the active window on Windows Explorer.Actually I have add a form and combo box and it will list all the file in current solution, but apparently the IDE hang every time the form load during adding the combobox item. some body suggest using threading. now I haven't got quite far. but it's the power of extensibility that make us does not do the repetitive task.
To create one just new project->other->addin . and then follow the wizard and choose the option as you needed.
I add another form
open the connect.cs that supplied for you.this is the main process goes to
every time your add in is clicked it will trigger the exec event.
the onconnection is the event usually where you want to change the icon.see the integer 100? that's the default icon , to get the complete listing i've to download the working with visual studio ebooks, which i haven't done so.
Command command = commands.AddNamedCommand2(_addInInstance, "CiptoAddin", "CiptoAddin", "Executes the command for CiptoAddin", true, 100
put this code before the handled, this variable name already implies it's usage...
Connect.cs
1: public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
2: { 3: handled = false;
4: if(executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
5: { 6: if(commandName == "CiptoAddin.Connect.CiptoAddin")
7: { 8: FrmOpen frmopen = new FrmOpen();
9: frmopen.m_applicationobject = (DTE)this._applicationObject;
10: frmopen.Show();
11: handled = true;
12: return;
13: }
14: }
15: }
Form1.cs
1: public partial class FrmOpen : Form
2: { 3: public DTE m_applicationobject { get; set; } 4: public FrmOpen()
5: { 6: InitializeComponent();
7:
8: }
9:
10: private void button1_Click(object sender, EventArgs e)
11: { 12: Window active = m_applicationobject.ActiveWindow;
13: System.Diagnostics.Process.Start(active.Document.Path);
14: }
15: private void FrmOpen_Activated(object sender, EventArgs e)
16: { 17: //get the current solution opened
18: //Solution2 temp = (Solution2)m_applicationobject.Solution;
19: //foreach (Project objproject in temp.Projects)
20: //{ 21: // foreach (ProjectItem item in objproject.ProjectItems)
22: // { 23: // //if(cmbfile.InvokeRequired)
24: // if (item != null)
25: // cmbfile.Items.Add(item.Name.ToString() + " " + item.Document.Path.ToString());
26:
27: // }
28: }
29: }
30: }
Now the form activated run just once, after that the IDE will hang every time on the loop so I just uncommented it, but it's the way to iterate it