generated from itdominator/Python-With-Gtk-Template
Mostly completed tab inferastructure setup
This commit is contained in:
parent
729b3850a0
commit
386628a949
@ -70,4 +70,5 @@ class BaseController(SignalsMixins, BaseControllerData):
|
||||
settings_manager.register_signals_to_builder([self, self.core_widget])
|
||||
|
||||
def get_core_widget(self):
|
||||
return self.core_widget
|
||||
return self.core_widget
|
||||
|
||||
|
@ -31,12 +31,10 @@ class BridgeController:
|
||||
event_system.emit(f"handle_file_event_{event.originator}", (event,))
|
||||
case "load_buffer":
|
||||
event_system.emit(f"handle_file_event_{event.originator}", (event,))
|
||||
# case "add_tab":
|
||||
# event_system.emit(f"add_tab_{event.originator}", (event,))
|
||||
|
||||
case "load_file":
|
||||
event_system.emit(f"handle_file_event_{event.originator}", (event,))
|
||||
case "error":
|
||||
content = base64.b64decode( event.content.encode() ).decode("utf-8")
|
||||
logger.info(content)
|
||||
case _:
|
||||
...
|
||||
|
||||
...
|
@ -29,20 +29,25 @@ class FilesController:
|
||||
event_system.subscribe(f"handle_file_event_{self.INDEX}", self.handle_file_event)
|
||||
|
||||
def set_pre_drop_dnd(self, gfiles):
|
||||
keys = self.opened_files.keys()
|
||||
|
||||
for gfile in gfiles:
|
||||
fhash = str(gfile.hash())
|
||||
if fhash in keys: continue
|
||||
|
||||
ftype, fhash = self.insert_to_sessions(fhash, gfile)
|
||||
|
||||
fname = gfile.get_basename()
|
||||
fpath = gfile.get_path()
|
||||
content = None
|
||||
path = gfile.get_path()
|
||||
with open(path) as f:
|
||||
|
||||
with open(fpath) as f:
|
||||
content = base64.b64encode( f.read().encode(), altchars = None ).decode("utf-8")
|
||||
|
||||
event_system.emit("load_file", (ftype, fhash, gfile.get_basename(), content))
|
||||
info = gfile.query_info("standard::*", 0, cancellable = None)
|
||||
ftype = info.get_content_type().replace("x-", "").split("/")[1]
|
||||
event_system.emit(
|
||||
f"load_file_{self.INDEX}",
|
||||
(
|
||||
ftype,
|
||||
fname,
|
||||
fpath,
|
||||
content
|
||||
)
|
||||
)
|
||||
|
||||
def handle_file_event(self, event):
|
||||
match event.topic:
|
||||
@ -53,10 +58,13 @@ class FilesController:
|
||||
if basename:
|
||||
event_system.emit(f"updated_tab_{event.originator}", (event.target, basename,))
|
||||
case "close":
|
||||
self.close_session(event.target)
|
||||
event_system.emit(f"close_tab_{event.originator}", (event.target))
|
||||
case "load_buffer":
|
||||
self.load_buffer(event.target)
|
||||
event_system.emit(f"add_tab_{event.originator}", (event.target, "buffer",))
|
||||
case "load_file":
|
||||
content = base64.b64decode( event.content.encode() ).decode("utf-8")
|
||||
event_system.emit(f"add_tab_with_name_{event.originator}", (event.target, content,))
|
||||
case _:
|
||||
return
|
||||
|
||||
@ -74,10 +82,6 @@ class FilesController:
|
||||
self.update_session(fhash, gfile)
|
||||
return gfile.get_basename()
|
||||
|
||||
|
||||
def close_session(self, target):
|
||||
del self.opened_files[target]
|
||||
|
||||
def update_session(self, fhash, gfile):
|
||||
info = gfile.query_info("standard::*", 0, cancellable = None)
|
||||
ftype = info.get_content_type().replace("x-", "").split("/")[1]
|
||||
|
@ -47,6 +47,7 @@ class AceEditor(WebKit2.WebView):
|
||||
event_system.subscribe(f"new_session_{self.INDEX}", self.new_session)
|
||||
event_system.subscribe(f"switch_session_{self.INDEX}", self.switch_session)
|
||||
event_system.subscribe(f"close_session_{self.INDEX}", self.close_session)
|
||||
event_system.subscribe(f"remove_session_{self.INDEX}", self.remove_session)
|
||||
event_system.subscribe(f"ui_message_{self.INDEX}", self.ui_message)
|
||||
|
||||
def _load_settings(self):
|
||||
@ -78,8 +79,8 @@ class AceEditor(WebKit2.WebView):
|
||||
except Exception as e:
|
||||
logger.info(e)
|
||||
|
||||
def load_file(self, ftype: str, fhash: str, file: str, content: str):
|
||||
command = f"loadFile('{ftype}', '{fhash}', '{file}', '{content}')"
|
||||
def load_file(self, ftype: str, fname: str, fpath: str, content: str):
|
||||
command = f"loadFile('{ftype}', '{fname}', '{fpath}', '{content}')"
|
||||
self.run_javascript(command, None, None)
|
||||
|
||||
def new_session(self):
|
||||
@ -94,6 +95,10 @@ class AceEditor(WebKit2.WebView):
|
||||
command = f"closeSession('{fhash}')"
|
||||
self.run_javascript(command, None, None)
|
||||
|
||||
def remove_session(self, fhash):
|
||||
command = f"removeSession('{fhash}')"
|
||||
self.run_javascript(command, None, None)
|
||||
|
||||
def ui_message(self, message, mtype):
|
||||
command = f"displayMessage('{message}', '{mtype}', '3')"
|
||||
self.run_javascript(command, None, None)
|
||||
|
@ -19,9 +19,11 @@ class DnDBox(DnDMixin, Gtk.DrawingArea):
|
||||
understand how to acount for non DnD events.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, index):
|
||||
super(DnDBox, self).__init__()
|
||||
|
||||
self.INDEX = index
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._subscribe_to_events()
|
||||
|
@ -19,7 +19,7 @@ class FixedBox(Gtk.Fixed):
|
||||
|
||||
def __init__(self, index):
|
||||
super(FixedBox, self).__init__()
|
||||
|
||||
|
||||
self.INDEX = index
|
||||
|
||||
self._setup_styling()
|
||||
@ -42,7 +42,7 @@ class FixedBox(Gtk.Fixed):
|
||||
|
||||
def _load_widgets(self):
|
||||
self.ace_editor = AceEditor(self.INDEX)
|
||||
self.dnd_box = DnDBox()
|
||||
self.dnd_box = DnDBox(self.INDEX)
|
||||
|
||||
self.add( self.ace_editor )
|
||||
self.add( self.dnd_box )
|
||||
|
@ -14,7 +14,8 @@ class TabBar(Gtk.Notebook):
|
||||
def __init__(self, index):
|
||||
super(TabBar, self).__init__()
|
||||
|
||||
self.INDEX = index
|
||||
self.INDEX = index
|
||||
self.added_tab = None
|
||||
|
||||
self.set_group_name("editor_widget")
|
||||
|
||||
@ -30,18 +31,20 @@ class TabBar(Gtk.Notebook):
|
||||
...
|
||||
|
||||
def _setup_signals(self):
|
||||
self.connect("switch-page", self._switch_page_update)
|
||||
self.connect("switch-page", self._switch_page_update)
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
event_system.subscribe(f"add_tab_{self.INDEX}", self.add_tab)
|
||||
event_system.subscribe(f"add_tab_{self.INDEX}", self.add_tab)
|
||||
event_system.subscribe(f"add_tab_with_name_{self.INDEX}", self.add_tab)
|
||||
event_system.subscribe(f"update_tab_{self.INDEX}", self.update_tab)
|
||||
event_system.subscribe(f"close_tab_{self.INDEX}", self.close_tab)
|
||||
|
||||
def _load_widgets(self):
|
||||
start_box = Gtk.Box()
|
||||
end_box = Gtk.Box()
|
||||
|
||||
add_tab = Gtk.Button(label = "+")
|
||||
add_tab.connect("released", self.add_tab_click)
|
||||
add_tab.connect("released", self._button_add_tab)
|
||||
|
||||
end_box.add(add_tab)
|
||||
|
||||
@ -51,19 +54,39 @@ class TabBar(Gtk.Notebook):
|
||||
self.set_action_widget(start_box, 0)
|
||||
self.set_action_widget(end_box, 1)
|
||||
|
||||
def _switch_page_update(self, notebook, page, page_num):
|
||||
print(page_num)
|
||||
...
|
||||
|
||||
def add_tab_click(self, widget):
|
||||
def _button_add_tab(self, widget):
|
||||
event_system.emit(f"new_session_{self.INDEX}")
|
||||
|
||||
def _button_close_tab(self, widget, container):
|
||||
self._close_tab(widget, container)
|
||||
event_system.emit(f"remove_session_{self.INDEX}", (container.fhash))
|
||||
|
||||
# Note: Need to get parent instead given we pass the close_tab method
|
||||
# from a potentially former notebook.
|
||||
def _close_tab(self, widget, container):
|
||||
notebook = container.get_parent()
|
||||
|
||||
if notebook.get_n_pages() < 2: return
|
||||
|
||||
page_num = notebook.page_num(container)
|
||||
notebook.remove_page(page_num)
|
||||
# container._cancel_current_file_watchers()
|
||||
|
||||
def _switch_page_update(self, notebook, container, page_num):
|
||||
if self.added_tab or self.added_tab == None:
|
||||
self.added_tab = False
|
||||
return
|
||||
|
||||
event_system.emit(f"switch_session_{self.INDEX}", (container.fhash,))
|
||||
|
||||
|
||||
def add_tab(self, fhash, title = "[BAD TITLE]"):
|
||||
container = Gtk.EventBox()
|
||||
header = TabHeaderWidget(container, self._close_tab)
|
||||
page_num = self.append_page(container, header)
|
||||
container = Gtk.EventBox()
|
||||
header = TabHeaderWidget(container, self._button_close_tab)
|
||||
page_num = self.append_page(container, header)
|
||||
|
||||
container.fhash = fhash
|
||||
self.added_tab = True
|
||||
|
||||
header.label.set_label(title)
|
||||
self.set_tab_detachable(container, True)
|
||||
@ -73,44 +96,23 @@ class TabBar(Gtk.Notebook):
|
||||
self.set_current_page(page_num)
|
||||
|
||||
def update_tab(self, fhash, title = "[BAD TITLE]"):
|
||||
container = Gtk.EventBox()
|
||||
header = TabHeaderWidget(container, self._close_tab)
|
||||
page_num = self.append_page(container, header)
|
||||
# container = Gtk.EventBox()
|
||||
# header = TabHeaderWidget(container, self._close_tab)
|
||||
# page_num = self.append_page(container, header)
|
||||
|
||||
header.label.set_label(title)
|
||||
self.set_tab_detachable(container, True)
|
||||
self.set_tab_reorderable(container, True)
|
||||
# header.label.set_label(title)
|
||||
# self.set_tab_detachable(container, True)
|
||||
# self.set_tab_reorderable(container, True)
|
||||
|
||||
self.show_all()
|
||||
self.set_current_page(page_num)
|
||||
# self.show_all()
|
||||
# self.set_current_page(page_num)
|
||||
...
|
||||
|
||||
# Note: Need to get parent instead given we pass the close_tab method
|
||||
# from a potentially former notebook.
|
||||
def _close_tab(self, widget, container):
|
||||
notebook = container.get_parent()
|
||||
def close_tab(self, fhash):
|
||||
target = None
|
||||
for child in self.get_children():
|
||||
if child.fhash == fhash:
|
||||
target = child
|
||||
break
|
||||
|
||||
if notebook.get_n_pages() < 2: return
|
||||
|
||||
page_num = notebook.page_num(container)
|
||||
|
||||
event_system.emit(f"close_session_{self.INDEX}", (container.fhash))
|
||||
notebook.remove_page(page_num)
|
||||
|
||||
|
||||
# def close_tab(self, button, container, source_view, eve = None):
|
||||
# notebook = container.get_parent()
|
||||
# if notebook.NAME == "notebook_1" and notebook.get_n_pages() == 1:
|
||||
# return
|
||||
|
||||
# file_type = source_view.get_filetype()
|
||||
# if not file_type == "buffer":
|
||||
# uri = source_view.get_current_file().get_uri()
|
||||
# event_system.emit("textDocument/didClose", (file_type, uri,))
|
||||
|
||||
# page_num = notebook.page_num(container)
|
||||
# source_view._cancel_current_file_watchers()
|
||||
# notebook.remove_page(page_num)
|
||||
|
||||
# if notebook.NAME == "notebook_2" and notebook.get_n_pages() == 0:
|
||||
# notebook.hide()
|
||||
# event_system.emit("focused_target_changed", ("notebook_1",))
|
||||
self._close_tab(None, target)
|
@ -53,4 +53,4 @@ class TabHeaderWidget(Gtk.Box):
|
||||
close.connect("released", self.close_tab, *(self.content,))
|
||||
|
||||
self.add(self.label)
|
||||
self.add(close)
|
||||
self.add(close)
|
||||
|
@ -67,5 +67,4 @@ class DnDMixin:
|
||||
|
||||
files.append(gfile)
|
||||
|
||||
event_system.emit('set_pre_drop_dnd', (files,))
|
||||
|
||||
event_system.emit(f"set_pre_drop_dnd_{self.INDEX}", (files,))
|
||||
|
@ -17,8 +17,7 @@
|
||||
<div class="container editor-container">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<pre id="editor">
|
||||
</pre>
|
||||
<pre id="editor"></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -5,7 +5,6 @@ window.onload = (eve) => {
|
||||
console.log("Window Loaded...");
|
||||
}
|
||||
|
||||
|
||||
window.onerror = function(msg, url, line, col, error) {
|
||||
// Note that col & error are new to the HTML 5 spec and may not be supported in every browser.
|
||||
const suppressErrorAlert = false;
|
||||
|
@ -28,16 +28,14 @@ const editorCommands = [
|
||||
name: "newSession",
|
||||
bindKey: {win: "ctrl-t", mac: "ctrl-t"},
|
||||
exec: function(editor) {
|
||||
let elm = document.querySelectorAll(`[fhash="${currentSession}"]`)[0];
|
||||
newSession(elm);
|
||||
newSession();
|
||||
},
|
||||
readOnly: true
|
||||
}, {
|
||||
name: "closeSession",
|
||||
bindKey: {win: "ctrl-w", mac: "ctrl-w"},
|
||||
exec: function(editor) {
|
||||
let elm = document.querySelectorAll(`[fhash="${currentSession}"]`)[0];
|
||||
closeSession(elm.children[1]);
|
||||
closeSession(currentSession);
|
||||
},
|
||||
readOnly: true
|
||||
}, {
|
||||
@ -71,4 +69,4 @@ const editorCommands = [
|
||||
}
|
||||
|
||||
|
||||
];
|
||||
];
|
@ -24,16 +24,18 @@ const loadEditor = () => {
|
||||
editor.setTheme("ace/theme/one_dark");
|
||||
}
|
||||
|
||||
const loadInitialSessionTab = async () => {
|
||||
const loadInitialSessionTab = () => {
|
||||
newSession(null, editor.getSession());
|
||||
}
|
||||
|
||||
const newSession = async (elm = null, session = null) => {
|
||||
|
||||
|
||||
const newSession = (eve = null, session = null) => {
|
||||
let ftype = "buffer";
|
||||
let fhash = await getSHA256Hash( new Date().toString() );
|
||||
let fhash = Date.now().toString();
|
||||
session = ( isNotNullOrUndefined(session) ) ? session : ace.createEditSession("");
|
||||
|
||||
aceSessions[fhash] = {"ftype": ftype, "file": "", "session": session};
|
||||
aceSessions[fhash] = {"ftype": ftype, "fname": "", "path": "", "session": session};
|
||||
|
||||
setSession(ftype, fhash, session);
|
||||
sendMessage("load_buffer", fhash, "");
|
||||
@ -46,15 +48,6 @@ const switchSession = (fhash) => {
|
||||
setSession(ftype, fhash, session);
|
||||
}
|
||||
|
||||
|
||||
const closeSession = (fhash) => {
|
||||
delete aceSessions[fhash];
|
||||
|
||||
keys = Object.keys(aceSessions);
|
||||
console.log(keys.length);
|
||||
}
|
||||
|
||||
|
||||
const setSession = (ftype, fhash, session) => {
|
||||
currentSession = fhash;
|
||||
editor.setSession(session);
|
||||
@ -64,53 +57,28 @@ const setSession = (ftype, fhash, session) => {
|
||||
}
|
||||
}
|
||||
|
||||
const closeSession = (fhash) => {
|
||||
delete aceSessions[fhash];
|
||||
sendMessage("close", fhash, "");
|
||||
}
|
||||
|
||||
const removeSession = (fhash) => {
|
||||
delete aceSessions[fhash];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const loadFile = (ftype, fhash, file, content) => {
|
||||
session = ace.createEditSession( atob(content) );
|
||||
aceSessions[fhash] = {"ftype": ftype, "file": file, "session": session};
|
||||
|
||||
// let tab = `
|
||||
// <li class='tab active-tab' role="presentation" fhash='${fhash}' ftype='${ftype}' draggable="true"
|
||||
// ondragend="dragEnd()" ondragover="dragOver(event)" ondragstart="dragStart(event)"
|
||||
// >
|
||||
// <span class='file-name' onclick='switchSession(this)'>${file}</span>
|
||||
// <span class='close-button' onclick='closeSession(this)'>
|
||||
// <i class="bi bi-x-square" aria-hidden="true"></i>
|
||||
// </span>
|
||||
// </li>
|
||||
// `;
|
||||
|
||||
// TODO: Need to account for given editor we have focused when implimented...
|
||||
// document.getElementsByClassName("nav-tabs")[0]
|
||||
// .insertAdjacentHTML('beforeend', tab);
|
||||
const loadFile = (ftype, fname, fpath, content) => {
|
||||
let fhash = Date.now().toString();
|
||||
session = ace.createEditSession( atob(content) );
|
||||
aceSessions[fhash] = {"ftype": ftype, "fname": fname, "path": fpath, "session": session};
|
||||
|
||||
setSession(ftype, fhash, session);
|
||||
sendMessage("load_file", fhash, fname);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const updatedTab = (ftype, fname) => {
|
||||
// let elm = document.querySelectorAll(`[fhash="${currentSession}"]`)[0];
|
||||
// let tabTitleElm = elm.children[0];
|
||||
@ -126,9 +94,10 @@ const updatedTab = (ftype, fname) => {
|
||||
|
||||
|
||||
const saveSession = () => {
|
||||
let fhash = currentSession;
|
||||
let session = aceSessions[fhash]["session"];
|
||||
let data = session.getValue();
|
||||
// let fhash = currentSession;
|
||||
// let session = aceSessions[fhash]["session"];
|
||||
// let data = session.getValue();
|
||||
|
||||
sendMessage("save", fhash, data);
|
||||
// sendMessage("save", fhash, data);
|
||||
console.log("");
|
||||
}
|
Loading…
Reference in New Issue
Block a user