Eclipse plug-in: syntax recoloring - eclipse-plugin

I have a costum editor for my own languages and I want to change from the property menu between them and recolor the syntax accordingly. I don't know if I have to use a reconciler or something else. The only way that the syntax is recolored, is by closing and opening the current file.

In your editor you need to listen for property change events from your preference store.
In your initializeEditor method call setPreferenceStore(preferenceStore)
Override the handlePreferenceStoreChanged method:
#Override
protected void handlePreferenceStoreChanged(PropertyChangeEvent event)
{
// TODO update settings affected by the event
// TODO If required invalidate the current presentation to update the colors
getSourceViewer().invalidateTextPresentation();
super.handlePreferenceStoreChanged(event);
}
You need to add code to look at the property change event to see if it is one that you need to handle. If the event changes something (such as changing the colors) that needs to text to be redrawn call getSourceViewer().invalidateTextPresentation().
To support all the normal text editor preferences you need to use a chained preference store in the setPreferenceStore call:
IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
IPreferenceStore yourPreferenceStore = get your preference store
IPreferenceStore combinedPreferenceStore = new ChainedPreferenceStore(new IPreferenceStore[] {yourPreferenceStore, generalTextStore});
setPreferenceStore(combinedPreferenceStore);

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.

Cannot get the selected item in a ListViewer in a JFace Dialog

I created a dialog class that inherited from JFace Dialog using Windows Builder. In that, I added some controls included a button and a JFace ListViewer. In widgetSelected() function of the button, I can get out the selected item in the ListViewer. But in `okPressed(), I cannot get this. I don't know why. Can you help me?
Thanks!
If you want to access UI elements in okPressed you must do so before calling super.okPressed() because that will close the dialog and dispose of the controls. So something like:
#Override
protected void okPressed()
{
IStructuredSelection sel = viewer.getStructuredSelection();
// TODO deal with selection
// Call super.okPressed() last
super.okPressed();
}
Alternatively save the selection when your widgetSelected is called.

Durandal 2.0 Dialog Repositioning

At the bottom of the durandal docs for dialogs / modals (http://durandaljs.com/documentation/Showing-Message-Boxes-And-Modals.html) there's some syntax for repositioning a dialog. The dialog I have gets gradually bigger as the user selects stuff, so every time a selection is made, I'd like to call reposition(). I tried following along with this:
vm.compositionComplete = function (child, parent, context) {
var addEditDialog = dialog.getDialog(context.model); // resolves
// whenever something is selected:
addEditDialog.context.reposition(vm); // no method 'reposition'
}
But I get an error - there is no function reposition. What am I doing wrong?
You can set up a custom dialog context that responds to a reposition message (using Durandal's app.trigger()). You would trigger the message upon some event in your dialog (such as, as you say, the user's selecting stuff).
Also in that custom dialog context, create a method call reposition. In the activate or attached handler of that custom dialog context, subscribe to the message you use to trigger a reposition.
I'm advocating a messaging approach because you may wish to isolate your "selection viewModel" in its own viewModel, and then compose it into your custom dialog context. With this approach, your selection viewModel and your custom dialog context would be loosely bound. That way, you could use your selection viewModel elsewhere in your code (and even have some other viewModel, instead of the custom dialog context, respond to the reposition message).

Windows 8 app: How to pass a parameter on GoBack()?

There are a lot of samples showing how to pass a parameter on navigating to a page in Window 8 (WinRT). But I could not find any hint for passing parameters going back.
Situation: The user navigates to a details page of same data. The data is passed to the page by
Frame.Navigate(typeof(DedtailsPage), data);
How can I pass back the changed data on GoBack()?
Store the reference to data somewhere and retrieve it when you navigate back?
Also note that it's best not to pass objects other than simple strings or values between pages, since only simple types are supported for storing frame navigation state in case your app gets suspended.
I know, that this is a very bad idea, but usualy I use this:
To write:
Frame rootFrame = Window.Current.Content as Frame;
rootFrame.Tag = myObject1;
To read:
Frame rootFrame = Window.Current.Content as Frame;
var myObject2 = rootFrame.Tag;
I've made another choice to handle this.
Keep in mind that I'm a Xamarin developer (not Forms!) so i was looking for a solution which was similar for all platforms: iOS, Android and Windows.
I am a great fun of events, rather than passing objects or storing globals.
So the best choice to pass data from PageB (the child) to PageA (the parent) is to communicate via events.
Some notes: In iOS and Android, when you navigate from a "page" to "page" you can do this by passing an instance of the target object you want to navigate to. In iOS you create an instance of a custom UIViewController. In Android you create an instance of a custom Fragment. Doing this allow you to attach events handler to your instances.
An example:
var controller = new ExtrasViewController();
controller.ExtraSelected += ExtrasFragment_ExtraSelected;
controller.ExtrasCleared += ExtrasFragment_ExtrasCleared;
this.NavigationController.PushViewController(controller, false);
In WinRT Apps you are only allowed to pass "types" of target page to navigate to. So the only way to attach event handlers to your page instance is to use the OnNavigatedFrom method from the calling page. So suppose you are in PageA and want to attach some event handlers to your PageB, before it become active, simply write in your PageA "code behind":
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
base.OnNavigatedFrom(e);
var page = e.Content as ExtraBody;
if(page != null)
{
page.ExtraSelected += ExtrasFragment_ExtraSelected;
page.ExtrasCleared += ExtrasFragment_ExtrasCleared;
}
}

Something like .NET's "tag" property for Interface Builder

I'm currently struggling to use UI elements in Interface Builder. I keep trying to do things "in the .NET way."
I have several buttons that all map down their TOUCH event to the SAME FUNCTION:
-(IBAction) onTouch:(id) sender
{
// do something with touch, DEPENDING ON WHAT BUTTON WAS PUSHED
// I want to do something like
if( sender.tag == "something" )
{
//...doesn't work on apple, of course..
}
}
I want to uniquely identify each BUTTON USING SOMETHING like the TAG property in .NET. I tried using the INTERFACE BUILDER "NAME" field that is on the "Identity" panel of interface builder, but I don't know how to access that field programmatically.
-(IBAction) onTouch:(id) sender
{
// do something with touch, DEPENDING ON WHAT BUTTON WAS PUSHED
// I want to do something like
if( sender.InterfaceBuilderName == "something" )
{
//...doesn't work..
}
}
So, WHAT / IS THERE a way to uniquely identify a UI element (such as a button) OTHER THAN doing something like
-(IBAction) onTouch:(id) sender
{
// look at
[sender currentTitle]
}
The reason that's bad is because if the text on the button changes for some cosmetic reason you break the whole app, right
The last solution I can think of is write seperate functions for each button's touch event but I really want to know if it is possible to uniquely identify a button by something similar to .Net's TAG property.
In the iPhone SDK all UIView objects have a property also called tag which is an integer value and can basically be used to do what you are intending.
I usually define a constant for the tag values I'm going to use for a specific purpose.
You can access the tag on the button object:
myButton.tag = MYBUTTON_TAG_CONSTANT
// button tag constant
#define MYBUTTON_TAG_CONSTANT 1
For buttons, there is a Tag entry in the View section (click on your button, select Attributes Inspector from the Tools menu). You can then use this integer value in your code.
Here is a link that may help as well:
http://www.iphonedevsdk.com/forum/iphone-sdk-development/25582-using-tags-interface-builder.html
UIView's tag property is accessible from Interface Builder. Unlike .NET, it's an integer rather than a string.