private static Xex.Symbol Qrule = "rule";
private static Xex.Symbol Qkeyseq = "keyseq";
private static Xex.Symbol Qprogn = "progn";
+ private static Xex.Symbol Qcatch = "catch";
private static Xex.Symbol Qinsert = "insert";
private static Xex.Symbol Qinsert_candidates = "insert-candidates";
private static Xex.Symbol Qchar_at = "char-at";
public int ToChar ()
{
- return key & 0x1FFFFF;
+ return (int) (key & 0x1FFFFF);
}
public override string ToString ()
{
- string str = Char.ToString ((char) key);
+ MText mt = new MText (ToChar ());
KeyModifier m = ((KeyModifier) key) & KeyModifier.All;
if (m != KeyModifier.None)
{
if ((m & KeyModifier.Shift) != KeyModifier.None)
- str = "S-" + str;
+ mt.Ins (0, "S-");
if ((m & KeyModifier.Control) != KeyModifier.None)
- str = "C-" + str;
+ mt.Ins (0, "C-");
if ((m & KeyModifier.Alt) != KeyModifier.None)
- str = "A-" + str;
+ mt.Ins (0, "A-");
if ((m & KeyModifier.AltGr) != KeyModifier.None)
- str = "G-" + str;
+ mt.Ins (0, "G-");
if ((m & KeyModifier.Super) != KeyModifier.None)
- str = "s-" + str;
+ mt.Ins (0, "s-");
if ((m & KeyModifier.Hyper) != KeyModifier.None)
- str = "H-" + str;
+ mt.Ins (0, "H-");
}
- return str;
+ return (string) mt;
}
}
public override string ToString ()
{
- string str;
-
+ MText mt;
foreach (Key key in keyseq)
if (key.HasModifier)
{
- str = "(keyseq";
+ mt = "(";
foreach (Key k in keyseq)
- str += " " + k.ToString ();
- return str + ")";
+ {
+ if (mt.Length > 1)
+ mt.Cat (' ');
+ mt.Cat (k.ToString ());
+ }
+ return (string) mt.Cat (")");
}
- str = "\"";
- foreach (Key key in keyseq)
- str += key.ToString ();
- return str + "\"";
+ mt = "\"";
+ foreach (Key k in keyseq)
+ {
+ if (mt.Length > 1)
+ mt.Cat (' ');
+ mt.Cat (k.ToString ());
+ }
+ return (string) mt.Cat ("\"");
}
}
if (description == null)
description = "No description";
keys = new List<KeySeq> ();
- Console.WriteLine ("cmd:" + p);
for (p = p.next; ! p.IsEmpty; p = p.next)
{
if (p.IsMText)
this.actions = actions;
}
}
+
+ public override string ToString () { return (string) name; }
}
internal class Keymap
range = null;
else
{
- range = new int[pl.Count * 2];
- for (int i = 0; i < range.Length; i++)
+ int nrange = pl.Count;
+ range = new int[nrange * 2];
+ for (int i = 0; i < nrange; i++)
{
if (pl.IsPlist)
{
private static Xex.Term Fshift (Xex.Domain domain, Xex.Variable vari,
Xex.Term[] args)
{
- ((Context) domain.context).shift (args[0].Symval);
+ Context ic = (Context) domain.context;
+ State state;
+ if (ic.im.states.TryGetValue (args[0].Symval, out state))
+ ((Context) domain.context).shift (state);
+ else
+ throw new Exception ("Unknown state: " + args[0].Symval);
return args[0];
}
private static Xex.Term Fshiftback (Xex.Domain domain, Xex.Variable vari,
Xex.Term[] args)
{
- ((Context) domain.context).shiftback ();
+ ((Context) domain.context).shift (null);
return Tnil;
}
{
internal static Xex.Symbol Qcandidates_group_size
= "candidates-group-size";
- private MInputMethod im;
+ internal MInputMethod im;
private Dictionary<MSymbol, Callback> callbacks
= new Dictionary<MSymbol, Callback> ();
private int candidate_from, candidate_to;
private bool candidate_show;
- private List<State> state_list = new List<State> state_list ();
+ private List<State> state_list = new List<State> ();
private Keymap keymap;
// Sequence of input keys.
static MPlist callback_arg = new MPlist ();
+ static Xex.Term[] catch_args = new Xex.Term[2];
+
+ private bool take_action (Xex.Term[] actions)
+ {
+ catch_args[0] = Tcatch_tag;
+ catch_args[1]= new Xex.Term (domain, Qprogn, actions);
+ Xex.Term term = new Xex.Term (domain, Qcatch, catch_args);
+ term = term.Eval (domain);
+ return (! term.IsSymbol || term.Symval != Tcatch_tag.Symval);
+ }
+
+
private bool call_callback (MSymbol name, MPlist arg)
{
Callback callback;
changed |= ChangedStatus.Preedit;
}
- private void new_state (bool changed)
+ internal void shift (State state)
{
+ bool changed;
+
+ if (state == null)
+ {
+ if (state_list.Count > 1)
+ state_list.RemoveAt (state_list.Count - 1);
+ state = state_list[state_list.Count - 1];
+ changed = true;
+ }
+ else
+ {
+ changed = state != state_list[state_list.Count - 1];
+ if (changed)
+ state_list.Add (state);
+ }
if (state_list.Count == 1)
{
commit ();
state_var_values = domain.SaveValues ();
if (changed)
{
- State state = state_list[state_list.Count - 1];
status = state.title;
if (status == null)
status = im.title;
this.changed |= ChangedStatus.StateTitle;
if (state.enter_actions != null)
- on_entry.Eval (domain);
+ take_action (state.enter_actions);
}
}
}
- internal void shift (Xex.Symbol sym)
- {
- State state;
- bool changed;
-
- if (! im.states.TryGetValue (sym, out state))
- throw new Exception ("Unknown state: " + sym);
- changed = state != state_list[state_list.Count - 1];
- if (changed)
- state_list.Add (state);
- new_state (changed);
- }
-
- internal void shiftback ()
- {
- if (state_list.Count > 1)
- state_list.RemoveAt (state_list.Count - 1);
- new_state (true);
- }
-
internal void reset ()
{
preedit.Del ();
return candidates.Current;
}
+ private void restore_state ()
+ {
+ }
+
private bool handle_key ()
{
State state = state_list[state_list.Count - 1];
if (sub != keymap)
{
keymap = sub;
- if (keymap->map_actions)
+ if (keymap.map_actions != null)
{
restore_state ();
- if (! take_action (keymap->map_actions))
+ if (! take_action (keymap.map_actions))
return false;
}
- else if (keymap->submaps != null)
+ else if (keymap.submaps != null)
{
- for (int i = state_key_head; i < n; i++)
+ for (int i = state_key_head; i < key_head; i++)
preedit_replace (cursor_pos, cursor_pos,
keys.keyseq[i].ToChar ());
}
-
- if (keymap->submaps == null)
+ if (keymap.submaps == null)
{
- if (keymap->branch_actions != null)
+ if (keymap.branch_actions != null)
{
- if (! take_action (keymap->branch_actions))
+ if (! take_action (keymap.branch_actions))
return false;
}
- if (keymap != state->keymap)
- shift (state->name);
+ if (keymap != state.keymap)
+ shift (state);
}
}
else
{
- if (keymap->branch_actions)
+ if (keymap.branch_actions != null)
+ {
+ if (! take_action (keymap.branch_actions))
+ return false;
+ }
+ if (state == state_list[state_list.Count - 1])
{
- if (! take_action (keymap->branch_actions))
+ if (state == im.initial_state
+ && key_head < keys.keyseq.Count)
return false;
+ if (keymap != state.keymap)
+ shift (state);
+ else if (keymap.branch_actions == null)
+ shift (im.initial_state);
}
-
}
+ return true;
}
public bool Toggle ()