mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-25 07:33:57 -06:00
Shows an error message when a user tries to add a printer with a name that already excists.
Also auto-generates numbering in the name, when the automatically generated machine-name is non-unique contributes to #CURA-325
This commit is contained in:
parent
98d2acaba7
commit
b2f4e2bf26
1 changed files with 89 additions and 11 deletions
|
@ -18,18 +18,70 @@ Item
|
||||||
|
|
||||||
property variant wizard: null;
|
property variant wizard: null;
|
||||||
|
|
||||||
|
property bool visibility: base.wizard.visible
|
||||||
|
onVisibilityChanged:
|
||||||
|
{
|
||||||
|
machineName.text = getMachineName()
|
||||||
|
errorMessage.show = false
|
||||||
|
}
|
||||||
|
|
||||||
|
function editMachineName(word)
|
||||||
|
{
|
||||||
|
//Adds '#2' at the end or increases the number by 1 if the word ends with '#' and 1 or more digits
|
||||||
|
var regEx = /[#][\d]+$///ends with '#' and then 1 or more digit
|
||||||
|
var result = word.match(regEx)
|
||||||
|
|
||||||
|
if (result != null)
|
||||||
|
{
|
||||||
|
result = result[0].split('')
|
||||||
|
|
||||||
|
var numberString = ''
|
||||||
|
for (var i = 1; i < result.length; i++){//starting at 1, makes it ignore the '#'
|
||||||
|
numberString += result[i]
|
||||||
|
}
|
||||||
|
var newNumber = Number(numberString) + 1
|
||||||
|
|
||||||
|
var newWord = word.replace(/[\d]+$/, newNumber)//replaces the last digits in the string by the same number + 1
|
||||||
|
return newWord
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return word + ' #2'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getMachineName()
|
||||||
|
{
|
||||||
|
var name = machineList.model.getItem(machineList.currentIndex).name
|
||||||
|
|
||||||
|
//if the automatically assigned name is not unique, the editMachineName function keeps editing it untill it is.
|
||||||
|
while (UM.MachineManager.getNameUniqueness(name) == false)
|
||||||
|
{
|
||||||
|
name = editMachineName(name)
|
||||||
|
}
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
|
||||||
Connections
|
Connections
|
||||||
{
|
{
|
||||||
target: base.wizard
|
target: base.wizard
|
||||||
onNextClicked: //You can add functions here that get triggered when the final button is clicked in the wizard-element
|
onNextClicked: //You can add functions here that get triggered when the final button is clicked in the wizard-element
|
||||||
{
|
{
|
||||||
var old_page_count = base.wizard.getPageCount()
|
var name = machineName.text
|
||||||
// Delete old pages (if any)
|
if (UM.MachineManager.getNameUniqueness(name) == false)
|
||||||
for (var i = old_page_count - 1; i > 0; i--)
|
|
||||||
{
|
{
|
||||||
base.wizard.removePage(i)
|
errorMessage.show = true
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var old_page_count = base.wizard.getPageCount()
|
||||||
|
// Delete old pages (if any)
|
||||||
|
for (var i = old_page_count - 1; i > 0; i--)
|
||||||
|
{
|
||||||
|
base.wizard.removePage(i)
|
||||||
|
}
|
||||||
|
saveMachine()
|
||||||
|
base.wizard.visible = false
|
||||||
}
|
}
|
||||||
saveMachine()
|
|
||||||
}
|
}
|
||||||
onBackClicked:
|
onBackClicked:
|
||||||
{
|
{
|
||||||
|
@ -63,7 +115,8 @@ Item
|
||||||
{
|
{
|
||||||
id: machinesHolder
|
id: machinesHolder
|
||||||
|
|
||||||
anchors{
|
anchors
|
||||||
|
{
|
||||||
left: parent.left;
|
left: parent.left;
|
||||||
top: subTitle.bottom;
|
top: subTitle.bottom;
|
||||||
right: parent.right;
|
right: parent.right;
|
||||||
|
@ -110,6 +163,7 @@ Item
|
||||||
onClicked: {
|
onClicked: {
|
||||||
base.activeManufacturer = section;
|
base.activeManufacturer = section;
|
||||||
machineList.currentIndex = machineList.model.find("manufacturer", section)
|
machineList.currentIndex = machineList.model.find("manufacturer", section)
|
||||||
|
machineName.text = getMachineName()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +182,10 @@ Item
|
||||||
|
|
||||||
text: model.name
|
text: model.name
|
||||||
|
|
||||||
onClicked: ListView.view.currentIndex = index;
|
onClicked: {
|
||||||
|
ListView.view.currentIndex = index;
|
||||||
|
machineName.text = getMachineName()
|
||||||
|
}
|
||||||
|
|
||||||
Label
|
Label
|
||||||
{
|
{
|
||||||
|
@ -169,11 +226,33 @@ Item
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Item
|
|
||||||
|
|
||||||
|
Column
|
||||||
{
|
{
|
||||||
id: machineNameHolder
|
id: machineNameHolder
|
||||||
height: childrenRect.height
|
|
||||||
anchors.bottom: parent.bottom;
|
anchors.bottom: parent.bottom;
|
||||||
|
//height: insertNameLabel.lineHeight * (2 + errorMessage.lineCount)
|
||||||
|
|
||||||
|
Item
|
||||||
|
{
|
||||||
|
height: errorMessage.lineHeight
|
||||||
|
anchors.bottom: insertNameLabel.top
|
||||||
|
anchors.bottomMargin: insertNameLabel.height * errorMessage.lineCount
|
||||||
|
Label
|
||||||
|
{
|
||||||
|
id: errorMessage
|
||||||
|
property bool show: false
|
||||||
|
width: base.width
|
||||||
|
height: errorMessage.show ? errorMessage.lineHeight : 0
|
||||||
|
visible: errorMessage.show
|
||||||
|
text: catalog.i18nc("@label", "This printer name has already been used. Please choose a different printer name.");
|
||||||
|
wrapMode: Text.WordWrap
|
||||||
|
Behavior on height {NumberAnimation {duration: 75; }}
|
||||||
|
color: UM.Theme.colors.error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Label
|
Label
|
||||||
{
|
{
|
||||||
id: insertNameLabel
|
id: insertNameLabel
|
||||||
|
@ -182,8 +261,7 @@ Item
|
||||||
TextField
|
TextField
|
||||||
{
|
{
|
||||||
id: machineName;
|
id: machineName;
|
||||||
anchors.top: insertNameLabel.bottom
|
text: getMachineName()
|
||||||
text: machineList.model.getItem(machineList.currentIndex).name
|
|
||||||
implicitWidth: UM.Theme.sizes.standard_list_input.width
|
implicitWidth: UM.Theme.sizes.standard_list_input.width
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue