mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-22 20:37:19 -08:00
optimize<FolderDialog>: simplify FolderDialog interface
This commit is contained in:
parent
5a9c4c32b0
commit
9d9e741aa5
6 changed files with 16 additions and 43 deletions
|
@ -45,8 +45,9 @@ namespace SourceGit.UI {
|
|||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void SelectParentFolder(object sender, RoutedEventArgs e) {
|
||||
var dialog = new FolderDailog("Select folder to store repository", null);
|
||||
dialog.Open(path => txtParentFolder.Text = path);
|
||||
FolderDailog.Open("Select folder to store repository", path => {
|
||||
txtParentFolder.Text = path;
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -297,8 +297,7 @@ namespace SourceGit.UI {
|
|||
MenuItem saveAs = new MenuItem();
|
||||
saveAs.Header = "Save As ...";
|
||||
saveAs.Click += (obj, ev) => {
|
||||
var dialog = new FolderDailog("Save To ...", null);
|
||||
dialog.Open(saveTo => {
|
||||
FolderDailog.Open("Save file to ...", saveTo => {
|
||||
var savePath = Path.Combine(saveTo, Path.GetFileName(path));
|
||||
commit.SaveFileTo(repo, path, savePath);
|
||||
});
|
||||
|
@ -503,8 +502,7 @@ namespace SourceGit.UI {
|
|||
saveAs.Header = "Save As ...";
|
||||
saveAs.IsEnabled = node.CommitObject == null || node.CommitObject.Kind == Git.Commit.Object.Type.Blob;
|
||||
saveAs.Click += (obj, ev) => {
|
||||
var dialog = new FolderDailog("Save To ...", null);
|
||||
dialog.Open(saveTo => {
|
||||
FolderDailog.Open("Save file to ...", saveTo => {
|
||||
var path = Path.Combine(saveTo, node.Name);
|
||||
commit.SaveFileTo(repo, node.FilePath, path);
|
||||
});
|
||||
|
|
|
@ -92,8 +92,8 @@ namespace SourceGit.UI {
|
|||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="title"></param>
|
||||
/// <param name="initPath"></param>
|
||||
public FolderDailog(string title, string initPath) {
|
||||
/// <param name="cb"></param>
|
||||
public FolderDailog(string title, Action<string> onOK) {
|
||||
InitializeComponent();
|
||||
|
||||
// Move to center.
|
||||
|
@ -104,46 +104,23 @@ namespace SourceGit.UI {
|
|||
var drives = DriveInfo.GetDrives();
|
||||
foreach (var drive in drives) {
|
||||
var node = new Node(drive.Name, drive.Name);
|
||||
|
||||
node.CollectChildren();
|
||||
if (initPath != null && initPath.StartsWith(drive.Name)) InitializePath(node, initPath);
|
||||
|
||||
root.Children.Add(node);
|
||||
}
|
||||
|
||||
cb = onOK;
|
||||
btnSure.IsEnabled = false;
|
||||
txtTitle.Content = title.ToUpper();
|
||||
treePath.ItemsSource = root.Children;
|
||||
|
||||
if (selected != null) {
|
||||
Helpers.TreeViewHelper.SelectOneByContext(treePath, selected);
|
||||
} else {
|
||||
btnSure.IsEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set callbacks on click OK.
|
||||
/// Open dialog.
|
||||
/// </summary>
|
||||
/// <param name="title"></param>
|
||||
/// <param name="onOK"></param>
|
||||
public void Open(Action<string> onOK) {
|
||||
cb = onOK;
|
||||
Show();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize given path.
|
||||
/// </summary>
|
||||
/// <param name="parent"></param>
|
||||
/// <param name="initPath"></param>
|
||||
private void InitializePath(Node parent, string initPath) {
|
||||
foreach (var child in parent.Children) {
|
||||
child.CollectChildren();
|
||||
if (child.Path == initPath) {
|
||||
selected = child;
|
||||
} else if (initPath.StartsWith(child.Path)) {
|
||||
InitializePath(child, initPath);
|
||||
}
|
||||
}
|
||||
public static void Open(string title, Action<string> onOK) {
|
||||
new FolderDailog(title, onOK).Show();
|
||||
}
|
||||
|
||||
#region EVENTS
|
||||
|
|
|
@ -586,8 +586,7 @@ namespace SourceGit.UI {
|
|||
var patch = new MenuItem();
|
||||
patch.Header = "Save As Patch";
|
||||
patch.Click += (o, e) => {
|
||||
var dialog = new FolderDailog("Save To ...", null);
|
||||
dialog.Open(saveTo => {
|
||||
FolderDailog.Open("Save patch to ...", saveTo => {
|
||||
Repo.RunCommand($"format-patch {commit.SHA} -1 -o \"{saveTo}\"", null);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -44,8 +44,7 @@ namespace SourceGit.UI {
|
|||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void OpenOrAddRepo(object sender, RoutedEventArgs e) {
|
||||
var dialog = new FolderDailog("Open or init local repository", null);
|
||||
dialog.Open(path => {
|
||||
FolderDailog.Open("Open or init local repository", path => {
|
||||
CheckAndOpenRepo(path);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -116,8 +116,7 @@ namespace SourceGit.UI {
|
|||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void SelectDefaultClonePath(object sender, RoutedEventArgs e) {
|
||||
var dialog = new FolderDailog("Select Folder To Clone Repository Into As Default", null);
|
||||
dialog.Open(path => {
|
||||
FolderDailog.Open("Select default clone path", path => {
|
||||
txtGitCloneDir.Text = path;
|
||||
App.Preference.GitDefaultCloneDir = path;
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue