diff --git a/biscuit/core/components/editors/misc/welcome.py b/biscuit/core/components/editors/misc/welcome.py index da7c8778..daffa17b 100644 --- a/biscuit/core/components/editors/misc/welcome.py +++ b/biscuit/core/components/editors/misc/welcome.py @@ -26,6 +26,13 @@ def __init__(self, master, exists=False, editable=False, *args, **kwargs) -> Non self.description = Label(self.left, text="Made with ❤", font=("Segoe UI", 20), fg=self.base.theme.biscuit_dark, **self.base.theme.editors.biscuit_labels) self.description.grid(row=1, column=0, sticky=tk.W, pady=5) + if self.base.get_user_preset("editing.misc.welcome.lucky"): + lucky_word = self.base.get_user_preset("editing.misc.welcome.lucky") + self.lucky = Label(self.left, text=lucky_word, font=("Segoe UI", 14), fg=self.base.theme.biscuit_dark, **self.base.theme.editors.biscuit_labels) + self.lucky.grid(row=2, column=0, sticky=tk.W, pady=1) + else: + self.lucky = None + self.create_start_group() self.create_recent_group() diff --git a/biscuit/core/config.py b/biscuit/core/config.py index 07527882..1a9e3119 100644 --- a/biscuit/core/config.py +++ b/biscuit/core/config.py @@ -1,6 +1,7 @@ import os import sys +import importlib.util from .api import * from .components import * @@ -32,6 +33,46 @@ class ConfigManager: appdir: str extensionsdir: str + def get_user_integrated_preset_path(self): + return os.path.join(os.path.expanduser("~"), ".biscuit", "preset.entry.py") + + def load_user_integrated_preset(self): + path = self.get_user_integrated_preset_path() + if os.path.exists(path): + # user integrated preset exists + spec = importlib.util.spec_from_file_location("user_integrated_preset", path) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + self.user_integrated_preset = module + else: + self.user_integrated_preset = None + + def has_user_preset(self, path): + t = self.user_integrated_preset + ps = path.split('.') + for s in ps: + try: + t = getattr(t, s) + except: + return False + return True + + def get_user_preset(self, path): + t = self.user_integrated_preset + ps = path.split('.') + for s in ps: + try: + t = getattr(t, s) + except: + return None + return t + + def check_user_preset(self, path): + return self.get_user_preset(path) in [True,"yes", "y"] + + def check_user_preset_neither(self, path, any_): + return not (self.get_user_preset(path) in any_) + def setup_configs(self) -> None: self.git_found = False self.active_directory = None @@ -55,6 +96,8 @@ def setup_configs(self) -> None: self.git = Git(self) self.language_server_manager = LanguageServerManager(self) + self.load_user_integrated_preset() + def setup_path(self, appdir: str) -> None: # setup all paths used across editor self.appdir = os.path.dirname(appdir) @@ -80,4 +123,4 @@ def setup_api(self): # sets up the extension API & loads extensions self.api = ExtensionsAPI(self) self.extensions_manager = ExtensionManager(self) - \ No newline at end of file + diff --git a/presets/README.md b/presets/README.md new file mode 100644 index 00000000..3c85e2f0 --- /dev/null +++ b/presets/README.md @@ -0,0 +1,12 @@ +Here is a directory that holds and shows preset. Write a preset for yourself as you need. + +Look for the `empty.py` that shows a preset empty. + +Look for the `example.lucky.py` that shows how to setup a lucky word in the welcome panel; a panel that will start at first. + +Look for the `example.shells.py` that shows how to setup multiple shells. + +Feel free to merge them. After editing, move the preset as `~/.biscuit/preset.entry.py`. + +That's all! + diff --git a/presets/empty.py b/presets/empty.py new file mode 100644 index 00000000..e69de29b diff --git a/presets/example.lucky.py b/presets/example.lucky.py new file mode 100644 index 00000000..d8041512 --- /dev/null +++ b/presets/example.lucky.py @@ -0,0 +1,14 @@ + +# Preset for Editing-wide +class editing: + class misc: + class welcome: + lucky = "Don't you want me, On!" + +# Preset for Feature-wide +class features: + pass + +# Preset for Extendsions +class extensions: + pass diff --git a/presets/example.shells.py b/presets/example.shells.py new file mode 100644 index 00000000..cf89d517 --- /dev/null +++ b/presets/example.shells.py @@ -0,0 +1,14 @@ + +# Preset for Editing-wide +class editing: + class shells: + _1 = {} + _2 = {} + +# Preset for Feature-wide +class features: + pass + +# Preset for Extendsions +class extensions: + pass