void SettingsPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
      {
         if (!buffer.Dispatcher.CheckAccess())
         {
            buffer.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new SettingsChangedDelegate(SettingsPropertyChanged), sender, new object[] { e });
            return;
         }

         switch (e.PropertyName)
         {
            case "ShowInTaskbar":
               {
                  this.ShowInTaskbar = Properties.Settings.Default.ShowInTaskbar;
               } break;
            //case "ToolbarVisibility":
            //   {
            //      this.Toolbar.Visibility = Properties.Settings.Default.ToolbarVisibility;
            //      //switch (Properties.Settings.Default.ToolbarVisibility)
            //      //{
            //      //   case Visibility.Hidden:
            //      //   case Visibility.Collapsed:
            //      //      this.TryExtendFrameIntoClientArea(new Thickness(0.0));
            //      //      break;
            //      //   case Visibility.Visible:
            //      //      this.TryExtendFrameIntoClientArea(new Thickness(0.0, Toolbar.ActualHeight, 0.0, 0.0));
            //      //      break;
            //      //}

            //   } break;
            // TODO: let the new top-toolbars be hidden
            //case "StatusBar":
            //   {
            //      status.Visibility = Properties.Settings.Default.StatusBar ? Visibility.Visible : Visibility.Collapsed;
            //   } break;
            case "WindowHeight":
               {
                  // do nothing, this setting is set when height changes, so we don't want to get into a loop.
                  //this.Height = Properties.Settings.Default.WindowHeight;
               } break;
            case "WindowLeft":
               {
                  this.Left = Properties.Settings.Default.WindowLeft;
               } break;
            case "WindowWidth":
               {
                  // do nothing, this setting is set when width changes, so we don't want to get into a loop.
                  //this.Width = Properties.Settings.Default.WindowWidth;
               } break;
            case "WindowTop":
               {
                  this.Top = Properties.Settings.Default.WindowTop;
               } break;
            case "Animate":
               {
                  // do nothing, this setting is checked for each animation.
               } break;
            case "AutoHide":
               {
                  // do nothing, this setting is checked for each hide event.
               } break;
            case "SnapToScreenEdge":
               {
                  // do nothing, this setting is checked for each move
               } break;
            case "SnapDistance":
               {
                  // do nothing, this setting is checked for each move
               } break;
            case "AlwaysOnTop":
               {
                  this.Topmost = Settings.Default.AlwaysOnTop;
               } break;
            case "Opacity":
               {
                  this.Opacity = Settings.Default.Opacity;
               } break;
            case "WindowStyle":
               {
                  //((IPSConsole)buffer).WriteWarningLine("Window Style change requires a restart to take effect");
                  //this.WindowStyle = Properties.Settings.Default.WindowStyle;
                  //this.Hide();
                  //this.AllowsTransparency = (Properties.Settings.Default.WindowStyle == WindowStyle.None);
                  //this.Show();
               } break;
            //case "BorderColorTopLeft":
            //   {
            //      if (BorderBrush is LinearGradientBrush)
            //      {
            //         ((LinearGradientBrush)BorderBrush).GradientStops[0].Color = Properties.Settings.Default.BorderColorTopLeft;
            //      }
            //   } break;
            //case "BorderColorBottomRight":
            //   {
            //      if (BorderBrush is LinearGradientBrush)
            //      {
            //         ((LinearGradientBrush)BorderBrush).GradientStops[1].Color = Properties.Settings.Default.BorderColorBottomRight;
            //      }
            //   } break;
            //case "BorderThickness":
            //   {
            //      BorderThickness = Properties.Settings.Default.BorderThickness;
            //   } break;
            case "FocusKeyGesture":
            case "FocusKey":
               {
                  KeyBinding focusKey = null;
                  foreach (var hk in _Hotkeys.Hotkeys)
                  {
                     if(hk.Command is GlobalCommands.ActivateCommand)
                     {
                        focusKey = hk;
                     }
                  }
                  var kv = new KeyValueSerializer();
                  var km = new ModifierKeysValueSerializer();
                  KeyGesture newGesture = null;
                  try
                  {
                     var modifiers = Settings.Default.FocusKey.Split(new[] {'+'}).ToList();
                     var character = modifiers.Last();
                     modifiers.Remove(character);
                     newGesture = new KeyGesture((Key) kv.ConvertFromString(character, null),
                                       (ModifierKeys) km.ConvertFromString(string.Join("+", modifiers), null));
                  } 
                  catch (Exception)
                  {
                     if (focusKey != null)
                        Settings.Default.FocusKey = focusKey.Modifiers.ToString().Replace(", ","+") + "+" + focusKey.Key;
                  }

                  if (focusKey != null && newGesture != null)
                  {
                     _Hotkeys.Hotkeys.Remove(focusKey);
                     _Hotkeys.Hotkeys.Add(new KeyBinding(GlobalCommands.ActivateWindow, newGesture));
                  }

               } break;
            case "FontSize":
               {
                  buffer.FontSize = Properties.Settings.Default.FontSize;
               } break;
            case "FontFamily":
               {
                  buffer.FontFamily = Properties.Settings.Default.FontFamily;
               } break;
            default: break;
         }
      }
Example #2
0
      void SettingsPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) {
         if (!buffer.Dispatcher.CheckAccess()) {
            buffer.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new SettingsChangedDelegate(SettingsPropertyChanged), sender, new object[] { e });
            return;
         }

         switch (e.PropertyName) {
            case "ShowInTaskbar": {
                  ShowInTaskbar = Settings.Default.ShowInTaskbar;
               }
               break;
            case "WindowHeight": {
                  // do nothing, this setting is set when height changes, so we don't want to get into a loop.
                  this.Height = Properties.Settings.Default.WindowHeight;
               }
               break;
            case "WindowLeft": {
                  Left = Settings.Default.WindowLeft;
               }
               break;
            case "WindowWidth": {
                  // do nothing, this setting is set when width changes, so we don't want to get into a loop.
                  this.Width = Properties.Settings.Default.WindowWidth;
               }
               break;
            case "WindowTop": {
                  Top = Settings.Default.WindowTop;
               }
               break;
            case "Animate": {
                  // do nothing, this setting is checked for each animation.
               }
               break;
            case "AutoHide": {
                  // do nothing, this setting is checked for each hide event.
               }
               break;
            case "SnapToScreenEdge": {
                  // do nothing, this setting is checked for each move
               }
               break;
            case "SnapDistance": {
                  // do nothing, this setting is checked for each move
               }
               break;
            case "AlwaysOnTop": {
                  Topmost = Settings.Default.AlwaysOnTop;
               }
               break;
            case "QuakeMode": {
                  var snapTo = Interaction.GetBehaviors(this).OfType<SnapToBehavior>().Single();
                  snapTo.DockAgainst = Settings.Default.QuakeMode;
               }
               break;
            case "QuakeModeSize": {
                  var snapTo = Interaction.GetBehaviors(this).OfType<SnapToBehavior>().Single();
                  if (snapTo.WindowState == AdvancedWindowState.DockedTop) {
                     Height = Settings.Default.QuakeModeSize;
                  }
               }
               break;
            case "Opacity": {
                  // stop any animation before we try to apply the setting
                  var op = new DoubleAnimation(Settings.Default.Opacity, new Duration(TimeSpan.FromSeconds(0.5)));
                  BeginAnimation(OpacityProperty, op);
               }
               break;
            case "FocusKeyGesture":
            case "FocusKey": {
                  KeyBinding focusKey = null;
                  foreach (var hk in _hotkeys.Hotkeys) {
                     if (hk.Command is GlobalCommands.ActivateCommand) {
                        focusKey = hk;
                     }
                  }
                  var kv = new KeyValueSerializer();
                  var km = new ModifierKeysValueSerializer();
                  KeyGesture newGesture = null;
                  try {
                     var modifiers = Settings.Default.FocusKey.Split(new[] { '+' }).ToList();
                     var character = modifiers.Last();
                     modifiers.Remove(character);
                     // ReSharper disable AssignNullToNotNullAttribute
                     // ReSharper disable PossibleNullReferenceException
                     newGesture = new KeyGesture((Key)kv.ConvertFromString(character, null),
                                       (ModifierKeys)km.ConvertFromString(string.Join("+", modifiers), null));
                     // ReSharper restore PossibleNullReferenceException
                     // ReSharper restore AssignNullToNotNullAttribute
                  }
                  catch (Exception) {
                     if (focusKey != null)
                        Settings.Default.FocusKey = focusKey.Modifiers.ToString().Replace(", ", "+") + "+" + focusKey.Key;
                  }

                  if (focusKey != null && newGesture != null) {
                     _hotkeys.Hotkeys.Remove(focusKey);
                     _hotkeys.Hotkeys.Add(new KeyBinding(GlobalCommands.ActivateWindow, newGesture));
                  }

               }
               break;
            case "FontSize": {
                  buffer.FontSize = Settings.Default.FontSize;
               }
               break;
            case "FontFamily": {
                  // Fonts that are not embedded cannot be resolved from this base Uri
                  // FontFamily = new FontFamily(new Uri("pack://application:,,,/PoshConsole;component/poshconsole.xaml"), Properties.Settings.Default.FontFamily.Source + ",/FontLibrary;Component/#Bitstream Vera Sans Mono,Global Monospace");
                  buffer.FontFamily = Settings.Default.FontFamily;
               }
               break;

            default:
               break;
         }
         Settings.Default.Save();
      }