@@ -12,6 +12,7 @@ import {
1212 unstack ,
1313 listenProperty ,
1414} from "./util.js" ;
15+ import { once } from "../troll/src/util.js" ;
1516
1617import {
1718 setup as setupBlueprint ,
@@ -53,13 +54,15 @@ export default function PanelUI({
5354 // flat does nothing on GtkDropdown or GtkComboBox or GtkComboBoxText
5455 dropdown_ui_lang . get_first_child ( ) . get_style_context ( ) . add_class ( "flat" ) ;
5556
56- const { compile, decompile } = setupBlueprint ( { data_dir } ) ;
57+ const blueprint = setupBlueprint ( {
58+ data_dir,
59+ } ) ;
5760
5861 async function convertToXML ( ) {
5962 term_console . clear ( ) ;
6063 settings . set_boolean ( "show-console" , true ) ;
6164
62- const xml = await compile ( ) ;
65+ const xml = await blueprint . compile ( buffer_blueprint . text ) ;
6366 replaceBufferText ( buffer_xml , xml ) ;
6467 }
6568
@@ -70,7 +73,7 @@ export default function PanelUI({
7073 let blp ;
7174
7275 try {
73- blp = await decompile ( buffer_xml . text ) ;
76+ blp = await blueprint . decompile ( buffer_xml . text ) ;
7477 } catch ( err ) {
7578 if ( err instanceof LSPError ) {
7679 logBlueprintError ( err ) ;
@@ -101,35 +104,65 @@ export default function PanelUI({
101104 ) ;
102105 } ) ;
103106
104- let handler_ids = null ;
107+ let handler_ids_xml = null ;
108+ let handler_ids_blueprint = null ;
109+ let handler_id_lsp = null ;
105110
106- const scheduleUpdate = unstack ( update ) ;
111+ // FIXME we should wait for previewer update instead
112+ // when loading demo
107113 async function update ( ) {
108- let xml ;
109- if ( lang . id === "xml" ) {
110- xml = buffer_xml . text ;
111- } else {
112- xml = await compile ( ) ;
114+ if ( lang . id === "blueprint" ) {
115+ await blueprint . update ( buffer_blueprint . text ) ;
116+ await once (
117+ blueprint . lspc ,
118+ "notification::textDocument/x-blueprintcompiler/publishCompiled" ,
119+ ) ;
120+ } else if ( lang . id === "xml" ) {
121+ onXML ( buffer_xml . text ) ;
113122 }
123+ }
124+
125+ function onXML ( xml ) {
114126 panel . xml = xml || "" ;
115127 panel . emit ( "updated" ) ;
116128 }
117129
130+ const onBlueprint = unstack ( function onBlueprint ( ) {
131+ return blueprint . update ( buffer_blueprint . text ) ;
132+ } ) ;
133+
118134 function start ( ) {
119135 stop ( ) ;
120136 lang = getLanguage ( dropdown_ui_lang . selected_item . string ) ;
121137 // cannot use "changed" signal as it triggers many time for pasting
122- handler_ids = connect_signals ( lang . document . buffer , {
123- "end-user-action" : scheduleUpdate ,
124- undo : scheduleUpdate ,
125- redo : scheduleUpdate ,
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 ) ,
126142 } ) ;
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 (
149+ "notification::textDocument/x-blueprintcompiler/publishCompiled" ,
150+ ( _self , { xml } ) => onXML ( xml ) ,
151+ ) ;
127152 }
128153
129154 function stop ( ) {
130- if ( handler_ids !== null ) {
131- disconnect_signals ( lang . document . buffer , handler_ids ) ;
132- handler_ids = null ;
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 ;
162+ }
163+ if ( handler_id_lsp !== null ) {
164+ blueprint . lspc . disconnect ( handler_id_lsp ) ;
165+ handler_id_lsp = null ;
133166 }
134167 }
135168
0 commit comments