protected virtual void InitKeyboards()
        {
            Dictionary <string, IbusKeyboardDescription> curKeyboards = KeyboardController.Instance.Keyboards.OfType <IbusKeyboardDescription>().ToDictionary(kd => kd.Id);

            foreach (IBusEngineDesc ibusKeyboard in GetIBusKeyboards())
            {
                string id = string.Format("{0}_{1}", ibusKeyboard.Language, ibusKeyboard.LongName);
                IbusKeyboardDescription existingKeyboard;
                if (curKeyboards.TryGetValue(id, out existingKeyboard))
                {
                    if (!existingKeyboard.IsAvailable)
                    {
                        existingKeyboard.SetIsAvailable(true);
                        existingKeyboard.IBusKeyboardEngine = ibusKeyboard;
                    }
                    curKeyboards.Remove(id);
                }
                else
                {
                    var keyboard = new IbusKeyboardDescription(id, ibusKeyboard, SwitchingAdaptor);
                    KeyboardController.Instance.Keyboards.Add(keyboard);
                }
            }

            foreach (IbusKeyboardDescription existingKeyboard in curKeyboards.Values)
            {
                existingKeyboard.SetIsAvailable(false);
            }
        }
		protected virtual void InitKeyboards()
		{
			Dictionary<string, IbusKeyboardDescription> curKeyboards = KeyboardController.Instance.Keyboards.OfType<IbusKeyboardDescription>().ToDictionary(kd => kd.Id);
			foreach (IBusEngineDesc ibusKeyboard in GetIBusKeyboards())
			{
				string id = string.Format("{0}_{1}", ibusKeyboard.Language, ibusKeyboard.LongName);
				IbusKeyboardDescription existingKeyboard;
				if (curKeyboards.TryGetValue(id, out existingKeyboard))
				{
					if (!existingKeyboard.IsAvailable)
					{
						existingKeyboard.SetIsAvailable(true);
						existingKeyboard.IBusKeyboardEngine = ibusKeyboard;
					}
					curKeyboards.Remove(id);
				}
				else
				{
					var keyboard = new IbusKeyboardDescription(id, ibusKeyboard, SwitchingAdaptor);
					KeyboardController.Instance.Keyboards.Add(keyboard);
				}
			}

			foreach (IbusKeyboardDescription existingKeyboard in curKeyboards.Values)
				existingKeyboard.SetIsAvailable(false);
		}
예제 #3
0
        private void RegisterKeyboards(IDictionary <string, uint> keyboards)
        {
            if (keyboards.Count <= 0)
            {
                return;
            }

            Dictionary <string, IbusKeyboardDescription> curKeyboards = KeyboardController.Instance.Keyboards.OfType <IbusKeyboardDescription>().ToDictionary(kd => kd.Id);
            List <string> missingLayouts = new List <string>(keyboards.Keys);

            foreach (var ibusKeyboard in GetAllIBusKeyboards())
            {
                if (keyboards.ContainsKey(ibusKeyboard.LongName))
                {
                    missingLayouts.Remove(ibusKeyboard.LongName);
                }
                else if (keyboards.ContainsKey(ibusKeyboard.Name) &&
                         ibusKeyboard.Name.StartsWith("xkb:", StringComparison.InvariantCulture))
                {
                    missingLayouts.Remove(ibusKeyboard.Name);
                }
                else
                {
                    continue;
                }

                string id = string.Format("{0}_{1}", ibusKeyboard.Language, ibusKeyboard.LongName);
                IbusKeyboardDescription keyboard;
                if (curKeyboards.TryGetValue(id, out keyboard))
                {
                    if (!keyboard.IsAvailable)
                    {
                        keyboard.SetIsAvailable(true);
                        keyboard.IBusKeyboardEngine = ibusKeyboard;
                    }
                    curKeyboards.Remove(id);
                }
                else
                {
                    keyboard = new IbusKeyboardDescription(id, ibusKeyboard, SwitchingAdaptor);
                    KeyboardController.Instance.Keyboards.Add(keyboard);
                }
                keyboard.SystemIndex = keyboards[ibusKeyboard.LongName];
            }

            foreach (IbusKeyboardDescription existingKeyboard in curKeyboards.Values)
            {
                existingKeyboard.SetIsAvailable(false);
            }

            foreach (var layout in missingLayouts)
            {
                Console.WriteLine("{0}: Didn't find {1}", GetType().Name, layout);
            }
        }
        // Has to be internal because IbusKeyboardDescription is only internal
        internal virtual bool IBusKeyboardAlreadySet(IbusKeyboardDescription keyboard)
        {
            if (keyboard == null || keyboard.IBusKeyboardEngine == null)
            {
                UnsetKeyboard();
                return(true);
            }

            // check our cached value
            return(GlobalCachedInputContext.Keyboard == keyboard);
        }
		// Has to be internal because IbusKeyboardDescription is only internal
		internal virtual bool IBusKeyboardAlreadySet(IbusKeyboardDescription keyboard)
		{
			if (keyboard == null || keyboard.IBusKeyboardEngine == null)
			{
				UnsetKeyboard();
				return true;
			}

			// check our cached value
			return GlobalCachedInputContext.Keyboard == keyboard;
		}
		private void RegisterKeyboards(IDictionary<string, uint> keyboards)
		{
			if (keyboards.Count <= 0)
				return;

			Dictionary<string, IbusKeyboardDescription> curKeyboards = KeyboardController.Instance.Keyboards.OfType<IbusKeyboardDescription>().ToDictionary(kd => kd.Id);
			var missingLayouts = new List<string>(keyboards.Keys);
			foreach (var ibusKeyboard in GetAllIBusKeyboards())
			{
				if (keyboards.ContainsKey(ibusKeyboard.LongName))
				{
					missingLayouts.Remove(ibusKeyboard.LongName);
					string id = string.Format("{0}_{1}", ibusKeyboard.Language, ibusKeyboard.LongName);
					IbusKeyboardDescription keyboard;
					if (curKeyboards.TryGetValue(id, out keyboard))
					{
						if (!keyboard.IsAvailable)
						{
							keyboard.SetIsAvailable(true);
							keyboard.IBusKeyboardEngine = ibusKeyboard;
						}
						curKeyboards.Remove(id);
					}
					else
					{
						keyboard = new IbusKeyboardDescription(id, ibusKeyboard, SwitchingAdaptor);
						KeyboardController.Instance.Keyboards.Add(keyboard);
					}
					keyboard.SystemIndex = keyboards[ibusKeyboard.LongName];
				}
			}

			foreach (IbusKeyboardDescription existingKeyboard in curKeyboards.Values)
				existingKeyboard.SetIsAvailable(false);

			foreach (var layout in missingLayouts)
				Console.WriteLine("{0}: Didn't find {1}", GetType().Name, layout);
		}
		private static IbusKeyboardDescription CreateMockIbusKeyboard(IKeyboardSwitchingAdaptor ibusKeyboardAdapter,
			string name, string language, string layout)
		{
			var engineDescMock = new Mock<IBusEngineDesc>();
			engineDescMock.Setup(x => x.Name).Returns(name);
			engineDescMock.Setup(x => x.Language).Returns(language);
			engineDescMock.Setup(x => x.Layout).Returns(layout);
			var keyboard = new IbusKeyboardDescription(string.Format("{0}_{1}", language, name), engineDescMock.Object, ibusKeyboardAdapter) {SystemIndex = 3};
			KeyboardController.Instance.Keyboards.Add(keyboard);
			return keyboard;
		}