I want to override org.eclipse.ui.project.cleanAction.
Simple org.eclipse.ui. commands & handlers doesnt work because of structure of WorkbenchActionBuilder. I have solved it with code :
MenuManager menu = (MenuManager) ((WorkbenchWindow)PlatformUI.getWorkbench().getActiveWorkbenchWindow()).getActionBars().getMenuManager();
menu = (MenuManager) menu.find( "project" );
menu.replaceItem( "buildClean", new ActionContributionItem( new ABCBuildCleanAction( PlatformUI.getWorkbench().getActiveWorkbenchWindow() ) ) );
Now how can I make this code piece work when I press Project from menu? This is a MenuManager and I thought MenuAdapter (MenuListener) menuShown method can help but how can I make it run? I searched for a solution via plugin.xml Extensions but as which extension point should I add it?
Any Idea? Please don't hesitate to ask for more information...
We put that code piece under :
Bundle-Activator : in MANIFEST.MF file (It is the Activator.) That XXPlugin class extends AbstractUIPlugin class. In the start method I put my code to work.
This solved my problem, now when eclipse starts It loads this code and my code works instead of CleanDialog class...
ilke
Related
How to exclude UnityEditor reference from asmdef?
Why I need it:
I have an asmdef file. For example, it is MyAssembly/MyAssembly.asmdef. The MyAssembly contains a lot of features and each feature staff is placed in its own folder. And some of these features has a code that is needed only in editor, and it refers to UnityEditor namespace. Such editor code is placed into an Editor folder.
But as you know, Editor folder name means nothing in terms of asmdef usage. So I add AssemblyDefenitionReference in each folder and refer it to the MyAssemblyEditor.asmdef assembly definition. So the paths looks like this:
MyAssembly/MyAssembly.asmdef
MyAssembly/Editor/MyAssemblyEditor.asmdef - this folder contains no code. It's needed just to place asmdef, because it's not allowed to place two asmdefs in a single folder.
MyAssembly/SomeFeature/Editor/*feature editor staff*
MyAssembly/SomeFeature/Editor/Editor.asmref - refers to MyAssemblyEditor.asmdef
MyAssembly/SomeFeature/*feature staff*
All this works good. But the problem is that, when some developer adds a new feature, he can forget to add a reference to the MyAssemblyEditor.asmdef in the editor folder. And there are no any errors will be shown in this case. This mistake will be revealed only when the build will be cooked. But I'd like that using of UnityEditor in MyAssembly will be instantly marked as an error.
Feel free to suggest other solution for this problem.
This thread got me thinking I can use CsprojPostprocessor to remove all references to UnityEditor from my csproj file. I wrote such class:
using System.Text.RegularExpressions;
using UnityEditor;
// ReSharper disable once CheckNamespace
public class CsprojPostprocessor : AssetPostprocessor
{
public static string OnGeneratedCSProject(string path, string content)
{
if (!path.EndsWith("Editor.csproj") && !path.EndsWith("Tests.csproj"))
{
var newContent =
Regex.Replace(content, "<Reference Include=\"UnityEditor(.|\n)*?</Reference>", "");
return newContent;
}
return content;
}
}
It also can be done with an xml parser or something.
The only thing, that confuse me is that this mechanism is badly documented and doesn't look like something simple users should use. So I use it at my own risk, but looks like there is no guarantee it will be strongly supported in future.
Im using Ember with VS Code.
What I need is to generate import string on a fly when I encounter dependency. For example I write someting like:
#tracked isLarge = false;
But I don’t have “#tracked” imported yet. So the otion could be to set the coursor on #tracked, press something like “Action + .” and pick “generate import”. It should generate import string:
import { tracked } from '#ember/tracking';
But it doesn’t work out of the box. How can I do that?
UPDATE: the same question about:
go to definition
go to implementation
cmd+click to navigate to implementation/component
You can use the extension My Code Actions
You can create actions that just insert the text independent of an error.
"my-code-actions.actions": {
"[javascript]": {
"import tracked": {
"where": "insertAfter",
"insertFind": "^import",
"text": "import { tracked } from '#ember/tracking';\n"
}
}
}
The key combo to use is the Code Action combo: Ctrl+.
If you get a diagnostic (PROBLEM panel, and squiggle) you can use that to further customize the action and you can use text from the diagnostics message.
I'm current adding the possibility to make multiple edits in an action and to use further customization and generalization.
"Ember Language Server" brings some solution. But it works mostly with library code that has .d.ts typings.
In case of custom JS code it still doesn't work.
So there is no straight solution. Only 2 ways:
Write .d.ts typing for custom code JS files
Move project to typescript
I writing my own text editor plugin for eclipse. I am now working on my own formatter. Actually, following that link http://wiki.eclipse.org/FAQ_How_do_I_support_formatting_in_my_editor%3F.
I have written my Strategy, I have overridden getContentFormatter in my SourceViewerConfiguration..
As I run my plugin and press Ctrl+Shift+F - and nothing happens.
I think that I'm missing a step here. Should I create a handler or something?
Thanks
Might it be you skipped the last part of the linked page?
Finally, you will need to create an action that invokes the formatter. No generic formatting action is defined by the text infrastructure, but it is quite easy to create one of your own. The action’s run method can simply call the following on the source viewer to invoke the formatter:
sourceViewer.doOperation(ISourceViewer.FORMAT);
What helped me. I have created a handler with the following executors body:
//get the editorPart
if (editorPart != null) {
ITextOperationTarget target = (ITextOperationTarget) editorPart
.getAdapter(ITextOperationTarget.class);
if (target instanceof ISourceViewer) {
ISourceViewer textViewer = (ISourceViewer) target;
((ITextOperationTarget) textViewer)
.doOperation(ISourceViewer.FORMAT);
}
}
Then just create menu items and bind them to the handler.
I'd like to change at runtime the name of my eclipse RCP application, so to include the name of the project the user is working on.
This seems a pretty simple question, but I was only able to find a way to set the name statically (in the article "branding your application").
There is a simpler way to do it, after I tried to do it as suggested here, I got into problems getting a hold of the Application or WorkbenchWindowAdvisor. The solution was simply to get the shell of the workbench window and setText:
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().setText("My new title");
In your ApplicationWorkbenchWindowAdvisor get hold of the IWorkbenchWindowConfigurer and set the title there. e.g:
public void preWindowOpen()
{
IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
configurer.setTitle("Custom Name...");
}
You can update the title at any time by burrowing down through the Application object:
Application.getApplication().getWorkbenchAdvisor().getWorkbenchWindowAdvisor().setTitle();
I do the same thing. I hold the getWindowConfigurer(); in some static reference.
Utility.configurer = getWindowConfigurer();
Then use this reference anywhere to update application title.
Utility.configurer.setTitle("My New Title");
How do I retrieve the name and path of the project selected? (Package Explorer)
example: c:\project\test\projectName
someone has some code that explains how to complete I get the project name or full path of a particular project in my workspace?
Eclipse defines an extension point
"org.eclipse.ui.navigator.linkHelper"
If you contribute a class to these EP you have to implement ILinkHelper
The ILInkHelper interface notifies you, when something was selected in the explorer
public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection)
You can check the type of the selection
if (aSelection.getFirstElement() instanceof IFile) {
// Do something
}
Old memories but maybe useful for you. I guess package explorer provides its selection, so you can get the current selection in your code by calling:
ISelectionService service = getSite().getWorkbenchWindow().getSelectionService()
than you can get the package explorer view by its id (plugin.xml for more details):
IStructuredSelection selection = (IStructuredSelection) service.getSelection("org.eclipse.jdt.ui.PackageExplorer");
Please note AFAIK you can always safely cast ISelection to IStructuredSelection. Then call structured.getFirstElement() and I think the first element will be an IFile object. I hope my "pseudo code" whould be enough for you. And IFile has lots of usefule methods for your convenience