82
83
void DlgMacroExecuteImp::fillUpList(void)
84
85
// lists all files in macro path
85
QDir dir(this->macroPath, QLatin1String("*.FCMacro"));
86
QDir dir(this->macroPath, QLatin1String("*.FCMacro *.py"));
87
88
// fill up with the directory
88
89
macroListBox->clear();
116
117
QFileInfo fi(dir, item->text(0));
117
118
Application::Instance->macroManager()->run(Gui::MacroManager::File, fi.filePath().toUtf8());
118
119
// after macro run recalculate the document
119
if ( Application::Instance->activeDocument() )
120
if (Application::Instance->activeDocument())
120
121
Application::Instance->activeDocument()->getDocument()->recompute();
158
159
QLineEdit::Normal, QString::null, 0);
159
160
if (!fn.isEmpty())
161
if (!fn.endsWith(QLatin1String(".FCMacro")))
162
QString suffix = QFileInfo(fn).suffix().toLower();
163
if (suffix != QLatin1String("fcmacro") && suffix != QLatin1String("py"))
162
164
fn += QLatin1String(".FCMacro");
163
165
QDir dir(this->macroPath);
164
QFileInfo fi( dir, fn );
165
if ( fi.exists() && fi.isFile() )
166
QFileInfo fi(dir, fn);
167
if (fi.exists() && fi.isFile())
167
QMessageBox::warning( this, tr("Existing file"),
169
QMessageBox::warning(this, tr("Existing file"),
168
170
tr("'%1'.\nThis file already exists.").arg(fi.fileName()));
172
QString file = QString::fromAscii("%1/%2").arg(dir.absolutePath()).arg( fn );
174
QFile file(fi.absoluteFilePath());
175
if (!file.open(QFile::WriteOnly)) {
176
QMessageBox::warning(this, tr("Cannot create file"),
177
tr("Creation of file '%1' failed.").arg(fi.absoluteFilePath()));
173
181
PythonEditor* editor = new PythonEditor();
174
182
editor->setWindowIcon(Gui::BitmapFactory().pixmap("python_small"));
175
183
EditorView* edit = new EditorView(editor, getMainWindow());
177
edit->setWindowTitle( fn );
178
edit->resize( 400, 300 );
179
getMainWindow()->addWindow( edit );
184
edit->open(fi.absoluteFilePath());
185
edit->setWindowTitle(fn);
186
edit->resize(400, 300);
187
getMainWindow()->addWindow(edit);
189
197
if (!item) return;
191
199
QString fn = item->text(0);
192
int ret = QMessageBox::question(this, tr("Delete macro"), tr("Do you really want to delete the macro '%1'?").arg( fn ),
193
QMessageBox::Yes, QMessageBox::No|QMessageBox::Default|QMessageBox::Escape );
194
if ( ret == QMessageBox::Yes )
200
int ret = QMessageBox::question(this, tr("Delete macro"),
201
tr("Do you really want to delete the macro '%1'?").arg( fn ),
202
QMessageBox::Yes, QMessageBox::No|QMessageBox::Default|QMessageBox::Escape);
203
if (ret == QMessageBox::Yes)
196
205
QDir dir(this->macroPath);
198
207
int index = macroListBox->indexOfTopLevelItem(item);
199
208
macroListBox->takeTopLevelItem(index);