Skip to content
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

Add setToolTipText method to MenuItem #30

Closed
phermsdorf opened this issue Jul 5, 2022 · 8 comments · Fixed by #32
Closed

Add setToolTipText method to MenuItem #30

phermsdorf opened this issue Jul 5, 2022 · 8 comments · Fixed by #32
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@phermsdorf
Copy link
Contributor

Hi,

this method seems to be missing. The JavaDoc and method from SWT:

/**
 * Sets the receiver's tool tip text to the argument, which
 * may be null indicating that the default tool tip for the
 * control will be shown. For a menu item that has a default
 * tool tip, setting
 * the tool tip text to an empty string replaces the default,
 * causing no tool tip text to be shown.
 * <p>
 * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
 * To display a single '&amp;' in the tool tip, the character '&amp;' can be
 * escaped by doubling it in the string.
 * </p>
 * <p>
 * NOTE: Tooltips are currently not shown for top-level menu items in the
 * {@link Shell#setMenuBar(Menu) shell menubar} on Windows, Mac, and Ubuntu Unity desktop.
 * </p>
 * <p>
 * NOTE: This operation is a hint and behavior is platform specific, on Windows
 * for CJK-style mnemonics of the form " (&amp;C)" at the end of the tooltip text
 * are not shown in tooltip.
 * </p>
 * @param toolTip the new tool tip text (or null)
 *
 * @exception SWTException <ul>
 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
 * </ul>
 *
 * @since 3.104
 */
public void setToolTipText (String toolTip) {
	checkWidget();
	if (toolTip != null && (toolTip.trim().length() == 0 || toolTip.equals (toolTipText))) return;

	this.parent.getShell().setToolTipText (handle, (toolTipText = toolTip));
}

In RWT the handle is obviously missing.

Would be nice if that could be implemented. If someone would suggest a fix I could try to make a PR.

Thanks,
Bye Peter

@ifurnadjiev ifurnadjiev self-assigned this Jul 5, 2022
@ifurnadjiev ifurnadjiev added the enhancement New feature or request label Jul 5, 2022
@ifurnadjiev
Copy link
Contributor

Probably adding the method is enough. As seen from the code the toolTip text is set on the menu shell. Shell#setToolTipText is already available.

@phermsdorf
Copy link
Contributor Author

Compile-wise this works, but no Tooltip shows up when hovering over the MenuItems. (which works in SWT)
Should I anyway make a PR to integrate that as first step?

@ifurnadjiev
Copy link
Contributor

ifurnadjiev commented Jul 6, 2022

I've double checked the SWT implementation and it is different at least on Windows:

public void setToolTipText (String toolTip) {
	checkWidget ();
	if (toolTip == null && itemToolTip != null) {
		itemToolTip.setVisible (false);
		itemToolTip = null;
	}
	if (toolTip == null || toolTip.trim().length() == 0
			|| (itemToolTip != null && toolTip.equals(itemToolTip.getMessage()))) return;
	itemToolTip = new MenuItemToolTip (this.getParent().getShell());
	itemToolTip.setMessage (toolTip);
	itemToolTip.setVisible (false);
}

There is an internal class MenuItemToolTip extends ToolTip that handles the MenuItem tooltip.
The tooltip visibility is controlled by the method

void showTooltip (int x, int y) {
	if (itemToolTip == null) return;
	itemToolTip.setLocationInPixels (x, y);
	itemToolTip.setVisible (true);
}

which is called by the Menu class.

@ifurnadjiev
Copy link
Contributor

Maybe this is the way to go in RWT as well.

@ifurnadjiev
Copy link
Contributor

I'll try to come with complete JS implementation here, similar to the other widgets.

@phermsdorf
Copy link
Contributor Author

I tried to adapt that, but the tooltip does not show up when hovering over the MenuItem's.
I think "nobody" handles the hovering and calling getTooltipText().
I tried to adapt it like eg. ToolItems tooltip handling:

  • I added WidgetLCAUtil.preserveToolTipText( item, item.getToolTipText() ) in MenuItemLCA like it's done in ToolItemLCA
  • and added case "rwt.widgets.MenuItem": in
    getConfig : function( widget ) {
    if( widget.getParent() instanceof rwt.widgets.CoolBar ) {
    return this._getClickableConfig( widget );
    }
    switch( widget.classname ) {
    case "rwt.widgets.ControlDecorator":
    return this._quickConfig;
    case "rwt.widgets.Label":
    return this._getLabelConfig( widget );
    case "rwt.widgets.Button":
    case "rwt.widgets.TabItem":
    case "rwt.widgets.CTabItem":
    return this._getClickableConfig( widget );
    case "rwt.widgets.Text":
    case "rwt.widgets.Spinner":
    case "rwt.widgets.Combo":
    case "rwt.widgets.DateTimeDate":
    case "rwt.widgets.DateTimeTime":
    return this._fieldConfig;
    case "rwt.widgets.ToolItem":
    return this._getClickableConfig( widget );
    case "rwt.widgets.ProgressBar":

    like the ToolItem but it still does not work
    (not that I'm really knowing what I'm doing here but I just tried to do the same like ToolItem does ...)

Any ideas?

ifurnadjiev added a commit that referenced this issue Jul 6, 2022
Add new API:
- org.eclipse.swt.widgets.MenuItem.setToolTipText(String)
- org.eclipse.swt.widgets.MenuItem.getToolTipText()

To have a tooltip with markup, the RWT.TOOLTIP_MARKUP_ENABLED must be
set as data on the item.

Fix #30
@ifurnadjiev
Copy link
Contributor

@phermsdorf I've created a fully working implementation and a pull request. What is probably missing for you are the changes in MenuItemHandler.js.

@mknauer mknauer added this to the 3.22 milestone Jul 6, 2022
ifurnadjiev added a commit that referenced this issue Jul 6, 2022
Add new API:
- org.eclipse.swt.widgets.MenuItem.setToolTipText(String)
- org.eclipse.swt.widgets.MenuItem.getToolTipText()

To have a tooltip with markup, the RWT.TOOLTIP_MARKUP_ENABLED must be
set as data on the item.

Fix #30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants