Expose envdte dte in a ToolWindow1 button_click handler VS2022 #445
troglobytor
started this conversation in
Ideas
Replies: 3 comments 1 reply
-
Two methods illustrated, one static, one instance: // Guid...
public class ToolWindow1 : ToolWindowPane{
public static EnvDTE.DTE dte0;
public EnvDTE.DTE dte;
public ToolWindow1Control control;
// <summary>
// Initializes a new instance of the <see cref="ToolWindow1"/> class.
// </summary>
public ToolWindow1() : base(null){
ThreadHelper.ThrowIfNotOnUIThread();
this.Caption = "ToolWindow1";
//NO! dte at this point always null
//dte=(EnvDTE.DTE)GetService(typeof(EnvDTE.DTE));
// This is the user control hosted by the tool window; Note that, even if this class implements IDisposable,
// we are not calling Dispose on this object. This is because ToolWindowPane calls Dispose on
// the object returned by the Content property.
this.control = new ToolWindow1Control();
this.Content = control;
control.TW1 = this;
control.VisibilityChanged += Control_VisibilityChanged;
}
private void Control_VisibilityChanged(bool isVisible){
ThreadHelper.ThrowIfNotOnUIThread();
if (isVisible){
// Control is visible, perform any necessary actions
// Your code here...
if (this.dte == null) dte = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE));
if (dte0 == null) dte0 = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE));
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
Now how to get those "$(macros)" like a project's "(IntDir)"? |
Beta Was this translation helpful? Give feedback.
0 replies
-
I am getting the DTE object in the InitializeAsync of my package and hold on to it in the package.
Later when I need something from the DTE object then I use this reference to DTE. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I want to display various things in the ToolBoxWindow1 after a button is clicked that need a DTE dte instance accesible by the button_click handler. My first use was to show macros and expansions in the tool window for a project. None of the old examples seem to work or get the dte non null in the handler.
Beta Was this translation helpful? Give feedback.
All reactions