@Override
    public void matchFound(PatternMatchEvent event) {
      // Create a hyperlink to the resource
      try {
        final String str = console.getDocument().get(event.getOffset(), event.getLength());
        final String[] segs = str.split(":");
        final String filename = segs[0];
        int lineNumber = 0;
        if (segs.length > 1) {
          lineNumber = Integer.parseInt(segs[1]);
        }

        for (Resource res : sourceResources()) {
          IResource ires = getIResource(res);
          if (ires instanceof IFile && ires.getName().equals(filename)) {
            console.addHyperlink(
                new FileLink((IFile) ires, null, -1, -1, lineNumber),
                event.getOffset(),
                event.getLength());
            break;
          }
        }
      } catch (BadLocationException e) {
        e.printStackTrace();
      }
    }
  private void loadConsoles() {

    for (IConsole console : consoles) {
      if ((console instanceof TextConsole) && !(console instanceof GrepConsole)) {
        TextConsole textConsole = (TextConsole) console;
        consoleList.add(textConsole.getName());
      }
    }
    consoleList.setSelection(0);
  }
 @Override
 public void addHyperlink(IHyperlink hyperlink, int offset, int length)
     throws BadLocationException {
   currentHyperlinks.add(hyperlink);
   currentHyperlinkOffsets.add(offset);
   currentHyperlinkLengths.add(length);
   super.addHyperlink(hyperlink, offset, length);
 }
Example #4
0
  /**
   * Save the content from the tracing console to a file
   *
   * @param fileName The fileName of the File to save to
   */
  protected void saveContent(String fileName) {
    try {
      boolean confirmed = true;

      File file = new File(fileName);
      if (file.exists()) {
        confirmed =
            MessageDialog.openQuestion(
                Display.getCurrent().getActiveShell(),
                ConsoleMessages.ConsoleMessages_save_confirm_overwrite_title,
                ConsoleMessages.ConsoleMessages_save_confirm_overwrite_desc);
      }
      if (confirmed) {
        BufferedWriter out = new BufferedWriter(new FileWriter(fileName));
        out.write(fConsole.getDocument().get());
        out.close();
      }
    } catch (IOException e) {
      MessageDialog.openError(
          Display.getCurrent().getActiveShell(),
          ConsoleMessages.ConsoleMessages_save_info_io_error_title,
          ConsoleMessages.ConsoleMessages_save_info_io_error_desc);
    }
  }
Example #5
0
 public void clean(final TextConsole console) {
   console.clearConsole();
 }
  @Override
  public void matchFound(PatternMatchEvent event) {
    String content = null;
    try {
      content = fConsole.getDocument().get(event.getOffset(), event.getLength());
    } catch (BadLocationException e) {
    }

    if (content == null) {
      return;
    }

    content = content.trim();

    int paren_idx = -1;
    int colon_idx = -1;
    int sp_idx = -1;
    int lineno = -1;

    if (SVFileUtils.isWin()) {
      content = content.replace('\\', '/');

      // Recognize MinGW-style paths: /c/foo/path
      // Convert to Windows-type path: c:/foo/path
      //			if (content.length() >= 3 &&
      //					(content.charAt(0) == '/') &&
      //					(content.charAt(2) == '/')) {
      //				int ch = Character.toLowerCase(content.charAt(1));
      //
      //				if (ch >= 'a' && ch <= 'z') {
      //					content = content.charAt(1) + ":" + content.substring(2);
      //				}
      //			}
    }

    if ((paren_idx = content.indexOf('(')) != -1) {
      int end_idx = paren_idx + 1;

      while (end_idx < content.length() && Character.isDigit(content.charAt(end_idx))) {
        end_idx++;
      }

      String number =
          (end_idx < content.length())
              ? content.substring(paren_idx + 1, end_idx)
              : content.substring(paren_idx + 1);

      content = content.substring(0, paren_idx);

      try {
        lineno = Integer.parseInt(number);
      } catch (NumberFormatException e) {
      }
    } else if ((colon_idx = content.indexOf(':')) != -1) {
      if (colon_idx != 1 || (colon_idx = content.indexOf(':', colon_idx + 1)) != -1) {
        int end_idx = colon_idx + 1;

        while (end_idx < content.length() && Character.isDigit(content.charAt(end_idx))) {
          end_idx++;
        }

        String number =
            (end_idx < content.length())
                ? content.substring(colon_idx + 1, end_idx)
                : content.substring(colon_idx + 1);

        content = content.substring(0, colon_idx);

        try {
          lineno = Integer.parseInt(number);
        } catch (NumberFormatException e) {
        }
      }
    } else if ((sp_idx = content.indexOf(' ')) != -1) {
      // See if there's a trailing number.
      int idx = sp_idx;
      while (idx < content.length() && Character.isWhitespace(content.charAt(idx))) {
        idx++;
      }

      if (idx < content.length() && content.charAt(idx) >= '0' && content.charAt(idx) <= '9') {
        String number = content.substring(idx).trim();
        content = content.substring(0, sp_idx);
        try {
          lineno = Integer.parseInt(number);
        } catch (NumberFormatException e) {
          e.printStackTrace();
        }
      }
    }

    String path = content;
    if (fMgr != null) {
      path = SVFileUtils.resolvePath(path, fMgr.getWorkingDirectory(), fFS, true);
    }

    IFile file = SVFileUtils.findWorkspaceFile(path);
    File efile = SVFileUtils.getFile(content);

    // Eclipse sometimes returns a file (that doesn't exist) for
    // a directory path. We only want to hyperlink 'real' files.
    if (file != null && file.exists()) {
      FileLink link = new FileLink(file, null, -1, -1, lineno);
      try {
        fConsole.addHyperlink(link, event.getOffset(), content.length());
      } catch (BadLocationException e) {
      }
    } else if (efile != null && efile.isFile()) {
      IFileStore fs = EFS.getLocalFileSystem().getStore(new Path(efile.getAbsolutePath()));
      ExternalPathHyperlink link = new ExternalPathHyperlink(fs, null, -1, -1, lineno);
      try {
        fConsole.addHyperlink(link, event.getOffset(), content.length());
      } catch (BadLocationException e) {
      }
    }
  }
 public void addExistingHyperlink(IHyperlink hyperlink, int offset, int length)
     throws BadLocationException {
   super.addHyperlink(hyperlink, offset, length);
 }