Is it possible to make subfolders in the "Show View" menu? - eclipse

Let's say I have some view called "My View".
I know I can create a category, "My Category", and place my view inside it.
I'd like to create a subfolder/category inside "My Category" called "Sub Folder" and place my view inside it.
Then the view would be found through the "Show View" popup as follows:
My Category -> Sub Folder -> My View
I know you can do this with exports/imports, but it doesn't seem like you can with views.
Here is a sample plugin.xml
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.views">
<category
name="My Category"
id="My_Category">
</category>
<category
id="My_Sub_Folder"
name="Sub Folder"
parentCategory="My_Category">
</category>
<view
name="My View"
icon="icons/sample.gif"
category="My_Sub_Folder"
class="sample_plugin.views.SampleView"
id="sample_plugin.views.SampleView">
</view>
</extension>
</plugin>
However, when I use the plugin.xml above, the view category does not show up and the view is found in the "Other" category. If I change the view category back to "My_Category", the view shows up in the parent category.

(revised answer)
You can set up a parent category hierarchy, but the Show View menu will not respect this.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=92894
So the answer is effectively no.
Here is the documentation on setting up the useless parent category:
http://help.eclipse.org/helios/topic/org.eclipse.platform.doc.isv/reference/extension-points/org_eclipse_ui_views.html

it could be that your using package explorer. Switch to Navigator (window-->show view ---> other -------> Navigator)
now you can see the project as folders instead of packages.

Related

How does one set the Focus on a custom Tab in the Backstage View

PLATFORM: Office 2019
APPLICATION: Microsoft Word
We have created a custom tab that appears in the Backstage View.
However, we would like to set the focus on this tab when the Backstage View is opened. The tab appears exactly where we would like it and works correctly, but we would like it to be selected.
WHAT I'VE TRIED
public void OnShow(object contextObject)
{
try
{
this.ribbon.ActivateTab("OurCustomTab");
}
catch(Exception e )
{
MessageBox.Show(e.ToString());
}
}
The code above returns a message stating the value I've provided is out of range.
What I need to know is how do I find the control Id of a custom tab.
CUSTOM XML
<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
<commands>
<command idMso="FileSave" onAction="FileSaveOverride"/>
<command idMso="FileSaveAs" onAction="FileSaveAsOverride"/>
</commands>
<backstage onShow="OnShow">
<tab id="OurCustomTab" label="CUSTOM" insertBeforeMso="TabInfo" title="OUR TAB" tag ="OUR" getVisible="IsOURTabVisible" >
<firstColumn>
<group id="OURSave" label="Save" helperText="Performs Save operation for OUR documents">
<primaryItem>
<button id="OurCustomSaveButton" label="Save" imageMso="FileSave" isDefinitive="true" onAction="CustomSaveOverride" />
</primaryItem>
</group>
<group id="OurSaveAs" label="Save As" helperText="Performs Save As operation for OUR documents">
<primaryItem>
<button id="OurCustomSaveAsButton" label="Save As" imageMso="FileSaveAs" isDefinitive="true" onAction="CustomSaveAsOverride" />
</primaryItem>
</group>
</firstColumn>
</tab>
</backstage>
</customUI>
It looks like ActivateTab will not work in this instance.
Microsoft Active Accessibility and Microsoft UI Automation won't work here either. It looks like the controls are not loaded at the time that the "OnShow" callback is called.
How I tested this was by running a separate executable file that was able to set the focus on a custom tab in the Backstage View. The identical code would not work within the VSTO Add-in.
Since running an separate executable is outside the scope of our project I simply resorted to using SendKeys; not my favorite choice, but it works.

Why can't I access my application delegate from a ViewController?

In my app, I would like to access delegate methods from a View Controller, but when I try to access it this way :
let appDelegate = NSApplication.sharedApplication().delegate
I am getting nil, what could cause this ?
EDIT WITH ADDITIONAL INFO :
When I created the app, I did an error as I didn't choose to use storyboards, but when I needed them, I just added a storyboard file and defined it as the main interface, like this :
I believe my issue could come from here, could it be possible for the interface to be shown but not linked properly to the NSApplication (and so to the delegate) ?
If yes, how could I solve it ?
Thank you.
In your storyboard, make sure that App Delegate's custom class (in the Identity Inspector) is set to your delegate class.
Update
If you have just created a new storyboard, it will be empty. AFAIK there are no "standard" ways of creating the application scene. You have to copy it from another storyboard (they are just XMLs after all).
The simplest way would be creating a new project with Use Storyboard enabled, then right-click on your auto generated Main.storyboard, choose Open As ➔ Source Code. After that, copy the <!--Application--> part to your empty Storyboard.storyboard. Don't for get to grab the header and footer part of it, too. Below is just an example.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="7706" systemVersion="14D136" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="7706"/>
</dependencies>
<scenes>
<!--Application-->
<!-- your copied content -->
</scenes>
</document>
Finally, right-click on your Storyboard.storyboard and choose Open As ➔ Interface Builder - Storyboard to resume the normal design view.

Add dynamic team actions in Eclipse

I am developing an Eclipse Team Plugin. I want to contribute the Team popup menu, so I have defined an action in my plugin.xml file:
<plugin>
<extension point="org.eclipse.ui.popupMenus">
<objectContribution
adaptable="true"
id="com.myexample.ui.ResourceContributions"
objectClass="org.eclipse.core.resources.IResource">
<action
class="com.myexample.ui.actions.MyAction"
id="com.myexample.ui.actions.MyActionId"
label="Execute action" />
</objectContribution>
</extension
</plugin>
Also have an implementation for the action:
public class MyAction extends TeamAction {
...
}
At this point all is ok, my action is shown and I can execute it.
Now, what I want is to change the text of the action dynamically, when the selection changes, depending in some properties of the selected objects.
Is this possible? How could I do it? Could I do it programmatically?
Here is what I would try:
Override TeamAction.selectionChanged(IAction action, ISelection selection) in your MyAction class
Invoke IAction.setText(String text) in your overridden method.

Custom Eclipse perspective, with initially invisble view stacked to editor area

I got a custom perspecitve with an editor area declared in plugin.xml only.
In addtion, I got a custom view, that is opened programatically. I want to stack this view with the editor area.
If I set it in the perspective extension as initially visible, everything works fine.
<view
id="my.viewID"
minimized="false"
relationship="stack"
relative="org.eclipse.ui.editorss"
visible="false">
</view>
However, if I set visible="false", and use the following code to open it programmatically, it always appears in the bottom area stacked with the ConsoleView.
IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.showView("my.viewID", "secondID", IWorkbenchPage.VIEW_ACTIVATE);
Does anybody know how to have an initially invisble view stacked to the editor area when opened programmatically?
I already tried the recommendations given in this thread but without any success: Eclipse RCP - relative field of view perspective extension not working
Sometimes you can't imagine how simple solutions can be:
Simply adding :* at the end of the view id in the plugin.xml solved this issue:
<view
id="my.viewID:*"
minimized="false"
relationship="stack"
relative="org.eclipse.ui.editorss"
visible="false">
</view>
Unbelievable how many times you find people saying this would not be possible at all...
Well, I've read most stuff about placing a view over the editor area, and none worked. The Answer 1 above causes the plugin.xml to have warnings. In Eclipse Luna, this works however when your perspective is initialized:
public void createInitialLayout(IPageLayout layout) {
if ( layout instanceof org.eclipse.ui.internal.e4.compatibility.ModeledPageLayout ) {
org.eclipse.ui.internal.e4.compatibility.ModeledPageLayout layout4=(org.eclipse.ui.internal.e4.compatibility.ModeledPageLayout)layout;
layout4.stackView(ID+":*",layout.getEditorArea(),false);
}
...
The code above adds a view with "ID" that is a multiple view, added to the stack of editors hidden (last parameter is false="not visible").
It may also work with other Eclipse versions, but I haven't tried it.
Good luck!
The simplest way to achieve this is to add the view to the perspective extensions like this:
<extension point="org.eclipse.ui.perspectiveExtensions">
<perspectiveExtension targetID="org.my.perspective">
<view id="org.my.view"
minimized="false"
relationship="stack"
relative="org.eclipse.ui.editorss"
visible="false">
</view>
</perspectiveExtension>
</extension>
and then calling IWorkbenchPage::showView() without a secondary ID, i.e. only with one argument like this:
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("org.my.view");

Removing a view from Eclipse Window -> Show views

We have an application in which some views only work when attached to certain perspectives.
We want to remove those views from the Window -> Show View dialog so that users cannot add them to perspectives where they don't work.
Any ideas on how to do this either programmatically or declaratively?
I have tried using <visibleWhen />, but the views are still showing in the dialog:
<view class="com.mycompany.ViewClass"
id="com.mycompany.ViewId"
name="View Name"
restorable="true">
<visibleWhen>
<with variable="activeWorkbenchWindow.activePerspective">
<equals value="com.mycompany.MyPerspective"/>
</with>
</visibleWhen>
</view>
I don't think there is any problem with the <visibleWhen /> clause, so I'm wondering if it can be used with a View?
It should be treated as a menu contribution, using the <visibleWhen/> to only display that option when a certain condition is met.
See the wiki article "Menu Contribution" for more.
Unfortunately, it seems that Eclipse already does this for the Introduction view by calling the private ViewContentProvider.removeIntroView on the content provider for the Show Views dialog. A way to get around this limitation is to define activities by adding to the org.eclipse.ui.activities extension point (see activityPatternBinding on how activities can be mapped to UI contributions). Doing this will not only remove the views from the Show Views dialog, but it will also prevent them from showing in the perspectives themselves. The views can then be shown programmatically. I had to also enable the activities in the ApplicationWorkbenchAdvisor.preStartup method because of limitations in our application:
Set<String> activityIds = new HashSet<String>();
activityIds.add("com.my.activity.id");
IWorkbenchActivitySupport activitySupport = PlatformUI.getWorkbench().getActivitySupport();
activitySupport.setEnabledActivityIds(activityIds);
In this case, the activity has to be disabled before showing the dialog, so the Show Views menu contribution has to be modified to do this as well.
Hopefully an extension point will be added to the next version of Eclipse to provide the option for developers to remove views from the dialog declaratively.