Replace the regular TextView with GtkSourceView for syntax highlighting.
(self)
| 1819 | self.is_loading = False |
| 1820 | |
| 1821 | def _replace_textview_with_sourceview(self): |
| 1822 | """Replace the regular TextView with GtkSourceView for syntax highlighting.""" |
| 1823 | if not self.raw_text_view: |
| 1824 | return |
| 1825 | |
| 1826 | try: |
| 1827 | parent = self.raw_text_view.get_parent() |
| 1828 | if not parent: |
| 1829 | return |
| 1830 | |
| 1831 | source_view = GtkSource.View() |
| 1832 | |
| 1833 | source_view.set_monospace(True) |
| 1834 | source_view.set_wrap_mode(Gtk.WrapMode.NONE) |
| 1835 | source_view.set_editable(True) |
| 1836 | source_view.set_hexpand(True) |
| 1837 | source_view.set_vexpand(True) |
| 1838 | source_view.set_left_margin(8) |
| 1839 | source_view.set_right_margin(8) |
| 1840 | source_view.set_top_margin(6) |
| 1841 | source_view.set_bottom_margin(6) |
| 1842 | |
| 1843 | source_view.get_style_context().add_class("raw-editor") |
| 1844 | |
| 1845 | source_view.set_show_line_numbers(True) |
| 1846 | source_view.set_highlight_current_line(True) |
| 1847 | source_view.set_auto_indent(True) |
| 1848 | source_view.set_indent_on_tab(True) |
| 1849 | source_view.set_tab_width(4) |
| 1850 | source_view.set_insert_spaces_instead_of_tabs(True) |
| 1851 | |
| 1852 | parent.set_child(None) |
| 1853 | parent.set_child(source_view) |
| 1854 | |
| 1855 | self.raw_text_view = source_view |
| 1856 | |
| 1857 | except Exception as e: |
| 1858 | print(f"Warning: Could not replace TextView with GtkSourceView: {e}") |
| 1859 | pass |
| 1860 | |
| 1861 | def _show_helpful_placeholder(self): |
| 1862 | """Show helpful placeholder text when the raw editor is empty or invalid.""" |