예제 #1
0
 public LinkedPosition getCurrentLinkedPosition() {
   int start = context.getSelectionOffset();
   int end = start + context.getSelectionLength();
   LinkedPosition[] positions = fLinkedPositionGroup.getPositions();
   for (int i = 0; i < positions.length; i++) {
     LinkedPosition position = positions[i];
     if (position.includes(start) && position.includes(end)) {
       return position;
     }
   }
   return null;
 }
예제 #2
0
 private void restoreFullSelection() {
   if (fOriginalSelection.y != 0) {
     int originalOffset = fOriginalSelection.x;
     LinkedPosition[] positions = fLinkedPositionGroup.getPositions();
     for (int i = 0; i < positions.length; i++) {
       LinkedPosition position = positions[i];
       if (!position.isDeleted() && position.includes(originalOffset)) {
         fEditor.getViewer().setSelectedRange(position.offset, position.length);
         return;
       }
     }
   }
 }
 public LinkedPosition getCurrentLinkedPosition() {
   Point selection = fEditor.getViewer().getSelectedRange();
   int start = selection.x;
   int end = start + selection.y;
   LinkedPosition[] positions = fLinkedPositionGroup.getPositions();
   for (int i = 0; i < positions.length; i++) {
     LinkedPosition position = positions[i];
     if (position.includes(start) && position.includes(end)) {
       return position;
     }
   }
   return null;
 }
예제 #4
0
 public boolean isOriginalName() {
   try {
     String newName = fNamePosition.getContent();
     return fOriginalName.equals(newName);
   } catch (BadLocationException e) {
     return false;
   }
 }
예제 #5
0
 public boolean isEnabled() {
   try {
     String newName = fNamePosition.getContent();
     if (fOriginalName.equals(newName)) {
       return false;
     }
     // TODO(scheglov) we may be rename not only variable, but also method, type, etc
     return NamingConventions.validateVariableName(newName).isOK();
   } catch (BadLocationException e) {
     return false;
   }
 }
  @Override
  public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {
    if (length == 0 && (event.character == SWT.BS || event.character == SWT.DEL)) {
      LinkedPosition position =
          model.findPosition(new LinkedPosition(fDocument, offset, 0, LinkedPositionGroup.NO_STOP));
      if (position != null) {
        if (event.character == SWT.BS) {
          if (offset - 1 < position.getOffset()) {
            // skip backspace at beginning of linked position
            event.doit = false;
          }
        } else /* event.character == SWT.DEL */ {
          if (offset + 1 > position.getOffset() + position.getLength()) {
            // skip delete at end of linked position
            event.doit = false;
          }
        }
      }
    }

    return null; // don't change behavior
  }
예제 #7
0
  public void startFullDialog() {
    cancel();

    try {
      String newName = fNamePosition.getContent();
      RenameSupport renameSupport = undoAndCreateRenameSupport(newName);
      if (renameSupport != null) {
        renameSupport.openDialog(fEditor.getSite().getShell());
      }
    } catch (CoreException e) {
      DartToolsPlugin.log(e);
    } catch (BadLocationException e) {
      DartToolsPlugin.log(e);
    }
  }
 public boolean isEnabled() {
   try {
     String newName = fNamePosition.getContent();
     if (fOriginalName.equals(newName)) {
       return false;
     }
     /*
      * TODO: use DartRenameProcessor#checkNewElementName(String) but make sure implementations
      * don't access outdated Dart Model (cache all necessary information before starting linked
      * mode).
      */
     // TODO(scheglov) we may be rename not only variable, but also method, type, etc
     return DartConventions.validateVariableName(newName).isOK();
   } catch (BadLocationException e) {
     return false;
   }
 }
예제 #9
0
  void doRename(boolean showPreview) {
    cancel();

    Image image = null;
    Label label = null;

    fShowPreview |= showPreview;
    try {
      ISourceViewer viewer = fEditor.getViewer();
      if (viewer instanceof SourceViewer) {
        SourceViewer sourceViewer = (SourceViewer) viewer;
        Control viewerControl = sourceViewer.getControl();
        if (viewerControl instanceof Composite) {
          Composite composite = (Composite) viewerControl;
          Display display = composite.getDisplay();

          // Flush pending redraw requests:
          while (!display.isDisposed() && display.readAndDispatch()) {}

          // Copy editor area:
          GC gc = new GC(composite);
          Point size;
          try {
            size = composite.getSize();
            image = new Image(gc.getDevice(), size.x, size.y);
            gc.copyArea(image, 0, 0);
          } finally {
            gc.dispose();
            gc = null;
          }

          // Persist editor area while executing refactoring:
          label = new Label(composite, SWT.NONE);
          label.setImage(image);
          label.setBounds(0, 0, size.x, size.y);
          label.moveAbove(null);
        }
      }

      String newName = fNamePosition.getContent();
      if (fOriginalName.equals(newName)) {
        return;
      }
      RenameSupport renameSupport = undoAndCreateRenameSupport(newName);
      if (renameSupport == null) {
        return;
      }

      Shell shell = fEditor.getSite().getShell();
      if (renameSupport.hasUnresolvedNameReferences()) {
        fShowPreview = true;
      }
      boolean executed;
      if (fShowPreview) { // could have been updated by undoAndCreateRenameSupport(..)
        executed = renameSupport.openDialog(shell, true);
      } else {
        renameSupport.perform(shell, fEditor.getSite().getWorkbenchWindow());
        executed = true;
      }
      if (executed) {
        restoreFullSelection();
      }
    } catch (CoreException ex) {
      DartToolsPlugin.log(ex);
    } catch (InterruptedException ex) {
      // canceling is OK -> redo text changes in that case?
    } catch (InvocationTargetException ex) {
      DartToolsPlugin.log(ex);
    } catch (BadLocationException e) {
      DartToolsPlugin.log(e);
    } finally {
      if (label != null) {
        label.dispose();
      }
      if (image != null) {
        image.dispose();
      }
    }
  }