コード例 #1
0
        private void RaiseCommandCanExecuteChanged()
        {
            CancelCommand.RaiseCanExecuteChanged();

            FileCommands?.RaiseCommandCanExecuteChanged();
            ImageViewModel?.ImageCommands?.RaiseCommandCanExecuteChanged();
        }
コード例 #2
0
 public GumCommands()
 {
     GuiCommands       = new GuiCommands();
     FileCommands      = new FileCommands();
     Edit              = new EditCommands();
     WireframeCommands = new WireframeCommands();
 }
コード例 #3
0
        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.");
            }
        }
コード例 #4
0
 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();
     }
 }
コード例 #5
0
        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);
                }
            });
        }
コード例 #6
0
        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
        }
コード例 #7
0
        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);
            }
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
            }
        }
コード例 #10
0
 private void closeToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (this.ActiveDocument != null)
     {
         FileCommands.Close(this.ActiveDocument);
     }
 }
コード例 #11
0
        /*
         * 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);
            }
        }
コード例 #12
0
        private void NewFile()
        {
            LispEditor editor = FileCommands.NewFile();

            SetupEditor(editor);
            ShowEditor(editor, DockState.Document);
        }
コード例 #13
0
 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), "");
 }
コード例 #14
0
        private void OpenFile()
        {
            string[] files = FileCommands.OpenFiles(this);

            foreach (string filePath in files)
            {
                OpenFile(filePath);
            }
        }
コード例 #15
0
        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);
        }
コード例 #16
0
 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();
         }
     });
 }
コード例 #17
0
        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);
            }
        }
コード例 #18
0
        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);
        }
コード例 #19
0
        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.";
            }
        }
コード例 #20
0
        public void PurgeQueues()
        {
            while (_waitingCommandQueue.Count > 0)
            {
                _waitingCommandQueue.TryDequeue(out var dummy);
                CommandQueueLengthChanged?.Invoke(this, CommandQueueLength);
            }

            SystemCommands.Purge();
            ManualCommands.Purge();
            FileCommands.Purge();
            MacroCommands.Purge();
        }
コード例 #21
0
        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);
        }
コード例 #22
0
        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);
                }
            }
        }
コード例 #23
0
        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));
        }
コード例 #24
0
 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();
 }
コード例 #25
0
        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);
            }
        }
コード例 #26
0
 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);
     }
 }
コード例 #27
0
 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);
 }
コード例 #28
0
 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!");
     }
 }
コード例 #29
0
 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());
             }
         }
     }
 }
コード例 #30
0
        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);
        }