PageRenderTime 100ms CodeModel.GetById 91ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/bundles/plugins-trunk/XInsert/src/SubVariableCommand.java

#
Java | 65 lines | 32 code | 8 blank | 25 comment | 12 complexity | ba94abb710f456fd8a64f79a6cadc2fc MD5 | raw file
 1/*
 2 *
 3 * SubVariableCommand.java
 4 * Copyright (C) 2001 Dominic Stolerman
 5 * dstolerman@jedit.org
 6 *
 7 * This program is free software; you can redistribute it and/or
 8 * modify it under the terms of the GNU General Public License
 9 * as published by the Free Software Foundation; either version 2
10 * of the License, or any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 */
21
22 
23import org.gjt.sp.jedit.*;
24
25/**
26 *
27 * @author  Dominic Stolerman
28 */
29public class SubVariableCommand extends Object implements Command {
30
31
32    /** Creates new SubVariableCommand */
33  public SubVariableCommand(String variable) {
34     this.variable = variable;
35     }
36
37    public void run(ScriptContext context) {
38      View parent = context.getView();
39      XTreeNode node = context.getNode();
40      String key = variable.substring(2, XScripter.findWordEnd(variable, 3, null));
41      String value;
42      boolean isTempValue = true;
43      if(variable.charAt(0) == '=') {
44         value = XScripter.getSubstituteFor(parent, key, node);
45         if (value == null)
46         value = "";
47         }
48      else if(variable.charAt(0) == '?') {
49         value = XScripter.getSubstituteFor(parent, key, (XTreeNode)node.getParent());
50         if(value == null) {
51           value = XScripter.showInputDialog(parent, key, node.getVariable(key));
52           node.addVariable(key, value);
53           }
54         }
55      else {
56         value = XScripter.getSubstituteFor(parent, key, node);
57         if(value == null)
58           value = key;
59         }
60      InsertTextCommand.insertText(value, context);
61    }
62    
63    private final String variable;
64}
65