<commit_before>// Copyright (c) 2015 Ultimaker B.V.
// Cura is released under the terms of the AGPLv3 or higher.

import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.1
import QtQuick.Layouts 1.1

import UM 1.1 as UM

Rectangle {
    id: base;

    property real progress: UM.Backend.progress;
    property bool activity: Printer.getPlatformActivity;
    Behavior on progress { NumberAnimation { duration: 250; } }
    property int totalHeight: childrenRect.height
    property string fileBaseName
    property variant activeMachineInstance: UM.MachineManager.activeMachineInstance

    onActiveMachineInstanceChanged:
    {
        base.createFileName()
    }

    UM.I18nCatalog { id: catalog; name:"cura"}

    property variant printDuration: PrintInformation.currentPrintTime;
    property real printMaterialAmount: PrintInformation.materialAmount;

    function createFileName(){
        var splitMachineName = UM.MachineManager.activeMachineInstance.split(" ")
        var abbrMachine = ''
            for (var i = 0; i < splitMachineName.length; i++){
                if (splitMachineName[i].search(/ultimaker/i) != -1){
                    abbrMachine += 'UM'
                }
                else{
                    if (splitMachineName[i].charAt(0).search(/[0-9]/g) == -1)
                        abbrMachine += splitMachineName[i].charAt(0)
                }
                var regExpAdditives = /[0-9\+]/g;
                var resultAdditives = splitMachineName[i].match(regExpAdditives);
                if (resultAdditives != null){
                    for (var j = 0; j < resultAdditives.length; j++){
                        abbrMachine += resultAdditives[j]

                    }
                }
            }
        //printJobTextfield.text = abbrMachine + '_' + base.fileBaseName
    }

     Connections {
        target: openDialog
        onHasMesh: {
            base.fileBaseName = name
            base.createFileName()
        }
    }

    Rectangle{
        id: printJobRow
        implicitWidth: base.width;
        //implicitHeight: UM.Theme.sizes.sidebar_header.height /////////////remove this TODO
        implicitHeight: 1
        anchors.top: parent.top
        //color: UM.Theme.colors.sidebar_header_bar
        color: UM.Theme.colors.setting_control_border
//         Label{
//             id: printJobTextfieldLabel
//             text: catalog.i18nc("@label","Printjob name");
//             anchors.left: parent.left
//             anchors.leftMargin: UM.Theme.sizes.default_margin.width;
//             anchors.verticalCenter: parent.verticalCenter
//             font: UM.Theme.fonts.default;
//             color: UM.Theme.colors.text_white
//         }
//         TextField {
//             id: printJobTextfield
//             anchors.right: parent.right
//             anchors.rightMargin: UM.Theme.sizes.default_margin.width;
//             anchors.verticalCenter: parent.verticalCenter
//             width: parent.width/100*55
//             height: UM.Theme.sizes.sidebar_inputFields.height
//             property int unremovableSpacing: 5
//             text: ''
//             onEditingFinished: {
//                 if (printJobTextfield.text != ''){
//                     printJobTextfield.focus = false
//                 }
//             }
//             validator: RegExpValidator {
//                 regExp: /^[^\\ \/ \.]*$/
//             }
//             style: TextFieldStyle{
//                 textColor: UM.Theme.colors.setting_control_text;
//                 font: UM.Theme.fonts.default;
//                 background: Rectangle {
//                     radius: 0
//                     implicitWidth: parent.width
//                     implicitHeight: parent.height
//                     border.width: 1;
//                     border.color: UM.Theme.colors.slider_groove_border;
//                 }
//             }
//         }
    }

    Rectangle {
        id: specsRow
        implicitWidth: base.width
        implicitHeight: UM.Theme.sizes.sidebar_specs_bar.height
        anchors.top: printJobRow.bottom
        Item{
            id: time
            width: (parent.width / 100 * 45) - UM.Theme.sizes.default_margin.width * 2
            height: parent.height
            anchors.left: parent.left
            anchors.leftMargin: UM.Theme.sizes.default_margin.width
            anchors.top: parent.top
            visible: base.printMaterialAmount > 0 ? true : false
            UM.RecolorImage {
                id: timeIcon
                anchors.verticalCenter: parent.verticalCenter
                anchors.left: parent.left
                width: UM.Theme.sizes.save_button_specs_icons.width
                height: UM.Theme.sizes.save_button_specs_icons.height
                sourceSize.width: width
                sourceSize.height: width
                color: UM.Theme.colors.text_hover
                source: UM.Theme.icons.print_time;
            }
            Label{
                id: timeSpec
                anchors.verticalCenter: parent.verticalCenter
                anchors.left: timeIcon.right
                anchors.leftMargin: UM.Theme.sizes.default_margin.width/2
                font: UM.Theme.fonts.default
                color: UM.Theme.colors.text
                text: (!base.printDuration || !base.printDuration.valid) ? "" : catalog.i18nc("@label h:m (hours:minutes) is added to the expected printtime (%1)", "%1 h:m").arg(base.printDuration.getDisplayString(UM.DurationFormat.Short))
            }
        }
        Item{
            width: parent.width / 100 * 55
            height: parent.height
            anchors.left: time.right
            anchors.top: parent.top
            visible: base.printMaterialAmount > 0 ? true : false
            UM.RecolorImage {
                id: lengthIcon
                anchors.verticalCenter: parent.verticalCenter
                anchors.left: parent.left
                width: UM.Theme.sizes.save_button_specs_icons.width
                height: UM.Theme.sizes.save_button_specs_icons.height
                sourceSize.width: width
                sourceSize.height: width
                color: UM.Theme.colors.text_hover
                source: UM.Theme.icons.category_material;
            }
            Label{
                id: lengthSpec
                anchors.verticalCenter: parent.verticalCenter
                anchors.left: lengthIcon.right
                anchors.leftMargin: UM.Theme.sizes.default_margin.width/2
                font: UM.Theme.fonts.default
                color: UM.Theme.colors.text
                text: base.printMaterialAmount <= 0 ? "" : catalog.i18nc("@label","%1 m").arg(base.printMaterialAmount)
            }
        }
    }

    Rectangle{
        id: saveRow
        width: base.width
        height: saveToButton.height + (UM.Theme.sizes.default_margin.height / 2) // height + bottomMargin
        anchors.top: specsRow.bottom
        anchors.left: parent.left

        Button {
            id: saveToButton
            property int resizedWidth
            x: base.width - saveToButton.resizedWidth - UM.Theme.sizes.default_margin.width - UM.Theme.sizes.save_button_save_to_button.height
            tooltip: UM.OutputDeviceManager.activeDeviceDescription;
            enabled: base.progress > 0.99 && base.activity == true
            height: UM.Theme.sizes.save_button_save_to_button.height<commit_msg>re-implements the safebutton -> filename -> textfield<commit_after>// Copyright (c) 2015 <NAME>.V.
// Cura is released under the terms of the AGPLv3 or higher.

import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.1
import QtQuick.Layouts 1.1

import UM 1.1 as UM

Rectangle {
    id: base;

    property real progress: UM.Backend.progress;
    property bool activity: Printer.getPlatformActivity;
    Behavior on progress { NumberAnimation { duration: 250; } }
    property int totalHeight: childrenRect.height
    property string fileBaseName
    property variant activeMachineInstance: UM.MachineManager.activeMachineInstance

    onActiveMachineInstanceChanged:
    {
        base.createFileName()
    }

    UM.I18nCatalog { id: catalog; name:"cura"}

    property variant printDuration: PrintInformation.currentPrintTime;
    property real printMaterialAmount: PrintInformation.materialAmount;

    function createFileName(){
        var splitMachineName = UM.MachineManager.activeMachineInstance.split(" ")
        var abbrMachine = ''
            for (var i = 0; i < splitMachineName.length; i++){
                if (splitMachineName[i].search(/ultimaker/i) != -1){
                    abbrMachine += 'UM'
                }
                else{
                    if (splitMachineName[i].charAt(0).search(/[0-9]/g) == -1)
                        abbrMachine += splitMachineName[i].charAt(0)
                }
                var regExpAdditives = /[0-9\+]/g;
                var resultAdditives = splitMachineName[i].match(regExpAdditives);
                if (resultAdditives != null){
                    for (var j = 0; j < resultAdditives.length; j++){
                        abbrMachine += resultAdditives[j]

                    }
                }
            }
        printJobTextfield.text = abbrMachine + '_' + base.fileBaseName
    }

     Connections {
        target: openDialog
        onHasMesh: {
            base.fileBaseName = name
            base.createFileName()
        }
    }

    Rectangle{
        id: printJobRow
        implicitWidth: base.width;
        implicitHeight: UM.Theme.sizes.sidebar_header.height
        anchors.top: parent.top
        color: UM.Theme.colors.sidebar_header_bar
        Label{
            id: printJobTextfieldLabel
            text: catalog.i18nc("@label:textbox", "Printjob name");
            anchors.left: parent.left
            anchors.leftMargin: UM.Theme.sizes.default_margin.width;
            anchors.verticalCenter: parent.verticalCenter
            font: UM.Theme.fonts.default;
            color: UM.Theme.colors.text_white
        }
        TextField {
            id: printJobTextfield
            anchors.right: parent.right
            anchors.rightMargin: UM.Theme.sizes.default_margin.width;
            anchors.verticalCenter: parent.verticalCenter
            width: parent.width/100*55
            height: UM.Theme.sizes.sidebar_inputFields.height
            property int unremovableSpacing: 5
            text: ''
            onEditingFinished: {
                if (printJobTextfield.text != ''){
                    printJobTextfield.focus = false
                }
            }
            validator: RegExpValidator {
                regExp: /^[^\\ \/ \.]*$/
            }
            style: TextFieldStyle{
                textColor: UM.Theme.colors.setting_control_text;
                font: UM.Theme.fonts.default;
                background: Rectangle {
                    radius: 0
                    implicitWidth: parent.width
                    implicitHeight: parent.height
                    border.width: 1;
                    border.color: UM.Theme.colors.slider_groove_border;
                }
            }
        }
    }

    Rectangle {
        id: specsRow
        implicitWidth: base.width
        implicitHeight: UM.Theme.sizes.sidebar_specs_bar.height
        anchors.top: printJobRow.bottom
        Item{
            id: time
            width: (parent.width / 100 * 45) - UM.Theme.sizes.default_margin.width * 2
            height: parent.height
            anchors.left: parent.left
            anchors.leftMargin: UM.Theme.sizes.default_margin.width
            anchors.top: parent.top
            visible: base.printMaterialAmount > 0 ? true : false
            UM.RecolorImage {
                id: timeIcon
                anchors.verticalCenter: parent.verticalCenter
                anchors.left: parent.left
                width: UM.Theme.sizes.save_button_specs_icons.width
                height: UM.Theme.sizes.save_button_specs_icons.height
                sourceSize.width: width
                sourceSize.height: width
                color: UM.Theme.colors.text_hover
                source: UM.Theme.icons.print_time;
            }
            Label{
                id: timeSpec
                anchors.verticalCenter: parent.verticalCenter
                anchors.left: timeIcon.right
                anchors.leftMargin: UM.Theme.sizes.default_margin.width/2
                font: UM.Theme.fonts.default
                color: UM.Theme.colors.text
                text: (!base.printDuration || !base.printDuration.valid) ? "" : catalog.i18nc("@label h:m (abbreviation for hours:minutes) is added to the expected printtime (%1)", "%1 h:m").arg(base.printDuration.getDisplayString(UM.DurationFormat.Short))
            }
        }
        Item{
            width: parent.width / 100 * 55
            height: parent.height
            anchors.left: time.right
            anchors.top: parent.top
            visible: base.printMaterialAmount > 0 ? true : false
            UM.RecolorImage {
                id: lengthIcon
                anchors.verticalCenter: parent.verticalCenter
                anchors.left: parent.left
                width: UM.Theme.sizes.save_button_specs_icons.width
                height: UM.Theme.sizes.save_button_specs_icons.height
                sourceSize.width: width
                sourceSize.height: width
                color: UM.Theme.colors.text_hover
                source: UM.Theme.icons.category_material;
            }
            Label{
                id: lengthSpec
                anchors.verticalCenter: parent.verticalCenter
                anchors.left: lengthIcon.right
                anchors.leftMargin: UM.Theme.sizes.default_margin.width/2
                font: UM.Theme.fonts.default
                color: UM.Theme.colors.text
                text: base.printMaterialAmount <= 0 ? "" : catalog.i18nc("@label m (abbreviation for meters) is added to the expected length of filament (%1) ","%1 m").arg(base.printMaterialAmount)
            }
        }
    }

    Rectangle{
        id: saveRow
        width: base.width
        height: saveToButton.height + (UM.Theme.sizes.default_margin.height / 2) // height + bottomMargin
        anchors.top: specsRow.bottom
        anchors.left: parent.left

        Button {
            id: saveToButton
            property int resizedWidth
            x: base.width - saveToButton.resizedWidth - UM.Theme.sizes.default_margin.width - UM.Theme.sizes.save_button_save_to_button.height
            tooltip: UM.OutputDeviceManager.activeDeviceDescription;
            enabled: base.progress > 0.99 && base.activity == true
            height: UM.Theme.sizes.save_button_save_to_button.height
{'fraction_non_alphanumeric': 0.0931064749172912, 'fraction_numerical': 0.009182364458848154, 'mean_word_length': 1.6616352201257862, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 12, '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': '2201886', 'n_tokens_mistral': 4200, 'n_tokens_neox': 3889, 'n_words': 758}