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

import QtQuick 2.1
import QtQuick.Controls 1.1

import UM 1.2 as UM
import Cura 1.0 as Cura

UM.ManagementPage
{
    id: base;

    title: catalog.i18nc("@title:tab", "Printers");
    property int numInstances: model.rowCount();
    model: UM.ContainerStacksModel
    {
        filter: {"type": "machine"}
        onDataChanged: numInstances = model.rowCount()
    }

    onAddObject: Printer.requestAddPrinter()
    onRemoveObject: confirmDialog.open();
    onRenameObject: renameDialog.open();
    onActivateObject: Cura.MachineManager.setActiveMachine(base.currentItem.id)

    removeEnabled: base.currentItem != null && numInstances > 1
    renameEnabled: base.currentItem != null && numInstances > 0
    activateEnabled: base.currentItem != null

    Flow
    {
        anchors.fill: parent;
        spacing: UM.Theme.getSize("default_margin").height;

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

        Label { text: catalog.i18nc("@label", "Type"); width: parent.width * 0.2; }
        Label { text: base.currentItem && base.currentItem.typeName ? base.currentItem.typeName : ""; width: parent.width * 0.7; }

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

        UM.ConfirmRemoveDialog
        {
            id: confirmDialog;
            object: base.currentItem && base.currentItem.name ? base.currentItem.name : "";
            onYes: Cura.MachineManager.removeMachine(base.currentItem.id);
        }

        UM.RenameDialog
        {
            id: renameDialog;
            object: base.currentItem && base.currentItem.name ? base.currentItem.name : "";
            onAccepted:
            {
                Cura.MachineManager.renameMachine(base.currentItem.id, newName.trim());
                //Reselect current item to update details panel
                var index = objectList.currentIndex
                objectList.currentIndex = -1
                objectList.currentIndex = index
            }
        }
    }
}
<commit_msg>Prevent removing the last printer, disable Activate button for current active printer<commit_after>// Copyright (c) 2016 <NAME>.V.
// Uranium is released under the terms of the AGPLv3 or higher.

import QtQuick 2.1
import QtQuick.Controls 1.1

import UM 1.2 as UM
import Cura 1.0 as Cura

UM.ManagementPage
{
    id: base;

    title: catalog.i18nc("@title:tab", "Printers");
    model: UM.ContainerStacksModel
    {
        filter: {"type": "machine"}
    }

    onAddObject: Printer.requestAddPrinter()
    onRemoveObject: confirmDialog.open();
    onRenameObject: renameDialog.open();
    onActivateObject: Cura.MachineManager.setActiveMachine(base.currentItem.id)

    removeEnabled: base.currentItem != null && model.rowCount() > 1
    renameEnabled: base.currentItem != null
    activateEnabled: base.currentItem != null && base.currentItem.id != Cura.MachineManager.activeMachineId

    Flow
    {
        anchors.fill: parent;
        spacing: UM.Theme.getSize("default_margin").height;

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

        Label { text: catalog.i18nc("@label", "Type"); width: parent.width * 0.2; }
        Label { text: base.currentItem && base.currentItem.typeName ? base.currentItem.typeName : ""; width: parent.width * 0.7; }

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

        UM.ConfirmRemoveDialog
        {
            id: confirmDialog;
            object: base.currentItem && base.currentItem.name ? base.currentItem.name : "";
            onYes: Cura.MachineManager.removeMachine(base.currentItem.id);
        }

        UM.RenameDialog
        {
            id: renameDialog;
            object: base.currentItem && base.currentItem.name ? base.currentItem.name : "";
            onAccepted:
            {
                Cura.MachineManager.renameMachine(base.currentItem.id, newName.trim());
                //Reselect current item to update details panel
                var index = objectList.currentIndex
                objectList.currentIndex = -1
                objectList.currentIndex = index
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.10969162995594714, 'fraction_numerical': 0.011233480176211454, 'mean_word_length': 2.2763347763347763, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 8, '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': '6790681', 'n_tokens_mistral': 1361, 'n_tokens_neox': 1283, 'n_words': 284}