Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macro: Macro Rename #973

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Gui/DlgMacroExecute.ui
Expand Up @@ -246,11 +246,24 @@
</item>
<item>
<widget class="QPushButton" name="editButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="renameButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Rename</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
Expand Down
76 changes: 71 additions & 5 deletions src/Gui/DlgMacroExecuteImp.cpp
Expand Up @@ -53,9 +53,9 @@ namespace Gui {
MacroItem(QTreeWidget * widget, bool systemwide)
: QTreeWidgetItem(widget),
systemWide(systemwide){}

~MacroItem(){}

bool systemWide;
};
}
Expand All @@ -65,8 +65,8 @@ namespace Gui {
/* TRANSLATOR Gui::Dialog::DlgMacroExecuteImp */

/**
* Constructs a DlgMacroExecuteImp which is a child of 'parent', with the
* name 'name' and widget flags set to 'f'
* Constructs a DlgMacroExecuteImp which is a child of 'parent', with the
* name 'name' and widget flags set to 'f'
*
* The dialog will by default be modeless, unless you set 'modal' to
* true to construct a modal dialog.
Expand All @@ -90,7 +90,7 @@ DlgMacroExecuteImp::DlgMacroExecuteImp( QWidget* parent, Qt::WindowFlags fl )
fillUpList();
}

/**
/**
* Destroys the object and frees any allocated resources
*/
DlgMacroExecuteImp::~DlgMacroExecuteImp()
Expand Down Expand Up @@ -136,11 +136,15 @@ void DlgMacroExecuteImp::on_userMacroListBox_currentItemChanged(QTreeWidgetItem*
executeButton->setEnabled(true);
deleteButton->setEnabled(true);
createButton->setEnabled(true);
editButton->setEnabled(true);
renameButton->setEnabled(true);
}
else {
executeButton->setEnabled(false);
deleteButton->setEnabled(false);
createButton->setEnabled(true);
editButton->setEnabled(false);
renameButton->setEnabled(false);
}
}

Expand All @@ -152,11 +156,15 @@ void DlgMacroExecuteImp::on_systemMacroListBox_currentItemChanged(QTreeWidgetIte
executeButton->setEnabled(true);
deleteButton->setEnabled(false);
createButton->setEnabled(false);
editButton->setEnabled(true); //look but don't touch
renameButton->setEnabled(false);
}
else {
executeButton->setEnabled(false);
deleteButton->setEnabled(false);
createButton->setEnabled(false);
editButton->setEnabled(false);
renameButton->setEnabled(false);
}
}

Expand All @@ -170,11 +178,15 @@ void DlgMacroExecuteImp::on_tabMacroWidget_currentChanged(int index)
executeButton->setEnabled(true);
deleteButton->setEnabled(true);
createButton->setEnabled(true);
editButton->setEnabled(true);
renameButton->setEnabled(true);
}
else {
executeButton->setEnabled(false);
deleteButton->setEnabled(false);
createButton->setEnabled(true);
editButton->setEnabled(false);
renameButton->setEnabled(false);
}
}
else { //index==1 system-wide
Expand All @@ -184,11 +196,15 @@ void DlgMacroExecuteImp::on_tabMacroWidget_currentChanged(int index)
executeButton->setEnabled(true);
deleteButton->setEnabled(false);
createButton->setEnabled(false);
editButton->setEnabled(true); //but you can't save it
renameButton->setEnabled(false);
}
else {
executeButton->setEnabled(false);
deleteButton->setEnabled(false);
createButton->setEnabled(false);
editButton->setEnabled(false);
renameButton->setEnabled(false);
}
}

Expand Down Expand Up @@ -376,4 +392,54 @@ void DlgMacroExecuteImp::on_deleteButton_clicked()
}
}

/**
* renames the selected macro
*/
void DlgMacroExecuteImp::on_renameButton_clicked()
{
QDir dir;
QTreeWidgetItem* item = 0;

int index = tabMacroWidget->currentIndex();
if (index == 0) { //user-specific
item = userMacroListBox->currentItem();
dir.setPath(this->macroPath);
}

if (!item)
return;

QString oldName = item->text(0);
QFileInfo oldfi(dir, oldName);
QFile oldfile(oldfi.absoluteFilePath());
if (!oldfile.open(QFile::ReadWrite)) {
QMessageBox::warning(this, tr("System reports read-only file"),
tr("Can not rename '%1'.").arg(oldfi.absoluteFilePath()));
return;
}

// query new name
QString fn = QInputDialog::getText(this, tr("Renaming Macro File"),
tr("Enter new name:"), QLineEdit::Normal, oldName, 0);
if (!fn.isEmpty()) {
QString suffix = QFileInfo(fn).suffix().toLower();
if (suffix != QLatin1String("fcmacro") && suffix != QLatin1String("py"))
fn += QLatin1String(".FCMacro");
QFileInfo fi(dir, fn);
// check if new name exists
if (fi.exists()) {
QMessageBox::warning(this, tr("Existing file"),
tr("'%1'\n already exists.").arg(fi.absoluteFilePath()));
} else {
QFile file(fi.absoluteFilePath());
if (!oldfile.rename(fi.absoluteFilePath())) {
QMessageBox::warning(this, tr("Rename Failed"),
tr("Failed to rename to '%1'.\nPerhaps a file permission error?").arg(fi.absoluteFilePath()));
return;
}
}
fillUpList();
}
}

#include "moc_DlgMacroExecuteImp.cpp"
1 change: 1 addition & 0 deletions src/Gui/DlgMacroExecuteImp.h
Expand Up @@ -50,6 +50,7 @@ public Q_SLOTS:
void on_createButton_clicked();
void on_deleteButton_clicked();
void on_editButton_clicked();
void on_renameButton_clicked();

protected Q_SLOTS:
void on_userMacroListBox_currentItemChanged(QTreeWidgetItem*);
Expand Down