コード例 #1
0
        public InputHandler(Editor owner, CSharpSourceEditorControl editorControl, CompletionWindow completionWindow, MethodOverloadList overloadList, CompletionService completionService)
        {
            OwnerEditor   = owner;
            EditorControl = editorControl;
            EditorControl.OnTextEntered   = OnTextEntered;
            EditorControl.OnTextEntering  = OnTextEntering;
            EditorControl.PointerPressed += OnPointerPressed;
            EditorControl.TextChanged    += OnDocumentChanged;

            EditorControl.LostFocus += (s, e) =>
            {
                if (MethodOverloadList.IsVisible)
                {
                    MethodOverloadList.IsVisible = false;
                }

                if (CompletionWindow.IsVisible)
                {
                    CompletionWindow.IsVisible = false;
                }
            };

            EditorControl.OnPreviewKeyDown = OnPreviewKeyDown;
            EditorControl.OnPreviewKeyUp   = OnPreviewKeyUp;

            EditorControl.PointerHover        += OnPointerHover;
            EditorControl.PointerHoverStopped += OnPointerHoverStopped;

            EditorControl.OnPaste += OnPaste;

            EditorControl.OnPreviewPointerWheelChanged += OnWheelChanged;

            CompletionWindow   = completionWindow;
            MethodOverloadList = overloadList;
            CompletionService  = completionService;
        }
コード例 #2
0
        private async Task Initialize(string sourceText, string preSource, string postSource, IEnumerable <CachedMetadataReference> references, CSharpCompilationOptions compilationOptions, string guid, Shortcut[] additionalShortcuts)
        {
            this.CompilationOptions = compilationOptions;
            this.Guid = guid;

            EditorControl = this.FindControl <CSharpSourceEditorControl>("EditorControl");

            await EditorControl.SetText(sourceText);

            this.PreSource  = preSource;
            this.PostSource = postSource;

            OriginalText      = EditorControl.Text.ToString();
            OriginalDocument  = EditorControl.Document;
            LastSavedText     = OriginalText;
            OriginalTimeStamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
            CompletionService service = CompletionService.GetService(OriginalDocument);

            this.FindControl <CompletionWindow>("CompletionWindow").Document          = OriginalDocument;
            this.FindControl <CompletionWindow>("CompletionWindow").CompletionService = service;

            this.CompletionWindow   = this.FindControl <CompletionWindow>("CompletionWindow");
            this.MethodOverloadList = this.FindControl <MethodOverloadList>("MethodOverloadList");

            this.FindControl <MethodOverloadList>("MethodOverloadList").Document = OriginalDocument;

            this.FindControl <CompletionWindow>("CompletionWindow").Committed += CompletionCommitted;

            StatusBar = this.FindControl <StatusBar>("StatusBar");

            ErrorContainer       = this.FindControl <ErrorContainer>("ErrorContainer");
            ReferencesContainer  = this.FindControl <ReferencesContainer>("ReferencesContainer");
            SaveHistoryContainer = this.FindControl <SaveHistoryContainer>("SaveHistoryContainer");
            SettingsContainer    = new SettingsContainer(additionalShortcuts)
            {
                Margin = new Thickness(10, 0, 0, 10), IsVisible = false
            };
            Grid.SetRow(SettingsContainer, 2);
            this.FindControl <Grid>("ContainerGrid").Children.Add(SettingsContainer);



            await this.SetReferences(ImmutableList.Create((from el in references select(MetadataReference) el).ToArray()));

            EditorControl.ClearUndoStack();

            this.CompilationErrorChecker = CompilationErrorChecker.Attach(this);

            this.SymbolToolTip            = this.FindControl <SymbolToolTip>("SymbolToolTip");
            this.SymbolToolTip.References = References;

            this.BreakpointPanel = this.FindControl <BreakpointPanel>("BreakpointPanel");

            string autosaveDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Assembly.GetEntryAssembly().GetName().Name);

            Directory.CreateDirectory(Path.Combine(autosaveDirectory, Guid));
            AutoSaveFile   = Path.Combine(autosaveDirectory, Guid, "autosave_" + System.Guid.NewGuid().ToString("N") + ".cs");
            SaveDirectory  = Path.Combine(autosaveDirectory, Guid);
            this.AutoSaver = AutoSaver.Start(this, AutoSaveFile);

            InputHandler = new InputHandler(this, EditorControl, this.FindControl <CompletionWindow>("CompletionWindow"), this.FindControl <MethodOverloadList>("MethodOverloadList"), service);
            EditorControl.ToggleBreakpoint += async(s, e) =>
            {
                await this.TryToggleBreakpoint(e.LineStart, e.LineEnd);
            };
        }