How to get current list of decorations OR handle decoration position change in VSCode Extension? - visual-studio-code

Lets take this example into account.
I have a file with contents:
1: one
2: two
3: three
and I create a line decoration for line "two":
const position = new vscode.Position(1, 0);
const range = new vscode.Range(position, position);
const decoration = vscode.window.createTextEditorDecorationType({
gutterIconPath: context.asAbsolutePath('images/icon.svg')
});
vscode.window.activeTextEditor?.setDecorations(decoration, [range]);
that gives me
1: one
* 2: two
3: three
Next step:
I am changing file contents by adding a new line before line "two".
After that file looks like this:
1: one
2:
* 3: two
4: three
As you can see VSCode has updated my line decoration and now it is positioned on line 3 (instead of 2) which is totally correct and I've expected that.
And now the question:
how can I get this current updated position of my line decoration?
If I hold the range reference - it is still pointing to line 2.
What is the right way to handle this decoration changes?
Either of these 2 options would satisfy me:
a way to query all the current decoration positions displayed for currently open file
a way to subscribe to decoration / range changes so that I can handle those manually.
Maybe I am totally wrong and it should be done in another way.
Please advise!

So apparently there is no way to get all the current decorations for open file in VSCode. Here is an old issue without clear plans to be resolved https://github.com/microsoft/vscode/issues/54147.
I've found an internal method getLineDecorations - https://github.com/microsoft/vscode/blob/master/src/vs/editor/browser/widget/codeEditorWidget.ts#L1118 - and I was trying to reach to it via
vscode.window.activeTextEditor?._proxy
vscode.window.activeTextEditor?._runOnProxy
but I did not succeed.
So for now probably the only option that we have mentioned here https://github.com/microsoft/vscode/issues/54147#issuecomment-439177546 is:
to store a copy of all decoration positions
to update it manually on each text update via vscode.workspace.onDidChangeTextDocument handler
It is doable but very annoying that we have to do this stuff manually. ¯_(ツ)_/¯
Also very error prone )

Related

How to mix bar and lines in Grafana in one chart

How can I display one dataseries as bar and another as a line in one graph like it is used in the last comment of: see last picture
Short answer:
It's not possible (yet) using the Grafana UI, only by hand.
Long answer:
As far as I know there is no way of doing this using the UI switches; you'll have to use the use the "alias or regex" fields below the visualisation configuration.
Prepare your data
Before you start, make sure that your queries A and B retrieve actual data. You won't see your data otherwise and be confused why they're not showing.
Adding fields and values to the aliases
Once you are selecting the correct data you want to display, just add the following on the visualisation section of the graph at the 'alias or regex' fields:
Add 2 overrides, one for each value you want to display using the 'Add series override' button.
Add a "Bars:false" option flag and a "Lines:true" for the value you want as a line.
Be sure to use the exact opposite values for your bars ("Bars:true" & "Lines:false")
Add a 'Y-axis: 2' to the value you want to have on the right side of your graph.
Optionally, you can add a "Z-index: 3" for the value that you want to have on top (I added this option to the line to make sure it's always drawing on top of the bars).
Enjoy
You should now have a nice graph with 2 types of data and visualisations in one; something like this:
For those who were asking in the comment section, yes this isn't available in version 8, however, you can still change the time series visualization to graph(old) so you can set the alias/regex.

Unity editor - How to stop field from turning blue when its edited

I am making a tool in Unity to build your project for muliple platforms when you press a button.
I started with the preferences window for the tool, and came up with an anoying thing. Whenever I change the enum value of the EnumPopup field, the field turns blue in the editor window. Is there a way to disable this?
See how in the 2nd picture the field is not blue, and in the 3rd picture the field has changed to blue? How do I prevent this from happening?
Thanks in advance!
Difficult to help without having the rest of your code.
This is Unity built-in behaviour. I tried a lot of stuff see here to disable / overwrite the built-in coloring of prefix labels but had no luck so far.
A workarround however might be to instead use an independent EditorGUI.LabelField which will not be affected by the EnumPopup together with the EditorGUIUtility.labelWidth:
var LabelRect = new Rect(
FILEMANAGEMENT_ENUMFIELD_RECT.x,
FILEMANAGEMENT_ENUMFIELD_RECT.y,
// use the current label width
EditorGUIUtility.labelWidth,
FILEMANAGEMENT_ENUMFIELD_RECT.height
);
var EnumRect = new Rect(
FILEMANAGEMENT_ENUMFIELD_RECT.x + EditorGUIUtility.labelWidth,
FILEMANAGEMENT_ENUMFIELD_RECT.y,
FILEMANAGEMENT_ENUMFIELD_RECT.width - EditorGUIUtility.labelWidth,
FILEMANAGEMENT_ENUMFIELD_RECT.height
);
EditorGUI.LabelField(LabelRect, "File relative to");
QuickBuilder.Settings.Relation = (QuickBuilder.Settings.PathRelation)EditorGUI.EnumPopup(EnumRect, QuickBuilder.Settings.Relation);
As you can see the label is not turned blue while the width keeps being flexible
Sidenotes
Instead of setting values via edito scripts directly like
QuickBuilder.Settings.Relation = you should always try and use the proper SerializedProperty. It handles things like Undo/Redo and also marks the according objects and scenes as dirty.
Is there also a special reason why you use EditorGUI instead of EditorGUILayout? In the latter you don't need to setup Rects.
EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.LabelField("File relative to", GUILayout.Width(EditorGUIUtility.labelWidth));
QuickBuilder.Settings.Relation = (QuickBuilder.Settings.PathRelation)EditorGUILayout.EnumPopup(QuickBuilder.Settings.Relation);
}
EditorGUILayout.EndHorizontal();

Change line behavior of a combined chart in SAPUI5 VizFrame

I am using a combined chart (Stacked Column + Line) for my application. Is it possible to change the line plotting?. (somewhat like shown in RED in the image). If yes then how is it possible?
I'm sure you already know the VIZ documentation where you can find all possible properties of VizFrame. As far as I know there currently is no way to get the behavior you're asking for except for writing your own lineRenderer (vizProperties.plotArea.lineRenderer). There is one alternative line plotting mode available which is smoothening it but I'm sure thats not what you want.
However you could use a second series of column chart instead. Just use a standard column chart and add two data series instead of one. I think this would show the exact information you're trying to get with the current diagram just no connection between them.

Eclipse ui: retrieving the first visible line of an editor

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.

How to highlight first node of GtkTreeView

I would like to highlight the first node of a GtkTreeView and give that node the focus. gtk_tree_view_row_activated () seems appropriate for what I am trying to do, but I couldn't figure out the arguments it takes.
Thanks in advance.
gtk_tree_view_row_activated() actually acts on just one cell. I wonder if you really want to Highlight the row or just select it. I.e. if you want to leave the highlight even if the cursor is on another line.
If that's the case, note that you can define extra fields in the underlying model, for example, if you have 3 fields for your data, you can add field 4 with a color. Then you can tell the renderer to use the color in field 4 (instead of giving the renderer the color immediately).
This example not only changes the background, but also the text color:
http://faq.pygtk.org/index.py?req=show&file=faq13.031.htp
For more sophisticated work, you can even modify the atributes on a cell-per-cell basis:
http://www.pygtk.org/docs/pygtk/class-gtktreeviewcolumn.html#method-gtktreeviewcolumn--set-cell-data-func
Use set_cursor method:
TextView.set_cursor(0,None,False)
0 = Index of the first row