Class VimIMContext
- All Implemented Interfaces:
Proxy
The GtkSourceVimIMContext is a IMContext implementation that can
be used to provide Vim-like editing controls within a View.
The GtkSourceViMIMContext will process incoming KeyEvent as the
user types. It should be used in conjunction with a EventControllerKey.
Various features supported by GtkSourceVimIMContext include:
- Normal, Insert, Replace, Visual, and Visual Line modes
- Support for an integrated command bar and current command preview
- Search and replace
- Motions and Text Objects
- History replay
- Jumplists within the current file
- Registers including the system and primary clipboards
- Creation and motion to marks
- Some commonly used Vim commands
It is recommended that applications display the contents of
VimIMContext:command-bar-text and
VimIMContext:command-text to the user as they represent the
command-bar and current command preview found in Vim.
GtkSourceVimIMContext attempts to work with additional IMContext
implementations such as IBus by querying the TextView before processing
the command in states which support it (notably Insert and Replace modes).
GtkEventController *key;
GtkIMContext *im_context;
GtkWidget *view;
view = gtk_source_view_new ();
im_context = gtk_source_vim_im_context_new ();
key = gtk_event_controller_key_new ();
gtk_event_controller_key_set_im_context (GTK_EVENT_CONTROLLER_KEY (key), im_context);
gtk_event_controller_set_propagation_phase (key, GTK_PHASE_CAPTURE);
gtk_widget_add_controller (view, key);
gtk_im_context_set_client_widget (im_context, view);
g_object_bind_property (im_context, "command-bar-text", command_bar_label, "label", 0);
g_object_bind_property (im_context, "command-text", command_label, "label", 0);
key = Gtk.EventControllerKey.new()
im_context = GtkSource.VimIMContext.new()
buffer = GtkSource.Buffer()
view = GtkSource.View.new_with_buffer(buffer)
key.set_im_context(im_context)
key.set_propagation_phase(Gtk.PropagationPhase.CAPTURE)
view.add_controller(key)
im_context.set_client_widget(view)
im_context.bind_property(
source_property="command-text",
target=command_label,
target_property="label",
flags=GObject.BindingFlags.DEFAULT,
)
im_context.bind_property(
source_property="command-bar-text",
target=command_bar_label,
target_property="label",
flags=GObject.BindingFlags.DEFAULT,
)
- Since:
- 5.4
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classVimIMContext.Builder<B extends VimIMContext.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static interfaceFunctional interface declaration of theEditCallbackcallback.static interfaceFunctional interface declaration of theExecuteCommandCallbackcallback.static interfaceFunctional interface declaration of theFormatTextCallbackcallback.static classstatic interfaceFunctional interface declaration of theWriteCallbackcallback.Nested classes/interfaces inherited from class org.gnome.gtk.IMContext
IMContext.CommitCallback, IMContext.DeleteSurroundingCallback, IMContext.IMContext$Impl, IMContext.IMContextClass, IMContext.PreeditChangedCallback, IMContext.PreeditEndCallback, IMContext.PreeditStartCallback, IMContext.RetrieveSurroundingCallbackNested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new VimIMContext.VimIMContext(MemorySegment address) Create a VimIMContext proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected VimIMContextasParent()Returns this instance as if it were its parent type.static VimIMContext.Builder<? extends VimIMContext.Builder> builder()AVimIMContext.Builderobject constructs aVimIMContextwith the specified properties.voidEmits the "edit" signal.booleanemitExecuteCommand(String command) Emits the "execute-command" signal.voidemitFormatText(@Nullable TextIter begin, @Nullable TextIter end) Emits the "format-text" signal.voidEmits the "write" signal.voidexecuteCommand(String command) Executescommandas if it was typed into the command bar by the user except that this does not emit theVimIMContext::execute-commandsignal.Gets the current command-bar text as it is entered by the user.Gets the current command text as it is entered by the user.static @Nullable TypegetType()Get the GType of the VimIMContext classonEdit(VimIMContext.EditCallback handler) Requests the application open the file found atpath.The signal is emitted when a command should be executed.Requests that the application format the text betweenbeginandend.onWrite(VimIMContext.WriteCallback handler) Requests the application save the file.Methods inherited from class org.gnome.gtk.IMContext
activateOsk, activateOsk, activateOskWithEvent, commit, deleteSurrounding, emitCommit, emitDeleteSurrounding, emitPreeditChanged, emitPreeditEnd, emitPreeditStart, emitRetrieveSurrounding, filterKey, filterKey, filterKeypress, focusIn, focusOut, getMemoryLayout, getPreeditString, getSurrounding, getSurroundingWithSelection, onCommit, onDeleteSurrounding, onPreeditChanged, onPreeditEnd, onPreeditStart, onRetrieveSurrounding, preeditChanged, preeditEnd, preeditStart, reset, retrieveSurrounding, setClientWidget, setCursorLocation, setSurrounding, setSurroundingWithSelection, setUsePreeditMethods 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, 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
-
VimIMContext
Create a VimIMContext proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
VimIMContext
public VimIMContext()Creates a new VimIMContext.
-
-
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. -
executeCommand
Executescommandas if it was typed into the command bar by the user except that this does not emit theVimIMContext::execute-commandsignal.- Parameters:
command- the command text- Since:
- 5.4
-
getCommandBarText
Gets the current command-bar text as it is entered by the user.- Returns:
- A string containing the command-bar text
- Since:
- 5.4
-
getCommandText
Gets the current command text as it is entered by the user.- Returns:
- A string containing the command text
- Since:
- 5.4
-
onEdit
Requests the application open the file found atpath.If
pathisnull, then the current file should be reloaded from storage.This may be executed in relation to the user running the
:editor:ecommands.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- Since:
- 5.4
- See Also:
-
emitEdit
Emits the "edit" signal. SeeonEdit(org.gnome.gtksourceview.VimIMContext.EditCallback). -
onExecuteCommand
public SignalConnection<VimIMContext.ExecuteCommandCallback> onExecuteCommand(VimIMContext.ExecuteCommandCallback handler) The signal is emitted when a command should be executed. This might be something like:wqor:e <path>.If the application chooses to implement this, it should return
truefrom this signal to indicate the command has been handled.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- Since:
- 5.4
- See Also:
-
emitExecuteCommand
Emits the "execute-command" signal. SeeonExecuteCommand(org.gnome.gtksourceview.VimIMContext.ExecuteCommandCallback). -
onFormatText
public SignalConnection<VimIMContext.FormatTextCallback> onFormatText(VimIMContext.FormatTextCallback handler) Requests that the application format the text betweenbeginandend.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- Since:
- 5.4
- See Also:
-
emitFormatText
Emits the "format-text" signal. SeeonFormatText(org.gnome.gtksourceview.VimIMContext.FormatTextCallback). -
onWrite
Requests the application save the file.If a filename was provided, it will be available to the signal handler as
path.This may be executed in relation to the user running the:writeor:wcommands.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- Since:
- 5.4
- See Also:
-
emitWrite
Emits the "write" signal. SeeonWrite(org.gnome.gtksourceview.VimIMContext.WriteCallback). -
builder
AVimIMContext.Builderobject constructs aVimIMContextwith the specified properties. Use the variousset...()methods to set properties, and finish construction withVimIMContext.Builder.build().- Returns:
- the builder object
-