@@ -3,15 +3,7 @@ import GObject from "gi://GObject";
33import Gtk from "gi://Gtk" ;
44
55import { LSPError } from "./lsp/LSP.js" ;
6- import {
7- getLanguage ,
8- settings ,
9- connect_signals ,
10- disconnect_signals ,
11- replaceBufferText ,
12- unstack ,
13- listenProperty ,
14- } from "./util.js" ;
6+ import { getLanguage , settings , unstack , listenProperty } from "./util.js" ;
157import { once } from "../troll/src/util.js" ;
168
179import {
@@ -26,16 +18,21 @@ export default function PanelUI({
2618 builder,
2719 data_dir,
2820 term_console,
21+ document_xml,
22+ document_blueprint,
2923} ) {
3024 let lang ;
3125
26+ const code_view_xml = document_xml . code_view ;
27+ const code_view_blueprint = document_blueprint . code_view ;
28+
3229 const panel = {
3330 xml : "" ,
3431 } ;
3532 addSignalMethods ( panel ) ;
3633
37- const buffer_blueprint = getLanguage ( "blueprint" ) . document . buffer ;
38- const buffer_xml = getLanguage ( "xml" ) . document . buffer ;
34+ const buffer_blueprint = code_view_blueprint . buffer ;
35+ const buffer_xml = code_view_xml . buffer ;
3936
4037 const button_ui = builder . get_object ( "button_ui" ) ;
4138 const panel_ui = builder . get_object ( "panel_ui" ) ;
@@ -56,14 +53,15 @@ export default function PanelUI({
5653
5754 const blueprint = setupBlueprint ( {
5855 data_dir,
56+ document : document_blueprint ,
5957 } ) ;
6058
6159 async function convertToXML ( ) {
6260 term_console . clear ( ) ;
6361 settings . set_boolean ( "show-console" , true ) ;
6462
6563 const xml = await blueprint . compile ( buffer_blueprint . text ) ;
66- replaceBufferText ( buffer_xml , xml ) ;
64+ code_view_xml . replaceText ( xml ) ;
6765 }
6866
6967 async function convertToBlueprint ( ) {
@@ -82,7 +80,7 @@ export default function PanelUI({
8280 throw err ;
8381 }
8482
85- replaceBufferText ( buffer_blueprint , blp ) ;
83+ code_view_blueprint . replaceText ( blp ) ;
8684 }
8785
8886 const button_ui_experimental_blueprint = builder . get_object (
@@ -104,9 +102,8 @@ export default function PanelUI({
104102 ) ;
105103 } ) ;
106104
107- let handler_ids_xml = null ;
108- let handler_ids_blueprint = null ;
109- let handler_id_lsp = null ;
105+ let handler_id_xml = null ;
106+ let handler_id_blueprint = null ;
110107
111108 // FIXME we should wait for previewer update instead
112109 // when loading demo
@@ -134,35 +131,25 @@ export default function PanelUI({
134131 function start ( ) {
135132 stop ( ) ;
136133 lang = getLanguage ( dropdown_ui_lang . selected_item . string ) ;
137- // cannot use "changed" signal as it triggers many time for pasting
138- handler_ids_xml = connect_signals ( buffer_xml , {
139- "end-user-action" : ( ) => onXML ( buffer_xml . text ) ,
140- undo : ( ) => onXML ( buffer_xml . text ) ,
141- redo : ( ) => onXML ( buffer_xml . text ) ,
142- } ) ;
143- handler_ids_blueprint = connect_signals ( buffer_blueprint , {
144- "end-user-action" : onBlueprint ,
145- undo : onBlueprint ,
146- redo : onBlueprint ,
147- } ) ;
148- handler_id_lsp = blueprint . lspc . connect (
134+ handler_id_xml = code_view_xml . connect (
135+ "changed" ,
136+ ( ) => code_view_xml . buffer . text ,
137+ ) ;
138+ handler_id_blueprint = code_view_blueprint . connect ( "changed" , onBlueprint ) ;
139+ blueprint . lspc . connect (
149140 "notification::textDocument/x-blueprintcompiler/publishCompiled" ,
150141 ( _self , { xml } ) => onXML ( xml ) ,
151142 ) ;
152143 }
153144
154145 function stop ( ) {
155- if ( handler_ids_xml !== null ) {
156- disconnect_signals ( buffer_xml , handler_ids_xml ) ;
157- handler_ids_xml = null ;
158- }
159- if ( handler_ids_blueprint !== null ) {
160- disconnect_signals ( buffer_blueprint , handler_ids_blueprint ) ;
161- handler_ids_blueprint = null ;
146+ if ( handler_id_xml !== null ) {
147+ code_view_xml . disconnect ( handler_id_xml ) ;
148+ handler_id_xml = null ;
162149 }
163- if ( handler_id_lsp !== null ) {
164- blueprint . lspc . disconnect ( handler_id_lsp ) ;
165- handler_id_lsp = null ;
150+ if ( handler_id_blueprint !== null ) {
151+ code_view_blueprint . disconnect ( handler_id_blueprint ) ;
152+ handler_id_blueprint = null ;
166153 }
167154 }
168155
0 commit comments