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

Gtk: Only reload specified rows with GridView.ReloadData #2199

Merged
merged 1 commit into from
Apr 24, 2022
Merged
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
20 changes: 20 additions & 0 deletions src/Eto.Gtk/Forms/Controls/GridHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,26 @@ protected void UpdateModel()
SetSelectedRows(selected);
SkipSelectedChange = false;
}

protected (double? hscroll, double? vscroll) SaveScrollState()
{
var hscrollbar = Control.HScrollbar as Gtk.Scrollbar;
var vscrollbar = Control.VScrollbar as Gtk.Scrollbar;
var hscroll = hscrollbar?.Value;
var vscroll = vscrollbar?.Value;
return (hscroll, vscroll);
}

protected void RestoreScrollState((double? hscroll, double? vscroll) state)

{
var hscrollbar = Control.HScrollbar as Gtk.Scrollbar;
var vscrollbar = Control.VScrollbar as Gtk.Scrollbar;
if (state.hscroll != null)
hscrollbar.Value = state.hscroll.Value;
if (state.vscroll != null)
vscrollbar.Value = state.vscroll.Value;
}

protected override void Initialize()
{
Expand Down
12 changes: 11 additions & 1 deletion src/Eto.Gtk/Forms/Controls/GridViewHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,17 @@ public EnumerableChangedHandler<object> Collection

public void ReloadData(IEnumerable<int> rows)
{
UpdateModel();
if (rows != null)
{
foreach (var row in rows)
{
var iter = GetIterAtRow(row);
var path = GetPathAtRow(row);
Tree.Model.EmitRowChanged(path, iter);
}
}
else
UpdateModel();
}

public object GetCellAt(PointF location, out int column, out int row)
Expand Down
18 changes: 0 additions & 18 deletions src/Eto.Gtk/Forms/Controls/TreeGridViewHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -497,24 +497,6 @@ public int GetRowOfItem(ITreeGridItem item)
return collection == null ? -1 : collection.IndexOf(item);
}

(double? hscroll, double? vscroll) SaveScrollState()
{
var hscrollbar = Control.HScrollbar as Gtk.HScrollbar;
var vscrollbar = Control.VScrollbar as Gtk.VScrollbar;
var hscroll = hscrollbar?.Value;
var vscroll = vscrollbar?.Value;
return (hscroll, vscroll);
}

void RestoreScrollState((double? hscroll, double? vscroll) state)
{
var hscrollbar = Control.HScrollbar as Gtk.HScrollbar;
var vscrollbar = Control.VScrollbar as Gtk.VScrollbar;
if (state.hscroll != null)
hscrollbar.Value = state.hscroll.Value;
if (state.vscroll != null)
vscrollbar.Value = state.vscroll.Value;
}

public void ReloadData()
{
Expand Down