Skip to content

API turboframe.ui.editing

rafageist edited this page Dec 4, 2026 · 4 revisions

turboframe.ui.editing

Source: turboframe/ui/editing.py. Generated from the code of TurboFrame 0.3.0 by tools/wiki_api.py.

The editors' application flows: File > New, Open, Save, Save as, Save all, closing, Search > Go to line.

EditorMixin is part of the application (a DesktopApp). It owns the editor windows (turboframe.ui.editor.EditorWindow):

  • New opens an untitled window (NONAME00, NONAME01...); saving it asks for a name (Save as).
  • Open reads a file safely (turboframe.files.read_source: not binary, UTF-8, not too large) into its window, or brings up the window that already has it.
  • Save writes atomically (turboframe.files.write_source) and, when another program changed the file since it was read, asks before overwriting it. Save as asks before replacing a file, and refuses a file open in another window. Save all saves every window with changes.
  • Closing a window with unsaved changes asks: Yes saves, No discards, Cancel keeps it open (the close icon goes through request_close). close_all() does it for every editor, before the application exits.
  • Go to line (CM_GOTO_LINE) moves the cursor of the active editor; goto_location(path, start, end) opens a file and selects a range in it (Find in files' results, references, problems).

The application's parts are hooks with defaults: EDITOR_WINDOW (the window's class), editor_root() (the folder the titles are relative to), place_editor(window), after_open(window), after_save(window) and after_close(window). The after_* hooks, editor_changed and cursor_moved are cooperative: an override calls super(), so other mixins (turboframe.ui.git, turboframe.ui.lsp) hear them too. editor_command(command, info) runs the File commands and Go to line for the application's run_command.

editors, open_file and discard_editor are this mixin's whatever the order of the bases: the explorer's (turboframe.ui.explorer.ExplorerMixin) and git's (turboframe.ui.git.GitMixin) defer to them.

Contents

CM_GOTO_LINE, EDITOR_COMMANDS, save_changes, overwrite_changed, lf_location, EditorMixin

CM_GOTO_LINE

10294

EDITOR_COMMANDS

frozenset (7 entries)

save_changes

def save_changes(name: str) -> MessageBox

Closing a window (or the application) with unsaved changes: Yes saves, No discards, Cancel keeps it.

overwrite_changed

def overwrite_changed(name: str) -> MessageBox

The file changed on disk since it was opened: replace it, or keep the disk's version.

lf_location

def lf_location(text: str, offset: int) -> tuple[int, int]

The (row, column) in text of an offset counted with \n newlines: a file with \r\n newlines counts one character less per line than the editor's text.

class EditorMixin

class EditorMixin

Open, save, save as, close, go to line and select, mixed into a DesktopApp.

Hooks (with defaults): EDITOR_WINDOW, editor_root(), place_editor(window), after_open(window), after_save(window), after_close(window); editor_changed(window) and cursor_moved(window) are the editor windows' own. The after_* hooks and the editor's two are cooperative (call super()).

  • editor_root() -> Path | None: The folder the windows' titles are relative to: the application's folder by default.
  • place_editor(window: EditorWindow) -> None: Put a new editor window on the desktop (an application places it, or tiles the editors).
  • after_open(window: EditorWindow) -> None: A new editor window is on the desktop (its file read, or untitled). Cooperative.
  • after_save(window: EditorWindow) -> None: window's text was written to window.path (maybe a new one: Save as). Cooperative.
  • after_close(window: EditorWindow) -> None: window was closed (its path still says which file it had). Cooperative.
  • editor_changed(window: EditorWindow) -> None: An editor's text changed (EditorWindow says so). Cooperative.
  • cursor_moved(window: EditorWindow) -> None: An editor's cursor or selection moved (EditorWindow says so). Cooperative.
  • editors() -> list[EditorWindow]: The editor windows, bottom to top.
  • editor_for(path: Path | None) -> EditorWindow | None: The editor of path (resolved), if one has it open.
  • active_editor() -> EditorWindow | None: The active window when it is an editor, else the editor nearest the top (None without editors).
  • new_file(text: str = '') -> EditorWindow: An untitled window (NONAME00...) holding text, which counts as unsaved.
  • async open_file(path: Path) -> EditorWindow | None: path in its editor (opened if it is not), on top; None when it cannot be opened (said).
  • async choose_and_open() -> EditorWindow | None: File > Open: the file dialog, from the folder of the file being edited (or the open folder).
  • async save(window: EditorWindow, path: Path | None = None) -> bool: Write the editor's text (to path: Save as). An untitled window asks for a name. Asks before overwriting a file another program changed. False when nothing was written.
  • async save_as(window: EditorWindow) -> bool: Save under a name the file dialog asks for: a file there is replaced only when the user says so, and never one open in another window.
  • async save_all() -> bool: Save every window with unsaved changes; False when one was not saved (the rest are not tried).
  • discard_editor(window: EditorWindow) -> None: Close window without asking (its file was deleted or replaced, or its changes were declined).
  • async close_editor(window: EditorWindow) -> bool: Close window; with unsaved changes, ask first. False when the user kept it open.
  • request_close(window: Window) -> None: The close icon of window (an editor asks about unsaved changes first).
  • async close_window(window: Window) -> bool: Close window: an editor through close_editor. False when it stays open.
  • async close_all() -> bool: Close every editor, asking about each one with unsaved changes (before the application exits). False when the user kept one open: the rest stay too.
  • async goto_line(window: EditorWindow | None = None) -> None: Search > Go to line: the dialog, then the cursor on that line of window (the active editor).
  • goto_location(path: Path | None, start: int, end: int | None = None) -> None: Open path and select start to end, offsets counted with \n newlines (what Find in files' results, the references and the problems give).
  • select_in(window: EditorWindow, start: int, end: int | None = None) -> None: Raise window and select start to end in it (offsets into its text).
  • select_in_lf(window: EditorWindow, start: int, end: int | None = None) -> None: select_in for offsets counted with \n newlines (lf_location).
  • async editor_command(command: int, info: object = None) -> bool: Run one of EDITOR_COMMANDS (from a worker): info is a path for Open, a window for Close. False when the command is not one of them, or needs an editor and there is none.

Clone this wiki locally