Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actions - Availability Helpers #1357

Open
benjamin-kirkbride opened this issue Jul 7, 2023 · 1 comment
Open

Actions - Availability Helpers #1357

benjamin-kirkbride opened this issue Jul 7, 2023 · 1 comment

Comments

@benjamin-kirkbride
Copy link
Contributor

Subtask of #1342

I wanted to document the different ideas that have been had for availability helpers (formerly known as availability callbacks).

Discussion here about how we came to the current design: #1349 (comment)

Discussion here about how we need to be sure to document well the different patterns and helpers: #1349 (comment)

List of helpers to be made/ironed out:

  • filetype of tab
  • filetype of file
  • name of file
  • if a Path is the "project root"
  • if a Path is .gitignore'd
  • contents of the FileTab selection
  • contents of the FileTab insert line
  • contents of the clipboard
  • whether a FileTab has unsaved changes
  • contents of the Filetab undo stack
  • if internet is available
  • various config options
  • if plugins are available
This was referenced Jul 6, 2023
@benjamin-kirkbride
Copy link
Contributor Author

For posterity this was the (bad) design for the filetype_availability helper

def filetype_availability(filetypes: list[str]) -> Callable[[FileTab | Path], bool]:
    def _filetype_availability(filetypes: list[str], context: FileTab | Path) -> bool:
        if isinstance(context, FileTab):
            tab = context
            if tab.settings.get("filetype_name", object) in filetypes:
                return True
            return False

        if isinstance(context, Path):
            path = context

            if not path.exists():
                raise RuntimeError(f"{path} does not exist.")
            if path.is_dir():
                raise RuntimeError(
                    f"{path} is a directory - an action consumer registered this action incorrectly"
                )
            if not path.is_file():
                raise RuntimeError(f"{path} is not a file")

            # return True if get_filetype_from_path(path) in filetypes else False
            raise NotImplementedError  # TODO: there is a way to do this already right?

        raise RuntimeError("wrong context passed")

    return partial(_filetype_availability, filetypes)

This was referenced Jul 8, 2023
benjamin-kirkbride added a commit to benjamin-kirkbride/porcupine that referenced this issue Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant