How to activate the window that comes with idea through code? - intellij-plugin

I want to develop a plugin that prints in the console window, but I don't want to customize the Tool Window component。
This is how I currently do it:
ToolWindow toolWindow = ToolWindowManager.getInstance(e.getProject()).getToolWindow("Run");
toolWindow.show();
ContentManager contentManager = toolWindow.getContentManager();
ConsoleView consoleView = TextConsoleBuilderFactory.getInstance().createBuilder(e.getProject()).getConsole();
Content content = contentManager.getFactory().createContent(consoleView.getComponent(), "Generator", false);
contentManager.addContent(content );
contentManager.setSelectedContent(content);
consoleView.print(text, ConsoleViewContentType.NORMAL_OUTPUT);
consoleView.scrollTo(consoleView.getContentSize()-1);
But I found that if the window is not activated, the getToolWindow method gets null。
Is it possible to activate the window directly by means of code, rather than by activate it from the View -> Tool Windows menu?

Related

VSCT: Place Search Textbox below the toolwindow toolbar

I have made a toolbar that has a Search Textbox, using the visual studio built in search for the toolwindowpane: https://learn.microsoft.com/pt-pt/previous-versions/visualstudio/visual-studio-2015/extensibility/adding-search-to-a-tool-window?view=vs-2015&redirectedfrom=MSDN
That is working just fine right now after overriding the methods, however i also added a toolbar to the toolwindow from the vsct file, however it is positioning the search and the toolbar in the same row:
Is there any way to position the search bar underneath the toolbar just like the solution explorer in visual studio? If not, is there a way to decrease the toolbar size so it uses the minimum space so it doesn't look weird like in the picture?
Thank you.
EDIT: Constructor of the class that inherits ToolWindowPane:
public CpcObjectsWindow() : base(null)
{
this.Caption = "CPC Objects";
// 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.Content = new CpcObjectsWindowControl();
this.ToolBar = new CommandID(new Guid(CpcExtensionPackage.guidCpcExtensionPackageCmdSet), CpcExtensionPackage.cpcObjectsToolbar);
this.ToolBarLocation = (int)VSTWT_LOCATION.VSTWT_TOP;
}
I tried to add search to a tool window , a search control appears at the top of the tool window.
I tried to search form the ToolWindowPane Class but there is not any property can set the size of search bar. I think that you can submit a feature request on DC.

How to make "Browse/save file as" dialog show over NSMainMenuWindowLevel

I had the need to create a window so it covers the menubar at top and the dock at bottom. So I had to [NSWindow setLevel:NSMainMenuWindowLevel+1] (if i did just NSMainMenuWindowLevel some of the corner items in the top right of the menubar would still show over my window so I had to go +1).
So now the issue is, a user right clicks in my window (which is a canvas drawing of an image) and then they select "save as", at this point I pop open the "Save as" dialog, but it is showing behind my window. Is there anyway to like find that just opened dialog window with objc and set its level to be above NSMainMenuWindowLevel+1?
Like is there anyway to make this panel open higher then this level:
var NSSavePanel = objc_getClass('NSSavePanel');
var savePanel = sel_registerName('savePanel');
var aSavePanel = objc_msgSend(NSSavePanel, savePanel);
var runModal = sel_registerName('runModal')
Thanks
You have to defer the setting of the save panel's level until after the window is showing, which is tricky. You can do something like this (in Objective-C) before the call to -runModal:
dispatch_async(dispatch_get_main_queue(), ^{
[[NSApp modalWindow] setLevel:NSMainMenuWindowLevel+1];
});
If you can't use GCD, you can use -performSelector:withObject:afterDelay: with a 0 delay. You'll have to use the selector of a method of your own. (You can't use #selector(setLevel:) because that takes a scalar, not an object, as its parameter.)

Safari Extension: window.open(...) doesn't work sometimes?

I have an injected stylesheet that calls a popup with window...open() on two occasions. One when the user clicks an HTML button, and two, when a user clicks on a context menu item. To listen for the context menu item, I need to add a listener on the injected script like so
safari.self.addEventListener("message", messageCallBack, false); // Message comes from global.html when context menu item is clicked
And the following callback
function messageCallBack(msgEvent) {
...
window.open(...)
...
}
For some reason, the popup works when the button calls window.open, but NOT when the message callback calls window.open. I'm assuming it maybe have something to do with the window object.
I suspect this is due to restrictions on window.open designed to combat pop-up ads. This means it will only work in response to a click event.
To get around this, I would recommend you open the new window from your global page using the safari.application API:
safari.application.openBrowserWindow();
safari.application.activeBrowserWindow.activeTab.url = '...';
You can also open new tabs with:
safari.application.activeBrowserWindow.openTab('foreground').url = '...';
To achieve this, you may need to send a message from your injected script to the global page.

Get the visibility status of a toolbar according to Customize perspective dialog in Eclipse

I'm working on a plug-in, which contributes to the toolbar. The toolbar is listed in the Customize perstpective dialog. When I uncheck the check-box, the toolbar disappears as expected. But when the toolbar is updated from my code (using the toolbar manager), it gets displayed again. I need to get somehow the visibility status from code in order to prevent the toolbar from beeing updated when disabled.
Do you anybody have any idea, where the Customize perspective dialog stores the visibility status of menus and toolbars and how to get it from code, please?
You can get information by item ID this way:
private static boolean isToolbarItemVisible(String id){
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
return !((WorkbenchPage) workbenchWindow.getActivePage()).getHiddenItems().contains((ModeledPageLayout.HIDDEN_TOOLBAR_PREFIX + id + ","));
}

how to get (ScriptObject)HtmlPage.Window.GetProperty("Xrm") in silverlight which was embedded in html/javascript showModalDialog

Hi In CRM2011 I created custom button in form. On click of that button it opens javascript modal dialog. This modal dialog calls html where silverlight app is embedded. So my question i s how can I get following information. If silverlight app is in form we may easily get following values but my silver light app opens in modal dialog.
var xrmProperty = (ScriptObject)HtmlPage.Window.GetProperty("Xrm");
You want to talk to the opener. For example, in JavaScript you'd call:
window.opener.Xrm.Page.getAttribute('cei_name').getValue()
to get the value of the "cei_name" attribute on the form.
Try Following code
dynamic xrmnew = (ScriptObject)HtmlPage.Window.GetProperty("Xrm");
if (xrmnew == null)
{
HtmlWindow parentWindow = HtmlPage.Window.GetProperty("parent") as HtmlWindow;
xrmnew = (ScriptObject)parentWindow.GetProperty("Xrm");
}
Guid Id = new Guid(xrmnew.Page.data.entity.getId());