Repository navigation
API turboframe.ui.findfiles
Source: turboframe/ui/findfiles.py. Generated from the code of TurboFrame 0.3.0 by tools/wiki_api.py.
Find in files (Borland Pascal's Tools > Grep): a text in every file of a folder.
Search > Find looks in the file being edited; this looks in all of the folder's files (turboframe.files.project_files: git's list when the folder is a repository, else a walk that skips caches, virtual environments and node_modules), or the ones a mask names (*.py;*.md), with the Find dialog's options: case sensitive, whole words only, regular expression. The files open in editors are searched as they are being edited, saved or not.
It is bounded for large source trees: at most MAX_FILES files, MAX_MATCHES matches and MAX_SECONDS seconds, files over MAX_TEXT_BYTES skipped; it runs in a thread, so the desktop stays responsive, and the application is told when a bound stopped it.
What it finds goes to a window, as Turbo Pascal's grep put it in the Messages window: parts/header.tpl(12): <the line>, a row per line with a match; Enter (or a double click) calls the application's goto_location with the match.
An application mixes FindInFilesMixin into its DesktopApp and calls find_in_files() from a worker (a menu command). The mixin's hooks say where to look and where the results go; their defaults suit an application whose editor windows have path and editor (a TextArea).
MAX_MATCHES, MAX_SECONDS, MAX_SHOWN_LINE, Hit, masks, wanted, search, FindInFilesDialog, FindResultsWindow, result_items, FindInFilesMixin
2000
20.0
200
class Hit
Hit(rel: str, line: int, start: int, end: int, text: str)A match: the file (relative, with /), its line (1-based), its offsets in the file's text, and the line, trimmed.
def masks(text: str) -> list[str]The masks of *.py;*.md (separated by ;, , or spaces); * when there is none.
def wanted(rel: str, patterns: list[str]) -> boolA mask matches the file's name or its relative path.
def search(root: Path, files: list[str], pattern: re.Pattern[str], *, edited: dict[str, str] | None = None, limit: int = 2000, seconds: float = 20.0) -> tuple[list[Hit], int]Every match of pattern in files (relative to root); edited holds the texts of the files open in editors. Returns the hits (at most limit, found within seconds) and how many files had one.
class FindInFilesDialog(TVDialog)
FindInFilesDialog(query: str, options: SearchOptions)The text, the files to look in and the Find dialog's options. MASK_HINT is the example of masks its label shows: an application sets the kinds of files it works with.
valid(command: Command) -> bool
class FindResultsWindow(LocationsWindow)
FindResultsWindow(number: int = 0)What Find in files found, one row per line with a match.
def result_items(root: Path, query: str, mask: str, hits: list[Hit], in_files: int) -> list[MessageItem]The heading, then a row per line with a match (the first one on it is the one selected).
class FindInFilesMixinFind in files, mixed into a DesktopApp: await self.find_in_files() from a worker.
The last text and options are kept in search_text and search_options, which Search > Find can share. The hooks below have defaults; an application overrides the ones that differ.
-
find_files_root() -> Path | None: The folder to look in: the application'sfolderby default. -
find_files_edited() -> list[tuple[Path | None, str]]: The open editors' files and texts, searched instead of the disk: by default every window with apathand aneditorholdingtext. -
find_files_selection() -> str: The text to start with: the active window's selection when it is on one line. -
async find_files_no_root() -> None: There is no folder to look in. -
show_find_results(window: FindResultsWindow) -> FindResultsWindow: Put a new results window on the desktop (an application places it, along the bottom for example). find_results_window() -> FindResultsWindow | Noneasync find_in_files() -> 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