Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save sorting #286

Draft
wants to merge 6 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions data/com.github.stsdc.monitor.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,11 @@
<summary>Opened view</summary>
<description>The last opened view</description>
</key>

<key type="s" name="process-view-columns-sorting-state">
<default>'00000000'</default>
<summary>Process view columns sorting state</summary>
<description>Process view columns sorting state</description>
</key>
</schema>
</schemalist>
10 changes: 10 additions & 0 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public class Monitor.MainWindow : Hdy.ApplicationWindow {
resources = new Resources ();

process_view = new ProcessView ();
var sorting_state = MonitorApp.settings.get_string ("process-view-columns-sorting-state");
debug ("sorting state: " + sorting_state);

process_view.process_tree_view.set_sorting_state (sorting_state);
system_view = new SystemView (resources);

stack = new Gtk.Stack ();
Expand Down Expand Up @@ -90,6 +94,7 @@ public class Monitor.MainWindow : Hdy.ApplicationWindow {
this.present ();
setup_window_state ();
this.show_all ();

});

shortcuts = new Shortcuts (this);
Expand All @@ -107,6 +112,8 @@ public class Monitor.MainWindow : Hdy.ApplicationWindow {

MonitorApp.settings.set_string ("opened-view", stack.visible_child_name);

MonitorApp.settings.set_string ("process-view-columns-sorting-state", process_view.process_tree_view.get_sorting_state ());

if (MonitorApp.settings.get_boolean ("indicator-state")) {
this.hide_on_delete ();
} else {
Expand Down Expand Up @@ -138,6 +145,9 @@ public class Monitor.MainWindow : Hdy.ApplicationWindow {
} else {
move (position_x, position_y);
}



}

}
36 changes: 36 additions & 0 deletions src/Views/ProcessView/ProcessTreeView/CPUProcessTreeView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public class Monitor.CPUProcessTreeView : Gtk.TreeView {

cursor_changed.connect (_cursor_changed);
// model.process_manager.updated.connect (_cursor_changed);

}
public void icon_cell_layout (Gtk.CellLayout cell_layout, Gtk.CellRenderer icon_cell, Gtk.TreeModel model, Gtk.TreeIter iter) {
Value icon_name;
Expand Down Expand Up @@ -207,4 +208,39 @@ public class Monitor.CPUProcessTreeView : Gtk.TreeView {
}
}

public string get_sorting_state () {
string sorting_state = "";

foreach (var column in this.get_columns ()) {
int sort_indicator = column.sort_indicator ? 1 : 0;
sorting_state += "%d%d".printf (sort_indicator, column.get_sort_order ());

}
debug ("Get sorting state: " + sorting_state);

return sorting_state;
}

public void set_sorting_state (string sorting_state) {
debug ("== Going to set sorting state: " + sorting_state);

var columns = this.get_columns ();

int index = 0;
foreach (var column in columns) {

column.sort_indicator = (sorting_state[index] == '1');

var sort_type = sorting_state[index + 1] == '1' ? Gtk.SortType.ASCENDING : Gtk.SortType.DESCENDING;
column.set_sort_order (sort_type);

debug ("== " + (sorting_state[index] == '1').to_string () + " " + sort_type.to_string ());

index += 2;
}
get_sorting_state ();
set_model (model);

}

}