예제 #1
0
        private void CreateDataWindowButtonForDialog(IDialogOption option)
        {
            DataWindowButton btn = null;

            if (option.IsApplyBehavior)
            {
                btn = DataWindowButton.FromAsync(option.Caption, async() => await OnApplyExecuteAsync(), OnApplyCanExecute);

                btn.IsDefault = option.IsDefault;
            }

            if (option.IsOkBehavior)
            {
                btn = DataWindowButton.FromAsync(option.Caption, async() => await OnOkExecuteAsync(), OnOkCanExecute);

                btn.IsDefault = option.IsDefault;
            }

            if (option.IsCancelBehavior)
            {
                btn          = DataWindowButton.FromAsync(option.Caption, async() => await OnCancelExecuteAsync(), OnCancelCanExecute);
                btn.IsCancel = true;
            }

            AddCustomButton(btn);
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SimpleDataWindow" /> class.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        /// <param name="mode">The data window mode.</param>
        /// <param name="additionalButtons">The additional buttons.</param>
        /// <exception cref="System.NotSupportedException"></exception>
        protected SimpleDataWindow(IViewModel viewModel, DataWindowMode mode = DataWindowMode.OkCancel, IEnumerable <DataWindowButton> additionalButtons = null)
        {
            if (CatelEnvironment.IsInDesignMode)
            {
                return;
            }

            ThemeHelper.EnsureCatelMvvmThemeIsLoaded();

            _logic = new WindowLogic(this, null, viewModel);
            _logic.PropertyChanged          += (sender, e) => PropertyChanged.SafeInvoke(this, e);
            _logic.ViewModelChanged         += (sender, e) => ViewModelChanged.SafeInvoke(this, e);
            _logic.ViewModelPropertyChanged += (sender, e) => ViewModelPropertyChanged.SafeInvoke(this, e);

            Loaded             += (sender, e) => _viewLoaded.SafeInvoke(this);
            Unloaded           += (sender, e) => _viewUnloaded.SafeInvoke(this);
            DataContextChanged += (sender, e) => _viewDataContextChanged.SafeInvoke(this, new DataContextChangedEventArgs(e.OldValue, e.NewValue));

            if (additionalButtons != null)
            {
                foreach (var button in additionalButtons)
                {
                    _buttons.Add(button);
                }
            }

            var languageService = ServiceLocator.Default.ResolveType <ILanguageService>();

            if (mode == DataWindowMode.OkCancel || mode == DataWindowMode.OkCancelApply)
            {
                var button = DataWindowButton.FromAsync(languageService.GetString("OK"), OnOkExecuteAsync, OnOkCanExecute);
                button.IsDefault = true;
                _buttons.Add(button);
            }

            if (mode == DataWindowMode.OkCancel || mode == DataWindowMode.OkCancelApply)
            {
                var button = DataWindowButton.FromAsync(languageService.GetString("Cancel"), OnCancelExecuteAsync, OnCancelCanExecute);
                button.IsCancel = true;
                _buttons.Add(button);
            }

            if (mode == DataWindowMode.OkCancelApply)
            {
                var button = DataWindowButton.FromSync(languageService.GetString("Apply"), OnApplyExecute, OnApplyCanExecute);
                _buttons.Add(button);
            }

            if (mode == DataWindowMode.Close)
            {
                var button = DataWindowButton.FromSync(languageService.GetString("Close"), OnCloseExecute, null);
                _buttons.Add(button);
            }

            // Call manually the first time (for injected view models)
            OnViewModelChanged();

            this.FixBlurriness();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ExampleDialogWindow"/> class.
        /// </summary>
        public ExampleDialogWindow()
            : base(DataWindowMode.Custom)
        {
            AddCustomButton(DataWindowButton.FromAsync("Save anyway", ExecuteOkAsync, OnOkCanExecute));
            AddCustomButton(DataWindowButton.FromAsync("Cancel", ExecuteCancelAsync, OnCancelCanExecute));

            InitializeComponent();
        }
예제 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="KeyboardMappingsOverviewWindow"/> class.
        /// </summary>
        /// <param name="viewModel">The view model to inject.</param>
        /// <remarks>
        /// This constructor can be used to use view-model injection.
        /// </remarks>
        public KeyboardMappingsOverviewWindow(KeyboardMappingsOverviewViewModel viewModel)
            : base(viewModel, DataWindowMode.Custom)
        {
            AddCustomButton(new DataWindowButton("Print", "Print"));
            AddCustomButton(new DataWindowButton("Customize", "Customize"));
            AddCustomButton(DataWindowButton.FromSync("Close", Close, null));

            InitializeComponent();
        }
예제 #5
0
        /// <summary>
        /// Adds a custom button to the list of buttons.
        /// </summary>
        /// <param name="dataWindowButton">The data window button.</param>
        /// <exception cref="InvalidOperationException">The <paramref name="dataWindowButton"/> is added when the window is already loaded.</exception>
        protected void AddCustomButton(DataWindowButton dataWindowButton)
        {
            if (InternalGrid != null)
            {
                var languageService = ServiceLocator.Default.ResolveType <ILanguageService>();
                throw new InvalidOperationException(languageService.GetString("DataWindowButtonCanOnlyBeAddedWhenWindowIsNotLoaded"));
            }

            _buttons.Add(dataWindowButton);
        }
예제 #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SimpleDataWindow" /> class.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        /// <param name="mode">The data window mode.</param>
        /// <param name="additionalButtons">The additional buttons.</param>
        /// <exception cref="System.NotSupportedException"></exception>
        protected SimpleDataWindow(IViewModel viewModel, DataWindowMode mode = DataWindowMode.OkCancel, IEnumerable <DataWindowButton> additionalButtons = null)
        {
            _logic = new WindowLogic(this, null, viewModel);
            _logic.PropertyChanged          += (sender, e) => PropertyChanged.SafeInvoke(this, e);
            _logic.ViewModelChanged         += (sender, e) => ViewModelChanged.SafeInvoke(this, e);
            _logic.ViewModelPropertyChanged += (sender, e) => ViewModelPropertyChanged.SafeInvoke(this, e);

            Loaded             += (sender, e) => _viewLoaded.SafeInvoke(this);
            Unloaded           += (sender, e) => _viewUnloaded.SafeInvoke(this);
            DataContextChanged += (sender, e) => _viewDataContextChanged.SafeInvoke(this, new DataContextChangedEventArgs(e.OldValue, e.NewValue));

            if (additionalButtons != null)
            {
                foreach (var button in additionalButtons)
                {
                    _buttons.Add(button);
                }
            }

            if (mode == DataWindowMode.OkCancel || mode == DataWindowMode.OkCancelApply)
            {
                var button = new DataWindowButton("Ok", async() => await OnOkExecuteAsync(), OnOkCanExecute);
                button.IsDefault = true;
                _buttons.Add(button);
            }

            if (mode == DataWindowMode.OkCancel || mode == DataWindowMode.OkCancelApply)
            {
                var button = new DataWindowButton("Cancel", async() => await OnCancelExecuteAsync(), OnCancelCanExecute);
                button.IsCancel = true;
                _buttons.Add(button);
            }

            if (mode == DataWindowMode.OkCancelApply)
            {
                var button = new DataWindowButton("Apply", OnApplyExcute, OnApplyCanExecute);
                _buttons.Add(button);
            }

            if (mode == DataWindowMode.Close)
            {
                var button = new DataWindowButton("Close", OnCloseExecute);
                _buttons.Add(button);
            }

            // Call manually the first time (for injected view models)
            OnViewModelChanged();

            this.FixBlurriness();
        }
예제 #7
0
        public DialogHost(IViewModel vm)
            : base(vm, DataWindowMode.Custom)
        {
            var dialogOptions = (ViewModel as IDialogViewModel)?.Dialog ?? GetDefaultParameters();

            if (dialogOptions.IsCloseButtonAvaialble)
            {
                var button = DataWindowButton.FromSync("Close", OnCloseExecute, OnCloseCanExecute);
                AddCustomButton(button);
            }


            foreach (var option in dialogOptions.Options)
            {
                CreateDataWindowButtonForDialog(option);
            }

            InitializeComponent();
        }
예제 #8
0
        /// <summary>
        /// Invoked when the content of this control has been changed. This method will add the dynamic controls automatically.
        /// </summary>
        /// <param name="oldContent">Old content.</param>
        /// <param name="newContent">New content.</param>
        protected override void OnContentChanged(object oldContent, object newContent)
        {
            base.OnContentChanged(oldContent, newContent);

            if (CatelEnvironment.IsInDesignMode)
            {
                return;
            }

            var newContentAsFrameworkElement = newContent as FrameworkElement;

            if (_isWrapped || !WrapControlHelper.CanBeWrapped(newContentAsFrameworkElement))
            {
                return;
            }

            var languageService = ServiceLocator.Default.ResolveType <ILanguageService>();

            if (IsOKButtonAvailable)
            {
                var button = DataWindowButton.FromAsync(languageService.GetString("OK"), OnOkExecuteAsync, OnOkCanExecute);
                button.IsDefault = (DefaultButton == DataWindowDefaultButton.OK);
                _buttons.Add(button);
            }
            if (IsCancelButtonAvailable)
            {
                var button = DataWindowButton.FromAsync(languageService.GetString("Cancel"), OnCancelExecuteAsync, OnCancelCanExecute);
                button.IsCancel = true;
                _buttons.Add(button);
            }
            if (IsApplyButtonAvailable)
            {
                var button = DataWindowButton.FromAsync(languageService.GetString("Apply"), OnApplyExcuteAsync, OnApplyCanExecute);
                button.IsDefault = (DefaultButton == DataWindowDefaultButton.Apply);
                _buttons.Add(button);
            }
            if (IsCloseButtonAvailable)
            {
                var button = DataWindowButton.FromSync(languageService.GetString("Close"), OnCloseExecute, OnCloseCanExecute);
                button.IsDefault = (DefaultButton == DataWindowDefaultButton.Close);
                _buttons.Add(button);
            }

            foreach (var button in _buttons)
            {
                _commands.Add(button.Command);
            }

            var wrapOptions = WrapOptions.GenerateWarningAndErrorValidatorForDataContext;

            switch (_infoBarMessageControlGenerationMode)
            {
            case InfoBarMessageControlGenerationMode.None:
                break;

            case InfoBarMessageControlGenerationMode.Inline:
                wrapOptions |= WrapOptions.GenerateInlineInfoBarMessageControl;
                break;

            case InfoBarMessageControlGenerationMode.Overlay:
                wrapOptions |= WrapOptions.GenerateOverlayInfoBarMessageControl;
                break;
            }

            _isWrapped = true;

            var contentGrid = WrapControlHelper.Wrap(newContentAsFrameworkElement, wrapOptions, _buttons.ToArray(), this);

            var internalGrid = contentGrid.FindVisualDescendant(obj => (obj is FrameworkElement) && string.Equals(((FrameworkElement)obj).Name, WrapControlHelper.InternalGridName)) as Grid;

            if (internalGrid != null)
            {
                internalGrid.SetResourceReference(StyleProperty, "WindowGridStyle");

                newContentAsFrameworkElement.FocusFirstControl();

                _defaultOkCommand = (from button in _buttons
                                     where button.IsDefault
                                     select button.Command).FirstOrDefault();
                _defaultOkElement = WrapControlHelper.GetWrappedElement <ButtonBase>(contentGrid, WrapControlHelper.DefaultOkButtonName);

                _defaultCancelCommand = (from button in _buttons
                                         where button.IsCancel
                                         select button.Command).FirstOrDefault();

                InternalGrid = internalGrid;

                OnInternalGridChanged();
            }
        }
예제 #9
0
 /// <summary>
 /// Adds a custom button to the list of buttons.
 /// </summary>
 /// <param name="dataWindowButton">The data window button.</param>
 /// <exception cref="InvalidOperationException">The <paramref name="dataWindowButton"/> is added when the window is already loaded.</exception>
 protected void AddCustomButton(DataWindowButton dataWindowButton)
 {
     _buttons.Add(dataWindowButton);
 }
예제 #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ShellWindow"/> class.
        /// </summary>
        /// <remarks>This method is required for design time support.</remarks>
        public ShellWindow()
            : base(DataWindowMode.Custom, setOwnerAndFocus: false)
        {
            var currentLogFileName = TaskRunnerEnvironment.CurrentLogFileName;

            if (File.Exists(currentLogFileName))
            {
                File.Delete(currentLogFileName);
            }

            var fileLogListener = new FileLogListener(currentLogFileName, 25 * 1000)
            {
                IgnoreCatelLogging = true,
                IsDebugEnabled     = false
            };

            LogManager.AddListener(fileLogListener);

            var serviceLocator      = this.GetServiceLocator();
            var taskRunnerService   = serviceLocator.ResolveType <ITaskRunnerService>();
            var commandManager      = serviceLocator.ResolveType <ICommandManager>();
            var uiVisualizerService = serviceLocator.ResolveType <IUIVisualizerService>();

            if (taskRunnerService.ShowCustomizeShortcutsButton)
            {
                AddCustomButton(DataWindowButton.FromAsync("Keyboard shortcuts", () => uiVisualizerService.ShowDialogAsync <KeyboardMappingsOverviewViewModel>(), null));
            }

            serviceLocator.RegisterInstance <IAboutInfoService>(taskRunnerService);

            if (taskRunnerService.GetAboutInfo() != null)
            {
                var aboutService = serviceLocator.ResolveType <IAboutService>();
#pragma warning disable AvoidAsyncVoid // Avoid async void
                commandManager.RegisterAction("Help.About", async() => await aboutService.ShowAboutAsync());
#pragma warning restore AvoidAsyncVoid // Avoid async void

                AddCustomButton(new DataWindowButton("About", commandManager.GetCommand("Help.About")));
            }

            ThemeHelper.EnsureApplicationThemes(GetType().Assembly, true);

            InitializeComponent();
            serviceLocator.RegisterInstance <ILogControlService>(new LogControlService(traceOutputControl));

            ConfigurationContext = taskRunnerService.GetViewDataContext();

            var startupSize = taskRunnerService.GetInitialWindowSize();
            if (startupSize != null && !startupSize.IsEmpty)
            {
                var setWidth  = startupSize.Width > 0d;
                var setHeight = startupSize.Height > 0d;

                if (setHeight && setWidth)
                {
                    SetCurrentValue(SizeToContentProperty, SizeToContent.Manual);
                }
                else if (setHeight)
                {
                    SetCurrentValue(SizeToContentProperty, SizeToContent.Width);
                }
                else if (setWidth)
                {
                    SetCurrentValue(SizeToContentProperty, SizeToContent.Height);
                }
                else
                {
                    SetCurrentValue(SizeToContentProperty, SizeToContent.WidthAndHeight);
                }

                if (setWidth)
                {
                    SetCurrentValue(MinWidthProperty, startupSize.Width);
                    SetCurrentValue(WidthProperty, startupSize.Width);
                }

                if (setHeight)
                {
                    SetCurrentValue(MinHeightProperty, startupSize.Height);
                    SetCurrentValue(HeightProperty, startupSize.Height);
                }
            }

            var view = taskRunnerService.GetView();

            contentControl.Content = view;
        }