diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml
index 1b1f29d8f..d6e72dd83 100644
--- a/src/Resources/Locales/en_US.axaml
+++ b/src/Resources/Locales/en_US.axaml
@@ -533,6 +533,7 @@
Current Branch & Selected Commits
Selected Commits Only
Selected Commits (First-parent Only)
+ Reset Columns to Defaults
SELECTED {0} COMMITS
SHOW COLUMNS
Hold 'Ctrl' or 'Shift' to select multiple commits.
diff --git a/src/ViewModels/Histories.cs b/src/ViewModels/Histories.cs
index 128b53ff9..e26599651 100644
--- a/src/ViewModels/Histories.cs
+++ b/src/ViewModels/Histories.cs
@@ -58,6 +58,7 @@ public bool IsAuthorColumnVisible
if (_repo.UIStates.IsAuthorColumnVisibleInHistory != value)
{
_repo.UIStates.IsAuthorColumnVisibleInHistory = value;
+ _repo.UIStates.Save();
OnPropertyChanged();
}
}
@@ -71,6 +72,7 @@ public bool IsSHAColumnVisible
if (_repo.UIStates.IsSHAColumnVisibleInHistory != value)
{
_repo.UIStates.IsSHAColumnVisibleInHistory = value;
+ _repo.UIStates.Save();
OnPropertyChanged();
}
}
@@ -84,6 +86,7 @@ public bool IsAuthorTimeColumnVisible
if (_repo.UIStates.IsAuthorTimeColumnVisibleInHistory != value)
{
_repo.UIStates.IsAuthorTimeColumnVisibleInHistory = value;
+ _repo.UIStates.Save();
OnPropertyChanged();
}
}
@@ -97,6 +100,7 @@ public bool IsCommitTimeColumnVisible
if (_repo.UIStates.IsCommitTimeColumnVisibleInHistory != value)
{
_repo.UIStates.IsCommitTimeColumnVisibleInHistory = value;
+ _repo.UIStates.Save();
OnPropertyChanged();
}
}
@@ -240,6 +244,28 @@ public bool HasShowFlag(Models.HistoryShowFlags flag)
return _repo.UIStates.HistoryShowFlags.HasFlag(flag);
}
+ public void SaveColumnWidths()
+ {
+ _repo.UIStates.Save();
+ }
+
+ public void ResetColumns()
+ {
+ var defaults = new Models.RepositoryUIStates();
+ var states = _repo.UIStates;
+ states.IsAuthorColumnVisibleInHistory = defaults.IsAuthorColumnVisibleInHistory;
+ states.IsSHAColumnVisibleInHistory = defaults.IsSHAColumnVisibleInHistory;
+ states.IsAuthorTimeColumnVisibleInHistory = defaults.IsAuthorTimeColumnVisibleInHistory;
+ states.IsCommitTimeColumnVisibleInHistory = defaults.IsCommitTimeColumnVisibleInHistory;
+ states.AuthorColumnWidth = defaults.AuthorColumnWidth;
+ states.Save();
+
+ OnPropertyChanged(nameof(IsAuthorColumnVisible));
+ OnPropertyChanged(nameof(IsSHAColumnVisible));
+ OnPropertyChanged(nameof(IsAuthorTimeColumnVisible));
+ OnPropertyChanged(nameof(IsCommitTimeColumnVisible));
+ }
+
public void ToggleShowFlag(Models.HistoryShowFlags flag)
{
if (HasShowFlag(flag))
diff --git a/src/Views/Histories.axaml b/src/Views/Histories.axaml
index a3d24529f..ee8574b8c 100644
--- a/src/Views/Histories.axaml
+++ b/src/Views/Histories.axaml
@@ -34,6 +34,7 @@
ColumnHeaderHeight="24"
RowHeight="26"
LayoutUpdated="OnCommitListLayoutUpdated"
+ SizeChanged="OnCommitListSizeChanged"
ContextRequested="OnCommitListContextRequested"
DoubleTapped="OnCommitListDoubleTapped">
diff --git a/src/Views/Histories.axaml.cs b/src/Views/Histories.axaml.cs
index 846c59d1b..fc9f4eb80 100644
--- a/src/Views/Histories.axaml.cs
+++ b/src/Views/Histories.axaml.cs
@@ -464,8 +464,32 @@ protected override void OnDataContextChanged(EventArgs e)
{
base.OnDataContextChanged(e);
- if (DataContext is ViewModels.Histories vm)
- CommitListContainer.Columns[1].Width = new(vm.AuthorColumnWidth, DataGridLengthUnitType.Pixel);
+ ApplyAuthorColumnWidth();
+ }
+
+ private void OnCommitListSizeChanged(object sender, SizeChangedEventArgs e)
+ {
+ if (e.WidthChanged)
+ ApplyAuthorColumnWidth();
+ }
+
+ private double GetMaxAuthorColumnWidth()
+ {
+ var listWidth = CommitListContainer.Bounds.Width;
+ return listWidth > 0 ? Math.Max(listWidth * MaxAuthorColumnWidthRatio, MinAuthorColumnWidth) : double.MaxValue;
+ }
+
+ private void ApplyAuthorColumnWidth()
+ {
+ if (DataContext is not ViewModels.Histories vm)
+ return;
+
+ // The saved width is kept as-is. It is only capped while displayed, so a width chosen on a
+ // wide screen does not squeeze the subject column on a narrow one, and comes back when wide again.
+ var w = Math.Min(vm.AuthorColumnWidth, GetMaxAuthorColumnWidth());
+ var column = CommitListContainer.Columns[1];
+ if (column.Width.UnitType != DataGridLengthUnitType.Pixel || column.Width.Value != w)
+ column.Width = new(w, DataGridLengthUnitType.Pixel);
}
private void OnCommitListHeaderPointerMoved(object sender, PointerEventArgs e)
@@ -480,9 +504,10 @@ private void OnCommitListHeaderPointerMoved(object sender, PointerEventArgs e)
if (_resizingAuthorColumn)
{
var posX = CommitListContainer.Columns[0].ActualWidth;
- var maxW = posX + CommitListContainer.Columns[1].ActualWidth - 100;
+ var curW = CommitListContainer.Columns[1].ActualWidth;
+ var maxW = Math.Min(posX + curW - 100, GetMaxAuthorColumnWidth());
var delta = posX - pos.X;
- var w = Math.Max(Math.Min(vm.AuthorColumnWidth + delta, maxW), 80);
+ var w = Math.Max(Math.Min(curW + delta, maxW), MinAuthorColumnWidth);
CommitListContainer.Columns[1].Width = new(w, DataGridLengthUnitType.Pixel);
vm.AuthorColumnWidth = w;
}
@@ -520,6 +545,9 @@ private void OnCommitListHeaderPointerPressed(object sender, PointerPressedEvent
private void OnCommitListHeaderPointerReleased(object sender, PointerReleasedEventArgs e)
{
+ if (_resizingAuthorColumn && DataContext is ViewModels.Histories vm)
+ vm.SaveColumnWidths();
+
_resizingAuthorColumn = false;
}
@@ -719,6 +747,16 @@ private void OnOpenAdvancedOptions(object sender, RoutedEventArgs e)
ev.Handled = true;
};
+ var resetColumns = new MenuItem();
+ resetColumns.Header = App.Text("Histories.ResetColumns");
+ resetColumns.Icon = this.CreateMenuIcon("Icons.Reset");
+ resetColumns.Click += (_, ev) =>
+ {
+ histories.ResetColumns();
+ ApplyAuthorColumnWidth();
+ ev.Handled = true;
+ };
+
var menu = new ContextMenu();
menu.Placement = PlacementMode.BottomEdgeAlignedLeft;
menu.Items.Add(layout);
@@ -746,6 +784,8 @@ private void OnOpenAdvancedOptions(object sender, RoutedEventArgs e)
menu.Items.Add(shaColumn);
menu.Items.Add(authorTimeColumn);
menu.Items.Add(commitTimeColumn);
+ menu.Items.Add(new MenuItem() { Header = "-" });
+ menu.Items.Add(resetColumns);
menu.Open(button);
}
@@ -1969,6 +2009,8 @@ private async Task InteractiveRebaseWithPrefillActionAsync(ViewModels.Repository
private AvaloniaList _issueTrackers = null;
private bool _isScrollToTopVisible = false;
private bool _isDetailsPanelExpanded = true;
+ private const double MinAuthorColumnWidth = 80;
+ private const double MaxAuthorColumnWidthRatio = 0.4;
private bool _resizingAuthorColumn = false;
private Cursor _resizingCursor = new(StandardCursorType.SizeWestEast);
}