20
20
#include <klocale.h>
22
22
#include "../rkglobals.h"
23
#include "../rkeditormanager.h"
24
23
#include "../dataeditor/rkeditor.h"
25
24
#include "rcontainerobject.h"
25
#include "../windows/rkworkplace.h"
27
27
#include "../debug.h"
29
29
RKModificationTracker::RKModificationTracker (QObject *parent) : QObject (parent) {
30
30
RK_TRACE (OBJECTS);
35
37
RK_TRACE (OBJECTS);
38
void RKModificationTracker::removeObject (RObject *object, RKEditor *editor, bool removed_in_workspace) {
40
bool RKModificationTracker::removeObject (RObject *object, RKEditor *editor, bool removed_in_workspace) {
39
41
RK_TRACE (OBJECTS);
40
42
// TODO: allow more than one editor per object
43
// WARNING: This does not work, if a sub-object is being edited!
41
44
RKEditor *ed = object->objectOpened ();
42
45
RK_ASSERT (!((editor) && (!ed)));
43
46
RK_ASSERT (!(removed_in_workspace && editor));
45
48
if (removed_in_workspace) {
47
if (KMessageBox::questionYesNo (0, i18n ("The object '%1' was removed from workspace, but is currently opened for editing. Do you want to restore it?").arg (object->getFullName ()), i18n ("Restore object?")) == KMessageBox::Yes) {
50
if (KMessageBox::questionYesNo (0, i18n ("The object '%1' was removed from workspace or changed to a different type of object, but is currently opened for editing. Do you want to restore it?").arg (object->getFullName ()), i18n ("Restore object?")) == KMessageBox::Yes) {
48
51
if (removed_in_workspace) ed->restoreObject (object);
53
56
if (editor || ed) {
54
57
if (KMessageBox::questionYesNo (0, i18n ("Do you really want to remove the object '%1'? The object is currently opened for editing, it will be removed in the editor, too. There's no way to get it back.").arg (object->getFullName ()), i18n ("Remove object?")) != KMessageBox::Yes) {
58
61
// TODO: check for other editors editing this object
59
62
if (KMessageBox::questionYesNo (0, i18n ("Do you really want to remove the object '%1'? There's no way to get it back.").arg (object->getFullName ()), i18n ("Remove object?")) != KMessageBox::Yes) {
65
if (ed) ed->removeObject (object);
66
emit (objectRemoved (object));
68
if (ed) ed->removeObject (object); // READ: delete ed
69
/* What's this? A child of a removed complex object may be edited somewhere, but not the whole object. In this case, the editor has no chance of restoring the object, but it still needs to be closed. We search all editors for the removed object */
70
if (object->isContainer ()) {
71
RKWorkplace::RKWorkplaceObjectList list = RKWorkplace::mainWorkplace ()->getObjectList (RKMDIWindow::DataEditorWindow);
72
for (RKWorkplace::RKWorkplaceObjectList::const_iterator it = list.constBegin (); it != list.constEnd (); ++it) {
73
RKEditor *subed = static_cast<RKEditor *> (*it);
74
RObject *subedobj = subed->getObject ();
75
if (static_cast<RContainerObject *> (object)->isParentOf (subedobj, true)) {
76
subed->removeObject (subedobj);
81
if (updates_locked <= 0) emit (objectRemoved (object));
67
82
object->remove (removed_in_workspace);
70
87
void RKModificationTracker::renameObject (RObject *object, const QString &new_name) {
78
95
// since we may end up with a different name that originally requested, we propagate the change also to the original editor
79
96
if (ed) ed->renameObject (object);
80
emit (objectPropertiesChanged (object));
97
if (updates_locked <= 0) emit (objectPropertiesChanged (object));
83
100
void RKModificationTracker::addObject (RObject *object, RKEditor *editor) {