示例#1
0
        public void RenamePreset(string newPresetName)
        {
            this.SelectedPreset.Preset.Name = newPresetName;

            // Remove from the folder and add it back again so it goes in the right place.
            PresetFolderViewModel currentFolder = this.FindFolderViewModel(this.SelectedPreset.Preset.FolderId);

            currentFolder.RemoveItem(this.SelectedPreset);
            currentFolder.AddItem(this.SelectedPreset);

            this.SavePreset();
        }
示例#2
0
        public void MovePresetToFolder(PresetViewModel presetViewModel, PresetFolderViewModel targetFolder)
        {
            PresetFolderViewModel previousFolder = this.FindFolderViewModel(presetViewModel.Preset.FolderId);

            previousFolder.RemoveItem(presetViewModel);

            targetFolder.AddItem(presetViewModel);
            presetViewModel.Preset.FolderId = targetFolder.Id;

            targetFolder.IsExpanded = true;

            this.SaveUserPresets();
        }
示例#3
0
        private void PopulateCustomFolder(PresetFolderViewModel folderViewModel)
        {
            // Add all child folders
            var childFolders = this.presetFolders.Where(f => f.ParentId == folderViewModel.Id);

            foreach (PresetFolder childPresetFolder in childFolders)
            {
                var childFolderViewModel = PresetFolderViewModel.FromPresetFolder(childPresetFolder, this);
                this.PopulateCustomFolder(childFolderViewModel);
                folderViewModel.AddSubfolder(childFolderViewModel);
            }

            // Add all presets directly in folder
            var folderPresets = this.AllPresets.Where(p => p.Preset.FolderId == folderViewModel.Id);

            foreach (PresetViewModel presetViewModel in folderPresets)
            {
                folderViewModel.AddItem(presetViewModel);
            }
        }
示例#4
0
        public PresetsService()
        {
            List <Preset> userPresets = PresetStorage.UserPresets;

            this.presetFolders           = PresetFolderStorage.PresetFolders;
            this.collapsedBuiltInFolders = CustomConfig.CollapsedBuiltInFolders;

            var    unmodifiedPresets = userPresets.Where(preset => !preset.IsModified);
            Preset modifiedPreset    = userPresets.FirstOrDefault(preset => preset.IsModified);

            this.allPresets = new ObservableCollection <PresetViewModel>();
            int modifiedPresetIndex = -1;
            int defaultPresetIndex  = 0;

            foreach (Preset userPreset in unmodifiedPresets)
            {
                PresetViewModel presetVM;
                if (modifiedPreset != null && modifiedPreset.Name == userPreset.Name)
                {
                    modifiedPresetIndex      = this.allPresets.Count;
                    presetVM                 = new PresetViewModel(modifiedPreset);
                    presetVM.OriginalProfile = userPreset.EncodingProfile;
                }
                else
                {
                    presetVM = new PresetViewModel(userPreset);
                }

                this.allPresets.Add(presetVM);
            }

            // Populate the custom preset folder before built-in presets are added to AllPresets collection.
            this.customPresetFolder = new PresetFolderViewModel(this, !this.collapsedBuiltInFolders.Contains(CustomFolderKey))
            {
                Name = EncodingRes.PresetFolder_Custom, Id = 0, IsBuiltIn = false
            };
            this.PopulateCustomFolder(this.customPresetFolder);

            // Populate built-in folder from HandBrake presets
            IList <PresetCategory> handBrakePresets = HandBrakePresetService.GetBuiltInPresets();

            this.builtInFolder = new PresetFolderViewModel(this, !this.collapsedBuiltInFolders.Contains(BuiltInFolderKey))
            {
                Name = EncodingRes.PresetFolder_BuiltIn, IsBuiltIn = true
            };
            foreach (PresetCategory handbrakePresetCategory in handBrakePresets)
            {
                var builtInSubfolder = new PresetFolderViewModel(this, !this.collapsedBuiltInFolders.Contains(handbrakePresetCategory.PresetName))
                {
                    Name      = handbrakePresetCategory.PresetName,
                    IsBuiltIn = true,
                };

                this.builtInFolder.AddSubfolder(builtInSubfolder);

                foreach (HBPreset handbrakePreset in handbrakePresetCategory.ChildrenArray)
                {
                    if (handbrakePreset.Default)
                    {
                        defaultPresetIndex = this.allPresets.Count;
                    }

                    Preset          builtInPreset          = PresetConverter.ConvertHandBrakePresetToVC(handbrakePreset);
                    PresetViewModel builtInPresetViewModel = new PresetViewModel(builtInPreset);

                    this.allPresets.Add(builtInPresetViewModel);
                    builtInSubfolder.AddItem(builtInPresetViewModel);
                }
            }

            this.allPresetsTree = new ObservableCollection <PresetFolderViewModel>();

            if (this.customPresetFolder.Items.Count > 0 || this.customPresetFolder.SubFolders.Count > 0)
            {
                this.AllPresetsTree.Add(this.customPresetFolder);
            }

            this.AllPresetsTree.Add(this.builtInFolder);



            // Always select the modified preset if it exists.
            // Otherwise, choose the last selected preset.
            int presetIndex;

            if (modifiedPresetIndex >= 0)
            {
                presetIndex = modifiedPresetIndex;
            }
            else
            {
                int lastPresetIndex = Config.LastPresetIndex;
                if (lastPresetIndex >= 0)
                {
                    presetIndex = lastPresetIndex;
                }
                else
                {
                    presetIndex = defaultPresetIndex;
                }
            }

            if (presetIndex >= this.allPresets.Count)
            {
                presetIndex = 0;
            }

            this.SelectedPreset = this.allPresets[presetIndex];
        }