Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ public class CTabRendering extends CTabFolderRenderer implements ICTabRendering,
*/
public static final boolean SHOW_FULL_TEXT_FOR_VIEW_TABS_DEFAULT = false;

/**
* A named preference for setting CTabFolder's to be rendered with dirty
* indicator overlay on close button
* <p>
* The default value for this preference is: <code>false</code> (do not show
* dirty indicator)
* </p>
*/
public static final String SHOW_DIRTY_INDICATOR_ON_TABS = "SHOW_DIRTY_INDICATOR_ON_TABS"; //$NON-NLS-1$

/**
* Default value for "dirty indicator" preference for tabs
*/
public static final boolean SHOW_DIRTY_INDICATOR_ON_TABS_DEFAULT = false;

private static int MIN_VIEW_CHARS = 1;
private static int MAX_VIEW_CHARS = Integer.MAX_VALUE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.eclipse.e4.ui.internal.workbench.renderers.swt.SWTRenderersMessages;
import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
import org.eclipse.e4.ui.internal.workbench.swt.CSSConstants;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
import org.eclipse.e4.ui.model.application.ui.MElementContainer;
import org.eclipse.e4.ui.model.application.ui.MUIElement;
Expand Down Expand Up @@ -164,6 +165,8 @@ public class StackRenderer extends LazyStackRenderer {
@Preference(nodePath = CTabRendering.PREF_QUALIFIER_ECLIPSE_E4_UI_WORKBENCH_RENDERERS_SWT)
private IEclipsePreferences preferences;

private IEclipsePreferences.IPreferenceChangeListener dirtyIndicatorListener;

@Inject
@Named(WorkbenchRendererFactory.SHARED_ELEMENTS_STORE)
Map<MUIElement, Set<MPlaceholder>> renderedMap;
Expand Down Expand Up @@ -443,6 +446,11 @@ void subscribeTopicChildrenMoved(@UIEventTopic(UIEvents.ElementContainer.TOPIC_C

CTabItem newItem = new CTabItem(tabFolder, (showClose ? SWT.CLOSE : SWT.NONE), newIndex);
newItem.setText(text);
MPart part = movedElement instanceof MPart p ? p
: (MPart) ((MPlaceholder) movedElement).getRef();
if (part != null) {
newItem.setShowDirty(part.isDirty() && getShowDirtyIndicatorForTabsFromPreferences());
}
newItem.setImage(image);
newItem.setToolTipText(toolTipText);
newItem.setFont(font);
Expand Down Expand Up @@ -704,6 +712,39 @@ protected boolean requiresFocus(MPart element) {
@PostConstruct
public void init() {
super.init(eventBroker);
dirtyIndicatorListener = e -> {
if (CTabRendering.SHOW_DIRTY_INDICATOR_ON_TABS.equals(e.getKey())) {
synchronize.asyncExec(this::updateDirtyIndicatorStyle);
}
};
preferences.addPreferenceChangeListener(dirtyIndicatorListener);
}

private void updateDirtyIndicatorStyle() {
MApplication app = context.get(MApplication.class);
if (app == null) {
return;
}
List<MPartStack> stacks = modelService.findElements(app, null, MPartStack.class, null);
for (MPartStack stack : stacks) {
Object widget = stack.getWidget();
if (widget instanceof CTabFolder tabFolder) {
boolean showDirtyIndicator = getShowDirtyIndicatorForTabsFromPreferences();
tabFolder.setDirtyIndicatorStyle(showDirtyIndicator);
for (CTabItem item : tabFolder.getItems()) {
MUIElement element = (MUIElement) item.getData(OWNING_ME);
if (element == null) {
continue;
}
MPart part = element instanceof MPart p ? p : (MPart) ((MPlaceholder) element).getRef();
if (part == null) {
continue;
}
item.setShowDirty(part.isDirty() && showDirtyIndicator);
item.setText(getLabel(part, part.getLocalizedLabel()));
}
}
}
}

protected void updateTab(CTabItem cti, MPart part, String attName, Object newValue) {
Expand All @@ -715,6 +756,7 @@ protected void updateTab(CTabItem cti, MPart part, String attName, Object newVal
break;
case UIEvents.Dirtyable.DIRTY:
cti.setText(getLabel(part, part.getLocalizedLabel()));
cti.setShowDirty(part.isDirty() && getShowDirtyIndicatorForTabsFromPreferences());
break;
case UIEvents.UILabel.ICONURI:
changePartTabImage(part, cti);
Expand All @@ -741,6 +783,7 @@ private void changePartTabImage(MPart part, CTabItem item) {

@PreDestroy
public void contextDisposed() {
preferences.removePreferenceChangeListener(dirtyIndicatorListener);
super.contextDisposed(eventBroker);
}

Expand All @@ -751,7 +794,8 @@ private String getLabel(MUILabel itemPart, String newName) {
newName = LegacyActionTools.escapeMnemonics(newName);
}

if (itemPart instanceof MDirtyable && ((MDirtyable) itemPart).isDirty()) {
if (itemPart instanceof MDirtyable && ((MDirtyable) itemPart).isDirty()
&& !getShowDirtyIndicatorForTabsFromPreferences()) {
newName = '*' + newName;
}
return newName;
Expand Down Expand Up @@ -794,6 +838,7 @@ public Object createWidget(MUIElement element, Object parent) {
new DropTarget(dropZone, drop);
}
tabFolder.setMRUVisible(getMRUValue());
tabFolder.setDirtyIndicatorStyle(getShowDirtyIndicatorForTabsFromPreferences());

// Adjust the minimum chars based on the location
if (isInSharedArea) {
Expand Down Expand Up @@ -895,6 +940,11 @@ private boolean getMRUValueFromPreferences() {
return preferences.getBoolean(MRU_KEY, initialMRUValue);
}

private boolean getShowDirtyIndicatorForTabsFromPreferences() {
return preferences.getBoolean(CTabRendering.SHOW_DIRTY_INDICATOR_ON_TABS,
CTabRendering.SHOW_DIRTY_INDICATOR_ON_TABS_DEFAULT);
}

private void updateMRUValue(CTabFolder tabFolder) {
boolean actualMRUValue = getMRUValue();
tabFolder.setMRUVisible(actualMRUValue);
Expand Down Expand Up @@ -1060,6 +1110,7 @@ protected void createTab(MElementContainer<MUIElement> stack, MUIElement element

tabItem.setData(OWNING_ME, element);
tabItem.setText(getLabel(part, part.getLocalizedLabel()));
tabItem.setShowDirty(part.isDirty() && getShowDirtyIndicatorForTabsFromPreferences());
tabItem.setImage(getImage(part));

String toolTip = getToolTip(part);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,8 @@ public class WorkbenchMessages extends NLS {
public static String ViewsPreference_viewTabs_icons_and_titles_label;
public static String ViewsPreference_showFullTextForViewTabs;
public static String ViewsPreference_hideIconsForViewTabs;
public static String ViewsPreference_viewTabs_dirty_indicator_label;
public static String ViewsPreference_showDirtyIndicatorForTabs;
public static String ToggleFullScreenMode_ActivationPopup_Description;
public static String ToggleFullScreenMode_ActivationPopup_Description_NoKeybinding;
public static String ToggleFullScreenMode_ActivationPopup_DoNotShowAgain;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ public class ViewsPreferencePage extends PreferencePage implements IWorkbenchPre
private Button hideIconsForViewTabs;
private Button showFullTextForViewTabs;

private Button showDirtyIndicatorForTabs;

@Override
protected Control createContents(Composite parent) {
initializeDialogUnits(parent);
Expand Down Expand Up @@ -198,6 +200,8 @@ protected Control createContents(Composite parent) {
createHideIconsForViewTabs(comp);
createDependency(showFullTextForViewTabs, hideIconsForViewTabs);

createShowDirtyIndicatorForTabs(comp);

createRescaleAtRuntimeCheckButton(comp);

if (currentTheme != null) {
Expand Down Expand Up @@ -270,6 +274,15 @@ protected void createHideIconsForViewTabs(Composite composite) {
actualValue);
}

protected void createShowDirtyIndicatorForTabs(Composite composite) {
boolean actualValue = getSwtRendererPreference(CTabRendering.SHOW_DIRTY_INDICATOR_ON_TABS,
CTabRendering.SHOW_DIRTY_INDICATOR_ON_TABS_DEFAULT);
createLabel(composite, ""); //$NON-NLS-1$
createLabel(composite, WorkbenchMessages.ViewsPreference_viewTabs_dirty_indicator_label);
showDirtyIndicatorForTabs = createCheckButton(composite,
WorkbenchMessages.ViewsPreference_showDirtyIndicatorForTabs, actualValue);
}

private boolean getSwtRendererPreference(String prefName, boolean defaultValue) {
return Platform.getPreferencesService().getBoolean(CTabRendering.PREF_QUALIFIER_ECLIPSE_E4_UI_WORKBENCH_RENDERERS_SWT,
prefName, defaultValue, null);
Expand Down Expand Up @@ -455,6 +468,7 @@ public boolean performOk() {
}
prefs.putBoolean(CTabRendering.HIDE_ICONS_FOR_VIEW_TABS, hideIconsForViewTabs.getSelection());
prefs.putBoolean(CTabRendering.SHOW_FULL_TEXT_FOR_VIEW_TABS, showFullTextForViewTabs.getSelection());
prefs.putBoolean(CTabRendering.SHOW_DIRTY_INDICATOR_ON_TABS, showDirtyIndicatorForTabs.getSelection());
}

IPreferenceStore apiStore = PrefUtil.getAPIPreferenceStore();
Expand Down Expand Up @@ -605,6 +619,8 @@ protected void performDefaults() {
showFullTextForViewTabs.setSelection(defaultPrefs.getBoolean(CTabRendering.SHOW_FULL_TEXT_FOR_VIEW_TABS,
CTabRendering.SHOW_FULL_TEXT_FOR_VIEW_TABS_DEFAULT));
showFullTextForViewTabs.notifyListeners(SWT.Selection, null);
showDirtyIndicatorForTabs.setSelection(defaultPrefs.getBoolean(CTabRendering.SHOW_DIRTY_INDICATOR_ON_TABS,
CTabRendering.SHOW_DIRTY_INDICATOR_ON_TABS_DEFAULT));
}
IPreferenceStore apiStore = PrefUtil.getAPIPreferenceStore();
useColoredLabels.setSelection(apiStore.getDefaultBoolean(IWorkbenchPreferenceConstants.USE_COLORED_LABELS));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ ViewsPreference_enableMRU = Show &most recently used tabs
ViewsPreference_showFullTextForViewTabs = Always show full titles
ViewsPreference_hideIconsForViewTabs = Hide icons
ViewsPreference_viewTabs_icons_and_titles_label = Tab icons and titles in view areas:
ViewsPreference_viewTabs_dirty_indicator_label = Dirty indicator for view and editor tabs:
ViewsPreference_showDirtyIndicatorForTabs = Indicate unsaved changes by overlaying the close button
ToggleFullScreenMode_ActivationPopup_Description=You have gone full screen. Use the Toggle Full Screen command ({0}) to deactivate.
ToggleFullScreenMode_ActivationPopup_Description_NoKeybinding=You have gone full screen. Use the Toggle Full Screen command to deactivate.
ToggleFullScreenMode_ActivationPopup_DoNotShowAgain=Do not show again
Expand Down
Loading