Example #1
0
        public void OnImportsSatisfied()
        {
            editViewModel        = new EditPaneViewModel(Workspace);
            editPane.DataContext = editViewModel;

            Workspace.CommandExecuted  += Workspace_CommandExecuted;
            Workspace.WorkspaceChanged += Workspace_WorkspaceChanged;
            Workspace.SettingsService.SettingChanged += SettingsManager_PropertyChanged;

            // prepare status bar bindings
            var vm = new StatusBarViewModel(Workspace.SettingsService);

            foreach (var x in new[] { new { TextBlock = this.orthoStatus, Path = nameof(WpfSettingsProvider.Ortho) },
                                      new { TextBlock = this.pointSnapStatus, Path = nameof(WpfSettingsProvider.PointSnap) },
                                      new { TextBlock = this.angleSnapStatus, Path = nameof(WpfSettingsProvider.AngleSnap) },
                                      new { TextBlock = this.debugStatus, Path = nameof(DefaultSettingsProvider.Debug) } })
            {
                var binding = new Binding(x.Path);
                binding.Source    = vm;
                binding.Converter = new BoolToBrushConverter();
                binding.Mode      = BindingMode.TwoWay;
                x.TextBlock.SetBinding(TextBlock.ForegroundProperty, binding);
            }

            // add keyboard shortcuts for command bindings
            foreach (var command in from c in Commands
                     let metadata = c.Metadata
                                    where metadata.Key != BCad.Commands.Key.None ||
                                    metadata.Modifier != BCad.Commands.ModifierKeys.None
                                    select metadata)
            {
                this.InputBindings.Add(new InputBinding(
                                           new UserCommand(this.Workspace, command.Name),
                                           new KeyGesture((System.Windows.Input.Key)command.Key, (System.Windows.Input.ModifierKeys)command.Modifier)));
            }

            // add keyboard shortcuts for toggled settings
            foreach (var setting in new[] {
                new { Name = nameof(WpfSettingsProvider.AngleSnap), Shortcut = Workspace.SettingsService.GetValue <KeyboardShortcut>(WpfSettingsProvider.AngleSnapShortcut) },
                new { Name = nameof(WpfSettingsProvider.PointSnap), Shortcut = Workspace.SettingsService.GetValue <KeyboardShortcut>(WpfSettingsProvider.PointSnapShortcut) },
                new { Name = nameof(WpfSettingsProvider.Ortho), Shortcut = Workspace.SettingsService.GetValue <KeyboardShortcut>(WpfSettingsProvider.OrthoShortcut) },
                new { Name = nameof(DefaultSettingsProvider.Debug), Shortcut = Workspace.SettingsService.GetValue <KeyboardShortcut>(WpfSettingsProvider.DebugShortcut) }
            })
            {
                if (setting.Shortcut.HasValue)
                {
                    this.InputBindings.Add(new InputBinding(
                                               new ToggleSettingsCommand(Workspace.SettingsService, setting.Name),
                                               new KeyGesture(setting.Shortcut.Key, setting.Shortcut.Modifier)));
                }
            }

            Workspace_WorkspaceChanged(this, WorkspaceChangeEventArgs.Reset());
        }
Example #2
0
        public void Initialize(IWorkspace workspace, IViewControl viewControl)
        {
            this.Workspace   = workspace;
            this.ViewControl = viewControl;

            viewModel.SelectedEntities = workspace.SelectedEntities;
            DataContext = viewModel;
            Workspace.WorkspaceChanged += Workspace_WorkspaceChanged;
            Workspace.SettingsService.SettingChanged     += Workspace_SettingChanged;
            Workspace.SelectedEntities.CollectionChanged += SelectedEntities_CollectionChanged;
            Workspace.RubberBandGeneratorChanged         += Workspace_RubberBandGeneratorChanged;

            this.Loaded += (_, __) =>
            {
                SetBackgroundColor();
                Workspace_WorkspaceChanged(Workspace, WorkspaceChangeEventArgs.Reset());
            };
        }