~ubuntu-branches/ubuntu/maverick/freecad/maverick

« back to all changes in this revision

Viewing changes to src/Gui/DlgMacroExecuteImp.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam C. Powell, IV
  • Date: 2010-01-11 08:48:33 UTC
  • mfrom: (3.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20100111084833-4g9vgdqbkw8u34zb
Tags: 0.9.2646.5-1
* New upstream version (closes: #561696).
* Added swig to Build-Depends (closes: #563523, #563772).
* Removed python-opencv from Build-Depends and Recommends (closes: #560768).

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
 
24
24
#include "PreCompiled.h"
25
 
 
26
 
#ifndef __Qt4All__
27
 
# include "Qt4All.h"
 
25
#ifndef _PreComp_
 
26
# include <QInputDialog>
 
27
# include <QHeaderView>
 
28
# include <QMessageBox>
28
29
#endif
29
30
 
30
31
#include "DlgMacroExecuteImp.h"
82
83
void DlgMacroExecuteImp::fillUpList(void)
83
84
{
84
85
    // lists all files in macro path
85
 
    QDir dir(this->macroPath, QLatin1String("*.FCMacro"));
 
86
    QDir dir(this->macroPath, QLatin1String("*.FCMacro *.py"));
86
87
  
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();
121
122
}
122
123
 
158
159
        QLineEdit::Normal, QString::null, 0);
159
160
    if (!fn.isEmpty())
160
161
    {
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())
166
168
        {
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()));
169
171
        }
170
172
        else
171
173
        {
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()));
 
178
                return;
 
179
            }
 
180
            file.close();
173
181
            PythonEditor* editor = new PythonEditor();
174
182
            editor->setWindowIcon(Gui::BitmapFactory().pixmap("python_small"));
175
183
            EditorView* edit = new EditorView(editor, getMainWindow());
176
 
            edit->open(file);
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);
180
188
            close();
181
189
        }
182
190
    }
189
197
    if (!item) return;
190
198
 
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)
195
204
    {
196
205
        QDir dir(this->macroPath);
197
 
        dir.remove( fn );
 
206
        dir.remove(fn);
198
207
        int index = macroListBox->indexOfTopLevelItem(item);
199
208
        macroListBox->takeTopLevelItem(index);
200
209
        delete item;