| 1 |
/*************************************************************************** |
| 2 |
* Copyright (c) 2004 Werner Mayer <wmayer[at]users.sourceforge.net> * |
| 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 |
#include <QAction> |
| 24 |
#include <QList> |
| 25 |
|
| 26 |
#include "Dialogs/DlgUndoRedo.h" |
| 27 |
#include "Application.h" |
| 28 |
#include "MainWindow.h" |
| 29 |
#include "MDIView.h" |
| 30 |
|
| 31 |
|
| 32 |
using namespace Gui::Dialog; |
| 33 |
|
| 34 |
/* TRANSLATOR Gui::Dialog::UndoRedoDialog */ |
| 35 |
|
| 36 |
/** |
| 37 |
* Constructs a UndoRedoDialog which is a child of 'parent', with the |
| 38 |
* name 'name'.' |
| 39 |
*/ |
| 40 |
UndoDialog::UndoDialog(QWidget* parent) |
| 41 |
: QMenu(parent) |
| 42 |
{ |
| 43 |
connect(this, &QMenu::aboutToShow, this, &UndoDialog::onFetchInfo); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Destroys the object and frees any allocated resources. |
| 48 |
*/ |
| 49 |
UndoDialog::~UndoDialog() = default; |
| 50 |
|
| 51 |
/** |
| 52 |
* This method fetches the undo / redo information from the |
| 53 |
* active document and shows it in the undo / redo dialog. |
| 54 |
*/ |
| 55 |
void UndoDialog::onFetchInfo() |
| 56 |
{ |
| 57 |
clear(); // Remove first all items |
| 58 |
|
| 59 |
MDIView* mdi = getMainWindow()->activeWindow(); |
| 60 |
if (mdi) { |
| 61 |
QStringList vecUndos = mdi->undoActions(); |
| 62 |
for (QStringList::Iterator i = vecUndos.begin(); i != vecUndos.end(); ++i) { |
| 63 |
addAction(*i, this, &UndoDialog::onSelected); |
| 64 |
} |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
/** Closes the dialog and sends the message 'Undo' to the currently active MDI view. */ |
| 69 |
void UndoDialog::onSelected() |
| 70 |
{ |
| 71 |
auto a = static_cast<QAction*>(sender()); |
| 72 |
QList<QAction*> acts = this->actions(); |
| 73 |
for (QList<QAction*>::Iterator it = acts.begin(); it != acts.end(); ++it) { |
| 74 |
Gui::Application::Instance->sendMsgToActiveView("Undo"); |
| 75 |
if (*it == a) { |
| 76 |
break; |
| 77 |
} |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
/* TRANSLATOR Gui::Dialog::RedoDialog */ |
| 82 |
|
| 83 |
/** |
| 84 |
* Constructs a UndoRedoDialog which is a child of 'parent', with the |
| 85 |
* name 'name'.' |
| 86 |
*/ |
| 87 |
RedoDialog::RedoDialog(QWidget* parent) |
| 88 |
: QMenu(parent) |
| 89 |
{ |
| 90 |
connect(this, &QMenu::aboutToShow, this, &RedoDialog::onFetchInfo); |
| 91 |
} |
| 92 |
|
| 93 |
/** |
| 94 |
* Destroys the object and frees any allocated resources. |
| 95 |
*/ |
| 96 |
RedoDialog::~RedoDialog() = default; |
| 97 |
|
| 98 |
/** |
| 99 |
* This method fetches the undo / redo information from the |
| 100 |
* active document and shows it in the undo / redo dialog. |
| 101 |
*/ |
| 102 |
void RedoDialog::onFetchInfo() |
| 103 |
{ |
| 104 |
clear(); // Remove first all items |
| 105 |
|
| 106 |
MDIView* mdi = getMainWindow()->activeWindow(); |
| 107 |
if (mdi) { |
| 108 |
QStringList vecRedos = mdi->redoActions(); |
| 109 |
for (QStringList::Iterator i = vecRedos.begin(); i != vecRedos.end(); ++i) { |
| 110 |
addAction(*i, this, &RedoDialog::onSelected); |
| 111 |
} |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
/** Closes the dialog and sends the message 'Redo' to the currently active MDI view. */ |
| 116 |
void RedoDialog::onSelected() |
| 117 |
{ |
| 118 |
auto a = static_cast<QAction*>(sender()); |
| 119 |
QList<QAction*> acts = this->actions(); |
| 120 |
for (QList<QAction*>::Iterator it = acts.begin(); it != acts.end(); ++it) { |
| 121 |
Gui::Application::Instance->sendMsgToActiveView("Redo"); |
| 122 |
if (*it == a) { |
| 123 |
break; |
| 124 |
} |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
#include "moc_DlgUndoRedo.cpp" |