Example #1
0
  @Override
  protected void okPressed() {
    if (!isCommitWithoutFilesAllowed()) {
      MessageDialog.openWarning(
          getShell(),
          UIText.CommitDialog_ErrorNoItemsSelected,
          UIText.CommitDialog_ErrorNoItemsSelectedToBeCommitted);
      return;
    }

    if (!commitMessageComponent.checkCommitInfo()) return;

    Object[] checkedElements = filesViewer.getCheckedElements();
    selectedFiles.clear();
    for (Object obj : checkedElements) selectedFiles.add(((CommitItem) obj).path);

    amending = commitMessageComponent.isAmending();
    commitMessage = commitMessageComponent.getCommitMessage();
    author = commitMessageComponent.getAuthor();
    committer = commitMessageComponent.getCommitter();
    createChangeId = changeIdItem.getSelection();

    IDialogSettings settings = org.eclipse.egit.ui.Activator.getDefault().getDialogSettings();
    settings.put(SHOW_UNTRACKED_PREF, showUntracked);
    CommitMessageHistory.saveCommitHistory(getCommitMessage());
    super.okPressed();
  }
Example #2
0
  private void updateMessage() {
    if (commitButton == null)
      // Not yet fully initialized.
      return;

    String message = null;
    int type = IMessageProvider.NONE;

    String commitMsg = commitMessageComponent.getCommitMessage();
    if (commitMsg == null || commitMsg.trim().length() == 0) {
      message = UIText.CommitDialog_Message;
      type = IMessageProvider.INFORMATION;
    } else if (!isCommitWithoutFilesAllowed()) {
      message = UIText.CommitDialog_MessageNoFilesSelected;
      type = IMessageProvider.INFORMATION;
    } else {
      CommitStatus status = commitMessageComponent.getStatus();
      message = status.getMessage();
      type = status.getMessageType();
    }

    setMessage(message, type);
    boolean commitEnabled = type == IMessageProvider.WARNING || type == IMessageProvider.NONE;
    commitButton.setEnabled(commitEnabled);
    commitAndPushButton.setEnabled(commitEnabled);
  }
Example #3
0
 private void openStagingViewLinkClicked() {
   IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
   IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
   try {
     StagingView view = (StagingView) workbenchPage.showView(StagingView.VIEW_ID);
     view.reload(repository);
     String message = commitMessageComponent.getCommitMessage();
     if (message != null && message.length() > 0) view.setCommitMessage(message);
     setReturnCode(CANCEL);
     close();
   } catch (PartInitException e) {
     Activator.handleError(UIText.CommitDialog_OpenStagingViewError, e, true);
   }
 }
Example #4
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;
  }