private void RaiseCommandCanExecuteChanged() { CancelCommand.RaiseCanExecuteChanged(); FileCommands?.RaiseCommandCanExecuteChanged(); ImageViewModel?.ImageCommands?.RaiseCommandCanExecuteChanged(); }
public GumCommands() { GuiCommands = new GuiCommands(); FileCommands = new FileCommands(); Edit = new EditCommands(); WireframeCommands = new WireframeCommands(); }
public string SaveTextGeneratorData() { var outputDataPath = Path.Combine(DefaultPaths.RootFolder, "Default", "TextGenerator", "TextGenerator.json"); try { var json = JsonConvert.SerializeObject(MainWindow.TextGeneratorWindow.Data, Newtonsoft.Json.Formatting.Indented); if (CurrentModule != null) { outputDataPath = DefaultPaths.ModuleTextGeneratorDataFile(CurrentModule.ModuleData); } if (FileCommands.WriteToFile(outputDataPath, json)) { string msg = $"TextGenerator settings were saved to '{outputDataPath}'."; Log.Here().Activity(msg); return(msg); } else { string msg = $"Error saving TextGenerator settings to '{outputDataPath}'."; Log.Here().Error(msg); return(msg); } } catch (Exception ex) { Log.Here().Error($"Error loading TextGenerator data file: {ex.ToString()}"); return($"Error saving TextGenerator settings to '{outputDataPath}'. Check the log."); } }
public void LoadAppSettings() { if (File.Exists(DefaultPaths.MainAppSettingsFile)) { try { Log.Here().Activity($"Loading main app settings from {DefaultPaths.MainAppSettingsFile}"); string json = FileCommands.ReadFile(DefaultPaths.MainAppSettingsFile); JsonSerializerSettings jsonSettings = new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Ignore, ObjectCreationHandling = ObjectCreationHandling.Auto }; var settings = JsonConvert.DeserializeObject <AppSettingsData>(json, jsonSettings); Data.AppSettings = settings; Log.Enabled = !Data.AppSettings.LogDisabled; } catch (Exception ex) { Log.Here().Error($"Error loading main app settings from {DefaultPaths.MainAppSettingsFile}: {ex.ToString()}"); } } else { Log.Here().Warning($"Main app settings file at {DefaultPaths.MainAppSettingsFile} not found. Creating new file."); Data.AppSettings = new AppSettingsData(); } }
private void ProcessQueue() { _processing = true; Observable.Timer(TimeSpan.Zero, TimeSpan.FromMilliseconds(10)).TakeUntil(_stopSubject).Subscribe( l => { if ((SystemCommands.TryPeekCommand(out var cmd) || ManualCommands.TryPeekCommand(out cmd) || FileCommands.TryPeekCommand(out cmd) || FileCommands.State != CommandSourceState.Running && _waitingCommandQueue.Count == 0 && MacroCommands.TryPeekCommand(out cmd)) && cmd != null && cmd.Data.RemoveSpace().Length + CommandQueueLength <= _bufferSizeLimit) { var continueProcess = cmd.Source switch { CommandSourceType.System => SystemCommands.TryGetCommand(out cmd), CommandSourceType.Macros => MacroCommands.TryGetCommand(out cmd), CommandSourceType.Manual => ManualCommands.TryGetCommand(out cmd), CommandSourceType.File => FileCommands.TryGetCommand(out cmd), _ => false }; if (!continueProcess) { return; } _commandPreProcessor.Process(ref cmd); Send(cmd); } }); }
private void LispEditor_FormClosing(object sender, FormClosingEventArgs e) { // Check if the document has been modified if (this.Scintilla.Modified) { string message = String.Format( CultureInfo.CurrentCulture, "The text in {0} has changed.{1}{2}Do you want to save the changes?", this.Text.TrimEnd(' ', '*'), Environment.NewLine, Environment.NewLine); DialogResult dr = MessageBox.Show(this, message, Program.Title, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation); if (dr == DialogResult.Cancel) { // Cancel closing e.Cancel = true; return; } else if (dr == DialogResult.Yes) { // Try to save e.Cancel = !FileCommands.SaveFile(this, this); return; } } // Continue closing }
private void OnSaveAs(bool success, string path) { if (success) { //if (Path.GetFileName(path) == Path.GetFileName(DefaultFilePath)) SaveCommand.OpenSaveAsOnDefault = false; if (FileCommands.PathIsRelative(path)) { path = Common.Functions.GetRelativePath.RelativePathGetter.Relative(Directory.GetCurrentDirectory(), path); } bool saveAppSettings = false; if (FilePath != path) { saveAppSettings = true; FilePath = path; } MainWindow.FooterLog("Saved {0} to {1}", Name, FilePath); if (saveAppSettings) { FileCommands.Save.SaveModuleSettings(parentData); } } else { MainWindow.FooterLog("Error saving {0} to {1}", Name, path); } }
public void MenuAction_SaveLog() { string logContent = ""; foreach (var data in mainWindow.LogWindow.ViewModel.Logs.Items) { logContent += data.Output + Environment.NewLine; } string sysFormat = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern.Replace("/", "-"); string fileName = "SourceControlGenerator_Log_" + DateTime.Now.ToString(sysFormat + "_HH-mm") + ".txt"; FileCommands.Save.OpenDialog_Old(mainWindow, "Save Log File...", Data.AppSettings.LastLogPath, (string logPath) => { if (FileCommands.WriteToFile(logPath, logContent)) { Log.Here().Activity($"Saved log file to {logPath}."); } else { Log.Here().Error($"Error saving log file to {logPath}."); } Data.AppSettings.LastLogPath = logPath; }, fileName); }
public void SelectFoldersDialog(Window ParentWindow, string Title, string FilePath, Action <List <string> > OnFoldersSelected) { var openFolder = new CommonOpenFileDialog(); openFolder.AllowNonFileSystemItems = true; openFolder.Multiselect = true; openFolder.IsFolderPicker = true; openFolder.Title = Title; openFolder.DefaultFileName = ""; openFolder.InitialDirectory = Path.GetFullPath(FilePath); openFolder.DefaultDirectory = Path.GetFullPath(Assembly.GetExecutingAssembly().Location); var result = openFolder.ShowDialog(ParentWindow); if (result == CommonFileDialogResult.Ok) { var folders = openFolder.FileNames.ToList(); for (int i = 0; i < folders.Count; i++) { var path = folders[i]; if (FileCommands.PathIsRelative(path)) { path = path.Replace(Directory.GetCurrentDirectory(), ""); } } OnFoldersSelected?.Invoke(folders); } }
private void closeToolStripMenuItem_Click(object sender, EventArgs e) { if (this.ActiveDocument != null) { FileCommands.Close(this.ActiveDocument); } }
/* * public void OpenOokiiFolderDialog(Window ParentWindow, string Title, string FilePath, Action<string> OnFolderSelected) * { * VistaFolderBrowserDialog folderDialog = new VistaFolderBrowserDialog(); * folderDialog.SelectedPath = Path.GetFullPath(FilePath); * folderDialog.Description = Title; * folderDialog.UseDescriptionForTitle = true; * folderDialog.ShowNewFolderButton = true; * * Nullable<bool> result = folderDialog.ShowDialog(ParentWindow); * * if (result == true) * { * string path = folderDialog.SelectedPath; * if (FileCommands.PathIsRelative(path)) * { * path = folderDialog.SelectedPath.Replace(Directory.GetCurrentDirectory(), ""); * } * * OnFolderSelected?.Invoke(path); * } * * } */ public void OpenFolderDialog(Window ParentWindow, string Title, string FilePath, Action <string> OnFolderSelected, bool RetainRelativity = true) { var openFolder = new CommonOpenFileDialog(); openFolder.AllowNonFileSystemItems = true; openFolder.Multiselect = false; openFolder.IsFolderPicker = true; openFolder.Title = Title; openFolder.DefaultFileName = ""; openFolder.InitialDirectory = Path.GetFullPath(FilePath); openFolder.DefaultDirectory = Path.GetFullPath(Assembly.GetExecutingAssembly().Location); var result = openFolder.ShowDialog(ParentWindow); if (result == CommonFileDialogResult.Ok) { string path = Path.GetFullPath(openFolder.FileNames.First()); if (RetainRelativity && FileCommands.PathIsRelative(path)) { path = path.Replace(Directory.GetCurrentDirectory(), ""); } OnFolderSelected?.Invoke(path); } }
private void NewFile() { LispEditor editor = FileCommands.NewFile(); SetupEditor(editor); ShowEditor(editor, DockState.Document); }
public void MakeSettingsFolderPortable() { DefaultPaths.RootFolder = DefaultPaths.DefaultPortableRootFolder; if (CurrentModule != null && CurrentModule.ModuleData != null && CurrentModule.ModuleData.ModuleSettings != null) { CurrentModule.ModuleData.ModuleSettings.SetToDefault(CurrentModule.ModuleData); } FileCommands.WriteToFile(Path.Combine(Directory.GetCurrentDirectory(), DefaultPaths.PortableSettingsFile), ""); }
private void OpenFile() { string[] files = FileCommands.OpenFiles(this); foreach (string filePath in files) { OpenFile(filePath); } }
public override bool CanExecute(object parameter) { if (base.CanExecute(parameter) && parameter != null && FileCommands.Load != null) { string filePath = (String)parameter; return(FileCommands.IsValidPath(filePath)); } return(false); }
private void KeywordsList_Default_Click(object sender, RoutedEventArgs e) { FileCommands.OpenConfirmationDialog(this, "Reset Keyword List?", "Reset Keyword values to default?", "Changes will be lost.", (bool confirmed) => { if (confirmed) { Data.UserKeywords.ResetToDefault(); } }); }
public void SaveModuleSettings(IModuleData Data) { Log.Here().Activity("Saving module settings to {0}", Path.GetFullPath(DefaultPaths.ModuleSettingsFile(Data))); if (Data.ModuleSettings != null) { SaveTemplates(Data); string json = JsonConvert.SerializeObject(Data.ModuleSettings, Newtonsoft.Json.Formatting.Indented); FileCommands.WriteToFile(DefaultPaths.ModuleSettingsFile(Data), json); } }
public static bool SaveManagedProjects(DOS2ModuleData Data) { Log.Here().Important("Saving Managed Projects data to {0}", Data.Settings.AddedProjectsFile); if (Data.ManagedProjectsData != null && Data.ManagedProjectsData.SavedProjects.Count > 0 && Data.Settings != null && FileCommands.IsValidPath(Data.Settings.AddedProjectsFile)) { string json = JsonInterface.SerializeObject(Data.ManagedProjectsData); return(FileCommands.WriteToFile(Data.Settings.AddedProjectsFile, json)); } return(false); }
public void OnFileLocationChanged() { FileValidation = FileValidation.None; if (!String.IsNullOrWhiteSpace(FileLocationText)) { if (!FileCommands.IsValidPath(FileLocationText)) { FileValidation = FileValidation.Error; } else { if (BrowseType == FileBrowseType.Directory) { if (!FileCommands.DirectoryExists(FileLocationText)) { FileValidation = FileValidation.Warning; } } else if (BrowseType == FileBrowseType.File) { if (!FileCommands.FileExists(FileLocationText)) { FileValidation = FileValidation.Warning; } } } } if (FileValidation == FileValidation.None) { if (ToolTip != null) { ClearValue(FileBrowseControl.ToolTipProperty); } } else if (FileValidation == FileValidation.Warning) { if (BrowseType == FileBrowseType.Directory) { ToolTip = "Folder not found."; } else if (BrowseType == FileBrowseType.File) { ToolTip = "File not found."; } } else if (FileValidation == FileValidation.Error) { ToolTip = "Error: Path is not valid."; } }
public void PurgeQueues() { while (_waitingCommandQueue.Count > 0) { _waitingCommandQueue.TryDequeue(out var dummy); CommandQueueLengthChanged?.Invoke(this, CommandQueueLength); } SystemCommands.Purge(); ManualCommands.Purge(); FileCommands.Purge(); MacroCommands.Purge(); }
public void Delete_FileDoesNotExist() { var fileWrapperMock = new Mock <IFile>(); fileWrapperMock .Setup(x => x.Exists("test")) .Returns(false); var fileCommands = new FileCommands(createFileStream, fileWrapperMock.Object); var isDeleted = fileCommands.Delete("test"); Assert.False(isDeleted); }
private void OpenFile(string filePath, DockState dockState) { // Ensure this file isn't already open if (!IsOpen(filePath)) { LispEditor editor = FileCommands.OpenFile(filePath); //Open the file if (editor != null) { SetupEditor(editor); ShowEditor(editor, dockState); } } }
public static async Task <T> DeserializeObjectAsync <T>(string path) { try { string contents = await FileCommands.ReadFileAsync(path); return(JsonConvert.DeserializeObject <T>(contents)); } catch (Exception ex) { Log.Here().Error($"Error deserializing json ({path}):\n{ex.ToString()}"); } return(default(T)); }
public GlueCommands() { mSelf = this; GenerateCodeCommands = new GenerateCodeCommands(); GluxCommands = new GluxCommands(); OpenCommands = new OpenCommands(); ProjectCommands = new ProjectCommands(); RefreshCommands = new RefreshCommands(); TreeNodeCommands = new TreeNodeCommands(); UpdateCommands = new UpdateCommands(); DialogCommands = new DialogCommands(); GlueViewCommands = new GlueViewCommands(); FileCommands = new FileCommands(); SelectCommands = new SelectCommands(); }
public void LoadTemplates(IModuleData Data) { string templateFilePath = DefaultPaths.ModuleTemplateSettingsFile(Data); if (File.Exists(Data.ModuleSettings.TemplateSettingsFile)) { templateFilePath = Data.ModuleSettings.TemplateSettingsFile; } else if (!File.Exists(templateFilePath)) { FileCommands.WriteToFile(templateFilePath, Properties.Resources.Templates); } XDocument templateXml = null; try { templateXml = XDocument.Load(templateFilePath); foreach (var template in templateXml.Descendants("Template")) { TemplateEditorData templateData = TemplateEditorData.LoadFromXml(Data, template); Data.Templates.Add(templateData); } } catch (Exception ex) { Log.Here().Error(Message: $"Error loading template file {templateFilePath}: {ex.ToString()}"); } if (Data.ModuleSettings.TemplateFiles != null) { foreach (var templateFile in Data.ModuleSettings.TemplateFiles) { var data = Data.Templates.FirstOrDefault(t => t.ID == templateFile.ID); if (data != null) { data.FilePath = templateFile.FilePath; } } } for (int i = 0; i < Data.Templates.Count; i++) { var template = Data.Templates[i]; template.Init(Data); } }
private void OnKeywordsSaveAs(bool success, string path) { if (success) { if (FileCommands.PathIsRelative(path)) { path = Common.Functions.GetRelativePath.RelativePathGetter.Relative(Directory.GetCurrentDirectory(), path); } Data.CurrentModuleData.ModuleSettings.UserKeywordsFile = path; MainWindow.FooterLog("Saved Keywords to {0}", path); } else { MainWindow.FooterLog("Error saving Keywords to {0}", path); } }
public bool SaveSourceControlData(SourceControlData data, string folderPath) { if (!String.IsNullOrEmpty(folderPath) && Directory.Exists(folderPath)) { Log.Here().Important("Serializing and saving source control data."); var filePath = Path.Combine(folderPath, DefaultPaths.SourceControlGeneratorDataFile); try { string json = JsonConvert.SerializeObject(data, Newtonsoft.Json.Formatting.Indented); return(FileCommands.WriteToFile(filePath, json)); } catch (Exception ex) { Log.Here().Error("Error serializing source control data at {0}: {1}", filePath, ex.ToString()); } } return(false); }
public override void ExecuteSave(object parameter) { if (parameter != null && parameter is ISaveCommandData data) { if (OpenSaveAsOnDefault && data.InitialDirectory == data.FilePath) { FileCommands.Save.OpenDialogAndSave(App.Current.MainWindow, data.SaveAsText, data.FilePath, data.Content, this.OnSaveAs, data.DefaultFileName, data.InitialDirectory); } else { bool success = FileCommands.WriteToFile(data.FilePath, data.Content); OnSave?.Invoke(success); } } else { Log.Here().Error("Parameter is not SaveFileCommandData!"); } }
public void SaveGitGenerationSettings(IModuleData Data, string filePath) { if (Data.GitGenerationSettings != null) { if (!String.IsNullOrEmpty(filePath)) { Log.Here().Important("Serializing and saving git generation settings data."); try { string json = JsonConvert.SerializeObject(Data.GitGenerationSettings, Newtonsoft.Json.Formatting.Indented); FileCommands.WriteToFile(filePath, json); } catch (Exception ex) { Log.Here().Error("Error serializing {0}: {1}", filePath, ex.ToString()); } } } }
public async Task <SourceControlData> LoadSourceControlDataAsync(string filePath) { if (!String.IsNullOrEmpty(filePath) && File.Exists(filePath)) { try { var contents = await FileCommands.ReadFileAsync(filePath); SourceControlData data = JsonConvert.DeserializeObject <SourceControlData>(contents); data.RepositoryPath = Directory.GetDirectoryRoot(filePath); return(data); } catch (Exception ex) { Log.Here().Error("Error deserializing {0}: {1}", filePath, ex.ToString()); } } return(null); }