mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -08:00
optimize<Manager>: simplify Manager page
This commit is contained in:
parent
eac212737c
commit
dc17bb4b12
5 changed files with 162 additions and 436 deletions
|
@ -191,6 +191,27 @@ namespace SourceGit {
|
|||
|
||||
if (removedIdx >= 0) Groups.RemoveAt(removedIdx);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if given group has relations.
|
||||
/// </summary>
|
||||
/// <param name="parentId"></param>
|
||||
/// <param name="subId"></param>
|
||||
/// <returns></returns>
|
||||
public bool IsSubGroup(string parentId, string subId) {
|
||||
if (string.IsNullOrEmpty(parentId)) return false;
|
||||
|
||||
var g = FindGroup(subId);
|
||||
if (g == null) return false;
|
||||
|
||||
g = FindGroup(g.ParentId);
|
||||
while (g != null) {
|
||||
if (g.Id == parentId) return true;
|
||||
g = FindGroup(g.ParentId);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region METHODS_ON_REPOS
|
||||
|
@ -209,7 +230,6 @@ namespace SourceGit {
|
|||
Path = dir.FullName,
|
||||
Name = dir.Name,
|
||||
GroupId = groupId,
|
||||
LastOpenTime = 0,
|
||||
};
|
||||
|
||||
Repositories.Add(repo);
|
||||
|
|
|
@ -43,10 +43,6 @@ namespace SourceGit.Git {
|
|||
/// </summary>
|
||||
public int Color { get; set; } = 0;
|
||||
/// <summary>
|
||||
/// Last open time(File time format).
|
||||
/// </summary>
|
||||
public long LastOpenTime { get; set; }
|
||||
/// <summary>
|
||||
/// Expand tags.
|
||||
/// </summary>
|
||||
public bool ExpandTags { get; set; }
|
||||
|
@ -255,7 +251,6 @@ namespace SourceGit.Git {
|
|||
/// Open repository.
|
||||
/// </summary>
|
||||
public void Open() {
|
||||
LastOpenTime = DateTime.Now.ToFileTime();
|
||||
isWatcherDisabled = false;
|
||||
|
||||
GitDir = ".git";
|
||||
|
|
|
@ -69,7 +69,7 @@ namespace SourceGit.UI {
|
|||
|
||||
public string Title {
|
||||
get {
|
||||
if (Repo == null) return "Repositories";
|
||||
if (Repo == null) return "New Page";
|
||||
return Repo.Parent == null ? Repo.Name : $"{Repo.Parent.Name} : {Repo.Name}";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:SourceGit.UI"
|
||||
xmlns:git="clr-namespace:SourceGit.Git"
|
||||
xmlns:converters="clr-namespace:SourceGit.Converters"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
|
@ -13,244 +12,149 @@
|
|||
<UserControl.Resources>
|
||||
<converters:IntToRepoColor x:Key="IntToRepoColor"/>
|
||||
<converters:BoolToCollapsed x:Key="BoolToCollapsed"/>
|
||||
<converters:InverseBoolToCollapsed x:Key="InverseBoolToCollapsed"/>
|
||||
<converters:InverseBool x:Key="InverseBool"/>
|
||||
</UserControl.Resources>
|
||||
|
||||
<Grid>
|
||||
|
||||
<Grid>
|
||||
<!-- Main Body -->
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="200" MinWidth="200" MaxWidth="360"/>
|
||||
<ColumnDefinition Width="2"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- Left panel -->
|
||||
<Grid Grid.Column="0" Background="{StaticResource Brush.BG1}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="32"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="32"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- Recent Opened Repositories -->
|
||||
<Label Grid.Row="0" Margin="8,8,0,0" Content="RECENTLY OPENED" Style="{StaticResource Style.Label.GroupHeader}"/>
|
||||
<ListView
|
||||
x:Name="recentOpened"
|
||||
Grid.Row="1"
|
||||
Height="Auto"
|
||||
Margin="0,4"
|
||||
Background="Transparent"
|
||||
BorderThickness="0"
|
||||
Style="{StaticResource Style.ListView.Borderless}"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
||||
GotFocus="RecentsGotFocus"
|
||||
SelectionChanged="RecentsSelectionChanged"
|
||||
MouseDoubleClick="RecentsMouseDoubleClick">
|
||||
<ListView.ItemContainerStyle>
|
||||
<Style TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource Style.ListViewItem.Borderless}">
|
||||
<EventSetter Event="ContextMenuOpening" Handler="RecentsContextMenuOpening"/>
|
||||
</Style>
|
||||
</ListView.ItemContainerStyle>
|
||||
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type git:Repository}">
|
||||
<Grid Height="24">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Path Grid.Column="0" Width="12" Margin="16,0,0,0" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Git}"/>
|
||||
|
||||
<StackPanel Grid.Column="1" Orientation="Horizontal">
|
||||
<TextBlock Margin="4,0" Text="{Binding Name}" VerticalAlignment="Center" Foreground="{StaticResource Brush.FG}"/>
|
||||
<TextBlock FontSize="10" Text="{Binding Path}" VerticalAlignment="Center" Foreground="{StaticResource Brush.FG2}"/>
|
||||
</StackPanel>
|
||||
|
||||
<Path
|
||||
Grid.Column="2"
|
||||
Width="12" Height="12" Margin="4,0"
|
||||
Style="{StaticResource Style.Icon}"
|
||||
Data="{StaticResource Icon.Bookmark}"
|
||||
Fill="{Binding Color, Converter={StaticResource IntToRepoColor}}"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
|
||||
<!-- Repositories' tree -->
|
||||
<Grid Grid.Row="2" Margin="8,8,0,0">
|
||||
<Grid Background="{StaticResource Brush.BG1}" HorizontalAlignment="Center" MinWidth="420" TextElement.FontFamily="Consolas">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- Welcome -->
|
||||
<StackPanel Orientation="Vertical" Margin="0,64,0,0">
|
||||
<Path Width="72" Height="72" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Git}" Fill="#FFF05133"/>
|
||||
<TextBlock Grid.Column="0" Margin="0,16" HorizontalAlignment="Center" Text="Welcome to SourceGit :)" FontSize="26" FontWeight="ExtraBold" Foreground="{StaticResource Brush.FG2}"/>
|
||||
<Grid Margin="0,0,0,36">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="8"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Label Grid.Column="0" Content="REPOSITORIES" Style="{StaticResource Style.Label.GroupHeader}"/>
|
||||
|
||||
<Button Grid.Column="1" Click="CloneRepo" Style="{StaticResource Style.Button}" ToolTip="Clone Remote Repository">
|
||||
<Path Width="14" Height="14" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Pull}" Opacity=".8"/>
|
||||
<Button Click="OpenOrAddRepo" Grid.Column="0" Style="{StaticResource Style.Button.Bordered}">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Path Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Folder}"/>
|
||||
<Label Margin="4,0,0,0" Content="Open Local Repository"/>
|
||||
</StackPanel>
|
||||
</Button>
|
||||
|
||||
<Button Grid.Column="2" Click="OpenOrAddRepo" Style="{StaticResource Style.Button}" Margin="8,0,4,0" ToolTip="Open Local Repository">
|
||||
<Path Width="14" Height="14" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Folder.Open}" Opacity=".8"/>
|
||||
<Button Click="CloneRepo" Grid.Column="2" Style="{StaticResource Style.Button.Bordered}">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Path Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Pull}"/>
|
||||
<Label Margin="4,0,0,0" Content="Clone Remote Repository"/>
|
||||
</StackPanel>
|
||||
</Button>
|
||||
</Grid>
|
||||
<TreeView
|
||||
x:Name="repositories"
|
||||
Grid.Row="3"
|
||||
Margin="0,4"
|
||||
Padding="0"
|
||||
AllowDrop="True"
|
||||
ContextMenuOpening="TreeContextMenuOpening"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
||||
Drop="TreeDrop"
|
||||
GotFocus="TreeGotFocus"
|
||||
MouseMove="TreeMouseMove">
|
||||
<Rectangle Height=".5" Fill="{StaticResource Brush.Border1}"/>
|
||||
</StackPanel>
|
||||
|
||||
<TreeView.ItemContainerStyle>
|
||||
<Style TargetType="{x:Type TreeViewItem}" BasedOn="{StaticResource Style.TreeView.ItemContainerStyle}">
|
||||
<Setter Property="IsExpanded" Value="{Binding IsExpended, Mode=TwoWay}"/>
|
||||
<!-- Repositories' tree -->
|
||||
<Grid Grid.Row="1" Margin="0,8,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<EventSetter Event="Selected" Handler="TreeNodeSelected"/>
|
||||
<EventSetter Event="DragOver" Handler="TreeNodeDragOver"/>
|
||||
<EventSetter Event="Drop" Handler="TreeNodeDrop"/>
|
||||
<EventSetter Event="Expanded" Handler="TreeNodeIsExpandedChanged"/>
|
||||
<EventSetter Event="Collapsed" Handler="TreeNodeIsExpandedChanged"/>
|
||||
<EventSetter Event="KeyDown" Handler="TreeNodeKeyDown"/>
|
||||
<EventSetter Event="ContextMenuOpening" Handler="TreeNodeContextMenuOpening"/>
|
||||
<EventSetter Event="MouseDoubleClick" Handler="TreeNodeDoubleClick"/>
|
||||
</Style>
|
||||
</TreeView.ItemContainerStyle>
|
||||
<TextBlock Grid.Column="0" Text="REPOSITORIES" FontSize="18" FontWeight="ExtraBold" Foreground="{StaticResource Brush.FG2}"/>
|
||||
<TextBlock Grid.Column="2" Text="DRAG-DROP YOUR FOLDER" FontSize="14" Foreground="{StaticResource Brush.FG2}" VerticalAlignment="Center"/>
|
||||
</Grid>
|
||||
<TreeView
|
||||
x:Name="repositories"
|
||||
Grid.Row="2"
|
||||
Margin="0,4"
|
||||
Padding="0"
|
||||
AllowDrop="True"
|
||||
TextElement.FontSize="14"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
||||
ContextMenuOpening="TreeContextMenuOpening"
|
||||
Drop="TreeDrop"
|
||||
MouseMove="TreeMouseMove">
|
||||
|
||||
<TreeView.ItemTemplate>
|
||||
<HierarchicalDataTemplate ItemsSource="{Binding Children}">
|
||||
<Grid Height="26">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Path
|
||||
x:Name="icon"
|
||||
Grid.Column="0"
|
||||
Width="14" Height="14"
|
||||
Style="{StaticResource Style.Icon}"
|
||||
Data="{StaticResource Icon.Folder.Fill}"/>
|
||||
|
||||
<TextBlock
|
||||
x:Name="name"
|
||||
Grid.Column="1"
|
||||
Margin="4,0,0,0"
|
||||
Text="{Binding Name}"
|
||||
<TreeView.ItemContainerStyle>
|
||||
<Style TargetType="{x:Type TreeViewItem}" BasedOn="{StaticResource Style.TreeView.ItemContainerStyle}">
|
||||
<Setter Property="IsExpanded" Value="{Binding IsExpended, Mode=TwoWay}"/>
|
||||
<Setter Property="AllowDrop" Value="{Binding IsRepo, Converter={StaticResource InverseBool}}"/>
|
||||
|
||||
<EventSetter Event="DragOver" Handler="TreeNodeDragOver"/>
|
||||
<EventSetter Event="Drop" Handler="TreeNodeDrop"/>
|
||||
<EventSetter Event="Expanded" Handler="TreeNodeIsExpandedChanged"/>
|
||||
<EventSetter Event="Collapsed" Handler="TreeNodeIsExpandedChanged"/>
|
||||
<EventSetter Event="KeyDown" Handler="TreeNodeKeyDown"/>
|
||||
<EventSetter Event="ContextMenuOpening" Handler="TreeNodeContextMenuOpening"/>
|
||||
<EventSetter Event="MouseDoubleClick" Handler="TreeNodeDoubleClick"/>
|
||||
</Style>
|
||||
</TreeView.ItemContainerStyle>
|
||||
|
||||
<TreeView.ItemTemplate>
|
||||
<HierarchicalDataTemplate ItemsSource="{Binding Children}">
|
||||
<Grid Height="32">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Path
|
||||
x:Name="icon"
|
||||
Grid.Column="0"
|
||||
Width="16" Height="16"
|
||||
Style="{StaticResource Style.Icon}"
|
||||
Data="{StaticResource Icon.Folder.Fill}"/>
|
||||
|
||||
<StackPanel
|
||||
x:Name="name"
|
||||
Grid.Column="1"
|
||||
Orientation="Horizontal"
|
||||
Visibility="{Binding IsEditing, Converter={StaticResource InverseBoolToCollapsed}}">
|
||||
<TextBlock
|
||||
Margin="8,0,0,0"
|
||||
Text="{Binding Name}"
|
||||
Foreground="{StaticResource Brush.FG}"
|
||||
VerticalAlignment="Center"/>
|
||||
|
||||
<TextBox
|
||||
x:Name="editName"
|
||||
Grid.Column="1"
|
||||
Margin="4,0,0,0"
|
||||
Text="{Binding Name}"
|
||||
Loaded="TreeNodeRenameStart"
|
||||
KeyDown="TreeNodeRenameKeyDown"
|
||||
LostFocus="TreeNodeRenameEnd"/>
|
||||
|
||||
<Path
|
||||
x:Name="bookmark"
|
||||
Grid.Column="2"
|
||||
Width="14" Height="14"
|
||||
Margin="4,0"
|
||||
Style="{StaticResource Style.Icon}"
|
||||
Data="{StaticResource Icon.Bookmark}"
|
||||
Fill="{Binding Color, Converter={StaticResource IntToRepoColor}}"
|
||||
<TextBlock
|
||||
Margin="8,0,0,0"
|
||||
Text="{Binding Id}"
|
||||
Foreground="{StaticResource Brush.FG2}"
|
||||
VerticalAlignment="Center"
|
||||
Visibility="{Binding IsRepo, Converter={StaticResource BoolToCollapsed}}"/>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
|
||||
<HierarchicalDataTemplate.Triggers>
|
||||
<DataTrigger Binding="{Binding IsExpended}" Value="True">
|
||||
<Setter TargetName="icon" Property="Data" Value="{StaticResource Icon.Folder.Open}"/>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding IsRepo}" Value="True">
|
||||
<Setter TargetName="icon" Property="Data" Value="{StaticResource Icon.Git}"/>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding IsEditing}" Value="True">
|
||||
<Setter TargetName="name" Property="Visibility" Value="Hidden"/>
|
||||
<Setter TargetName="editName" Property="Visibility" Value="Visible"/>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding IsEditing}" Value="False">
|
||||
<Setter TargetName="name" Property="Visibility" Value="Visible"/>
|
||||
<Setter TargetName="editName" Property="Visibility" Value="Hidden"/>
|
||||
</DataTrigger>
|
||||
</HierarchicalDataTemplate.Triggers>
|
||||
</HierarchicalDataTemplate>
|
||||
</TreeView.ItemTemplate>
|
||||
</TreeView>
|
||||
</Grid>
|
||||
<TextBox
|
||||
x:Name="editName"
|
||||
Grid.Column="1"
|
||||
Margin="4,0,0,0"
|
||||
Text="{Binding Name}"
|
||||
Loaded="TreeNodeRenameStart"
|
||||
KeyDown="TreeNodeRenameKeyDown"
|
||||
LostFocus="TreeNodeRenameEnd"
|
||||
Visibility="{Binding IsEditing, Converter={StaticResource BoolToCollapsed}}"/>
|
||||
|
||||
<GridSplitter Grid.Column="1" HorizontalAlignment="Stretch" Background="{StaticResource Brush.BG3}"/>
|
||||
<Path
|
||||
x:Name="bookmark"
|
||||
Grid.Column="2"
|
||||
Width="14" Height="14"
|
||||
Margin="4,0"
|
||||
Style="{StaticResource Style.Icon}"
|
||||
Data="{StaticResource Icon.Bookmark}"
|
||||
Fill="{Binding Color, Converter={StaticResource IntToRepoColor}}"
|
||||
Visibility="{Binding IsRepo, Converter={StaticResource BoolToCollapsed}}"/>
|
||||
</Grid>
|
||||
|
||||
<!-- Right Panel -->
|
||||
<Grid Grid.Column="2" Background="{StaticResource Brush.BG3}">
|
||||
<!-- Brief -->
|
||||
<Grid Margin="16">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- Name & Path -->
|
||||
<StackPanel Grid.Row="0" Orientation="Horizontal">
|
||||
<TextBlock x:Name="repoName" Margin="4,0,0,0" FontSize="28" FontWeight="Bold" FontFamily="Consolas" Foreground="{StaticResource Brush.FG}" VerticalAlignment="Center"/>
|
||||
<Border Background="{StaticResource Brush.BG4}" Margin="16,0,0,0" Height="26" CornerRadius="4" VerticalAlignment="Center">
|
||||
<TextBlock x:Name="repoPath" FontSize="20" Margin="8,0" FontWeight="Light" FontFamily="Consolas" Foreground="{StaticResource Brush.FG2}" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Status of selected repository -->
|
||||
<Label Grid.Row="1" Content="STATUS" FontSize="16" Margin="0,16,0,4" FontWeight="Bold" Opacity=".8"/>
|
||||
<StackPanel Grid.Row="2" Orientation="Horizontal">
|
||||
<Label Content="Local Changes :" Opacity=".5" FontWeight="Bold"/>
|
||||
<Label x:Name="localChanges" Margin="2,0,0,0"/>
|
||||
|
||||
<Label Content="Total Commits :" Opacity=".5" FontWeight="Bold"/>
|
||||
<Label x:Name="totalCommits" Margin="2,0,0,0"/>
|
||||
|
||||
<Label Content="Last Commit :" Opacity=".5" FontWeight="Bold"/>
|
||||
<Border Background="{StaticResource Brush.BG4}" Height="18" CornerRadius="4" VerticalAlignment="Center">
|
||||
<Label x:Name="lastCommitId" Foreground="{StaticResource Brush.FG2}" FontFamily="Consolas" Padding="4,0" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
<TextBlock x:Name="lastCommit" Margin="4,0,0,0" FontFamily="Consolas" Foreground="{StaticResource Brush.FG}" VerticalAlignment="Center"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- README.md -->
|
||||
<Label Grid.Row="3" Content="README" FontSize="16" Margin="0,16,0,4" FontWeight="Bold" Opacity=".8"/>
|
||||
<Border Grid.Row="4" Margin="6,0,0,0" BorderBrush="{StaticResource Brush.BG4}" BorderThickness="1">
|
||||
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
|
||||
<TextBlock FontSize="10pt"
|
||||
FontFamily="Consolas"
|
||||
Padding="8"
|
||||
Opacity="0.8"
|
||||
Background="{StaticResource Brush.BG2}"
|
||||
Foreground="{StaticResource Brush.FG}"
|
||||
x:Name="readme"/>
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
</Grid>
|
||||
|
||||
<!-- Mask -->
|
||||
<Border x:Name="briefMask" Background="{StaticResource Brush.BG3}" IsHitTestVisible="False">
|
||||
<StackPanel Orientation="Vertical" VerticalAlignment="Center" Opacity=".2">
|
||||
<Path Width="160" Height="160" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Git}"/>
|
||||
<Label Margin="0,32,0,0" Content="WELCOME TO SOURCE GIT :-)" FontSize="24" FontWeight="UltraBold" HorizontalAlignment="Center"/>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Grid>
|
||||
<HierarchicalDataTemplate.Triggers>
|
||||
<DataTrigger Binding="{Binding IsExpended}" Value="True">
|
||||
<Setter TargetName="icon" Property="Data" Value="{StaticResource Icon.Folder.Open}"/>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding IsRepo}" Value="True">
|
||||
<Setter TargetName="icon" Property="Data" Value="{StaticResource Icon.Git}"/>
|
||||
</DataTrigger>
|
||||
</HierarchicalDataTemplate.Triggers>
|
||||
</HierarchicalDataTemplate>
|
||||
</TreeView.ItemTemplate>
|
||||
</TreeView>
|
||||
</Grid>
|
||||
|
||||
<!-- Popup -->
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
|
@ -14,7 +12,6 @@ namespace SourceGit.UI {
|
|||
/// Repository manager.
|
||||
/// </summary>
|
||||
public partial class Manager : UserControl {
|
||||
private TreeViewItem selectedTreeViewItem = null;
|
||||
|
||||
/// <summary>
|
||||
/// Used to build tree
|
||||
|
@ -35,7 +32,6 @@ namespace SourceGit.UI {
|
|||
/// </summary>
|
||||
public Manager() {
|
||||
InitializeComponent();
|
||||
UpdateRecentOpened();
|
||||
UpdateTree();
|
||||
}
|
||||
|
||||
|
@ -59,105 +55,13 @@ namespace SourceGit.UI {
|
|||
private void CloneRepo(object sender, RoutedEventArgs e) {
|
||||
if (MakeSureReady()) {
|
||||
popupManager.Show(new Clone(popupManager, () => {
|
||||
UpdateRecentOpened();
|
||||
UpdateTree();
|
||||
}));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region EVENT_RECENT_LISTVIEW
|
||||
private void RecentsGotFocus(object sender, RoutedEventArgs e) {
|
||||
if (selectedTreeViewItem != null) selectedTreeViewItem.IsSelected = false;
|
||||
selectedTreeViewItem = null;
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void RecentsSelectionChanged(object sender, SelectionChangedEventArgs e) {
|
||||
var recent = recentOpened.SelectedItem as Git.Repository;
|
||||
if (recent != null) ShowBrief(recent);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void RecentsMouseDoubleClick(object sender, MouseButtonEventArgs e) {
|
||||
var list = sender as ListView;
|
||||
var recent = list.SelectedItem as Git.Repository;
|
||||
|
||||
if (recent != null) {
|
||||
CheckAndOpenRepo(recent.Path);
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void RecentsContextMenuOpening(object sender, ContextMenuEventArgs e) {
|
||||
var repo = (sender as ListViewItem).DataContext as Git.Repository;
|
||||
if (repo == null) return;
|
||||
|
||||
var open = new MenuItem();
|
||||
open.Header = "Open";
|
||||
open.Click += (o, ev) => {
|
||||
CheckAndOpenRepo(repo.Path);
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
var explore = new MenuItem();
|
||||
explore.Header = "Open Container Folder";
|
||||
explore.Click += (o, ev) => {
|
||||
Process.Start("explorer", repo.Path);
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
var iconBookmark = FindResource("Icon.Bookmark") as Geometry;
|
||||
var bookmark = new MenuItem();
|
||||
bookmark.Header = "Bookmark";
|
||||
for (int i = 0; i < Converters.IntToRepoColor.Colors.Length; i++) {
|
||||
var icon = new System.Windows.Shapes.Path();
|
||||
icon.Style = FindResource("Style.Icon") as Style;
|
||||
icon.Data = iconBookmark;
|
||||
icon.Fill = Converters.IntToRepoColor.Colors[i];
|
||||
icon.Width = 8;
|
||||
|
||||
var mark = new MenuItem();
|
||||
mark.Icon = icon;
|
||||
mark.Header = $"{i}";
|
||||
|
||||
var refIdx = i;
|
||||
mark.Click += (o, e) => {
|
||||
repo.Color = refIdx;
|
||||
UpdateRecentOpened();
|
||||
UpdateTree();
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
bookmark.Items.Add(mark);
|
||||
}
|
||||
|
||||
var delete = new MenuItem();
|
||||
delete.Header = "Delete";
|
||||
delete.Click += (o, ev) => {
|
||||
App.Setting.RemoveRepository(repo.Path);
|
||||
UpdateRecentOpened();
|
||||
UpdateTree();
|
||||
HideBrief();
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
var menu = new ContextMenu();
|
||||
menu.Items.Add(open);
|
||||
menu.Items.Add(explore);
|
||||
menu.Items.Add(bookmark);
|
||||
menu.Items.Add(delete);
|
||||
menu.IsOpen = true;
|
||||
e.Handled = true;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region EVENT_TREEVIEW
|
||||
private void TreeGotFocus(object sender, RoutedEventArgs e) {
|
||||
recentOpened.SelectedItems.Clear();
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void TreeContextMenuOpening(object sender, ContextMenuEventArgs e) {
|
||||
var addFolder = new MenuItem();
|
||||
addFolder.Header = "Add Folder";
|
||||
|
@ -175,13 +79,8 @@ namespace SourceGit.UI {
|
|||
|
||||
private void TreeMouseMove(object sender, MouseEventArgs e) {
|
||||
if (e.LeftButton != MouseButtonState.Pressed) return;
|
||||
|
||||
if (selectedTreeViewItem == null) return;
|
||||
|
||||
var node = selectedTreeViewItem.DataContext as Node;
|
||||
if (node == null || !node.IsRepo) return;
|
||||
|
||||
DragDrop.DoDragDrop(repositories, selectedTreeViewItem, DragDropEffects.Move);
|
||||
if (repositories.SelectedItem == null) return;
|
||||
DragDrop.DoDragDrop(repositories, repositories.SelectedItem, DragDropEffects.Move);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
|
@ -204,15 +103,19 @@ namespace SourceGit.UI {
|
|||
needRebuild = true;
|
||||
}
|
||||
}
|
||||
} else if (e.Data.GetDataPresent(typeof(TreeViewItem))) {
|
||||
var item = e.Data.GetData(typeof(TreeViewItem)) as TreeViewItem;
|
||||
var node = item.DataContext as Node;
|
||||
if (node == null || !node.IsRepo) return;
|
||||
} else if (e.Data.GetDataPresent(typeof(Node))) {
|
||||
var node = e.Data.GetData(typeof(Node)) as Node;
|
||||
if (node == null) return;
|
||||
|
||||
var group = "";
|
||||
var to = (sender as TreeViewItem)?.DataContext as Node;
|
||||
if (to != null) group = to.IsRepo ? to.ParentId : to.Id;
|
||||
App.Setting.FindRepository(node.Id).GroupId = group;
|
||||
var parent = to != null ? to.Id : "";
|
||||
|
||||
if (node.IsRepo) {
|
||||
App.Setting.FindRepository(node.Id).GroupId = to != null ? to.Id : "";
|
||||
} else if (!App.Setting.IsSubGroup(node.Id, parent)) {
|
||||
App.Setting.FindGroup(node.Id).ParentId = parent;
|
||||
}
|
||||
|
||||
needRebuild = true;
|
||||
}
|
||||
|
||||
|
@ -222,19 +125,6 @@ namespace SourceGit.UI {
|
|||
#endregion
|
||||
|
||||
#region EVENT_TREEVIEWITEM
|
||||
private void TreeNodeSelected(object sender, RoutedEventArgs e) {
|
||||
selectedTreeViewItem = sender as TreeViewItem;
|
||||
|
||||
var node = selectedTreeViewItem.DataContext as Node;
|
||||
if (node.IsRepo) {
|
||||
ShowBrief(App.Setting.FindRepository(node.Id));
|
||||
} else {
|
||||
HideBrief();
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void TreeNodeDoubleClick(object sender, MouseButtonEventArgs e) {
|
||||
var node = (sender as TreeViewItem).DataContext as Node;
|
||||
if (node != null && node.IsRepo) {
|
||||
|
@ -308,7 +198,6 @@ namespace SourceGit.UI {
|
|||
App.Setting.RenameGroup(node.Id, text.Text);
|
||||
}
|
||||
|
||||
UpdateRecentOpened();
|
||||
UpdateTree();
|
||||
e.Handled = true;
|
||||
}
|
||||
|
@ -353,7 +242,6 @@ namespace SourceGit.UI {
|
|||
var repo = App.Setting.FindRepository(node.Id);
|
||||
if (repo != null) {
|
||||
repo.Color = refIdx;
|
||||
UpdateRecentOpened();
|
||||
UpdateTree();
|
||||
}
|
||||
e.Handled = true;
|
||||
|
@ -391,7 +279,6 @@ namespace SourceGit.UI {
|
|||
delete.Header = "Delete";
|
||||
delete.Click += (o, ev) => {
|
||||
DeleteNode(node);
|
||||
HideBrief();
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
|
@ -402,66 +289,6 @@ namespace SourceGit.UI {
|
|||
}
|
||||
#endregion
|
||||
|
||||
#region EVENT_BRIEF
|
||||
private void ShowBrief(Git.Repository repo) {
|
||||
if (repo == null || !Git.Repository.IsValid(repo.Path)) {
|
||||
if (Directory.Exists(repo.Path)) {
|
||||
popupManager.Show(new Init(popupManager, repo.Path, () => {
|
||||
UpdateRecentOpened();
|
||||
UpdateTree();
|
||||
}));
|
||||
} else {
|
||||
App.RaiseError("Path is NOT valid git repository or has been removed.");
|
||||
App.Setting.RemoveRepository(repo.Path);
|
||||
UpdateRecentOpened();
|
||||
UpdateTree();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
briefMask.Visibility = Visibility.Hidden;
|
||||
|
||||
repoName.Text = repo.Name;
|
||||
repoPath.Text = repo.Path;
|
||||
|
||||
Task.Run(() => {
|
||||
var changes = repo.LocalChanges();
|
||||
var count = changes.Count;
|
||||
Dispatcher.Invoke(() => localChanges.Content = count);
|
||||
});
|
||||
|
||||
Task.Run(() => {
|
||||
var count = repo.TotalCommits();
|
||||
Dispatcher.Invoke(() => totalCommits.Content = count);
|
||||
});
|
||||
|
||||
Task.Run(() => {
|
||||
var commits = repo.Commits("-n 1");
|
||||
Dispatcher.Invoke(() => {
|
||||
if (commits.Count > 0) {
|
||||
var c = commits[0];
|
||||
lastCommitId.Content = c.ShortSHA;
|
||||
lastCommit.Text = c.Subject;
|
||||
} else {
|
||||
lastCommitId.Content = "---";
|
||||
lastCommit.Text = "";
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (File.Exists(repo.Path + "/README.md")) {
|
||||
readme.Text = File.ReadAllText(repo.Path + "/README.md");
|
||||
} else {
|
||||
readme.Text = "";
|
||||
}
|
||||
}
|
||||
|
||||
private void HideBrief() {
|
||||
briefMask.Visibility = Visibility.Visible;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region PRIVATES
|
||||
/// <summary>
|
||||
/// Make sure git is configured.
|
||||
|
@ -485,10 +312,7 @@ namespace SourceGit.UI {
|
|||
|
||||
if (!Git.Repository.IsValid(path)) {
|
||||
if (Directory.Exists(path)) {
|
||||
popupManager.Show(new Init(popupManager, path, () => {
|
||||
UpdateRecentOpened();
|
||||
UpdateTree();
|
||||
}));
|
||||
popupManager.Show(new Init(popupManager, path, () => UpdateTree()));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -498,22 +322,6 @@ namespace SourceGit.UI {
|
|||
|
||||
var repo = App.Setting.AddRepository(path, "");
|
||||
App.Open(repo);
|
||||
UpdateRecentOpened();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update recent opened repositories.
|
||||
/// </summary>
|
||||
private void UpdateRecentOpened() {
|
||||
var sorted = App.Setting.Repositories.OrderByDescending(a => a.LastOpenTime).ToList();
|
||||
var top5 = new List<Git.Repository>();
|
||||
|
||||
for (int i = 0; i < sorted.Count && i < 5; i++) {
|
||||
if (sorted[i].LastOpenTime <= 0) break;
|
||||
top5.Add(sorted[i]);
|
||||
}
|
||||
|
||||
recentOpened.ItemsSource = top5;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -576,7 +384,6 @@ namespace SourceGit.UI {
|
|||
private void DeleteNode(Node node) {
|
||||
if (node.IsRepo) {
|
||||
App.Setting.RemoveRepository(node.Id);
|
||||
UpdateRecentOpened();
|
||||
} else {
|
||||
App.Setting.RemoveGroup(node.Id);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue