コード例 #1
0
    @Override
    public void widgetSelected(final SelectionEvent event) {
      final TexCommand command = (TexCommand) event.widget.getData();

      final IEditorPart editor = UIAccess.getActiveWorkbenchPage(true).getActiveEditor();
      if (editor instanceof ILtxEditor) {
        final ILtxEditor texEditor = (ILtxEditor) editor;
        if (!texEditor.isEditable(true)) {
          return;
        }
        final SourceViewer viewer = ((ILtxEditor) editor).getViewer();
        Point selection = viewer.getSelectedRange();
        if (selection == null || selection.x < 0) {
          return;
        }
        try {
          final String contentType =
              TextUtils.getContentType(
                  viewer.getDocument(),
                  texEditor.getDocumentContentInfo(),
                  selection.x,
                  selection.y == 0);

          final LtxAssistInvocationContext context =
              new LtxAssistInvocationContext(
                  texEditor, selection.x, contentType, true, new NullProgressMonitor());
          final LtxCommandCompletionProposal proposal =
              new LtxCommandCompletionProposal(context, context.getInvocationOffset(), command);
          proposal.apply(viewer, (char) 0, 1, context.getInvocationOffset());
          selection = proposal.getSelection(viewer.getDocument());
          if (selection != null) {
            viewer.setSelectedRange(selection.x, selection.y);
            viewer.revealRange(selection.x, selection.y);
          } else {
            viewer.revealRange(context.getInvocationOffset(), 0);
          }
        } catch (final Exception e) {
          StatusManager.getManager()
              .handle(
                  new Status(
                      IStatus.ERROR,
                      TexUI.PLUGIN_ID,
                      0,
                      "An error occurred when inserting LaTeX symbol.",
                      e));
        }
      }
    }
コード例 #2
0
 @Override
 public SourceSelection getSelection() {
   final Point selection = viewer.getSelectedRange();
   return new SourceSelection(getBlock(), selection.x, selection.y);
 }