Пример #1
0
        public void AddHandlers()
        {
            if (SelectedExtensions.Count > 0 && SelectedProfile != null)
            {
                if (SelectedExtensions.First().PropertyHandlerState == HandlerState.None && SelectedProfile.IsNull)
                {
                    MessageBox.Show(LocalizedMessages.PleaseSelectProfile, LocalizedMessages.SetupHandler);
                    return;
                }
                else if (SelectedExtensions.First().PropertyHandlerState == HandlerState.Foreign)
                {
                    if (SelectedProfile.IsNull)
                    {
                        if (MessageBox.Show(SelectedExtensions.Count > 1 ? LocalizedMessages.ConfirmCustomNoMerges : LocalizedMessages.ConfirmCustomNoMerge,
                                            LocalizedMessages.SetupHandler, MessageBoxButton.YesNo) == MessageBoxResult.No)
                        {
                            return;
                        }
                    }
                    else
                    {
                        if (MessageBox.Show(string.Format(SelectedExtensions.Count > 1 ? LocalizedMessages.ConfirmCustomMerges : LocalizedMessages.ConfirmCustomMerge,
                                                          SelectedProfile.Name), LocalizedMessages.SetupHandler, MessageBoxButton.YesNo) == MessageBoxResult.No)
                        {
                            return;
                        }
                    }
                }

                foreach (Extension ext in SelectedExtensions)
                {
                    ext.SetupHandlerForExtension(SelectedProfile, true);

                    if (ext.PropertyHandlerState == HandlerState.ProfileOnly)
                    {
                        MessageBox.Show(string.Format(LocalizedMessages.WindowsWontExtendHandler, ext.Name),
                                        LocalizedMessages.SetupHandler);
                    }
                }
            }

            OnPropertyChanged("Profiles");
            DeterminePossibleActions();
            SortRequired = true;
        }
Пример #2
0
        private void DeterminePossibleActions()
        {
            // Cases are:
            // 1. All selected extensions have no handler: profile combo box is enabled and profile property lists are shown.
            // 2. All selected extensions have File Meta handler: profile combo box is disabled and profile for the
            //    first selected extension is shown in combo box and profile property lists.
            // 3. All other cases: profile combo box is disabled and profile property lists are empty.
            handlersSelected = null;
            foreach (Extension e in SelectedExtensions)
            {
                if (e.PropertyHandlerState == HandlerState.None)
                {
                    if (handlersSelected == null)
                    {
                        handlersSelected = HandlerSet.None;
                    }
                    else if (handlersSelected == HandlerSet.None)
                    {
                        continue;
                    }
                    else
                    {
                        handlersSelected = HandlerSet.Other;
                        break;
                    }
                }
                else if (e.PropertyHandlerState == HandlerState.Foreign)
                {
                    if (handlersSelected == null)
                    {
                        handlersSelected = HandlerSet.Foreign;
                    }
                    else if (handlersSelected == HandlerSet.Foreign)
                    {
                        continue;
                    }
                    else
                    {
                        handlersSelected = HandlerSet.Other;
                        break;
                    }
                }
                else if (e.PropertyHandlerState == HandlerState.Ours ||
                         e.PropertyHandlerState == HandlerState.Chained ||
                         e.PropertyHandlerState == HandlerState.ProfileOnly)
                {
                    if (handlersSelected == null)
                    {
                        handlersSelected = HandlerSet.Ours;
                    }
                    else if (handlersSelected == HandlerSet.Ours)
                    {
                        continue;
                    }
                    else
                    {
                        handlersSelected = HandlerSet.Other;
                        break;
                    }
                }
                else
                {
                    handlersSelected = HandlerSet.Other;
                    break;
                }
            }
            if (handlersSelected == null)
            {
                handlersSelected = HandlerSet.Other;
            }

            customPreviewProfile     = null;
            customPreviewProfileBase = null;

            switch (handlersSelected)
            {
            case HandlerSet.Ours:
                SelectedProfile = SelectedExtensions.First().Profile;
                break;

            case HandlerSet.Foreign:
            {
                if (SelectedExtensions.Count == 1)
                {
                    customPreviewProfileBase = SelectedExtensions.First().GetDefaultCustomProfile();
                    customPreviewProfile     = customPreviewProfileBase;
                }

                SelectedProfile = null;
                break;
            }

            case HandlerSet.None:
            case HandlerSet.Other:
                SelectedProfile = null;
                break;
            }

            OnPropertyChanged("ProfileToDisplay");
            OnPropertyChanged("CanChooseProfile");
            OnPropertyChanged("CanAddPropertyHandlerEtc");
            OnPropertyChanged("CanRemovePropertyHandlerEtc");
        }