diff --git a/LICENSE b/LICENSE index 82749c0..a42cabb 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 not-nef +Copyright (c) 2023 not-nef Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/src/editor.py b/src/editor.py index b67bafb..206eba3 100644 --- a/src/editor.py +++ b/src/editor.py @@ -1,6 +1,6 @@ -from os.path import basename +from os.path import basename, isfile from tkinter import Frame, Label, PhotoImage -from tkinter.filedialog import askopenfile +from tkinter.filedialog import askopenfile, asksaveasfile from tkinter.ttk import Button, Notebook, Scrollbar, Style from toml import load @@ -37,7 +37,24 @@ def openfile(self): self.file.close() def save(self): - pass + self.editor = self.nametowidget(self.select()) # Retrieves Editor Object of currently opened Tab + self.filetosave = self.editor.filedir.cget("text") + if isfile(self.filetosave): + self.file2 = open(self.filetosave, "w") + self.file2.write(self.editor.text.get("1.0", "end")) + self.file2.close() + else: + self.saveas() + + def saveas(self): + self.editor = self.nametowidget(self.select()) + self.file3 = asksaveasfile() + if self.file3 != None: + self.file3.write(self.editor.text.get("1.0", "end")) + self.editor.filedir.configure(text=self.file3.name) + self.tab(self.select(), text=basename(self.file3.name)) + self.file3.close() + # The next two functions are heavily inspired by Akuli: @@ -98,10 +115,10 @@ def __init__(self, file, *args): self.text["yscrollcommand"] = self.yscroll - if file != None: self.text.insert("1.0", file.read()) self.filedir.configure(text=file.name) + file.close() # Extra function so that the linenumbers and the scrollbar dont fight over the yscrollcommand diff --git a/src/main.py b/src/main.py index 194ae8b..b54b5a2 100644 --- a/src/main.py +++ b/src/main.py @@ -31,9 +31,10 @@ def __init__(self): self.menubar.add_cascade(label="File", menu=self.filemenu) - self.filemenu.add_command(label="New", command=lambda:self.manager.newtab(), foreground="white" if LINUX else "black") + self.filemenu.add_command(label="New", command=self.manager.newtab, foreground="white" if LINUX else "black") self.filemenu.add_command(label="Open", command=self.manager.openfile, foreground="white" if LINUX else "black") self.filemenu.add_command(label="Save", command=self.manager.save, foreground="white" if LINUX else "black") + self.filemenu.add_command(label="Save As", command=self.manager.saveas, foreground="white" if LINUX else "black")