adding option for disabling completions, fixes #10

This commit is contained in:
Manindra Moharana
2013-08-25 18:36:37 +05:30
parent d0d3648c2d
commit 285f81db65
3 changed files with 21 additions and 1 deletions

View File

@@ -31,6 +31,7 @@ import java.util.List;
import java.util.Map;
import java.util.Stack;
import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.regex.Pattern;
import javax.swing.BorderFactory;
@@ -154,6 +155,7 @@ public class ASTGenerator {
setupGUI();
//addCompletionPopupListner();
addListeners(); loadJavaDoc();
predictionsEnabled = new AtomicBoolean(true);
}
protected void setupGUI(){
@@ -776,8 +778,10 @@ public class ASTGenerator {
*/
protected ArrayList<CompletionCandidate> candidates;
protected String lastPredictedWord = " ";
protected AtomicBoolean predictionsEnabled;
public void preparePredictions(final String word, final int line, final int lineStartNonWSOffset) {
if(!predictionsEnabled.get()) return;
// This method is called from TextArea.fetchPhrase, which is called via a SwingWorker instance
// in TextArea.processKeyEvent
if(caretWithinLineComment()){

View File

@@ -166,6 +166,11 @@ public class DebugEditor extends JavaEditor implements ActionListener {
*/
protected JCheckBoxMenuItem writeErrorLog;
/**
* Enable/Disable code completion
*/
protected JCheckBoxMenuItem completionsEnabled;
public DebugEditor(Base base, String path, EditorState state, Mode mode) {
super(base, path, state, mode);
@@ -521,6 +526,17 @@ public class DebugEditor extends JavaEditor implements ActionListener {
});
debugMenu.add(showWarnings);
completionsEnabled = new JCheckBoxMenuItem("Code Completion Enabled");
completionsEnabled.setSelected(true);
completionsEnabled.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
errorCheckerService.getASTGenerator().predictionsEnabled
.set(((JCheckBoxMenuItem) e.getSource()).isSelected());
}
});
debugMenu.add(completionsEnabled);
debugMessagesEnabled = new JCheckBoxMenuItem("Show Debug Messages");
debugMessagesEnabled.setSelected(ExperimentalMode.DEBUG);
debugMessagesEnabled.addActionListener(new ActionListener() {

View File

@@ -179,7 +179,7 @@ public class TextArea extends JEditTextArea {
}
super.processKeyEvent(evt);
if (evt.getID() == KeyEvent.KEY_TYPED) {
if (evt.getID() == KeyEvent.KEY_TYPED && editor.errorCheckerService.getASTGenerator().predictionsEnabled.get()) {
final KeyEvent evt2 = evt;
SwingWorker worker = new SwingWorker() {
protected Object doInBackground() throws Exception {