Class SpaceDrawer
- All Implemented Interfaces:
Proxy
GtkSourceSpaceDrawer provides a way to visualize white spaces, by drawing
symbols.
Call View.getSpaceDrawer() to get the GtkSourceSpaceDrawer
instance of a certain View.
By default, no white spaces are drawn because the
SpaceDrawer:enable-matrix is false.
To draw white spaces, setTypesForLocations(java.util.Set<org.gnome.gtksourceview.SpaceLocationFlags>, java.util.Set<org.gnome.gtksourceview.SpaceTypeFlags>) can
be called to set the SpaceDrawer:matrix property (by default all
space types are enabled at all locations). Then call
setEnableMatrix(boolean).
For a finer-grained method, there is also the Tag's
Tag:draw-spaces property.
Example
To draw non-breaking spaces everywhere and draw all types of trailing spaces
except newlines:
gtk_source_space_drawer_set_types_for_locations (space_drawer,
GTK_SOURCE_SPACE_LOCATION_ALL,
GTK_SOURCE_SPACE_TYPE_NBSP);
gtk_source_space_drawer_set_types_for_locations (space_drawer,
GTK_SOURCE_SPACE_LOCATION_TRAILING,
GTK_SOURCE_SPACE_TYPE_ALL &
~GTK_SOURCE_SPACE_TYPE_NEWLINE);
gtk_source_space_drawer_set_enable_matrix (space_drawer, TRUE);
space_drawer.set_types_for_locations(
locations=GtkSource.SpaceLocationFlags.ALL,
types=GtkSource.SpaceTypeFlags.NBSP,
)
all_types_except_newline = GtkSource.SpaceTypeFlags(
int(GtkSource.SpaceTypeFlags.ALL) & ~int(GtkSource.SpaceTypeFlags.NEWLINE)
)
space_drawer.set_types_for_locations(
locations=GtkSource.SpaceLocationFlags.TRAILING,
types=all_types_except_newline,
)
space_drawer.set_enable_matrix(True)
Use-case: draw unwanted white spaces
A possible use-case is to draw only unwanted white spaces. Examples:
- Draw all trailing spaces.
- If the indentation and alignment must be done with spaces, draw tabs.
And non-breaking spaces can always be drawn, everywhere, to distinguish them from normal spaces.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classSpaceDrawer.Builder<B extends SpaceDrawer.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static classNested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new SpaceDrawer.SpaceDrawer(MemorySegment address) Create a SpaceDrawer proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected SpaceDrawerasParent()Returns this instance as if it were its parent type.voidbindMatrixSetting(Settings settings, String key, Set<SettingsBindFlags> flags) Binds theSpaceDrawer:matrixproperty to aSettingskey.voidbindMatrixSetting(Settings settings, String key, SettingsBindFlags... flags) Binds theSpaceDrawer:matrixproperty to aSettingskey.static SpaceDrawer.Builder<? extends SpaceDrawer.Builder> builder()ASpaceDrawer.Builderobject constructs aSpaceDrawerwith the specified properties.booleanGets the value of theSpaceDrawer:matrixproperty, as aGLib.Variant.static @Nullable TypegetType()Get the GType of the SpaceDrawer classgetTypesForLocations(Set<SpaceLocationFlags> locations) If only one location is specified, this function returns what kind of white spaces are drawn at that location.getTypesForLocations(SpaceLocationFlags... locations) If only one location is specified, this function returns what kind of white spaces are drawn at that location.voidsetEnableMatrix(boolean enableMatrix) Sets whether theSpaceDrawer:matrixproperty is enabled.voidSets a new value to theSpaceDrawer:matrixproperty, as aGLib.Variant.voidsetTypesForLocations(Set<SpaceLocationFlags> locations, Set<SpaceTypeFlags> types) Modifies theSpaceDrawer:matrixproperty at the specifiedlocations.voidsetTypesForLocations(SpaceLocationFlags locations, SpaceTypeFlags... types) Modifies theSpaceDrawer:matrixproperty at the specifiedlocations.Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getMemoryLayout, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newv, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
SpaceDrawer
Create a SpaceDrawer proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
SpaceDrawer
public SpaceDrawer()Creates a new SpaceDrawer.
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuperkeyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName(). This will call the native function pointer of this virtual method in the typeclass of the parent type. -
bindMatrixSetting
Binds theSpaceDrawer:matrixproperty to aSettingskey.The
Settingskey must be of the same type as theSpaceDrawer:matrixproperty, that is,"au".The
Settings.bind(java.lang.String, org.gnome.gobject.GObject, java.lang.String, java.util.Set<org.gnome.gio.SettingsBindFlags>)function cannot be used, because the default GIO mapping functions don't supportGLib.Variantproperties (maybe it will be supported by a future GIO version, in which case this function can be deprecated).- Parameters:
settings- aGSettingsobject.key- thesettingskey to bind.flags- flags for the binding.
-
bindMatrixSetting
Binds theSpaceDrawer:matrixproperty to aSettingskey.The
Settingskey must be of the same type as theSpaceDrawer:matrixproperty, that is,"au".The
Settings.bind(java.lang.String, org.gnome.gobject.GObject, java.lang.String, java.util.Set<org.gnome.gio.SettingsBindFlags>)function cannot be used, because the default GIO mapping functions don't supportGLib.Variantproperties (maybe it will be supported by a future GIO version, in which case this function can be deprecated).- Parameters:
settings- aGSettingsobject.key- thesettingskey to bind.flags- flags for the binding.
-
getEnableMatrix
public boolean getEnableMatrix() -
getMatrix
Gets the value of theSpaceDrawer:matrixproperty, as aGLib.Variant.An empty array can be returned in case the matrix is a zero matrix.
The
getTypesForLocations(java.util.Set<org.gnome.gtksourceview.SpaceLocationFlags>)function may be more convenient to use.- Returns:
- the
GtkSourceSpaceDrawer:matrix value as a new floatingGVariantinstance.
-
getTypesForLocations
If only one location is specified, this function returns what kind of white spaces are drawn at that location.The value is retrieved from the
SpaceDrawer:matrixproperty.If several locations are specified, this function returns the logical AND for those locations. Which means that if a certain kind of white space is present in the return value, then that kind of white space is drawn at all the specified
locations.- Parameters:
locations- one or severalGtkSourceSpaceLocationFlags.- Returns:
- a combination of
GtkSourceSpaceTypeFlags.
-
getTypesForLocations
If only one location is specified, this function returns what kind of white spaces are drawn at that location.The value is retrieved from the
SpaceDrawer:matrixproperty.If several locations are specified, this function returns the logical AND for those locations. Which means that if a certain kind of white space is present in the return value, then that kind of white space is drawn at all the specified
locations.- Parameters:
locations- one or severalGtkSourceSpaceLocationFlags.- Returns:
- a combination of
GtkSourceSpaceTypeFlags.
-
setEnableMatrix
public void setEnableMatrix(boolean enableMatrix) Sets whether theSpaceDrawer:matrixproperty is enabled.- Parameters:
enableMatrix- the new value.
-
setMatrix
Sets a new value to theSpaceDrawer:matrixproperty, as aGLib.Variant.If
matrixisnull, then an empty array is set.If
matrixis floating, it is consumed.The
setTypesForLocations(java.util.Set<org.gnome.gtksourceview.SpaceLocationFlags>, java.util.Set<org.gnome.gtksourceview.SpaceTypeFlags>)function may be more convenient to use.- Parameters:
matrix- the new matrix value, ornull.
-
setTypesForLocations
Modifies theSpaceDrawer:matrixproperty at the specifiedlocations.- Parameters:
locations- one or severalGtkSourceSpaceLocationFlags.types- a combination ofGtkSourceSpaceTypeFlags.
-
setTypesForLocations
Modifies theSpaceDrawer:matrixproperty at the specifiedlocations.- Parameters:
locations- one or severalGtkSourceSpaceLocationFlags.types- a combination ofGtkSourceSpaceTypeFlags.
-
builder
ASpaceDrawer.Builderobject constructs aSpaceDrawerwith the specified properties. Use the variousset...()methods to set properties, and finish construction withSpaceDrawer.Builder.build().- Returns:
- the builder object
-