Skip to content

Improve UI Indication for Unsaved Changes in Tabs #2568

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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 @@ -72,7 +72,7 @@ public Font getFont(Object element) {
public String getText(Object element) {
if (element instanceof MDirtyable
&& ((MDirtyable) element).isDirty()) {
return "*" + ((MUILabel) element).getLocalizedLabel(); //$NON-NLS-1$
return ((MUILabel) element).getLocalizedLabel() + " ●"; //$NON-NLS-1$
}
return ((MUILabel) element).getLocalizedLabel();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,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> (render
* CTabFolder's with icons)
* </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 Expand Up @@ -616,6 +631,7 @@ void drawSelectedTab(int itemIndex, GC gc, Rectangle bounds) {
}

if (selectedTabHighlightColor != null) {
Color originalBackground = gc.getBackground();
gc.setBackground(selectedTabHighlightColor);
boolean highlightOnTop = drawTabHighlightOnTop;
if (onBottom) {
Expand All @@ -627,6 +643,7 @@ void drawSelectedTab(int itemIndex, GC gc, Rectangle bounds) {
int widthAdjustment = cornerSize == SQUARE_CORNER ? 0 : 1;
gc.fillRectangle(bounds.x + horizontalOffset, bounds.y + verticalOffset, bounds.width - widthAdjustment,
highlightHeight);
gc.setBackground(originalBackground);
}

if (backgroundPattern != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,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 Down Expand Up @@ -683,7 +684,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 @@ -822,6 +824,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
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ private PerspectiveLabelProvider getPerspectiveLabelProvider() {
/** Returns the text for the given {@link WorkbenchPartReference} */
protected String getWorkbenchPartReferenceText(WorkbenchPartReference ref) {
if (ref.isDirty()) {
return "*" + ref.getTitle(); //$NON-NLS-1$
return ref.getTitle() + " ●"; //$NON-NLS-1$
}
return ref.getTitle();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,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_preferences_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 @@ -82,6 +82,11 @@ public class WorkbookEditorsHandler extends FilteredTableBaseHandler {
*/
private static final String DIRTY_PREFIX = "*"; //$NON-NLS-1$

/**
* Prefix used to mark Editors that are dirty (unsaved changes).
*/
private static final String DIRTY_INDICATOR = " ●"; //$NON-NLS-1$

/**
* Used to signify that matching path segments have been omitted from modified
* file paths.
Expand Down Expand Up @@ -298,7 +303,7 @@ private Path getPathSegment(Integer segmentIndex, java.nio.file.Path path) {
*/
private String prependDirtyIndicationIfDirty(EditorReference editorReference, String labelText) {
if (editorReference.isDirty()) {
return DIRTY_PREFIX + labelText;
return labelText + DIRTY_INDICATOR; // DIRTY_PREFIX + labelText;
}
return labelText;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,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 @@ -186,6 +188,8 @@ protected Control createContents(Composite parent) {
createHideIconsForViewTabs(comp);
createDependency(showFullTextForViewTabs, hideIconsForViewTabs);

createShowDiryIndicatorForTabs(comp);

createHiDPISettingsGroup(comp);

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

protected void createShowDiryIndicatorForTabs(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_preferences_label);
showDirtyIndicatorForTabs = createCheckButton(composite,
WorkbenchMessages.ViewsPreference_showDirtyIndicatorForTabs, actualValue);
}

private boolean getSwtRendererPreference(String prefName, boolean defaultValue) {
return Platform.getPreferencesService().getBoolean(PREF_QUALIFIER_ECLIPSE_E4_UI_WORKBENCH_RENDERERS_SWT,
prefName, defaultValue, null);
Expand Down Expand Up @@ -362,6 +375,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 @@ -458,6 +472,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 @@ -682,7 +682,7 @@ String[] getText() {
text = new String[2];
if (editorRef != null) {
if (editorRef.isDirty()) {
text[0] = "*" + editorRef.getTitle(); //$NON-NLS-1$
text[0] = editorRef.getTitle() + " ●"; //$NON-NLS-1$
} else {
text[0] = editorRef.getTitle();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,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_showDirtyIndicatorForTabs = Indicate unsaved changes by overlaying the close button
ViewsPreference_viewTabs_preferences_label = Tab preferences:
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
*/
public class EditorElement extends QuickAccessElement {

private static final String DIRTY_MARK = "*"; //$NON-NLS-1$
// private static final String DIRTY_PREFIX = "*"; //$NON-NLS-1$
private static final String DIRTY_INDICATOR = " ●"; //$NON-NLS-1$

private IEditorReference editorReference;
private boolean dirty;
Expand Down Expand Up @@ -65,7 +66,8 @@ public ImageDescriptor getImageDescriptor() {

@Override
public String getLabel() {
return (dirty ? DIRTY_MARK : "") + editorReference.getTitle() + separator + editorReference.getTitleToolTip(); //$NON-NLS-1$
return editorReference.getTitle() + (dirty ? DIRTY_INDICATOR : "") + separator //$NON-NLS-1$
+ editorReference.getTitleToolTip();
}

@Override
Expand Down