From 6a868fda84965046f0e2c4fabdd1c7374495341b Mon Sep 17 00:00:00 2001 From: handa Date: Wed, 7 Oct 2009 08:16:14 +0000 Subject: [PATCH] *** empty log message *** --- MInputMethod.cs | 156 +++++++++++++++++++++++++++++++++---------------------- input.cs | 9 ++-- 2 files changed, 98 insertions(+), 67 deletions(-) diff --git a/MInputMethod.cs b/MInputMethod.cs index 717cccf..6091f14 100644 --- a/MInputMethod.cs +++ b/MInputMethod.cs @@ -68,6 +68,7 @@ namespace M17N.Input 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"; @@ -317,30 +318,30 @@ namespace M17N.Input 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; } } @@ -404,20 +405,27 @@ namespace M17N.Input 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 ("\""); } } @@ -435,7 +443,6 @@ namespace M17N.Input if (description == null) description = "No description"; keys = new List (); - Console.WriteLine ("cmd:" + p); for (p = p.next; ! p.IsEmpty; p = p.next) { if (p.IsMText) @@ -1007,6 +1014,8 @@ namespace M17N.Input this.actions = actions; } } + + public override string ToString () { return (string) name; } } internal class Keymap @@ -1610,8 +1619,9 @@ namespace M17N.Input 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) { @@ -2258,14 +2268,19 @@ namespace M17N.Input 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; } @@ -2319,7 +2334,7 @@ namespace M17N.Input { internal static Xex.Symbol Qcandidates_group_size = "candidates-group-size"; - private MInputMethod im; + internal MInputMethod im; private Dictionary callbacks = new Dictionary (); @@ -2333,7 +2348,7 @@ namespace M17N.Input private int candidate_from, candidate_to; private bool candidate_show; - private List state_list = new List state_list (); + private List state_list = new List (); private Keymap keymap; // Sequence of input keys. @@ -2365,6 +2380,18 @@ namespace M17N.Input 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; @@ -2669,8 +2696,23 @@ namespace M17N.Input 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 (); @@ -2684,37 +2726,16 @@ namespace M17N.Input 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 (); @@ -2758,6 +2779,10 @@ namespace M17N.Input return candidates.Current; } + private void restore_state () + { + } + private bool handle_key () { State state = state_list[state_list.Count - 1]; @@ -2766,39 +2791,48 @@ namespace M17N.Input 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 () diff --git a/input.cs b/input.cs index 9cc52e7..172eb7c 100644 --- a/input.cs +++ b/input.cs @@ -26,14 +26,11 @@ public class Test Console.WriteLine (node.OuterXml); -#elif false +#elif true MInputMethod im = MInputMethod.Find ("vi", "telex"); - if (im.Info (out desc, out title, out vars, out cmds)) - { - Console.WriteLine ("{0}, {1}, {2}, {3}", desc, title, vars, cmds); - im.Open (); - } + im.Open (); + Console.WriteLine (im); #else MInputMethod[] ims = MInputMethod.List (); foreach (MInputMethod im in ims) -- 1.7.10.4