feature<Welcome>: add sort supports

This commit is contained in:
leo 2022-10-17 10:12:59 +08:00
parent 1beafbc84c
commit 918263130c
10 changed files with 101 additions and 35 deletions

View file

@ -34,14 +34,16 @@
<Rectangle Grid.Column="0" Grid.ColumnSpan="4" Fill="{DynamicResource Brush.Border0}" Height="1" VerticalAlignment="Bottom"/>
<!-- Main Menu -->
<controls:IconButton
<Button
Grid.Column="0"
Margin="4,4,4,0"
Width="14"
Icon="{StaticResource Icon.List}"
ToolTip="{DynamicResource Text.Launcher.Menu}"
Width="16"
Background="Transparent"
BorderThickness="0"
WindowChrome.IsHitTestVisibleInChrome="True"
Click="ToggleMainMenu"/>
Click="ToggleMainMenu">
<Path Data="{StaticResource Icon.Git}" Fill="{DynamicResource Brush.Logo}"/>
</Button>
<!-- Tabs -->
<widgets:PageTabBar

View file

@ -78,6 +78,12 @@ namespace SourceGit.Views {
} else {
tabs.Replace(tabs.Current, repo.Name, repo.Path, repo.Bookmark);
}
foreach (var tab in tabs.Tabs) {
if (tab.IsRepository) continue;
var dirty = container.Get(tabs.Current) as Widgets.Welcome;
if (dirty != null) dirty.UpdateVisibles();
}
}
#endregion

View file

@ -11,8 +11,6 @@
d:DesignHeight="800" d:DesignWidth="800">
<Grid Background="Transparent" AllowDrop="True" DragEnter="OnPageDragEnter" DragLeave="OnPageDragLeave" Drop="OnPageDrop">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
@ -24,34 +22,15 @@
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!-- App Name -->
<TextBlock
Grid.Row="0" Grid.Column="1"
Margin="0,64,0,0"
HorizontalAlignment="Left"
Text="SourceGit"
FontSize="28pt"
TextOptions.TextFormattingMode="Ideal"
TextOptions.TextRenderingMode="ClearType"
RenderOptions.ClearTypeHint="Enabled"/>
<!-- App Desc -->
<TextBlock
Grid.Row="1" Grid.Column="1"
HorizontalAlignment="Left"
Text="{DynamicResource Text.Welcome.Title}"
Foreground="{DynamicResource Brush.FG2}"
FontSize="18pt"
Margin="0,8"/>
<!-- Repositories Tool Bar -->
<Grid Grid.Row="2" Grid.Column="1" Margin="0,32,0,0">
<Grid Grid.Row="0" Grid.Column="1" Margin="0,100,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock
@ -86,10 +65,19 @@
Click="OnOpenTerminalClicked">
<Path Width="16" Height="14" Data="{StaticResource Icon.Terminal}" Fill="{DynamicResource Brush.Accent1}"/>
</Button>
<Button
Grid.Column="5"
Width="32" Height="28"
Style="{DynamicResource Style.Button.Link}"
ToolTip="{DynamicResource Text.Welcome.Sort}"
Click="OnSortMethodClicked">
<Path Width="16" Height="14" Data="{StaticResource Icon.Sort}" Fill="{DynamicResource Brush.Accent1}"/>
</Button>
</Grid>
<!-- Search Bar -->
<Grid Grid.Row="3" Grid.Column="1" Margin="2,8" Height="28" VerticalAlignment="Top">
<Grid Grid.Row="1" Grid.Column="1" Margin="2,8" Height="28" VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="24"/>
<ColumnDefinition Width="*"/>
@ -116,7 +104,7 @@
</Grid>
<!-- Repositories List -->
<Grid Grid.Row="4" Grid.Column="1" Margin="0,0,0,8" AllowDrop="True" Drop="OnDropFolder">
<Grid Grid.Row="2" Grid.Column="1" Margin="0,0,0,80" AllowDrop="True" Drop="OnDropFolder">
<Grid.Resources>
<converters:IntToBookmarkBrush x:Key="IntToBookmarkBrush"/>
</Grid.Resources>
@ -191,6 +179,6 @@
</Grid>
<!-- Popup -->
<widgets:PopupPanel x:Name="popup" Grid.Row="0" Grid.RowSpan="5" Grid.Column="0" Grid.ColumnSpan="3"/>
<widgets:PopupPanel x:Name="popup" Grid.Row="0" Grid.RowSpan="3" Grid.Column="0" Grid.ColumnSpan="3"/>
</Grid>
</UserControl>

View file

@ -67,6 +67,40 @@ namespace SourceGit.Views.Widgets {
if (MakeSureReady()) new Popups.Clone().Show();
}
private void FillSortMenu(ContextMenu menu, Models.Preference.SortMethod desired, string label) {
var item = new MenuItem();
item.Header = App.Text(label);
item.Click += (s, ev) => {
Models.Preference.Instance.General.SortBy = desired;
UpdateVisibles();
};
if (Models.Preference.Instance.General.SortBy == desired) {
var icon = new System.Windows.Shapes.Path();
icon.Data = FindResource("Icon.Check") as Geometry;
icon.Fill = FindResource("Brush.FG1") as Brush;
icon.Width = 12;
item.Icon = icon;
}
menu.Items.Add(item);
}
private void OnSortMethodClicked(object sender, RoutedEventArgs e) {
var menu = new ContextMenu();
menu.Placement = PlacementMode.Bottom;
menu.PlacementTarget = sender as Button;
menu.StaysOpen = false;
menu.Focusable = true;
FillSortMenu(menu, Models.Preference.SortMethod.ByNameASC, "Sort.NameAsc");
FillSortMenu(menu, Models.Preference.SortMethod.ByNameDESC, "Sort.NameDesc");
FillSortMenu(menu, Models.Preference.SortMethod.ByRecentlyOpened, "Sort.RecentlyOpened");
menu.IsOpen = true;
e.Handled = true;
}
private void OnRemoveRepository(object sender, RoutedEventArgs e) {
var repo = (sender as Button).DataContext as Models.Repository;
if (repo == null) return;
@ -206,6 +240,18 @@ namespace SourceGit.Views.Widgets {
}
}
switch (Models.Preference.Instance.General.SortBy) {
case Models.Preference.SortMethod.ByNameASC:
visibles.Sort((l, r) => l.Name.CompareTo(r.Name));
break;
case Models.Preference.SortMethod.ByNameDESC:
visibles.Sort((l, r) => r.Name.CompareTo(l.Name));
break;
default:
visibles.Sort((l, r) => r.LastOpenTime.CompareTo(l.LastOpenTime));
break;
}
repoList.ItemsSource = visibles;
}