Repository navigation
API 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.
CM_GOTO_LINE, EDITOR_COMMANDS, save_changes, overwrite_changed, lf_location, EditorMixin
10294
frozenset (7 entries)
def save_changes(name: str) -> MessageBoxClosing a window (or the application) with unsaved changes: Yes saves, No discards, Cancel keeps it.
def overwrite_changed(name: str) -> MessageBoxThe file changed on disk since it was opened: replace it, or keep the disk's version.
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 EditorMixinOpen, 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'sfolderby 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 towindow.path(maybe a new one: Save as). Cooperative. -
after_close(window: EditorWindow) -> None:windowwas closed (itspathstill says which file it had). Cooperative. -
editor_changed(window: EditorWindow) -> None: An editor's text changed (EditorWindowsays so). Cooperative. -
cursor_moved(window: EditorWindow) -> None: An editor's cursor or selection moved (EditorWindowsays so). Cooperative. -
editors() -> list[EditorWindow]: The editor windows, bottom to top. -
editor_for(path: Path | None) -> EditorWindow | None: The editor ofpath(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...) holdingtext, which counts as unsaved. -
async open_file(path: Path) -> EditorWindow | None:pathin 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 (topath: 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: Closewindowwithout asking (its file was deleted or replaced, or its changes were declined). -
async close_editor(window: EditorWindow) -> bool: Closewindow; with unsaved changes, ask first. False when the user kept it open. -
request_close(window: Window) -> None: The close icon ofwindow(an editor asks about unsaved changes first). -
async close_window(window: Window) -> bool: Closewindow: an editor throughclose_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 ofwindow(the active editor). -
goto_location(path: Path | None, start: int, end: int | None = None) -> None: Openpathand selectstarttoend, offsets counted with\nnewlines (what Find in files' results, the references and the problems give). -
select_in(window: EditorWindow, start: int, end: int | None = None) -> None: Raisewindowand selectstarttoendin it (offsets into its text). -
select_in_lf(window: EditorWindow, start: int, end: int | None = None) -> None:select_infor offsets counted with\nnewlines (lf_location). -
async editor_command(command: int, info: object = None) -> bool: Run one ofEDITOR_COMMANDS(from a worker):infois 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.
TurboFrame · part of Divengine · GPL-3.0-or-later · report an issue
Tutorial
Examples
The desktop
- The Desktop
- Application Mixins
- Windows and Lists
- Dialogs
- Histories
- Progress
- Themes and Colors
- Glyphs
- Settings and Recent Files
- Command Palette
Editing
Tasks
Languages
Running
Reference
Links