@Override
 public void setMode(CommandLineMode mode) {
   if (mode == CommandLineMode.DEFAULT) {
     commandLineText.setEditable(true);
     if (registerModeSelection != null) {
       commandLineText.replaceTextRange(registerModeSelection.x, 1, "");
       commandLineText.setSelection(registerModeSelection);
       registerModeSelection = null;
     } else {
       // Reset any selection made in a readonly mode, otherwise we need to check if
       // cut/copy needs to be enabled.
       commandLineText.setSelection(commandLineText.getCaretOffset());
     }
     readOnly = false;
   } else if (mode == CommandLineMode.REGISTER) {
     if (registerModeSelection == null) {
       Point sel = commandLineText.getSelection();
       int leftOffset = Math.min(sel.x, sel.y);
       commandLineText.replaceTextRange(leftOffset, 0, "\"");
       registerModeSelection = sel;
       readOnly = true;
     }
   } else if (mode == CommandLineMode.MESSAGE || mode == CommandLineMode.MESSAGE_CLIPPED) {
     commandLineText.setEditable(false);
     setPosition(0);
     commandLineText.setTopIndex(0);
     readOnly = true;
     pasteItem.setEnabled(false);
     commandLineText.setWordWrap(mode == CommandLineMode.MESSAGE);
   }
 }
 static void toggle(IAction action, ITextEditor editor) {
   StyledText text = (StyledText) editor.getAdapter(Control.class);
   boolean currentWrap = text.getWordWrap();
   text.setWordWrap(!currentWrap);
   if (action instanceof Action) {
     Action act = (Action) action;
     act.setChecked(!currentWrap);
   }
 }
Example #3
0
 @Override
 protected Control createContents(Composite parent) {
   Composite ret = new Composite(parent, SWT.NONE);
   ret.setLayout(new FillLayout());
   StyledText text = new StyledText(ret, SWT.NONE);
   text.setWordWrap(true);
   text.setText(
       Messages.ImporterHost_ExplanationLine1
           + Messages.ImporterHost_ExplanationLine2
           + Messages.ImporterHost_ExplanationLine3
           + Messages.ImporterHost_ExplanationLine4);
   return ret;
 }
  @Override
  public void close() {
    commandLineText.setVisible(false);
    commandLineText.setEditable(true);
    registerModeSelection = null;
    prompt = "";
    contentsOffset = 0;
    resetContents("");
    commandLineText.setWordWrap(true);

    readOnly = false;

    copyItem.setEnabled(false);
    cutItem.setEnabled(false);
    pasteItem.setEnabled(true);
  }
Example #5
0
  public CommandLineUIFactory(StyledText parentText) {
    parent = parentText;

    StyledText widget = new StyledText(parent, SWT.ON_TOP);
    widget.setFont(parent.getFont());
    widget.setMargins(COMMAND_CHAR_INDENT, 3, 3, 3);
    widget.setSize(5, 5);
    widget.setBackground(parent.getBackground());
    widget.setForeground(parent.getForeground());
    widget.setWordWrap(true);
    widget.setEnabled(true);
    //        widget.setCaretOffset(2);
    widget.moveAbove(parent);
    widget.setVisible(false);
    widget.addPaintListener(new BorderPaintListener());
    commandLineText = widget;

    parent.addPaintListener(new TextEditorPaintListener());
    parent.addFocusListener(
        new FocusAdapter() {
          @Override
          public void focusGained(FocusEvent e) {
            if (commandLineUI != null && commandLineUI.isOpen()) {
              commandLineText.forceFocus();
            }
          }
        });
    parent.addDisposeListener(
        new DisposeListener() {
          @Override
          public void widgetDisposed(DisposeEvent e) {
            commandLineText.dispose();
            if (commandLineUI != null) {
              commandLineUI.dispose();
            }
          }
        });
  }
Example #6
0
  /**
   * This is a callback that will allow us to create the viewer and initialize it. It is called by
   * the Eclipse framework.
   */
  @PostConstruct
  public void createPartControl(Composite parent) {
    parentCompo = parent;
    parentCompo.addControlListener(this);

    RowLayout rowLayout = new RowLayout();
    rowLayout.fill = true;
    textAreaContainer = new Composite(parent, SWT.NONE);
    textAreaContainer.setLayout(rowLayout);

    initPrint();

    // create the layout to be used in the text area widget
    rowData = new RowData();
    //	rowData.width = ShellConstants.MAIN_WINDOW_WIDTH - 60; // 60 is the size
    // of the scroll
    // control
    //	rowData.height = (int) (ShellConstants.MAIN_WINDOW_HEIGHT
    //			* ShellConstants.SHELL_WINDOW_RATIO - 60);

    shellTextArea =
        new StyledText(textAreaContainer, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL | SWT.BORDER);
    //	shellTextArea.setLayoutData(rowData);
    shellTextArea.setWordWrap(true);
    //	shellTextArea.setFont(DesignUIPlugin.fontRegistry.get(DesignUIPlugin.COURRIER));
    /*
     * Add a keylistener to de-activate certain keys
     */

    // create all functionality for the text area contextual menu
    createShellMenu(shellTextArea);

    // create the object that will handle all the input and output associated to
    // the StyledText widget
    shellController = new ShellUIController(shellTextArea);
    shellController.displayPrompt();

    /*
     * To jump to end disable backspace key in transcript
     */
    shellTextArea.addVerifyKeyListener(
        new VerifyKeyListener() {
          public void verifyKey(VerifyEvent event) {

            boolean illegalAction = shellController.jumpToEndOnIllegalInsertion();
            if (illegalAction) {
              if ((event.character >= '\u0008') && (event.character <= '\u007F')) {
                shellController.setCaretEndText();
              }
              //						 boolean isCtrlC = (event.stateMask == SWT.CTRL) && (event.character ==
              // '\u0003');
              boolean isCtrlV = (event.stateMask == SWT.CTRL) && (event.character == '\u0016');
              boolean isCtrlX = (event.stateMask == SWT.CTRL) && (event.character == '\u0018');
              if (isCtrlV || isCtrlX) {
                shellController.setCaretEndText();
              }
            }
          }
        });

    String mySecondaryID = null; // this.getViewSite().getSecondaryId();
    if ((mySecondaryID == null) || (mySecondaryID.startsWith(LOCAL))) {
      // create additional objects (ShellCommandManager + TextAreaReader)
      // required for this local shell
      // shellController.initBackEndObjects(null);
      shellController.initBackEndObjects(TclShellCommandManager.instance());
    }
  }
Example #7
0
  public void _setWhatsNew() {

    if (sWhatsNew.indexOf("<html") >= 0 || sWhatsNew.indexOf("<HTML") >= 0) {
      BrowserWrapper browser = Utils.createSafeBrowser(cWhatsNew, SWT.NONE);
      if (browser != null) {
        browser.setText(sWhatsNew);
      } else {
        try {
          File tempFile = File.createTempFile("AZU", ".html");
          tempFile.deleteOnExit();
          FileUtil.writeBytesAsFile(tempFile.getAbsolutePath(), sWhatsNew.getBytes("utf8"));
          Utils.launch(tempFile.getAbsolutePath());
          shell.dispose();
          return;
        } catch (IOException e) {
        }
      }
    } else {

      StyledText helpPanel = new StyledText(cWhatsNew, SWT.VERTICAL | SWT.HORIZONTAL);

      helpPanel.setEditable(false);
      try {
        helpPanel.setRedraw(false);
        helpPanel.setWordWrap(false);
        helpPanel.setFont(monospace);

        black = ColorCache.getColor(display, 0, 0, 0);
        white = ColorCache.getColor(display, 255, 255, 255);
        light = ColorCache.getColor(display, 200, 200, 200);
        grey = ColorCache.getColor(display, 50, 50, 50);
        green = ColorCache.getColor(display, 30, 80, 30);
        blue = ColorCache.getColor(display, 20, 20, 80);
        int style;
        boolean setStyle;

        helpPanel.setForeground(grey);

        String[] lines = sWhatsNew.split("\\r?\\n");
        for (int i = 0; i < lines.length; i++) {
          String line = lines[i];

          setStyle = false;
          fg = grey;
          bg = white;
          style = SWT.NORMAL;

          char styleChar;
          String text;

          if (line.length() < 2) {
            styleChar = ' ';
            text = " " + lineSeparator;
          } else {
            styleChar = line.charAt(0);
            text = line.substring(1) + lineSeparator;
          }

          switch (styleChar) {
            case '*':
              text = "  * " + text;
              fg = green;
              setStyle = true;
              break;
            case '+':
              text = "     " + text;
              fg = black;
              bg = light;
              style = SWT.BOLD;
              setStyle = true;
              break;
            case '!':
              style = SWT.BOLD;
              setStyle = true;
              break;
            case '@':
              fg = blue;
              setStyle = true;
              break;
            case '$':
              bg = blue;
              fg = white;
              style = SWT.BOLD;
              setStyle = true;
              break;
            case ' ':
              text = "  " + text;
              break;

            default:
              text = styleChar + text;
          }

          helpPanel.append(text);

          if (setStyle) {
            int lineCount = helpPanel.getLineCount() - 1;
            int charCount = helpPanel.getCharCount();
            //          System.out.println("Got Linecount " + lineCount + ", Charcount " +
            // charCount);

            int lineOfs = helpPanel.getOffsetAtLine(lineCount - 1);
            int lineLen = charCount - lineOfs;
            //          System.out.println("Setting Style : " + lineOfs + ", " + lineLen);
            helpPanel.setStyleRange(new StyleRange(lineOfs, lineLen, fg, bg, style));
            helpPanel.setLineBackground(lineCount - 1, 1, bg);
          }
        }

        helpPanel.setRedraw(true);
      } catch (Exception e) {
        System.out.println("Unable to load help contents because:" + e);
        // e.printStackTrace();
      }
    }

    if (labelLoading != null && !labelLoading.isDisposed()) {
      labelLoading.dispose();
    }
    shell.layout(true, true);
  }
  @Override
  public void createPartControl(Composite parent) {

    this.setPartName("Ocaml Toplevel");

    composite = new Composite(parent, SWT.BORDER);
    composite.addControlListener(
        new ControlAdapter() {
          @Override
          public void controlResized(ControlEvent e) {
            resized();
          }
        });

    userText = new StyledText(this.composite, SWT.V_SCROLL);
    userText.setWordWrap(true);
    resultText = new StyledText(this.composite, SWT.V_SCROLL);
    resultText.setWordWrap(true);

    sash = new Sash(composite, SWT.HORIZONTAL | SWT.SMOOTH);

    sash.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            sash.setBounds(e.x, e.y, e.width, e.height);
            layout();
          }
        });

    Color c =
        Display.findDisplay(Thread.currentThread()).getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
    sash.setBackground(c);

    toplevel = new Toplevel(this, userText, resultText);

    IActionBars actionBars = this.getViewSite().getActionBars();
    IMenuManager dropDownMenu = actionBars.getMenuManager();
    IToolBarManager toolBarManager = actionBars.getToolBarManager();

    ImageDescriptor iconAdd = ImageRepository.getImageDescriptor(ImageRepository.ICON_ADD);
    Action actionNewToplevel =
        new Action("New toplevel", iconAdd) {
          @Override
          public void run() {
            try {
              IWorkbenchPage page =
                  PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
              OcamlToplevelView.this.secondaryId = "ocamltoplevelview" + new Random().nextInt();
              page.showView(ID, OcamlToplevelView.this.secondaryId, IWorkbenchPage.VIEW_ACTIVATE);
            } catch (Exception e) {
              OcamlPlugin.logError("ocaml plugin error", e);
            }
          }
        };

    ImageDescriptor iconReset = ImageRepository.getImageDescriptor(ImageRepository.ICON_RESET);
    Action actionReset =
        new Action("Reset", iconReset) {
          @Override
          public void run() {
            toplevel.reset();
          }
        };

    ImageDescriptor iconInterrupt =
        ImageRepository.getImageDescriptor(ImageRepository.ICON_INTERRUPT);
    Action actionBreak =
        new Action("Interrupt", iconInterrupt) {
          @Override
          public void run() {
            toplevel.interrupt();
          }
        };

    ImageDescriptor iconClear = ImageRepository.getImageDescriptor(ImageRepository.ICON_CLEAR);
    Action actionClear =
        new Action("Clear", iconClear) {
          @Override
          public void run() {
            toplevel.clear();
          }
        };

    ImageDescriptor iconHelp = ImageRepository.getImageDescriptor(ImageRepository.ICON_HELP);
    Action actionHelp =
        new Action("Help", iconHelp) {
          @Override
          public void run() {
            toplevel.help();
          }
        };

    Action actionUseTopfind =
        new Action("Use Topfind") {
          @Override
          public void run() {
            toplevel.eval("#use \"topfind\";;");
          }
        };

    dropDownMenu.add(actionUseTopfind);

    toolBarManager.add(actionBreak);
    toolBarManager.add(actionClear);
    toolBarManager.add(actionReset);
    toolBarManager.add(actionNewToplevel);
    toolBarManager.add(actionHelp);

    if (bStartWhenCreated) toplevel.start();

    OcamlPlugin.setLastFocusedToplevelInstance(this);
  }
  @Override
  protected void createBundleContent(Composite parent) {

    mform = new ManagedForm(parent);
    setManagedForm(mform);
    sform = mform.getForm();
    FormToolkit toolkit = mform.getToolkit();
    sform.setText("Server Console");
    sform.setImage(ServerUICore.getLabelProvider().getImage(getServer()));
    sform.setExpandHorizontal(true);
    sform.setExpandVertical(true);
    toolkit.decorateFormHeading(sform.getForm());

    Composite body = sform.getBody();
    GridLayout layout = new GridLayout(1, false);
    layout.marginLeft = 6;
    layout.marginTop = 6;
    layout.marginRight = 6;
    body.setLayout(layout);

    Section manifestSection =
        toolkit.createSection(sform.getBody(), ExpandableComposite.TITLE_BAR | Section.DESCRIPTION);
    manifestSection.setText("Commands");
    manifestSection.setDescription("Execute commands on server.");
    layout = new GridLayout();
    manifestSection.setLayout(layout);
    manifestSection.setLayoutData(new GridData(GridData.FILL_BOTH));

    Composite manifestComposite = toolkit.createComposite(manifestSection);
    layout = new GridLayout();
    layout.marginLeft = 6;
    layout.marginTop = 6;
    layout.numColumns = 3;
    manifestComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
    manifestComposite.setLayout(layout);
    manifestSection.setClient(manifestComposite);

    Label commandLabel = toolkit.createLabel(manifestComposite, "Command:");
    commandLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
    GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(commandLabel);
    commandText = toolkit.createText(manifestComposite, "", SWT.CANCEL | SWT.SEARCH);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(commandText);

    commandText.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyPressed(KeyEvent e) {
            if (e.character == SWT.CR || e.character == SWT.LF) {
              history.add(commandText.getText());
              String cmdLine = commandText.getText();
              executeCommand(cmdLine);
            } else if (e.keyCode == SWT.ARROW_UP) {
              String command = history.back();
              commandText.setText(command);
              commandText.setSelection(command.length());
              e.doit = false;
            } else if (e.keyCode == SWT.ARROW_DOWN) {
              String command = history.forward();
              commandText.setText(command);
              commandText.setSelection(command.length());
              e.doit = false;
            }
          }
        });

    Button commandButton = toolkit.createButton(manifestComposite, "Execute", SWT.PUSH);
    commandButton.addSelectionListener(
        new SelectionAdapter() {

          @Override
          public void widgetSelected(SelectionEvent e) {
            history.add(commandText.getText());
            String cmdLine = commandText.getText();
            executeCommand(cmdLine);
          }
        });
    Button clearButton = toolkit.createButton(manifestComposite, "Clear", SWT.PUSH);
    clearButton.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            manifestText.setText("");
          }
        });

    manifestText =
        new StyledText(manifestComposite, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    manifestText.setWordWrap(false);
    manifestText.setFont(JFaceResources.getTextFont());
    GridData data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 3;
    manifestText.setLayoutData(data);

    Label helpLabel =
        toolkit.createLabel(manifestComposite, "Type 'help' to get a list of supported commands.");
    GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(helpLabel);

    toolBarManager = sform.getToolBarManager();

    backAction =
        new Action("Back") {
          @Override
          public void run() {
            commandText.setText(history.back());
            String cmdLine = commandText.getText();
            executeCommand(cmdLine);
          }
        };
    backAction.setImageDescriptor(
        ImageResource.getImageDescriptor(
            org.eclipse.ui.internal.browser.ImageResource.IMG_ELCL_NAV_BACKWARD));
    backAction.setHoverImageDescriptor(
        ImageResource.getImageDescriptor(ImageResource.IMG_CLCL_NAV_BACKWARD));
    backAction.setDisabledImageDescriptor(
        ImageResource.getImageDescriptor(ImageResource.IMG_DLCL_NAV_BACKWARD));
    backAction.setEnabled(false);
    toolBarManager.add(backAction);

    forwardAction =
        new Action("Forward") {
          @Override
          public void run() {
            commandText.setText(history.forward());
            String cmdLine = commandText.getText();
            executeCommand(cmdLine);
          }
        };
    forwardAction.setImageDescriptor(
        ImageResource.getImageDescriptor(ImageResource.IMG_ELCL_NAV_FORWARD));
    forwardAction.setHoverImageDescriptor(
        ImageResource.getImageDescriptor(ImageResource.IMG_CLCL_NAV_FORWARD));
    forwardAction.setDisabledImageDescriptor(
        ImageResource.getImageDescriptor(ImageResource.IMG_DLCL_NAV_FORWARD));
    forwardAction.setEnabled(false);
    toolBarManager.add(forwardAction);

    refreshAction =
        new Action(
            "Refresh from server",
            ImageResource.getImageDescriptor(ImageResource.IMG_ELCL_NAV_REFRESH)) {

          @Override
          public void run() {
            String cmdLine = history.current();
            if (cmdLine != null) {
              executeCommand(cmdLine);
            }
          }
        };
    toolBarManager.add(refreshAction);
    sform.updateToolBar();
  }