Skip to content

Commit

Permalink
saving files
Browse files Browse the repository at this point in the history
  • Loading branch information
not-nef committed Sep 2, 2023
1 parent de17e35 commit 66cd993
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
25 changes: 21 additions & 4 deletions src/editor.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")



Expand Down

0 comments on commit 66cd993

Please sign in to comment.