private void RemoveFile(object file) { try { if (file != null) { var filePath = (string)file; var fileName = Path.GetFileNameWithoutExtension(filePath); var fileToRemove = FilesNameCollection.FirstOrDefault(f => f.FilePath.Equals(filePath)); if (fileToRemove != null) { FilesNameCollection.Remove(fileToRemove); //remove the scripts which coresponds with the removed file from the grid var scriptsToBeRemoved = ScriptsCollection.Where(s => s.Key.Equals(fileName)).ToList(); foreach (var script in scriptsToBeRemoved) { ScriptsCollection.Remove(script); } } if (ScriptsCollection.Count.Equals(0)) { MessageVisibility = "Collapsed"; } } SetGridVisibility(); } catch (Exception ex) { Log.Logger.Error($"{Constants.RemoveFile}: {Constants.Message}: {ex.Message}\n " + $"{Constants.StackTrace}: {ex.StackTrace}\n {Constants.InnerException}: {ex.InnerException}"); } }
private async void HandlePreviewDrop(object dropedFile) { var file = dropedFile as IDataObject; if (null == file) { return; } var documentsPath = (string[])file.GetData(DataFormats.FileDrop); if (documentsPath != null) { foreach (var path in documentsPath) { if (ProcessScript.IsGeneratedByAhkPlugin(path)) { MessageVisibility = "Collapsed"; var pathAlreadyAdded = FilesNameCollection.Any(p => p.FilePath.Equals(path)); if (!pathAlreadyAdded) { var scripts = ProcessScript.ReadImportedScript(path); foreach (var script in scripts) { var exist = await ProcessScript.ScriptContentAlreadyExist(script.Value); if (!exist) { script.Value.ScriptStateAction = script.Value.Active ? "Disable" : "Enable"; script.Value.RowColor = script.Value.Active ? "Black" : "DarkGray"; ScriptsCollection.Add(script); } } var newFile = new ImportScriptItemTemplate { Content = Path.GetFileNameWithoutExtension(path), RemoveFileCommand = new RelayCommand(RemoveFile), FilePath = path }; FilesNameCollection.Add(newFile); if (ScriptsCollection.Count.Equals(0)) { MessageVisibility = "Visible"; Message = "Imported scripts are already in the master script."; } } } else { MessageVisibility = "Visible"; Message = "Only scripts generated by AHK Plugin are supported."; } } } SetGridVisibility(); }
private void RemoveFile(object file) { if (file != null) { var filePath = (string)file; var fileName = Path.GetFileNameWithoutExtension(filePath); var fileToRemove = FilesNameCollection.FirstOrDefault(f => f.FilePath.Equals(filePath)); if (fileToRemove != null) { FilesNameCollection.Remove(fileToRemove); //remove the scripts which coresponds with the removed file from the grid var scriptsToBeRemoved = ScriptsCollection.Where(s => s.Key.Equals(fileName)).ToList(); foreach (var script in scriptsToBeRemoved) { ScriptsCollection.Remove(script); } } } SetGridVisibility(); }
private void HandlePreviewDrop(object dropedFile) { var file = dropedFile as IDataObject; if (null == file) { return; } var documentsPath = (string[])file.GetData(DataFormats.FileDrop); var defaultFormat = DataFormats.Text; if (documentsPath != null) { foreach (var path in documentsPath) { if (ProcessScript.IsGeneratedByAhkPlugin(path)) { MessageVisibility = "Hidden"; var pathAlreadyAdded = FilesNameCollection.Any(p => p.FilePath.Equals(path)); if (!pathAlreadyAdded) { var scripts = ProcessScript.ReadImportedScript(path); ScriptsCollection.AddRange(scripts); var newFile = new ImportScriptItemTemplate { Content = Path.GetFileNameWithoutExtension(path), RemoveFileCommand = new RelayCommand(RemoveFile), FilePath = path }; FilesNameCollection.Add(newFile); } } else { MessageVisibility = "Visible"; Message = "Only scripts generated by AHK Plugin are supported."; } } } SetGridVisibility(); }