Skip to content

Commit

Permalink
GIT, DIFF EDITOR reimplemented
Browse files Browse the repository at this point in the history
- readded git pane, statusbar info, diff editor
- added minimalist optimized mode for text editor
  • Loading branch information
tomlin7 committed Jun 21, 2023
1 parent 29f7fbe commit ebc4213
Show file tree
Hide file tree
Showing 35 changed files with 246 additions and 412 deletions.
1 change: 0 additions & 1 deletion biscuit/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sys

from app import App

dir = None
Expand Down
46 changes: 23 additions & 23 deletions biscuit/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,54 +78,54 @@ def open_directory(self, dir):
self.active_directory = dir
self.explorer.directory.change_path(dir)
self.set_title(os.path.basename(self.active_directory))

# self.check_git()
# self.update_git()
self.update_git()

def close_active_dir(self):
def close_active_directory(self):
self.active_directory = None
self.active_directory_name = None
self.explorer.directory.close_directory()
self.editorsmanager.delete_all_editors()
self.set_title()
self.update_git()

def close_active_editor(self):
self.editorsmanager.close_active_editor()

def open_editor(self, path, exists=True):
if not os.path.isfile(path):
if exists and not os.path.isfile(path):
return

self.editorsmanager.open_editor(path, exists)

def open_diff(self, path, exists=True):
if exists and not os.path.isfile(path):
return

self.editorsmanager.open_diff_editor(path, exists)

# games ----
def open_tetris(self, *_):
self.editorsmanager.add_editor(Tetris(self.editorsmanager))

# ----------

# def update_git(self):
# if self.git_found:
# self.active_branch_name = self.git.get_active_branch()

# self.statusbar.configure_git_info(True)
# self.update_statusbar_git_info()

# self.source_control_ref.create_root()
# self.source_control_ref.update_panes()
# else:
# self.statusbar.configure_git_info(False)
# self.source_control_ref.disable_tree()
def update_git(self):
self.git.check_git()
self.statusbar.update_git_info()
self.source_control.refresh()

def open_in_new_window(self, dir):
subprocess.Popen(["python", sys.argv[0], dir])

def open_new_window(self):
subprocess.Popen(["python", sys.argv[0]])

def set_title(self, name):
def set_title(self, name=None):
if name:
return self.title("Biscuit")
self.title(f"{name} - Biscuit")

# def update_statusbar_git_info(self):
# self.statusbar.set_git_info(self.git.get_active_branch())

def update_statusbar(self):
if editor := self.editorsmanager.get_active_editor():
if editor := self.editorsmanager.active_editor:
if editor.content and editor.content.editable:
self.statusbar.toggle_editmode(True)
active_text = editor.content.text
Expand Down
15 changes: 10 additions & 5 deletions biscuit/core/components/editors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
from ..utils import FileType
from .breadcrumbs import BreadCrumbs

#TODO from .diffeditor import DiffViewer
from .diffeditor import DiffEditor
from .imageviewer import ImageViewer
from .texteditor import TextEditor
from .misc import Welcome


def get_editor(path):
def get_editor(path, diff):
"picks the right editor for the given path"
if diff:
return DiffEditor

if os.path.isfile(path):
if FileType.is_image(path):
return ImageViewer
Expand All @@ -32,25 +35,27 @@ class Editor(tk.Frame):
path - the path to the file to be opened
exists - whether the file exists or not
diff - whether this is a git diff
showpath - whether to show the breadcrumbs or not
"""
def __init__(self, master, path=None, exists=True, showpath=True, *args, **kwargs):
def __init__(self, master, path=None, exists=True, diff=False, showpath=True, *args, **kwargs):
super().__init__(master, *args, **kwargs)
self.master = master
self.base = master.base

self.path = path
self.exists = exists
self.diff = diff
self.showpath = showpath
self.filename = os.path.basename(self.path) if path else None
# TODO for now, this
if self.filename.endswith('::'):
self.filename = self.filename[:-2]

self.grid_columnconfigure(0, weight=1)
self.content = get_editor(path=path)(self, path, exists)
self.content = get_editor(path=path, diff=diff)(self, path, exists)

if self.showpath:
if self.showpath and not diff:
self.breadcrumbs = BreadCrumbs(self, path)
self.grid_rowconfigure(1, weight=1)
self.breadcrumbs.grid(row=0, column=0, sticky=EW, pady=(0, 1))
Expand Down
17 changes: 8 additions & 9 deletions biscuit/core/components/editors/breadcrumbs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,19 @@ def __init__(self, master, path=None, *args, **kwargs):

# if the file does not belong to active directory, use the absolute path instead
if not (self.base.active_directory and
os.path.commonpath([self.base.active_directory, path]) == os.path.abspath(self.base.active_directory)):
os.path.commonpath([self.base.active_directory, os.path.abspath(path)]) == os.path.abspath(self.base.active_directory)):
path = os.path.abspath(path).split('\\')
for i, item in enumerate(path):
text = item if item == path[-1] else f"{item} ›"

btn = Item(self, "\\".join(path[:i]), text=text)
btn.bind("<Button-1>", self.pathview.show)
btn.pack(side=tk.LEFT)
self.additem("\\".join(path[:i]), text)
else:
# otherwise use the relative path to active directory
path = os.path.relpath(path, self.base.active_directory).split('\\')
path = os.path.relpath(path, self.base.active_directory).split('\\')
for i, item in enumerate(path):
text = item if item == path[-1] else f"{item} ›"
self.additem(os.path.join(self.base.active_directory, "\\".join(path[:i])), text)

btn = Item(self, os.path.join(self.base.active_directory, "\\".join(path[:i])), text=text)
btn.bind("<Button-1>", self.pathview.show)
btn.pack(side=tk.LEFT)
def additem(self, path, text):
btn = Item(self, path, text=text)
btn.bind("<Button-1>", self.pathview.show)
btn.pack(side=tk.LEFT)
19 changes: 10 additions & 9 deletions biscuit/core/components/editors/diffeditor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

from .pane import DiffPane
from .differ import Differ
from ..editor import BaseEditor

#TODO reimplement diff editor + git
class DiffViewer(tk.Frame):

class DiffEditor(BaseEditor):
def __init__(self, master, path, *args, **kwargs):
super().__init__(master, orient=tk.HORIZONTAL, *args, **kwargs)
super().__init__(master, *args, **kwargs)
self.base = master.base
self.master = master
self.path = path
Expand All @@ -17,16 +18,16 @@ def __init__(self, master, path, *args, **kwargs):
self.rhs_data = []

self.lhs = DiffPane(self, path)
self.add(self.lhs, stretch='always')
self.lhs.pack(side=tk.LEFT, expand=True, fill=tk.BOTH)

self.rhs = DiffPane(self, path)
self.add(self.rhs, stretch='always')
self.rhs.pack(side=tk.RIGHT, expand=True, fill=tk.BOTH)

self.left = self.lhs.content.text
self.right = self.text = self.rhs.content.text
self.left = self.lhs.text
self.right = self.text = self.rhs.text

self.lhs.content.scrollbar['command'] = self.on_scrollbar
self.rhs.content.scrollbar['command'] = self.on_scrollbar
self.lhs.scrollbar['command'] = self.on_scrollbar
self.rhs.scrollbar['command'] = self.on_scrollbar
self.left['yscrollcommand'] = self.on_textscroll
self.right['yscrollcommand'] = self.on_textscroll

Expand Down
2 changes: 1 addition & 1 deletion biscuit/core/components/editors/diffeditor/differ.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import difflib, sys
import difflib


class Differ(difflib.Differ):
Expand Down
5 changes: 4 additions & 1 deletion biscuit/core/components/editors/diffeditor/pane.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from ..texteditor import TextEditor


# TODO currently using TextEditor, use Editor instead
class DiffPane(TextEditor):
def __init__(self, master, *args, **kwargs):
super().__init__(master, exists=False, minimalist=True, *args, **kwargs)

def load_file(self):
self.text.load_file()

Expand Down
6 changes: 3 additions & 3 deletions biscuit/core/components/editors/misc/welcome.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ def create_start_group(self):

#TODO add recents

def new_file(self, _):
def new_file(self, *_):
self.base.events.new_file()

def open_file(self, _):
def open_file(self, *_):
self.base.events.open_file()

def open_folder(self, _):
def open_folder(self, *_):
self.base.events.open_directory()
16 changes: 10 additions & 6 deletions biscuit/core/components/editors/texteditor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,27 @@


class TextEditor(BaseEditor):
def __init__(self, master, path=None, exists=True, *args, **kwargs):
def __init__(self, master, path=None, exists=True, minimalist=False, *args, **kwargs):
super().__init__(master, path, exists, *args, **kwargs)
self.font = self.base.settings.font
self.minimalist = minimalist

self.rowconfigure(0, weight=1)
self.columnconfigure(1, weight=1)

self.text = Text(self, path=self.path, exists=self.exists)
self.text = Text(self, path=self.path, exists=self.exists, minimalist=minimalist)
self.linenumbers = LineNumbers(self, text=self.text)
self.minimap = Minimap(self, self.text)
self.scrollbar = Scrollbar(self, orient=tk.VERTICAL, command=self.text.yview)

self.text.config(font=self.font)
self.text.configure(yscrollcommand=self.scrollbar.set)


if not self.minimalist:
self.minimap = Minimap(self, self.text)
self.minimap.grid(row=0, column=2, sticky=tk.NS)

self.linenumbers.grid(row=0, column=0, sticky=tk.NS)
self.text.grid(row=0, column=1, sticky=tk.NSEW)
self.minimap.grid(row=0, column=2, sticky=tk.NS)
self.scrollbar.grid(row=0, column=3, sticky=tk.NS)

if self.exists:
Expand All @@ -47,7 +50,8 @@ def focus(self):

def on_change(self, event=None):
self.linenumbers.redraw()
self.minimap.redraw()
if not self.minimalist:
self.minimap.redraw()
self.text.on_change()
self.event_generate("<<Change>>")
self.base.update_statusbar()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
from .highlighter import Highlighter

from core.config.languages import CPP


class Syntax:
def __init__(self, master):
self.master = master
Expand Down
20 changes: 15 additions & 5 deletions biscuit/core/components/editors/texteditor/text.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import re
import tkinter as tk

from .syntax import Highlighter
from .autocomplete import AutoComplete
from .syntax import Syntax
from .highlighter import Highlighter
from .autocomplete import AutoComplete

class Text(tk.Text):
def __init__(self, master, path=None, exists=True, *args, **kwargs):
def __init__(self, master, path=None, exists=True, minimalist=False, *args, **kwargs):
super().__init__(master, *args, **kwargs)
self.base = master.base
self.master = master

self.path = path
self.data = None
self.exists = exists
self.minimalist = minimalist

self.syntax = Syntax(self)
self.highlighter = Highlighter(self)

self.current_word = None
self.words = []
self.auto_completion = AutoComplete(
self, items=self.syntax.get_autocomplete_list())
self, items=self.syntax.get_autocomplete_list()) if not minimalist else None

self.configure(wrap=tk.NONE, relief=tk.FLAT, bg="white", fg="#3b3b3b")
self.tag_config(tk.SEL, background="#b98852")
Expand All @@ -48,6 +49,9 @@ def config_bindings(self):
self.bind("<Return>", self.enter_key_events)
self.bind("<Tab>", self.tab_key_events)

if self.minimalist:
return

self.bind("<FocusOut>", self.hide_autocomplete)
self.bind("<Button-1>", self.hide_autocomplete)
self.bind("<Up>", self.auto_completion.move_up)
Expand Down Expand Up @@ -118,6 +122,9 @@ def update_words(self, *_):
self.after(1000, self.update_words)

def update_completions(self):
if self.minimalist:
return

self.auto_completion.update_completions()

def confirm_autocomplete(self, text):
Expand Down Expand Up @@ -153,10 +160,13 @@ def cursor_screen_location(self):
return (pos_x + bbx_x - 1, pos_y + bbx_y + bbx_h)

def hide_autocomplete(self, *_):
if self.minimalist:
return

self.auto_completion.hide()

def show_autocomplete(self, event):
if not self.check_autocomplete_keys(event):
if self.minimalist or not self.check_autocomplete_keys(event):
return

if self.current_word.strip() not in ["{", "}", ":", "", None, "\""] and not self.current_word.strip()[0].isdigit():
Expand Down
1 change: 1 addition & 0 deletions biscuit/core/components/games/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .tetris import Tetris
from .whoops import Whoops

def get_game(name):
"picks the right game for the given name"
Expand Down
7 changes: 7 additions & 0 deletions biscuit/core/components/games/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ def __init__(self, master, path=None, *args, **kwargs):
self.exists = False
self.showpath = False
self.content = None
self.diff = False
self.editable = False

self.__buttons__ = ()

def reload(self, *_):
...

def save(self, *_):
...
Empty file.
Loading

0 comments on commit ebc4213

Please sign in to comment.