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

Implement common editors menu #149 #152

Merged
merged 3 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions biscuit/core/components/floating/palette/actionset.py
tomlin7 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,16 +1,37 @@
from typing import Callable, List, Tuple


class ActionSet(list):
def __init__(self, description, prompt, items=[], pinned=[], *args, **kwargs) -> None:
def __init__(self, description: str, prompt: str, items: List[Tuple[str, Callable]] = [],
pinned: List[Tuple[str, Callable]] = [], *args, **kwargs) -> None:
"""Palette Actionset
A list of items that can be searched through.

Attributes
----------
description : str
The description of the actionset.
prompt : str
The prompt of the actionset.
items : List[Tuple[str, Callable]]
The items in the actionset.
pinned : List[Tuple[str, Callable]]
The pinned items in the actionset.
"""

super().__init__(items, *args, **kwargs)
self.description = description
self.prompt = prompt
self.description: str = description
self.prompt: str = prompt

self.pinned = pinned # [[command, callback], ...]
self.pinned: List[Tuple[str, Callable]] = pinned # [[command, callback], ...]

def update(self, items) -> None:
"Clear and update the items in the actionset."
self.clear()
self += items

def get_pinned(self, term) -> list:
"Returns the pinned items with the term formatted."
if not self.pinned:
return []

Expand Down
17 changes: 14 additions & 3 deletions biscuit/core/layout/base/content/editors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
from __future__ import annotations

import typing
from typing import List

from biscuit.core.components.floating.palette.actionset import ActionSet

if typing.TYPE_CHECKING:
from .. import ContentPane
Expand Down Expand Up @@ -45,13 +48,21 @@ def __init__(self, master: ContentPane, *args, **kwargs) -> None:
self.editorsbar.grid(row=0, column=0, sticky=tk.EW, pady=(0,1))
self.tabs = self.editorsbar.tabs

self.editors = []
self.closed_editors = {}
self.editors: List[Editor] = []
self.closed_editors: List[Editor] = {}

self.empty = True
self.emptytab = Empty(self)
self.emptytab.grid(column=0, row=1, sticky=tk.NSEW)

self.default_editors = [Welcome(self)]
self.default_editors: List[Editor] = [Welcome(self)]
self.actionset = ActionSet("Switch to active editors", "active:", [])
self.base.palette.register_actionset(self.get_active_actionset)

def get_active_actionset(self) -> ActionSet:
"Generates the active editors actionset"
self.actionset.update([(editor.filename, editor) for editor in self.editors])
return self.actionset
tomlin7 marked this conversation as resolved.
Show resolved Hide resolved

def add_default_editors(self) -> None:
"Adds all default editors"
Expand Down
5 changes: 3 additions & 2 deletions biscuit/core/layout/base/content/editors/editorsbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ class Editorsbar(Frame):
def __init__(self, master: EditorsPane, *args, **kwargs) -> None:
super().__init__(master, *args, **kwargs)
self.config(**self.base.theme.layout.base.content.editors.bar)
self.master = master

self.tabs = Tabs(self)
self.tabs.pack(fill=tk.BOTH, side=tk.LEFT, expand=True)

self.menu = EditorsbarMenu(self, "tabs")
self.menu.add_item("Show Opened Editors")
self.menu.add_item("Show Opened Editors", lambda: self.base.palette.show_prompt("active:"))
self.menu.add_separator(10)
self.menu.add_item("Close All")
self.menu.add_item("Close All", self.master.delete_all_editors)

self.buttons = []
self.default_buttons = (('ellipsis', self.menu.show),)
Expand Down