| 221 | } |
| 222 | |
| 223 | bool DocumentView::onCloseView(Workspace* workspace, bool quitting) |
| 224 | { |
| 225 | if (m_editor->isMovingPixels()) |
| 226 | m_editor->dropMovingPixels(); |
| 227 | |
| 228 | // If there is another view for this document, just close the view. |
| 229 | for (auto view : *workspace) { |
| 230 | DocumentView* docView = dynamic_cast<DocumentView*>(view); |
| 231 | if (docView && docView != this && |
| 232 | docView->document() == document()) { |
| 233 | workspace->removeView(this); |
| 234 | delete this; |
| 235 | return true; |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | UIContext* ctx = UIContext::instance(); |
| 240 | bool save_it; |
| 241 | bool try_again = true; |
| 242 | |
| 243 | while (try_again) { |
| 244 | // This flag indicates if we have to sabe the sprite before to destroy it |
| 245 | save_it = false; |
| 246 | { |
| 247 | // see if the sprite has changes |
| 248 | while (m_document->isModified()) { |
| 249 | // ask what want to do the user with the changes in the sprite |
| 250 | int ret = Alert::show("Warning" |
| 251 | "<<Saving changes to the sprite" |
| 252 | "<<\"%s\" before %s?" |
| 253 | "||&Save||Do&n't Save||&Cancel", |
| 254 | m_document->name().c_str(), |
| 255 | quitting ? "quitting": "closing"); |
| 256 | |
| 257 | if (ret == 1) { |
| 258 | // "save": save the changes |
| 259 | save_it = true; |
| 260 | break; |
| 261 | } |
| 262 | else if (ret != 2) { |
| 263 | // "cancel" or "ESC" */ |
| 264 | return false; // we back doing nothing |
| 265 | } |
| 266 | else { |
| 267 | // "discard" |
| 268 | break; |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | // Does we need to save the sprite? |
| 274 | if (save_it) { |
| 275 | ctx->setActiveView(this); |
| 276 | ctx->updateFlags(); |
| 277 | |
| 278 | Command* save_command = |
| 279 | CommandsModule::instance()->getCommandByName(CommandId::SaveFile); |
| 280 | ctx->executeCommand(save_command); |
nothing calls this directly
no test coverage detected