From e0ee8bb8ca0f2c1eb9f3e5c1b47e2314a94a434a Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 12 Jan 2016 01:26:34 +0100 Subject: [PATCH] + allow to open system macros in read-only mode --- src/Gui/DlgMacroExecute.ui | 3 -- src/Gui/DlgMacroExecuteImp.cpp | 50 ++++++++++++++++++++-------------- src/Gui/PythonEditor.cpp | 8 ++++-- 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/src/Gui/DlgMacroExecute.ui b/src/Gui/DlgMacroExecute.ui index b343a3f9e..1b6e526ad 100644 --- a/src/Gui/DlgMacroExecute.ui +++ b/src/Gui/DlgMacroExecute.ui @@ -246,9 +246,6 @@ - - false - Edit diff --git a/src/Gui/DlgMacroExecuteImp.cpp b/src/Gui/DlgMacroExecuteImp.cpp index cceba258a..79d3e0ffd 100644 --- a/src/Gui/DlgMacroExecuteImp.cpp +++ b/src/Gui/DlgMacroExecuteImp.cpp @@ -108,7 +108,7 @@ void DlgMacroExecuteImp::fillUpList(void) // fill up with the directory userMacroListBox->clear(); - for (int i=0; isetText(0, dir[i]); } @@ -118,7 +118,7 @@ void DlgMacroExecuteImp::fillUpList(void) systemMacroListBox->clear(); if (dir.exists()) { - for (int i=0; isetText(0, dir[i]); } @@ -134,13 +134,11 @@ void DlgMacroExecuteImp::on_userMacroListBox_currentItemChanged(QTreeWidgetItem* LineEditMacroName->setText(item->text(0)); executeButton->setEnabled(true); - editButton->setEnabled(true); deleteButton->setEnabled(true); createButton->setEnabled(true); } else { executeButton->setEnabled(false); - editButton->setEnabled(false); deleteButton->setEnabled(false); createButton->setEnabled(true); } @@ -152,13 +150,11 @@ void DlgMacroExecuteImp::on_systemMacroListBox_currentItemChanged(QTreeWidgetIte LineEditMacroName->setText(item->text(0)); executeButton->setEnabled(true); - editButton->setEnabled(false); deleteButton->setEnabled(false); createButton->setEnabled(false); } else { executeButton->setEnabled(false); - editButton->setEnabled(false); deleteButton->setEnabled(false); createButton->setEnabled(false); } @@ -172,13 +168,11 @@ void DlgMacroExecuteImp::on_tabMacroWidget_currentChanged(int index) item = userMacroListBox->currentItem(); if (item) { executeButton->setEnabled(true); - editButton->setEnabled(true); deleteButton->setEnabled(true); createButton->setEnabled(true); } else { executeButton->setEnabled(false); - editButton->setEnabled(false); deleteButton->setEnabled(false); createButton->setEnabled(true); } @@ -188,13 +182,11 @@ void DlgMacroExecuteImp::on_tabMacroWidget_currentChanged(int index) if (item) { executeButton->setEnabled(true); - editButton->setEnabled(false); deleteButton->setEnabled(false); createButton->setEnabled(false); } else { executeButton->setEnabled(false); - editButton->setEnabled(false); deleteButton->setEnabled(false); createButton->setEnabled(false); } @@ -204,7 +196,7 @@ void DlgMacroExecuteImp::on_tabMacroWidget_currentChanged(int index) LineEditMacroName->setText(item->text(0)); } else { - LineEditMacroName->setText(QString::fromLatin1("")); + LineEditMacroName->clear(); } } @@ -270,27 +262,45 @@ void DlgMacroExecuteImp::on_fileChooser_fileNameChanged(const QString& fn) } } -/** +/** * Opens the macro file in an editor. */ void DlgMacroExecuteImp::on_editButton_clicked() { - QTreeWidgetItem* item = userMacroListBox->currentItem(); + QDir dir; + QTreeWidgetItem* item = 0; + + int index = tabMacroWidget->currentIndex(); + if (index == 0) { //user-specific + item = userMacroListBox->currentItem(); + dir.setPath(this->macroPath); + } + else { + //index == 1 system-wide + item = systemMacroListBox->currentItem(); + dir.setPath(QString::fromUtf8(App::GetApplication().getHomePath()) + QString::fromUtf8("Macro")); + } + if (!item) return; MacroItem * mitem = static_cast(item); + QString file = QString::fromLatin1("%1/%2").arg(dir.absolutePath()).arg(item->text(0)); + PythonEditor* editor = new PythonEditor(); + editor->setWindowIcon(Gui::BitmapFactory().iconFromTheme("applications-python")); + PythonEditorView* edit = new PythonEditorView(editor, getMainWindow()); + edit->open(file); + edit->resize(400, 300); + getMainWindow()->addWindow(edit); + if (mitem->systemWide) { - QMessageBox::critical(qApp->activeWindow(), QObject::tr("Delete macro"), - QObject::tr("Not allowed to edit system-wide macros")); - return; + editor->setReadOnly(true); + QString shownName; + shownName = QString::fromLatin1("%1[*] - [%2]").arg(item->text(0)).arg(tr("Read-only")); + edit->setWindowTitle(shownName); } - QDir dir(this->macroPath); - QString file = QString::fromLatin1("%1/%2").arg(dir.absolutePath()).arg(item->text(0)); - - Application::Instance->open(file.toUtf8(), "FreeCADGui"); close(); } diff --git a/src/Gui/PythonEditor.cpp b/src/Gui/PythonEditor.cpp index 008f654fb..22f2e4c5d 100644 --- a/src/Gui/PythonEditor.cpp +++ b/src/Gui/PythonEditor.cpp @@ -155,9 +155,11 @@ void PythonEditor::drawMarker(int line, int x, int y, QPainter* p) void PythonEditor::contextMenuEvent ( QContextMenuEvent * e ) { QMenu* menu = createStandardContextMenu(); - menu->addSeparator(); - menu->addAction( tr("Comment"), this, SLOT( onComment() ), Qt::ALT + Qt::Key_C ); - menu->addAction( tr("Uncomment"), this, SLOT( onUncomment() ), Qt::ALT + Qt::Key_U ); + if (!isReadOnly()) { + menu->addSeparator(); + menu->addAction( tr("Comment"), this, SLOT( onComment() ), Qt::ALT + Qt::Key_C ); + menu->addAction( tr("Uncomment"), this, SLOT( onUncomment() ), Qt::ALT + Qt::Key_U ); + } menu->exec(e->globalPos()); delete menu;