diff --git a/src/Models/OpenFile.vala b/src/Models/OpenFile.vala new file mode 100644 index 00000000..96e6a78b --- /dev/null +++ b/src/Models/OpenFile.vala @@ -0,0 +1,13 @@ +/* + * SPDX-License-Identifier: GPL-3.0-or-later + * SPDX-FileCopyrightText: 2025 elementary, Inc. (https://elementary.io) + */ + +public class Monitor.OpenFile : GLib.Object { + public string path { get; set; } + + public OpenFile (string path) { + Object (path: path); + } + +} diff --git a/src/Models/OpenFilesTreeViewModel.vala b/src/Models/OpenFilesTreeViewModel.vala deleted file mode 100644 index 48cdea28..00000000 --- a/src/Models/OpenFilesTreeViewModel.vala +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SPDX-License-Identifier: GPL-3.0-or-later - * SPDX-FileCopyrightText: 2025 elementary, Inc. (https://elementary.io) - */ - -public class Monitor.OpenFilesTreeViewModel : Gtk.TreeStore { - private Gee.Map open_files_paths = new Gee.HashMap (); - - private Process _process; - - public Process ? process { - get { - return _process; - } - set { - _process = value; - - // repopulating - open_files_paths.clear (); - clear (); - add_paths (); - } - } - - construct { - set_column_types (new Type[] { - typeof (string), - typeof (string), - }); - - } - - public void add_paths () { - foreach (var path in process.open_files_paths) { - add_path (path); - } - } - - private bool add_path (string path) { - if (path.substring (0, 1) == "/") { - Gtk.TreeIter iter; - append (out iter, null); - - set (iter, Column.NAME, path, -1); - - // open_files_paths.set (path, iter); - return true; - } - return false; - } - -} diff --git a/src/Views/ProcessView/ProcessInfoView/OpenFilesTreeView.vala b/src/Views/ProcessView/ProcessInfoView/OpenFilesTreeView.vala index 70992c9e..821547aa 100644 --- a/src/Views/ProcessView/ProcessInfoView/OpenFilesTreeView.vala +++ b/src/Views/ProcessView/ProcessInfoView/OpenFilesTreeView.vala @@ -3,53 +3,52 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ -public class Monitor.OpenFilesTreeView : Gtk.TreeView { - public new OpenFilesTreeViewModel model; - private Gtk.TreeViewColumn path_column; +public class Monitor.OpenFilesTreeView : Granite.Bin { + private GLib.ListStore model; public signal void process_selected (Process process); public OpenFilesTreeView () { - this.model = new OpenFilesTreeViewModel (); + model = new GLib.ListStore (typeof (Monitor.OpenFile)); + var selection_model = new Gtk.NoSelection (model); - show_expanders = false; + var path_column_factory = new Gtk.SignalListItemFactory (); + path_column_factory.setup.connect (on_path_column_setup); + path_column_factory.bind.connect (on_path_column_bind); - // setup name column - path_column = new Gtk.TreeViewColumn (); - path_column.title = _("Opened files"); - path_column.expand = true; - path_column.min_width = 250; - path_column.set_sort_column_id (Column.NAME); + var path_column = new Gtk.ColumnViewColumn (_("Opened files"), path_column_factory) { + expand = true, + }; - var icon_cell = new Gtk.CellRendererPixbuf (); - path_column.pack_start (icon_cell, false); - // path_column.add_attribute (icon_cell, "icon_name", Column.ICON); - path_column.set_cell_data_func (icon_cell, icon_cell_layout); + var column_view = new Gtk.ColumnView (selection_model); + column_view.append_column (path_column); - var name_cell = new Gtk.CellRendererText (); - name_cell.ellipsize = Pango.EllipsizeMode.END; - name_cell.set_fixed_height_from_font (1); - path_column.pack_start (name_cell, false); - path_column.add_attribute (name_cell, "text", Column.NAME); - insert_column (path_column, -1); - - // resize all of the columns - columns_autosize (); + vexpand = true; - set_model (model); + child = new Gtk.ScrolledWindow () { + child = column_view, + max_content_height = 250, + }; + } - hadjustment = null; - vadjustment = null; - vexpand = true; + private void on_path_column_setup (Gtk.SignalListItemFactory factory, GLib.Object list_item_obj) { + var label = new Gtk.Label (""); + label.halign = Gtk.Align.START; + ((Gtk.ListItem) list_item_obj).child = label; + } + private void on_path_column_bind (Gtk.SignalListItemFactory factory, GLib.Object list_item_obj) { + var list_item = (Gtk.ListItem) list_item_obj; + var item_data = (OpenFile) list_item.item; + var label = (Gtk.Label) list_item.child; + label.label = item_data.path; } - public void icon_cell_layout (Gtk.CellLayout cell_layout, Gtk.CellRenderer icon_cell, Gtk.TreeModel model, Gtk.TreeIter iter) { - try { - var icon = Icon.new_for_string ("emblem-documents-symbolic"); - ((Gtk.CellRendererPixbuf)icon_cell).icon_name = icon.to_string (); - } catch (Error e) { - warning (e.message); + public void update (Process process) { + visible = true; + model.remove_all (); + foreach (var path in process.open_files_paths) { + model.append (new OpenFile (path)); } } diff --git a/src/Views/ProcessView/ProcessInfoView/ProcessInfoIOStats.vala b/src/Views/ProcessView/ProcessInfoView/ProcessInfoIOStats.vala index ef592ba5..e287c27e 100644 --- a/src/Views/ProcessView/ProcessInfoView/ProcessInfoIOStats.vala +++ b/src/Views/ProcessView/ProcessInfoView/ProcessInfoIOStats.vala @@ -22,10 +22,6 @@ public class Monitor.ProcessInfoIOStats : Gtk.Grid { open_files_tree_view = new OpenFilesTreeView (); - var open_files_tree_view_scrolled = new Gtk.ScrolledWindow () { - child = open_files_tree_view - }; - column_spacing = 6; row_spacing = 6; column_homogeneous = true; @@ -35,7 +31,7 @@ public class Monitor.ProcessInfoIOStats : Gtk.Grid { attach (create_label_with_icon (write_bytes_label, "go-down-symbolic"), 0, 3); attach (cancelled_write_label, 1, 1); attach (cancelled_write_bytes_label, 1, 2); - attach (open_files_tree_view_scrolled, 0, 4, 2); + attach (open_files_tree_view, 0, 4, 2); } public void update (Process process) { diff --git a/src/Views/ProcessView/ProcessInfoView/ProcessInfoView.vala b/src/Views/ProcessView/ProcessInfoView/ProcessInfoView.vala index d32fcaa3..d793e266 100644 --- a/src/Views/ProcessView/ProcessInfoView/ProcessInfoView.vala +++ b/src/Views/ProcessView/ProcessInfoView/ProcessInfoView.vala @@ -37,8 +37,12 @@ public class Monitor.ProcessInfoView : Gtk.Box { permission_error_infobar.revealed = false; - process_info_io_stats.open_files_tree_view.model.process = _process; - process_info_io_stats.open_files_tree_view.visible = true; + process_info_io_stats.update (_process); + + // Updating open files list on process change (row select) only + // to prevent list jump to the top after a scroll + process_info_io_stats.open_files_tree_view.update (process); + } } } @@ -125,10 +129,6 @@ public class Monitor.ProcessInfoView : Gtk.Box { process_info_header.update (process); process_info_cpu_ram.update (process); process_info_io_stats.update (process); - - process_info_io_stats.open_files_tree_view.model.process = _process; - - process_info_io_stats.open_files_tree_view.visible = true; } } } diff --git a/src/meson.build b/src/meson.build index b6464f8d..ffd4d65e 100644 --- a/src/meson.build +++ b/src/meson.build @@ -33,7 +33,7 @@ source_app_files = [ # Models 'Models/TreeViewModel.vala', - 'Models/OpenFilesTreeViewModel.vala', + 'Models/OpenFile.vala', # Other # 'Managers/AppManager.vala',