Skip to main content
summaryrefslogtreecommitdiffstats
blob: c4809a44979661d78c436555fe2b8ca2072964c5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*******************************************************************************
 *  Copyright (c) 2000, 2009 IBM Corporation and others.
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  which accompanies this distribution, and is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 * 
 *  Contributors:
 *     IBM Corporation - initial API and implementation
 *     Anton Leherbauer (Wind River Systems)
 *     Sergey Prigogin  (Google)
 *     Andrew Ferguson  (Symbian)
 *******************************************************************************/
package org.eclipse.cdt.ui.text;

import org.eclipse.core.runtime.Preferences;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.IWordDetector;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.rules.WordRule;
import org.eclipse.jface.util.PropertyChangeEvent;

import org.eclipse.cdt.core.CCorePreferenceConstants;
import org.eclipse.cdt.ui.IPropertyChangeParticipant;

/**
 * Which words should be recognized as task tags is specified under {@link CCorePreferenceConstants#TODO_TASK_TAGS} as a
 * comma delimited list.
 * 
 * @see CCorePreferenceConstants#TODO_TASK_TAGS
 * @since 5.0
 * @deprecated This class doesn't properly implement parsing of task tags
 * (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=246846). It will be removed.
 */
@Deprecated
public final class TaskTagRule extends WordRule implements IPropertyChangeParticipant {	
	private static class TaskTagDetector implements IWordDetector {
		public boolean isWordStart(char c) {
			return Character.isLetter(c);
		}
		public boolean isWordPart(char c) {
			return Character.isLetter(c);
		}
	}

	/**
	 * Convenience method for extracting a list of words that should be recognized as 
	 * task labels from an {@link IPreferenceStore} and a backup {@link Preferences}
	 * @param preferenceStore
	 * @param corePreferences
	 * @return a list of words that should be recognized as task labels in the format
	 * expected by TaskTagRule
	 */
	public static String getTaskWords(IPreferenceStore preferenceStore, Preferences corePreferences) {
		String result= null;
		if (preferenceStore.contains(CCorePreferenceConstants.TODO_TASK_TAGS)) {
			result= preferenceStore.getString(CCorePreferenceConstants.TODO_TASK_TAGS);
		} else if (corePreferences != null) {
			result= corePreferences.getString(CCorePreferenceConstants.TODO_TASK_TAGS);
		}
		return result;
	}

	private IToken fToken;

	/**
	 * Creates a new task tag rule
	 * @param token the token to return for words recognized as task tags
	 * @param taskWords a comma delimited list of words to recognize as task tags
	 */
	public TaskTagRule(IToken token, String taskWords) {
		super(new TaskTagDetector(), Token.UNDEFINED);
		fToken= token;
		if( taskWords!= null) {
			addTaskTags(taskWords);
		}
	}

	/**
	 * Removes the current list of words that should be
	 * recognized as task tags.
	 */
	public void clearTaskTags() {
		fWords.clear();
	}

	/**
	 * Adds tags from the specified string as task tags.
	 * @param value a comma delimited list of words to recognize as task tags
	 */
	public void addTaskTags(String value) {
		String[] tasks= value.split(","); //$NON-NLS-1$
		for (int i= 0; i < tasks.length; i++) {
			if (tasks[i].length() > 0) {
				addWord(tasks[i], fToken);
			}
		}
	}

	/*
	 * @see org.eclipse.cdt.ui.IPropertyChangeParticipant#affectsBehavior(org.eclipse.jface.util.PropertyChangeEvent)
	 */
	public boolean affectsBehavior(PropertyChangeEvent event) {
		return event.getProperty().equals(CCorePreferenceConstants.TODO_TASK_TAGS);
	}

	/*
	 * @see org.eclipse.cdt.ui.IPropertyChangeParticipant#adaptToPreferenceChange(org.eclipse.jface.util.PropertyChangeEvent)
	 */
	public void adaptToPreferenceChange(PropertyChangeEvent event) {
		if (event.getProperty().equals(CCorePreferenceConstants.TODO_TASK_TAGS)) {
			Object value= event.getNewValue();

			if (value instanceof String) {
				clearTaskTags();
				addTaskTags((String) value);
			}
		}
	}
}

Back to the top