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