Improve mini browser and terminal.
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 23 Jan 2020 17:12:20 +0000 (18:12 +0100)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 23 Jan 2020 17:12:20 +0000 (18:12 +0100)
rcp/org.argeo.eclipse.ui.rcp/src/org/argeo/swt/desktop/MiniBrowser.java
rcp/org.argeo.eclipse.ui.rcp/src/org/argeo/swt/desktop/MiniTerminal.java

index 3152db1a9704fd97917053e27d6a0fc3c8e76b27..4b41207fc646a28178e4266c4bdd1e617ea77254 100644 (file)
@@ -48,18 +48,25 @@ public class MiniBrowser implements BiFunction<Composite, MiniBrowser.Context, C
        }
 
        public Control createBody(Composite parent, MiniBrowser.Context context) {
-               Browser browser = new Browser(parent, SWT.WEBKIT);
+               Browser browser = new Browser(parent, SWT.NONE);
                browser.addLocationListener(new LocationAdapter() {
                        @Override
                        public void changing(LocationEvent event) {
-                               if (!context.getUrl().equals(event.location))
+//                             if (event.top && !context.getUrl().equals(event.location))
+//                                     context.setUrl(event.location);
+                       }
+
+                       @Override
+                       public void changed(LocationEvent event) {
+                               if (event.top && !context.getUrl().equals(event.location))
                                        context.setUrl(event.location);
                        }
+
                });
                browser.addTitleListener(e -> context.setTitle(e.title));
                context.addObserver((o, v) -> {
                        String url = ((Context) o).getUrl();
-                       if (!url.equals(browser.getUrl()))
+                       if (url != null && !url.equals(browser.getUrl()))
                                browser.setUrl(url.toString());
                });
                return browser;
index 1280d1d44c12ec597be4b0e30b7982f29507a4c2..cacf55aaa76e3186fd85b093827a4b463569d94e 100644 (file)
@@ -54,9 +54,13 @@ public class MiniTerminal implements KeyListener, PaintListener {
        private String host = "localhost";
        private String username;
 
+       // Sub process
+       private Process process;
        private boolean running = false;
        private OutputStream stdIn = null;
 
+       private Thread readOut;
+
        public MiniTerminal(Composite parent, int style) {
                charset = StandardCharsets.UTF_8;
 
@@ -107,6 +111,13 @@ public class MiniTerminal implements KeyListener, PaintListener {
                        userInput.setLength(userInput.length() - 1);
                        if (!running && buf.length() > 0)
                                buf.setLength(buf.length() - 1);
+               } else if (e.stateMask == 0x40000 && e.keyCode == 0x63) {// Ctrl+C
+                       if (process != null)
+                               process.destroy();
+               } else if (e.stateMask == 0x40000 && e.keyCode == 0xdf) {// Ctrl+\
+                       if (process != null) {
+                               process.destroyForcibly();
+                       }
                } else {
                        // if (!running)
                        buf.append(e.character);
@@ -196,10 +207,10 @@ public class MiniTerminal implements KeyListener, PaintListener {
                        pb.redirectErrorStream(true);
                        pb.directory(currentDir.toFile());
 //                     Process process = Runtime.getRuntime().exec(input, null, currentPath.toFile());
-                       Process process = pb.start();
+                       process = pb.start();
 
                        stdIn = process.getOutputStream();
-                       Thread readOut = new Thread("Read out") {
+                       readOut = new Thread("MinitTerminal read out") {
                                @Override
                                public void run() {
                                        running = true;
@@ -215,6 +226,8 @@ public class MiniTerminal implements KeyListener, PaintListener {
                                        stdIn = null;
                                        displayPrompt();
                                        running = false;
+                                       readOut = null;
+                                       process = null;
                                }
                        };
                        readOut.start();