Пример #1
0
        /// <summary>
        /// Save a file and set text of json editor
        /// </summary>
        /// <param name="editor"></param>
        public static void SaveAsFile(this ICodeEditor editor, string lastFile)
        {
            var content = editor.JsonContent;

            if (!string.IsNullOrWhiteSpace(content))
            {
                SaveFileDialog saveFileDialog = new SaveFileDialog();

                if (!string.IsNullOrWhiteSpace(editor.CurrentFileName))
                {
                    saveFileDialog.InitialDirectory = Path.GetDirectoryName(editor.CurrentFileName);
                }
                else if (!string.IsNullOrWhiteSpace(lastFile))
                {
                    saveFileDialog.InitialDirectory = Path.GetDirectoryName(lastFile);
                }

                if (saveFileDialog.ShowDialog() == true)
                {
                    WriteFile(saveFileDialog.FileName, content);
                    editor.CurrentFileName = saveFileDialog.FileName;
                }
            }
            return;
        }
        public override void Start()
        {
            _xmlValidationManager = XmlValidationManager.Instance;

            // try to load existing rules
            // if this fails, an exception will be thrown, preventing this component from starting
            var rules = CollectionUtils.Map(_xmlValidationManager.GetRules(_applicationComponentClass),
                                            (XmlElement node) => new Rule(node.OuterXml, _liveComponent));

            _rules.Items.AddRange(rules);

            _componentProperties = CollectionUtils.Select(_applicationComponentClass.GetProperties(),
                                                          p => !p.DeclaringType.Equals(typeof(IApplicationComponent)) &&
                                                          !p.DeclaringType.Equals(typeof(ApplicationComponent)));

            _rulesActionModel = new CrudActionModel(true, false, true);
            _rulesActionModel.Add.SetClickHandler(AddNewRule);
            _rulesActionModel.Delete.SetClickHandler(DeleteSelectedRule);
            _rulesActionModel.Delete.Enabled = false;

            _editor          = CodeEditorFactory.CreateCodeEditor();
            _editor.Language = "xml";

            _editorHost = new ChildComponentHost(this.Host, _editor.GetComponent());
            _editorHost.StartComponent();

            base.Start();
        }
Пример #3
0
        private void InitEditor(ICodeEditor editor, string settingName)
        {
            editor.Preferences = _preferences;
            editor.ViewModel   = new JsonEditViewModel(editor.TextBox, new JsonCodeCompletion(editor), _preferences)
            {
                SettingName = settingName
            };

            var lastFile = JTranEdit.user.Default[settingName]?.ToString() ?? "";

            if (!string.IsNullOrWhiteSpace(lastFile))
            {
                try
                {
                    editor.LoadFile(lastFile);
                }
                catch
                {
                    // If can't load last file then just ignore

                    // Set last file to nothing
                    JTranEdit.user.Default[settingName] = "";
                }
            }
        }
Пример #4
0
 public CompletionData(ICodeEditor winEditor, SyntaxElement element)
 {
     _winEditor       = winEditor;
     _element         = element;
     this.Text        = element.Name;
     this.Description = element.Description;
 }
Пример #5
0
        Boolean ICodeEditor.Find(String findText, Boolean matchCase, Boolean searchReverse)
        {
            Int32 characterIndex = this.editorView.Caret.Position.CharacterIndex;

            if (((this.TextView.Selection.Count > 0) && (this.TextView.Selection.ActiveSpan != null)) && (this.TextView.Selection.ActiveSpan.Length > 0))
            {
                if (searchReverse)
                {
                    characterIndex = this.TextView.Selection.ActiveSpan.End - 1;
                }
                else
                {
                    characterIndex = this.TextView.Selection.ActiveSpan.End;
                }
            }
            this.findLogic.MatchCase     = matchCase;
            this.findLogic.SearchString  = findText;
            this.findLogic.SearchReverse = searchReverse;
            TextSpan span = this.findLogic.FindNext(characterIndex, false);

            if (span != null)
            {
                ICodeEditor editor = this;
                editor.ClearSelection();
                editor.Select(span.Start, span.Length);
                editor.EnsureSpanVisible(span.Start, span.Length);
                editor.CaretPosition = span.End;
                editor.EnsureCaretVisible();
                return(true);
            }
            return(false);
        }
Пример #6
0
        // // Driven by user IDE subs:

        public bool NewIDEbyUser(out IIDE newIde)
        {
            if (VirtualMachineBuilder?.VisibleTypes.Count < 1)
            {
                OnShowingMessage("There're no available Virtual Machine types to add in a new IDE. Check types settings via Component Manager."
                                 , "Workplace Configuration Warning in " + Title, MessageBoxIcon.Exclamation);
                newIde = null;
                return(false);
            }
            if (CodeEditorBuilder?.VisibleTypes.Count < 1)
            {
                OnShowingMessage("There're no available Code Editor types to add in a new IDE. Check types settings via Component Manager."
                                 , "Workplace Configuration Warning in " + Title, MessageBoxIcon.Exclamation);
                newIde = null;
                return(false);
            }
            //

            IVirtualMachine machine             = null;
            ICodeEditor     codeEditor          = null;
            IInputPort      inputPort           = null;
            int             withInputPortIndex  = -1;
            IOutputPort     outputPort          = null;
            int             withOutputPortIndex = -1;
            bool            withConsole         = false;

            newIde = null;

            DialogResult newIDEdialogResult;

            using (var newIDEdialog = new NewIdeDialog(VirtualMachineBuilder.VisibleTypes, CodeEditorBuilder.VisibleTypes
                                                       , InputPortBuilder.VisibleTypes, OutputPortBuilder.VisibleTypes
                                                       , InputDeviceBuilder.VisibleTypes.Any(t => t.TypeName == typeof(ConsoleDevice).Name) ||
                                                       OutputDeviceBuilder.VisibleTypes.Any(t => t.TypeName == typeof(ConsoleDevice).Name)))
            {
                newIDEdialogResult = newIDEdialog.ShowDialog(MainForm as Form);
                if (newIDEdialogResult == DialogResult.OK)
                {
                    machine = VirtualMachineBuilder.GetNew(VirtualMachineBuilder.VisibleTypes[newIDEdialog.ChosenMachineTypeIndex]);
                    machine.CurrentLanguage = newIDEdialog.ChosenLanguage;
                    codeEditor = CodeEditorBuilder.GetNew(CodeEditorBuilder.VisibleTypes[newIDEdialog.ChosenCodeEditorTypeIndex]);
                    inputPort  = newIDEdialog.ChosenInputPortTypeFullName.IsNotNullOrEmpty()
                            ? InputPortBuilder.GetNew(InputPortBuilder.VisibleTypes[newIDEdialog.ChosenInputPortTypeIndex]) : null;
                    withInputPortIndex = newIDEdialog.ChosenInputPortIndex;
                    outputPort         = newIDEdialog.ChosenOutputPortTypeFullName.IsNotNullOrEmpty()
                            ? OutputPortBuilder.GetNew(OutputPortBuilder.VisibleTypes[newIDEdialog.ChosenOutputPortTypeIndex]) : null;
                    withOutputPortIndex = newIDEdialog.ChosenOutputPortIndex;
                    withConsole         = newIDEdialog.ChosenWithConsole;
                }
            }
            if (newIDEdialogResult != DialogResult.OK)
            {
                return(false);
            }

            newIde = NewIDE(machine, codeEditor, inputPort, withInputPortIndex
                            , outputPort, withOutputPortIndex, withConsole);

            return(true);
        }
Пример #7
0
 public CodeEditorTypeInfo(string assemblyQualifiedTypeName, string typeName, string typeFullName
                           , string sourceFileName, object tag
                           , ICodeEditor componentExample)
     : base(assemblyQualifiedTypeName, typeName, typeFullName
            , componentExample.DefaultName, componentExample.Version, componentExample.Author, componentExample.Description
            , sourceFileName, tag)
 {
 }
Пример #8
0
		public TextMarkerService(ICodeEditor codeEditor)
		{
			if (codeEditor == null)
				throw new ArgumentNullException("codeEditor");
			this.codeEditor = codeEditor;
			codeEditor.DocumentChanged += codeEditor_DocumentChanged;
			codeEditor_DocumentChanged(null, null);
		}
 public TextMarkerService(ICodeEditor codeEditor)
 {
     if (codeEditor == null)
     {
         throw new ArgumentNullException("codeEditor");
     }
     this.codeEditor             = codeEditor;
     codeEditor.DocumentChanged += codeEditor_DocumentChanged;
     codeEditor_DocumentChanged(null, null);
 }
Пример #10
0
        /// <summary>
        /// Executes Emmet command with the specified identifier on the specified editor view.
        /// </summary>
        /// <param name="cmdId">Identifier of the command to execute.</param>
        /// <param name="view">Editor to execute command in.</param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// Indicates that the specified command identifier was not found.
        /// </exception>
        public bool RunCommand(int cmdId, ICodeEditor view)
        {
            if (!_initialized)
            {
                InitializeEngine();
            }

            string script;

            switch (cmdId)
            {
            case PackageIds.CmdIDExpandAbbreviation:
                script = GetExpandAbbreviationScript(view);
                break;

            case PackageIds.CmdIDWrapWithAbbreviation:
                script = GetWrapWithAbbreviationScript(view);
                if (script is null)
                {
                    return(false);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(
                          nameof(cmdId),
                          cmdId,
                          "Specified command identifier not found.");
            }

            Trace($"Running script: {script}");
            JavaScriptContext.Current = _context;
            JavaScriptValue result = JavaScriptContext.RunScript(script, _currentSourceContext++);

            if (result.ValueType is JavaScriptValueType.Boolean)
            {
                Trace("Emmet engine failed to execute command.");
                return(false);
            }

            string replacement = result.ToString();

            JavaScriptContext.Idle();
            if (cmdId is PackageIds.CmdIDExpandAbbreviation)
            {
                view.ReplaceCurrentLine(replacement);
            }
            else
            {
                view.ReplaceSelection(replacement);
            }

            Trace($"Command {script} completed successfully.");
            return(true);
        }
Пример #11
0
        private string GetExpandAbbreviationScript(ICodeEditor view)
        {
            string syntax      = ContentTypeToSyntax(view.GetContentTypeInActiveBuffer());
            string currentLine = JavaScriptEscape(view.GetCurrentLine());
            int    caretPos    = view.GetCaretPosColumn();

            return(string.Format(
                       ScriptTemplate,
                       currentLine,
                       caretPos,
                       syntax,
                       "null",
                       view.AbbreviationPrefix));
        }
Пример #12
0
        public static void LoadFile(this ICodeEditor editor, string fileName)
        {
            var result = "";

            using (var stream = File.OpenRead(fileName))
            {
                result = stream.ReadString();
            }

            if (!string.IsNullOrWhiteSpace(result))
            {
                editor.JsonContent     = result;
                editor.CurrentFileName = fileName;
            }

            return;
        }
Пример #13
0
        /// <summary>
        /// Save a file and set text of json editor
        /// </summary>
        /// <param name="editor"></param>
        public static void SaveFile(this ICodeEditor editor, string lastFile)
        {
            var content = editor.JsonContent;

            if (!string.IsNullOrWhiteSpace(content))
            {
                if (!string.IsNullOrWhiteSpace(editor.CurrentFileName))
                {
                    WriteFile(editor.CurrentFileName, content);
                }
                else
                {
                    editor.SaveAsFile(lastFile);
                }
            }

            return;
        }
Пример #14
0
        Boolean ICodeEditor.Replace(String findText, String replaceText, Boolean matchCase)
        {
            if (this.TextView.Selection.Count == 1)
            {
                Int32 start = this.TextView.Selection.ActiveSpan.Start;
                this.findLogic.MatchCase     = matchCase;
                this.findLogic.SearchString  = findText;
                this.findLogic.SearchReverse = false;
                TextSpan span = this.findLogic.FindNext(start, false);
                if ((span != null) && this.TextView.Selection.ActiveSpan.Equals(span))
                {
                    this.EditorCommands.ReplaceSelection(replaceText);
                }
            }
            ICodeEditor editor = this;

            return(editor.Find(findText, matchCase, false));
        }
Пример #15
0
        /// <summary>
        /// Initializes a new diagram editor.
        /// </summary>
        /// <param name="diagram">The diagram being edited</param>
        /// <param name="codeEditor">The code editor</param>
        /// <param name="notifications">Creates objects that report progress</param>
        /// <param name="diagramRenderers">Responsible for converting diagram data to images</param>
        /// <param name="diagramIO">Saves diagrams</param>
        /// <param name="compiler">Compiles diagrams</param>
        /// <param name="autoSaveTimer">Determines how soon after a change a diagram will be autosaved</param>
        /// <param name="refreshTimer">Determines how long after the last code modification was made to automatically refresh a diagram's image</param>
        /// <param name="uiScheduler">A task scheduler for executing UI tasks</param>
        public DiagramEditorViewModel(Diagram diagram, ICodeEditor codeEditor, INotifications notifications,
                                      IIndex <ImageFormat, IDiagramRenderer> diagramRenderers, IDiagramIOService diagramIO, IDiagramCompiler compiler,
                                      ITimer autoSaveTimer, ITimer refreshTimer, TaskScheduler uiScheduler)
        {
            _diagram = Property.New(this, p => p.Diagram, OnPropertyChanged);
            Diagram  = diagram;

            _notifications    = notifications;
            _diagramRenderers = diagramRenderers;
            _diagramIO        = diagramIO;
            _compiler         = compiler;
            _autoSaveTimer    = autoSaveTimer;
            _refreshTimer     = refreshTimer;
            _uiScheduler      = uiScheduler;

            CodeEditor                  = codeEditor;
            CodeEditor.Content          = Diagram.Content;
            CodeEditor.PropertyChanged += codeEditor_PropertyChanged;                   // Subscribe after setting the content the first time.

            _imageFormat = Property.New(this, p => p.ImageFormat, OnPropertyChanged);
            ImageFormat  = Diagram.ImageFormat;

            _diagramImage = Property.New(this, p => p.DiagramImage, OnPropertyChanged);

            _isIdle = Property.New(this, p => p.IsIdle, OnPropertyChanged)
                      .AlsoChanges(p => p.CanSave)
                      .AlsoChanges(p => p.CanRefresh)
                      .AlsoChanges(p => p.CanClose);
            IsIdle = true;

            _autoSave         = Property.New(this, p => p.AutoSave, OnPropertyChanged);
            _autoSaveInterval = Property.New(this, p => p.AutoSaveInterval, OnPropertyChanged);

            _saveCommand    = Command.For(this).DependsOn(p => p.CanSave).Asynchronously().Executes(SaveAsync);
            _refreshCommand = Command.For(this).DependsOn(p => p.CanRefresh).Asynchronously().Executes(RefreshAsync);
            _closeCommand   = Command.For(this).DependsOn(p => p.CanClose).Executes(Close);

            // The document has been opened first time. So, any changes
            // made to the document will require creating a backup.
            _firstSaveAfterOpen = true;

            _autoSaveTimer.Elapsed += autoSaveTimerElapsed;
            _refreshTimer.Elapsed  += refreshTimer_Elapsed;
        }
Пример #16
0
        private async Task GoToDefinition(ICodeEditor editor)
        {
            var definition = await editor.LanguageService?.GotoDefinition(1);

            var studio = IoC.Get <IStudio>();

            if (definition.MetaDataFile == null)
            {
                var document = studio.CurrentSolution.FindFile(definition.FileName);

                if (document != null)
                {
                    await studio.OpenDocumentAsync(document, definition.Line, definition.Column, definition.Column, selectLine : true, focus : true);
                }
            }
            else
            {
                await studio.OpenDocumentAsync(definition.MetaDataFile, definition.Line, definition.Column, definition.Column, selectLine : true, focus : true);
            }
        }
Пример #17
0
        private string GetWrapWithAbbreviationScript(ICodeEditor view)
        {
            string syntax       = ContentTypeToSyntax(view.GetContentTypeInActiveBuffer());
            string selection    = JavaScriptEscape(view.GetSelection());
            string abbreviation = view.Prompt();

            if (string.IsNullOrWhiteSpace(selection) || string.IsNullOrWhiteSpace(abbreviation))
            {
                Trace("Cannot wrap empty string.");
                return(null);
            }

            return(string.Format(
                       ScriptTemplate,
                       abbreviation,
                       abbreviation.Length,
                       syntax,
                       "'" + selection + "'",
                       string.Empty));
        }
Пример #18
0
        /// <summary>
        /// Load a file and set text of json editor
        /// </summary>
        /// <param name="editor"></param>
        public static void LoadFile(this ICodeEditor editor, string filter, string lastFile)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            if (!string.IsNullOrWhiteSpace(editor.CurrentFileName))
            {
                openFileDialog.InitialDirectory = Path.GetDirectoryName(editor.CurrentFileName);
            }
            else if (!string.IsNullOrWhiteSpace(lastFile))
            {
                openFileDialog.InitialDirectory = Path.GetDirectoryName(lastFile);
            }

            openFileDialog.Filter = filter;

            if (openFileDialog.ShowDialog() == true)
            {
                editor.LoadFile(openFileDialog.FileName);
            }

            return;
        }
        /// <summary>
        /// Initializes a new diagram editor.
        /// </summary>
        /// <param name="diagram">The diagram being edited</param>
        /// <param name="codeEditor">The code editor</param>
        /// <param name="notifications">Creates objects that report progress</param>
        /// <param name="diagramRenderers">Responsible for converting diagram data to images</param>
        /// <param name="diagramIO">Saves diagrams</param>
        /// <param name="compiler">Compiles diagrams</param>
        /// <param name="autoSaveTimer">Determines how soon after a change a diagram will be autosaved</param>
        /// <param name="refreshTimer">Determines how long after the last code modification was made to automatically refresh a diagram's image</param>
        /// <param name="uiScheduler">A task scheduler for executing UI tasks</param>
        public DiagramEditorViewModel(Diagram diagram,
                                      ICodeEditor codeEditor,
                                      INotifications notifications,
                                      IReadOnlyDictionary <ImageFormat, IDiagramRenderer> diagramRenderers,
                                      IDiagramIOService diagramIO,
                                      IDiagramCompiler compiler,
                                      ITimer autoSaveTimer,
                                      ITimer refreshTimer,
                                      TaskScheduler uiScheduler) : this()
        {
            Diagram = diagram;

            _notifications    = notifications;
            _diagramRenderers = diagramRenderers;
            _diagramIO        = diagramIO;
            _compiler         = compiler;
            _autoSaveTimer    = autoSaveTimer;
            _refreshTimer     = refreshTimer;
            _uiScheduler      = uiScheduler;

            CodeEditor                  = codeEditor;
            CodeEditor.Content          = Diagram.Content;
            CodeEditor.PropertyChanged += codeEditor_PropertyChanged;                   // Subscribe after setting the content the first time.

            ImageFormat = Diagram.ImageFormat;

            IsIdle = true;
            Errors = new List <DiagramErrorViewModel>(0);

            // The document has been opened first time. So, any changes
            // made to the document will require creating a backup.
            _firstSaveAfterOpen = true;

            _autoSaveTimer.Elapsed += AutoSaveTimerElapsed;
            _refreshTimer.Elapsed  += RefreshTimerElapsed;
        }
Пример #20
0
        public IIDE NewIDE(IVirtualMachine machine, ICodeEditor codeEditor
                           , IInputPort inputPort   = null, int withInputPortIndex  = -1
                           , IOutputPort outputPort = null, int withOutputPortIndex = -1
                           , bool withConsole       = false)
        {
            if (!IsInitialized)
            {
                throw new InvalidOperationException();
            }

            (codeEditor as Form).MdiParent = MainForm as Form;
            IIDE newIde = new IDE(machine, codeEditor);

            newIde.ParentWorkplace    = this;
            newIde.ShowingMessage    += MainSymbolService.ShowMessage;
            newIde.AskingUser        += MainSymbolService.AskUser;
            newIde.OpeningFileByUser += MainSymbolService.OpenFileByUser;
            newIde.SavingFileByUser  += MainSymbolService.SaveFileByUser;

            if (inputPort != null && withInputPortIndex >= -1)
            {
                newIde.MachineInsertInputPort(withInputPortIndex, inputPort);
            }
            if (outputPort != null && withOutputPortIndex >= -1)
            {
                newIde.MachineInsertOutputPort(withOutputPortIndex, outputPort);
            }

            if (withConsole && (inputPort != null || outputPort != null))
            {
                IInputDevice  newConsoleAsInputDevice;
                IOutputDevice newConsoleAsOutputDevice = null;
                if (inputPort != null)
                {
                    InputDeviceTypeInfo consoleDeviceTypeInfo =
                        InputDeviceBuilder.RegisteredTypes.Find(i => i.TypeFullName == typeof(ConsoleDevice).FullName);
                    if (consoleDeviceTypeInfo != null)
                    {
                        NewInputDevice(consoleDeviceTypeInfo, out newConsoleAsInputDevice);
                        newConsoleAsOutputDevice = newConsoleAsInputDevice as IOutputDevice;
                        newIde.MachineSetInputDevice(inputPort, newConsoleAsInputDevice);
                    }
                }
                if (outputPort != null)
                {
                    if (newConsoleAsOutputDevice != null)
                    {
                        newIde.MachineSetOutputDevice(outputPort, newConsoleAsOutputDevice);
                    }
                    else
                    {
                        OutputDeviceTypeInfo consoleDeviceTypeInfo =
                            OutputDeviceBuilder.RegisteredTypes.Find(i => i.TypeFullName == typeof(ConsoleDevice).FullName);
                        if (consoleDeviceTypeInfo != null)
                        {
                            NewOutputDevice(consoleDeviceTypeInfo, out newConsoleAsOutputDevice);
                            newIde.MachineSetOutputDevice(outputPort, newConsoleAsOutputDevice);
                        }
                    }
                }
            }

            newIde.Machine.Id         = MachinesIdCounter++;
            newIde.Machine.CustomName = newIde.Machine.ToString();

            newIde.Id = IdeIdCounter++;
            newIde.ProgramFile.ShortFileName = GetNewProgramFileShortName(newIde);
            newIde.Title = GetNewIDEtitle(newIde);
            newIde.ConfigFile.ShortFileName = newIde.Title;

            IDEs.Add(newIde);
            OnGotUpdated();

            return(newIde);
        }
Пример #21
0
 public CodeEditorContext(EditCodeVM vm, ICodeEditor codeEditor)
 {
     VM         = vm;
     CodeEditor = codeEditor;
 }
Пример #22
0
 public RoslynCodeDocument(ICodeEditor codeEditor, DocumentInfo documentInfo, string nameNoExtension)
 {
     this.codeEditor = codeEditor;
     Info            = documentInfo;
     NameNoExtension = nameNoExtension;
 }
Пример #23
0
 /*************************************************************************/
 public JsonCodeCompletion(ICodeEditor winEditor)
 {
     _winEditor = winEditor;
 }
Пример #24
0
		public RoslynCodeDocument(ICodeEditor codeEditor, DocumentInfo documentInfo, string nameNoExtension) {
			this.codeEditor = codeEditor;
			Info = documentInfo;
			NameNoExtension = nameNoExtension;
		}
Пример #25
0
 public RoslynCodeDocument(ICodeEditor codeEditor, DocumentInfo documentInfo)
 {
     this.codeEditor = codeEditor;
     Info            = documentInfo;
 }
 private string GetSelection(ICodeEditor editor)
 {
     return(editor?.CurrentSelection);
 }
Пример #27
0
 /*************************************************************************/
 public JTranCodeCompletion(ICodeEditor winEditor) : base(winEditor)
 {
 }