[meld] dirdiff: Add an ISO-format version of our mtime column (#188)
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld] dirdiff: Add an ISO-format version of our mtime column (#188)
- Date: Sat, 8 Jan 2022 21:51:40 +0000 (UTC)
commit 85d62c46e7b2b1dba82895afd214af95c78ae010
Author: Kai Willadsen <kai willadsen gmail com>
Date: Sun Jan 9 07:49:49 2022 +1000
dirdiff: Add an ISO-format version of our mtime column (#188)
meld/dirdiff.py | 25 ++++++++++++++++++++++++-
meld/preferences.py | 8 ++++++--
meld/ui/cellrenderers.py | 15 ++++++++++++++-
3 files changed, 44 insertions(+), 4 deletions(-)
---
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index 30e01822..4bc7da25 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -45,6 +45,7 @@ from meld.ui.cellrenderers import (
CellRendererByteSize,
CellRendererDate,
CellRendererFileMode,
+ CellRendererISODate,
)
from meld.ui.emblemcellrenderer import EmblemCellRenderer
from meld.ui.util import map_widgets_into_lists
@@ -569,6 +570,14 @@ class DirDiff(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
column.set_attributes(rentext, timestamp=col_index(COL_TIME, i))
self.treeview[i].append_column(column)
self.columns_dict[i]["modification time"] = column
+ # Create ISO-format date-time CellRenderer
+ column = Gtk.TreeViewColumn(_("Modification time (ISO)"))
+ column.set_resizable(True)
+ rentext = CellRendererISODate()
+ column.pack_start(rentext, True)
+ column.set_attributes(rentext, timestamp=col_index(COL_TIME, i))
+ self.treeview[i].append_column(column)
+ self.columns_dict[i]["iso-time"] = column
# Create permissions CellRenderer
column = Gtk.TreeViewColumn(_("Permissions"))
column.set_resizable(True)
@@ -627,11 +636,22 @@ class DirDiff(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
_files_same, comparison_args=comparison_args)
self.refresh()
- def update_treeview_columns(self, settings, key):
+ def update_treeview_columns(
+ self, settings: Gio.Settings, key: str,
+ ) -> None:
"""Update the visibility and order of columns"""
+
columns = settings.get_value(key)
have_extra_columns = any(visible for name, visible in columns)
+ # Check for columns missing from the settings, special-casing
+ # the always-present name column
+ configured_columns = [name for name, visible in columns] + ["name"]
+ missing_columns = [
+ c for c in self.columns_dict[0].keys()
+ if c not in configured_columns
+ ]
+
for i, treeview in enumerate(self.treeview):
last_column = treeview.get_column(0)
for column_name, visible in columns:
@@ -644,6 +664,9 @@ class DirDiff(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
treeview.move_column_after(current_column, last_column)
last_column = current_column
+ for column_name in missing_columns:
+ self.columns_dict[i][column_name].set_visible(False)
+
treeview.set_headers_visible(have_extra_columns)
def get_filter_visibility(self) -> Tuple[bool, bool, bool]:
diff --git a/meld/preferences.py b/meld/preferences.py
index 8139a65f..67e99ad2 100644
--- a/meld/preferences.py
+++ b/meld/preferences.py
@@ -131,6 +131,7 @@ class ColumnList(Gtk.VBox, EditableListWidget):
available_columns = {
"size": _("Size"),
"modification time": _("Modification time"),
+ "iso-time": _("Modification time (ISO)"),
"permissions": _("Permissions"),
}
@@ -158,10 +159,13 @@ class ColumnList(Gtk.VBox, EditableListWidget):
column_order[column_name] = sort_key
columns = [
- (column_vis.get(name, True), name, label)
+ (column_vis.get(name, False), name, label)
for name, label in self.available_columns.items()
]
- columns = sorted(columns, key=lambda c: column_order.get(c[1], 0))
+ columns = sorted(
+ columns,
+ key=lambda c: column_order.get(c[1], len(self.available_columns)),
+ )
for visibility, name, label in columns:
self.model.append([visibility, name, label])
diff --git a/meld/ui/cellrenderers.py b/meld/ui/cellrenderers.py
index 24824894..488dd1ce 100644
--- a/meld/ui/cellrenderers.py
+++ b/meld/ui/cellrenderers.py
@@ -26,6 +26,9 @@ class CellRendererDate(Gtk.CellRendererText):
MIN_TIMESTAMP = -2147483648
DATETIME_FORMAT = "%a %d %b %Y %H:%M:%S"
+ def _format_datetime(self, dt: datetime.datetime) -> str:
+ return dt.strftime(self.DATETIME_FORMAT)
+
def get_timestamp(self):
return getattr(self, '_datetime', self.MIN_TIMESTAMP)
@@ -37,7 +40,7 @@ class CellRendererDate(Gtk.CellRendererText):
else:
try:
mod_datetime = datetime.datetime.fromtimestamp(value)
- time_str = mod_datetime.strftime(self.DATETIME_FORMAT)
+ time_str = self._format_datetime(mod_datetime)
except Exception:
time_str = ''
self.props.markup = time_str
@@ -51,6 +54,16 @@ class CellRendererDate(Gtk.CellRendererText):
)
+class CellRendererISODate(CellRendererDate):
+
+ __gtype_name__ = "CellRendererISODate"
+
+ def _format_datetime(self, dt: datetime.datetime) -> str:
+ # Limit our ISO display to seconds (i.e., no milli or
+ # microseconds) for usability
+ return dt.isoformat(timespec="seconds")
+
+
class CellRendererByteSize(Gtk.CellRendererText):
__gtype_name__ = "CellRendererByteSize"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]