generated from itdominator/Python-With-Gtk-Template
Vimifying efforts
This commit is contained in:
parent
362267fa69
commit
35a461ff68
|
@ -31,6 +31,7 @@ class BaseController(SignalsMixins, BaseControllerData):
|
|||
if len(messages) > 0:
|
||||
settings_manager.set_is_starting_with_file(True)
|
||||
|
||||
|
||||
self.setup_controller_data()
|
||||
|
||||
self._setup_styling()
|
||||
|
@ -38,6 +39,7 @@ class BaseController(SignalsMixins, BaseControllerData):
|
|||
self._subscribe_to_events()
|
||||
self._load_controllers()
|
||||
|
||||
|
||||
if args.no_plugins == "false":
|
||||
self.plugins.launch_plugins()
|
||||
|
||||
|
@ -50,8 +52,8 @@ class BaseController(SignalsMixins, BaseControllerData):
|
|||
|
||||
def _setup_signals(self):
|
||||
self.window.connect("focus-out-event", self.unset_keys_and_data)
|
||||
self.window.connect("key-press-event", self.on_global_key_press_controller)
|
||||
self.window.connect("key-release-event", self.on_global_key_release_controller)
|
||||
# self.window.connect("key-press-event", self.on_global_key_press_controller)
|
||||
# self.window.connect("key-release-event", self.on_global_key_release_controller)
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
event_system.subscribe("shutting_down", lambda: print("Shutting down..."))
|
||||
|
|
|
@ -84,10 +84,10 @@ class FilesController:
|
|||
event_system.emit(f"close_tab_{event.originator}", (event.fhash))
|
||||
case "load_buffer":
|
||||
self.load_buffer(event.fhash)
|
||||
event_system.emit(f"add_tab_{event.originator}", (event.fhash, "buffer",))
|
||||
# event_system.emit(f"add_tab_{event.originator}", (event.fhash, "buffer",))
|
||||
case "load_file":
|
||||
content = base64.b64decode( event.content.encode() ).decode("utf-8")
|
||||
event_system.emit(f"add_tab_with_name_{event.originator}", (event.fhash, content,))
|
||||
# event_system.emit(f"add_tab_with_name_{event.originator}", (event.fhash, content,))
|
||||
case _:
|
||||
return
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ from gi.repository import Gtk
|
|||
|
||||
# Application imports
|
||||
from ....controllers.files_controller import FilesController
|
||||
from ...controls.tab_bar import TabBar
|
||||
# from ...controls.tab_bar import TabBar
|
||||
from .fixed_box import FixedBox
|
||||
|
||||
|
||||
|
@ -44,5 +44,5 @@ class Editor(Gtk.Box):
|
|||
FilesController(self.INDEX)
|
||||
|
||||
def _load_widgets(self):
|
||||
self.add( TabBar(self.INDEX) )
|
||||
# self.add( TabBar(self.INDEX) )
|
||||
self.add( FixedBox(self.INDEX) )
|
|
@ -14,16 +14,49 @@
|
|||
</head>
|
||||
<body>
|
||||
|
||||
<div class="container editor-container">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<pre id="editor"></pre>
|
||||
|
||||
<div id="alerts-container" class="container-fluid">
|
||||
<div class="row page-alert-zone-container">
|
||||
<div id="page-alert-zone" class="col">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<pre id="editor"></pre>
|
||||
|
||||
<!-- Buffers modal -->
|
||||
<div class="modal fade" id="buffers-modal" tabindex="-1" role="dialog" data-bs-theme="dark">
|
||||
<div class="modal-dialog modal-xl" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h3>Buffers:</h3>
|
||||
</div>
|
||||
|
||||
<div class="modal-body margin-bottom-neg-200">
|
||||
<div class="row">
|
||||
<div class="col max-height-600 noselect">
|
||||
<ul id="buffers-selection" class="list-group scroller">
|
||||
</ul>
|
||||
<input id="buffer-search" class="form-control mr-sm-2" type="search" placeholder="Search..." aria-label="Search" />
|
||||
</div>
|
||||
<div class="col max-height-800">
|
||||
<pre id="preview-editor"></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<button type="button" data-bs-dismiss="modal" class="btn btn-danger btn-sm">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- For internal scripts... -->
|
||||
<!-- <script src="js/libs/jquery-3.7.1.min.js"></script> -->
|
||||
<script src="resources/js/libs/jquery-3.7.1.min.js"></script>
|
||||
|
||||
<!-- For Bootstrap... -->
|
||||
<script src="resources/js/libs/bootstrap5/bootstrap.bundle.min.js"></script>
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
/* IDs */
|
||||
|
||||
#editor,
|
||||
#preview-editor {
|
||||
background-color: #00000000;
|
||||
}
|
||||
|
||||
#editor {
|
||||
background-color: #00000000;
|
||||
margin: 0;
|
||||
|
@ -28,8 +33,30 @@
|
|||
}
|
||||
|
||||
|
||||
#preview-editor {
|
||||
height: -webkit-fill-available;
|
||||
width: -webkit-fill-available;
|
||||
max-height: calc(100% - 200px);
|
||||
}
|
||||
|
||||
#buffers-selection {
|
||||
max-height: 565px;
|
||||
min-height: 565px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
|
||||
/* CLASSES */
|
||||
|
||||
.max-height-800 {
|
||||
max-height: 800px;
|
||||
}
|
||||
|
||||
|
||||
.margin-bottom-neg-200 {
|
||||
margin-bottom: -200px;
|
||||
}
|
||||
|
||||
.ace_status-indicator {
|
||||
color: gray;
|
||||
position: absolute;
|
||||
|
|
|
@ -11,4 +11,14 @@ body {
|
|||
|
||||
ul, li {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.modal-header,
|
||||
.modal-footer {
|
||||
background-color: rgba(0, 0, 0, 0.64);
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
background-color: rgba(50, 56, 62, 0.74);
|
||||
border-color: rgba(249, 148, 6, 0.74);
|
||||
}
|
|
@ -1,8 +1,9 @@
|
|||
window.onload = (eve) => {
|
||||
loadEditor();
|
||||
loadInitialSessionTab();
|
||||
|
||||
console.log("Window Loaded...");
|
||||
|
||||
loadEditor();
|
||||
loadPreviewEditor();
|
||||
loadInitialSession();
|
||||
}
|
||||
|
||||
window.onerror = function(msg, url, line, col, error) {
|
||||
|
@ -16,4 +17,63 @@ window.onerror = function(msg, url, line, col, error) {
|
|||
|
||||
// If you return true, then error alerts (like in older versions of Internet Explorer) will be suppressed.
|
||||
return suppressErrorAlert;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
document.addEventListener("keyup", (eve) => {
|
||||
switch (eve.key) {
|
||||
case "ArrowUp":
|
||||
break;
|
||||
case "ArrowDown":
|
||||
break;
|
||||
case "ArrowLeft":
|
||||
break;
|
||||
case "ArrowRight":
|
||||
break;
|
||||
case "Enter":
|
||||
if ( isNotNullOrUndefined(previewSel) ) {
|
||||
let event = new MouseEvent('dblclick', {
|
||||
'view': window,
|
||||
'bubbles': true,
|
||||
'cancelable': true
|
||||
});
|
||||
|
||||
previewSel.dispatchEvent(event);
|
||||
}
|
||||
case "Control":
|
||||
isControlDown = false;
|
||||
case "b":
|
||||
if (isControlDown) {
|
||||
$('#buffers-modal').modal("toggle");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
document.addEventListener("keydown", (eve) => {
|
||||
switch (eve.key) {
|
||||
case "ArrowUp":
|
||||
if ( isNotNullOrUndefined(previewSel) ) {
|
||||
eve.preventDefault();
|
||||
selectPriorPreview();
|
||||
}
|
||||
break;
|
||||
case "ArrowDown":
|
||||
if ( isNotNullOrUndefined(previewSel) ) {
|
||||
eve.preventDefault();
|
||||
selectNextPreview();
|
||||
}
|
||||
break;
|
||||
case "ArrowLeft":
|
||||
break;
|
||||
case "ArrowRight":
|
||||
break;
|
||||
case "Control":
|
||||
isControlDown = true;
|
||||
default:
|
||||
break
|
||||
}
|
||||
});
|
||||
|
|
|
@ -3,5 +3,8 @@ const messenger = (window.webkit) ? window.webkit.messageHandlers : (message) =
|
|||
};
|
||||
|
||||
let editor = null;
|
||||
let previewEditor = null;
|
||||
let aceSessions = {};
|
||||
let currentSession = null;
|
||||
let previewSel = null;
|
||||
let isControlDown = false;
|
|
@ -17,6 +17,13 @@ const editorCommands = [
|
|||
editor.showKeyboardShortcuts();
|
||||
})
|
||||
}
|
||||
}, {
|
||||
name: "listBuffers",
|
||||
bindKey: {win: "ctrl-b", mac: "ctrl-b"},
|
||||
exec: function(editor) {
|
||||
listOpenBuffers();
|
||||
},
|
||||
readOnly: true
|
||||
}, {
|
||||
name: "saveSession",
|
||||
bindKey: {win: "ctrl-s", mac: "ctrl-s"},
|
||||
|
|
|
@ -1,3 +1,30 @@
|
|||
|
||||
const loadPreviewEditor = () => {
|
||||
ace.require("ace/ext/language_tools");
|
||||
|
||||
previewEditor = ace.edit("preview-editor");
|
||||
// Note: https://github.com/ajaxorg/ace/wiki/Configuring-Ace
|
||||
previewEditor.setOptions({
|
||||
printMarginColumn: 80,
|
||||
enableBasicAutocompletion: true,
|
||||
enableInlineAutocompletion: true,
|
||||
enableSnippets: true,
|
||||
enableLiveAutocompletion: true,
|
||||
highlightActiveLine: true,
|
||||
useSoftTabs: true,
|
||||
tabSize: 4,
|
||||
tooltipFollowsMouse: true,
|
||||
useWrapMode: false,
|
||||
scrollPastEnd: 0.5,
|
||||
mergeUndoDeltas: false
|
||||
});
|
||||
|
||||
// Note: https://github.com/ajaxorg/ace/wiki/Default-Keyboard-Shortcuts
|
||||
previewEditor.commands.addCommands(editorCommands);
|
||||
|
||||
previewEditor.setTheme("ace/theme/one_dark");
|
||||
}
|
||||
|
||||
const loadEditor = () => {
|
||||
ace.require("ace/ext/language_tools");
|
||||
|
||||
|
@ -24,7 +51,7 @@ const loadEditor = () => {
|
|||
editor.setTheme("ace/theme/one_dark");
|
||||
}
|
||||
|
||||
const loadInitialSessionTab = () => {
|
||||
const loadInitialSession = () => {
|
||||
newSession(null, editor.getSession());
|
||||
}
|
||||
|
||||
|
@ -93,3 +120,83 @@ const saveSession = (fhash) => {
|
|||
|
||||
sendMessage("save", ftype, fhash, fpath, content);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
const listOpenBuffers = () => {
|
||||
$('#buffers-modal').modal("toggle");
|
||||
|
||||
let ulElm = document.getElementById('buffers-selection');
|
||||
let keys = Object.keys(aceSessions);
|
||||
|
||||
clearChildNodes(ulElm);
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
let session = aceSessions[keys[i]];
|
||||
let liElm = document.createElement("li");
|
||||
let fname = aceSessions[keys[i]]["fname"];
|
||||
let fhash = keys[i];
|
||||
|
||||
liElm.innerText = ( fname === "" ) ? "buffer" : fname;
|
||||
liElm.classList.add("list-group-item");
|
||||
liElm.setAttribute("fhash", fhash);
|
||||
|
||||
if (fhash === currentSession) {
|
||||
previewSel = liElm;
|
||||
liElm.classList.add("bg-success");
|
||||
liElm.classList.add("bg-info");
|
||||
}
|
||||
|
||||
|
||||
liElm.addEventListener("click", (elm) => {
|
||||
previewSel.classList.remove("bg-info");
|
||||
|
||||
let fhash = elm.target.getAttribute("fhash");
|
||||
let ftype = aceSessions[fhash]["ftype"];
|
||||
let session = aceSessions[fhash]["session"];
|
||||
previewSel = elm.target;
|
||||
|
||||
previewEditor.setSession(session);
|
||||
|
||||
if (ftype !== "buffer") {
|
||||
previewEditor.session.setMode("ace/mode/" + ftype);
|
||||
}
|
||||
|
||||
previewSel.classList.add("bg-info");
|
||||
})
|
||||
|
||||
liElm.addEventListener("dblclick", (elm) => {
|
||||
let fhash = elm.target.getAttribute("fhash");
|
||||
let ftype = aceSessions[fhash]["ftype"];
|
||||
let session = aceSessions[fhash]["session"];
|
||||
previewSel = null;
|
||||
|
||||
setSession(ftype, fhash, session);
|
||||
$('#buffers-modal').modal("toggle");
|
||||
})
|
||||
|
||||
ulElm.appendChild(liElm);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
const selectPriorPreview = () => {
|
||||
let selectedElm = previewSel.previousElementSibling;
|
||||
if ( !isNotNullOrUndefined(selectedElm) ) {
|
||||
let childrenElms = previewSel.parentElement.children;
|
||||
selectedElm = childrenElms[childrenElms.length - 1];
|
||||
}
|
||||
|
||||
selectedElm.click();
|
||||
}
|
||||
|
||||
const selectNextPreview = () => {
|
||||
let selectedElm = previewSel.nextElementSibling;
|
||||
if ( !isNotNullOrUndefined(selectedElm) ) {
|
||||
let childrenElms = previewSel.parentElement.children;
|
||||
selectedElm = childrenElms[0];
|
||||
}
|
||||
|
||||
selectedElm.click();
|
||||
}
|
Loading…
Reference in New Issue