Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the ShowAllModulesWindow class.
        /// </summary>
        public ShowAllModulesWindow()
        {
            this.InitializeComponent();

            if (this.AllModulesControl != null && this.AllModulesControl.ShowModuleControl != null)
            {
                this.AllModulesControl.ShowModuleControl.Owner = this;
            }

            this.SizeChanged += new SizeChangedEventHandler(this.ShowAllModulesWindow_SizeChanged);
            this.LocationChanged += new System.EventHandler(this.ShowAllModulesWindow_LocationChanged);
            this.StateChanged += new System.EventHandler(this.ShowAllModulesWindow_StateChanged);
            this.Loaded += new RoutedEventHandler(this.ShowAllModulesWindow_Loaded);

            RoutedCommand plusSettings = new RoutedCommand();
            KeyGestureConverter keyGestureConverter = new KeyGestureConverter();

            try
            {
                plusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomIn1Shortcut));
                plusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomIn2Shortcut));
                plusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomIn3Shortcut));
                plusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomIn4Shortcut));
                CommandBindings.Add(new CommandBinding(plusSettings, ZoomEventHandlerPlus));
            }
            catch (NotSupportedException)
            { 
                //localized has a problematic string - going to default
                plusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString("Ctrl+Add"));
                plusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString("Ctrl+Plus"));
                CommandBindings.Add(new CommandBinding(plusSettings, ZoomEventHandlerPlus));
            };  
            

            RoutedCommand minusSettings = new RoutedCommand();
            try
            {
                minusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomOut1Shortcut));
                minusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomOut2Shortcut));
                minusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomOut3Shortcut));
                minusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomOut4Shortcut));

                CommandBindings.Add(new CommandBinding(minusSettings, ZoomEventHandlerMinus));
            }
            catch (NotSupportedException)
            {
                //localized has a problematic string - going to default
                minusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString("Ctrl+Subtract"));
                minusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString("Ctrl+Minus"));
                CommandBindings.Add(new CommandBinding(minusSettings, ZoomEventHandlerMinus));
            }

        }
Ejemplo n.º 2
0
        public static IEnumerable<KeyBinding> GenerateKeyBinding(JsonArray array, object obj)
        {
            List<KeyBinding> keyBindings = new List<KeyBinding>();
              KeyGestureConverter keyGestureConverter = new KeyGestureConverter();

              foreach (JsonNode jsonNode in array)
              {
            KeyGesture keyGesture =
              keyGestureConverter.ConvertFromString(jsonNode.GetObjectOrDefault("gesture", "")) as KeyGesture;
            if (keyGesture == null)
              continue;
            MethodInfo methodInfo = obj.GetType().GetMethod(jsonNode.GetObjectOrDefault("command", ""), new Type[0]);
            if (methodInfo == null)
              continue;
            keyBindings.Add(new KeyBinding(new ManualCommand(() => methodInfo.Invoke(obj, null)), keyGesture ));
              }

              return keyBindings;
        }
 // http://www.bryanewert.net/journal/2010/6/8/how-to-use-markupextension-for-a-string-resource-that-define.html
 /// <summary>
 /// Initializes a new instance of the <see cref="KeyGestureExtension"/> class.
 /// </summary>
 /// <param name="gesture">The gesture.</param>
 public KeyGestureExtension(string gesture)
 {
     var kgc = new KeyGestureConverter();
     this.gesture=kgc.ConvertFromString(gesture) as KeyGesture;
 }
Ejemplo n.º 4
0
        private static KeyGesture ParseGesture(IAction action, KeyGestureConverter converter)
        {
            try
            {
                return converter.ConvertFromString(action.InputGesture) as KeyGesture;
            }
            catch
            {
                Logger.Instance.Warn("Unable to create keybinding for action: {0}", action.InputGesture);
            }

            return null;
        }
Ejemplo n.º 5
0
        private void StartWindow(string invocation, string outputModeOptions, AutoResetEvent closedEvent)
        {
            this.closedEvent = closedEvent;
            this.gridViewWindowLoaded = new AutoResetEvent(false);

            ParameterizedThreadStart threadStart = new ParameterizedThreadStart(
               new ThreadDelegate(delegate
               {
                   try
                   {
                       this.gridViewWindow = new Window();
                       this.managementList = CreateManagementList(outputModeOptions);
                       this.gridViewWindow.Loaded += new RoutedEventHandler(this.GridViewWindowLoaded);
                       this.gridViewWindow.Content = CreateMainGrid(outputModeOptions);
                       this.gridViewWindow.Title = invocation;
                       this.gridViewWindow.Closed += new EventHandler(this.GridViewWindowClosed);

                       RoutedCommand plusSettings = new RoutedCommand();
                       KeyGestureConverter keyGestureConverter = new KeyGestureConverter();

                       try
                       {
                           plusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomIn1Shortcut));
                           plusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomIn2Shortcut));
                           plusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomIn3Shortcut));
                           plusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomIn4Shortcut));
                           this.gridViewWindow.CommandBindings.Add(new CommandBinding(plusSettings, ZoomEventHandlerPlus));
                       }
                       catch (NotSupportedException)
                       {
                           //localized has a problematic string - going to default
                           plusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString("Ctrl+Add"));
                           plusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString("Ctrl+Plus"));
                           this.gridViewWindow.CommandBindings.Add(new CommandBinding(plusSettings, ZoomEventHandlerPlus));
                       };

                       RoutedCommand minusSettings = new RoutedCommand();
                       try
                       {
                           minusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomOut1Shortcut));
                           minusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomOut2Shortcut));
                           minusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomOut3Shortcut));
                           minusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString(UICultureResources.ZoomOut4Shortcut));

                           this.gridViewWindow.CommandBindings.Add(new CommandBinding(minusSettings, ZoomEventHandlerMinus));
                       }
                       catch (NotSupportedException)
                       {
                           //localized has a problematic string - going to default
                           minusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString("Ctrl+Subtract"));
                           minusSettings.InputGestures.Add((KeyGesture)keyGestureConverter.ConvertFromString("Ctrl+Minus"));
                           this.gridViewWindow.CommandBindings.Add(new CommandBinding(minusSettings, ZoomEventHandlerMinus));
                       }

                       this.gridViewWindow.ShowDialog();
                   }
                   catch (Exception e)
                   {
                       // Store the exception in a local variable that will be checked later.
                       if (e.InnerException != null)
                       {
                           this.exception = e.InnerException;
                       }
                       else
                       {
                           this.exception = e;
                       }
                   }
               }));

            guiThread = new Thread(threadStart);
            guiThread.SetApartmentState(ApartmentState.STA);

            guiThread.Start();
        }