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

« back to all changes in this revision

Viewing changes to src/Gui/CommandDoc.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Teemu Ikonen
  • Date: 2009-07-16 18:37:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090716183741-oww9kcxqrk991i1n
Tags: upstream-0.8.2237
ImportĀ upstreamĀ versionĀ 0.8.2237

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (c) 2002 Jļæ½rgen Riegel <juergen.riegel@web.de>              *
 
3
 *                                                                         *
 
4
 *   This file is part of the FreeCAD CAx development system.              *
 
5
 *                                                                         *
 
6
 *   This library is free software; you can redistribute it and/or         *
 
7
 *   modify it under the terms of the GNU Library General Public           *
 
8
 *   License as published by the Free Software Foundation; either          *
 
9
 *   version 2 of the License, or (at your option) any later version.      *
 
10
 *                                                                         *
 
11
 *   This library  is distributed in the hope that it will be useful,      *
 
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
14
 *   GNU Library General Public License for more details.                  *
 
15
 *                                                                         *
 
16
 *   You should have received a copy of the GNU Library General Public     *
 
17
 *   License along with this library; see the file COPYING.LIB. If not,    *
 
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
 
19
 *   Suite 330, Boston, MA  02111-1307, USA                                *
 
20
 *                                                                         *
 
21
 ***************************************************************************/
 
22
 
 
23
 
 
24
#include "PreCompiled.h"
 
25
#include <algorithm>
 
26
 
 
27
#include <Base/Exception.h>
 
28
#include <Base/Interpreter.h>
 
29
#include <Base/Sequencer.h>
 
30
#include <App/Document.h>
 
31
#include <App/DocumentObjectGroup.h>
 
32
#include <App/Feature.h>
 
33
 
 
34
#include "Action.h"
 
35
#include "Application.h"
 
36
#include "Document.h"
 
37
#include "Command.h"
 
38
#include "FileDialog.h"
 
39
#include "MainWindow.h"
 
40
#include "BitmapFactory.h"
 
41
#include "Selection.h"
 
42
#include "DlgProjectInformationImp.h"
 
43
 
 
44
using Base::Sequencer;
 
45
using namespace Gui;
 
46
 
 
47
 
 
48
//===========================================================================
 
49
// Std_Open
 
50
//===========================================================================
 
51
 
 
52
DEF_STD_CMD(StdCmdOpen);
 
53
 
 
54
StdCmdOpen::StdCmdOpen()
 
55
  : Command("Std_Open")
 
56
{
 
57
    // seting the
 
58
    sGroup        = QT_TR_NOOP("File");
 
59
    sMenuText     = QT_TR_NOOP("&Open...");
 
60
    sToolTipText  = QT_TR_NOOP("Open a document or import files");
 
61
    sWhatsThis    = "Std_Open";
 
62
    sStatusTip    = QT_TR_NOOP("Open a document or import files");
 
63
    sPixmap       = "document-open";
 
64
    iAccel        = Qt::CTRL+Qt::Key_O;
 
65
}
 
66
 
 
67
void StdCmdOpen::activated(int iMsg)
 
68
{
 
69
    // fill the list of registered endings
 
70
    QString formatList;
 
71
    const char* supported = QT_TR_NOOP("Supported formats");
 
72
    const char* allFiles = QT_TR_NOOP("All files (*.*)");
 
73
    formatList = QObject::tr(supported);
 
74
    formatList += QLatin1String(" (");
 
75
 
 
76
    std::vector<std::string> filetypes = App::GetApplication().getImportTypes();
 
77
    std::vector<std::string>::iterator it;
 
78
    // Make sure FCStd is the very first fileformat
 
79
    it = std::find(filetypes.begin(), filetypes.end(), "FCStd");
 
80
    if (it != filetypes.end()) {
 
81
        filetypes.erase(it);
 
82
        filetypes.insert(filetypes.begin(), "FCStd");
 
83
    }
 
84
    for (it=filetypes.begin();it != filetypes.end();++it) {
 
85
        formatList += QLatin1String(" *.");
 
86
        formatList += QLatin1String(it->c_str());
 
87
    }
 
88
 
 
89
    formatList += QLatin1String(");;");
 
90
 
 
91
    std::map<std::string, std::string> FilterList = App::GetApplication().getImportFilters();
 
92
    std::map<std::string, std::string>::iterator jt;
 
93
    // Make sure the format name for FCStd is the very first in the list
 
94
    for (jt=FilterList.begin();jt != FilterList.end();++jt) {
 
95
        if (jt->first.find("*.FCStd") != std::string::npos) {
 
96
            formatList += QLatin1String(jt->first.c_str());
 
97
            formatList += QLatin1String(";;");
 
98
            FilterList.erase(jt);
 
99
            break;
 
100
        }
 
101
    }
 
102
    for (jt=FilterList.begin();jt != FilterList.end();++jt) {
 
103
        formatList += QLatin1String(jt->first.c_str());
 
104
        formatList += QLatin1String(";;");
 
105
    }
 
106
    formatList += QObject::tr(allFiles);
 
107
 
 
108
    QString selectedFilter;
 
109
    QStringList fileList = FileDialog::getOpenFileNames(getMainWindow(),
 
110
        QObject::tr("Open document"), QString(), formatList, &selectedFilter);
 
111
    // load the files with the associated modules
 
112
    SelectModule::Dict dict = SelectModule::importHandler(fileList, selectedFilter);
 
113
    for (SelectModule::Dict::iterator it = dict.begin(); it != dict.end(); ++it) {
 
114
        getGuiApplication()->open(it.key().toUtf8(), it.value().toAscii());
 
115
    }
 
116
}
 
117
 
 
118
//===========================================================================
 
119
// Std_Import
 
120
//===========================================================================
 
121
 
 
122
DEF_STD_CMD_A(StdCmdImport);
 
123
 
 
124
StdCmdImport::StdCmdImport()
 
125
  : Command("Std_Import")
 
126
{
 
127
    // seting the
 
128
    sGroup        = QT_TR_NOOP("File");
 
129
    sMenuText     = QT_TR_NOOP("&Import...");
 
130
    sToolTipText  = QT_TR_NOOP("Import a file in the active document");
 
131
    sWhatsThis    = "Std_Import";
 
132
    sStatusTip    = QT_TR_NOOP("Import a file in the active document");
 
133
    //sPixmap       = "Open";
 
134
    iAccel        = Qt::CTRL+Qt::Key_I;
 
135
}
 
136
 
 
137
void StdCmdImport::activated(int iMsg)
 
138
{
 
139
    // fill the list of registered endings
 
140
    QString formatList;
 
141
    const char* supported = QT_TR_NOOP("Supported formats");
 
142
    const char* allFiles = QT_TR_NOOP("All files (*.*)");
 
143
    formatList = QObject::tr(supported);
 
144
    formatList += QLatin1String(" (");
 
145
 
 
146
    std::vector<std::string> filetypes = App::GetApplication().getImportTypes();
 
147
    std::vector<std::string>::const_iterator it;
 
148
    for (it=filetypes.begin();it != filetypes.end();++it) {
 
149
        if (*it != "FCStd") {
 
150
            // ignore the project file format
 
151
            formatList += QLatin1String(" *.");
 
152
            formatList += QLatin1String(it->c_str());
 
153
        }
 
154
    }
 
155
 
 
156
    formatList += QLatin1String(");;");
 
157
 
 
158
    std::map<std::string, std::string> FilterList = App::GetApplication().getImportFilters();
 
159
    std::map<std::string, std::string>::const_iterator jt;
 
160
    for (jt=FilterList.begin();jt != FilterList.end();++jt) {
 
161
        // ignore the project file format
 
162
        if (jt->first.find("(*.FCStd)") == std::string::npos) {
 
163
            formatList += QLatin1String(jt->first.c_str());
 
164
            formatList += QLatin1String(";;");
 
165
        }
 
166
    }
 
167
    formatList += QObject::tr(allFiles);
 
168
 
 
169
    QString selectedFilter;
 
170
    QStringList fileList = FileDialog::getOpenFileNames(getMainWindow(),
 
171
        QObject::tr("Import file"), QString(), formatList, &selectedFilter);
 
172
    SelectModule::Dict dict = SelectModule::importHandler(fileList, selectedFilter);
 
173
    // load the files with the associated modules
 
174
    for (SelectModule::Dict::iterator it = dict.begin(); it != dict.end(); ++it) {
 
175
        getGuiApplication()->importFrom(it.key().toUtf8(),
 
176
            getActiveGuiDocument()->getDocument()->getName(),
 
177
            it.value().toAscii());
 
178
    }
 
179
}
 
180
 
 
181
bool StdCmdImport::isActive(void)
 
182
{
 
183
  return ( getActiveGuiDocument() ? true : false );
 
184
}
 
185
 
 
186
 
 
187
//===========================================================================
 
188
// Std_Export
 
189
//===========================================================================
 
190
 
 
191
DEF_STD_CMD_A(StdCmdExport);
 
192
 
 
193
StdCmdExport::StdCmdExport()
 
194
  : Command("Std_Export")
 
195
{
 
196
    // seting the
 
197
    sGroup        = QT_TR_NOOP("File");
 
198
    sMenuText     = QT_TR_NOOP("&Export...");
 
199
    sToolTipText  = QT_TR_NOOP("Export an object in the active document");
 
200
    sWhatsThis    = "Std_Export";
 
201
    sStatusTip    = QT_TR_NOOP("Export an object in the active document");
 
202
    //sPixmap       = "Open";
 
203
    iAccel        = Qt::CTRL+Qt::Key_E;
 
204
}
 
205
 
 
206
void StdCmdExport::activated(int iMsg)
 
207
{
 
208
    // fill the list of registered endings
 
209
    QString formatList;
 
210
    const char* supported = QT_TR_NOOP("Supported formats");
 
211
    formatList = QObject::tr(supported);
 
212
    formatList += QLatin1String(" (");
 
213
 
 
214
    std::vector<std::string> filetypes = App::GetApplication().getExportTypes();
 
215
    std::vector<std::string>::const_iterator it;
 
216
    for (it=filetypes.begin();it != filetypes.end();++it) {
 
217
        if (*it != "FCStd") {
 
218
            // ignore the project file format
 
219
            formatList += QLatin1String(" *.");
 
220
            formatList += QLatin1String(it->c_str());
 
221
        }
 
222
    }
 
223
 
 
224
    formatList += QLatin1String(");;");
 
225
 
 
226
    std::map<std::string, std::string> FilterList = App::GetApplication().getExportFilters();
 
227
    std::map<std::string, std::string>::const_iterator jt;
 
228
    for (jt=FilterList.begin();jt != FilterList.end();++jt) {
 
229
        // ignore the project file format
 
230
        if (jt->first.find("(*.FCStd)") == std::string::npos) {
 
231
            formatList += QLatin1String(jt->first.c_str());
 
232
            formatList += QLatin1String(";;");
 
233
        }
 
234
    }
 
235
 
 
236
    QString selectedFilter;
 
237
    QString fileName = FileDialog::getSaveFileName(getMainWindow(),
 
238
        QObject::tr("Export file"), QString(), formatList, &selectedFilter);
 
239
    if (!fileName.isEmpty()) {
 
240
        SelectModule::Dict dict = SelectModule::exportHandler(fileName, selectedFilter);
 
241
        // export the files with the associated modules
 
242
        for (SelectModule::Dict::iterator it = dict.begin(); it != dict.end(); ++it) {
 
243
            getGuiApplication()->exportTo(it.key().toUtf8(),
 
244
                getActiveGuiDocument()->getDocument()->getName(),
 
245
                it.value().toAscii());
 
246
        }
 
247
    }
 
248
}
 
249
 
 
250
bool StdCmdExport::isActive(void)
 
251
{
 
252
    return (getActiveGuiDocument() ? true : false);
 
253
}
 
254
 
 
255
//===========================================================================
 
256
// Std_New
 
257
//===========================================================================
 
258
 
 
259
DEF_STD_CMD(StdCmdNew);
 
260
 
 
261
StdCmdNew::StdCmdNew()
 
262
  :Command("Std_New")
 
263
{
 
264
  sGroup        = QT_TR_NOOP("File");
 
265
  sMenuText     = QT_TR_NOOP("&New");
 
266
  sToolTipText  = QT_TR_NOOP("Create a new empty Document");
 
267
  sWhatsThis    = "Std_New";
 
268
  sStatusTip    = QT_TR_NOOP("Create a new empty Document");
 
269
  sPixmap       = "document-new";
 
270
  iAccel        = Qt::CTRL+Qt::Key_N;
 
271
}
 
272
 
 
273
void StdCmdNew::activated(int iMsg)
 
274
{
 
275
  doCommand(Command::Doc,"App.newDocument()");
 
276
}
 
277
 
 
278
//===========================================================================
 
279
// Std_Save
 
280
//===========================================================================
 
281
DEF_STD_CMD_A(StdCmdSave);
 
282
 
 
283
StdCmdSave::StdCmdSave()
 
284
  :Command("Std_Save")
 
285
{
 
286
  sGroup        = QT_TR_NOOP("File");
 
287
  sMenuText     = QT_TR_NOOP("&Save");
 
288
  sToolTipText  = QT_TR_NOOP("Save the active document");
 
289
  sWhatsThis    = "Std_Save";
 
290
  sStatusTip    = QT_TR_NOOP("Save the active document");
 
291
  sPixmap       = "document-save";
 
292
  iAccel        = Qt::CTRL+Qt::Key_S;
 
293
}
 
294
 
 
295
void StdCmdSave::activated(int iMsg)
 
296
{
 
297
#if 0
 
298
  Gui::Document* pActiveDoc = getActiveGuiDocument();
 
299
  if ( pActiveDoc )
 
300
    pActiveDoc->save();
 
301
  else
 
302
#endif
 
303
    doCommand(Command::Gui,"Gui.SendMsgToActiveView(\"Save\")");
 
304
}
 
305
 
 
306
bool StdCmdSave::isActive(void)
 
307
{
 
308
#if 0
 
309
  if( getActiveGuiDocument() )
 
310
    return true;
 
311
  else
 
312
#endif
 
313
    return getGuiApplication()->sendHasMsgToActiveView("Save");
 
314
}
 
315
 
 
316
//===========================================================================
 
317
// Std_SaveAs
 
318
//===========================================================================
 
319
DEF_STD_CMD_A(StdCmdSaveAs);
 
320
 
 
321
StdCmdSaveAs::StdCmdSaveAs()
 
322
  :Command("Std_SaveAs")
 
323
{
 
324
  sGroup        = QT_TR_NOOP("File");
 
325
  sMenuText     = QT_TR_NOOP("Save &As...");
 
326
  sToolTipText  = QT_TR_NOOP("Save the active document under a new file name");
 
327
  sWhatsThis    = "Std_SaveAs";
 
328
  sStatusTip    = QT_TR_NOOP("Save the active document under a new file name");
 
329
#if QT_VERSION >= 0x040200
 
330
  sPixmap       = "document-save-as";
 
331
#endif
 
332
  iAccel        = 0;
 
333
}
 
334
 
 
335
void StdCmdSaveAs::activated(int iMsg)
 
336
{
 
337
#if 0
 
338
  Gui::Document* pActiveDoc = getActiveGuiDocument();
 
339
  if ( pActiveDoc )
 
340
    pActiveDoc->saveAs();
 
341
  else
 
342
#endif
 
343
    doCommand(Command::Gui,"Gui.SendMsgToActiveView(\"SaveAs\")");
 
344
}
 
345
 
 
346
bool StdCmdSaveAs::isActive(void)
 
347
{
 
348
#if 0
 
349
  if( getActiveGuiDocument() )
 
350
    return true;
 
351
  else
 
352
#endif
 
353
    return getGuiApplication()->sendHasMsgToActiveView("SaveAs");
 
354
}
 
355
 
 
356
//===========================================================================
 
357
// Std_ProjectInfo
 
358
//===========================================================================
 
359
 
 
360
DEF_STD_CMD_A(StdCmdProjectInfo);
 
361
 
 
362
StdCmdProjectInfo::StdCmdProjectInfo()
 
363
  :Command("Std_ProjectInfo")
 
364
{
 
365
  // seting the 
 
366
  sGroup        = QT_TR_NOOP("File");
 
367
  sMenuText     = QT_TR_NOOP("Project i&nformation...");
 
368
  sToolTipText  = QT_TR_NOOP("Show details of the currently active project");
 
369
  sWhatsThis    = "Std_ProjectInfo";
 
370
  sStatusTip    = QT_TR_NOOP("Show details of the currently active project");
 
371
#if QT_VERSION >= 0x040200
 
372
  sPixmap       = "document-properties";
 
373
#endif
 
374
}
 
375
 
 
376
void StdCmdProjectInfo::activated(int iMsg)
 
377
{
 
378
  Gui::Dialog::DlgProjectInformationImp dlg(getActiveGuiDocument()->getDocument(), getMainWindow());
 
379
  dlg.exec();
 
380
}
 
381
 
 
382
bool StdCmdProjectInfo::isActive(void)
 
383
{
 
384
  return ( getActiveGuiDocument() ? true : false );
 
385
}
 
386
 
 
387
//===========================================================================
 
388
// Std_Print
 
389
//===========================================================================
 
390
DEF_STD_CMD_A(StdCmdPrint );
 
391
 
 
392
StdCmdPrint::StdCmdPrint()
 
393
  :Command("Std_Print")
 
394
{
 
395
  sGroup        = QT_TR_NOOP("File");
 
396
  sMenuText     = QT_TR_NOOP("&Print...");
 
397
  sToolTipText  = QT_TR_NOOP("Print the document");
 
398
  sWhatsThis    = "Std_Print";
 
399
  sStatusTip    = QT_TR_NOOP("Print the document");
 
400
  sPixmap       = "document-print";
 
401
  iAccel        = Qt::CTRL+Qt::Key_P;;
 
402
}
 
403
 
 
404
void StdCmdPrint::activated(int iMsg)
 
405
{
 
406
  if ( getMainWindow()->activeWindow() )
 
407
  {
 
408
      getMainWindow()->statusBar()->showMessage(QObject::tr("Printing..."));
 
409
    getMainWindow()->activeWindow()->print();
 
410
  }
 
411
}
 
412
 
 
413
bool StdCmdPrint::isActive(void)
 
414
{
 
415
  return getGuiApplication()->sendHasMsgToActiveView("Print");
 
416
}
 
417
 
 
418
//===========================================================================
 
419
// Std_PrintPdf
 
420
//===========================================================================
 
421
DEF_STD_CMD_A(StdCmdPrintPdf);
 
422
 
 
423
StdCmdPrintPdf::StdCmdPrintPdf()
 
424
  :Command("Std_PrintPdf")
 
425
{
 
426
  sGroup        = QT_TR_NOOP("File");
 
427
  sMenuText     = QT_TR_NOOP("&Export PDF...");
 
428
  sToolTipText  = QT_TR_NOOP("Export the document as PDF");
 
429
  sWhatsThis    = "Std_PrintPdf";
 
430
  sStatusTip    = QT_TR_NOOP("Export the document as PDF");
 
431
}
 
432
 
 
433
void StdCmdPrintPdf::activated(int iMsg)
 
434
{
 
435
  if ( getMainWindow()->activeWindow() )
 
436
  {
 
437
    getMainWindow()->statusBar()->showMessage(QLatin1String("Exporting PDF..."));
 
438
    getMainWindow()->activeWindow()->printPdf();
 
439
  }
 
440
}
 
441
 
 
442
bool StdCmdPrintPdf::isActive(void)
 
443
{
 
444
  return getGuiApplication()->sendHasMsgToActiveView("PrintPdf");
 
445
}
 
446
 
 
447
//===========================================================================
 
448
// Std_Quit
 
449
//===========================================================================
 
450
 
 
451
DEF_STD_CMD(StdCmdQuit );
 
452
 
 
453
StdCmdQuit::StdCmdQuit()
 
454
  :Command("Std_Quit")
 
455
{
 
456
  sGroup        = QT_TR_NOOP("File");
 
457
  sMenuText     = QT_TR_NOOP("E&xit");
 
458
  sToolTipText  = QT_TR_NOOP("Quits the application");
 
459
  sWhatsThis    = "Std_Quit";
 
460
  sStatusTip    = QT_TR_NOOP("Quits the application");
 
461
#if QT_VERSION >= 0x040200
 
462
  sPixmap       = "system-log-out";
 
463
#endif
 
464
  iAccel        = Qt::ALT+Qt::Key_F4;
 
465
}
 
466
 
 
467
void StdCmdQuit::activated(int iMsg)
 
468
{
 
469
  // close the main window and exit the event loop
 
470
  if (getMainWindow()->close())
 
471
    qApp->quit();
 
472
}
 
473
 
 
474
//===========================================================================
 
475
// Std_Undo
 
476
//===========================================================================
 
477
 
 
478
DEF_STD_CMD_AC(StdCmdUndo);
 
479
 
 
480
StdCmdUndo::StdCmdUndo()
 
481
  :Command("Std_Undo")
 
482
{
 
483
  sGroup        = QT_TR_NOOP("Edit");
 
484
  sMenuText     = QT_TR_NOOP("&Undo");
 
485
  sToolTipText  = QT_TR_NOOP("Undo exactly one action");
 
486
  sWhatsThis    = "Std_Undo";
 
487
  sStatusTip    = QT_TR_NOOP("Undo exactly one action");
 
488
  sPixmap       = "edit-undo";
 
489
  iAccel        = Qt::CTRL+Qt::Key_Z;
 
490
}
 
491
 
 
492
void StdCmdUndo::activated(int iMsg)
 
493
{
 
494
//  Application::Instance->slotUndo();
 
495
  getGuiApplication()->sendMsgToActiveView("Undo");
 
496
}
 
497
 
 
498
bool StdCmdUndo::isActive(void)
 
499
{
 
500
  return getGuiApplication()->sendHasMsgToActiveView("Undo");
 
501
}
 
502
 
 
503
Action * StdCmdUndo::createAction(void)
 
504
{
 
505
  Action *pcAction;
 
506
 
 
507
  pcAction = new UndoAction(this,getMainWindow());
 
508
  pcAction->setText(QObject::tr(sMenuText));
 
509
  pcAction->setToolTip(QObject::tr(sToolTipText));
 
510
  pcAction->setStatusTip(QObject::tr(sStatusTip));
 
511
  pcAction->setWhatsThis(QObject::tr(sWhatsThis));
 
512
  if(sPixmap)
 
513
    pcAction->setIcon(Gui::BitmapFactory().pixmap(sPixmap));
 
514
  pcAction->setShortcut(iAccel);
 
515
 
 
516
  return pcAction;
 
517
}
 
518
 
 
519
//===========================================================================
 
520
// Std_Redo
 
521
//===========================================================================
 
522
 
 
523
DEF_STD_CMD_AC(StdCmdRedo );
 
524
 
 
525
StdCmdRedo::StdCmdRedo()
 
526
  :Command("Std_Redo")
 
527
{
 
528
  sGroup        = QT_TR_NOOP("Edit");
 
529
  sMenuText     = QT_TR_NOOP("&Redo");
 
530
  sToolTipText  = QT_TR_NOOP("Redoes a previously undone action");
 
531
  sWhatsThis    = "Std_Redo";
 
532
  sStatusTip    = QT_TR_NOOP("Redoes a previously undone action");
 
533
  sPixmap       = "edit-redo";
 
534
  iAccel        = Qt::CTRL+Qt::Key_Y;
 
535
}
 
536
 
 
537
void StdCmdRedo::activated(int iMsg)
 
538
{
 
539
//  Application::Instance->slotRedo();
 
540
  getGuiApplication()->sendMsgToActiveView("Redo");
 
541
}
 
542
 
 
543
bool StdCmdRedo::isActive(void)
 
544
{
 
545
  return getGuiApplication()->sendHasMsgToActiveView("Redo");
 
546
}
 
547
 
 
548
Action * StdCmdRedo::createAction(void)
 
549
{
 
550
  Action *pcAction;
 
551
 
 
552
  pcAction = new RedoAction(this,getMainWindow());
 
553
  pcAction->setText(QObject::tr(sMenuText));
 
554
  pcAction->setToolTip(QObject::tr(sToolTipText));
 
555
  pcAction->setStatusTip(QObject::tr(sStatusTip));
 
556
  pcAction->setWhatsThis(QObject::tr(sWhatsThis));
 
557
  if(sPixmap)
 
558
    pcAction->setIcon(Gui::BitmapFactory().pixmap(sPixmap));
 
559
  pcAction->setShortcut(iAccel);
 
560
 
 
561
  return pcAction;
 
562
}
 
563
 
 
564
//===========================================================================
 
565
// Std_Cut
 
566
//===========================================================================
 
567
DEF_STD_CMD_A(StdCmdCut);
 
568
 
 
569
StdCmdCut::StdCmdCut()
 
570
  :Command("Std_Cut")
 
571
{
 
572
  sGroup        = QT_TR_NOOP("Edit");
 
573
  sMenuText     = QT_TR_NOOP("&Cut");
 
574
  sToolTipText  = QT_TR_NOOP("Cut out");
 
575
  sWhatsThis    = "Std_Cut";
 
576
  sStatusTip    = QT_TR_NOOP("Cut out");
 
577
  sPixmap       = "edit-cut";
 
578
  iAccel        = Qt::CTRL+Qt::Key_X;
 
579
}
 
580
 
 
581
void StdCmdCut::activated(int iMsg)
 
582
{
 
583
  getGuiApplication()->sendMsgToActiveView("Cut");
 
584
}
 
585
 
 
586
bool StdCmdCut::isActive(void)
 
587
{
 
588
  return getGuiApplication()->sendHasMsgToActiveView("Cut");
 
589
}
 
590
 
 
591
//===========================================================================
 
592
// Std_Copy
 
593
//===========================================================================
 
594
DEF_STD_CMD_A(StdCmdCopy);
 
595
 
 
596
StdCmdCopy::StdCmdCopy()
 
597
  :Command("Std_Copy")
 
598
{
 
599
  sGroup        = QT_TR_NOOP("Edit");
 
600
  sMenuText     = QT_TR_NOOP("C&opy");
 
601
  sToolTipText  = QT_TR_NOOP("Copy operation");
 
602
  sWhatsThis    = "Std_Copy";
 
603
  sStatusTip    = QT_TR_NOOP("Copy operation");
 
604
  sPixmap       = "edit-copy";
 
605
  iAccel        = Qt::CTRL+Qt::Key_C;
 
606
}
 
607
 
 
608
void StdCmdCopy::activated(int iMsg)
 
609
{
 
610
  getGuiApplication()->sendMsgToActiveView("Copy");
 
611
}
 
612
 
 
613
bool StdCmdCopy::isActive(void)
 
614
{
 
615
  return getGuiApplication()->sendHasMsgToActiveView("Copy");
 
616
}
 
617
 
 
618
//===========================================================================
 
619
// Std_Paste
 
620
//===========================================================================
 
621
DEF_STD_CMD_A(StdCmdPaste);
 
622
 
 
623
StdCmdPaste::StdCmdPaste()
 
624
  :Command("Std_Paste")
 
625
{
 
626
  sGroup        = QT_TR_NOOP("Edit");
 
627
  sMenuText     = QT_TR_NOOP("&Paste");
 
628
  sToolTipText  = QT_TR_NOOP("Paste operation");
 
629
  sWhatsThis    = "Std_Paste";
 
630
  sStatusTip    = QT_TR_NOOP("Paste operation");
 
631
  sPixmap       = "edit-paste";
 
632
  iAccel        = Qt::CTRL+Qt::Key_V;
 
633
}
 
634
 
 
635
void StdCmdPaste::activated(int iMsg)
 
636
{
 
637
  getGuiApplication()->sendMsgToActiveView("Paste");
 
638
}
 
639
 
 
640
bool StdCmdPaste::isActive(void)
 
641
{
 
642
  return getGuiApplication()->sendHasMsgToActiveView("Paste");
 
643
}
 
644
 
 
645
//===========================================================================
 
646
// Std_SelectAll
 
647
//===========================================================================
 
648
 
 
649
DEF_STD_CMD_A(StdCmdSelectAll);
 
650
 
 
651
StdCmdSelectAll::StdCmdSelectAll()
 
652
  : Command("Std_SelectAll")
 
653
{
 
654
    sGroup        = QT_TR_NOOP("Edit");
 
655
    sMenuText     = QT_TR_NOOP("Select &All");
 
656
    sToolTipText  = QT_TR_NOOP("Select all");
 
657
    sWhatsThis    = "Std_SelectAll";
 
658
    sStatusTip    = QT_TR_NOOP("Select all");
 
659
#if QT_VERSION >= 0x040200
 
660
    sPixmap       = "edit-select-all";
 
661
#endif
 
662
    //iAccel        = Qt::CTRL+Qt::Key_A; // superseeds shortcuts for text edits
 
663
}
 
664
 
 
665
void StdCmdSelectAll::activated(int iMsg)
 
666
{
 
667
    SelectionSingleton& rSel = Selection();
 
668
    App::Document* doc = App::GetApplication().getActiveDocument();
 
669
    std::vector<App::DocumentObject*> objs = doc->getObjectsOfType(App::DocumentObject::getClassTypeId());
 
670
    for(std::vector<App::DocumentObject*>::const_iterator it=objs.begin();it!=objs.end();++it) {
 
671
        if (!rSel.isSelected(doc->getName(), (*it)->getNameInDocument()))
 
672
            rSel.addSelection(doc->getName(), (*it)->getNameInDocument());
 
673
    }
 
674
}
 
675
 
 
676
bool StdCmdSelectAll::isActive(void)
 
677
{
 
678
    return App::GetApplication().getActiveDocument() != 0;
 
679
}
 
680
 
 
681
//===========================================================================
 
682
// Std_Delete
 
683
//===========================================================================
 
684
DEF_STD_CMD_A(StdCmdDelete);
 
685
 
 
686
StdCmdDelete::StdCmdDelete()
 
687
  :Command("Std_Delete")
 
688
{
 
689
  sGroup        = QT_TR_NOOP("Edit");
 
690
  sMenuText     = QT_TR_NOOP("&Delete");
 
691
  sToolTipText  = QT_TR_NOOP("Deletes the selected objects");
 
692
  sWhatsThis    = "Std_Delete";
 
693
  sStatusTip    = QT_TR_NOOP("Deletes the selected objects");
 
694
#if QT_VERSION >= 0x040200
 
695
  sPixmap       = "edit-delete";
 
696
#endif
 
697
  iAccel        = Qt::Key_Delete;
 
698
}
 
699
 
 
700
void StdCmdDelete::activated(int iMsg)
 
701
{
 
702
    // go through all documents
 
703
    const SelectionSingleton& rSel = Selection();
 
704
    const std::vector<App::Document*> docs = App::GetApplication().getDocuments();
 
705
    for ( std::vector<App::Document*>::const_iterator it = docs.begin(); it != docs.end(); ++it ) {
 
706
        const std::vector<App::DocumentObject*> sel = rSel.getObjectsOfType(App::DocumentObject::getClassTypeId(), (*it)->getName());
 
707
        if (!sel.empty()) {
 
708
            (*it)->openTransaction("Delete");
 
709
            for(std::vector<App::DocumentObject*>::const_iterator ft=sel.begin();ft!=sel.end();ft++) {
 
710
                if ((*ft)->getTypeId().isDerivedFrom(App::DocumentObjectGroup::getClassTypeId()))
 
711
                doCommand(Doc,"App.getDocument(\"%s\").getObject(\"%s\").removeObjectsFromDocument()"
 
712
                             ,(*it)->getName(), (*ft)->getNameInDocument());
 
713
                doCommand(Doc,"App.getDocument(\"%s\").removeObject(\"%s\")"
 
714
                             ,(*it)->getName(), (*ft)->getNameInDocument());
 
715
            }
 
716
            (*it)->commitTransaction();
 
717
        }
 
718
    }
 
719
}
 
720
 
 
721
bool StdCmdDelete::isActive(void)
 
722
{
 
723
  return Selection().getCompleteSelection().size() > 0;
 
724
}
 
725
 
 
726
//===========================================================================
 
727
// Std_Refresh
 
728
//===========================================================================
 
729
DEF_STD_CMD_A(StdCmdRefresh);
 
730
 
 
731
StdCmdRefresh::StdCmdRefresh()
 
732
  :Command("Std_Refresh")
 
733
{
 
734
  sGroup        = QT_TR_NOOP("Edit");
 
735
  sMenuText     = QT_TR_NOOP("&Refresh");
 
736
  sToolTipText  = QT_TR_NOOP("Recomputes the current active document");
 
737
  sWhatsThis    = "Std_Refresh";
 
738
  sStatusTip    = QT_TR_NOOP("Recomputes the current active document");
 
739
  sPixmap       = "view-refresh";
 
740
  iAccel        = Qt::Key_F5;
 
741
}
 
742
 
 
743
void StdCmdRefresh::activated(int iMsg)
 
744
{
 
745
  if ( getActiveGuiDocument() )
 
746
  {
 
747
    openCommand("Refresh active document");
 
748
    doCommand(Doc,"App.activeDocument().recompute()");
 
749
    commitCommand(); 
 
750
  }
 
751
}
 
752
 
 
753
bool StdCmdRefresh::isActive(void)
 
754
{
 
755
  return this->getDocument() && this->getDocument()->isTouched();
 
756
}
 
757
 
 
758
 
 
759
namespace Gui {
 
760
 
 
761
void CreateDocCommands(void)
 
762
{
 
763
    CommandManager &rcCmdMgr = Application::Instance->commandManager();
 
764
 
 
765
    rcCmdMgr.addCommand(new StdCmdNew());
 
766
    rcCmdMgr.addCommand(new StdCmdOpen());
 
767
    rcCmdMgr.addCommand(new StdCmdImport());
 
768
    rcCmdMgr.addCommand(new StdCmdExport());
 
769
 
 
770
    rcCmdMgr.addCommand(new StdCmdSave());
 
771
    rcCmdMgr.addCommand(new StdCmdSaveAs());
 
772
    rcCmdMgr.addCommand(new StdCmdProjectInfo());
 
773
    rcCmdMgr.addCommand(new StdCmdUndo());
 
774
    rcCmdMgr.addCommand(new StdCmdRedo());
 
775
    rcCmdMgr.addCommand(new StdCmdPrint());
 
776
    rcCmdMgr.addCommand(new StdCmdPrintPdf());
 
777
    rcCmdMgr.addCommand(new StdCmdQuit());
 
778
    rcCmdMgr.addCommand(new StdCmdCut());
 
779
    rcCmdMgr.addCommand(new StdCmdCopy());
 
780
    rcCmdMgr.addCommand(new StdCmdPaste());
 
781
    rcCmdMgr.addCommand(new StdCmdSelectAll());
 
782
    rcCmdMgr.addCommand(new StdCmdDelete());
 
783
    rcCmdMgr.addCommand(new StdCmdRefresh());
 
784
}
 
785
 
 
786
} // namespace Gui