blob: e2e3022d94d44c6b4d9936d1e8fdc003ed06c740 (
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
|
/*******************************************************************************
* Copyright (c) 2004, 2007 Mylyn project committers 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
*******************************************************************************/
package org.eclipse.mylyn.internal.tasks.ui.editors;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
/**
* TODO this is used only for spell checking which is not yet implemented, therefore this is not properly tested
*
* @author Shawn Minto
*/
public class SpellingDialog extends Dialog {
private final String title;
private Text wordToFix;
private List suggestions;
private final IDocument document;
private ICompletionProposal[] proposals;
protected SpellingDialog(Shell parentShell, String title, IDocument document) {
super(parentShell);
this.title = title;
this.document = document;
}
@Override
protected Control createDialogArea(Composite parent) {
Control c = super.createDialogArea(parent);
Composite spellingComposite = new Composite(parent, SWT.NONE);
GridLayout spellingLayout = new GridLayout();
spellingLayout.numColumns = 1;
spellingComposite.setLayout(spellingLayout);
wordToFix = new Text(spellingComposite, SWT.BORDER | SWT.READ_ONLY);
GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
gd.widthHint = 150;
wordToFix.setLayoutData(gd);
suggestions = new List(spellingComposite, SWT.BORDER);
gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
gd.widthHint = 150;
gd.heightHint = 120;
suggestions.setLayoutData(gd);
return c;
}
@Override
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
newShell.setText(title);
}
public void open(String word, ICompletionProposal[] proposals) {
create();
this.proposals = proposals;
wordToFix.setText(word);
suggestions.removeAll();
for (int i = 0; i < proposals.length; i++) {
suggestions.setItem(i, proposals[i].getDisplayString());
}
super.open();
}
@Override
protected void handleShellCloseEvent() {
if (getReturnCode() == Window.OK) {
int i = suggestions.getSelectionIndex();
if (i > 0 && i < proposals.length) {
proposals[i].apply(document);
}
}
super.handleShellCloseEvent();
}
}
|