diff --git a/src/UI/Clone.xaml.cs b/src/UI/Clone.xaml.cs
index 6beccdf9..6e30504a 100644
--- a/src/UI/Clone.xaml.cs
+++ b/src/UI/Clone.xaml.cs
@@ -45,8 +45,9 @@ namespace SourceGit.UI {
///
///
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;
+ });
}
///
diff --git a/src/UI/CommitViewer.xaml.cs b/src/UI/CommitViewer.xaml.cs
index f84f64b3..a3f12709 100644
--- a/src/UI/CommitViewer.xaml.cs
+++ b/src/UI/CommitViewer.xaml.cs
@@ -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);
});
diff --git a/src/UI/FolderDailog.xaml.cs b/src/UI/FolderDailog.xaml.cs
index d915a294..5d46b945 100644
--- a/src/UI/FolderDailog.xaml.cs
+++ b/src/UI/FolderDailog.xaml.cs
@@ -92,8 +92,8 @@ namespace SourceGit.UI {
/// Constructor
///
///
- ///
- public FolderDailog(string title, string initPath) {
+ ///
+ public FolderDailog(string title, Action 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;
- }
}
///
- /// Set callbacks on click OK.
+ /// Open dialog.
///
+ ///
///
- public void Open(Action onOK) {
- cb = onOK;
- Show();
- }
-
- ///
- /// Initialize given path.
- ///
- ///
- ///
- 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 onOK) {
+ new FolderDailog(title, onOK).Show();
}
#region EVENTS
diff --git a/src/UI/Histories.xaml.cs b/src/UI/Histories.xaml.cs
index 1bee9578..9995539c 100644
--- a/src/UI/Histories.xaml.cs
+++ b/src/UI/Histories.xaml.cs
@@ -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);
});
};
diff --git a/src/UI/Manager.xaml.cs b/src/UI/Manager.xaml.cs
index dbe2a63b..c6334c14 100644
--- a/src/UI/Manager.xaml.cs
+++ b/src/UI/Manager.xaml.cs
@@ -44,8 +44,7 @@ namespace SourceGit.UI {
///
///
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);
});
}
diff --git a/src/UI/Preference.xaml.cs b/src/UI/Preference.xaml.cs
index a3e6db8c..6be8a68b 100644
--- a/src/UI/Preference.xaml.cs
+++ b/src/UI/Preference.xaml.cs
@@ -116,8 +116,7 @@ namespace SourceGit.UI {
///
///
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;
});