Lines 14-27
Link Here
|
14 |
import org.eclipse.core.resources.IFile; |
14 |
import org.eclipse.core.resources.IFile; |
15 |
import org.eclipse.core.resources.IResource; |
15 |
import org.eclipse.core.resources.IResource; |
16 |
import org.eclipse.core.runtime.IAdaptable; |
16 |
import org.eclipse.core.runtime.IAdaptable; |
|
|
17 |
import org.eclipse.jface.dialogs.*; |
17 |
import org.eclipse.jface.dialogs.Dialog; |
18 |
import org.eclipse.jface.dialogs.Dialog; |
18 |
import org.eclipse.jface.dialogs.DialogPage; |
|
|
19 |
import org.eclipse.jface.text.TextSelection; |
19 |
import org.eclipse.jface.text.TextSelection; |
20 |
import org.eclipse.jface.viewers.ISelection; |
20 |
import org.eclipse.jface.viewers.ISelection; |
21 |
import org.eclipse.jface.viewers.IStructuredSelection; |
21 |
import org.eclipse.jface.viewers.IStructuredSelection; |
22 |
import org.eclipse.pde.internal.core.search.*; |
22 |
import org.eclipse.pde.internal.core.search.*; |
23 |
import org.eclipse.pde.internal.ui.IHelpContextIds; |
23 |
import org.eclipse.pde.internal.ui.*; |
24 |
import org.eclipse.pde.internal.ui.PDEUIMessages; |
|
|
25 |
import org.eclipse.search.ui.*; |
24 |
import org.eclipse.search.ui.*; |
26 |
import org.eclipse.swt.SWT; |
25 |
import org.eclipse.swt.SWT; |
27 |
import org.eclipse.swt.events.*; |
26 |
import org.eclipse.swt.events.*; |
Lines 32-38
Link Here
|
32 |
|
31 |
|
33 |
public class PluginSearchPage extends DialogPage implements ISearchPage { |
32 |
public class PluginSearchPage extends DialogPage implements ISearchPage { |
34 |
|
33 |
|
|
|
34 |
private static final String DIALOG_SETTINGS = "org.eclipse.pde.internal.ui.search.PluginSearchPage"; //$NON-NLS-1$ |
35 |
private static final String PREVIOUS_QUERIES_SETTINGS_KEY = "previousQueries"; //$NON-NLS-1$ |
36 |
|
35 |
class QueryData { |
37 |
class QueryData { |
|
|
38 |
protected static final String SEPARATOR = "\n"; //$NON-NLS-1$ |
39 |
|
36 |
public String text; |
40 |
public String text; |
37 |
public boolean isCaseSensitive; |
41 |
public boolean isCaseSensitive; |
38 |
public int searchElement; |
42 |
public int searchElement; |
Lines 40-45
Link Here
|
40 |
public int externalScope; |
44 |
public int externalScope; |
41 |
public int workspaceScope; |
45 |
public int workspaceScope; |
42 |
public IWorkingSet[] workingSets; |
46 |
public IWorkingSet[] workingSets; |
|
|
47 |
|
48 |
/** |
49 |
* Returns the ordered fields of the object separated by newlines. |
50 |
* Newlines were chosen because the query text can not contain newlines |
51 |
* which means it is a safe character to split by. |
52 |
* |
53 |
* The names of selected working sets are added after the normal properties. |
54 |
*/ |
55 |
public String toString() { |
56 |
StringBuilder out = new StringBuilder(); |
57 |
out.append(text); |
58 |
out.append(SEPARATOR); |
59 |
out.append(isCaseSensitive); |
60 |
out.append(SEPARATOR); |
61 |
out.append(searchElement); |
62 |
out.append(SEPARATOR); |
63 |
out.append(limit); |
64 |
out.append(SEPARATOR); |
65 |
out.append(externalScope); |
66 |
out.append(SEPARATOR); |
67 |
out.append(workspaceScope); |
68 |
// add working sets to the end if there is any |
69 |
if (workingSets != null) { |
70 |
for (int i = 0; i < workingSets.length; i++) { |
71 |
out.append(SEPARATOR); |
72 |
out.append(workingSets[i].getName()); |
73 |
} |
74 |
} |
75 |
return out.toString(); |
76 |
} |
77 |
|
78 |
/** |
79 |
* Reads the string representation of the fields created |
80 |
* by the toString method. |
81 |
* @param data |
82 |
* @returns the success status of the read. false if the data was invalid. |
83 |
*/ |
84 |
public boolean readString(String data) { |
85 |
String[] parts = data.split(SEPARATOR); |
86 |
if (parts.length < 6) { |
87 |
return false; |
88 |
} |
89 |
text = parts[0]; |
90 |
isCaseSensitive = Boolean.parseBoolean(parts[1]); |
91 |
searchElement = Integer.parseInt(parts[2]); |
92 |
limit = Integer.parseInt(parts[3]); |
93 |
externalScope = Integer.parseInt(parts[4]); |
94 |
workspaceScope = Integer.parseInt(parts[5]); |
95 |
// if there are more than 6 they are selected working sets |
96 |
// look them up by name and add them to the array |
97 |
if (parts.length > 6) { |
98 |
IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager(); |
99 |
workingSets = new IWorkingSet[parts.length - 6]; |
100 |
// offset i by six to start after normal properties |
101 |
for (int i = 6; i < parts.length; i++) { |
102 |
IWorkingSet set = manager.getWorkingSet(parts[i]); |
103 |
if (set != null) { |
104 |
workingSets[i - 6] = set; |
105 |
} |
106 |
} |
107 |
} |
108 |
return true; |
109 |
} |
43 |
|
110 |
|
44 |
public boolean equals(Object obj) { |
111 |
public boolean equals(Object obj) { |
45 |
if (obj instanceof QueryData) { |
112 |
if (obj instanceof QueryData) { |
Lines 72-77
Link Here
|
72 |
createPatternSection(result); |
139 |
createPatternSection(result); |
73 |
createSettingsSection(result); |
140 |
createSettingsSection(result); |
74 |
|
141 |
|
|
|
142 |
restorePreviousQueries(); // load from dialog settings |
75 |
hookListeners(); |
143 |
hookListeners(); |
76 |
|
144 |
|
77 |
setControl(result); |
145 |
setControl(result); |
Lines 247-252
Link Here
|
247 |
|
315 |
|
248 |
public boolean performAction() { |
316 |
public boolean performAction() { |
249 |
saveQueryData(); |
317 |
saveQueryData(); |
|
|
318 |
// Save the queries array to persistent storage |
319 |
savePreviousQueries(); |
250 |
NewSearchUI.activateSearchResultView(); |
320 |
NewSearchUI.activateSearchResultView(); |
251 |
NewSearchUI.runQueryInBackground(new PluginSearchQuery(getInput())); |
321 |
NewSearchUI.runQueryInBackground(new PluginSearchQuery(getInput())); |
252 |
return true; |
322 |
return true; |
Lines 292-297
Link Here
|
292 |
previousQueries.remove(0); |
362 |
previousQueries.remove(0); |
293 |
} |
363 |
} |
294 |
|
364 |
|
|
|
365 |
/** |
366 |
* Saves the previousQueries array to IDialogSettings. |
367 |
* Serializes the QueryData objects into an array of strings. |
368 |
*/ |
369 |
private void savePreviousQueries() { |
370 |
IDialogSettings settings = getDialogSettings(); |
371 |
String[] items = new String[previousQueries.size()]; |
372 |
// build up the items array by serializing each query |
373 |
for (int i = 0; i < previousQueries.size(); i++) { |
374 |
QueryData item = (QueryData) previousQueries.get(i); |
375 |
items[i] = item.toString(); |
376 |
} |
377 |
|
378 |
settings.put(PREVIOUS_QUERIES_SETTINGS_KEY, items); |
379 |
} |
380 |
|
381 |
/** |
382 |
* Restores the dialog from IDialogSettings. |
383 |
* Destroys the previousQueries array and rebuilds it from persistent storage. |
384 |
*/ |
385 |
private void restorePreviousQueries() { |
386 |
IDialogSettings settings = getDialogSettings(); |
387 |
String[] items = settings.getArray(PREVIOUS_QUERIES_SETTINGS_KEY); |
388 |
if (items == null) { |
389 |
return; // no previous data to load |
390 |
} |
391 |
previousQueries.clear(); |
392 |
// build up the previousQueries array by serializing each query |
393 |
for (int i = 0; i < items.length; i++) { |
394 |
String itemdata = items[i]; |
395 |
QueryData newData = new QueryData(); |
396 |
boolean success = newData.readString(itemdata); |
397 |
if (success) |
398 |
previousQueries.add(newData); |
399 |
} |
400 |
} |
401 |
|
402 |
protected IDialogSettings getDialogSettings() { |
403 |
IDialogSettings settings = PDEPlugin.getDefault().getDialogSettings().getSection(DIALOG_SETTINGS); |
404 |
|
405 |
if (settings == null) { |
406 |
settings = PDEPlugin.getDefault().getDialogSettings().addNewSection(DIALOG_SETTINGS); |
407 |
} |
408 |
|
409 |
return settings; |
410 |
} |
411 |
|
295 |
public void setContainer(ISearchPageContainer container) { |
412 |
public void setContainer(ISearchPageContainer container) { |
296 |
this.container = container; |
413 |
this.container = container; |
297 |
} |
414 |
} |