Esempio n. 1
0
 public static void Reset(this AvalonEditViewModel vm)
 {
     Application.Current.Dispatcher.Invoke(delegate
     {
         vm.Document    = new TextDocument();
         vm.OwerName    = string.Empty;
         vm.Highlighter = JsonHighlighter;
     });
 }
Esempio n. 2
0
        public static void Set(this AvalonEditViewModel vm, string assetProperties, string ownerName, IHighlightingDefinition format = null)
        {
            Application.Current.Dispatcher.Invoke(delegate
            {
                vm.Document    = new TextDocument(assetProperties);
                vm.OwerName    = ownerName;
                vm.Highlighter = format ?? JsonHighlighter;
            });

            if (Properties.Settings.Default.AutoSave)
            {
                vm.Save(true);
            }
        }
Esempio n. 3
0
        public static void Save(this AvalonEditViewModel vm, bool autoSave)
        {
            Application.Current.Dispatcher.Invoke(delegate
            {
                if (vm.HasData())
                {
                    if (autoSave)
                    {
                        string path = Properties.Settings.Default.OutputPath + "\\JSONs" + vm.OwnerPath + "\\";
                        string file = Folders.GetUniqueFilePath(path + Path.ChangeExtension(vm.OwnerName, ".json"));

                        Directory.CreateDirectory(path);
                        File.WriteAllText(file, vm.Document.Text);
                        if (File.Exists(file))
                        {
                            DebugHelper.WriteLine("{0} {1} {2}", "[FModel]", "[AvalonEditViewModel]", $"{vm.OwnerName} successfully saved");
                            FConsole.AppendText(string.Format(Properties.Resources.SaveSuccess, Path.GetFileName(file)), FColors.Green, true);
                        }
                    }
                    else
                    {
                        Directory.CreateDirectory(Properties.Settings.Default.OutputPath + "\\JSONs" + vm.OwnerPath);
                        var saveFileDialog = new SaveFileDialog
                        {
                            Title            = Properties.Resources.Save,
                            FileName         = Path.ChangeExtension(vm.OwnerName, ".json"),
                            InitialDirectory = Properties.Settings.Default.OutputPath + "\\JSONs" + vm.OwnerPath,
                            Filter           = Properties.Resources.JsonFilter
                        };
                        if ((bool)saveFileDialog.ShowDialog())
                        {
                            File.WriteAllText(saveFileDialog.FileName, vm.Document.Text);
                            if (File.Exists(saveFileDialog.FileName))
                            {
                                DebugHelper.WriteLine("{0} {1} {2}", "[FModel]", "[AvalonEditViewModel]", $"{vm.OwnerName} successfully saved");
                                Globals.gNotifier.ShowCustomMessage(Properties.Resources.Success, Properties.Resources.DataSaved, string.Empty, saveFileDialog.FileName);
                            }
                        }
                    }
                }
                else
                {
                    Globals.gNotifier.ShowCustomMessage(Properties.Resources.Error, Properties.Resources.NoDataToSave);
                }
            });
        }
Esempio n. 4
0
 // always call this on the UI thread
 public static bool HasData(this AvalonEditViewModel vm) => !string.IsNullOrEmpty(vm.Document?.Text);