Bug 177806 - [Trim] Provide a way for a trim control to participate in commands/handler
Summary: [Trim] Provide a way for a trim control to participate in commands/handler
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.3   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 3.3 M6   Edit
Assignee: Paul Webster CLA
QA Contact:
URL:
Whiteboard:
Keywords: api
: 154268 (view as bug list)
Depends on:
Blocks: 152736
  Show dependency tree
 
Reported: 2007-03-16 13:58 EDT by Paul Webster CLA
Modified: 2007-03-21 12:38 EDT (History)
4 users (show)

See Also:


Attachments
Proposed API v01 (7.36 KB, patch)
2007-03-16 14:06 EDT, Paul Webster CLA
no flags Details | Diff
Actual (mostly) working code v01 (17.84 KB, patch)
2007-03-16 14:07 EDT, Paul Webster CLA
no flags Details | Diff
Proposed API v02 (2.95 KB, patch)
2007-03-16 15:46 EDT, Paul Webster CLA
no flags Details | Diff
Focus Service implementation v02 (12.99 KB, patch)
2007-03-16 15:47 EDT, Paul Webster CLA
no flags Details | Diff
Focus Service implementation v03 (13.85 KB, patch)
2007-03-16 16:22 EDT, Paul Webster CLA
no flags Details | Diff
Focus Service implementation v04 (12.93 KB, patch)
2007-03-17 09:17 EDT, Paul Webster CLA
no flags Details | Diff
Focus Service implementation v05 (13.15 KB, patch)
2007-03-19 07:32 EDT, Paul Webster CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Webster CLA 2007-03-16 13:58:59 EDT
When a trim control has focus, it should be able to specify that its handlers are active.

PW
Comment 1 Paul Webster CLA 2007-03-16 14:06:31 EDT
Created attachment 61144 [details]
Proposed API v01

This is the proposed API for tracking the registered in focus control.

PW
Comment 2 Paul Webster CLA 2007-03-16 14:07:14 EDT
Created attachment 61145 [details]
Actual (mostly) working code v01

This is the backing that I'm working on ... in progress.
PW
Comment 3 Paul Webster CLA 2007-03-16 15:46:09 EDT
Created attachment 61155 [details]
Proposed API v02

This is the API proposal:  2 constants on ISources plus the IFocusService.

When the trim control(s) are created, they call the IFocusService:
Text tw = ...;
IFocusService fc = (IFocusService) getWorkbenchWindow().getService(
		IFocusService.class);
fc.addTrackerFor(tw, getId());

Then they can create expressions and use them to use their own handlers.  ACTIVE_FOCUS_CONTROL_ID is one of the highest priorities for resolving conflicts.

For example, to provide a widget paste handler to the control registered as org.eclipse.ui.tests.focusText:

<handler
      class="org.eclipse.ui.internal.handlers.WidgetMethodHandler:paste"
      commandId="org.eclipse.ui.edit.paste">
   <activeWhen>
      <with variable="activeFocusControlId">
         <equals value="org.eclipse.ui.tests.focusText"/>
      </with>
   </activeWhen>
</handler>

PW
Comment 4 Paul Webster CLA 2007-03-16 15:47:12 EDT
Created attachment 61156 [details]
Focus Service implementation v02

The implementation patch.
PW
Comment 5 Paul Webster CLA 2007-03-16 16:22:16 EDT
Created attachment 61159 [details]
Focus Service implementation v03

Updated patch with constants for default cut/copy/paste/selectAll behaviour.
PW
Comment 6 Mike Wilson CLA 2007-03-16 17:13:02 EDT
+1
Comment 7 Paul Webster CLA 2007-03-17 09:17:01 EDT
Created attachment 61190 [details]
Focus Service implementation v04

Update service with some more documentation.  The API now consists of 2 constants in org.eclipse.ui.ISources, and the IFocusService interface.

It contains 4 constants whose values can be used to provide default cut/copy/paste/selectAll behaviour.  It also contains 2 methods to add and remove a control from the focus service.

PW
Comment 8 Paul Webster CLA 2007-03-17 09:37:32 EDT
Dani, I'm interested in your opinion on this Focus service.  Our first usecase is to allow a trim widget that has focus to specify its own commands and provide handlers to known commands (like cut/copy/paste).

But it's written in such a way that any Control that can take focus can have commands and handlers associated with it.

PW
Comment 9 Dani Megert CLA 2007-03-19 04:37:12 EDT
re: IFocusService: reading its Javadoc and not being familiar with the internals it is not quite clear what 'track' actually means. Why is it in ui.menus? Is it restricted to menus?

Would this mechanism also allow to generally extend an SWT widget with a command? An interesting use case is for example to provide camel case navigation actions for standard SWT controls. Currently JDT UI has its own hacks to provide this and of course this only works in wizards and dialogs provided by JDT UI.
Comment 10 Paul Webster CLA 2007-03-19 07:32:14 EDT
Created attachment 61272 [details]
Focus Service implementation v05

Minor modification to the patch.  Let's try org.eclipse.ui.swt.IFocusService since it's specifically to handle SWT controls.  And I've slighly re-worded the addFocusTracker(*) javadoc.

PW
Comment 11 Paul Webster CLA 2007-03-19 07:47:12 EDT
(In reply to comment #9)
> re: IFocusService: reading its Javadoc and not being familiar with the
> internals it is not quite clear what 'track' actually means. Why is it in
> ui.menus? Is it restricted to menus?

I've moved it to an org.eclipse.ui.swt package, since it's actually an SWT Control service.


> Would this mechanism also allow to generally extend an SWT widget with a
> command? An interesting use case is for example to provide camel case
> navigation actions for standard SWT controls. Currently JDT UI has its own
> hacks to provide this and of course this only works in wizards and dialogs
> provided by JDT UI.

I guess it depends on what you mean by extend.  It provides a registered SWT control that's in focus as a variable (well, 2) for evaluation by the services.  That means it can be used in core expressions, and that it'll show up in the application context passed to a handler during execution.

It will allow an SWT control to provide its own handlers ... for as long as it's in focus.

You could use it to active a programmatic context contributed through the IContextService, or to activate a declarative or programmatic handler with an activeWhen clause.  In our case, we're activing appropriate handlers for cut/copy/paste/selectAll.

PW
Comment 12 Dani Megert CLA 2007-03-19 07:53:22 EDT
>I guess it depends on what you mean by extend.
I meant to contribute a command (and its action) to e.g. the SWT Text widget so that it's available globally in all Text widgets.
Comment 13 Paul Webster CLA 2007-03-19 08:15:08 EDT
(In reply to comment #12)
> I meant to contribute a command (and its action) to e.g. the SWT Text widget so
> that it's available globally in all Text widgets.

Ah, I see.  Initially it won't support that, since each Control has a unique ID.  However one of the enhancements we are considering post 3.3 is to allow multiple controls to specify the same ID.

Then all text widgets that registered with that ID would get all the same handlers (and their commands).

Should we consider allowing multiple controls to register the same ID now?

PW
Comment 14 Paul Webster CLA 2007-03-19 11:52:14 EDT
Released into HEAD for the 13:00 EDT I build.

I've removed the one-to-one restriction on controls to IDs, it's now many to one.

PW
Comment 15 Paul Webster CLA 2007-03-20 20:35:53 EDT
I20070320-1620
PW
Comment 16 Paul Webster CLA 2007-03-21 12:38:27 EDT
*** Bug 154268 has been marked as a duplicate of this bug. ***