pub struct FileDialog { /* private fields */ }Expand description
A Dialog that assembles the file picker — the directory/file panes
(FileList, FileInputLine, FileInfoPane) plus a filename label, a
history icon, a scroll bar, and the action buttons — into a working file
dialog.
The file-selection dialog and its building blocks: FileDialog,
ChDirDialog, the directory/file panes (FileList, DirListBox,
FileInfoPane, FileInputLine), and the data types they hold
(DirEntry, SearchRec, DirCollection, FileCollection).
DirEntry/SearchRec/DirCollection/FileCollection are pure data;
DirListBox is the directory-tree pane, a concrete
ListViewer over a
Vec<DirEntry> that renders a tree-indented listing.
Following tvision-rs’s “collections become Vec” convention, DirCollection is a
plain Vec<DirEntry> alias and FileCollection is a Vec<SearchRec> carrying
only the one piece of real logic — the sorted insert and its comparator. The
general-purpose collection API (index-of, remove, replace-at, find-first, …) is
omitted; nothing here needs it.
§Native paths
Paths are native and /-separated, enumerated with std::fs::read_dir. There
is no DOS drive-letter machinery (drive scanning, \-separators); it has no
Linux counterpart and is omitted.
§Structural shape
This embeds a Dialog and forwards the un-overridden
View methods (embed-and-delegate composition). It
overrides only handle_event, reset_current, and as_any_mut (so the
modal loop / the owner-downcast target is the FileDialog, not the inner
Dialog). The 49×19 minimum (TFileDialog::sizeLimits) is pushed into the
embedded window via set_min_size at construction (D16), so every clamp
path — including the interactive corner drag — honors it through the
delegated size_limits.
§Native paths
The initial directory comes from std::env::current_dir, normalized to end
with / (the FileList::read_directory trailing-slash precondition). No
drive letters, no backslashes.
The screen-relative percentage resize is applied at the first handle_event
call (when ctx.owner_size() is available) rather than at construction, since
there is no Context in the constructor; this happens before the first draw.
§Turbo Vision heritage
Ports the TFileDialog family — TFileDialog, TChDirDialog, TFileList,
TDirListBox, TFileInfoPane, TFileInputLine, plus TDirEntry,
TSearchRec, TDirCollection, TFileCollection (filedial.cpp,
fileopen.cpp, tfildlg.cpp and headers). The DOS file model is re-imagined
for native Linux /-paths (deviation D14); TCollections become Vecs and
TStreamable persistence is dropped (deviation D12).
Ports TFileDialog (tfildlg.cpp/stddlg.h), a dialog subclass; here it
becomes embed-and-delegate composition (deviation D2), the DOS path model
becomes native /-paths (deviation D14), and persistence is dropped
(deviation D12).
Implementations§
Source§impl FileDialog
impl FileDialog
Sourcepub fn new(
wild_card: impl Into<String>,
title: impl Into<String>,
input_name: impl Into<String>,
options: u16,
history_id: u8,
) -> Self
pub fn new( wild_card: impl Into<String>, title: impl Into<String>, input_name: impl Into<String>, options: u16, history_id: u8, ) -> Self
Build a file dialog with the given mask, title, prompt label, options, and history id.
wild_card— initial glob mask (e.g."*.rs"); shown in the filename field and used to filter the file list.title— the dialog window title (e.g."Open File").input_name— the label above the filename field (e.g."~F~ile name").options— bitwise OR ofFD_*constants controlling which action buttons appear and whether the listing loads immediately.history_id— identifies the history bucket for the filename field; use a unique constant per dialog type across the application.
Assembles the children in a fixed insertion order (so the labels/history
can link to the already-created input-line / file-list ids, and
reset_current focuses the first selectable = the input line). Each
child’s grow_mode is set before insert for correct resize behaviour.
Sourcepub fn get_file_name(&mut self) -> String
pub fn get_file_name(&mut self) -> String
Resolve the input-line text into an absolute, normalized filename relative
to directory.
Steps: expand the field text against directory
(expand_path), then split off the filename (split_dir_file); when
the resolved path is a bare directory (no filename part) the wildcard is
appended. With native paths the wildcard is its own filename, so
self.wild_card is appended directly.
&mut self (not &self): it reads the FileInputLine via child_mut.
It is only called from valid (which has &mut self)
and refreshes resolved_name so the &self
value can return the result without child_mut.
Trait Implementations§
Source§impl View for FileDialog
impl View for FileDialog
Source§fn handle_event(&mut self, ev: &mut Event, ctx: &mut Context<'_>)
fn handle_event(&mut self, ev: &mut Event, ctx: &mut Context<'_>)
Run the embedded dialog’s event handling first, then:
- a file-open / file-replace / file-clear command → end the modal loop with
that command + clear the event. (The path-check gate is
valid(), run by the modal loop on close.) - a “file double-clicked” broadcast → re-post as an OK command + clear. The embedded dialog then turns the OK into a modal close on the next cycle.
One-time pre-delegate work (before the embedded call): if
needs_screen_resize is true and the screen size is available from
ctx.owner_size(), applies the screen-relative percentage resize. It runs
at the first handle_event where ctx.owner_size() is non-zero (set by the
owning group), before any event reaches the children — so before the first
draw.
Source§fn reset_current(&mut self, ctx: &mut Context<'_>)
fn reset_current(&mut self, ctx: &mut Context<'_>)
Framework init hook: called by the modal loop when the dialog first becomes
the current view (i.e., when Program::run_modal activates it).
Focuses the filename input line, then — once, unless FD_NO_LOAD_DIR was
passed to FileDialog::new — reads std::env::current_dir into the
FileList (with scrollbar sync and focused-file broadcast) and refreshes
the FileInfoPane’s cached directory and wildcard. You do not call this
directly; use FD_NO_LOAD_DIR to suppress the initial directory read if the
dialog is shown before the working directory is set.
Source§fn as_any_mut(&mut self) -> Option<&mut dyn Any>
fn as_any_mut(&mut self) -> Option<&mut dyn Any>
The modal loop and any owner-downcast target must reach the FileDialog,
so as_any_mut returns self, NOT the inner Dialog.
Source§fn valid(&mut self, cmd: Command, ctx: &mut Context<'_>) -> bool
fn valid(&mut self, cmd: Command, ctx: &mut Context<'_>) -> bool
The navigate/accept gate.
- On the VALID command →
trueimmediately, before the group check. - else run the embedded dialog’s group validation first; on its
false→false(keep open). - on group-valid, for the accept commands (NOT cancel / file-clear):
resolve the filename, then
- wildcard → NAVIGATE: split into dir+wildcard, check the directory,
on success set
directory/wild_card+ re-read; always fall through tofalse(keep open). - existing directory → NAVIGATE into it: check it, on success append
/, setdirectory, re-read;false. - valid filename → ACCEPT (
true). - else → “invalid file name” box +
false.
- wildcard → NAVIGATE: split into dir+wildcard, check the directory,
on success set
- cancel / file-clear →
true(always valid, after the group check — file-clear must still pass the group).
Refreshes resolved_name via get_file_name
for every non-VALID command, so the &self value() is current after any
such call — including the cancel / file-clear path that returns before the
branches.
Source§fn value(&self) -> Option<FieldValue>
fn value(&self) -> Option<FieldValue>
Returns the resolved filename as FieldValue::Text(path).
The modal gather reads this immediately after valid(end_state) returns
true, so you typically access it indirectly: run the dialog modally, then
call dialog.value() (or let the gather scatter it). On a cancel or
file-clear close the value is still valid — valid() resolves the field text
unconditionally on every non-VALID command, so the cache is always current.
Source§fn set_value(&mut self, v: FieldValue)
fn set_value(&mut self, v: FieldValue)
Pre-fill the filename field from a FieldValue::Text.
Use this before the dialog opens to seed the field with a default path (the
scatter half of dialog data transfer). Note that set_value cannot also
trigger a directory navigation or focus request, because it has no
&mut Context — if you need the listing to reflect the pre-filled path,
let reset_current handle it (which reads the process cwd on first show)
or open the dialog without FD_NO_LOAD_DIR.
Source§fn draw(&mut self, ctx: &mut DrawCtx<'_>)
fn draw(&mut self, ctx: &mut DrawCtx<'_>)
ctx. Must be overridden. Read moreSource§fn set_state(&mut self, flag: StateFlag, enable: bool, ctx: &mut Context<'_>)
fn set_state(&mut self, flag: StateFlag, enable: bool, ctx: &mut Context<'_>)
StateFlag::Focused, emits the focus broadcast
(RECEIVED_FOCUS/RELEASED_FOCUS) via ctx. Read moreSource§fn set_modal_answer(&mut self, cmd: Command)
fn set_modal_answer(&mut self, cmd: Command)
Context::request_message_box (the
answer_to/RouteModalAnswer round-trip). Default: no-op. Overridden by
views that drive a Yes/No/Cancel prompt out of valid (e.g.
FileEditor caches it for the re-validate).Source§fn set_modal_data(&mut self, data: FieldValue)
fn set_modal_data(&mut self, data: FieldValue)
Source§fn set_value_ctx(&mut self, v: FieldValue, ctx: &mut Context<'_>)
fn set_value_ctx(&mut self, v: FieldValue, ctx: &mut Context<'_>)
FieldValue into this control with a Context. Default:
calls set_value (the context-free setter). Override
when scatter needs deferred publishing (e.g.
ListBox republishes its vertical scrollbar via
focus_item).Source§fn awaken(&mut self)
fn awaken(&mut self)
Source§fn change_bounds(&mut self, bounds: Rect)
fn change_bounds(&mut self, bounds: Rect)
bounds to this view and propagate as needed. Read moreSource§fn on_bounds_changed(&mut self, ctx: &mut Context<'_>)
fn on_bounds_changed(&mut self, ctx: &mut Context<'_>)
change_bounds is applied via
Deferred::ChangeBounds — provides a
Context for re-publishing state that depends on the new bounds (e.g. scrollbar
params). Default implementation is a no-op. Read moreSource§fn cursor_request(&self) -> Option<Point>
fn cursor_request(&self) -> Option<Point>
None to
hide it. Base: Some(cursor) iff the view is focused with a visible cursor,
else None. Read moreSource§fn caret_size(&self) -> u8
fn caret_size(&self) -> u8
CARET_INSERT (a block) when the
cursor_ins state is set, else
CARET_NORMAL (the normal caret).
The event loop reads it along the same focused chain as
cursor_request;
Group overrides it to descend into its current
child. Read moreSource§fn find_mut(&mut self, id: ViewId) -> Option<&mut dyn View>
fn find_mut(&mut self, id: ViewId) -> Option<&mut dyn View>
id to a descendant of this view (never self — the parent
identifies a view by id). A leaf has no descendants, so the base returns
None; a Group overrides to search its children
and recurse; a Group-embedding view delegates to its inner group. This is
the “tree-walk via Context” — the uniform way the event loop
/ a capture handler acts on a view it holds only by id (move a window’s
bounds, flip the dragging flag, …).Source§fn remove_descendant(&mut self, id: ViewId, ctx: &mut Context<'_>) -> bool
fn remove_descendant(&mut self, id: ViewId, ctx: &mut Context<'_>) -> bool
id from whichever group owns it.
Returns true if it was found+removed. Distinct
from find_mut because removal happens in the owner’s
child Vec (a view cannot remove itself — it doesn’t know its owner)
and must run the owning group’s reset_current. Base: false (a leaf owns
nothing).Source§fn focus_descendant(&mut self, id: ViewId, ctx: &mut Context<'_>) -> bool
fn focus_descendant(&mut self, id: ViewId, ctx: &mut Context<'_>) -> bool
id within whichever group owns it
— the tree-op behind a label focusing its linked control. Returns true
if id was found in this subtree (selectable or not — finding it stops the
walk). Distinct from find_mut because focusing happens in
the owning group (a view cannot select itself within itself): the
owning Group calls focus_child after applying the
selectable gate. Base: false (a leaf owns nothing). Read moreSource§fn has_focusable_leaf(&self) -> bool
fn has_focusable_leaf(&self) -> bool
Group
overrides to recurse into children; wrapper views delegate. Used by the
hierarchical Tab traversal to skip selectable-but-empty subtrees.Source§fn focus_to_edge(&mut self, backward: bool, ctx: &mut Context<'_>) -> bool
fn focus_to_edge(&mut self, backward: bool, ctx: &mut Context<'_>) -> bool
backward = false) or last (Shift-Tab,
backward = true) focusable leaf in this view’s subtree, establishing the
full focus path down to it. Returns true if a focusable leaf was focused. Read moreSource§fn settle_currency(&mut self, ctx: &mut Context<'_>)
fn settle_currency(&mut self, ctx: &mut Context<'_>)
Source§fn set_visible_descendant(
&mut self,
id: ViewId,
visible: bool,
ctx: &mut Context<'_>,
) -> bool
fn set_visible_descendant( &mut self, id: ViewId, visible: bool, ctx: &mut Context<'_>, ) -> bool
visible flag of the descendant named by id from its
OWNING group, running the owning group’s currency tail. Toggling
visibility on a selectable view re-picks the owner’s current child, in both
directions (show and hide). Returns true if id was found in this
subtree. Read moreSource§fn number(&self) -> Option<i16>
fn number(&self) -> Option<i16>
None);
Window overrides to return its number when > 0
(0 means unnumbered → None).Source§fn tile(&mut self, r: Rect)
fn tile(&mut self, r: Rect)
Desktop lays out
windows). r is the desktop-local layout rect. Mirrors
select_window_num: the live loop drives the
desktop by id through &mut dyn View.Source§fn cascade(&mut self, r: Rect)
fn cascade(&mut self, r: Rect)
Desktop overrides.menu::menu_view::update_menu_commands
implements the re-gray walk. Read moreMenuBar / MenuBox)
override to set their
MenuViewState::current — the write-only
display cache their draw reads to pick the selected colour. Read moreSource§fn get_help_ctx(&self) -> HelpCtx
fn get_help_ctx(&self) -> HelpCtx
HelpCtx::DRAGGING while the view is being dragged, otherwise the
view’s own ViewState::help_ctx. Read moreSource§fn descendant_global_bounds(&self, id: ViewId, acc: Point) -> Option<Rect>
fn descendant_global_bounds(&self, id: ViewId, acc: Point) -> Option<Rect>
id to its absolute bounds, given acc = this
view’s own absolute origin. Base returns None (a leaf owns no
descendants); a Group overrides to walk its children
accumulating origins, and a Group-embedding view delegates to its inner
group. The THistory open path needs its linked
input line’s bounds in the root/absolute frame, because exec_view
root-inserts the modal and the modal frame hit-tests in absolute coords (the
documented ROOT-INSERT + (0,0) caveat). Mirrors
find_mut’s recursion but returns geometry, not a borrow.Source§fn set_indicator_value(&mut self, location: Point, modified: bool)
fn set_indicator_value(&mut self, location: Point, modified: bool)
Indicator overrides it to store the new
cursor location + modified flag. Driven by
Deferred::IndicatorSetValue:
the editor (a leaf) cannot reach its indicator sibling inline, so it requests
this and the pump calls the method by id — virtual dispatch, not a downcast.Source§fn apply_page_sync(&mut self, idx: usize, ctx: &mut Context<'_>)
fn apply_page_sync(&mut self, idx: usize, ctx: &mut Context<'_>)
PageStack overrides it to make page idx
active. Driven by
Deferred::PageStackSync: the pump
reads the bound tab bar’s value and calls this method by id — virtual
dispatch, not a downcast.Source§fn calc_bounds(&mut self, owner_size: Point, delta: Point) -> Rect
fn calc_bounds(&mut self, owner_size: Point, delta: Point) -> Rect
owner_size (delta = new - old). Computes the size limits via the overridable
size_limits hook — so a widget override (e.g. a
window’s minimum) participates — then delegates the grow math to
ViewState::calc_bounds (the single source). Returns the bounds; it does
not apply them (change_bounds does).Source§fn grabs_focus_on_click(&self) -> bool
fn grabs_focus_on_click(&self) -> bool
Group::route_event). Default true (the common case); a
Button overrides to return its grab-focus flag.
A view returning false is not focused by a click but still
receives the click (so it can act, e.g. press, without becoming the
current view).Source§fn select_window_num(&mut self, num: i16, ctx: &mut Context<'_>) -> bool
fn select_window_num(&mut self, num: i16, ctx: &mut Context<'_>) -> bool
num. Returns
whether one matched. Consistent with the find_mut /
remove_descendant tree-op family: the live
loop holds a subtree only by id (here, the desktop) and asks it to act.
Default: no-op (false). Desktop overrides.Source§fn apply_scroll_sync(
&mut self,
_h: Option<i32>,
_v: Option<i32>,
_ctx: &mut Context<'_>,
)
fn apply_scroll_sync( &mut self, _h: Option<i32>, _v: Option<i32>, _ctx: &mut Context<'_>, )
None if that bar
is absent or unresolved), each read via View::value. Overridden by the
list viewers (delegate to
list_viewer::apply_scroll),
Scroller, the outline viewer, and the editor —
every sibling-scrollbar read sync routes through this one method instead of
a pump downcast. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for FileDialog
impl !Send for FileDialog
impl !Sync for FileDialog
impl !UnwindSafe for FileDialog
impl Freeze for FileDialog
impl Unpin for FileDialog
impl UnsafeUnpin for FileDialog
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.