<commit_before>// Copyright (c) 2015 <NAME>.
// Uranium is released under the terms of the AGPLv3 or higher.

import QtQuick 2.1
import QtQuick.Controls 1.1
import QtQuick.Dialogs 1.2

import UM 1.2 as UM
import Cura 1.0 as Cura

UM.ManagementPage
{
    id: base;

    title: catalog.i18nc("@title:tab", "Profiles");
    addText: catalog.i18nc("@label", "Duplicate")

    model: UM.InstanceContainersModel { filter: { "type": "quality" } }

    activeId: Cura.MachineManager.activeQualityId
    activeIndex: {
        for(var i = 0; i < model.rowCount(); i++) {
            if (model.getItem(i).id == Cura.MachineManager.activeQualityId) {
                return i;
            }
        }
        return -1;
    }

    onActivateObject: Cura.MachineManager.setActiveQuality(currentItem.id)
    onAddObject: {
        var selectedProfile;
        if (objectList.currentIndex == 0) {
            // Current settings
            selectedProfile = UM.MachineManager.createProfile();
        } else {
            selectedProfile = UM.MachineManager.duplicateProfile(currentItem.name);
        }
        base.selectProfile(selectedProfile);

        renameDialog.removeWhenRejected = true;
        renameDialog.open();
        renameDialog.selectText();
    }
    onRemoveObject: confirmDialog.open();
    onRenameObject: { renameDialog.removeWhenRejected = false; renameDialog.open(); renameDialog.selectText(); }

    activateEnabled: currentItem != null ? currentItem.id != Cura.MachineManager.activeQualityId : false;
    addEnabled: currentItem != null;
    removeEnabled: currentItem != null ? !currentItem.readOnly : false;
    renameEnabled: currentItem != null ? !currentItem.readOnly : false;

    scrollviewCaption: catalog.i18nc("@label %1 is printer name","Printer: %1").arg(UM.MachineManager.activeMachineInstance)

    signal selectProfile(string name)
    onSelectProfile: {
        objectList.currentIndex = objectList.model.find("name", name);
    }

    Item {
        visible: base.currentItem != null
        anchors.fill: parent

        Label {
            id: profileName
            text: base.currentItem ? base.currentItem.name : ""
            font: UM.Theme.getFont("large")
            width: parent.width
            elide: Text.ElideRight
        }

        ScrollView {
            anchors.left: parent.left
            anchors.top: profileName.bottom
            anchors.topMargin: UM.Theme.getSize("default_margin").height
            anchors.right: parent.right
            anchors.bottom: parent.bottom

            Column
            {
                spacing: UM.Theme.getSize("default_margin").height

                Row
                {
                    visible: base.currentItem.id == -1 || currentItem.id == Cura.MachineManager.activeQualityId
                    Button
                    {
                        text: {
                            var profileName = UM.MachineManager.activeProfile;
                            profileName = (profileName.length > 20) ? profileName.substring(0, 20) + '...' : profileName;
                            return catalog.i18nc("@action:button", "Update \"%1\"".arg(profileName));
                        }
                        enabled: Cura.MachineManager.hasUserSettings && !Cura.MachineManager.isReadOnly(Cura.MachineManager.activeQualityId)
                        onClicked: UM.ActiveProfile.updateProfile()
                    }

                    Button
                    {
                        text: catalog.i18nc("@action:button", "Discard changes");
                        enabled: Cura.MachineManager.hasUserSettings
                        onClicked: Cura.MachineManager.clearUserSettings();
                    }
                }

                Grid
                {
                    id: containerGrid
                    columns: 2
                    spacing: UM.Theme.getSize("default_margin").width

                    Label {
                        text: base.currentItem == null ? "" :
                            base.currentItem.id == -1 ? catalog.i18nc("@label", "Based on") : catalog.i18nc("@label", "Profile type")
                    }
                    Label {
                        text: base.currentItem == null ? "" :
                            base.currentItem.id == -1 ? Cura.MachineManager.activeQualityName:
                            base.currentItem.readOnly ? catalog.i18nc("@label", "Protected profile") : catalog.i18nc("@label", "Custom profile")
                    }

                    Column {
                        Repeater {<commit_msg>Updating profile now also works in profile page<commit_after>// Copyright (c) 2015 Ultimaker B.V.
// Uranium is released under the terms of the AGPLv3 or higher.

import QtQuick 2.1
import QtQuick.Controls 1.1
import QtQuick.Dialogs 1.2

import UM 1.2 as UM
import Cura 1.0 as Cura

UM.ManagementPage
{
    id: base;

    title: catalog.i18nc("@title:tab", "Profiles");
    addText: catalog.i18nc("@label", "Duplicate")

    model: UM.InstanceContainersModel { filter: { "type": "quality" } }

    activeId: Cura.MachineManager.activeQualityId
    activeIndex: {
        for(var i = 0; i < model.rowCount(); i++) {
            if (model.getItem(i).id == Cura.MachineManager.activeQualityId) {
                return i;
            }
        }
        return -1;
    }

    onActivateObject: Cura.MachineManager.setActiveQuality(currentItem.id)
    onAddObject: {
        var selectedContainer;
        if (objectList.currentIndex == 0) {
            // Current settings
            selectedContainer = Cura.MachineManager.convertUserContainerToQuality();
        } else {
            selectedContainer = Cura.MachineManager.duplicateContainer(currentItem.id);
        }
        base.selectContainer(selectedContainer);

        renameDialog.removeWhenRejected = true;
        renameDialog.open();
        renameDialog.selectText();
    }
    onRemoveObject: confirmDialog.open();
    onRenameObject: { renameDialog.removeWhenRejected = false; renameDialog.open(); renameDialog.selectText(); }

    activateEnabled: currentItem != null ? currentItem.id != Cura.MachineManager.activeQualityId : false;
    addEnabled: currentItem != null;
    removeEnabled: currentItem != null ? !currentItem.readOnly : false;
    renameEnabled: currentItem != null ? !currentItem.readOnly : false;

    scrollviewCaption: catalog.i18nc("@label %1 is printer name","Printer: %1").arg(Cura.MachineManager.activeMachineName)

    signal selectContainer(string id)
    onSelectContainer: {
        objectList.currentIndex = objectList.model.find("id", id);
    }

    Item {
        visible: base.currentItem != null
        anchors.fill: parent

        Label {
            id: profileName
            text: base.currentItem ? base.currentItem.name : ""
            font: UM.Theme.getFont("large")
            width: parent.width
            elide: Text.ElideRight
        }

        ScrollView {
            anchors.left: parent.left
            anchors.top: profileName.bottom
            anchors.topMargin: UM.Theme.getSize("default_margin").height
            anchors.right: parent.right
            anchors.bottom: parent.bottom

            Column
            {
                spacing: UM.Theme.getSize("default_margin").height

                Row
                {
                    visible: base.currentItem.id == -1 || currentItem.id == Cura.MachineManager.activeQualityId
                    Button
                    {
                        text: {
                            var profileName = Cura.MachineManager.activeQualityName;
                            profileName = (profileName.length > 20) ? profileName.substring(0, 20) + '...' : profileName;
                            return catalog.i18nc("@action:button", "Update \"%1\"".arg(profileName));
                        }
                        enabled: Cura.MachineManager.hasUserSettings && !Cura.MachineManager.isReadOnly(Cura.MachineManager.activeQualityId)
                        onClicked: Cura.MachineManager.updateUserContainerToQuality()
                    }

                    Button
                    {
                        text: catalog.i18nc("@action:button", "Discard changes");
                        enabled: Cura.MachineManager.hasUserSettings
                        onClicked: Cura.MachineManager.clearUserSettings();
                    }
                }

                Grid
                {
                    id: containerGrid
                    columns: 2
                    spacing: UM.Theme.getSize("default_margin").width

                    Label {
                        text: base.currentItem == null ? "" :
                            base.currentItem.id == -1 ? catalog.i18nc("@label", "Based on") : catalog.i18nc("@label", "Profile type")
                    }
                    Label {
                        text: base.currentItem == null ? "" :
                            base.currentItem.id == -1 ? Cura.MachineManager.activeQualityName:
                            base.currentItem.readOnly ? catalog.i18nc("@label", "Protected profile") : catalog.i18nc("@label", "Custom profile")
                    }

                    Column {
                        Repeater {
{'fraction_non_alphanumeric': 0.10194854128539133, 'fraction_numerical': 0.010334804607600388, 'mean_word_length': 1.7052999417588817, 'pattern_counts': {'":': 2, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1549479', 'n_tokens_mistral': 2530, 'n_tokens_neox': 2338, 'n_words': 462}