Esempio n. 1
0
        public EditorContext()
        {
            Postbox = Postbox.InstanceFor(EditorCode);
            Configuration.ConfigManager.AddEditorConfig(EditorCode, new Configuration.Config {
                Language       = SupportedLanguages.JS,
                FormattingType = FormattingType.BRACKETS
            });

            TextsToEnter      = new List <string>();
            CaretView         = new CaretView();
            TextView          = new TextView(CaretView);
            SelectionView     = new SelectionView(TextView);
            LinesView         = new LinesView();
            FoldingView       = new FoldingView();
            EnterTextCommand  = new EnterTextCommand(TextView, CaretView, SelectionView);
            RemoveTextCommand = new RemoveTextCommand(TextView, CaretView, SelectionView);
            CaretMoveCommand  = new CaretMoveCommand(CaretView, TextView);
            SelectionCommand  = new TextSelectionCommand(TextView, SelectionView, CaretView);

            CaretView.EditorCode     = EditorCode;
            CaretView.Postbox        = Postbox;
            TextView.EditorCode      = EditorCode;
            TextView.Postbox         = Postbox;
            SelectionView.EditorCode = EditorCode;
            SelectionView.Postbox    = Postbox;
            LinesView.EditorCode     = EditorCode;
            LinesView.Postbox        = Postbox;
            FoldingView.EditorCode   = EditorCode;
            FoldingView.Postbox      = Postbox;

            InitEvents();
            ForceDraw();
        }
        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            var caretMoveCmd = new CaretMoveCommand(caretView, textView);

            if (caretMoveCmd.CanExecute(e))
            {
                caretMoveCmd.Execute(e);
            }

            selectionView.HandleMouseDown(e);
            textView.HandleMouseDown(e);
        }
        protected override void OnKeyDown(KeyEventArgs e)
        {
            var removeTextCmd  = new RemoveTextCommand(textView, caretView, selectionView);
            var caretMoveCmd   = new CaretMoveCommand(caretView, textView);
            var selectionCmd   = new TextSelectionCommand(textView, selectionView, caretView);
            var deselectionCmd = new TextDeselectionCommand(selectionView);

            if (removeTextCmd.CanExecute(e))
            {
                ExecuteTextCommand(removeTextCmd, new UndoRemoveTextCommand(textView, caretView), e);
                deselectionCmd.Execute();
            }
            else if (caretMoveCmd.CanExecute(e))
            {
                caretMoveCmd.Execute(e);
                deselectionCmd.Execute();
            }
            else if (selectionCmd.CanExecute(e))
            {
                selectionCmd.Execute(e);
            }
        }