@Override
  protected Control createDialogArea(Composite parent) {
    final Composite composite = (Composite) super.createDialogArea(parent);
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 1;
    composite.setLayout(gridLayout);

    setTitle(UIText.RebaseInteractiveHandler_EditMessageDialogTitle);
    setMessage(UIText.RebaseInteractiveHandler_EditMessageDialogText);

    messageArea = new SpellcheckableMessageArea(composite, commitMessage);
    messageArea.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
    Point size = messageArea.getTextWidget().getSize();
    int minHeight = messageArea.getTextWidget().getLineHeight() * 3;
    messageArea.setLayoutData(
        GridDataFactory.fillDefaults()
            .grab(true, true)
            .hint(size)
            .minSize(size.x, minHeight)
            .align(SWT.FILL, SWT.FILL)
            .create());
    messageArea.setFocus();

    return composite;
  }
 private void refreshSignedOffBy() {
   String curText = commitText.getText();
   if (signedOff)
     // add signed off line
     commitText.setText(signOff(curText));
   else {
     // remove signed off line
     String s = getSignedOff();
     if (s != null) {
       curText = replaceSignOff(curText, s, EMPTY_STRING);
       if (curText.endsWith(Text.DELIMITER + Text.DELIMITER))
         curText = curText.substring(0, curText.length() - Text.DELIMITER.length());
       commitText.setText(curText);
     }
   }
 }
 /** @param selection */
 public void setAmendingButtonSelection(boolean selection) {
   amending = selection;
   if (!selection) {
     originalChangeId = null;
     authorText.setText(author);
     commitText.setText(commitMessageBeforeAmending);
     commitMessageBeforeAmending = EMPTY_STRING;
   } else {
     getHeadCommitInfo();
     saveOriginalChangeId();
     commitMessageBeforeAmending = commitText.getText();
     commitText.setText(previousCommitMessage);
     if (previousAuthor != null) authorText.setText(previousAuthor);
   }
   refreshChangeIdText();
 }
  private void updateChangeIdButton() {
    String curText = commitText.getText();
    if (!curText.endsWith(Text.DELIMITER)) curText += Text.DELIMITER;

    createChangeId = curText.indexOf(Text.DELIMITER + "Change-Id: ") != -1; // $NON-NLS-1$
    listener.updateChangeIdToggleSelection(createChangeId);
  }
  private void addListeners() {
    authorHandler = UIUtils.addPreviousValuesContentProposalToText(authorText, AUTHOR_VALUES_PREF);
    committerText.addModifyListener(
        new ModifyListener() {
          String oldCommitter = committerText.getText();

          public void modifyText(ModifyEvent e) {
            if (!listersEnabled) return;
            if (signedOff) {
              // the commit message is signed
              // the signature must be updated
              String newCommitter = committerText.getText();
              String oldSignOff = getSignedOff(oldCommitter);
              String newSignOff = getSignedOff(newCommitter);
              commitText.setText(replaceSignOff(commitText.getText(), oldSignOff, newSignOff));
              oldCommitter = newCommitter;
            }
          }
        });
    committerHandler =
        UIUtils.addPreviousValuesContentProposalToText(committerText, COMMITTER_VALUES_PREF);
    commitText
        .getTextWidget()
        .addModifyListener(
            new ModifyListener() {
              public void modifyText(ModifyEvent e) {
                if (!listersEnabled) return;
                updateSignedOffButton();
                updateChangeIdButton();
              }
            });
  }
 /** @return state */
 public CommitMessageComponentState getState() {
   updateStateFromUI();
   CommitMessageComponentState state = new CommitMessageComponentState();
   state.setAmend(isAmending());
   state.setAuthor(getAuthor());
   // store text with platform specific line endings
   state.setCommitMessage(commitText.getText());
   state.setCommitter(getCommitter());
   state.setHeadCommit(getHeadCommit());
   return state;
 }
 private void refreshChangeIdText() {
   if (createChangeId) {
     // ChangeIdUtil uses \n line endings
     String text = commitText.getText().replaceAll(Text.DELIMITER, "\n"); // $NON-NLS-1$
     String changedText =
         ChangeIdUtil.insertId(
             text, originalChangeId != null ? originalChangeId : ObjectId.zeroId(), true);
     if (!text.equals(changedText)) {
       changedText = changedText.replaceAll("\n", Text.DELIMITER); // $NON-NLS-1$
       commitText.setText(changedText);
     }
   } else {
     String text = commitText.getText();
     int changeIdOffset = findOffsetOfChangeIdLine(text);
     if (changeIdOffset > 0) {
       String cleanedText;
       int endOfChangeId = findNextEOL(changeIdOffset, text);
       if (endOfChangeId == -1) cleanedText = text.substring(0, changeIdOffset);
       else cleanedText = text.substring(0, changeIdOffset) + text.substring(endOfChangeId);
       commitText.setText(cleanedText);
     }
   }
 }
Exemple #8
0
  private void createMessageArea(Composite parent, FormToolkit toolkit, int span) {
    Section messageSection = createSection(parent, toolkit, span);
    Composite messageArea = createSectionClient(messageSection, toolkit);

    messageSection.setText(UIText.CommitEditorPage_SectionMessage);

    RevCommit commit = getCommit().getRevCommit();
    String message = commit.getFullMessage();

    PersonIdent author = commit.getAuthorIdent();
    if (author != null) message = replaceSignedOffByLine(message, author);
    PersonIdent committer = commit.getCommitterIdent();
    if (committer != null) message = replaceSignedOffByLine(message, committer);

    SpellcheckableMessageArea textContent =
        new SpellcheckableMessageArea(messageArea, message, true, toolkit.getBorderStyle()) {

          @Override
          protected IAdaptable getDefaultTarget() {
            return new PlatformObject() {
              public Object getAdapter(Class adapter) {
                return Platform.getAdapterManager().getAdapter(getEditorInput(), adapter);
              }
            };
          }

          protected void createMarginPainter() {
            // Disabled intentionally
          }
        };
    if ((toolkit.getBorderStyle() & SWT.BORDER) == 0)
      textContent.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
    GridDataFactory.fillDefaults().hint(SWT.DEFAULT, 80).grab(true, true).applyTo(textContent);

    updateSectionClient(messageSection, messageArea, toolkit);
  }
  /** Initial UI update */
  public void updateUI() {
    if (amending) getHeadCommitInfo();

    commitText.setText(calculateCommitMessage(filesToCommit));
    authorText.setText(getSafeString(author));
    committerText.setText(getSafeString(committer));
    if (amending) {
      authorText.setText(previousAuthor);
      saveOriginalChangeId();
    } else {
      if (!amendAllowed) {
        originalChangeId = null;
      }
      refreshSignedOffBy();
      refreshChangeIdText();
    }
    updateSignedOffButton();
    updateChangeIdButton();
  }
Exemple #10
0
  @Override
  protected Control createDialogArea(Composite parent) {
    Composite container = (Composite) super.createDialogArea(parent);
    parent.getShell().setText(UIText.CommitDialog_CommitChanges);

    container = toolkit.createComposite(container);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(container);
    toolkit.paintBordersFor(container);
    GridLayoutFactory.swtDefaults().applyTo(container);

    final SashForm sashForm = new SashForm(container, SWT.VERTICAL | SWT.FILL);
    toolkit.adapt(sashForm, true, true);
    sashForm.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    createMessageAndPersonArea(sashForm);
    filesSection = createFileSection(sashForm);
    sashForm.setWeights(new int[] {50, 50});

    applyDialogFont(container);
    container.pack();
    commitText.setFocus();
    Image titleImage = UIIcons.WIZBAN_CONNECT_REPO.createImage();
    UIUtils.hookDisposal(parent, titleImage);
    setTitleImage(titleImage);
    setTitle(UIText.CommitDialog_Title);
    setMessage(UIText.CommitDialog_Message, IMessageProvider.INFORMATION);

    filesViewer.addCheckStateListener(
        new ICheckStateListener() {

          public void checkStateChanged(CheckStateChangedEvent event) {
            updateMessage();
          }
        });

    updateFileSectionText();
    return container;
  }
Exemple #11
0
  private Composite createMessageAndPersonArea(Composite container) {

    Composite messageAndPersonArea = toolkit.createComposite(container);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(messageAndPersonArea);
    GridLayoutFactory.swtDefaults().margins(0, 0).spacing(0, 0).applyTo(messageAndPersonArea);

    Section messageSection =
        toolkit.createSection(
            messageAndPersonArea,
            ExpandableComposite.TITLE_BAR | ExpandableComposite.CLIENT_INDENT);
    messageSection.setText(UIText.CommitDialog_CommitMessage);
    Composite messageArea = toolkit.createComposite(messageSection);
    GridLayoutFactory.fillDefaults().spacing(0, 0).extendedMargins(2, 2, 2, 2).applyTo(messageArea);
    toolkit.paintBordersFor(messageArea);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(messageSection);
    GridLayoutFactory.swtDefaults().applyTo(messageSection);

    Composite headerArea = new Composite(messageSection, SWT.NONE);
    GridLayoutFactory.fillDefaults().spacing(0, 0).numColumns(2).applyTo(headerArea);

    ToolBar messageToolbar = new ToolBar(headerArea, SWT.FLAT | SWT.HORIZONTAL);
    GridDataFactory.fillDefaults()
        .align(SWT.END, SWT.FILL)
        .grab(true, false)
        .applyTo(messageToolbar);

    addMessageDropDown(headerArea);

    messageSection.setTextClient(headerArea);

    final CommitProposalProcessor commitProposalProcessor =
        new CommitProposalProcessor() {
          @Override
          protected Collection<String> computeFileNameProposals() {
            return getFileList();
          }

          @Override
          protected Collection<String> computeMessageProposals() {
            return CommitMessageHistory.getCommitHistory();
          }
        };
    commitText =
        new CommitMessageArea(messageArea, commitMessage, SWT.NONE) {
          @Override
          protected CommitProposalProcessor getCommitProposalProcessor() {
            return commitProposalProcessor;
          }
        };
    commitText.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
    messageSection.setClient(messageArea);
    Point size = commitText.getTextWidget().getSize();
    int minHeight = commitText.getTextWidget().getLineHeight() * 3;
    commitText.setLayoutData(
        GridDataFactory.fillDefaults()
            .grab(true, true)
            .hint(size)
            .minSize(size.x, minHeight)
            .align(SWT.FILL, SWT.FILL)
            .create());

    UIUtils.addBulbDecorator(commitText.getTextWidget(), UIText.CommitDialog_ContentAssist);

    Composite personArea = toolkit.createComposite(messageAndPersonArea);
    toolkit.paintBordersFor(personArea);
    GridLayoutFactory.swtDefaults().numColumns(2).applyTo(personArea);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(personArea);

    toolkit
        .createLabel(personArea, UIText.CommitDialog_Author)
        .setForeground(toolkit.getColors().getColor(IFormColors.TB_TOGGLE));
    authorText = toolkit.createText(personArea, null);
    authorText.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
    authorText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    if (repository != null
        && repository.getRepositoryState().equals(RepositoryState.CHERRY_PICKING_RESOLVED))
      authorText.setEnabled(false);

    toolkit
        .createLabel(personArea, UIText.CommitDialog_Committer)
        .setForeground(toolkit.getColors().getColor(IFormColors.TB_TOGGLE));
    committerText = toolkit.createText(personArea, null);
    committerText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    if (committer != null) committerText.setText(committer);

    amendingItem = new ToolItem(messageToolbar, SWT.CHECK);
    amendingItem.setSelection(amending);
    if (amending) amendingItem.setEnabled(false); // if already set, don't allow any
    // changes
    else if (!amendAllowed) amendingItem.setEnabled(false);
    amendingItem.setToolTipText(UIText.CommitDialog_AmendPreviousCommit);
    Image amendImage = UIIcons.AMEND_COMMIT.createImage();
    UIUtils.hookDisposal(amendingItem, amendImage);
    amendingItem.setImage(amendImage);

    signedOffItem = new ToolItem(messageToolbar, SWT.CHECK);

    signedOffItem.setToolTipText(UIText.CommitDialog_AddSOB);
    Image signedOffImage = UIIcons.SIGNED_OFF.createImage();
    UIUtils.hookDisposal(signedOffItem, signedOffImage);
    signedOffItem.setImage(signedOffImage);

    changeIdItem = new ToolItem(messageToolbar, SWT.CHECK);
    Image changeIdImage = UIIcons.GERRIT.createImage();
    UIUtils.hookDisposal(changeIdItem, changeIdImage);
    changeIdItem.setImage(changeIdImage);
    changeIdItem.setToolTipText(UIText.CommitDialog_AddChangeIdLabel);

    final ICommitMessageComponentNotifications listener =
        new ICommitMessageComponentNotifications() {

          public void updateSignedOffToggleSelection(boolean selection) {
            signedOffItem.setSelection(selection);
          }

          public void updateChangeIdToggleSelection(boolean selection) {
            changeIdItem.setSelection(selection);
          }

          public void statusUpdated() {
            updateMessage();
          }
        };

    commitMessageComponent = new CommitMessageComponent(repository, listener);
    commitMessageComponent.enableListeners(false);
    commitMessageComponent.setDefaults();
    commitMessageComponent.attachControls(commitText, authorText, committerText);
    commitMessageComponent.setCommitMessage(commitMessage);
    commitMessageComponent.setAuthor(author);
    commitMessageComponent.setCommitter(committer);
    commitMessageComponent.setAmending(amending);
    commitMessageComponent.setFilesToCommit(getFileList());

    amendingItem.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent arg0) {
            commitMessageComponent.setAmendingButtonSelection(amendingItem.getSelection());
          }
        });

    changeIdItem.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent arg0) {
            commitMessageComponent.setChangeIdButtonSelection(changeIdItem.getSelection());
          }
        });

    signedOffItem.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent arg0) {
            commitMessageComponent.setSignedOffButtonSelection(signedOffItem.getSelection());
          }
        });

    commitMessageComponent.updateUI();
    commitMessageComponent.enableListeners(true);

    return messageAndPersonArea;
  }
 private void updateSignedOffButton() {
   String curText = commitText.getText();
   if (!curText.endsWith(Text.DELIMITER)) curText += Text.DELIMITER;
   signedOff = curText.indexOf(getSignedOff() + Text.DELIMITER) != -1;
   listener.updateSignedOffToggleSelection(signedOff);
 }
 public void updateUIFromState() {
   commitText.setText(commitMessage);
   authorText.setText(author);
   committerText.setText(committer);
 }
 public void updateStateFromUI() {
   commitMessage = commitText.getText();
   author = authorText.getText().trim();
   committer = committerText.getText().trim();
 }
 /**
  * Returns the commit message, converting platform-specific line endings to '\n' and hard-wrapping
  * lines if necessary.
  *
  * @return the message
  */
 public String getCommitMessage() {
   commitMessage = commitText.getCommitMessage();
   return commitMessage;
 }