optimize<Manager>: simplify Manager page

This commit is contained in:
leo 2020-12-31 15:55:19 +08:00
parent eac212737c
commit dc17bb4b12
5 changed files with 162 additions and 436 deletions

View file

@ -191,6 +191,27 @@ namespace SourceGit {
if (removedIdx >= 0) Groups.RemoveAt(removedIdx); 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 #endregion
#region METHODS_ON_REPOS #region METHODS_ON_REPOS
@ -209,7 +230,6 @@ namespace SourceGit {
Path = dir.FullName, Path = dir.FullName,
Name = dir.Name, Name = dir.Name,
GroupId = groupId, GroupId = groupId,
LastOpenTime = 0,
}; };
Repositories.Add(repo); Repositories.Add(repo);

View file

@ -43,10 +43,6 @@ namespace SourceGit.Git {
/// </summary> /// </summary>
public int Color { get; set; } = 0; public int Color { get; set; } = 0;
/// <summary> /// <summary>
/// Last open time(File time format).
/// </summary>
public long LastOpenTime { get; set; }
/// <summary>
/// Expand tags. /// Expand tags.
/// </summary> /// </summary>
public bool ExpandTags { get; set; } public bool ExpandTags { get; set; }
@ -255,7 +251,6 @@ namespace SourceGit.Git {
/// Open repository. /// Open repository.
/// </summary> /// </summary>
public void Open() { public void Open() {
LastOpenTime = DateTime.Now.ToFileTime();
isWatcherDisabled = false; isWatcherDisabled = false;
GitDir = ".git"; GitDir = ".git";

View file

@ -69,7 +69,7 @@ namespace SourceGit.UI {
public string Title { public string Title {
get { get {
if (Repo == null) return "Repositories"; if (Repo == null) return "New Page";
return Repo.Parent == null ? Repo.Name : $"{Repo.Parent.Name} : {Repo.Name}"; return Repo.Parent == null ? Repo.Name : $"{Repo.Parent.Name} : {Repo.Name}";
} }
} }

View file

@ -5,7 +5,6 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SourceGit.UI" xmlns:local="clr-namespace:SourceGit.UI"
xmlns:git="clr-namespace:SourceGit.Git"
xmlns:converters="clr-namespace:SourceGit.Converters" xmlns:converters="clr-namespace:SourceGit.Converters"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"> d:DesignHeight="450" d:DesignWidth="800">
@ -13,244 +12,149 @@
<UserControl.Resources> <UserControl.Resources>
<converters:IntToRepoColor x:Key="IntToRepoColor"/> <converters:IntToRepoColor x:Key="IntToRepoColor"/>
<converters:BoolToCollapsed x:Key="BoolToCollapsed"/> <converters:BoolToCollapsed x:Key="BoolToCollapsed"/>
<converters:InverseBoolToCollapsed x:Key="InverseBoolToCollapsed"/>
<converters:InverseBool x:Key="InverseBool"/>
</UserControl.Resources> </UserControl.Resources>
<Grid> <Grid>
<!-- Main Body --> <!-- Main Body -->
<Grid> <Grid Background="{StaticResource Brush.BG1}" HorizontalAlignment="Center" MinWidth="420" TextElement.FontFamily="Consolas">
<Grid.ColumnDefinitions> <Grid.RowDefinitions>
<ColumnDefinition Width="200" MinWidth="200" MaxWidth="360"/> <RowDefinition Height="Auto"/>
<ColumnDefinition Width="2"/> <RowDefinition Height="Auto"/>
<ColumnDefinition Width="*"/> <RowDefinition Height="*"/>
</Grid.ColumnDefinitions> </Grid.RowDefinitions>
<!-- Left panel --> <!-- Welcome -->
<Grid Grid.Column="0" Background="{StaticResource Brush.BG1}"> <StackPanel Orientation="Vertical" Margin="0,64,0,0">
<Grid.RowDefinitions> <Path Width="72" Height="72" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Git}" Fill="#FFF05133"/>
<RowDefinition Height="32"/> <TextBlock Grid.Column="0" Margin="0,16" HorizontalAlignment="Center" Text="Welcome to SourceGit :)" FontSize="26" FontWeight="ExtraBold" Foreground="{StaticResource Brush.FG2}"/>
<RowDefinition Height="Auto"/> <Grid Margin="0,0,0,36">
<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.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/> <ColumnDefinition Width="8"/>
<ColumnDefinition Width="Auto"/> <ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Button Click="OpenOrAddRepo" Grid.Column="0" Style="{StaticResource Style.Button.Bordered}">
<Label Grid.Column="0" Content="REPOSITORIES" Style="{StaticResource Style.Label.GroupHeader}"/> <StackPanel Orientation="Horizontal">
<Path Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Folder}"/>
<Button Grid.Column="1" Click="CloneRepo" Style="{StaticResource Style.Button}" ToolTip="Clone Remote Repository"> <Label Margin="4,0,0,0" Content="Open Local Repository"/>
<Path Width="14" Height="14" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Pull}" Opacity=".8"/> </StackPanel>
</Button> </Button>
<Button Click="CloneRepo" Grid.Column="2" Style="{StaticResource Style.Button.Bordered}">
<Button Grid.Column="2" Click="OpenOrAddRepo" Style="{StaticResource Style.Button}" Margin="8,0,4,0" ToolTip="Open Local Repository"> <StackPanel Orientation="Horizontal">
<Path Width="14" Height="14" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Folder.Open}" Opacity=".8"/> <Path Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Pull}"/>
<Label Margin="4,0,0,0" Content="Clone Remote Repository"/>
</StackPanel>
</Button> </Button>
</Grid> </Grid>
<TreeView <Rectangle Height=".5" Fill="{StaticResource Brush.Border1}"/>
x:Name="repositories" </StackPanel>
Grid.Row="3"
Margin="0,4"
Padding="0"
AllowDrop="True"
ContextMenuOpening="TreeContextMenuOpening"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
Drop="TreeDrop"
GotFocus="TreeGotFocus"
MouseMove="TreeMouseMove">
<TreeView.ItemContainerStyle> <!-- Repositories' tree -->
<Style TargetType="{x:Type TreeViewItem}" BasedOn="{StaticResource Style.TreeView.ItemContainerStyle}"> <Grid Grid.Row="1" Margin="0,8,0,0">
<Setter Property="IsExpanded" Value="{Binding IsExpended, Mode=TwoWay}"/> <Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<EventSetter Event="Selected" Handler="TreeNodeSelected"/> <TextBlock Grid.Column="0" Text="REPOSITORIES" FontSize="18" FontWeight="ExtraBold" Foreground="{StaticResource Brush.FG2}"/>
<EventSetter Event="DragOver" Handler="TreeNodeDragOver"/> <TextBlock Grid.Column="2" Text="DRAG-DROP YOUR FOLDER" FontSize="14" Foreground="{StaticResource Brush.FG2}" VerticalAlignment="Center"/>
<EventSetter Event="Drop" Handler="TreeNodeDrop"/> </Grid>
<EventSetter Event="Expanded" Handler="TreeNodeIsExpandedChanged"/> <TreeView
<EventSetter Event="Collapsed" Handler="TreeNodeIsExpandedChanged"/> x:Name="repositories"
<EventSetter Event="KeyDown" Handler="TreeNodeKeyDown"/> Grid.Row="2"
<EventSetter Event="ContextMenuOpening" Handler="TreeNodeContextMenuOpening"/> Margin="0,4"
<EventSetter Event="MouseDoubleClick" Handler="TreeNodeDoubleClick"/> Padding="0"
</Style> AllowDrop="True"
</TreeView.ItemContainerStyle> TextElement.FontSize="14"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ContextMenuOpening="TreeContextMenuOpening"
Drop="TreeDrop"
MouseMove="TreeMouseMove">
<TreeView.ItemTemplate> <TreeView.ItemContainerStyle>
<HierarchicalDataTemplate ItemsSource="{Binding Children}"> <Style TargetType="{x:Type TreeViewItem}" BasedOn="{StaticResource Style.TreeView.ItemContainerStyle}">
<Grid Height="26"> <Setter Property="IsExpanded" Value="{Binding IsExpended, Mode=TwoWay}"/>
<Grid.ColumnDefinitions> <Setter Property="AllowDrop" Value="{Binding IsRepo, Converter={StaticResource InverseBool}}"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Path <EventSetter Event="DragOver" Handler="TreeNodeDragOver"/>
x:Name="icon" <EventSetter Event="Drop" Handler="TreeNodeDrop"/>
Grid.Column="0" <EventSetter Event="Expanded" Handler="TreeNodeIsExpandedChanged"/>
Width="14" Height="14" <EventSetter Event="Collapsed" Handler="TreeNodeIsExpandedChanged"/>
Style="{StaticResource Style.Icon}" <EventSetter Event="KeyDown" Handler="TreeNodeKeyDown"/>
Data="{StaticResource Icon.Folder.Fill}"/> <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 <TextBlock
x:Name="name" Margin="8,0,0,0"
Grid.Column="1"
Margin="4,0,0,0"
Text="{Binding Name}" Text="{Binding Name}"
Foreground="{StaticResource Brush.FG}" Foreground="{StaticResource Brush.FG}"
VerticalAlignment="Center"/> VerticalAlignment="Center"/>
<TextBlock
<TextBox Margin="8,0,0,0"
x:Name="editName" Text="{Binding Id}"
Grid.Column="1" Foreground="{StaticResource Brush.FG2}"
Margin="4,0,0,0" VerticalAlignment="Center"
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}}"
Visibility="{Binding IsRepo, Converter={StaticResource BoolToCollapsed}}"/> Visibility="{Binding IsRepo, Converter={StaticResource BoolToCollapsed}}"/>
</Grid> </StackPanel>
<HierarchicalDataTemplate.Triggers> <TextBox
<DataTrigger Binding="{Binding IsExpended}" Value="True"> x:Name="editName"
<Setter TargetName="icon" Property="Data" Value="{StaticResource Icon.Folder.Open}"/> Grid.Column="1"
</DataTrigger> Margin="4,0,0,0"
<DataTrigger Binding="{Binding IsRepo}" Value="True"> Text="{Binding Name}"
<Setter TargetName="icon" Property="Data" Value="{StaticResource Icon.Git}"/> Loaded="TreeNodeRenameStart"
</DataTrigger> KeyDown="TreeNodeRenameKeyDown"
<DataTrigger Binding="{Binding IsEditing}" Value="True"> LostFocus="TreeNodeRenameEnd"
<Setter TargetName="name" Property="Visibility" Value="Hidden"/> Visibility="{Binding IsEditing, Converter={StaticResource BoolToCollapsed}}"/>
<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>
<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 --> <HierarchicalDataTemplate.Triggers>
<Grid Grid.Column="2" Background="{StaticResource Brush.BG3}"> <DataTrigger Binding="{Binding IsExpended}" Value="True">
<!-- Brief --> <Setter TargetName="icon" Property="Data" Value="{StaticResource Icon.Folder.Open}"/>
<Grid Margin="16"> </DataTrigger>
<Grid.RowDefinitions> <DataTrigger Binding="{Binding IsRepo}" Value="True">
<RowDefinition Height="Auto"/> <Setter TargetName="icon" Property="Data" Value="{StaticResource Icon.Git}"/>
<RowDefinition Height="Auto"/> </DataTrigger>
<RowDefinition Height="Auto"/> </HierarchicalDataTemplate.Triggers>
<RowDefinition Height="Auto"/> </HierarchicalDataTemplate>
<RowDefinition Height="*"/> </TreeView.ItemTemplate>
</Grid.RowDefinitions> </TreeView>
<!-- 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>
</Grid> </Grid>
<!-- Popup --> <!-- Popup -->

View file

@ -1,8 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
@ -14,7 +12,6 @@ namespace SourceGit.UI {
/// Repository manager. /// Repository manager.
/// </summary> /// </summary>
public partial class Manager : UserControl { public partial class Manager : UserControl {
private TreeViewItem selectedTreeViewItem = null;
/// <summary> /// <summary>
/// Used to build tree /// Used to build tree
@ -35,7 +32,6 @@ namespace SourceGit.UI {
/// </summary> /// </summary>
public Manager() { public Manager() {
InitializeComponent(); InitializeComponent();
UpdateRecentOpened();
UpdateTree(); UpdateTree();
} }
@ -59,105 +55,13 @@ namespace SourceGit.UI {
private void CloneRepo(object sender, RoutedEventArgs e) { private void CloneRepo(object sender, RoutedEventArgs e) {
if (MakeSureReady()) { if (MakeSureReady()) {
popupManager.Show(new Clone(popupManager, () => { popupManager.Show(new Clone(popupManager, () => {
UpdateRecentOpened();
UpdateTree(); UpdateTree();
})); }));
} }
} }
#endregion #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 #region EVENT_TREEVIEW
private void TreeGotFocus(object sender, RoutedEventArgs e) {
recentOpened.SelectedItems.Clear();
e.Handled = true;
}
private void TreeContextMenuOpening(object sender, ContextMenuEventArgs e) { private void TreeContextMenuOpening(object sender, ContextMenuEventArgs e) {
var addFolder = new MenuItem(); var addFolder = new MenuItem();
addFolder.Header = "Add Folder"; addFolder.Header = "Add Folder";
@ -175,13 +79,8 @@ namespace SourceGit.UI {
private void TreeMouseMove(object sender, MouseEventArgs e) { private void TreeMouseMove(object sender, MouseEventArgs e) {
if (e.LeftButton != MouseButtonState.Pressed) return; if (e.LeftButton != MouseButtonState.Pressed) return;
if (repositories.SelectedItem == null) return;
if (selectedTreeViewItem == null) return; DragDrop.DoDragDrop(repositories, repositories.SelectedItem, DragDropEffects.Move);
var node = selectedTreeViewItem.DataContext as Node;
if (node == null || !node.IsRepo) return;
DragDrop.DoDragDrop(repositories, selectedTreeViewItem, DragDropEffects.Move);
e.Handled = true; e.Handled = true;
} }
@ -204,15 +103,19 @@ namespace SourceGit.UI {
needRebuild = true; needRebuild = true;
} }
} }
} else if (e.Data.GetDataPresent(typeof(TreeViewItem))) { } else if (e.Data.GetDataPresent(typeof(Node))) {
var item = e.Data.GetData(typeof(TreeViewItem)) as TreeViewItem; var node = e.Data.GetData(typeof(Node)) as Node;
var node = item.DataContext as Node; if (node == null) return;
if (node == null || !node.IsRepo) return;
var group = "";
var to = (sender as TreeViewItem)?.DataContext as Node; var to = (sender as TreeViewItem)?.DataContext as Node;
if (to != null) group = to.IsRepo ? to.ParentId : to.Id; var parent = to != null ? to.Id : "";
App.Setting.FindRepository(node.Id).GroupId = group;
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; needRebuild = true;
} }
@ -222,19 +125,6 @@ namespace SourceGit.UI {
#endregion #endregion
#region EVENT_TREEVIEWITEM #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) { private void TreeNodeDoubleClick(object sender, MouseButtonEventArgs e) {
var node = (sender as TreeViewItem).DataContext as Node; var node = (sender as TreeViewItem).DataContext as Node;
if (node != null && node.IsRepo) { if (node != null && node.IsRepo) {
@ -308,7 +198,6 @@ namespace SourceGit.UI {
App.Setting.RenameGroup(node.Id, text.Text); App.Setting.RenameGroup(node.Id, text.Text);
} }
UpdateRecentOpened();
UpdateTree(); UpdateTree();
e.Handled = true; e.Handled = true;
} }
@ -353,7 +242,6 @@ namespace SourceGit.UI {
var repo = App.Setting.FindRepository(node.Id); var repo = App.Setting.FindRepository(node.Id);
if (repo != null) { if (repo != null) {
repo.Color = refIdx; repo.Color = refIdx;
UpdateRecentOpened();
UpdateTree(); UpdateTree();
} }
e.Handled = true; e.Handled = true;
@ -391,7 +279,6 @@ namespace SourceGit.UI {
delete.Header = "Delete"; delete.Header = "Delete";
delete.Click += (o, ev) => { delete.Click += (o, ev) => {
DeleteNode(node); DeleteNode(node);
HideBrief();
ev.Handled = true; ev.Handled = true;
}; };
@ -402,66 +289,6 @@ namespace SourceGit.UI {
} }
#endregion #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 #region PRIVATES
/// <summary> /// <summary>
/// Make sure git is configured. /// Make sure git is configured.
@ -485,10 +312,7 @@ namespace SourceGit.UI {
if (!Git.Repository.IsValid(path)) { if (!Git.Repository.IsValid(path)) {
if (Directory.Exists(path)) { if (Directory.Exists(path)) {
popupManager.Show(new Init(popupManager, path, () => { popupManager.Show(new Init(popupManager, path, () => UpdateTree()));
UpdateRecentOpened();
UpdateTree();
}));
return; return;
} }
@ -498,22 +322,6 @@ namespace SourceGit.UI {
var repo = App.Setting.AddRepository(path, ""); var repo = App.Setting.AddRepository(path, "");
App.Open(repo); 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> /// <summary>
@ -576,7 +384,6 @@ namespace SourceGit.UI {
private void DeleteNode(Node node) { private void DeleteNode(Node node) {
if (node.IsRepo) { if (node.IsRepo) {
App.Setting.RemoveRepository(node.Id); App.Setting.RemoveRepository(node.Id);
UpdateRecentOpened();
} else { } else {
App.Setting.RemoveGroup(node.Id); App.Setting.RemoveGroup(node.Id);
} }