Example #1
0
        private void ProcessPresetList(PresetTransportContainer container, bool ignoreOldBuiltIn)
        {
            // The presets file loaded was OK, so process it.
            foreach (var item in container.PresetList)
            {
                object deserialisedItem = JsonConvert.DeserializeObject <PresetCategory>(item.ToString());

                // Handle Categorised Presets.
                PresetCategory category = deserialisedItem as PresetCategory;
                if (category != null && category.Folder)
                {
                    foreach (HBPreset hbpreset in category.ChildrenArray)
                    {
                        Preset preset = JsonPresetFactory.ImportPreset(hbpreset);

                        if (preset.IsBuildIn && ignoreOldBuiltIn)
                        {
                            continue;
                        }

                        // Migration
                        preset.Category  = category.PresetName == "User Presets" ? UserPresetCatgoryName : category.PresetName;
                        preset.IsBuildIn = hbpreset.Type == 0;

                        // IF we are using Source Max, Set the Max Width / Height values.
                        if (preset.PictureSettingsMode == PresetPictureSettingsMode.SourceMaximum)
                        {
                            preset.Task.MaxWidth  = preset.Task.Height;
                            preset.Task.MaxHeight = preset.Task.Width;
                        }

                        this.Add(preset, true);
                    }
                }

                // Uncategorised Presets
                deserialisedItem = JsonConvert.DeserializeObject <HBPreset>(item.ToString());
                HBPreset hbPreset = deserialisedItem as HBPreset;
                if (hbPreset != null && !hbPreset.Folder)
                {
                    Preset preset = JsonPresetFactory.ImportPreset(hbPreset);
                    preset.Category  = UserPresetCatgoryName;
                    preset.IsBuildIn = hbPreset.Type == 1;

                    // IF we are using Source Max, Set the Max Width / Height values.
                    if (preset.PictureSettingsMode == PresetPictureSettingsMode.SourceMaximum)
                    {
                        preset.Task.MaxWidth  = preset.Task.Height;
                        preset.Task.MaxHeight = preset.Task.Width;
                    }

                    this.Add(preset, true);
                }
            }
        }
Example #2
0
        /// <summary>
        /// The import.
        /// </summary>
        /// <param name="filename">
        /// The filename.
        /// </param>
        public void Import(string filename)
        {
            if (!string.IsNullOrEmpty(filename))
            {
                PresetTransportContainer container = null;
                try
                {
                    container = HandBrakePresetService.GetPresetFromFile(filename);
                }
                catch (Exception exc)
                {
                    this.errorService.ShowError(Resources.Main_PresetImportFailed, Resources.Main_PresetImportFailedSolution, exc);
                    return;
                }

                if (container?.PresetList == null || container.PresetList.Count == 0)
                {
                    this.errorService.ShowError(Resources.Main_PresetImportFailed, Resources.Main_PresetImportFailedSolution, Resources.NoAdditionalInformation);
                    return;
                }

                // HBPreset Handling
                if (container.PresetList != null)
                {
                    foreach (var objectPreset in container.PresetList)
                    {
                        PresetCategory category = JsonConvert.DeserializeObject <PresetCategory>(objectPreset.ToString());
                        if (category != null && category.ChildrenArray != null && category.ChildrenArray.Count > 0)
                        {
                            foreach (HBPreset hbPreset in category.ChildrenArray)
                            {
                                Preset preset = this.ConvertHbPreset(hbPreset);
                                if (preset != null)
                                {
                                    this.AddOrUpdateImportedPreset(preset);
                                }
                            }
                        }
                        else
                        {
                            HBPreset hbPreset = JsonConvert.DeserializeObject <HBPreset>(objectPreset.ToString());
                            if (hbPreset != null)
                            {
                                Preset preset = this.ConvertHbPreset(hbPreset);
                                if (preset != null)
                                {
                                    this.AddOrUpdateImportedPreset(preset);
                                }
                            }
                        }
                    }
                }
            }
        }
Example #3
0
        private void ProcessPresetList(PresetTransportContainer container)
        {
            // The presets file loaded was OK, so process it.
            foreach (var item in container.PresetList)
            {
                object deserialisedItem = JsonConvert.DeserializeObject <PresetCategory>(item.ToString());

                // Handle Categorised Presets.
                PresetCategory category = deserialisedItem as PresetCategory;
                if (category != null && category.Folder)
                {
                    foreach (HBPreset hbpreset in category.ChildrenArray)
                    {
                        Preset preset = JsonPresetFactory.ImportPreset(hbpreset);

                        // Migration
                        preset.Category         = category.PresetName == "User Presets" ? UserPresetCatgoryName : category.PresetName;
                        preset.IsBuildIn        = hbpreset.Type == 0;
                        preset.IsPresetDisabled = this.IsPresetDisabled(preset);

                        this.Add(preset, true);
                    }
                }

                // Uncategorised Presets
                deserialisedItem = JsonConvert.DeserializeObject <HBPreset>(item.ToString());
                HBPreset hbPreset = deserialisedItem as HBPreset;
                if (hbPreset != null && !hbPreset.Folder)
                {
                    Preset preset = JsonPresetFactory.ImportPreset(hbPreset);
                    preset.Category         = UserPresetCatgoryName;
                    preset.IsBuildIn        = hbPreset.Type == 1;
                    preset.IsPresetDisabled = this.IsPresetDisabled(preset);

                    this.Add(preset, true);
                }
            }
        }
Example #4
0
        /// <summary>
        /// Load in the Built-in and User presets into the collection
        /// </summary>
        private void LoadPresets()
        {
            // First clear the Presets arraylists
            this.presets.Clear();

            // Load the presets file.
            try
            {
                // If we don't have a presets file. Create one for first load.
                if (!File.Exists(this.presetFile))
                {
                    // If this is a nightly, and we don't have a presets file, try port the main version if it exists.
                    string releasePresetFile = Path.Combine(DirectoryUtilities.GetUserStoragePath(false), "presets.json");
                    if (VersionHelper.IsNightly() && File.Exists(releasePresetFile))
                    {
                        File.Copy(releasePresetFile, DirectoryUtilities.GetUserStoragePath(true));
                    }
                    else
                    {
                        this.UpdateBuiltInPresets();
                        return; // Update built-in presets stores the presets locally, so just return.
                    }
                }

                // Otherwise, we already have a file, so lets try load it.
                PresetTransportContainer container = null;
                using (StreamReader reader = new StreamReader(this.presetFile))
                {
                    try
                    {
                        container = JsonConvert.DeserializeObject <PresetTransportContainer>(reader.ReadToEnd());
                    }
                    catch (Exception exc)
                    {
                        Debug.WriteLine("Failed to parse presets file: " + exc);
                    }
                }

                // Sanity Check. Did the container deserialise.
                if (container == null || container.PresetList == null)
                {
                    string filename = this.RecoverFromCorruptedPresetFile(this.presetFile);
                    this.errorService.ShowMessageBox(
                        Resources.PresetService_UnableToLoadPresets + filename,
                        Resources.PresetService_UnableToLoad,
                        MessageBoxButton.OK,
                        MessageBoxImage.Exclamation);

                    this.UpdateBuiltInPresets();
                    return; // Update built-in presets stores the presets locally, so just return.
                }

                // Version Check
                // If we have old presets, or the container wasn't parseable, or we have a version mismatch, backup the user preset file
                // incase something goes wrong and reset built-in presets, then re-save.
                if (container.VersionMajor != Constants.PresetVersionMajor || container.VersionMinor != Constants.PresetVersionMinor || container.VersionMicro != Constants.PresetVersionMicro)
                {
                    string fileName = this.ArchivePresetFile(this.presetFile);
                    this.errorService.ShowMessageBox(
                        Resources.PresetService_PresetsOutOfDate
                        + Environment.NewLine + Environment.NewLine + Resources.PresetService_ArchiveFile + fileName,
                        Resources.PresetService_UnableToLoad,
                        MessageBoxButton.OK,
                        MessageBoxImage.Exclamation);
                    this.UpdateBuiltInPresets(); // Update built-in presets stores the presets locally, so just return.
                    return;
                }

                // Force Upgrade of presets
                if (this.userSettingService.GetUserSetting <int>(UserSettingConstants.ForcePresetReset) < ForcePresetReset)
                {
                    this.userSettingService.SetUserSetting(UserSettingConstants.ForcePresetReset, ForcePresetReset);

                    string fileName = this.ArchivePresetFile(this.presetFile);
                    this.errorService.ShowMessageBox(
                        Resources.Presets_PresetForceReset
                        + Environment.NewLine + Environment.NewLine + Resources.PresetService_ArchiveFile + fileName,
                        Resources.PresetService_UnableToLoad,
                        MessageBoxButton.OK,
                        MessageBoxImage.Exclamation);
                    this.UpdateBuiltInPresets(); // Update built-in presets stores the presets locally, so just return.
                    return;
                }

                // The presets file loaded was OK, so process it.
                foreach (var item in container.PresetList)
                {
                    object deserialisedItem = JsonConvert.DeserializeObject <PresetCategory>(item.ToString());

                    // Handle Categorised Presets.
                    PresetCategory category = deserialisedItem as PresetCategory;
                    if (category != null && category.Folder)
                    {
                        foreach (HBPreset hbpreset in category.ChildrenArray)
                        {
                            Preset preset = JsonPresetFactory.ImportPreset(hbpreset);

                            // Migration
                            if (category.PresetName == "User Presets")
                            {
                                preset.Category = UserPresetCatgoryName;
                            }
                            else
                            {
                                preset.Category = category.PresetName;
                            }
                            preset.IsBuildIn = hbpreset.Type == 0;

                            // IF we are using Source Max, Set the Max Width / Height values.
                            if (preset.PictureSettingsMode == PresetPictureSettingsMode.SourceMaximum)
                            {
                                preset.Task.MaxWidth  = preset.Task.Height;
                                preset.Task.MaxHeight = preset.Task.Width;
                            }

                            this.Add(preset, true);
                        }
                    }

                    // Uncategorised Presets
                    deserialisedItem = JsonConvert.DeserializeObject <HBPreset>(item.ToString());
                    HBPreset hbPreset = deserialisedItem as HBPreset;
                    if (hbPreset != null && !hbPreset.Folder)
                    {
                        Preset preset = JsonPresetFactory.ImportPreset(hbPreset);
                        preset.Category  = UserPresetCatgoryName;
                        preset.IsBuildIn = hbPreset.Type == 1;

                        // IF we are using Source Max, Set the Max Width / Height values.
                        if (preset.PictureSettingsMode == PresetPictureSettingsMode.SourceMaximum)
                        {
                            preset.Task.MaxWidth  = preset.Task.Height;
                            preset.Task.MaxHeight = preset.Task.Width;
                        }

                        this.Add(preset, true);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                this.RecoverFromCorruptedPresetFile(this.presetFile);
                this.UpdateBuiltInPresets();
            }
        }
Example #5
0
        /// <summary>
        /// The import.
        /// </summary>
        /// <param name="filename">
        /// The filename.
        /// </param>
        public void Import(string filename)
        {
            if (!string.IsNullOrEmpty(filename))
            {
                PresetTransportContainer container = null;
                try
                {
                    container = HandBrakePresetService.GetPresetsFromFile(filename);
                }
                catch (Exception exc)
                {
                    this.errorService.ShowError(Resources.Main_PresetImportFailed, Resources.Main_PresetImportFailedSolution, exc);
                    return;
                }

                if (container?.PresetList == null || container.PresetList.Count == 0)
                {
                    this.errorService.ShowError(Resources.Main_PresetImportFailed, Resources.Main_PresetImportFailedSolution, Resources.NoAdditionalInformation);
                    return;
                }

                // HBPreset Handling
                if (container.PresetList != null)
                {
                    bool containsBuildInPreset = false;
                    foreach (var objectPreset in container.PresetList)
                    {
                        PresetCategory category = JsonConvert.DeserializeObject <PresetCategory>(objectPreset.ToString());
                        if (category != null && category.ChildrenArray != null && category.ChildrenArray.Count > 0)
                        {
                            foreach (HBPreset hbPreset in category.ChildrenArray)
                            {
                                Preset preset = this.ConvertHbPreset(hbPreset);
                                preset.IsPresetDisabled = this.IsPresetDisabled(preset);
                                if (preset != null && !preset.IsBuildIn)
                                {
                                    this.AddOrUpdateImportedPreset(preset);
                                }
                                else
                                {
                                    containsBuildInPreset = true;
                                }
                            }
                        }
                        else
                        {
                            HBPreset hbPreset = JsonConvert.DeserializeObject <HBPreset>(objectPreset.ToString());
                            if (hbPreset != null)
                            {
                                Preset preset = this.ConvertHbPreset(hbPreset);
                                preset.IsPresetDisabled = this.IsPresetDisabled(preset);
                                if (preset != null && !preset.IsBuildIn)
                                {
                                    this.AddOrUpdateImportedPreset(preset);
                                }
                                else
                                {
                                    containsBuildInPreset = true;
                                }
                            }
                        }
                    }

                    if (containsBuildInPreset)
                    {
                        this.errorService.ShowMessageBox(
                            Properties.Resources.PresetService_ImportingBuiltInWarning,
                            Properties.Resources.Warning,
                            MessageBoxButton.OK,
                            MessageBoxImage.Warning);
                    }
                }
            }
        }
Example #6
0
        /// <summary>
        /// Load in the Built-in and User presets into the collection
        /// </summary>
        private void LoadPresets()
        {
            // First clear the Presets arraylists
            this.presets.Clear();

            // Load the presets file.
            try
            {
                // If we don't have a presets file. Create one for first load.
                if (!File.Exists(this.presetFile))
                {
                    this.UpdateBuiltInPresets();
                    return;
                }

                // Otherwise, we already have a file, so lets try load it.
                bool versionCheckChange = false;
                using (StreamReader reader = new StreamReader(this.presetFile))
                {
                    // New Preset Format.
                    PresetTransportContainer container = null;
                    try
                    {
                        container = JsonConvert.DeserializeObject <PresetTransportContainer>(reader.ReadToEnd());
                    }
                    catch (Exception)
                    {
                        // ignored
                    }

                    // Sanity Check. Did the container deserialise.
                    if (container?.PresetList == null)
                    {
                        // Close and Dispose of early.
                        reader.Close();
                        reader.Dispose();

                        string filename = this.RecoverFromCorruptedPresetFile(this.presetFile);
                        this.errorService.ShowMessageBox(
                            Resources.PresetService_UnableToLoadPresets + filename,
                            Resources.PresetService_UnableToLoad,
                            MessageBoxButton.OK,
                            MessageBoxImage.Exclamation);

                        this.UpdateBuiltInPresets();
                        return;
                    }

                    // Version Check
                    // If we have old presets, or the container wasn't parseable, or we have a version mismatch, backup the user preset file
                    // incase something goes wrong.
                    if (container.VersionMajor != Constants.PresetVersionMajor || container.VersionMinor != Constants.PresetVersionMinor || container.VersionMicro != Constants.PresetVersionMicro)
                    {
                        string fileName = this.ArchivePresetFile(this.presetFile);
                        this.errorService.ShowMessageBox(
                            Resources.PresetService_PresetsOutOfDate
                            + Environment.NewLine + Environment.NewLine + Resources.PresetService_ArchiveFile + fileName,
                            Resources.PresetService_UnableToLoad,
                            MessageBoxButton.OK,
                            MessageBoxImage.Exclamation);
                        versionCheckChange = true;
                    }

                    // Process the presets.
                    foreach (var item in container.PresetList)
                    {
                        object deserialisedItem = JsonConvert.DeserializeObject <PresetCategory>(item.ToString());;

                        // Handle Categorised Presets.
                        PresetCategory category = deserialisedItem as PresetCategory;
                        if (category != null && category.Folder)
                        {
                            foreach (HBPreset hbpreset in category.ChildrenArray)
                            {
                                Preset preset = JsonPresetFactory.ImportPreset(hbpreset);
                                preset.Category  = category.PresetName;
                                preset.IsBuildIn = hbpreset.Type == 0;

                                // IF we are using Source Max, Set the Max Width / Height values.
                                if (preset.PictureSettingsMode == PresetPictureSettingsMode.SourceMaximum)
                                {
                                    preset.Task.MaxWidth  = preset.Task.Height;
                                    preset.Task.MaxHeight = preset.Task.Width;
                                }

                                this.presets.Add(preset);
                            }
                        }

                        // Uncategorised Presets
                        deserialisedItem = JsonConvert.DeserializeObject <HBPreset>(item.ToString());
                        HBPreset hbPreset = deserialisedItem as HBPreset;
                        if (hbPreset != null && !hbPreset.Folder)
                        {
                            Preset preset = JsonPresetFactory.ImportPreset(hbPreset);
                            preset.Category  = UserPresetCatgoryName;
                            preset.IsBuildIn = hbPreset.Type == 1;

                            // IF we are using Source Max, Set the Max Width / Height values.
                            if (preset.PictureSettingsMode == PresetPictureSettingsMode.SourceMaximum)
                            {
                                preset.Task.MaxWidth  = preset.Task.Height;
                                preset.Task.MaxHeight = preset.Task.Width;
                            }

                            this.presets.Add(preset);
                        }
                    }
                }

                // Resave the presets if we failed the version check to update the container
                if (versionCheckChange)
                {
                    this.SavePresetFiles();
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                this.RecoverFromCorruptedPresetFile(this.presetFile);
                this.UpdateBuiltInPresets();
            }
        }
    void OnGUI()
    {
        if (window == null)
        {
            this.Close();
            return;
        }

        EditorGUILayout.BeginVertical();

        scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, false);
        EditorGUILayout.Separator();
        EditorGUILayout.LabelField(playgroundLanguage.presetManager, EditorStyles.largeLabel, GUILayout.Height(20));
        EditorGUILayout.Separator();

        GUILayout.BeginVertical("box");
        EditorGUILayout.HelpBox(playgroundLanguage.categoriesInfo, MessageType.Info);
        EditorGUILayout.Separator();

        for (int i = 0; i < PlaygroundParticleWindowC.presetCategories.Count; i++)
        {
            GUILayout.BeginVertical("box");

            GUILayout.BeginHorizontal();

            PresetCategory thisCategory = PlaygroundParticleWindowC.presetCategories[i];

            bool isProtectedFolder = thisCategory.categoryName == "Uncategorized" || thisCategory.categoryName == "Resources";

            // Category unfold
            thisCategory.foldout = GUILayout.Toggle(thisCategory.foldout, "", EditorStyles.foldout, GUILayout.MaxWidth(16f));

            // Category name
            GUI.enabled = !isProtectedFolder;
            GUI.SetNextControlName(thisCategory.categoryName);
            thisCategory.tmpNewName = EditorGUILayout.TextField(thisCategory.tmpNewName, EditorStyles.toolbarTextField);
            GUI.enabled             = true;
            if (!isProtectedFolder && thisCategory.tmpNewName != thisCategory.categoryName)
            {
                if (GUILayout.Button(playgroundLanguage.rename, GUILayout.ExpandWidth(false)))
                {
                    bool isValidFolderName = IsValidFolderName(thisCategory.tmpNewName);
                    if (isValidFolderName)
                    {
                        if (AssetDatabase.RenameAsset("Assets/" + thisCategory.categoryLocation, thisCategory.tmpNewName).Length == 0)
                        {
                            AssetDatabase.Refresh();

                            // Succesfully renamed
                            thisCategory.categoryName = thisCategory.tmpNewName;
                            requestFocusControl       = true;
                            focusControlName          = thisCategory.categoryName;
                            return;
                        }
                        else
                        {
                            thisCategory.tmpNewName = thisCategory.categoryName;
                        }
                    }
                    else
                    {
                        thisCategory.tmpNewName = thisCategory.categoryName;
                    }
                }
            }

            // Show amount of selected presets
            int selectedPresetsInCategory = 0;
            for (int x = 0; x < thisCategory.presetObjects.Count; x++)
            {
                if (thisCategory.presetObjects[x].selected)
                {
                    selectedPresetsInCategory++;
                }
            }
            GUI.enabled = selectedPresetsInCategory > 0;
            GUILayout.Label("(" + selectedPresetsInCategory.ToString() + "/" + thisCategory.presetObjects.Count.ToString() + ")");
            GUI.enabled = true;

            EditorGUILayout.Separator();

            // Remove category
            GUI.enabled = !isProtectedFolder;
            if (GUILayout.Button("-", EditorStyles.toolbarButton, new GUILayoutOption[] { GUILayout.Width(18), GUILayout.Height(16) }) && !isProtectedFolder)
            {
                if (EditorUtility.DisplayDialog(playgroundLanguage.removeCategory,
                                                thisCategory.categoryName + " " + playgroundLanguage.removeCategoryText,
                                                playgroundLanguage.yes,
                                                playgroundLanguage.no))
                {
                    // Move all presets contained to "Uncategorized" (parent folder) before removing the category folder
                    string[] presetsInCategory = Directory.GetFiles(Application.dataPath + "/" + thisCategory.categoryLocation);
                    foreach (string presetLoc in presetsInCategory)
                    {
                        string convertedPresetPath = presetLoc.Substring(Application.dataPath.Length - 6);
                        Object presetPathObject    = (Object)AssetDatabase.LoadAssetAtPath(convertedPresetPath, typeof(Object));
                        if (presetPathObject != null && (presetPathObject.GetType().Name) == "GameObject")
                        {
                            AssetDatabase.MoveAsset(convertedPresetPath, "Assets/" + playgroundSettings.playgroundPath + playgroundSettings.examplePresetPath + presetPathObject.name);
                        }
                    }
                    AssetDatabase.MoveAssetToTrash("Assets/" + thisCategory.categoryLocation);
                    AssetDatabase.Refresh();
                    GUI.FocusControl(null);
                    return;
                }
            }
            GUI.enabled = true;

            GUILayout.EndHorizontal();

            // List of presets
            if (thisCategory.foldout)
            {
                EditorGUILayout.Separator();

                // Mixed selection
                if (thisCategory.presetObjects.Count > 0)
                {
                    EditorGUI.showMixedValue = selectedPresetsInCategory > 0 && selectedPresetsInCategory < thisCategory.presetObjects.Count;
                    bool multiSelect = selectedPresetsInCategory > 0;
                    EditorGUI.BeginChangeCheck();
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(4f);
                    multiSelect = EditorGUILayout.Toggle(multiSelect);
                    EditorGUILayout.EndHorizontal();
                    if (EditorGUI.EndChangeCheck())
                    {
                        for (int x = 0; x < thisCategory.presetObjects.Count; x++)
                        {
                            thisCategory.presetObjects[x].selected = multiSelect;
                        }
                    }
                    EditorGUI.showMixedValue = false;
                }

                EditorGUI.indentLevel++;

                if (thisCategory.presetObjects.Count > 0)
                {
                    for (int x = 0; x < thisCategory.presetObjects.Count; x++)
                    {
                        GUILayout.BeginHorizontal("box");
                        PresetObjectC thisPreset = thisCategory.presetObjects[x];
                        thisPreset.selected = GUILayout.Toggle(thisPreset.selected, "", GUILayout.MaxWidth(24f));
                        if (GUILayout.Button(thisPreset.presetImage, EditorStyles.label, new GUILayoutOption[] { GUILayout.Width(24), GUILayout.Height(24) }) ||
                            GUILayout.Button(thisPreset.presetObject.name, EditorStyles.label))
                        {
                            EditorGUIUtility.PingObject(thisPreset.presetObject);
                        }
                        GUILayout.EndHorizontal();
                    }
                }
                else
                {
                    GUI.enabled = false;
                    GUILayout.Label(playgroundLanguage.empty);
                    GUI.enabled = true;
                }
                EditorGUI.indentLevel--;
            }

            GUILayout.EndVertical();
        }

        // New category creation
        EditorGUILayout.Separator();
        GUILayout.BeginHorizontal();
        if (GUILayout.Button(playgroundLanguage.create, EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
        {
            if (IsValidFolderName(createCategoryName))
            {
                createCategoryName = createCategoryName.Trim();
                string createdFolder = AssetDatabase.CreateFolder("Assets/" + playgroundSettings.playgroundPath + (playgroundSettings.examplePresetPath).Substring(0, playgroundSettings.examplePresetPath.Length - 1), createCategoryName);
                if (createdFolder != null && createdFolder.Length > 0)
                {
                    AssetDatabase.Refresh();
                    foreach (PresetCategory cat in PlaygroundParticleWindowC.presetCategories)
                    {
                        if (AssetDatabase.AssetPathToGUID("Assets/" + cat.categoryLocation) == createdFolder)
                        {
                            cat.foldout         = true;
                            requestFocusControl = true;
                            focusControlName    = cat.categoryName;
                            break;
                        }
                    }
                    createCategoryName = "New Category";
                    return;
                }
            }
        }
        createCategoryName = EditorGUILayout.TextField(createCategoryName, EditorStyles.toolbarTextField);
        GUILayout.EndHorizontal();

        GUILayout.EndVertical();

        GUILayout.EndScrollView();

        int  selectedPresets        = 0;
        bool isResourcesPresetsOnly = true;

        for (int i = 0; i < PlaygroundParticleWindowC.presetCategories.Count; i++)
        {
            for (int x = 0; x < PlaygroundParticleWindowC.presetCategories[i].presetObjects.Count; x++)
            {
                if (PlaygroundParticleWindowC.presetCategories[i].presetObjects[x].selected)
                {
                    if (PlaygroundParticleWindowC.presetCategories[i].presetObjects[x].example)
                    {
                        isResourcesPresetsOnly = false;
                    }
                    selectedPresets++;
                }
            }
        }

        // Bottom toolbar for selected presets
        if (selectedPresets > 0)
        {
            EditorGUILayout.BeginHorizontal("box");
            EditorGUILayout.LabelField(playgroundLanguage.selected + ": " + selectedPresets.ToString(), GUILayout.MaxWidth(90));

            // Move selected presets
            if (categoryNames == null || categoryNames.Length != PlaygroundParticleWindowC.presetCategories.Count + 1)
            {
                categoryNames    = new string[PlaygroundParticleWindowC.presetCategories.Count + 1];
                categoryNames[0] = playgroundLanguage.move + "...";
                for (int i = 0; i < PlaygroundParticleWindowC.presetCategories.Count; i++)
                {
                    categoryNames[i + 1] = PlaygroundParticleWindowC.presetCategories[i].categoryName;
                }
            }
            int selectedMoveCategory = 0;
            EditorGUI.BeginChangeCheck();
            selectedMoveCategory = EditorGUILayout.Popup(selectedMoveCategory, categoryNames, EditorStyles.toolbarPopup);
            if (EditorGUI.EndChangeCheck())
            {
                if (selectedMoveCategory > 0)
                {
                    List <Object> movedObjects = new List <Object>();
                    foreach (PresetCategory cat in PlaygroundParticleWindowC.presetCategories)
                    {
                        foreach (PresetObjectC obj in cat.presetObjects)
                        {
                            if (obj.selected)
                            {
                                movedObjects.Add(obj.presetObject);
                                AssetDatabase.MoveAsset(AssetDatabase.GetAssetPath(obj.presetObject), "Assets/" + PlaygroundParticleWindowC.presetCategories[selectedMoveCategory - 1].categoryLocation + "/" + obj.presetObject.name);
                            }
                        }
                    }
                    AssetDatabase.Refresh();

                    // Select the moved objects once again for less confusion
                    foreach (PresetCategory cat in PlaygroundParticleWindowC.presetCategories)
                    {
                        foreach (PresetObjectC obj in cat.presetObjects)
                        {
                            if (movedObjects.Contains(obj.presetObject))
                            {
                                obj.selected = true;
                            }
                        }
                    }

                    // Open the index, correct if 'Uncategorized' got removed in the process
                    int openIndex = selectedMoveCategory - 1 < PlaygroundParticleWindowC.presetCategories.Count? selectedMoveCategory - 1 : selectedMoveCategory - 2;
                    PlaygroundParticleWindowC.presetCategories[openIndex].foldout = true;
                }
            }

            GUILayout.Space(4f);

            // Convert selected presets to Resources
            GUI.enabled = !isResourcesPresetsOnly;
            if (GUILayout.Button(playgroundLanguage.convertTo + " " + playgroundLanguage.resources, EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
            {
                if (EditorUtility.DisplayDialog(playgroundLanguage.convertPresetsIntoResources,
                                                playgroundLanguage.convertPresetsIntoResourcesText,
                                                playgroundLanguage.yes,
                                                playgroundLanguage.no))
                {
                    List <Object> convertedObjects = new List <Object>();

                    foreach (PresetCategory cat in PlaygroundParticleWindowC.presetCategories)
                    {
                        foreach (PresetObjectC obj in cat.presetObjects)
                        {
                            if (obj.selected)
                            {
                                if (!Directory.Exists(Application.dataPath + "/" + playgroundSettings.playgroundPath + playgroundSettings.presetPath))
                                {
                                    Directory.CreateDirectory(Application.dataPath + "/" + playgroundSettings.playgroundPath + playgroundSettings.presetPath);
                                    AssetDatabase.Refresh();
                                }
                                convertedObjects.Add(obj.presetObject);
                                AssetDatabase.MoveAsset(AssetDatabase.GetAssetPath(obj.presetObject), "Assets/" + playgroundSettings.playgroundPath + playgroundSettings.presetPath + obj.presetObject.name);
                            }
                        }
                    }

                    // Select the converted objects once again for less confusion
                    foreach (PresetCategory cat in PlaygroundParticleWindowC.presetCategories)
                    {
                        foreach (PresetObjectC obj in cat.presetObjects)
                        {
                            if (convertedObjects.Contains(obj.presetObject))
                            {
                                obj.selected = true;
                            }
                        }
                    }

                    PlaygroundParticleWindowC.presetCategories[PlaygroundParticleWindowC.presetCategories.Count - 1].foldout = true;
                }
            }
            GUI.enabled = true;

            GUILayout.Space(4f);

            // Remove selected presets
            if (GUILayout.Button(playgroundLanguage.remove, EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
            {
                if (EditorUtility.DisplayDialog(playgroundLanguage.removeSelectedPresets,
                                                playgroundLanguage.removeSelectedPresetsText,
                                                playgroundLanguage.yes,
                                                playgroundLanguage.no))
                {
                    foreach (PresetCategory cat in PlaygroundParticleWindowC.presetCategories)
                    {
                        foreach (PresetObjectC obj in cat.presetObjects)
                        {
                            if (obj.selected)
                            {
                                AssetDatabase.MoveAssetToTrash(AssetDatabase.GetAssetPath(obj.presetObject));
                            }
                        }
                    }
                }
            }

            GUILayout.Space(4f);

            // Publish selected presets
            if (GUILayout.Button(playgroundLanguage.publish, EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
            {
                PlaygroundCreatePresetWindowC.ShowWindowPublish();
            }

            EditorGUILayout.Separator();

            // Deselect selected presets
            if (GUILayout.Button(playgroundLanguage.deselectAll, EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
            {
                for (int i = 0; i < PlaygroundParticleWindowC.presetCategories.Count; i++)
                {
                    for (int x = 0; x < PlaygroundParticleWindowC.presetCategories[i].presetObjects.Count; x++)
                    {
                        PlaygroundParticleWindowC.presetCategories[i].presetObjects[x].selected = false;
                    }
                }
            }
            EditorGUILayout.EndHorizontal();
        }

        EditorGUILayout.EndVertical();

        if (requestFocusControl)
        {
            EditorGUI.FocusTextInControl(focusControlName);
            requestFocusControl = false;
        }
    }