Skip to content

Commit

Permalink
Show dedicated indicator in tabs of dirty parts
Browse files Browse the repository at this point in the history
Tabs render dirty parts by showing a `*` in front of the tab name (e.g.,
in front of the file name.

This information is hard to see by developers. This change introduces a
graphical indicator on the close button to highlight dirty (unsaved)
changes.

Furthermore, introduction of a new preference "Indicate unsaved changes
by overlaying the close button" in section "Appearance".

If preference "Indicate unsaved changes by overlaying the close button"
is set and there are unsaved changes in the editor, the "dirty"
indicator overlays the close button.

If the preference is not set (which is the default), the old behavior is
in place which indicates unsaved changes by character `*`.
  • Loading branch information
schneidermic0 committed Dec 18, 2024
1 parent b019337 commit 062378a
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 7 deletions.
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 @@ -122,6 +122,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 @@ -185,6 +187,8 @@ protected Control createContents(Composite parent) {
createHideIconsForViewTabs(comp);
createDependency(showFullTextForViewTabs, hideIconsForViewTabs);

createShowDiryIndicatorForTabs(comp);

createHiDPISettingsGroup(comp);

if (currentTheme != null) {
Expand Down Expand Up @@ -245,6 +249,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 @@ -361,6 +374,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 @@ -450,6 +464,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

0 comments on commit 062378a

Please sign in to comment.