I have created multipage HTML editor in which one tab has text editor. I have set the global action handler to the action bar for undo / redo actions in the source editor. Whenever I am adding something in the source editor then undo it, it is not returning the same code in the first attempt. It is completing in the second attempt. Can anyone help me to solve this issue.
In the main editor override the setFocus() method and in this method call the following method of source editor.
public void setUndoRedoActionHandlers() {
final IActionBars actionBars = getEditorSite().getActionBars();
actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(),
mUndoAction);
actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(),
mRedoAction);
actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(),
mDeleteAction);
actionBars.setGlobalActionHandler(
ITextEditorActionConstants.DELETE_LINE, mDeleteLineAction);
actionBars.updateActionBars();
}
Thanks
Are you sure that you set global actions by overriding setFocus()? Look at this : https://wiki.eclipse.org/FAQ_How_do_I_enable_global_actions_such_as_Cut,_Paste,_and_Print_in_my_editor%3F
It says they need to be set inside method setActiveEditor()
The reason I guess why you are seeing it working second time is - When the first time you click your editor gets focus and setFocus is called and only then the global actions are set. Then second time it will work because the actions are now set.
Related
I need help with my VS Code extension. I've written a custom view which works just fine, however I'd like to activate / focus / bring into view that view by using a keyboard shortcut or a context menu command. I am unable to find how to use the VS code API to achieve that.
context.subscriptions.push(vscode.commands.registerCommand('extensionId.showView', () =>
{
// how to do that?
}));
I know this can be done, because one can display the file explorer by using this code snppet:
vscode.commands.executeCommand('workbench.view.search');
But how would you do that for a custom tree view?
You should be able to use the new focus option that was added to TreeView.reveal() in 1.25 for that. The method requires you to pass a tree item to be revealed, so it's more of a workaround for not being able to focus the view itself directly, but you could simply pass the first / root node.
treeView.reveal(item, {focus: true});
Note that focus in this case means keyboard focus. If you just want to bring it into view, calling reveal() without the focus option is good enough.
To obtain a TreeView instance, you need to call vscode.window.createTreeView() with your view ID and provider.
I think, it is also possible to use
vscode.commands.executeCommand("exampleView.focus")
using the exampleView declared in package.json:
...
"views": {
"exampleView": [
{
"id": "exampleView",
"name": "Example View"
}
]
},
...
as #Empiire said, focus command in the form of : vscode.commands.executeCommand
and adding the '.focus' at the end of the id of the view that was declared in the package.json works!
You can also provide an object as parameter such as { preserveFocus: true } to show without disturbing the current focus.
eamodio does it like that in gitlens : https://github.com/gitkraken/vscode-gitlens/blob/417587d0dfcda89e9e2d723f8b662d7cf9008c8f/src/webviews/webviewViewBase.ts#L85
I'm using an Input Field in a Unity 3D game. When I enter text on my Windows 10 Mobile, and push the back button to dismiss the keyboard, Unity thinks I want to clear the Input Field. This behavior is not even mentioned in the documentation and I have not found a way to override it. I'd like to make it so the user can use the back button to dismiss the keyboard without reverting the Input Field. Any suggestions? Is this just a bug with Unity?
You can see the source code of InputField here: https://bitbucket.org/Unity-Technologies/ui/src/0155c39e05ca5d7dcc97d9974256ef83bc122586/UnityEngine.UI/UI/Core/InputField.cs?at=5.2&fileviewer=file-view-default
Apparently, clearing the field on escape is made by design. look at line 980 - 984:
case KeyCode.Escape:
{
m_WasCanceled = true;
return EditState.Finish;
}
What you can try is to create your own subclass of InputField and override the function
protected EditState KeyPressed(Event evt)
Of course it is not really clean, since you'll have to copy everything that the base InputField does in this function, except for lines 980 - 984.
The function KeyPressed cant be overridden.
I just added that in my function that listens on the value changes of the inputField:
if (Input.GetKeyDown (KeyCode.Escape)) {
return;
}
And it does exactly what is necessary :)
In the Eclipse UI, I'd like to set the visible area in an editor. In other words, if the number of lines of my file is larger than the number of lines my editor can show then I want to specify the first shown line. My first approach was to calculate the first visible line via the selection value of its vertical scroll bar. The following link points to my initial question. Its answer explains how to set the first visible line in an editor.
eclipse ui: setting scrollbar but editor does not follow
The problem now is that my initial way of retrieving the first visible line in an editor fails in some cases: Although I verify that the active page is indeed an editor, the focus might be assigned to another page. In such a case, the following code yields the ScrollBar of a different page:
public static void update(final IWorkbenchWindow w)
final Scrollable scrollable =
(Scrollable) w.getWorkbench().getDisplay().getFocusControl();
final ScrollBar vScrollBar = scrollable.getVerticalBar();
So, my question: If editor is the reference of an active editor (ITextEditor and IReusableEditor), how to I get its first visible line?
If you can access the editor ITextViewer or its extension ISourceViewer (usually implemented by the SourceViewer or TextViewer class) you can call the ITextViewer.getTopIndex() method to get the top line index.
If your editor is derived from AbstractTextEditor (or one of its subclasses such as TextEditor) there is a protected method getSourceViewer() that returns this. You may have to add a public method if you want to access this from outside of the editor.
I'm currently working with IceFaces 1.8, and have been trying to find an simple way to chain effects on UI Components. For example, I have a "Show Help" link at the top right of the page. When clicked, help text will appear below certain controls for users. I'd like this text to appear by sliding down, then highlighting.
I have a basic isRenderHelp() method on my bean that returns true or false, and use that to render effects using the fire attribute on the <ice:effect> tag, so it looks something like this:
<ice:effect effectType="slidedown" fire="#{myBean.renderHelp}">
<ice:effect effectType="slideup" fire="#{!myBean.renderHelp}">
This works causing the help section to slide in and out as the help link toggles the renderHelp flag in the bean. There is the small exception that renderHelp returns null before the link is clicked for the first time to prevent the slideup animation from firing on the first page render.
Now, I noticed looking through the showcase code for 1.8 that there is an EffectQueue class that extends Effect. This allows me to add mutliple Effects to the queue in my bean, and return the queue from a getEffect method that I can then assign to a panelGroup effect attribute. However, it does not execute the events in the queue, despite having their priorities set. I'm sure I'm not using it properly, and I'm wondering how it should be used.
Normally I'd use jQuery for this type of thing, but the UI uses many partial submits. Our page is displayed via a Liferay portlet, so on any partialSubmit the view is rerendered, undoing any modifications to the DOM by jQuery.
So is there any simple way to chain effects in IceFaces 1.8? Suggestions?
here is how I implemented the effectQueue to appear and fade the text.
private EffectQueue effectQueue;
public Effect getSaveSettingsEffect() {
return effectQueue;
}
public void fireEffect(ActionListener e) {
if(effectQueue == null) {
effectQueue = new EffectQueue("apperAndFade");
Appear appear = new Appear();
appear.setDuration(2);
effectQueue.add(appear);
Fade fade = new Fade();
fade.setDuration(3);
effectQueue.add(fade);
effectQueue.setTransitory(true);
}
effectQueue.setFired(false);
}
facelet:
<ice:commandButton value="fireEffect" action="#{bean.fireEffect}"/>
<ice:outputText value="text" style="display: none;" effect="#{bean.effectQueue}"/>
I am developing a plugin to eclipse and I want to add some actions to the context menu. But actually I wanted to prepare results beforehead according to the text selection in the editor and just show them when the menu item will be selected.
I followed that article http://www.eclipse.org/articles/Article-WorkbenchSelections/article.html - all interfaces (ISelectionListener, ISelectionChangedListener etc) allow to handle the SelectionChanged event, but editor counts changing only when length of selection also changes - so the simple click in the editor doesn't fire the event, although I want to get the word (for example) as a selection if cursor is inside the word now and lenght is 0.
So the question is - what is the simpliest solution for traking down cursor position/offset/selections with zero lengh value changing?
In that case you have to use KeyListener and MouseListener as well. For e.g take a look at org.eclipse.jface.text.PaintManager, and it listens to all these events.
If you are extending TextEditor you can override handleCursorPositionChanged() method to fire your event and use getCursorPosition() to get the cursor position as a String.