|
Lines 11-19
Link Here
|
| 11 |
|
11 |
|
| 12 |
package org.eclipse.ui.internal.quickaccess; |
12 |
package org.eclipse.ui.internal.quickaccess; |
| 13 |
|
13 |
|
| 14 |
import java.util.ArrayList; |
|
|
| 15 |
import java.util.List; |
| 16 |
import java.util.StringTokenizer; |
| 17 |
|
14 |
|
| 18 |
import org.eclipse.jface.resource.ImageDescriptor; |
15 |
import org.eclipse.jface.resource.ImageDescriptor; |
| 19 |
|
16 |
|
|
Lines 35-54
Link Here
|
| 35 |
} |
32 |
} |
| 36 |
|
33 |
|
| 37 |
/** |
34 |
/** |
| 38 |
* @return a string containing the first character of every word for camel |
|
|
| 39 |
* case checking. |
| 40 |
*/ |
| 41 |
private static String getCamelCase(String label) { |
| 42 |
StringTokenizer tokenizer = new StringTokenizer(label); |
| 43 |
StringBuffer camelCase = new StringBuffer(); |
| 44 |
while (tokenizer.hasMoreTokens()) { |
| 45 |
String word = tokenizer.nextToken(); |
| 46 |
camelCase.append(word.charAt(0)); |
| 47 |
} |
| 48 |
return camelCase.toString().toLowerCase(); |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Returns the label to be displayed to the user. |
35 |
* Returns the label to be displayed to the user. |
| 53 |
* |
36 |
* |
| 54 |
* @return the label |
37 |
* @return the label |
|
Lines 95-109
Link Here
|
| 95 |
* @param filter |
78 |
* @param filter |
| 96 |
* @return |
79 |
* @return |
| 97 |
*/ |
80 |
*/ |
| 98 |
public QuickAccessEntry match(String filter, QuickAccessProvider providerForMatching) { |
81 |
public QuickAccessEntry match(String filter, |
| 99 |
String sortLabel = getSortLabel().toLowerCase(); |
82 |
QuickAccessProvider providerForMatching) { |
| 100 |
int index = sortLabel.indexOf(filter); |
83 |
String sortLabel = getLabel(); |
|
|
84 |
int index = sortLabel.toLowerCase().indexOf(filter); |
| 101 |
if (index != -1) { |
85 |
if (index != -1) { |
| 102 |
return new QuickAccessEntry(this, providerForMatching, new int[][] { { |
86 |
return new QuickAccessEntry(this, providerForMatching, |
| 103 |
index, index + filter.length() - 1 } }, EMPTY_INDICES); |
87 |
new int[][] { { index, index + filter.length() - 1 } }, |
|
|
88 |
EMPTY_INDICES); |
| 104 |
} |
89 |
} |
| 105 |
String combinedLabel = (providerForMatching.getName() + " " + getLabel()).toLowerCase(); //$NON-NLS-1$ |
90 |
String combinedLabel = (providerForMatching.getName() + " " + getLabel()); //$NON-NLS-1$ |
| 106 |
index = combinedLabel.indexOf(filter); |
91 |
index = combinedLabel.toLowerCase().indexOf(filter); |
| 107 |
if (index != -1) { |
92 |
if (index != -1) { |
| 108 |
int lengthOfElementMatch = index + filter.length() |
93 |
int lengthOfElementMatch = index + filter.length() |
| 109 |
- providerForMatching.getName().length() - 1; |
94 |
- providerForMatching.getName().length() - 1; |
|
Lines 112-132
Link Here
|
| 112 |
new int[][] { { 0, lengthOfElementMatch - 1 } }, |
97 |
new int[][] { { 0, lengthOfElementMatch - 1 } }, |
| 113 |
new int[][] { { index, index + filter.length() - 1 } }); |
98 |
new int[][] { { index, index + filter.length() - 1 } }); |
| 114 |
} |
99 |
} |
| 115 |
return new QuickAccessEntry(this, providerForMatching, EMPTY_INDICES, |
100 |
return new QuickAccessEntry(this, providerForMatching, |
| 116 |
new int[][] { { index, index + filter.length() - 1 } }); |
101 |
EMPTY_INDICES, new int[][] { { index, |
|
|
102 |
index + filter.length() - 1 } }); |
| 117 |
} |
103 |
} |
| 118 |
String camelCase = getCamelCase(sortLabel); |
104 |
String camelCase = CamelUtil.getCamelCase(sortLabel); |
| 119 |
index = camelCase.indexOf(filter); |
105 |
index = camelCase.indexOf(filter); |
| 120 |
if (index != -1) { |
106 |
if (index != -1) { |
| 121 |
int[][] indices = getCamelCaseIndices(sortLabel, index, filter |
107 |
int[][] indices = CamelUtil.getCamelCaseIndices(sortLabel, index, filter |
| 122 |
.length()); |
108 |
.length()); |
| 123 |
return new QuickAccessEntry(this, providerForMatching, indices, |
109 |
return new QuickAccessEntry(this, providerForMatching, indices, |
| 124 |
EMPTY_INDICES); |
110 |
EMPTY_INDICES); |
| 125 |
} |
111 |
} |
| 126 |
String combinedCamelCase = getCamelCase(combinedLabel); |
112 |
String combinedCamelCase = CamelUtil.getCamelCase(combinedLabel); |
| 127 |
index = combinedCamelCase.indexOf(filter); |
113 |
index = combinedCamelCase.indexOf(filter); |
| 128 |
if (index != -1) { |
114 |
if (index != -1) { |
| 129 |
String providerCamelCase = getCamelCase(providerForMatching |
115 |
String providerCamelCase = CamelUtil.getCamelCase(providerForMatching |
| 130 |
.getName()); |
116 |
.getName()); |
| 131 |
int lengthOfElementMatch = index + filter.length() |
117 |
int lengthOfElementMatch = index + filter.length() |
| 132 |
- providerCamelCase.length(); |
118 |
- providerCamelCase.length(); |
|
Lines 134-178
Link Here
|
| 134 |
return new QuickAccessEntry( |
120 |
return new QuickAccessEntry( |
| 135 |
this, |
121 |
this, |
| 136 |
providerForMatching, |
122 |
providerForMatching, |
| 137 |
getCamelCaseIndices(sortLabel, 0, lengthOfElementMatch), |
123 |
CamelUtil.getCamelCaseIndices(sortLabel, 0, lengthOfElementMatch), |
| 138 |
getCamelCaseIndices(providerForMatching.getName(), index, filter |
124 |
CamelUtil.getCamelCaseIndices(providerForMatching.getName(), |
| 139 |
.length() |
125 |
index, filter.length() - lengthOfElementMatch)); |
| 140 |
- lengthOfElementMatch)); |
|
|
| 141 |
} |
126 |
} |
| 142 |
return new QuickAccessEntry(this, providerForMatching, EMPTY_INDICES, |
127 |
return new QuickAccessEntry(this, providerForMatching, |
| 143 |
getCamelCaseIndices(providerForMatching.getName(), index, filter |
128 |
EMPTY_INDICES, CamelUtil.getCamelCaseIndices(providerForMatching |
| 144 |
.length())); |
129 |
.getName(), index, filter.length())); |
| 145 |
} |
130 |
} |
| 146 |
return null; |
131 |
return null; |
| 147 |
} |
132 |
} |
| 148 |
|
|
|
| 149 |
/** |
| 150 |
* @param camelCase |
| 151 |
* @param filter |
| 152 |
* @param index |
| 153 |
* @return |
| 154 |
*/ |
| 155 |
private int[][] getCamelCaseIndices(String original, int start, int length) { |
| 156 |
List result = new ArrayList(); |
| 157 |
int index = 0; |
| 158 |
while (start > 0) { |
| 159 |
index = original.indexOf(' ', index); |
| 160 |
while (original.charAt(index) == ' ') { |
| 161 |
index++; |
| 162 |
} |
| 163 |
start--; |
| 164 |
} |
| 165 |
while (length > 0) { |
| 166 |
result.add(new int[] { index, index }); |
| 167 |
index = original.indexOf(' ', index); |
| 168 |
if (index != -1) { |
| 169 |
while (index < original.length() |
| 170 |
&& original.charAt(index) == ' ') { |
| 171 |
index++; |
| 172 |
} |
| 173 |
} |
| 174 |
length--; |
| 175 |
} |
| 176 |
return (int[][]) result.toArray(new int[result.size()][]); |
| 177 |
} |
| 178 |
} |
133 |
} |