use of org.eclipse.egit.ui.internal.actions.BooleanPrefAction in project egit by eclipse.
the class RebaseInteractiveView method createPartControl.
@Override
public void createPartControl(Composite parent) {
GridLayoutFactory.fillDefaults().applyTo(parent);
final FormToolkit toolkit = new FormToolkit(parent.getDisplay());
parent.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
toolkit.dispose();
}
});
form = createForm(parent, toolkit);
createCommandToolBar(form, toolkit);
planTreeViewer = createPlanTreeViewer(form.getBody(), toolkit);
planLayout = new PlanLayout();
planTreeViewer.getTree().getParent().setLayout(planLayout);
createColumns(planLayout);
createStepActionToolBar(toolkit);
createPopupMenu(planTreeViewer);
setupListeners();
createLocalDragandDrop();
planTreeViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
PlanElement element = (PlanElement) ((IStructuredSelection) event.getSelection()).getFirstElement();
if (element == null)
return;
RepositoryCommit commit = loadCommit(element.getCommit());
if (commit != null)
CommitEditor.openQuiet(commit);
}
private RepositoryCommit loadCommit(AbbreviatedObjectId abbreviatedObjectId) {
if (abbreviatedObjectId != null) {
try (RevWalk walk = new RevWalk(RebaseInteractiveView.this.currentRepository)) {
Collection<ObjectId> resolved = walk.getObjectReader().resolve(abbreviatedObjectId);
if (resolved.size() == 1) {
RevCommit commit = walk.parseCommit(resolved.iterator().next());
return new RepositoryCommit(RebaseInteractiveView.this.currentRepository, commit);
}
} catch (IOException e) {
return null;
}
}
return null;
}
});
prefListener = new IPreferenceChangeListener() {
@Override
public void preferenceChange(PreferenceChangeEvent event) {
if (!RepositoryUtil.PREFS_DIRECTORIES_REL.equals(event.getKey())) {
return;
}
final Repository repo = currentRepository;
if (repo == null)
return;
if (Activator.getDefault().getRepositoryUtil().contains(repo))
return;
// Unselect repository as it has been removed
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
currentRepository = null;
showRepository(null);
}
});
}
};
InstanceScope.INSTANCE.getNode(org.eclipse.egit.core.Activator.getPluginId()).addPreferenceChangeListener(prefListener);
uiPrefsListener = new IPropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent event) {
String property = event.getProperty();
if (UIPreferences.DATE_FORMAT.equals(property) || UIPreferences.DATE_FORMAT_CHOICE.equals(property) || UIPreferences.RESOURCEHISTORY_SHOW_RELATIVE_DATE.equals(property)) {
refresh();
}
}
};
Activator.getDefault().getPreferenceStore().addPropertyChangeListener(uiPrefsListener);
IActionBars actionBars = getViewSite().getActionBars();
IToolBarManager toolbar = actionBars.getToolBarManager();
listenOnRepositoryViewSelection = RebaseInteractivePreferences.isReactOnSelection();
// link with selection
Action linkSelectionAction = new BooleanPrefAction((IPersistentPreferenceStore) Activator.getDefault().getPreferenceStore(), UIPreferences.REBASE_INTERACTIVE_SYNC_SELECTION, UIText.InteractiveRebaseView_LinkSelection) {
@Override
public void apply(boolean value) {
listenOnRepositoryViewSelection = value;
}
};
linkSelectionAction.setImageDescriptor(UIIcons.ELCL16_SYNCED);
toolbar.add(linkSelectionAction);
switchRepositoriesAction = new RepositoryToolbarAction(false, () -> currentRepository, repo -> setInput(new StructuredSelection(repo)));
toolbar.add(switchRepositoriesAction);
UIUtils.notifySelectionChangedWithCurrentSelection(selectionChangedListener, getSite());
getSite().setSelectionProvider(new RepositorySelectionProvider(planTreeViewer, () -> currentRepository));
}
use of org.eclipse.egit.ui.internal.actions.BooleanPrefAction in project egit by eclipse.
the class CompareTreeView method createActions.
private void createActions() {
IWorkbenchAction reuseCompareEditorAction = new CompareUtils.ReuseCompareEditorAction();
actionsToDispose.add(reuseCompareEditorAction);
getViewSite().getActionBars().getMenuManager().add(reuseCompareEditorAction);
compareModeAction = new BooleanPrefAction((IPersistentPreferenceStore) Activator.getDefault().getPreferenceStore(), UIPreferences.TREE_COMPARE_COMPARE_MODE, UIText.CompareTreeView_CompareModeTooltip) {
@Override
public void apply(boolean value) {
// nothing, just switch the preference
}
};
compareModeAction.setImageDescriptor(UIIcons.ELCL16_COMPARE_VIEW);
compareModeAction.setEnabled(true);
actionsToDispose.add(compareModeAction);
getViewSite().getActionBars().getToolBarManager().add(compareModeAction);
showEqualsAction = new BooleanPrefAction((IPersistentPreferenceStore) Activator.getDefault().getPreferenceStore(), UIPreferences.TREE_COMPARE_SHOW_EQUALS, UIText.CompareTreeView_EqualFilesTooltip) {
@Override
public void apply(boolean value) {
buildTrees(false);
}
};
showEqualsAction.setImageDescriptor(UIIcons.ELCL16_FILTER);
showEqualsAction.setEnabled(false);
actionsToDispose.add(showEqualsAction);
getViewSite().getActionBars().getToolBarManager().add(showEqualsAction);
IAction expandAllAction = new Action(UIText.CompareTreeView_ExpandAllTooltip) {
@Override
public void run() {
tree.expandAll();
}
};
expandAllAction.setImageDescriptor(UIIcons.EXPAND_ALL);
getViewSite().getActionBars().getToolBarManager().add(expandAllAction);
IAction collapseAllAction = new Action(UIText.CompareTreeView_CollapseAllTooltip) {
@Override
public void run() {
tree.collapseAll();
}
};
collapseAllAction.setImageDescriptor(UIIcons.COLLAPSEALL);
getViewSite().getActionBars().getToolBarManager().add(collapseAllAction);
}
use of org.eclipse.egit.ui.internal.actions.BooleanPrefAction in project egit by eclipse.
the class StagingView method updateToolbar.
private void updateToolbar() {
ControlContribution controlContribution = new ControlContribution(// $NON-NLS-1$
"StagingView.searchText") {
@Override
protected Control createControl(Composite parent) {
Composite toolbarComposite = toolkit.createComposite(parent, SWT.NONE);
toolbarComposite.setBackground(null);
GridLayout headLayout = new GridLayout();
headLayout.numColumns = 2;
headLayout.marginHeight = 0;
headLayout.marginWidth = 0;
headLayout.marginTop = 0;
headLayout.marginBottom = 0;
headLayout.marginLeft = 0;
headLayout.marginRight = 0;
toolbarComposite.setLayout(headLayout);
filterText = new Text(toolbarComposite, SWT.SEARCH | SWT.ICON_CANCEL | SWT.ICON_SEARCH);
filterText.setMessage(UIText.StagingView_Find);
GridData data = new GridData(GridData.FILL_HORIZONTAL);
data.widthHint = 150;
filterText.setLayoutData(data);
final Display display = Display.getCurrent();
filterText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
filterPattern = wildcardToRegex(filterText.getText());
final StagingViewSearchThread searchThread = new StagingViewSearchThread(StagingView.this);
display.timerExec(200, new Runnable() {
@Override
public void run() {
searchThread.start();
}
});
}
});
return toolbarComposite;
}
};
IActionBars actionBars = getViewSite().getActionBars();
IToolBarManager toolbar = actionBars.getToolBarManager();
toolbar.add(controlContribution);
refreshAction = new Action(UIText.StagingView_Refresh, IAction.AS_PUSH_BUTTON) {
@Override
public void run() {
if (cacheEntry != null) {
schedule(cacheEntry.createRefreshResourcesAndIndexDiffJob(), false);
}
}
};
refreshAction.setImageDescriptor(UIIcons.ELCL16_REFRESH);
toolbar.add(refreshAction);
// link with selection
Action linkSelectionAction = new BooleanPrefAction((IPersistentPreferenceStore) getPreferenceStore(), UIPreferences.STAGING_VIEW_SYNC_SELECTION, UIText.StagingView_LinkSelection) {
@Override
public void apply(boolean value) {
reactOnSelection = value;
}
};
linkSelectionAction.setImageDescriptor(UIIcons.ELCL16_SYNCED);
toolbar.add(linkSelectionAction);
toolbar.add(new Separator());
switchRepositoriesAction = new RepositoryToolbarAction(false, () -> realRepository, repo -> {
if (realRepository != repo) {
reload(repo);
}
});
toolbar.add(switchRepositoriesAction);
compareModeAction = new Action(UIText.StagingView_CompareMode, IAction.AS_CHECK_BOX) {
@Override
public void run() {
getPreferenceStore().setValue(UIPreferences.STAGING_VIEW_COMPARE_MODE, isChecked());
}
};
compareModeAction.setImageDescriptor(UIIcons.ELCL16_COMPARE_VIEW);
compareModeAction.setChecked(getPreferenceStore().getBoolean(UIPreferences.STAGING_VIEW_COMPARE_MODE));
toolbar.add(compareModeAction);
toolbar.add(new Separator());
openNewCommitsAction = new Action(UIText.StagingView_OpenNewCommits, IAction.AS_CHECK_BOX) {
@Override
public void run() {
getPreferenceStore().setValue(UIPreferences.STAGING_VIEW_SHOW_NEW_COMMITS, isChecked());
}
};
openNewCommitsAction.setChecked(getPreferenceStore().getBoolean(UIPreferences.STAGING_VIEW_SHOW_NEW_COMMITS));
columnLayoutAction = new Action(UIText.StagingView_ColumnLayout, IAction.AS_CHECK_BOX) {
@Override
public void run() {
getPreferenceStore().setValue(UIPreferences.STAGING_VIEW_COLUMN_LAYOUT, isChecked());
stagingSashForm.setOrientation(isChecked() ? SWT.HORIZONTAL : SWT.VERTICAL);
}
};
columnLayoutAction.setChecked(getPreferenceStore().getBoolean(UIPreferences.STAGING_VIEW_COLUMN_LAYOUT));
fileNameModeAction = new Action(UIText.StagingView_ShowFileNamesFirst, IAction.AS_CHECK_BOX) {
@Override
public void run() {
final boolean enable = isChecked();
getLabelProvider(stagedViewer).setFileNameMode(enable);
getLabelProvider(unstagedViewer).setFileNameMode(enable);
getContentProvider(stagedViewer).setFileNameMode(enable);
getContentProvider(unstagedViewer).setFileNameMode(enable);
StagingEntryComparator comparator = (StagingEntryComparator) unstagedViewer.getComparator();
comparator.setFileNamesFirst(enable);
comparator = (StagingEntryComparator) stagedViewer.getComparator();
comparator.setFileNamesFirst(enable);
getPreferenceStore().setValue(UIPreferences.STAGING_VIEW_FILENAME_MODE, enable);
refreshViewersPreservingExpandedElements();
}
};
fileNameModeAction.setChecked(getPreferenceStore().getBoolean(UIPreferences.STAGING_VIEW_FILENAME_MODE));
IMenuManager dropdownMenu = actionBars.getMenuManager();
MenuManager presentationMenu = new MenuManager(UIText.StagingView_Presentation);
listPresentationAction = new Action(UIText.StagingView_List, IAction.AS_RADIO_BUTTON) {
@Override
public void run() {
if (!isChecked()) {
return;
}
switchToListMode();
refreshViewers();
}
};
listPresentationAction.setImageDescriptor(UIIcons.FLAT);
presentationMenu.add(listPresentationAction);
treePresentationAction = new Action(UIText.StagingView_Tree, IAction.AS_RADIO_BUTTON) {
@Override
public void run() {
if (!isChecked()) {
return;
}
presentation = Presentation.TREE;
setPresentation(presentation, false);
listPresentationAction.setChecked(false);
compactTreePresentationAction.setChecked(false);
setExpandCollapseActionsVisible(false, isExpandAllowed(false), true);
setExpandCollapseActionsVisible(true, isExpandAllowed(true), true);
refreshViewers();
}
};
treePresentationAction.setImageDescriptor(UIIcons.HIERARCHY);
presentationMenu.add(treePresentationAction);
compactTreePresentationAction = new Action(UIText.StagingView_CompactTree, IAction.AS_RADIO_BUTTON) {
@Override
public void run() {
if (!isChecked()) {
return;
}
switchToCompactModeInternal(false);
refreshViewers();
}
};
compactTreePresentationAction.setImageDescriptor(UIIcons.COMPACT);
presentationMenu.add(compactTreePresentationAction);
presentation = readPresentation(UIPreferences.STAGING_VIEW_PRESENTATION, Presentation.LIST);
switch(presentation) {
case LIST:
listPresentationAction.setChecked(true);
setExpandCollapseActionsVisible(false, false, false);
setExpandCollapseActionsVisible(true, false, false);
break;
case TREE:
treePresentationAction.setChecked(true);
break;
case COMPACT_TREE:
compactTreePresentationAction.setChecked(true);
break;
default:
break;
}
dropdownMenu.add(presentationMenu);
dropdownMenu.add(new Separator());
dropdownMenu.add(openNewCommitsAction);
dropdownMenu.add(columnLayoutAction);
dropdownMenu.add(fileNameModeAction);
dropdownMenu.add(compareModeAction);
actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), new GlobalDeleteActionHandler());
// For the normal resource undo/redo actions to be active, so that files
// deleted via the "Delete" action in the staging view can be restored.
IUndoContext workspaceContext = AdapterUtils.adapt(ResourcesPlugin.getWorkspace(), IUndoContext.class);
undoRedoActionGroup = new UndoRedoActionGroup(getViewSite(), workspaceContext, true);
undoRedoActionGroup.fillActionBars(actionBars);
actionBars.updateActionBars();
}
Aggregations