2020-07-03 00:24:31 -07:00
|
|
|
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;
|
2020-12-09 01:59:37 -08:00
|
|
|
using System.Windows.Media;
|
2020-07-03 00:24:31 -07:00
|
|
|
|
|
|
|
namespace SourceGit.UI {
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Repository manager.
|
|
|
|
/// </summary>
|
|
|
|
public partial class Manager : UserControl {
|
|
|
|
private TreeViewItem selectedTreeViewItem = null;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Used to build tree
|
|
|
|
/// </summary>
|
|
|
|
public class Node {
|
|
|
|
public string Id { get; set; }
|
|
|
|
public string ParentId { get; set; }
|
|
|
|
public string Name { get; set; }
|
|
|
|
public bool IsRepo { get; set; }
|
|
|
|
public bool IsExpended { get; set; }
|
|
|
|
public bool IsEditing { get; set; }
|
2020-12-09 01:59:37 -08:00
|
|
|
public int Color { get; set; }
|
2020-07-03 00:24:31 -07:00
|
|
|
public List<Node> Children { get; set; } = new List<Node>();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Constructor.
|
|
|
|
/// </summary>
|
|
|
|
public Manager() {
|
|
|
|
InitializeComponent();
|
|
|
|
UpdateRecentOpened();
|
|
|
|
UpdateTree();
|
|
|
|
}
|
|
|
|
|
|
|
|
#region TOOLBAR
|
|
|
|
/// <summary>
|
|
|
|
/// Open or add local repository.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
/// <param name="e"></param>
|
|
|
|
private void OpenOrAddRepo(object sender, RoutedEventArgs e) {
|
2020-11-22 22:02:13 -08:00
|
|
|
FolderDailog.Open("Open or init local repository", path => {
|
2020-11-22 21:41:13 -08:00
|
|
|
CheckAndOpenRepo(path);
|
|
|
|
});
|
2020-07-03 00:24:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Clone remote repository.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
/// <param name="e"></param>
|
|
|
|
private void CloneRepo(object sender, RoutedEventArgs e) {
|
2020-08-06 00:41:25 -07:00
|
|
|
if (MakeSureReady()) popupManager.Show(new Clone(popupManager));
|
2020-07-03 00:24:31 -07:00
|
|
|
}
|
|
|
|
#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;
|
|
|
|
}
|
|
|
|
}
|
2020-08-05 20:31:20 -07:00
|
|
|
|
|
|
|
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) => {
|
2020-11-16 20:41:51 -08:00
|
|
|
Process.Start("explorer", repo.Path);
|
2020-08-05 20:31:20 -07:00
|
|
|
ev.Handled = true;
|
|
|
|
};
|
|
|
|
|
2020-12-09 01:59:37 -08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-08-05 20:31:20 -07:00
|
|
|
var delete = new MenuItem();
|
|
|
|
delete.Header = "Delete";
|
|
|
|
delete.Click += (o, ev) => {
|
2020-12-16 19:55:06 -08:00
|
|
|
App.Setting.RemoveRepository(repo.Path);
|
2020-08-05 20:31:20 -07:00
|
|
|
UpdateRecentOpened();
|
|
|
|
UpdateTree();
|
|
|
|
HideBrief();
|
|
|
|
ev.Handled = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
var menu = new ContextMenu();
|
|
|
|
menu.Items.Add(open);
|
|
|
|
menu.Items.Add(explore);
|
2020-12-09 01:59:37 -08:00
|
|
|
menu.Items.Add(bookmark);
|
2020-08-05 20:31:20 -07:00
|
|
|
menu.Items.Add(delete);
|
|
|
|
menu.IsOpen = true;
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
2020-07-03 00:24:31 -07:00
|
|
|
#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";
|
|
|
|
addFolder.Click += (o, ev) => {
|
2020-12-16 19:55:06 -08:00
|
|
|
var group = App.Setting.AddGroup("New Group", "");
|
2020-07-03 00:24:31 -07:00
|
|
|
UpdateTree(group.Id);
|
|
|
|
ev.Handled = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
var menu = new ContextMenu();
|
|
|
|
menu.Items.Add(addFolder);
|
|
|
|
menu.IsOpen = true;
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void TreeDrop(object sender, DragEventArgs e) {
|
|
|
|
bool needRebuild = false;
|
|
|
|
|
|
|
|
if (e.Data.GetDataPresent(DataFormats.FileDrop)) {
|
|
|
|
if (!MakeSureReady()) return;
|
|
|
|
|
|
|
|
string[] paths = e.Data.GetData(DataFormats.FileDrop) as string[];
|
|
|
|
string group = "";
|
|
|
|
|
|
|
|
var node = (sender as TreeViewItem)?.DataContext as Node;
|
|
|
|
if (node != null) group = node.IsRepo ? node.ParentId : node.Id;
|
|
|
|
|
|
|
|
foreach (var path in paths) {
|
|
|
|
FileInfo info = new FileInfo(path);
|
|
|
|
if (info.Attributes == FileAttributes.Directory && Git.Repository.IsValid(path)) {
|
2020-12-16 19:55:06 -08:00
|
|
|
App.Setting.AddRepository(path, group);
|
2020-07-03 00:24:31 -07:00
|
|
|
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;
|
|
|
|
|
|
|
|
var group = "";
|
|
|
|
var to = (sender as TreeViewItem)?.DataContext as Node;
|
|
|
|
if (to != null) group = to.IsRepo ? to.ParentId : to.Id;
|
2020-12-16 19:55:06 -08:00
|
|
|
App.Setting.FindRepository(node.Id).GroupId = group;
|
2020-07-03 00:24:31 -07:00
|
|
|
needRebuild = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (needRebuild) UpdateTree();
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region EVENT_TREEVIEWITEM
|
|
|
|
private void TreeNodeSelected(object sender, RoutedEventArgs e) {
|
|
|
|
selectedTreeViewItem = sender as TreeViewItem;
|
|
|
|
|
|
|
|
var node = selectedTreeViewItem.DataContext as Node;
|
|
|
|
if (node.IsRepo) {
|
2020-12-16 19:55:06 -08:00
|
|
|
ShowBrief(App.Setting.FindRepository(node.Id));
|
2020-07-03 00:24:31 -07:00
|
|
|
} 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) {
|
|
|
|
CheckAndOpenRepo(node.Id);
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void TreeNodeDragOver(object sender, DragEventArgs e) {
|
|
|
|
var item = sender as TreeViewItem;
|
|
|
|
var node = item.DataContext as Node;
|
|
|
|
if (node != null && !node.IsRepo) item.IsExpanded = true;
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void TreeNodeDrop(object sender, DragEventArgs e) {
|
|
|
|
TreeDrop(sender, e);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void TreeNodeIsExpandedChanged(object sender, RoutedEventArgs e) {
|
|
|
|
var item = sender as TreeViewItem;
|
|
|
|
var node = item.DataContext as Node;
|
|
|
|
|
|
|
|
if (node != null && !node.IsRepo) {
|
2020-12-16 19:55:06 -08:00
|
|
|
var group = App.Setting.FindGroup(node.Id);
|
2020-07-03 00:24:31 -07:00
|
|
|
group.IsExpended = item.IsExpanded;
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void TreeNodeKeyDown(object sender, KeyEventArgs e) {
|
|
|
|
if (e.Key != Key.Delete) return;
|
|
|
|
|
|
|
|
var node = (sender as TreeViewItem).DataContext as Node;
|
|
|
|
if (node != null) DeleteNode(node);
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void TreeNodeRenameStart(object sender, RoutedEventArgs e) {
|
|
|
|
var text = sender as TextBox;
|
|
|
|
if (text.IsVisible) {
|
|
|
|
text.SelectAll();
|
|
|
|
text.Focus();
|
|
|
|
}
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void TreeNodeRenameKeyDown(object sender, KeyEventArgs e) {
|
|
|
|
if (e.Key == Key.Escape) {
|
|
|
|
UpdateTree();
|
|
|
|
e.Handled = true;
|
|
|
|
} else if (e.Key == Key.Enter) {
|
|
|
|
TreeNodeRenameEnd(sender, e);
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void TreeNodeRenameEnd(object sender, RoutedEventArgs e) {
|
|
|
|
var text = sender as TextBox;
|
|
|
|
if (string.IsNullOrWhiteSpace(text.Text)) {
|
|
|
|
UpdateTree();
|
|
|
|
e.Handled = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var node = text.DataContext as Node;
|
|
|
|
if (node != null) {
|
|
|
|
if (node.IsRepo) {
|
2020-12-16 19:55:06 -08:00
|
|
|
App.Setting.RenameRepository(node.Id, text.Text);
|
2020-07-03 00:24:31 -07:00
|
|
|
} else {
|
2020-12-16 19:55:06 -08:00
|
|
|
App.Setting.RenameGroup(node.Id, text.Text);
|
2020-07-03 00:24:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
UpdateRecentOpened();
|
|
|
|
UpdateTree();
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void TreeNodeContextMenuOpening(object sender, ContextMenuEventArgs e) {
|
|
|
|
var item = sender as TreeViewItem;
|
|
|
|
var node = item.DataContext as Node;
|
|
|
|
var menu = new ContextMenu();
|
|
|
|
|
|
|
|
if (node.IsRepo) {
|
|
|
|
var open = new MenuItem();
|
|
|
|
open.Header = "Open";
|
|
|
|
open.Click += (o, ev) => {
|
|
|
|
CheckAndOpenRepo(node.Id);
|
|
|
|
ev.Handled = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
var explore = new MenuItem();
|
|
|
|
explore.Header = "Open Container Folder";
|
|
|
|
explore.Click += (o, ev) => {
|
2020-11-16 20:41:51 -08:00
|
|
|
Process.Start("explorer", node.Id);
|
2020-07-03 00:24:31 -07:00
|
|
|
ev.Handled = true;
|
|
|
|
};
|
|
|
|
|
2020-12-09 01:59:37 -08:00
|
|
|
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) => {
|
2020-12-16 19:55:06 -08:00
|
|
|
var repo = App.Setting.FindRepository(node.Id);
|
2020-12-09 01:59:37 -08:00
|
|
|
if (repo != null) {
|
|
|
|
repo.Color = refIdx;
|
|
|
|
UpdateRecentOpened();
|
|
|
|
UpdateTree();
|
|
|
|
}
|
|
|
|
e.Handled = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
bookmark.Items.Add(mark);
|
|
|
|
}
|
|
|
|
|
2020-07-03 00:24:31 -07:00
|
|
|
menu.Items.Add(open);
|
|
|
|
menu.Items.Add(explore);
|
2020-12-09 01:59:37 -08:00
|
|
|
menu.Items.Add(bookmark);
|
2020-07-03 00:24:31 -07:00
|
|
|
} else {
|
|
|
|
var addSubFolder = new MenuItem();
|
|
|
|
addSubFolder.Header = "Add Sub-Folder";
|
|
|
|
addSubFolder.Click += (o, ev) => {
|
2020-12-16 19:55:06 -08:00
|
|
|
var parent = App.Setting.FindGroup(node.Id);
|
2020-07-03 00:24:31 -07:00
|
|
|
if (parent != null) parent.IsExpended = true;
|
|
|
|
|
2020-12-16 19:55:06 -08:00
|
|
|
var group = App.Setting.AddGroup("New Group", node.Id);
|
2020-07-03 00:24:31 -07:00
|
|
|
UpdateTree(group.Id);
|
|
|
|
ev.Handled = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
menu.Items.Add(addSubFolder);
|
|
|
|
}
|
|
|
|
|
|
|
|
var rename = new MenuItem();
|
|
|
|
rename.Header = "Rename";
|
|
|
|
rename.Click += (o, ev) => {
|
|
|
|
UpdateTree(node.Id);
|
|
|
|
ev.Handled = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
var delete = new MenuItem();
|
|
|
|
delete.Header = "Delete";
|
|
|
|
delete.Click += (o, ev) => {
|
|
|
|
DeleteNode(node);
|
2020-08-05 20:31:20 -07:00
|
|
|
HideBrief();
|
2020-07-03 00:24:31 -07:00
|
|
|
ev.Handled = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
menu.Items.Add(rename);
|
|
|
|
menu.Items.Add(delete);
|
|
|
|
menu.IsOpen = true;
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region EVENT_BRIEF
|
|
|
|
private void ShowBrief(Git.Repository repo) {
|
|
|
|
if (repo == null || !Git.Repository.IsValid(repo.Path)) {
|
|
|
|
if (Directory.Exists(repo.Path)) {
|
2020-08-06 00:41:25 -07:00
|
|
|
popupManager.Show(new Init(popupManager, repo.Path));
|
2020-07-03 00:24:31 -07:00
|
|
|
} else {
|
|
|
|
App.RaiseError("Path is NOT valid git repository or has been removed.");
|
2020-12-16 19:55:06 -08:00
|
|
|
App.Setting.RemoveRepository(repo.Path);
|
2020-07-03 00:24:31 -07:00
|
|
|
UpdateRecentOpened();
|
|
|
|
UpdateTree();
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
briefMask.Visibility = Visibility.Hidden;
|
|
|
|
|
2020-12-07 03:28:36 -08:00
|
|
|
repoName.Text = repo.Name;
|
|
|
|
repoPath.Text = repo.Path;
|
2020-07-03 00:24:31 -07:00
|
|
|
|
|
|
|
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;
|
2020-12-07 03:28:36 -08:00
|
|
|
lastCommit.Text = c.Subject;
|
2020-07-03 00:24:31 -07:00
|
|
|
} else {
|
|
|
|
lastCommitId.Content = "---";
|
2020-12-07 03:28:36 -08:00
|
|
|
lastCommit.Text = "";
|
2020-07-03 00:24:31 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
private bool MakeSureReady() {
|
|
|
|
if (!App.IsGitConfigured) {
|
|
|
|
App.RaiseError("Git has NOT been configured.\nPlease to go [Preference] and configure it first.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Check and open repository
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="path"></param>
|
|
|
|
private void CheckAndOpenRepo(string path) {
|
|
|
|
if (!MakeSureReady()) return;
|
|
|
|
|
|
|
|
if (!Git.Repository.IsValid(path)) {
|
|
|
|
if (Directory.Exists(path)) {
|
2020-08-06 00:41:25 -07:00
|
|
|
popupManager.Show(new Init(popupManager, path));
|
2020-07-03 00:24:31 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
App.RaiseError($"Path[{path}] not exists!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-16 19:55:06 -08:00
|
|
|
var repo = App.Setting.AddRepository(path, "");
|
2020-11-29 23:21:45 -08:00
|
|
|
App.Open(repo);
|
2020-07-03 00:24:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Update recent opened repositories.
|
|
|
|
/// </summary>
|
|
|
|
private void UpdateRecentOpened() {
|
2020-12-16 19:55:06 -08:00
|
|
|
var sorted = App.Setting.Repositories.OrderByDescending(a => a.LastOpenTime).ToList();
|
2020-07-03 00:24:31 -07:00
|
|
|
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>
|
|
|
|
/// Update tree items.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="editingNodeId"></param>
|
|
|
|
private void UpdateTree(string editingNodeId = null) {
|
|
|
|
var groupNodes = new Dictionary<string, Node>();
|
|
|
|
var nodes = new List<Node>();
|
|
|
|
|
2020-12-16 19:55:06 -08:00
|
|
|
foreach (var group in App.Setting.Groups) {
|
2020-07-03 00:24:31 -07:00
|
|
|
Node node = new Node() {
|
|
|
|
Id = group.Id,
|
|
|
|
ParentId = group.ParentId,
|
|
|
|
Name = group.Name,
|
|
|
|
IsRepo = false,
|
|
|
|
IsExpended = group.IsExpended,
|
|
|
|
IsEditing = group.Id == editingNodeId,
|
2020-12-09 01:59:37 -08:00
|
|
|
Color = 0,
|
2020-07-03 00:24:31 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
groupNodes.Add(node.Id, node);
|
|
|
|
}
|
|
|
|
|
|
|
|
nodes.Clear();
|
|
|
|
|
|
|
|
foreach (var kv in groupNodes) {
|
|
|
|
if (groupNodes.ContainsKey(kv.Value.ParentId)) {
|
|
|
|
groupNodes[kv.Value.ParentId].Children.Add(kv.Value);
|
|
|
|
} else {
|
|
|
|
nodes.Add(kv.Value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-16 19:55:06 -08:00
|
|
|
foreach (var repo in App.Setting.Repositories) {
|
2020-07-03 00:24:31 -07:00
|
|
|
Node node = new Node() {
|
|
|
|
Id = repo.Path,
|
|
|
|
ParentId = repo.GroupId,
|
|
|
|
Name = repo.Name,
|
|
|
|
IsRepo = true,
|
|
|
|
IsExpended = false,
|
|
|
|
IsEditing = repo.Path == editingNodeId,
|
2020-12-09 01:59:37 -08:00
|
|
|
Color = repo.Color,
|
2020-07-03 00:24:31 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
if (groupNodes.ContainsKey(repo.GroupId)) {
|
|
|
|
groupNodes[repo.GroupId].Children.Add(node);
|
|
|
|
} else {
|
|
|
|
nodes.Add(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
repositories.ItemsSource = nodes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Delete tree node.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="node"></param>
|
|
|
|
private void DeleteNode(Node node) {
|
|
|
|
if (node.IsRepo) {
|
2020-12-16 19:55:06 -08:00
|
|
|
App.Setting.RemoveRepository(node.Id);
|
2020-07-03 00:24:31 -07:00
|
|
|
UpdateRecentOpened();
|
|
|
|
} else {
|
2020-12-16 19:55:06 -08:00
|
|
|
App.Setting.RemoveGroup(node.Id);
|
2020-07-03 00:24:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
UpdateTree();
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|