mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-21 05:10:25 +08:00
refactor: unify the behavior of Reveal in File Explorer when the selected is a folder across all platforms
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
@@ -106,7 +106,7 @@ namespace SourceGit.Native
|
||||
Process.Start(browser, url.Quoted());
|
||||
}
|
||||
|
||||
public void OpenInFileManager(string path, bool select)
|
||||
public void OpenInFileManager(string path)
|
||||
{
|
||||
if (Directory.Exists(path))
|
||||
{
|
||||
|
||||
@@ -91,7 +91,7 @@ namespace SourceGit.Native
|
||||
Process.Start("open", url);
|
||||
}
|
||||
|
||||
public void OpenInFileManager(string path, bool select)
|
||||
public void OpenInFileManager(string path)
|
||||
{
|
||||
if (Directory.Exists(path))
|
||||
Process.Start("open", path.Quoted());
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace SourceGit.Native
|
||||
List<Models.ExternalTool> FindExternalTools();
|
||||
|
||||
void OpenTerminal(string workdir, string args);
|
||||
void OpenInFileManager(string path, bool select);
|
||||
void OpenInFileManager(string path);
|
||||
void OpenBrowser(string url);
|
||||
void OpenWithDefaultEditor(string file);
|
||||
}
|
||||
@@ -198,9 +198,9 @@ namespace SourceGit.Native
|
||||
}
|
||||
}
|
||||
|
||||
public static void OpenInFileManager(string path, bool select = false)
|
||||
public static void OpenInFileManager(string path)
|
||||
{
|
||||
_backend.OpenInFileManager(path, select);
|
||||
_backend.OpenInFileManager(path);
|
||||
}
|
||||
|
||||
public static void OpenBrowser(string url)
|
||||
|
||||
@@ -177,32 +177,30 @@ namespace SourceGit.Native
|
||||
Process.Start(startInfo);
|
||||
}
|
||||
|
||||
public void OpenInFileManager(string path, bool select)
|
||||
public void OpenInFileManager(string path)
|
||||
{
|
||||
string fullpath;
|
||||
if (File.Exists(path))
|
||||
{
|
||||
fullpath = new FileInfo(path).FullName;
|
||||
select = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
fullpath = new DirectoryInfo(path!).FullName;
|
||||
fullpath += Path.DirectorySeparatorChar;
|
||||
var pidl = ILCreateFromPathW(new FileInfo(path).FullName);
|
||||
|
||||
try
|
||||
{
|
||||
SHOpenFolderAndSelectItems(pidl, 0, 0, 0);
|
||||
}
|
||||
finally
|
||||
{
|
||||
ILFree(pidl);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (select)
|
||||
var dir = new DirectoryInfo(path).FullName + Path.DirectorySeparatorChar;
|
||||
Process.Start(new ProcessStartInfo(dir)
|
||||
{
|
||||
OpenFolderAndSelectFile(fullpath);
|
||||
}
|
||||
else
|
||||
{
|
||||
Process.Start(new ProcessStartInfo(fullpath)
|
||||
{
|
||||
UseShellExecute = true,
|
||||
CreateNoWindow = true,
|
||||
});
|
||||
}
|
||||
UseShellExecute = true,
|
||||
CreateNoWindow = true,
|
||||
});
|
||||
}
|
||||
|
||||
public void OpenWithDefaultEditor(string file)
|
||||
@@ -213,6 +211,7 @@ namespace SourceGit.Native
|
||||
Process.Start(start);
|
||||
}
|
||||
|
||||
#region HELPER_METHODS
|
||||
private void FixWindowFrameOnWin10(Window w)
|
||||
{
|
||||
// Schedule the DWM frame extension to run in the next render frame
|
||||
@@ -228,11 +227,22 @@ namespace SourceGit.Native
|
||||
}, DispatcherPriority.Render);
|
||||
}
|
||||
|
||||
private PixelPoint IntPtrToPixelPoint(IntPtr param)
|
||||
private List<Models.ExternalTool.LaunchOption> GenerateVSProjectLaunchOptions(string path)
|
||||
{
|
||||
var v = IntPtr.Size == 4 ? param.ToInt32() : (int)(param.ToInt64() & 0xFFFFFFFF);
|
||||
return new PixelPoint((short)(v & 0xffff), (short)(v >> 16));
|
||||
var root = new DirectoryInfo(path);
|
||||
if (!root.Exists)
|
||||
return null;
|
||||
|
||||
var options = new List<Models.ExternalTool.LaunchOption>();
|
||||
root.WalkFiles(f =>
|
||||
{
|
||||
if (f.EndsWith(".sln", StringComparison.OrdinalIgnoreCase) ||
|
||||
f.EndsWith(".slnx", StringComparison.OrdinalIgnoreCase))
|
||||
options.Add(new(root.GetRelativePath(f), f.Quoted()));
|
||||
});
|
||||
return options;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region EXTERNAL_EDITOR_FINDER
|
||||
private string FindVSCode()
|
||||
@@ -385,35 +395,5 @@ namespace SourceGit.Native
|
||||
return string.Empty;
|
||||
}
|
||||
#endregion
|
||||
|
||||
private void OpenFolderAndSelectFile(string folderPath)
|
||||
{
|
||||
var pidl = ILCreateFromPathW(folderPath);
|
||||
|
||||
try
|
||||
{
|
||||
SHOpenFolderAndSelectItems(pidl, 0, 0, 0);
|
||||
}
|
||||
finally
|
||||
{
|
||||
ILFree(pidl);
|
||||
}
|
||||
}
|
||||
|
||||
private List<Models.ExternalTool.LaunchOption> GenerateVSProjectLaunchOptions(string path)
|
||||
{
|
||||
var root = new DirectoryInfo(path);
|
||||
if (!root.Exists)
|
||||
return null;
|
||||
|
||||
var options = new List<Models.ExternalTool.LaunchOption>();
|
||||
root.WalkFiles(f =>
|
||||
{
|
||||
if (f.EndsWith(".sln", StringComparison.OrdinalIgnoreCase) ||
|
||||
f.EndsWith(".slnx", StringComparison.OrdinalIgnoreCase))
|
||||
options.Add(new(root.GetRelativePath(f), f.Quoted()));
|
||||
});
|
||||
return options;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace SourceGit.Views
|
||||
explore.IsEnabled = Directory.Exists(fullPath);
|
||||
explore.Click += (_, ev) =>
|
||||
{
|
||||
Native.OS.OpenInFileManager(fullPath, true);
|
||||
Native.OS.OpenInFileManager(fullPath);
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
@@ -264,7 +264,7 @@ namespace SourceGit.Views
|
||||
explore.IsEnabled = File.Exists(fullPath);
|
||||
explore.Click += (_, ev) =>
|
||||
{
|
||||
Native.OS.OpenInFileManager(fullPath, true);
|
||||
Native.OS.OpenInFileManager(fullPath);
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace SourceGit.Views
|
||||
explore.IsEnabled = File.Exists(full);
|
||||
explore.Click += (_, ev) =>
|
||||
{
|
||||
Native.OS.OpenInFileManager(full, true);
|
||||
Native.OS.OpenInFileManager(full);
|
||||
ev.Handled = true;
|
||||
};
|
||||
menu.Items.Add(explore);
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace SourceGit.Views
|
||||
explore.IsEnabled = File.Exists(changeFullPath);
|
||||
explore.Click += (_, ev) =>
|
||||
{
|
||||
Native.OS.OpenInFileManager(changeFullPath, true);
|
||||
Native.OS.OpenInFileManager(changeFullPath);
|
||||
ev.Handled = true;
|
||||
};
|
||||
menu.Items.Add(explore);
|
||||
|
||||
@@ -446,7 +446,7 @@ namespace SourceGit.Views
|
||||
explore.IsEnabled = Directory.Exists(fullPath);
|
||||
explore.Click += (_, ev) =>
|
||||
{
|
||||
Native.OS.OpenInFileManager(fullPath, true);
|
||||
Native.OS.OpenInFileManager(fullPath);
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
@@ -567,10 +567,10 @@ namespace SourceGit.Views
|
||||
var explore = new MenuItem();
|
||||
explore.Header = App.Text("RevealFile");
|
||||
explore.Icon = App.CreateMenuIcon("Icons.Explore");
|
||||
explore.IsEnabled = File.Exists(fullPath);
|
||||
explore.IsEnabled = File.Exists(fullPath) || Directory.Exists(fullPath);
|
||||
explore.Click += (_, ev) =>
|
||||
{
|
||||
Native.OS.OpenInFileManager(fullPath, file.Type == Models.ObjectType.Blob);
|
||||
Native.OS.OpenInFileManager(fullPath);
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
|
||||
@@ -157,7 +157,7 @@ namespace SourceGit.Views
|
||||
explore.IsEnabled = File.Exists(fullPath);
|
||||
explore.Click += (_, ev) =>
|
||||
{
|
||||
Native.OS.OpenInFileManager(fullPath, true);
|
||||
Native.OS.OpenInFileManager(fullPath);
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
|
||||
@@ -285,7 +285,7 @@ namespace SourceGit.Views
|
||||
explore.Click += (_, e) =>
|
||||
{
|
||||
var target = hasSelectedFolder ? Native.OS.GetAbsPath(repo.FullPath, selectedSingleFolder) : path;
|
||||
Native.OS.OpenInFileManager(target, true);
|
||||
Native.OS.OpenInFileManager(target);
|
||||
e.Handled = true;
|
||||
};
|
||||
menu.Items.Add(explore);
|
||||
@@ -764,7 +764,7 @@ namespace SourceGit.Views
|
||||
explore.IsEnabled = Directory.Exists(dir);
|
||||
explore.Click += (_, e) =>
|
||||
{
|
||||
Native.OS.OpenInFileManager(dir, true);
|
||||
Native.OS.OpenInFileManager(dir);
|
||||
e.Handled = true;
|
||||
};
|
||||
menu.Items.Add(explore);
|
||||
@@ -960,7 +960,7 @@ namespace SourceGit.Views
|
||||
explore.Click += (_, e) =>
|
||||
{
|
||||
var target = hasSelectedFolder ? Native.OS.GetAbsPath(repo.FullPath, selectedSingleFolder) : path;
|
||||
Native.OS.OpenInFileManager(target, true);
|
||||
Native.OS.OpenInFileManager(target);
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
@@ -1173,7 +1173,7 @@ namespace SourceGit.Views
|
||||
explore.Icon = App.CreateMenuIcon("Icons.Explore");
|
||||
explore.Click += (_, e) =>
|
||||
{
|
||||
Native.OS.OpenInFileManager(dir, true);
|
||||
Native.OS.OpenInFileManager(dir);
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user