Changeset View
Changeset View
Standalone View
Standalone View
src/plugins/tables/kexitablepart.cpp
Show All 26 Lines | |||||
27 | #include <kexiutils/utils.h> | 27 | #include <kexiutils/utils.h> | ||
28 | #include <widget/properties/KexiCustomPropertyFactory.h> | 28 | #include <widget/properties/KexiCustomPropertyFactory.h> | ||
29 | #include <widget/tableview/KexiDataTableView.h> | 29 | #include <widget/tableview/KexiDataTableView.h> | ||
30 | #include <widget/tableview/KexiDataTableScrollArea.h> | 30 | #include <widget/tableview/KexiDataTableScrollArea.h> | ||
31 | #include "kexitabledesignerview.h" | 31 | #include "kexitabledesignerview.h" | ||
32 | #include "kexitabledesigner_dataview.h" | 32 | #include "kexitabledesigner_dataview.h" | ||
33 | #include "kexilookupcolumnpage.h" | 33 | #include "kexilookupcolumnpage.h" | ||
34 | #include <KexiWindow.h> | 34 | #include <KexiWindow.h> | ||
35 | #include <kexiutils/utils.h> | ||||
35 | 36 | | |||
36 | #include <KDbConnection> | 37 | #include <KDbConnection> | ||
37 | 38 | | |||
38 | #include <KMessageBox> | 39 | #include <KMessageBox> | ||
39 | 40 | | |||
40 | #include <QDebug> | 41 | #include <QDebug> | ||
41 | #include <QTabWidget> | 42 | #include <QTabWidget> | ||
42 | 43 | | |||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Line(s) | 128 | if (!project || !project->dbConnection()) | |||
128 | return false; | 129 | return false; | ||
129 | 130 | | |||
130 | KDbConnection *conn = project->dbConnection(); | 131 | KDbConnection *conn = project->dbConnection(); | ||
131 | KDbTableSchema *sch = conn->tableSchema(item->identifier()); | 132 | KDbTableSchema *sch = conn->tableSchema(item->identifier()); | ||
132 | 133 | | |||
133 | if (sch) { | 134 | if (sch) { | ||
134 | const tristate res = KexiTablePart::askForClosingObjectsUsingTableSchema( | 135 | const tristate res = KexiTablePart::askForClosingObjectsUsingTableSchema( | ||
135 | KexiMainWindowIface::global()->openedWindowFor(item->identifier()), conn, sch, | 136 | KexiMainWindowIface::global()->openedWindowFor(item->identifier()), conn, sch, | ||
136 | xi18n("You are about to remove table <resource>%1</resource> but following objects using this table are opened:", | 137 | kxi18n("<para>You are about to delete table <resource>%1</resource> but it is used by " | ||
137 | sch->name())); | 138 | "following opened windows:</para>") | ||
139 | .subs(sch->name())); | ||||
138 | if (res != true) { | 140 | if (res != true) { | ||
139 | return res; | 141 | return res; | ||
140 | } | 142 | } | ||
141 | return conn->dropTable(sch); | 143 | return conn->dropTable(sch); | ||
142 | } | 144 | } | ||
143 | //last chance: just remove item | 145 | //last chance: just remove item | ||
144 | return conn->removeObject(item->identifier()); | 146 | return conn->removeObject(item->identifier()); | ||
145 | } | 147 | } | ||
146 | 148 | | |||
147 | tristate KexiTablePart::rename(KexiPart::Item *item, const QString& newName) | 149 | tristate KexiTablePart::rename(KexiPart::Item *item, const QString& newName) | ||
148 | { | 150 | { | ||
149 | Q_ASSERT(item); | 151 | Q_ASSERT(item); | ||
150 | KDbConnection *conn = KexiMainWindowIface::global()->project()->dbConnection(); | 152 | KDbConnection *conn = KexiMainWindowIface::global()->project()->dbConnection(); | ||
151 | KDbTableSchema *schema = conn->tableSchema(item->identifier()); | 153 | KDbTableSchema *schema = conn->tableSchema(item->identifier()); | ||
152 | if (!schema) | 154 | if (!schema) | ||
153 | return false; | 155 | return false; | ||
154 | const tristate res = KexiTablePart::askForClosingObjectsUsingTableSchema( | 156 | const tristate res = KexiTablePart::askForClosingObjectsUsingTableSchema( | ||
155 | KexiMainWindowIface::global()->openedWindowFor(item->identifier()), conn, schema, | 157 | KexiMainWindowIface::global()->openedWindowFor(item->identifier()), conn, schema, | ||
156 | xi18n("You are about to rename table <resource>%1</resource> but following objects using this table are opened:", | 158 | kxi18n("<para>You are about to rename table <resource>%1</resource> but it is used by " | ||
157 | schema->name())); | 159 | "following opened windows:") | ||
160 | .subs(schema->name())); | ||||
158 | if (res != true) { | 161 | if (res != true) { | ||
159 | return res; | 162 | return res; | ||
160 | } | 163 | } | ||
161 | return conn->alterTableName(schema, newName); | 164 | return conn->alterTableName(schema, newName); | ||
162 | } | 165 | } | ||
163 | 166 | | |||
164 | KDbObject* KexiTablePart::loadSchemaObject(KexiWindow *window, const KDbObject& object, | 167 | KDbObject* KexiTablePart::loadSchemaObject(KexiWindow *window, const KDbObject& object, | ||
165 | Kexi::ViewMode viewMode, bool *ownedByWindow) | 168 | Kexi::ViewMode viewMode, bool *ownedByWindow) | ||
166 | { | 169 | { | ||
167 | Q_UNUSED(window); | 170 | Q_UNUSED(window); | ||
168 | Q_UNUSED(viewMode); | 171 | Q_UNUSED(viewMode); | ||
169 | if (ownedByWindow) | 172 | if (ownedByWindow) | ||
170 | *ownedByWindow = false; | 173 | *ownedByWindow = false; | ||
171 | return KexiMainWindowIface::global()->project()->dbConnection()->tableSchema(object.name()); | 174 | return KexiMainWindowIface::global()->project()->dbConnection()->tableSchema(object.name()); | ||
172 | } | 175 | } | ||
173 | 176 | | |||
174 | //static | 177 | // static | ||
175 | tristate KexiTablePart::askForClosingObjectsUsingTableSchema( | 178 | tristate KexiTablePart::askForClosingObjectsUsingTableSchema(KexiWindow *window, | ||
176 | KexiWindow *window, KDbConnection *conn, | 179 | KDbConnection *conn, | ||
177 | KDbTableSchema *table, const QString& msg) | 180 | KDbTableSchema *table, | ||
181 | const KLocalizedString &msg) | ||||
178 | { | 182 | { | ||
179 | Q_ASSERT(conn); | 183 | Q_ASSERT(conn); | ||
180 | Q_ASSERT(table); | 184 | Q_ASSERT(table); | ||
181 | if (!window) { | 185 | if (!window) { | ||
182 | return true; | 186 | return true; | ||
183 | } | 187 | } | ||
184 | QList<KDbTableSchemaChangeListener*> listeners | 188 | QList<KDbTableSchemaChangeListener*> listeners | ||
185 | = KDbTableSchemaChangeListener::listeners(conn, table); | 189 | = KDbTableSchemaChangeListener::listeners(conn, table); | ||
186 | KexiTablePartTempData *temp = static_cast<KexiTablePartTempData*>(window->data()); | 190 | KexiTablePartTempData *temp = static_cast<KexiTablePartTempData*>(window->data()); | ||
187 | // Special case: listener that is equal to window->data() will be silently closed | 191 | // Special case: listener that is equal to window->data() will be silently closed | ||
188 | // without asking for confirmation. It is not counted when looking for objects that | 192 | // without asking for confirmation. It is not counted when looking for objects that | ||
189 | // are "blocking" changes of the table. | 193 | // are "blocking" changes of the table. | ||
190 | const bool tempListenerExists = listeners.removeAll(temp) > 0; | 194 | const bool tempListenerExists = listeners.removeAll(temp) > 0; | ||
191 | // Immediate success if there's no temp-data's listener to close nor other listeners to close | 195 | // Immediate success if there's no temp-data's listener to close nor other listeners to close | ||
192 | if (!tempListenerExists && listeners.isEmpty()) { | 196 | if (!tempListenerExists && listeners.isEmpty()) { | ||
193 | return true; | 197 | return true; | ||
194 | } | 198 | } | ||
195 | 199 | | |||
196 | if (!listeners.isEmpty()) { | 200 | if (!listeners.isEmpty()) { | ||
197 | QString openedObjectsStr = "<list>"; | 201 | QString openedObjectsStr = "<p><ul>"; | ||
198 | for(const KDbTableSchemaChangeListener* listener : listeners) { | 202 | for(const KDbTableSchemaChangeListener* listener : listeners) { | ||
199 | openedObjectsStr += QString("<item>%1</item>").arg(listener->name()); | 203 | openedObjectsStr += QString("<li>%1</li>").arg(listener->name()); | ||
200 | } | 204 | } | ||
201 | openedObjectsStr += "</list>"; | 205 | openedObjectsStr += "</ul></p>"; | ||
202 | const int r = KMessageBox::questionYesNo(window, | 206 | QString message = "<html>" | ||
203 | i18nc("@info", "<para>%1</para><para>%2</para>", msg, openedObjectsStr) | 207 | + i18nc("@info/plain Sentence1 Sentence2 Sentence3", "%1%2%3", | ||
204 | + "<para>" | 208 | KexiUtils::localizedStringToHtmlSubstring(msg), openedObjectsStr, | ||
205 | + xi18n("Do you want to close all windows for these objects?") | 209 | KexiUtils::localizedStringToHtmlSubstring( | ||
206 | + "</para>", | 210 | kxi18nc("@info", "<para>Do you want to close these windows and save the " | ||
207 | QString(), KGuiItem(xi18nc("@action:button Close All Windows", "Close Windows"), koIconName("window-close")), KStandardGuiItem::cancel()); | 211 | "design or cancel saving?</para>"))) | ||
212 | + "</html>"; | ||||
213 | KGuiItem closeAndSaveItem(KStandardGuiItem::save()); | ||||
214 | closeAndSaveItem.setText( | ||||
215 | xi18nc("@action:button Close all windows and save", "Close Windows and Save")); | ||||
216 | closeAndSaveItem.setToolTip(xi18nc("@info:tooltip Close all windows and save design", | ||||
217 | "Close all windows and save design")); | ||||
218 | const int r = KMessageBox::questionYesNo(window, message, QString(), closeAndSaveItem, | ||||
219 | KStandardGuiItem::cancel(), QString(), | ||||
220 | KMessageBox::Notify | KMessageBox::Dangerous); | ||||
208 | if (r != KMessageBox::Yes) { | 221 | if (r != KMessageBox::Yes) { | ||
209 | return cancelled; | 222 | return cancelled; | ||
210 | } | 223 | } | ||
211 | } | 224 | } | ||
212 | //try to close every window depending on the table (if present) and also the temp-data's listener (if present) | 225 | // try to close every window depending on the table (if present) and also the temp-data's | ||
213 | const tristate res = KDbTableSchemaChangeListener::closeListeners(conn, table); | 226 | // listener (if present) | ||
227 | const tristate res = KDbTableSchemaChangeListener::closeListeners(conn, table, { temp }); | ||||
214 | if (res != true) { //do not expose closing errors twice; just cancel | 228 | if (res != true) { //do not expose closing errors twice; just cancel | ||
215 | return cancelled; | 229 | return cancelled; | ||
216 | } | 230 | } | ||
217 | return true; | 231 | return true; | ||
218 | } | 232 | } | ||
219 | 233 | | |||
220 | KLocalizedString KexiTablePart::i18nMessage( | 234 | KLocalizedString KexiTablePart::i18nMessage( | ||
221 | const QString& englishMessage, KexiWindow* window) const | 235 | const QString& englishMessage, KexiWindow* window) const | ||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Line(s) | 314 | { | |||
301 | return d->table; | 315 | return d->table; | ||
302 | } | 316 | } | ||
303 | 317 | | |||
304 | KDbConnection* KexiTablePartTempData::connection() | 318 | KDbConnection* KexiTablePartTempData::connection() | ||
305 | { | 319 | { | ||
306 | return d->conn; | 320 | return d->conn; | ||
307 | } | 321 | } | ||
308 | 322 | | |||
323 | void KexiTablePartTempData::closeDataInDataView() | ||||
324 | { | ||||
325 | const KexiWindow* window = static_cast<KexiWindow*>(parent()); | ||||
326 | if (window->currentViewMode() != Kexi::DataViewMode) { | ||||
327 | KexiTableDesigner_DataView *dataView | ||||
328 | = qobject_cast<KexiTableDesigner_DataView*>(window->viewForMode(Kexi::DataViewMode)); | ||||
329 | if (dataView && dataView->tableView()->data()) { | ||||
330 | dataView->setData(nullptr); | ||||
331 | } | ||||
332 | } | ||||
333 | } | ||||
334 | | ||||
309 | void KexiTablePartTempData::setTable(KDbTableSchema *table) | 335 | void KexiTablePartTempData::setTable(KDbTableSchema *table) | ||
310 | { | 336 | { | ||
311 | if (d->table == table) { | 337 | if (d->table == table) { | ||
312 | return; | 338 | return; | ||
313 | } | 339 | } | ||
314 | if (d->table) { | 340 | if (d->table) { | ||
315 | KDbTableSchemaChangeListener::unregisterForChanges(d->conn, this, d->table); | 341 | KDbTableSchemaChangeListener::unregisterForChanges(d->conn, d->table); | ||
316 | } | 342 | } | ||
343 | closeDataInDataView(); | ||||
317 | d->table = table; | 344 | d->table = table; | ||
318 | if (d->table) { | 345 | if (d->table) { | ||
319 | KDbTableSchemaChangeListener::registerForChanges(d->conn, this, d->table); | 346 | KDbTableSchemaChangeListener::registerForChanges(d->conn, this, d->table); | ||
320 | } | 347 | } | ||
321 | } | 348 | } | ||
322 | 349 | | |||
323 | tristate KexiTablePartTempData::closeListener() | 350 | tristate KexiTablePartTempData::closeListener() | ||
324 | { | 351 | { | ||
325 | KexiWindow* window = static_cast<KexiWindow*>(parent()); | 352 | KexiWindow* window = static_cast<KexiWindow*>(parent()); | ||
326 | if (window->currentViewMode() != Kexi::DataViewMode) { | 353 | qDebug() << window->partItem()->name(); | ||
327 | KexiTableDesigner_DataView *dataView | 354 | closeDataInDataView(); | ||
328 | = qobject_cast<KexiTableDesigner_DataView*>(window->viewForMode(Kexi::DataViewMode)); | 355 | if (closeWindowOnCloseListener) { | ||
329 | if (dataView && dataView->tableView()->data()) { | 356 | return KexiMainWindowIface::global()->closeWindow(window); | ||
330 | dataView->setData(nullptr); | | |||
331 | } | | |||
332 | } | 357 | } | ||
333 | return true; | 358 | return true; | ||
334 | } | 359 | } | ||
335 | 360 | | |||
336 | #include "kexitablepart.moc" | 361 | #include "kexitablepart.moc" |