Bug 296441 - [key-binding] provide template for inserting id of activate task
Summary: [key-binding] provide template for inserting id of activate task
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Mylyn (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P2 enhancement (vote)
Target Milestone: 3.4   Edit
Assignee: Andreas Höhmann CLA
QA Contact:
URL: http://sourceforge.net/apps/mantisbt/...
Whiteboard:
Keywords: bugday, contributed, helpwanted, noteworthy
Depends on:
Blocks:
 
Reported: 2009-11-30 05:12 EST by Andreas Höhmann CLA
Modified: 2017-03-21 02:01 EDT (History)
3 users (show)

See Also:


Attachments
Screenshot of my eclipse preferences (filtered for "template") (40.72 KB, image/png)
2009-12-15 05:25 EST, Andreas Höhmann CLA
no flags Details
first simple var-resolver for java and javadoc template-context (4.41 KB, patch)
2009-12-26 09:33 EST, Andreas Höhmann CLA
no flags Details | Diff
mylyn/context/zip (55.00 KB, application/octet-stream)
2009-12-26 09:33 EST, Andreas Höhmann CLA
no flags Details
error (16.77 KB, image/png)
2010-01-03 00:45 EST, Steffen Pingel CLA
no flags Details
second try (5.88 KB, patch)
2010-01-05 02:49 EST, Andreas Höhmann CLA
no flags Details | Diff
mylyn/context/zip (19.68 KB, application/octet-stream)
2010-01-05 02:50 EST, Andreas Höhmann CLA
no flags Details
third version (16.78 KB, patch)
2010-02-14 12:54 EST, Andreas Höhmann CLA
no flags Details | Diff
mylyn/context/zip (431.11 KB, application/octet-stream)
2010-02-14 12:54 EST, Andreas Höhmann CLA
no flags Details
configuration dialog (18.08 KB, image/png)
2010-05-22 20:07 EDT, Steffen Pingel CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Höhmann CLA 2009-11-30 05:12:15 EST
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)
Build Identifier: 

Hello,

this was a feature-request from the qc-mylyn project (see https://sourceforge.net/apps/mantisbt/qcmylyn/view.php?id=47):

"I would also advice some hotkey to give the current activated bug number, currently if don't display the task list i have no way of knowing which bug i'm working on, (so it would be nice maybe to add it to the title?)"

My comment was:
"I think this should be a mylyn feature request.
Such a feature could be done with the content-assist too.
Imagine you type "related to defect <ctrl+space>", then the shown list
contains "all known" bugs, and the current bug is preselect."

What do you think? Is there such a feature in mylyn?

Regards
Andreas

Reproducible: Always
Comment 1 Steffen Pingel CLA 2009-12-01 22:26:08 EST
Good idea. The task editor already has content assist that is populated with currently open bugs and the last 10 bugs from the activation history. I don't think there is much use for adding bug content assist to other editors. I can see however that it would be useful to have a key-binding to reference the current task.

In which editors would you expect the key-binding to work? What key-binding would you suggest and what would you expect to happen when the key-binding is pressed?
Comment 2 Andreas Höhmann CLA 2009-12-02 02:31:25 EST
(In reply to comment #1)
> Good idea. The task editor already has content assist that is populated with
> currently open bugs and the last 10 bugs from the activation history. I don't
> think there is much use for adding bug content assist to other editors. I can
> see however that it would be useful to have a key-binding to reference the
> current task.

Mylyn doesn't support such a bug list (ctrl+space) for the java editor?
Comment 3 elhanan Maayan CLA 2009-12-02 02:55:12 EST
(In reply to comment #1)
> Good idea. The task editor already has content assist that is populated with
> currently open bugs and the last 10 bugs from the activation history. I don't
> think there is much use for adding bug content assist to other editors. I can
> see however that it would be useful to have a key-binding to reference the
> current task.
> In which editors would you expect the key-binding to work? What key-binding
> would you suggest and what would you expect to happen when the key-binding is
> pressed?

well first of all the keybinding should be close to open Active Task one. 

on second thought i think it would much simpler, to have another variable in the templates after the same idea of current user current date and current time.
so the user would be able,so you'll have a variable for active task. and a variable for the prefix (perhaps the same variable, so it would generate a prepared link).

the variable should also be accissble in the xml templates at least , as well as jsp. 
thus you can reuse the same mechanism for quick templates as well as to  give the current active task

so the variable should like so:
${activetask}

and would give for example:
issue: 22123

assuming that 'issue' was the chosen prefix (in case of multiple prefixes allow only one to be generated in the template. so the user would be able to add more custom notes. you could also give other variable for commons tasks, like task.summery , or reported user and what not.

as a side note, i would suggest giving the bug id and title in eclipse title. or maybe in the status bar. to save screen space of task list view.
Comment 4 Andreas Höhmann CLA 2009-12-04 07:58:03 EST
> on second thought i think it would much simpler, to have another variable in
> the templates after the same idea of current user current date and current
> time.
> so the user would be able,so you'll have a variable for active task. and a
> variable for the prefix (perhaps the same variable, so it would generate a
> prepared link).

I guess such a "task-prefix" variable already exists:

${connector.task.prefix} - task-repository specific connector prefix

I see it in the "Tasks->Team->Commit Comment Template"

Steffen, can we configure this prefix via extension point?
At the moment our task-repo-prefix is hardcoded in our code (for task-hyperlink-detection: see https://bugs.eclipse.org/bugs/show_bug.cgi?id=296445)
Comment 5 Steffen Pingel CLA 2009-12-04 13:26:32 EST
That template uses the string that the connector returns in getTaskIdPrefix(). I am not sure what you mean by configure?
Comment 6 elhanan Maayan CLA 2009-12-05 11:20:50 EST
yes, i know, these are the  variables i had in mind, all one needs to expose them in the text templates so the would be available to all editors like java, xml etc,...



(In reply to comment #5)
> That template uses the string that the connector returns in getTaskIdPrefix().
> I am not sure what you mean by configure?

yy
Comment 7 Andreas Höhmann CLA 2009-12-06 04:05:13 EST
(In reply to comment #5)
> That template uses the string that the connector returns in getTaskIdPrefix().
> I am not sure what you mean by configure?

At the moment our QcRepositoryConnector doesn't overwrite the method. So we are using "task" per default.

Our QcRepositoryConnectorUi contains this code:

private static final Pattern ISSUE_PATTERN = Pattern.compile("((issue|bug|task|defect)\\s?)?#(\\d+)", Pattern.CASE_INSENSITIVE);

You see "task" is part of this pattern for "findHyperlinks".

But now we have 2 places in the code to maintain "repository-task-prefixes".

It would be nice to define this prefixes with a mylyn-core-extension point. Then one of these "configured" prefixes could be the "default-prefix".

In bug 296445 i try to describe this "feature request" :)

So the default code from mylyn should handle this task-prefix-stuff via extension-point and not with overwritten methods. This will cleanup the connector codes, reduce lines of code etc.
Comment 8 Steffen Pingel CLA 2009-12-09 14:08:45 EST
Andreas, let's keep the discussion for the extension point on bug 296445. 

Thanks for the input elhanan. As far as I understand you are suggesting a preference that would allow specifying a template. Wenn a configurable hotkey was pressed in text editors the corresponding text would be pasted at the current cursor position.
Comment 9 elhanan Maayan CLA 2009-12-09 16:44:34 EST
no, i'm saying forget the hotkey entirely, there are so many of them already in eclipse, it will be confusing.
i'm saying let's ride the template mechanism, all that needs to be done, is exposed  the same variables used in the commit message, to the preference section of templates, so when a user press insert variable when he design a template, along side the list to be selected from  lik %{user}, %{date}  etc... he would simply see these 4 variables as well. and that's it. so it would just like creating another template.  

(In reply to comment #8)
> Andreas, let's keep the discussion for the extension point on bug 296445. 
> Thanks for the input elhanan. As far as I understand you are suggesting a
> preference that would allow specifying a template. Wenn a configurable hotkey
> was pressed in text editors the corresponding text would be pasted at the
> current cursor position.
Comment 10 Steffen Pingel CLA 2009-12-09 16:59:04 EST
That sounds like a good idea but I'm not aware of a general template mechanism in Eclipse. As far as I can tell this would require implementing extensions for Ant, Java, and XML editors (but it would not work for text editors). Still this might be the best option as you point out.
Comment 11 Andreas Höhmann CLA 2009-12-09 17:12:56 EST
(In reply to comment #10)
> That sounds like a good idea but I'm not aware of a general template mechanism
> in Eclipse. As far as I can tell this would require implementing extensions for
> Ant, Java, and XML editors (but it would not work for text editors). Still this
> might be the best option as you point out.

Is quite simple to add a new placeholder for (java-)editor-templates.
For m2eclipse I implemented such a placeholder (here is the blog http://ahoehma.wordpress.com/2009/08/24/use-maven-artifact-version-in-eclipse-templates/).
Maybe other users will request more placeholders from the mylyn-context:
- current active task id
- current active task url
- what else?
Comment 12 Steffen Pingel CLA 2009-12-09 17:50:49 EST
Would you be interested in contributing a patch for this Andreas (check out http://wiki.eclipse.org/Mylyn_Contributor_Reference#Patches) ?
Comment 13 Andreas Höhmann CLA 2009-12-15 02:12:38 EST
(In reply to comment #12)
> Would you be interested in contributing a patch for this Andreas (check out
> http://wiki.eclipse.org/Mylyn_Contributor_Reference#Patches) ?
Yes :-) I will try to create such a placeholder provider.
Comment 14 elhanan Maayan CLA 2009-12-15 04:04:57 EST
i would recommend this feature should be available to all text editors (such as sql, xml files etc..) and not just java, as i've seen that some variables in java templates are not available in text templates.
(In reply to comment #13)
> (In reply to comment #12)
> > Would you be interested in contributing a patch for this Andreas (check out
> > http://wiki.eclipse.org/Mylyn_Contributor_Reference#Patches) ?
> Yes :-) I will try to create such a placeholder provider.
Comment 15 Andreas Höhmann CLA 2009-12-15 05:23:44 EST
(In reply to comment #14)
> i would recommend this feature should be available to all text editors (such as
> sql, xml files etc..) and not just java, as i've seen that some variables in
> java templates are not available in text templates.

You are right elhanan! :-)

We should create list for that.
(I guess its only a extension-point-configuration ... we can 
reuse the same place-holder-provider for all these template-contexts)
Here is a Screenshot of my eclipse (I searched for "template") ...
Steffen, what mylyn plugin would be the best place for the "mylyn-template-provider"?
Comment 16 Andreas Höhmann CLA 2009-12-15 05:25:46 EST
Created attachment 154464 [details]
Screenshot of my eclipse preferences (filtered for "template")

Our "active-task-id" template-placeholder can be add to this template-contexts ...
Comment 17 elhanan Maayan CLA 2009-12-15 05:53:43 EST
please make note that user would expect that for each place you add a template variables to be able to Press Ctrl-Link to it. 

i dobut that each mylyn provides such ability to every editor, but i still want that, however expect to see lots of features requests to add link capabilities for each such editor :)

(In reply to comment #16)
> Created an attachment (id=154464) [details]
> Screenshot of my eclipse preferences (filtered for "template")
> 
> Our "active-task-id" template-placeholder can be add to this template-contexts
> ...
Comment 18 Steffen Pingel CLA 2009-12-15 16:22:38 EST
Elhanan, the task id hyperlink detector is registered for textual editors and should work with all text editors that use the standard Eclipse hyperlink mechanism. 

Andreas, the right place for the template extension will depend on the nature of the integration. Can you provide a first cut of a template extension for the Java editor for the org.eclipse.mylyn.java.tasks plug-in?
Comment 19 Andreas Höhmann CLA 2009-12-26 09:33:47 EST
Created attachment 155050 [details]
first simple var-resolver for java and javadoc template-context
Comment 20 Andreas Höhmann CLA 2009-12-26 09:33:56 EST
Created attachment 155051 [details]
mylyn/context/zip
Comment 21 Andreas Höhmann CLA 2009-12-26 09:36:35 EST
With the patch it's possible to use the variable 'activeTask.id' in all java and javadoc templates.
I'm not sure if my implementation to get the active task is the right one, Steffen please check the code.
Comment 22 Steffen Pingel CLA 2010-01-03 00:45:55 EST
Created attachment 155177 [details]
error
Comment 23 Steffen Pingel CLA 2010-01-03 00:53:33 EST
The idea of the patch looks good to me but I wasn't able to make it work (see screenshot).

Here are some suggestions for improvement:

* Rename MylynTemplateVariableResolver to TasksTemplateVariableResolver.
* Call the template activeTaskKey instead of activeTask.id to make it more consistent with other templates.
* Consider providing a template for the task prefix as well. The prefix can be obtained by invoking TasksUiInternal.getTaskPrefix(). It returns "bug " for Bugzilla for instance.

Also note that patches should be created against the workspace root to make it easy to apply them: http://wiki.eclipse.org/Mylyn_Contributor_Reference#Patches .

If the "java" identifier in the patch is the only java specific dependency it could make sense to move this to the ide.ui plug-in instead to share the template resolver implemenation between ant, java, c++ etc.
Comment 24 Andreas Höhmann CLA 2010-01-05 02:49:54 EST
Created attachment 155305 [details]
second try

Thanks for the review steffen. I changed the code like you suggest and I add a new resolver for the "active task prefix". 

To get the prefix of the active task I used this:
final AbstractRepositoryConnector connector = TasksUi.getRepositoryManager().getRepositoryConnector(activeTask.getConnectorKind());
if (connector != null) {
 return connector.getTaskIdPrefix();
}
I found the code in org.eclipse.mylyn.internal.team.ui.templates.CommitTemplateVariables.
Comment 25 Andreas Höhmann CLA 2010-01-05 02:50:03 EST
Created attachment 155306 [details]
mylyn/context/zip
Comment 26 Steffen Pingel CLA 2010-01-26 10:00:01 EST
The patch is looking good. Here are some minor nits I noticed: Instead of calling activeTask.getTaskId() the template should use activeTask.getTaskKey() and to obtain the prefix it would be best to invoke TasksUiInternal.getTaskPrefix(activeTask.getConnectorKind()).

I got this exception when I inserted the template without having a task active. It seems that resolve() should return null instead of the empty string when a template can not be resolved:

org.eclipse.jface.text.BadLocationException
	at org.eclipse.jface.text.link.LinkedPositionGroup.enforceDisjoint(LinkedPositionGroup.java:148)
	at org.eclipse.jface.text.link.LinkedPositionGroup.enforceDisjoint(LinkedPositionGroup.java:162)
	at org.eclipse.jface.text.link.LinkedModeModel.enforceDisjoint(LinkedModeModel.java:306)
	at org.eclipse.jface.text.link.LinkedModeModel.addGroup(LinkedModeModel.java:418)
	at org.eclipse.jdt.internal.ui.text.template.contentassist.TemplateProposal.apply(TemplateProposal.java:264)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertProposal(CompletionProposalPopup.java:926)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertSelectedProposalWithMask(CompletionProposalPopup.java:877)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.verifyKey(CompletionProposalPopup.java:1304)
	at org.eclipse.jface.text.contentassist.ContentAssistant$InternalListener.verifyKey(ContentAssistant.java:806)
	at org.eclipse.jface.text.TextViewer$VerifyKeyListenersManager.verifyKey(TextViewer.java:489)
	at org.eclipse.swt.custom.StyledTextListener.handleEvent(StyledTextListener.java:62)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	
Can you add a simple test case that tests template resolution with an active task and no active task?

I also noticed a weirdness if the task key contains a "-",  e.g. for JIRA tasks the template "${activeTaskPrefix}${activeTaskKey}" was replaced by "issue DEMO - 2" instead of "issue DEMO-2".
Comment 27 Andreas Höhmann CLA 2010-01-29 02:26:48 EST
I moved the code to org.eclipse.mylyn.ide.ui (org.eclipse.mylyn.internal.ide.ui.TasksTemplateVariableResolver) and fixed the issues.

Now .... where can I put my testcase :) How can I mock the task-context (simulate active task with a "XYZ-repo") for tests? 
I can provide a simple jmock-based test (for that I must add some jar's to the org.eclipse.mylyn.ide.tests, is this ok?
Comment 28 Steffen Pingel CLA 2010-01-29 19:23:15 EST
It's probably simplest if you actually activate a task in the test case or change the implementation to allow you to provide a task (e.g. make a protected method getActiveTask()).
Comment 29 Andreas Höhmann CLA 2010-02-14 12:54:16 EST
Created attachment 159074 [details]
third version

I moved the resolve into the org.eclipse.mylyn.ide.ui plugin.
I created a unit test in org.eclipse.mylyn.ide.ui.tests plugin.
Steffen, please review again :-)
Comment 30 Andreas Höhmann CLA 2010-02-14 12:54:41 EST
Created attachment 159075 [details]
mylyn/context/zip
Comment 31 Andreas Höhmann CLA 2010-05-19 18:22:19 EDT
hihi, any new about this patch steffen?
Comment 32 Steffen Pingel CLA 2010-05-22 20:05:49 EDT
Thanks! The patch looks good to me. I have applied it with minor modifications.
Comment 33 Steffen Pingel CLA 2010-05-22 20:07:37 EDT
Created attachment 169601 [details]
configuration dialog
Comment 34 Mik Kersten CLA 2010-05-27 13:32:21 EDT
Nice feature!  Could we add this as a default template?
Comment 35 Steffen Pingel CLA 2010-05-28 17:42:16 EDT
(In reply to comment #34)
> Nice feature!  Could we add this as a default template?

Done. I have added a template called active_task that is active in the JavaDoc context by default.
Comment 36 Rhys Drummond CLA 2017-03-21 02:01:38 EDT
I know this is 7 years old, but this would be great to have in CDT.  I haven't been able to make it happen using the variables mentioned here; I'm guessing it's context specific.  

Are there any quick hacks I can do at my end to get that working in the C/C++ Context?

Neon.2