11 Editor
Classes matching this interface support the basic
editor<%>
functionality required by the framework.
This function returns
#t when the editor has the keyboard
focus. It is implemented using:
on-focusIndicates if this editor is in an edit sequence. Enclosing buffer’s
edit-sequence status is not considered by this method.
See
begin-edit-sequence
and
end-edit-sequence
for more info about edit sequences.
This method is used to install callbacks that will be run after any
edit-sequence completes.
The procedure thunk will be called immediately if the edit is
not in an edit-sequence. If the edit is in an edit-sequence, it will
be called when the edit-sequence completes.
If tag is a symbol, the thunk is keyed on that symbol, and
only one thunk per symbol will be called after the
edit-sequence. Specifically, the last call to
run-after-edit-sequence’s argument will be called.
This does not work for embedded editors.
Returns #t if the file on disk has been modified, by some other program.
|
→ boolean? |
filename : (or/c path? #f) = #f |
| format | | : | | (or/c 'guess 'standard 'text 'text-force-cr 'same 'copy) | | | | = | | 'same |
|
show-errors? : boolean? = #t |
This method is an alternative to
save-file. Rather than showing errors via
the original stdout, it opens a dialog with an error message
showing the error.
It returns #t if no error occurred and cancel was
not clicked, and it returns #f if an error occurred
or cancel was clicked.
Loads
filename, much like
load-file. Rather than showing errors via
the original stdout, however, it shows a dialog box when an
error occurs.
The result indicates if an error happened (the error has
already been shown to the user). It returns #t if
no error occurred and #f if an error occurred.
Reverts the content of the editor to the file on the disk,
showing errors to the user via
load-file/gui-error.
The result indicates if an error happened (the error has
already been shown to the user). It returns #t if
no error occurred and #f if an error occurred.
If get-filename returns #f or
if the filename is a temporary filename, the buffer is unchanged
and the result is #f.
This method is called when an editor is closed.
Typically, this method is called when the frame
containing the editor is closed, but in some cases an
editor is considered “closed” before the frame it is
in is closed (e.g., when a tab in DrRacket is closed), and
thus
on-close will be called at that point.
See also can-close? and close.
Default: does nothing.
This method is called to query the editor if is okay to
close the editor. Although there is no visible effect
associated with closing an editor, there may be some cleanup
actions that need to be run when the user is finished with
the editor (asking if it should be saved, for example).
See also
on-close and
close.
Returns #t.
This method is merely
(if (can-close?) |
(begin (on-close) #t) |
#f) |
It is intended as a shorthand, helper method for closing
an editor. See also
can-close?
and
on-close.
Returns the printed version of the filename for this
editor. If the editor doesn’t yet have a filename, it
returns a symbolic name (something like "Untitled").
This method’s first result is #f when the mouse
event does not correspond to a location in the editor.
If the second result is a text% object, then the
first result will be a position in the editor and
otherwise the first result will be #f.
The
editor<%> object will always be the nearest
enclosing editor containing the point (
x,
y).
This provides the basic editor services required by the rest of the
framework.
The result of this mixin uses the same initialization arguments as the
mixin’s argument.
Each instance of a class created with this mixin contains a private
keymap% that is chained to the global keymap via:
(send keymap chain-to-keymap (keymap:get-global) #f).
This installs the global keymap
keymap:get-global to
handle keyboard and mouse mappings not handled by
keymap. The
global keymap is created when the framework is invoked.
Checks to see if the file on the disk has been modified out
side of this editor, using
save-file-out-of-date?.
If it has, this method prompts the user to be sure they want to save.
If the current filename is not a temporary filename, this method calls
handler:add-to-recentwith the current filename.
to add the new filename to the list of recently opened files.
Additionally, updates a private instance variable with the
modification time of the file, for using in implementing
save-file-out-of-date?.
Updates a private instance variable with the modification
time of the file, for using in implementing
save-file-out-of-date?(super on-new-image-snip |
(if (eq? kind 'unknown) 'unknown/mask kind) |
relative-path? |
inline?) |
In addition, it calls
set-load-overwrites-styles
with
#f.
This ensures that saved files with different
settings for the style list do not clobber
the shared style list.
Classes matching this interface add support for mixing in multiple
keymaps. They provides an extensible interface to chained keymaps,
through the
get-keymaps
method.
The keymaps returned from this method are chained to this
editor<%>’s keymap.
The result of this method should not change – that is, it
should return the same list of keymaps each time it is
called.
See also editor:add-after-user-keymap.
Classes implementing this interface keep the
auto-wrap
state set based on the
'framework:auto-set-wrap? preference
(see
preferences:get for more information about preferences).
Objects supporting this interface are expected to support files.
The result of this method is used as the parent for the
dialog that asks about closing.
Returns #f by default.
Attempts to find a frame that displays this editor. If it
does, it updates the frame’s title based on a new filename
in the editor.
This method indicates if closing the file when it hasn’t
been saved is a reason to alert the user. See also
can-close?.
Returns #f by default.
If the file has not been saved, this prompts the user about saving and,
if the user says to save, then it saves the file.
The result is #t if the save file is up to date, or if
the user says it is okay to continue without saving. Generally used
when closing the file or quiting the app.
This editor locks itself when the file that is opened is read-only in
the filesystem.
The class that this mixin produces uses the same initialization
arguments as its input.
Updates the filename on each frame displaying this editor, for each
frame that matches
frame:editor<%>.
If the
allow-close-with-no-filename?
method returns
#f, this method checks to see if the file
has been saved at all yet. If not, it asks the user
about saving (and saves if they ask).
If the
allow-close-with-no-filename?
method returns #t, this method does as before,
except only asks if the editor’s
get-filenamemethod returns a path.
Also calls inner.
This returns a list containing the super-class’s keymaps, plus the
result of
keymap:get-file
Classes matching this interface support backup files and autosaving.
Indicates whether this
editor<%>
should be backed up.
Returns the value of the
preferences:get applied to
'framework:backup-files?.
Indicates whether this
editor<%>
should be autosaved.
Returns #t.
When the file has been modified since it was last saved and autosaving it
turned on (via the autosave? method) an
autosave file is created for this editor<%>.
Returns the filename where the autosave took place, or
#f if none
did. This method sets the parameter
editor:doing-autosave? to
#t during the dynamic extent of the call it makes to
save-file.
This method removes the autosave file associated with this
editor<%>.
This mixin adds backup and autosave functionality to an editor.
The result of this mixin uses the same initialization arguments as the
mixin’s argument.
|
→ boolean? |
filename : path? |
format : (or/c 'guess 'standard 'text 'text-force-cr 'same 'copy) |
If a backup file has not been created this session for this file,
deletes any existing backup file and copies the old save file into the
backup file. For the backup file’s name, see
path-utils:generate-backup-name
Deletes the autosave file and turns off autosaving.
Sets a flag indicating that this
editor<%> needs to be autosaved.
If the file is no longer modified, this method deletes the autosave
file. If it is, it updates a flag to indicate that the autosave file
is out of date.
This interface does not add any methods, but signals
that the given class was produced by
editor:autoload-mixin.
The result of this mixin uses
filesystem-change-evt to track
changes to the file that this editor saves to, offering to
revert the buffer to match the file when the file changes.
It strives to make sure that there is never a moment when
the file is unmonitored so there should be no races with
other processes. That said a call to
set-filename will disrupt the
connection.
The result of this mixin calls
enable-sha1 during
initialization of the object.
Disables the monitoring, unless the call is in the dynamic extent of
a call to
load-file
or
save-file.
|
filename : path? |
format : (or/c 'guess 'standard 'text 'text-force-cr 'same 'copy) |
Establishes the monitoring of
filename and ties it to this
editor<%>.
Uses the updated sha1 from
get-file-sha1, now that the editor’s content
and the file on the disk have been synchronized.
|
filename : path? |
format : (or/c 'guess 'standard 'text 'text-force-cr 'same 'copy) |
Establishes the monitoring of
filename and ties it to this
editor<%>.
Uses the updated sha1 from
get-file-sha1, now that the editor’s content
and the file on the disk have been synchronized.
The message field controls the initial contents. If there
is a list of strings, then each string is put on a separate line.
If there is just a single string, it is split on newlines and then
treated as if it were a list.
The stretchable-height has the opposite default from the
canvas% superclass.
Changes the message.
If message is a list of strings, then each
string is put on a separate line. If there is just a
single string, it is split on newlines and then treated as
if it were a list argument.
A parameter that indicates whether or not we are currently saving
the editor because of an autosave. See also
do-autosave.
Sets the font preference for the current monitor configuration to
new-size.
Determines the current monitor configuration and uses that to pick
one of the sizes from its argument. The argument is expected
to come from the preference value of 'framework:standard-style-list:font-size.
Except if editor:get-change-font-size-when-monitors-change? returns
#f, in which case the current monitor configuration is not considered
and the last-set size (the second position in the vector) is always returned.
As background, the font size
preference is actually saved on a per-monitor configuration basis; specifically
the preference value (using the same contract as the argument of this function)
contains a table mapping a list of monitor sizes (but not their
positions) obtained by get-display-size to the preferred font size
(plus a default size used for new configurations).
Returns
#t when the framework will automatically
adjust the current font size in the
"Standard"
style of the result of
editor:get-standard-style-list
based on the monitor configuration.
Defaults to #f
If the style named by name is already in the style list, it must
be a delta style.
Returns a style list that is used for all instances of
editor:standard-style-list%.
Returns a list that contains all of the keymaps in
keymaps, in the
same relative order, but also with
keymap, where
keymap
is now the first keymap after
keymap:get-user (if that keymap is
in the list.)