Ejemplo n.º 1
0
        public EditorManager(IFileViewModel setting, MainViewModel mainViewModel)
        {
            m_editorsWithSettings = new FilteredObservableCollection<IEditor>(m_baseEditors, editor => editor.Settings != null);
              m_setting = setting;
              m_mainViewModel = mainViewModel;
              m_imageViewerViewModel = new ImageViewerViewModel();
              m_jsonEditorViewModel = new JsonEditorViewModel(mainViewModel);
              m_simpleEditor = new BaseTextEditorViewModel(mainViewModel);
              m_findInFilesViewModel = new FindInFilesViewModel(mainViewModel);

              UpdateSettings();
              m_setting.ContentChanged += SettingOnContentChanged;
        }
Ejemplo n.º 2
0
        public JsonEditorViewModel(MainViewModel mainViewModel)
            : base(mainViewModel)
        {
            m_supportedFiles = new List<string> { ".json" };
              m_name = "Json editor";
              m_schemaManager = mainViewModel.SchemaManager;
              Task task = new Task(CheckJsonTask);
              task.Start();
              Task task2 = new Task(UpdateAutoCompletTask);
              task2.Start();

              m_menuItems = new ObservableCollection<IMenuItemViewModel>
            {
              new MenuItemViewModel("Generate schema", new ManualCommand(GenerateSchema))
            };
        }
Ejemplo n.º 3
0
        public BaseTextEditorViewModel(MainViewModel mainViewModel)
        {
            m_mainViewModel = mainViewModel;
              SetHighLight(Properties.Resources.Json_Mode, new[] {".json"}, "Json highlighting");
              SetHighLight(Properties.Resources.CSharp_Mode, new[] { ".cs" }, "C# highlighting");
              SetHighLight(Properties.Resources.CPP_Mode, new[] { ".c", ".h", ".cpp", ".hpp" }, "c/c++ highlighting");
              SetHighLight(Properties.Resources.CSS_Mode, new[] { ".css" }, "Css highlighting");
              SetHighLight(Properties.Resources.HTML_Mode, new[] { ".html", ".htm" }, "Html highlighting");
              SetHighLight(Properties.Resources.JavaScript_Mode, new[] { ".js" }, "Javascript highlighting");
              SetHighLight(Properties.Resources.XmlDoc, new[] { ".xml", ".xshd" }, "Xml highlighting");
              SetHighLight(Properties.Resources.Lua, new[] { ".lua", ".luac" }, "Lua highlighting");

              m_textDocument = new TextDocument();
              m_textDocument.TextChanged += TextDocumentOnTextChanged;

              m_findNextCommand = new ManualCommand(FindNext);
              m_replaceCommand = new ManualCommand(Replace);
              m_replaceAllCommand = new ManualCommand(ReplaceAll);
              m_settningsSchema = GetSettingsSchema(m_mainViewModel.SchemaManager);
              Settings = GetSettings();
        }
Ejemplo n.º 4
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
              List<string> files = new List<string>();
              StringBuilder errors = new StringBuilder();
              string outputPath = null;
              bool silent = false;
              MainViewModel mainViewModel = new MainViewModel();

              foreach (string arg in e.Args)
              {
            if (arg.StartsWith("-"))
            {
              Regex regex = new Regex("-([a-zA-Z]*):?([^,]*),?([^,]*),?([^,]*)");
              Match match = regex.Match(arg);
              if (match.Success)
              {
            string parameter = match.Groups[2].ToString();
            switch (match.Groups[1].ToString().ToLower())
            {
              case "folder":
                if (Directory.Exists(parameter))
                {
                  mainViewModel.Path = parameter;
                }
                else
                {
                  errors.AppendLine("Folder does not exist: " + parameter);
                }
                break;
              case "closeall":
                foreach (LayoutElementViewModel layoutElementViewModel in mainViewModel.LayoutManager.LayoutElements)
                {
                  layoutElementViewModel.OpenFiles.Clear();
                  layoutElementViewModel.FileUseOrder.Clear();
                  layoutElementViewModel.SelectedFile = null;
                }
                break;
              case "layout":
                LayoutType layoutType;
                if (Enum.TryParse(parameter, true, out layoutType))
                  mainViewModel.LayoutManager.SelectedLayoutType = layoutType;
                else
                  errors.AppendLine("Unknown layout: " + parameter);
                break;
              case "validate":
                if (File.Exists(parameter))
                {
                  JsonException jsonException;
                  string text = File.ReadAllText(parameter);
                  JsonObject jsonObject = JsonHelperFunctions.Parse(text, out jsonException);
                  if (jsonException != null)
                  {
                    errors.AppendLine("json error: " + jsonException.Message);
                    Environment.ExitCode = 1;
                    break;
                  }
                  Regex scheamRegex = new Regex(@"""\$schema""\s*\:\s*""(.*)""", RegexOptions.IgnoreCase);
                  Match schemaMatch = scheamRegex.Match(text);
                  Schema schema = schemaMatch.Success ? mainViewModel.SchemaManager.GetSchema(schemaMatch.Groups[1].ToString()) : null;
                  if (schema == null)
                  {
                    errors.AppendLine("Sschema not found: " + arg);
                    Environment.ExitCode = 2;
                    break;
                  }
                  Dictionary<int, List<ValidationError>> validationErrors = new Dictionary<int, List<ValidationError>>();
                  schema.Validate(jsonObject, validationErrors, Path.GetDirectoryName(parameter));
                  if (validationErrors.Count > 0)
                  {
                    Environment.ExitCode = 1;
                    foreach (KeyValuePair<int, List<ValidationError>> validationError in validationErrors)
                    {
                      foreach (ValidationError error in validationError.Value)
                      {
                        errors.AppendLine(validationError.Key + ": " + error.Message);
                      }
                    }
                  }
                }
                else
                {
                  errors.AppendLine("File not found: " + parameter);
                  Environment.ExitCode = 2;
                }
                break;
              case "silent":
                silent = true;
                break;
              case "output":
                outputPath = parameter;
                break;
              default:
                errors.AppendLine("Unknown command: " + arg);
                break;
            }
              }
              else
              {
            errors.AppendLine("Argument with wrong format: " + arg);
              }
            }
            else
            {
              if (File.Exists(arg))
            files.Add(arg);
              else
              {
            errors.Append("Can't find file: " + arg);
              }
            }
              }

              foreach (string file in files)
            mainViewModel.OpenFile(file);

              if (!silent)
              {
            if (outputPath != null)
            {
              File.WriteAllText(outputPath, errors.ToString());
            }
            else
            {
              if (errors.Length > 0)
              {
            FileViewModel fileViewModel = new FileViewModel(errors.ToString(), "Errors");
            mainViewModel.OpenFile(fileViewModel);
              }

              mainViewModel.Window.ShowDialog();
            }
              }

              Shutdown();
        }