@@ -63,75 +63,78 @@ class BamlToolWindowFactory : ToolWindowFactory {
6363 loadHTML(PLACEHOLDER_HTML .trimIndent())
6464 }
6565
66- // Create reload button
67- val reloadButton = JButton (" Reload" ).apply {
68- addActionListener {
69- val currentTime = java.time.LocalDateTime .now()
70- val savedPort = project.getService(BamlGetPortService ::class .java).port
71- System .out .println (" reload button clicked at ${currentTime} , port is ${savedPort} " )
72- if (savedPort != null ) {
73- browser.loadURL(" http://localhost:$savedPort /" )
74- } else {
75- browser.loadHTML(" <p>Port not ready</p>" )
66+ // Create control panel with conditional debug buttons
67+ val controlPanel = JPanel (FlowLayout (FlowLayout .RIGHT ))
68+
69+ if (BamlIdeConfig .isDebugMode) {
70+ // Create reload button
71+ val reloadButton = JButton (" Reload" ).apply {
72+ addActionListener {
73+ val currentTime = java.time.LocalDateTime .now()
74+ val savedPort = project.getService(BamlGetPortService ::class .java).port
75+ System .out .println (" reload button clicked at ${currentTime} , port is ${savedPort} " )
76+ if (savedPort != null ) {
77+ browser.loadURL(BamlIdeConfig .getPlaygroundUrl(savedPort))
78+ } else {
79+ browser.loadHTML(" <p>Port not ready</p>" )
80+ }
81+ System .out .println (" finished loading" )
7682 }
77- System .out .println (" finished loading" )
7883 }
79- }
8084
81- // Create lorem ipsum button
82- val loremButton = JButton (" Lorem Ipsum" ).apply {
83- addActionListener {
84- val currentTime = java.time.LocalDateTime .now()
85- System .out .println (" lorem button clicked at ${currentTime} " )
86- browser.loadHTML("""
87- <!DOCTYPE html>
88- <html>
89- <head><title>Lorem Ipsum</title></head>
90- <body style="font-family: Arial, sans-serif; padding: 20px; color: white;">
91- <h1>Lorem Ipsum</h1>
92- <p><strong>Generated at:</strong> $currentTime </p>
93- <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
94- </body>
95- </html>
96- """ .trimIndent())
85+ // Create lorem ipsum button
86+ val loremButton = JButton (" Lorem Ipsum" ).apply {
87+ addActionListener {
88+ val currentTime = java.time.LocalDateTime .now()
89+ System .out .println (" lorem button clicked at ${currentTime} " )
90+ browser.loadHTML("""
91+ <!DOCTYPE html>
92+ <html>
93+ <head><title>Lorem Ipsum</title></head>
94+ <body style="font-family: Arial, sans-serif; padding: 20px; color: white;">
95+ <h1>Lorem Ipsum</h1>
96+ <p><strong>Generated at:</strong> $currentTime </p>
97+ <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
98+ </body>
99+ </html>
100+ """ .trimIndent())
101+ }
97102 }
98- }
99103
100- val openDevToolsButton = JButton (" Open DevTools" ).apply {
101- addActionListener {
102- browser.openDevtools()
104+ val openDevToolsButton = JButton (" Open DevTools" ).apply {
105+ addActionListener {
106+ browser.openDevtools()
107+ }
103108 }
104- }
105- // Create control panel with buttons
106- val controlPanel = JPanel (FlowLayout (FlowLayout .RIGHT )).apply {
107- add(reloadButton)
108- add(loremButton)
109- add(openDevToolsButton)
109+
110+ controlPanel.add(reloadButton)
111+ controlPanel.add(loremButton)
112+ controlPanel.add(openDevToolsButton)
110113 }
111114
112115 // Create main panel with controls and browser
113116 val mainPanel = JPanel (BorderLayout ()).apply {
114- add(controlPanel, BorderLayout .NORTH )
117+ if (BamlIdeConfig .isDebugMode) {
118+ add(controlPanel, BorderLayout .NORTH )
119+ }
115120 add(browser.component, BorderLayout .CENTER )
116121 }
117122
118123 // Create content with the main panel
119124 val content = ContentFactory .getInstance().createContent(mainPanel, null , false )
120125 toolWindow.contentManager.addContent(content)
121126
122- System .out .println (" sam asking BamlToolWindowFactory about startup" );
123-
124127 val savedPort = project.getService(BamlGetPortService ::class .java).port
125128 if (savedPort != null ) {
126129 // LS was up before the tool-window opened
127- browser.loadURL(" http://localhost: $ savedPort/ " )
130+ browser.loadURL(BamlIdeConfig .getPlaygroundUrl( savedPort) )
128131 } else {
129132 // LS not ready yet wait for a port message
130133 val busConnection = project.messageBus.connect(toolWindow.disposable)
131134 busConnection.subscribe(
132135 BamlGetPortService .TOPIC ,
133136 BamlGetPortService .Listener { port ->
134- browser.loadURL(" http://localhost: $ port/ " )
137+ browser.loadURL(BamlIdeConfig .getPlaygroundUrl( port) )
135138 busConnection.disconnect() // one-shot, avoid duplicates
136139 }
137140 )
0 commit comments