MingaEditor.State.FileTree (Minga v0.1.0)

Copy Markdown View Source

File tree sub-state: tree data, focus, and backing buffer.

Wraps the file-tree-related fields from EditorState into a single struct with query and mutation helpers. Includes inline editing state for new file, new folder, and rename operations.

Summary

Types

Inline editing state for creating files/folders or renaming entries.

t()

File tree sub-state.

Explicit presentation state for the file tree sidebar.

Functions

Accepts the current filter and leaves the narrowed tree visible.

Cancels inline editing, clearing the editing state back to nil.

Clears a pending file tree clipboard operation.

Clears the active filter and exits filtering mode.

Clears the pending filesystem refresh timer reference.

Closes the tree and clears the buffer.

Returns true when inline editing is active.

Marks the sidebar as failed with a displayable reason.

Marks the file tree as focused.

Returns true when the file tree is open and focused.

Hides the file tree help overlay.

Marks the sidebar as loading.

Stores a pending file tree clipboard operation.

Opens the tree with the given data, buffer, and focused state.

Returns true when the file tree is open.

Returns true when a filesystem refresh timer is pending.

Replaces the backing tree and refreshes the presentation status.

Stores the pending filesystem refresh timer reference.

Updates the project root associated with the file tree.

Replaces the tree data.

Enters inline editing mode at the given index.

Starts inline file tree filtering.

Returns the explicit presentation status for the file tree.

Toggles the file tree help overlay.

Marks the file tree as unfocused.

Updates the text being typed in the inline editor.

Updates the active file tree filter.

Returns true when the explicit tree status should occupy the sidebar.

Returns the tree width, preserving the last sidebar width while state-only payloads are visible.

Types

clipboard_mark()

@type clipboard_mark() :: MingaEditor.State.FileTree.ClipboardMark.t()

clipboard_operation()

@type clipboard_operation() :: MingaEditor.State.FileTree.ClipboardMark.operation()

editing()

@type editing() :: %{
  index: non_neg_integer(),
  text: String.t(),
  type: editing_type(),
  original_name: String.t() | nil
}

editing_type()

@type editing_type() :: :new_file | :new_folder | :rename

Inline editing state for creating files/folders or renaming entries.

When non-nil, the user is actively typing a filename in the tree. The index is the visual position in the visible entry list where the editing row appears. For new file/folder, this is the insertion point. For rename, this is the entry being renamed.

t()

@type t() :: %MingaEditor.State.FileTree{
  buffer: pid() | nil,
  clipboard_mark: clipboard_mark() | nil,
  editing: editing() | nil,
  filtering: boolean(),
  focused: boolean(),
  help_visible: boolean(),
  original_root: String.t() | nil,
  project_root: String.t() | nil,
  refresh_timer: reference() | nil,
  tree: Minga.Project.FileTree.t() | nil,
  tree_status: tree_status(),
  tree_width: pos_integer()
}

File tree sub-state.

tree_status()

@type tree_status() :: :hidden | :loading | :empty | :ready | {:error, String.t()}

Explicit presentation state for the file tree sidebar.

Functions

accept_filter(ft)

@spec accept_filter(t()) :: t()

Accepts the current filter and leaves the narrowed tree visible.

cancel_editing(ft)

@spec cancel_editing(t()) :: t()

Cancels inline editing, clearing the editing state back to nil.

clear_clipboard(ft)

@spec clear_clipboard(t()) :: t()

Clears a pending file tree clipboard operation.

clear_filter(ft)

@spec clear_filter(t()) :: t()

Clears the active filter and exits filtering mode.

clear_refresh(ft)

@spec clear_refresh(t()) :: t()

Clears the pending filesystem refresh timer reference.

close(ft)

@spec close(t()) :: t()

Closes the tree and clears the buffer.

editing?(file_tree)

@spec editing?(t()) :: boolean()

Returns true when inline editing is active.

error(ft, reason)

@spec error(t(), term()) :: t()

Marks the sidebar as failed with a displayable reason.

focus(ft)

@spec focus(t()) :: t()

Marks the file tree as focused.

focused?(file_tree)

@spec focused?(t()) :: boolean()

Returns true when the file tree is open and focused.

hide_help(ft)

@spec hide_help(t()) :: t()

Hides the file tree help overlay.

loading(ft)

@spec loading(t()) :: t()

Marks the sidebar as loading.

mark_clipboard(ft, path, name, dir?, operation)

@spec mark_clipboard(t(), String.t(), String.t(), boolean(), clipboard_operation()) ::
  t()

Stores a pending file tree clipboard operation.

open(ft, tree, buffer)

@spec open(t(), Minga.Project.FileTree.t(), pid() | nil) :: t()

Opens the tree with the given data, buffer, and focused state.

open?(file_tree)

@spec open?(t()) :: boolean()

Returns true when the file tree is open.

refresh_scheduled?(file_tree)

@spec refresh_scheduled?(t()) :: boolean()

Returns true when a filesystem refresh timer is pending.

replace_tree(ft, tree)

@spec replace_tree(t(), Minga.Project.FileTree.t()) :: t()

Replaces the backing tree and refreshes the presentation status.

schedule_refresh(ft, ref)

@spec schedule_refresh(t(), reference()) :: t()

Stores the pending filesystem refresh timer reference.

set_project_root(ft, root)

@spec set_project_root(t(), String.t() | nil) :: t()

Updates the project root associated with the file tree.

set_tree(ft, tree)

@spec set_tree(t(), Minga.Project.FileTree.t() | nil) :: t()

Replaces the tree data.

start_editing(ft, index, type, initial_text \\ "")

@spec start_editing(t(), non_neg_integer(), editing_type(), String.t()) :: t()

Enters inline editing mode at the given index.

For new file/folder, initial_text is empty. For rename, initial_text is the current entry name.

start_filtering(ft)

@spec start_filtering(t()) :: t()

Starts inline file tree filtering.

status(ft)

@spec status(t()) :: tree_status()

Returns the explicit presentation status for the file tree.

toggle_help(ft)

@spec toggle_help(t()) :: t()

Toggles the file tree help overlay.

unfocus(ft)

@spec unfocus(t()) :: t()

Marks the file tree as unfocused.

update_editing_text(ft, new_text)

@spec update_editing_text(t(), String.t()) :: t()

Updates the text being typed in the inline editor.

update_filter(ft, filter)

@spec update_filter(t(), String.t()) :: t()

Updates the active file tree filter.

visible_status?(arg1)

@spec visible_status?(tree_status()) :: boolean()

Returns true when the explicit tree status should occupy the sidebar.

width(file_tree)

@spec width(t()) :: pos_integer()

Returns the tree width, preserving the last sidebar width while state-only payloads are visible.