Esempio n. 1
0
        public void CodeBox_TextArea_KeyDown(object sender, TextCompositionEventArgs e)
        {
            char got = e == null ? '\x08' : e.Text[0];

            AutoCompleteSpecialChars(got);
            if (got == '\x08')
            {
                DeleteSpecialChars();
            }

            if ((got == '\x08' && string.IsNullOrEmpty(got.ToString())) ||
                (!char.IsLetterOrDigit(got) && got != '\x08'))
            {
                completionWindow?.Close();
                return;
            }

            TextEditor   textEditor   = _lastFocusedTextEditor;
            TextLocation textLocation = textEditor.Document.GetLocation(
                textEditor.CaretOffset);
            Position position = new Position(textLocation.Line - 1, textLocation.Column - 1);
            string   file     = _currentTabHandler._file;
            string   path     = string.IsNullOrEmpty(file) ? _currentTabHandler.playground : "file://" + file;

            LspSender.RequestKeywords(position, path);
            AutoComplete(_lastFocusedTextEditor);
        }
Esempio n. 2
0
        private void DebugCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            TextEditor   ed       = _lastFocusedTextEditor;
            TextLocation location = ed.Document.GetLocation(ed.CaretOffset);

            LspSender.RequestDefinition(new Position(location.Line - 1, location.Column - 1),
                                        _currentTabHandler._file == null
                    ? _currentTabHandler.playground
                    : "file://" + _currentTabHandler._file);
        }
Esempio n. 3
0
 // Function in order to unregister previous instances (used for closing a tab)
 private void UnregisterNamesAndRemove(bool saved = true)
 {
     if (saved)
     {
         UnregisterName("Tab" + _currenttabId);
         UnregisterName("CodeBox" + _currenttabId);
         UnregisterName("python" + _currenttabId);
         UnregisterName("STD" + _currenttabId);
         LspSender.DidCloseNotification(_currentTabHandler._file == null ? _currentTabHandler.playground :
                                        "file://" + _currentTabHandler._file);
         ((TabablzControl)FindName("TabControl")).Items.RemoveAt(
             _currentTab);
         TabControl.SelectedIndex =
             ((TabablzControl)FindName("TabControl")).Items.Count - 1;
     }
 }
Esempio n. 4
0
        public void SendChanges(string currentUri)
        {
            double currentTime = GetTimeStamp();

            if (currentTime - lastTypedTime > 400)
            {
                Dispatcher.Invoke(() =>
                {
                    if (_currentTabHandler._file != null)
                    {
                        Save_Click();
                    }

                    while (documentsList[currentUri].Count > 1)
                    {
                        documentsList[currentUri].Dequeue();
                    }
                    LspSender.DidChangeNotification(
                        new VersionedTextDocumentIdentifier(++version, currentUri),
                        documentsList[currentUri]);
                });
            }
        }
Esempio n. 5
0
        private void NewTabItems(int n, string path)
        {
            StringReader stringReader =
                new StringReader(tabitem.Replace("_id_", n.ToString()));
            XmlReader xmlReader     = XmlReader.Create(stringReader);
            TabItem   newTabControl = (TabItem)XamlReader.Load(xmlReader);

            RegisterName("Tab" + n, newTabControl);
            ((TabablzControl)FindName("TabControl"))?.Items.Add(newTabControl);
            RegisterName("CodeBox" + n,
                         (TextEditor)((Grid)((TabItem)FindName("Tab" + n)).FindName(
                                          "grid_codebox")).Children[0]);
            RegisterName("python" + n,
                         (TextEditor)((Grid)((TabItem)FindName("Tab" + n)).FindName(
                                          "python_grid")).Children[0]);
            RegisterName("STD" + n,
                         (TextEditor)((Grid)((TabItem)FindName("Tab" + n)).FindName(
                                          "python_grid")).Children[3]);
            TabHandling tabHandling = new TabHandling(path, path == null ? ++playgroundCount : playgroundCount);

            tabAttributes.Add(n.ToString(), tabHandling);
            ((TextEditor)((Grid)((TabItem)FindName("Tab" + n)).FindName(
                              "grid_codebox")).Children[0])
            .SyntaxHighlighting = _highlightingDefinition;
            ((TextEditor)((Grid)((TabItem)FindName("Tab" + n)).FindName(
                              "python_grid")).Children[0])
            .SyntaxHighlighting = _highlightingDefinition;


            TabControl.SelectedIndex =
                ((TabablzControl)FindName("TabControl")).Items.Count - 1;
            if (!tabAttributes.TryGetValue(_currenttabId, out _currentTabHandler))
            {
                return;
            }

            string uri;

            if (path != null)
            {
                uri = "file://" + path;
                Dispatcher.Invoke(() =>
                                  LspSender.DidOpenNotification(uri, "", 0, File.ReadAllText(path)));
                string s = File.ReadAllText(path);
                ((TextEditor)FindName("CodeBox" + n)).Text = s;
                ((TabItem)FindName("Tab" + n)).Header      =
                    Path.GetFileNameWithoutExtension(tabHandling._file);
                tabHandling._firstData      = s;
                tabHandling._isFileSelected = true;
                tabHandling._isSaved        = true;
            }
            else
            {
                uri = _currentTabHandler.playground;
                Dispatcher.Invoke(() =>
                                  LspSender.DidOpenNotification(uri, "",
                                                                0, ""));
                ((TabItem)FindName("Tab" + n)).Header =
                    Path.GetFileNameWithoutExtension(tabHandling.playground);
            }

            documentsList[uri] = new Queue <TextDocumentContentChangeEvent>();

            TextEditor CodeBox =
                ((TextEditor)((Grid)((TabItem)FindName($"Tab{n}")).FindName(
                                  "grid_codebox")).Children[0]);
            TextEditor PythonBox =
                ((TextEditor)((Grid)((TabItem)FindName("Tab" + n)).FindName(
                                  "python_grid")).Children[0]);
            TextEditor STD =
                (TextEditor)((Grid)((TabItem)FindName("Tab" + n)).FindName(
                                 "python_grid")).Children[3];

            // Events called in order to update attributes for research
            CodeBox.TextArea.GotFocus   += CodeBoxSetLastElement;
            PythonBox.TextArea.GotFocus += PythonBoxSetLastElement;

            // Events called in order to manage the CTRL + Scroll with mouse
            CodeBox.TextArea.MouseWheel   += OnMouseDownMain;
            PythonBox.TextArea.MouseWheel += OnMouseDownMain;
            // Events called on text typing for autocompletion
            CodeBox.TextArea.PreviewKeyDown += CodeBox_TextArea_TextEntering;
            CodeBox.TextArea.TextEntered    += CodeBox_TextArea_KeyDown;
            CodeBox.TextArea.TextEntered    += CodeBoxText;
            // Tooltips
            CodeBox.TextArea.MouseDoubleClick += MouseCaptured;
            // Events called on click
            BrushConverter converter   = new BrushConverter();
            Brush          brush       = (Brush)converter.ConvertFrom("#ffeac8");
            Brush          borderbrush = (Brush)converter.ConvertFrom("#ed9200");
            Pen            pen         = new Pen(borderbrush, 0);

            CodeBox.TextArea.SelectionBorder   = pen;
            CodeBox.TextArea.SelectionBrush    = brush;
            PythonBox.TextArea.SelectionBorder = pen;
            PythonBox.TextArea.SelectionBrush  = brush;
            STD.TextArea.SelectionBorder       = pen;
            STD.TextArea.SelectionBrush        = brush;
            _lastFocusedTextEditor             = ((TextEditor)FindName("CodeBox" + n));
        }