public void InitTemplate(string toolName, string dir = null, bool isScript = true) { var resource = isScript ? "Metaseed.Metatool.Templates.Metatool.Tools.ScriptTool.zip" : "Metaseed.Metatool.Templates.Metatool.Tools.LibTool.zip"; dir ??= Path.Combine(Context.CurrentDirectory, toolName); if (Directory.Exists(dir)) { if (!Prompt.GetYesNo($"We already have a same folder at: {dir}, do you want to override?", false, ConsoleColor.Yellow)) { Console.WriteLine("command canceled."); return; } } using var stream = typeof(Scaffold).Assembly.GetManifestResourceStream(resource); new ZipArchive(stream).ExtractToDirectory(dir, true); _logger.LogInformation($"Metatool: tool {toolName} is created in folder: {dir}"); try { _shell.RunWithCmd($"code {dir}"); _logger.LogInformation("open it with vscode..."); } catch (Exception e) { _fileExplorer.Open(dir); _logger.LogWarning(e.Message); } }
private bool Explore( DocumentMessageModel model) { var localFile = model.Document.Document_?.Local; if (localFile?.Path != null) { var fileInfo = new FileInfo(localFile.Path); if (fileInfo.Exists) { var directory = fileInfo.Directory; _fileExplorer.Open(directory); } } return(false); }
public FileExplorer(IWindowManager windowManager, IFileExplorer fileExplorer, IConfig <Config> config, INotify notify, IKeyboard keyboard) { RegisterCommands(); var hotKeys = config.CurrentValue.FileExplorerPackage.Hotkeys; hotKeys.FocusItemsView.OnEvent(e => { var listBoxEle = windowManager.CurrentWindow?.FirstDescendant(c => c.ByClassName("UIItemsView")); var selectedItem = listBoxEle?.SelectedItems()?.FirstOrDefault(); if (selectedItem != null) { selectedItem.SetFocus(); } else { listBoxEle.FirstChild(c => c.ByClassName("UIItem"))?.Select(); } e.Handled = true; }, _ => windowManager.CurrentWindow.IsExplorerOrOpenSaveDialog); hotKeys.FocusNavigationTreeView.OnEvent(e => { var winEle = windowManager.CurrentWindow?.FirstDescendant(cf => cf.ByClassName("SysTreeView32")); var selectedItem = winEle?.SelectedItems().FirstOrDefault(); if (selectedItem != null) { selectedItem.SetFocus(); } else { winEle?.FirstDecendent(c => c.ByControlType(ControlType.TreeItem))?.Select(); } e.Handled = true; }, _ => windowManager.CurrentWindow.IsExplorerOrOpenSaveDialog); hotKeys.CopySelectedPath.OnEvent(async e => { e.Handled = true; var handle = windowManager.CurrentWindow.Handle; var paths = await fileExplorer.GetSelectedPaths(handle); var r = string.Join(';', paths); notify.ShowMessage($"Path Copied: {r}"); System.Windows.Clipboard.SetText(r); }, _ => windowManager.CurrentWindow.IsExplorerOrOpenSaveDialog); hotKeys.NewFile.OnEvent(async e => { e.Handled = true; const string newFileName = "NewFile"; var handle = windowManager.CurrentWindow.Handle; var fullPath = await fileExplorer.CurrentDirectory(handle); var fileName = newFileName; var i = 1; while (File.Exists(fullPath + "\\" + fileName)) { fileName = newFileName + i++; } var file = File.Create(fullPath + "\\" + fileName); file.Close(); var keyboard = Services.Get <IKeyboard>(); fileExplorer.Select(handle, new[] { fileName }); e.BeginInvoke(() => keyboard.Type(Key.F2)); }, _ => windowManager.CurrentWindow.IsExplorer); hotKeys.ShowDesktopFolder.OnEvent(e => { fileExplorer.Open(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)); e.Handled = true; }); (Ctrl + Back).OnDown(e => { // fix ctrl+back is a box char in explorer e.DisableVirtualKeyHandlingInThisEvent(); e.Handled = true; keyboard.Type(Ctrl + Shift + Left, Back); // Ctrl is up now keyboard.Down(Ctrl); //to trigger, if user hold ctrl and press back again }, e => windowManager.CurrentWindow.IsExplorerOrOpenSaveDialog); }