Skip to content

Commit

Permalink
feat: Drag-n-Drop to open files/directories #272 (nightly)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlin7 authored Apr 4, 2024
2 parents a6e8465 + 2f9ccee commit cf46893
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 7 deletions.
2 changes: 1 addition & 1 deletion biscuit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "2.66.4"
__version__ = "2.66.6"
__version_info__ = tuple([int(num) for num in __version__.split(".")])

# For tests to run successfully
Expand Down
11 changes: 11 additions & 0 deletions biscuit/core/components/editors/editor.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import tkinterDnD as dnd

from ..utils import Frame, IconButton


Expand All @@ -19,6 +21,15 @@ def __init__(self, master, path=None, path2=None, editable=True, *args, **kwargs

self.__buttons__ = []

self.register_drop_target(dnd.FILE)
self.bind("<<Drop>>", self.ondrop)

def ondrop(self, event):
if not event.data:
return

self.base.open(event.data, warn_for_directory=True)

def add_button(self, *args):
self.__buttons__.append(args)

Expand Down
6 changes: 5 additions & 1 deletion biscuit/core/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ def set_title(self, title: str = None) -> None:
self.menubar.set_title(title)
self.menubar.reposition_title()

def open(self, path: str) -> None:
def open(self, path: str, warn_for_directory=False) -> None:
"""Opens file/directory based on path.
TODO: Open directory in new window if warn_for_directory is True.
"""
if not path:
return

Expand Down
5 changes: 3 additions & 2 deletions biscuit/core/gui.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import platform
import tkinter as tk

from tkinterDnD import Tk

from .components import *
from .config import ConfigManager
from .layout import *


class GUIManager(tk.Tk, ConfigManager):
class GUIManager(Tk, ConfigManager):
"""
GUI MANAGER
-----------
Expand Down
31 changes: 29 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "biscuit"
version = "2.66.4"
version = "2.66.6"
description = "The uncompromising code editor"
authors = ["Billy <billydevbusiness@gmail.com>"]
license = "MIT"
Expand All @@ -25,6 +25,7 @@ tarts = "^0.12.0"
chardet = "^5.2.0"
pywinpty = {version = "^2.0.13", platform = "win32"}
ptyprocess = {version = "^0.7.0", platform = "linux"}
python-tkdnd = "^0.2.1"


[tool.poetry.group.dev.dependencies]
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ chardet
python-lsp-server
pywinpty; platform_system == "Windows"
ptyprocess; platform_system != "Windows"
python-tkdnd

0 comments on commit cf46893

Please sign in to comment.