/[gzz]/gzz/lava/gzz/client/PotionFallbackBinder.java
ViewVC logotype

Diff of /gzz/lava/gzz/client/PotionFallbackBinder.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by benja, Mon Jan 6 12:11:46 2003 UTC revision 1.7 by benja, Tue Jan 7 21:49:08 2003 UTC
# Line 10  public class PotionFallbackBinder implem Line 10  public class PotionFallbackBinder implem
10      public static boolean dbg = false;      public static boolean dbg = false;
11      private static void pa(String s) { System.out.println(s); }      private static void pa(String s) { System.out.println(s); }
12    
13      public FunctionExpression currentFunctionExpression;      public Call currentCall;
14      public CommandCall currentCommand;      public Fallback.Win currentWin;
     public int currentWin;  
15    
16      public static Object NORMAL_MODE = new Object();      public static Object NORMAL_MODE = new Object();
17        public static Object PARAM_EDIT_MODE = new Object();
18      public static Object CHAR_KEY = new Object();      public static Object CHAR_KEY = new Object();
19      public static Object ANY_KEY = new Object();      public static Object ANY_KEY = new Object();
20    
# Line 24  public class PotionFallbackBinder implem Line 24  public class PotionFallbackBinder implem
24      protected Map bindingsByMode;      protected Map bindingsByMode;
25      public Object mode = NORMAL_MODE;      public Object mode = NORMAL_MODE;
26    
27        protected gzz.potion.potions.ConstantExpression currentParam;
28    
29      public Set markedCells = new HashSet();      public Set markedCells = new HashSet();
30    
31      /** An arrow key.      /** An arrow key.
# Line 52  public class PotionFallbackBinder implem Line 54  public class PotionFallbackBinder implem
54      public void keystroke(String k, Fallback.Win win) {      public void keystroke(String k, Fallback.Win win) {
55          if(dbg) pa("Key: "+k);          if(dbg) pa("Key: "+k);
56    
57            if(k.equals("Esc") || k.equals("Escape")) {
58                // The 'safety belt': Esc always returns to normal mode
59                mode = NORMAL_MODE;
60                fallback.windows[fallback.RIGHT].textCursor = -1;
61                currentCall = null;
62                currentWin = null;
63                AbstractUpdateManager.setNoAnimation();
64                AbstractUpdateManager.chg();
65                return;
66            }
67    
68            if(mode == PARAM_EDIT_MODE) {
69                String s = currentParam.getStringValue();
70    
71                if(k.length() == 1) {
72                    currentParam.setStringValue(s + k);
73                } else if(k.equals("Backspace") && s.length() > 0) {
74                    currentParam.setStringValue(s.substring(0, s.length() - 1));
75                } else if(k.equals("Tab") || k.equals("Tabulator")) {
76                    mode = NORMAL_MODE;
77    
78                    if(currentCall instanceof CommandCall &&
79                       currentCall.isComplete()) {
80                        if(dbg) pa("Execute: "+currentCall);
81                        Map context = getContext(currentWin, k);
82                        ((CommandCall)currentCall).execute(context);
83                        currentCall = null;
84                        currentWin = null;
85                    }
86                }
87    
88                AbstractUpdateManager.setNoAnimation();
89                AbstractUpdateManager.chg();
90                return;
91            } else if((k.equals("Tab") || k.equals("Tabulator")) &&
92                      mode == NORMAL_MODE && currentCall != null &&
93                      !currentCall.isComplete()) {
94                mode = PARAM_EDIT_MODE;
95                currentParam = new gzz.potion.potions.ConstantExpression("");
96                currentCall = currentCall.setNextParam(currentParam);
97                AbstractUpdateManager.setNoAnimation();
98                AbstractUpdateManager.chg();
99                return;
100            }
101    
102          Map bindings = (Map)bindingsByMode.get(mode);          Map bindings = (Map)bindingsByMode.get(mode);
103          Object binding = bindings.get(k);          Object binding = bindings.get(k);
104          if(binding == null && k.length() == 1)          if(binding == null && k.length() == 1)
# Line 62  public class PotionFallbackBinder implem Line 109  public class PotionFallbackBinder implem
109          if(dbg) pa("Binding: "+binding);          if(dbg) pa("Binding: "+binding);
110          if(binding == null) {          if(binding == null) {
111              // no binding for this key: clear pending              // no binding for this key: clear pending
112              currentCommand = null;              // XXX not until "Shift" etc. don't clear as well...
113                //currentCall = null;
114                //currentWin = null;
115              AbstractUpdateManager.chg();              AbstractUpdateManager.chg();
116          } else if(binding instanceof FunctionExpression){          } else if(binding instanceof FunctionCall){
117              FunctionExpression f = (FunctionExpression)binding;                FunctionCall f = (FunctionCall)binding;
118              if(currentCommand==null){              if(currentCall == null || currentCall.isComplete()){
119                  currentFunctionExpression = f;                  currentCall = f;
120              } else {              } else if(!currentCall.isComplete()) {
121                  Map context = getContext(fallback.windows[currentWin], k);                  currentCall = currentCall.setNextParam(f);
                 currentCommand = (CommandCall)currentCommand.setNextParam(f);  
                 if(currentCommand.isComplete()) {  
                     if(dbg) pa("Execute: "+currentCommand);  
                     currentCommand.execute(context);  
                     currentCommand = null;  
                 }  
122              }              }
123          } else if(binding instanceof Action) {          } else if(binding instanceof Action) {
124              Action action = (Action)binding;              Action action = (Action)binding;
125              currentCommand = action.command;  
126              currentWin = action.window;              if(currentCall instanceof FunctionCall &&
127              if(dbg) pa("Replaced currentCommand.");                 !action.command.isComplete())
128              if(currentFunctionExpression!=null)                  currentCall = changePrefix(action.command, (FunctionCall)currentCall);
129                  currentCommand = (CommandCall)currentCommand.setNextParam(currentFunctionExpression);              else
130              currentFunctionExpression=null;                  currentCall = action.command;
131              if(currentCommand.isComplete()) {  
132                  if(dbg) pa("Execute: "+currentCommand);              currentWin = fallback.windows[action.window];
133                  Map context = getContext(fallback.windows[currentWin], k);              if(dbg) pa("Replaced currentCall.");
                 currentCommand.execute(context);  
                 currentCommand = null;  
             }  
134          } else if(binding instanceof Arrow) {          } else if(binding instanceof Arrow) {
135              Arrow a = (Arrow)binding;              Arrow a = (Arrow)binding;
136              Fallback.Win w = fallback.windows[a.win];              Fallback.Win w = fallback.windows[a.win];
137              AbstractUpdateManager.prioritize(w.getScreen());              AbstractUpdateManager.prioritize(w.getScreen());
138    
139              if(currentCommand == null) {              if(currentCall == null) {
140                  if(dbg) pa("Move.");                  if(dbg) pa("Move.");
141                  Cell n = w.cursor.s(w.dims[a.axis], a.dir);                  Cell n = w.cursor.s(w.dims[a.axis], a.dir);
142                  if(n != null) w.cursor = n;                  if(n != null) w.cursor = n;
143                    // No call to AUM.setNoAnimation(): *Do* animate!
144                    AbstractUpdateManager.chg();
145                    return;
146                } else if(currentCall.isComplete()) {
147                    currentCall = null;
148                    currentWin = null;
149              } else {              } else {
150                  Map context = getContext(w, k);                  Map context = getContext(w, k);
151                  Type t = currentCommand.getNextParam();                  Type t = currentCall.getNextParam();
152                  FunctionExpression e = t.readDir(a.win, a.axis, a.dir, context);                  FunctionExpression e = t.readDir(a.win, a.axis, a.dir, context);
153                  if(dbg) pa("Read direction: "+e);                  if(dbg) pa("Read direction: "+e);
154                  if(e == null) {                  if(e == null) {
155                        currentCall = null; currentWin = null;
156                      AbstractUpdateManager.chg();                      AbstractUpdateManager.chg();
157                        AbstractUpdateManager.setNoAnimation();
158                      return;                      return;
159                  }                  }
160                  currentCommand = (CommandCall)currentCommand.setNextParam(e);                  currentCall = (CommandCall)currentCall.setNextParam(e);
161                  if(dbg) pa("Updated currentCommand: "+currentCommand);                  currentWin = w;
162                  if(currentCommand.isComplete()) {                  if(dbg) pa("Updated currentCall: "+currentCall);
                     if(dbg) pa("Execute: "+currentCommand);  
                     currentCommand.execute(context);  
                     currentCommand = null;  
                 }  
163              }              }
164            } else {
165                // XXX How to handle this right?
166                // Currently not user-friendly...
167                throw new Error("Unrecognized binding type");
168            }
169    
170            if(currentCall instanceof CommandCall && currentCall.isComplete()) {
171                if(dbg) pa("Execute: "+currentCall);
172                Map context = getContext(currentWin, k);
173                ((CommandCall)currentCall).execute(context);
174                currentCall = null;
175                currentWin = null;
176            } else {
177                AbstractUpdateManager.setNoAnimation();
178          }          }
179    
180          AbstractUpdateManager.chg();          AbstractUpdateManager.chg();
181      }      }
182    
183        /** Change any PrefixOrXXX in a call to a given value.
184         */
185        protected static Call changePrefix(Call call, FunctionCall value) {
186            Head h = call.head;
187            if(h instanceof gzz.potion.potions.PrefixFunction)
188                return value;
189    
190            FunctionExpression[] n = new FunctionExpression[call.params.length];
191            for(int i=0; i<n.length; i++) {
192                n[i] = call.params[i];
193                if(n[i] instanceof FunctionCall)
194                    n[i] = (FunctionCall)changePrefix((FunctionCall)n[i], value);
195            }
196    
197            if(call instanceof CommandCall)
198                return new CommandCall((Command)h, n);
199            else if(call instanceof FunctionCall)
200                return new FunctionCall((Function)h, n);
201            else
202                throw new IllegalArgumentException("Unknown Call type: "+call);
203        }
204    
205      public Map getContext(Fallback.Win win, String key) {      public Map getContext(Fallback.Win win, String key) {
206          Map context = new HashMap();          Map context = new HashMap();
207          context.put(Space.class, fallback.space);          context.put(Space.class, fallback.space);

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26