~ubuntu-branches/ubuntu/karmic/rkward/karmic

« back to all changes in this revision

Viewing changes to rkward/core/rkmodificationtracker.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Friedrichsmeier
  • Date: 2006-11-06 16:30:00 UTC
  • mfrom: (1.2.1 upstream) (3.1.1 feisty)
  • Revision ID: james.westby@ubuntu.com-20061106163000-qi8ju75eqecrfay7
* new upstream release
* depend on either php4-cli or php5-cli

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include <klocale.h>
21
21
 
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"
26
26
 
27
27
#include "../debug.h"
28
28
 
29
29
RKModificationTracker::RKModificationTracker (QObject *parent) : QObject (parent) {
30
30
        RK_TRACE (OBJECTS);
 
31
 
 
32
        updates_locked = 0;
31
33
}
32
34
 
33
35
 
35
37
        RK_TRACE (OBJECTS);
36
38
}
37
39
 
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));
44
 
        
 
47
 
45
48
        if (removed_in_workspace) {
46
49
                if (ed) {
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);
49
 
                                return;
 
52
                                return false;
50
53
                        }
51
54
                }
52
55
        } else {
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) {
55
 
                                return;
 
58
                                return false;
56
59
                        }
57
60
                } else {
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) {
60
 
                                return;
 
63
                                return false;
61
64
                        }
62
65
                }
63
66
        }
64
67
        
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);
 
77
                        }
 
78
                }
 
79
        }
 
80
 
 
81
        if (updates_locked <= 0) emit (objectRemoved (object));
67
82
        object->remove (removed_in_workspace);
 
83
 
 
84
        return true;
68
85
}
69
86
 
70
87
void RKModificationTracker::renameObject (RObject *object, const QString &new_name) {
77
94
 
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));
81
98
}
82
99
 
83
100
void RKModificationTracker::addObject (RObject *object, RKEditor *editor) {
92
109
                        ed->addObject (object);
93
110
                }
94
111
        }
95
 
        emit (objectAdded (object));
 
112
        if (updates_locked <= 0) emit (objectAdded (object));
96
113
}
97
114
 
98
115
void RKModificationTracker::objectMetaChanged (RObject *object) {
103
120
        if (ed) {
104
121
                ed->updateObjectMeta (object);
105
122
        }
106
 
        emit (objectPropertiesChanged (object));
 
123
        if (updates_locked <= 0) emit (objectPropertiesChanged (object));
107
124
}
108
125
 
109
126
void RKModificationTracker::objectDataChanged (RObject *object, RObject::ChangeSet *changes) {