Search in sources :

Example 1 with OpenAction

use of com.oxygenxml.git.view.staging.actions.OpenAction in project oxygen-git-client-addon by oxygenxml.

the class GitResourceContextualMenu method createAllActions.

/**
 * Creates actions for contextual menu.
 *  @param allSelectedResources  A list with all selected resources.
 * @param selectedLeaves         A list of FileStatus with selected leaves.
 * @param selResProvider         Provides the resources that will be processed by the menu's actions.
 * @param forStagedRes           <code>true</code> if the contextual menu is created for staged files.
 */
private void createAllActions(final List<FileStatus> allSelectedResources, final List<FileStatus> selectedLeaves, final SelectedResourcesProvider selResProvider, final boolean forStagedRes) {
    // "Open in compare editor" action
    showDiffAction = new AbstractAction(TRANSLATOR.getTranslation(Tags.OPEN_IN_COMPARE)) {

        @Override
        public void actionPerformed(ActionEvent e) {
            DiffPresenter.showDiff(selectedLeaves.get(0), gitCtrl);
        }
    };
    // "Open" action
    openAction = new OpenAction(selResProvider);
    // "Stage"/"Unstage" actions
    stageUnstageAction = new StageUnstageResourceAction(allSelectedResources, // then the action should be unstage.
    !forStagedRes, gitCtrl);
    // Resolve using "mine"
    resolveUsingMineAction = new AbstractAction(TRANSLATOR.getTranslation(Tags.RESOLVE_USING_MINE)) {

        @Override
        public void actionPerformed(ActionEvent e) {
            gitCtrl.asyncResolveUsingMine(allSelectedResources);
        }
    };
    // Resolve using "theirs"
    resolveUsingTheirsAction = new AbstractAction(TRANSLATOR.getTranslation(Tags.RESOLVE_USING_THEIRS)) {

        @Override
        public void actionPerformed(ActionEvent e) {
            gitCtrl.asyncResolveUsingTheirs(allSelectedResources);
        }
    };
    // "Mark resolved" action
    markResolvedAction = new AbstractAction(TRANSLATOR.getTranslation(Tags.MARK_RESOLVED)) {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                if (FileUtil.containsConflictMarkers(allSelectedResources, GIT_ACCESS.getWorkingCopy())) {
                    int answer = FileStatusDialog.showWarningMessageWithConfirmation(TRANSLATOR.getTranslation(Tags.MARK_RESOLVED), TRANSLATOR.getTranslation(Tags.CONFLICT_MARKERS_MESSAGE), TRANSLATOR.getTranslation(Tags.RESOLVE_ANYWAY), TRANSLATOR.getTranslation(Tags.CANCEL));
                    if (answer == FileStatusDialog.RESULT_OK) {
                        gitCtrl.asyncAddToIndex(allSelectedResources);
                    }
                } else {
                    gitCtrl.asyncAddToIndex(allSelectedResources);
                }
            } catch (Exception err) {
                LOGGER.error(err.getMessage(), err);
            }
        }
    };
    // "Restart Merge" action
    restartMergeAction = new AbstractAction(TRANSLATOR.getTranslation(Tags.RESTART_MERGE)) {

        @Override
        public void actionPerformed(ActionEvent e) {
            String[] options = new String[] { "   " + TRANSLATOR.getTranslation(Tags.YES) + "   ", "   " + TRANSLATOR.getTranslation(Tags.NO) + "   " };
            int[] optionIds = new int[] { 0, 1 };
            int result = GitResourceContextualMenu.PLUGIN_WS.showConfirmDialog(TRANSLATOR.getTranslation(Tags.RESTART_MERGE), TRANSLATOR.getTranslation(Tags.RESTART_MERGE_CONFIRMATION), options, optionIds);
            if (result == optionIds[0]) {
                GIT_ACCESS.restartMerge();
            }
        }
    };
    // "Discard" action
    discardAction = new DiscardAction(selResProvider, gitCtrl);
    if (!forStagedRes) {
        // Show history
        historyAction = new AbstractAction(TRANSLATOR.getTranslation(Tags.SHOW_HISTORY)) {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (!allSelectedResources.isEmpty()) {
                    historyController.showResourceHistory(allSelectedResources.get(0).getFileLocation());
                }
            }
        };
        // "Blame" action
        blameAction = new ShowBlameForUnstagedResourceAction(historyController, selResProvider);
    }
}
Also used : DiscardAction(com.oxygenxml.git.view.staging.actions.DiscardAction) OpenAction(com.oxygenxml.git.view.staging.actions.OpenAction) StageUnstageResourceAction(com.oxygenxml.git.view.staging.actions.StageUnstageResourceAction) ActionEvent(java.awt.event.ActionEvent) ShowBlameForUnstagedResourceAction(com.oxygenxml.git.view.staging.actions.ShowBlameForUnstagedResourceAction) AbstractAction(javax.swing.AbstractAction)

Aggregations

DiscardAction (com.oxygenxml.git.view.staging.actions.DiscardAction)1 OpenAction (com.oxygenxml.git.view.staging.actions.OpenAction)1 ShowBlameForUnstagedResourceAction (com.oxygenxml.git.view.staging.actions.ShowBlameForUnstagedResourceAction)1 StageUnstageResourceAction (com.oxygenxml.git.view.staging.actions.StageUnstageResourceAction)1 ActionEvent (java.awt.event.ActionEvent)1 AbstractAction (javax.swing.AbstractAction)1