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])
|
gfile = Gio.File.new_for_path(parts[0])
|
||||||
try:
|
try:
|
||||||
line = int(parts[1]) if len(parts) > 1 else 0
|
line = int(parts[1]) if len(parts) > 1 else 0
|
||||||
except Exception as e:
|
except Exception:
|
||||||
...
|
...
|
||||||
|
|
||||||
self.create_view(None, None, gfile, line)
|
self.create_view(None, None, gfile, line)
|
||||||
|
@ -69,7 +69,6 @@ class FileEventsMixin:
|
|||||||
|
|
||||||
def finish_load_callback(obj, res, user_data=None):
|
def finish_load_callback(obj, res, user_data=None):
|
||||||
self._file_loader.load_finish(res)
|
self._file_loader.load_finish(res)
|
||||||
self._is_changed = False
|
|
||||||
self._document_loaded()
|
self._document_loaded()
|
||||||
self.got_to_line(line)
|
self.got_to_line(line)
|
||||||
self.update_labels(gfile)
|
self.update_labels(gfile)
|
||||||
@ -96,7 +95,7 @@ class FileEventsMixin:
|
|||||||
Gio.FileMonitorEvent.RENAMED,
|
Gio.FileMonitorEvent.RENAMED,
|
||||||
Gio.FileMonitorEvent.MOVED_IN,
|
Gio.FileMonitorEvent.MOVED_IN,
|
||||||
Gio.FileMonitorEvent.MOVED_OUT]:
|
Gio.FileMonitorEvent.MOVED_OUT]:
|
||||||
self._is_changed = True
|
self._buffer.set_modified(True)
|
||||||
|
|
||||||
if eve_type in [ Gio.FileMonitorEvent.CHANGES_DONE_HINT ]:
|
if eve_type in [ Gio.FileMonitorEvent.CHANGES_DONE_HINT ]:
|
||||||
if self._ignore_internal_change:
|
if self._ignore_internal_change:
|
||||||
@ -112,17 +111,12 @@ class FileEventsMixin:
|
|||||||
self._file_change_watcher.cancel()
|
self._file_change_watcher.cancel()
|
||||||
self._file_change_watcher = None
|
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):
|
def _write_file(self, gfile, save_as = False):
|
||||||
if not gfile: return
|
if not gfile: return
|
||||||
|
|
||||||
with open(gfile.get_path(), 'w') as f:
|
with open(gfile.get_path(), 'w') as f:
|
||||||
if not save_as:
|
if not save_as:
|
||||||
self._ignore_internal_change = True
|
self._ignore_internal_change = True
|
||||||
self._is_changed = False
|
|
||||||
|
|
||||||
start_itr = self._buffer.get_start_iter()
|
start_itr = self._buffer.get_start_iter()
|
||||||
end_itr = self._buffer.get_end_iter()
|
end_itr = self._buffer.get_end_iter()
|
||||||
@ -131,4 +125,5 @@ class FileEventsMixin:
|
|||||||
f.write(text)
|
f.write(text)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
self._buffer.set_modified(False)
|
||||||
return gfile
|
return gfile
|
||||||
|
@ -27,7 +27,6 @@ class SourceView(SourceViewEventsMixin, GtkSource.View):
|
|||||||
|
|
||||||
self._file_loader = None
|
self._file_loader = None
|
||||||
self._file_change_watcher = None
|
self._file_change_watcher = None
|
||||||
self._file_cdr_watcher = None
|
|
||||||
self._current_file: Gio.File = None
|
self._current_file: Gio.File = None
|
||||||
|
|
||||||
self._current_filename: str = ""
|
self._current_filename: str = ""
|
||||||
@ -35,7 +34,6 @@ class SourceView(SourceViewEventsMixin, GtkSource.View):
|
|||||||
self._current_filetype: str = "buffer"
|
self._current_filetype: str = "buffer"
|
||||||
|
|
||||||
self._skip_file_load = False
|
self._skip_file_load = False
|
||||||
self._is_changed = False
|
|
||||||
self._ignore_internal_change = False
|
self._ignore_internal_change = False
|
||||||
self._buffer = self.get_buffer()
|
self._buffer = self.get_buffer()
|
||||||
self._completion = self.get_completion()
|
self._completion = self.get_completion()
|
||||||
@ -87,7 +85,7 @@ class SourceView(SourceViewEventsMixin, GtkSource.View):
|
|||||||
self._buffer.connect('changed', self._is_modified)
|
self._buffer.connect('changed', self._is_modified)
|
||||||
self._buffer.connect("mark-set", self._on_cursor_move)
|
self._buffer.connect("mark-set", self._on_cursor_move)
|
||||||
self._buffer.connect('insert-text', self._insert_text)
|
self._buffer.connect('insert-text', self._insert_text)
|
||||||
|
self._buffer.connect('modified-changed', self._buffer_modified_changed)
|
||||||
|
|
||||||
def _subscribe_to_events(self):
|
def _subscribe_to_events(self):
|
||||||
...
|
...
|
||||||
@ -119,7 +117,6 @@ class SourceView(SourceViewEventsMixin, GtkSource.View):
|
|||||||
general_style_tag.set_property('scale', 100)
|
general_style_tag.set_property('scale', 100)
|
||||||
|
|
||||||
def _is_modified(self, *args):
|
def _is_modified(self, *args):
|
||||||
self._is_changed = True
|
|
||||||
self.update_cursor_position()
|
self.update_cursor_position()
|
||||||
|
|
||||||
def _insert_text(self, text_buffer, location_itr, text_str, len_int):
|
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():
|
with self._buffer.freeze_notify():
|
||||||
GLib.idle_add(self._update_multi_line_markers, *(text_str,))
|
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...
|
# NOTE: Mostly sinking pre-bound keys here to let our keybinder control instead...
|
||||||
def _key_press_event(self, widget, eve):
|
def _key_press_event(self, widget, eve):
|
||||||
keyname = Gdk.keyval_name(eve.keyval)
|
keyname = Gdk.keyval_name(eve.keyval)
|
||||||
@ -212,13 +214,7 @@ class SourceView(SourceViewEventsMixin, GtkSource.View):
|
|||||||
if len(uris) == 0:
|
if len(uris) == 0:
|
||||||
uris = data.get_text().split("\n")
|
uris = data.get_text().split("\n")
|
||||||
|
|
||||||
if self._is_changed:
|
if not self._current_file and not self._buffer.get_modified():
|
||||||
# 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:
|
|
||||||
gfile = Gio.File.new_for_uri(uris[0])
|
gfile = Gio.File.new_for_uri(uris[0])
|
||||||
self.open_file(gfile)
|
self.open_file(gfile)
|
||||||
uris.pop(0)
|
uris.pop(0)
|
||||||
|
@ -48,9 +48,9 @@ class TabHeaderWidget(Gtk.Box):
|
|||||||
...
|
...
|
||||||
|
|
||||||
def _load_widgets(self):
|
def _load_widgets(self):
|
||||||
label = Gtk.Label()
|
label = Gtk.Label()
|
||||||
close = Gtk.Button()
|
close = Gtk.Button()
|
||||||
icon = Gtk.Image(stock=Gtk.STOCK_CLOSE)
|
icon = Gtk.Image(stock = Gtk.STOCK_CLOSE)
|
||||||
|
|
||||||
# NOTE: Setup with settings and from file
|
# NOTE: Setup with settings and from file
|
||||||
label.set_xalign(0.0)
|
label.set_xalign(0.0)
|
||||||
@ -68,3 +68,9 @@ class TabHeaderWidget(Gtk.Box):
|
|||||||
|
|
||||||
def set_tab_label(self, label = "untitled"):
|
def set_tab_label(self, label = "untitled"):
|
||||||
self.get_children()[0].set_label(label)
|
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 ---- */
|
/* ---- make most desired things base transparent ---- */
|
||||||
popover,
|
popover,
|
||||||
/* popover *, */
|
|
||||||
popover > box
|
popover > box
|
||||||
window > box,
|
window > box,
|
||||||
window > box > box,
|
window > box > box,
|
||||||
@ -66,21 +65,6 @@ popover {
|
|||||||
color: rgba(255, 255, 255, 1);
|
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 ---- */
|
/* ---- make text selection slightly transparent ---- */
|
||||||
* selection {
|
* selection {
|
||||||
background-color: rgba(0, 115, 115, 0.34);
|
background-color: rgba(0, 115, 115, 0.34);
|
||||||
@ -90,11 +74,31 @@ popover {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ---- miniview properties ---- */
|
||||||
.source-view,
|
.source-view,
|
||||||
.mini-view {
|
.mini-view {
|
||||||
font-family: Monospace;
|
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...
|
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:
|
I've tried initial looks at:
|
||||||
|
Loading…
Reference in New Issue
Block a user