package io.github.vcuswimlab.stackintheflow.view;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class SearchToolWindowFactory implements ToolWindowFactory {

    private JButton searchButton;
    private JTextField searchBox;
    private JPanel content;
    private JList list1;
    private ToolWindow toolWindow;

    public SearchToolWindowFactory() {
        searchButton.addActionListener(e -> executeQuery(searchBox.getText()));
        searchBox.addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                super.keyPressed(e);
                if(e.getKeyCode() == KeyEvent.VK_ENTER) {
                    searchButton.doClick();
                }
            }
        });
    }

    @Override
    public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
        this.toolWindow = toolWindow;
        ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
        Content windowContent = contentFactory.createContent(content, "", false);
        toolWindow.getContentManager().addContent(windowContent);
    }

    //Stub method to be fleshed out
    private void executeQuery(String query) {
        Messages.showMessageDialog("Query: " + query, "Query", null);
    }
}

@@ -44,16 +44,215 @@
 .view;%0A%0A
+import com.intellij.ide.browsers.BrowserLauncher;%0Aimport com.intellij.ide.browsers.WebBrowser;%0Aimport com.intellij.ide.browsers.WebBrowserManager;%0Aimport com.intellij.ide.browsers.WebBrowserService;%0A
 import c
@@ -1836,16 +1836,238 @@
  null);%0A
+        openBrowser(query);%0A    %7D%0A%0A    //Stub method to be fleshed out%0A    private void openBrowser(String url) %7B%0A        BrowserLauncher.getInstance().browse(url, WebBrowserManager.getInstance().getFirstActiveBrowser());%0A
     %7D%0A%7D%0A

Add stub method for opening browser.