/**
  * Sets whether the attribute is dirty and also notifies the editor some part's dirty flag as
  * changed.
  *
  * <p>Subclasses should set the to true as a result of user interaction with the widgets in the
  * section and then should set to false when the commit() method completed.
  *
  * @param isDirty the new value to set the dirty-flag to
  */
 public void setDirty(boolean isDirty) {
   boolean wasDirty = mIsDirty;
   mIsDirty = isDirty;
   // TODO: for unknown attributes, getParent() != null && getParent().getEditor() != null
   if (wasDirty != isDirty) {
     AndroidXmlEditor editor = getUiParent().getEditor();
     if (editor != null) {
       editor.editorDirtyStateChanged();
     }
   }
 }
Esempio n. 2
0
 /* (non-java doc)
  * Change the tab/title name to include the project name.
  */
 @Override
 protected void setInput(IEditorInput input) {
   super.setInput(input);
   IFile inputFile = getInputFile();
   if (inputFile != null) {
     startMonitoringMarkers();
     setPartName(String.format("%1$s Manifest", inputFile.getProject().getName()));
   }
 }
Esempio n. 3
0
  @Override
  public void dispose() {
    super.dispose();

    GlobalProjectMonitor.getMonitor().removeFileListener(mMarkerMonitor);
  }
  private void checkFixes(String name, String caretLocation) throws Exception {
    IProject project = getProject();
    IFile file = getTestDataFile(project, name, FD_RES + "/" + FD_RES_LAYOUT + "/" + name);

    // Determine the offset
    String fileContent = AdtPlugin.readFile(file);
    int caretDelta = caretLocation.indexOf("^");
    assertTrue(caretLocation, caretDelta != -1);
    String caretContext =
        caretLocation.substring(0, caretDelta) + caretLocation.substring(caretDelta + "^".length());
    int caretContextIndex = fileContent.indexOf(caretContext);
    assertTrue("Caret content " + caretContext + " not found in file", caretContextIndex != -1);
    final int offset = caretContextIndex + caretDelta;

    RefactoringAssistant refactoringAssistant = new RefactoringAssistant();

    // Open file
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    assertNotNull(page);
    IEditorPart editor = IDE.openEditor(page, file);
    assertTrue(editor instanceof AndroidXmlEditor);
    AndroidXmlEditor layoutEditor = (AndroidXmlEditor) editor;
    final ISourceViewer viewer = layoutEditor.getStructuredSourceViewer();

    IQuickAssistInvocationContext invocationContext =
        new IQuickAssistInvocationContext() {
          @Override
          public int getLength() {
            return 0;
          }

          @Override
          public int getOffset() {
            return offset;
          }

          @Override
          public ISourceViewer getSourceViewer() {
            return viewer;
          }
        };
    ICompletionProposal[] proposals =
        refactoringAssistant.computeQuickAssistProposals(invocationContext);

    if (proposals != null) {
      for (ICompletionProposal proposal : proposals) {
        assertNotNull(proposal.getAdditionalProposalInfo());
        assertNotNull(proposal.getImage());
      }
    }

    StringBuilder sb = new StringBuilder(1000);
    sb.append("Quick assistant in " + name + " for " + caretLocation + ":\n");
    if (proposals != null) {
      for (ICompletionProposal proposal : proposals) {
        sb.append(proposal.getDisplayString());
        String help = proposal.getAdditionalProposalInfo();
        if (help != null && help.trim().length() > 0) {
          sb.append(" : ");
          sb.append(help.replace('\n', ' '));
        }
        sb.append('\n');
      }
    } else {
      sb.append("None found.\n");
    }
    assertEqualsGolden(name, sb.toString(), "txt");

    // No "apply" test on these assists since they are interactive. Refactoring
    // is tested elsewhere.
  }