[Macros Dialog] Add 2 new parameters: DuplicateIgnoreExtraNote and DuplicateReplaceSpaces
This commit is contained in:
@@ -718,6 +718,20 @@ void DlgMacroExecuteImp::on_duplicateButton_clicked()
|
||||
|
||||
bool from001 = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")->GetBool("DuplicateFrom001", false);
|
||||
App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")->SetBool("DuplicateFrom001", from001); //create parameter
|
||||
|
||||
//A user may wish to add a note to end of the filename when duplicating
|
||||
//example: mymacro@005.fix_bug_in_dialog.FCMacro
|
||||
//and then when duplicating to have the extra note removed so the suggested new name is:
|
||||
//mymacro@006.FCMacro instead of mymacro@006.fix_bug_in_dialog.FCMacro since the new duplicate will be given a new note
|
||||
|
||||
bool ignoreExtra = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")->GetBool("DuplicateIgnoreExtraNote", false);
|
||||
App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")->SetBool("DuplicateIgnoreExtraNote", ignoreExtra); //create parameter
|
||||
|
||||
//when creating a note it will be convenient to convert spaces to underscores if the user desires this behavior
|
||||
|
||||
bool replaceSpaces = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")->GetBool("DuplicateReplaceSpaces", false);
|
||||
App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")->SetBool("DuplicateReplaceSpaces", replaceSpaces); //create parameter
|
||||
|
||||
int index = ui->tabMacroWidget->currentIndex();
|
||||
if (index == 0) { //user-specific
|
||||
item = ui->userMacroListBox->currentItem();
|
||||
@@ -732,6 +746,7 @@ void DlgMacroExecuteImp::on_duplicateButton_clicked()
|
||||
QFileInfo oldfi(dir, oldName);
|
||||
QFile oldfile(oldfi.absoluteFilePath());
|
||||
QString completeSuffix = oldfi.completeSuffix(); //everything after the first "."
|
||||
QString extraNote = completeSuffix.left(completeSuffix.size()-oldfi.suffix().size());
|
||||
QString baseName = oldfi.baseName(); //everything before first "."
|
||||
QString neutralSymbol = QString::fromStdString("@");
|
||||
QString last3 = baseName.right(3);
|
||||
@@ -752,14 +767,28 @@ void DlgMacroExecuteImp::on_duplicateButton_clicked()
|
||||
}
|
||||
//at this point baseName = the base name without any digits, e.g. "MyMacro"
|
||||
//neutralSymbol = "@"
|
||||
//last3 is a string representing 3 digits, always "001" at this time
|
||||
//last3 is a string representing 3 digits, always "001"
|
||||
//unless from001 = false, in which case we begin with previous numbers
|
||||
//completeSuffix = FCMacro or py or FCMacro.py or else suffix will become FCMacro below
|
||||
//if ignoreExtra any extra notes added between @NN. and .FCMacro will be ignored
|
||||
//when suggesting a new filename
|
||||
|
||||
if(ignoreExtra && !extraNote.isEmpty()){
|
||||
nLast3++;
|
||||
last3 = QString::number(nLast3);
|
||||
while (last3.size()<3){
|
||||
last3.prepend(QString::fromStdString("0")); //pad 0's if needed
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QString oldNameDigitized = baseName+neutralSymbol+last3+QString::fromStdString(".")+completeSuffix;
|
||||
QFileInfo fi(dir, oldNameDigitized);
|
||||
|
||||
|
||||
// increment until we find available name with smallest digits
|
||||
// test from "001" through "999", then give up and let user enter name of choice
|
||||
|
||||
while (fi.exists()) {
|
||||
nLast3 = last3.toInt()+1;
|
||||
if (nLast3 >=1000){ //avoid infinite loop, 999 files will have to be enough
|
||||
@@ -773,10 +802,17 @@ void DlgMacroExecuteImp::on_duplicateButton_clicked()
|
||||
fi = QFileInfo(dir,oldNameDigitized);
|
||||
}
|
||||
|
||||
if(ignoreExtra && !extraNote.isEmpty()){
|
||||
oldNameDigitized = oldNameDigitized.remove(extraNote);
|
||||
}
|
||||
|
||||
// give user a chance to pick a different name from digitized name suggested
|
||||
QString fn = QInputDialog::getText(this, tr("Duplicate Macro"),
|
||||
tr("Enter new name:"), QLineEdit::Normal, oldNameDigitized,
|
||||
nullptr, Qt::MSWindowsFixedSizeDialogHint);
|
||||
if (replaceSpaces){
|
||||
fn = fn.replace(QString::fromStdString(" "),QString::fromStdString("_"));
|
||||
}
|
||||
if (!fn.isEmpty() && fn != oldName) {
|
||||
QString suffix = QFileInfo(fn).suffix().toLower();
|
||||
if (suffix != QLatin1String("fcmacro") && suffix != QLatin1String("py")){
|
||||
|
||||
Reference in New Issue
Block a user