generated from itdominator/Python-With-Gtk-Template
added buffer state indicator; small cleanup of unused code
This commit is contained in:
parent
f1cc022079
commit
6611eaacd2
@ -139,7 +139,7 @@ class EditorNotebook(EditorEventsMixin, EditorControllerMixin, Gtk.Notebook):
|
||||
gfile = Gio.File.new_for_path(parts[0])
|
||||
try:
|
||||
line = int(parts[1]) if len(parts) > 1 else 0
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
...
|
||||
|
||||
self.create_view(None, None, gfile, line)
|
||||
|
@ -69,7 +69,6 @@ class FileEventsMixin:
|
||||
|
||||
def finish_load_callback(obj, res, user_data=None):
|
||||
self._file_loader.load_finish(res)
|
||||
self._is_changed = False
|
||||
self._document_loaded()
|
||||
self.got_to_line(line)
|
||||
self.update_labels(gfile)
|
||||
@ -96,7 +95,7 @@ class FileEventsMixin:
|
||||
Gio.FileMonitorEvent.RENAMED,
|
||||
Gio.FileMonitorEvent.MOVED_IN,
|
||||
Gio.FileMonitorEvent.MOVED_OUT]:
|
||||
self._is_changed = True
|
||||
self._buffer.set_modified(True)
|
||||
|
||||
if eve_type in [ Gio.FileMonitorEvent.CHANGES_DONE_HINT ]:
|
||||
if self._ignore_internal_change:
|
||||
@ -112,17 +111,12 @@ class FileEventsMixin:
|
||||
self._file_change_watcher.cancel()
|
||||
self._file_change_watcher = None
|
||||
|
||||
if self._file_cdr_watcher:
|
||||
self._file_cdr_watcher.cancel()
|
||||
self._file_cdr_watcher = None
|
||||
|
||||
def _write_file(self, gfile, save_as = False):
|
||||
if not gfile: return
|
||||
|
||||
with open(gfile.get_path(), 'w') as f:
|
||||
if not save_as:
|
||||
self._ignore_internal_change = True
|
||||
self._is_changed = False
|
||||
|
||||
start_itr = self._buffer.get_start_iter()
|
||||
end_itr = self._buffer.get_end_iter()
|
||||
@ -131,4 +125,5 @@ class FileEventsMixin:
|
||||
f.write(text)
|
||||
f.close()
|
||||
|
||||
self._buffer.set_modified(False)
|
||||
return gfile
|
||||
|
@ -27,7 +27,6 @@ class SourceView(SourceViewEventsMixin, GtkSource.View):
|
||||
|
||||
self._file_loader = None
|
||||
self._file_change_watcher = None
|
||||
self._file_cdr_watcher = None
|
||||
self._current_file: Gio.File = None
|
||||
|
||||
self._current_filename: str = ""
|
||||
@ -35,7 +34,6 @@ class SourceView(SourceViewEventsMixin, GtkSource.View):
|
||||
self._current_filetype: str = "buffer"
|
||||
|
||||
self._skip_file_load = False
|
||||
self._is_changed = False
|
||||
self._ignore_internal_change = False
|
||||
self._buffer = self.get_buffer()
|
||||
self._completion = self.get_completion()
|
||||
@ -87,7 +85,7 @@ class SourceView(SourceViewEventsMixin, GtkSource.View):
|
||||
self._buffer.connect('changed', self._is_modified)
|
||||
self._buffer.connect("mark-set", self._on_cursor_move)
|
||||
self._buffer.connect('insert-text', self._insert_text)
|
||||
|
||||
self._buffer.connect('modified-changed', self._buffer_modified_changed)
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
...
|
||||
@ -119,7 +117,6 @@ class SourceView(SourceViewEventsMixin, GtkSource.View):
|
||||
general_style_tag.set_property('scale', 100)
|
||||
|
||||
def _is_modified(self, *args):
|
||||
self._is_changed = True
|
||||
self.update_cursor_position()
|
||||
|
||||
def _insert_text(self, text_buffer, location_itr, text_str, len_int):
|
||||
@ -129,6 +126,11 @@ class SourceView(SourceViewEventsMixin, GtkSource.View):
|
||||
with self._buffer.freeze_notify():
|
||||
GLib.idle_add(self._update_multi_line_markers, *(text_str,))
|
||||
|
||||
def _buffer_modified_changed(self, buffer):
|
||||
tab_widget = self.get_parent().get_tab_widget()
|
||||
tab_widget.set_status(changed = True if buffer.get_modified() else False)
|
||||
|
||||
|
||||
# NOTE: Mostly sinking pre-bound keys here to let our keybinder control instead...
|
||||
def _key_press_event(self, widget, eve):
|
||||
keyname = Gdk.keyval_name(eve.keyval)
|
||||
@ -212,13 +214,7 @@ class SourceView(SourceViewEventsMixin, GtkSource.View):
|
||||
if len(uris) == 0:
|
||||
uris = data.get_text().split("\n")
|
||||
|
||||
if self._is_changed:
|
||||
# TODO: Impliment change detection and offer to save as new file
|
||||
# Need to insure self._current_file gets set for further flow logic to work
|
||||
# self.maybe_saved()
|
||||
...
|
||||
|
||||
if not self._current_file:
|
||||
if not self._current_file and not self._buffer.get_modified():
|
||||
gfile = Gio.File.new_for_uri(uris[0])
|
||||
self.open_file(gfile)
|
||||
uris.pop(0)
|
||||
|
@ -48,9 +48,9 @@ class TabHeaderWidget(Gtk.Box):
|
||||
...
|
||||
|
||||
def _load_widgets(self):
|
||||
label = Gtk.Label()
|
||||
close = Gtk.Button()
|
||||
icon = Gtk.Image(stock=Gtk.STOCK_CLOSE)
|
||||
label = Gtk.Label()
|
||||
close = Gtk.Button()
|
||||
icon = Gtk.Image(stock = Gtk.STOCK_CLOSE)
|
||||
|
||||
# NOTE: Setup with settings and from file
|
||||
label.set_xalign(0.0)
|
||||
@ -68,3 +68,9 @@ class TabHeaderWidget(Gtk.Box):
|
||||
|
||||
def set_tab_label(self, label = "untitled"):
|
||||
self.get_children()[0].set_label(label)
|
||||
|
||||
def set_status(self, changed = False):
|
||||
label = self.get_children()[0]
|
||||
ctx = label.get_style_context()
|
||||
|
||||
ctx.add_class("buffer_changed") if changed else ctx.remove_class("buffer_changed")
|
||||
|
@ -1,6 +1,5 @@
|
||||
/* ---- make most desired things base transparent ---- */
|
||||
popover,
|
||||
/* popover *, */
|
||||
popover > box
|
||||
window > box,
|
||||
window > box > box,
|
||||
@ -66,21 +65,6 @@ popover {
|
||||
color: rgba(255, 255, 255, 1);
|
||||
}
|
||||
|
||||
|
||||
/* ---- miniview properties ---- */
|
||||
/* the mini view container of text */
|
||||
.mini-view > text {
|
||||
background: rgba(39, 43, 52, 0.64);
|
||||
}
|
||||
|
||||
/* draggable overlay of the miniview */
|
||||
.mini-view > * {
|
||||
background: rgba(64, 64, 64, 0.32);
|
||||
color: rgba(255, 255, 255, 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ---- make text selection slightly transparent ---- */
|
||||
* selection {
|
||||
background-color: rgba(0, 115, 115, 0.34);
|
||||
@ -90,11 +74,31 @@ popover {
|
||||
}
|
||||
|
||||
|
||||
/* ---- miniview properties ---- */
|
||||
.source-view,
|
||||
.mini-view {
|
||||
font-family: Monospace;
|
||||
}
|
||||
|
||||
/* the mini view container of text */
|
||||
.mini-view > text {
|
||||
background: rgba(39, 43, 52, 0.64);
|
||||
}
|
||||
|
||||
/* draggable overlay of the miniview */
|
||||
.mini-view > * {
|
||||
background: rgba(64, 64, 64, 0.32);
|
||||
color: rgba(255, 255, 255, 1);
|
||||
font-size: 1px;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* other properties */
|
||||
.buffer_changed {
|
||||
color: rgba(0, 232, 255, 0.64);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -106,8 +110,6 @@ popover {
|
||||
|
||||
|
||||
|
||||
.mini-view { font-size: 1px; }
|
||||
|
||||
/*
|
||||
Need these because updating buffer with get_tag_table and tags updates minimap to the same size due to its mapping structure...
|
||||
I've tried initial looks at:
|
||||
|
Loading…
Reference in New Issue
Block a user