| 
									
										
										
										
											2015-02-12 23:16:25 +08:00
										 |  |  | // Aseprite
 | 
					
						
							| 
									
										
										
										
											2017-11-30 22:57:18 +08:00
										 |  |  | // Copyright (C) 2001-2017  David Capello
 | 
					
						
							| 
									
										
										
										
											2015-02-12 23:16:25 +08:00
										 |  |  | //
 | 
					
						
							| 
									
										
										
										
											2016-08-27 04:02:58 +08:00
										 |  |  | // This program is distributed under the terms of
 | 
					
						
							|  |  |  | // the End-User License Agreement for Aseprite.
 | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-06 08:20:19 +08:00
										 |  |  | #ifdef HAVE_CONFIG_H
 | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | #include "config.h"
 | 
					
						
							| 
									
										
										
										
											2013-08-06 08:20:19 +08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-06 08:20:19 +08:00
										 |  |  | #include "app/app.h"
 | 
					
						
							|  |  |  | #include "app/commands/command.h"
 | 
					
						
							| 
									
										
										
										
											2016-06-09 00:27:36 +08:00
										 |  |  | #include "app/commands/commands.h"
 | 
					
						
							| 
									
										
										
										
											2013-08-06 08:20:19 +08:00
										 |  |  | #include "app/context.h"
 | 
					
						
							| 
									
										
										
										
											2018-07-07 22:54:44 +08:00
										 |  |  | #include "app/doc.h"
 | 
					
						
							| 
									
										
										
										
											2016-11-15 04:01:41 +08:00
										 |  |  | #include "app/job.h"
 | 
					
						
							| 
									
										
										
										
											2013-08-06 08:20:19 +08:00
										 |  |  | #include "app/ui/main_window.h"
 | 
					
						
							| 
									
										
										
										
											2012-06-18 09:49:58 +08:00
										 |  |  | #include "ui/alert.h"
 | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-06 08:20:19 +08:00
										 |  |  | namespace app { | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-06 08:20:19 +08:00
										 |  |  | class ExitCommand : public Command { | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | public: | 
					
						
							|  |  |  |   ExitCommand(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							| 
									
										
										
										
											2015-10-01 03:34:43 +08:00
										 |  |  |   void onExecute(Context* context) override; | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ExitCommand::ExitCommand() | 
					
						
							| 
									
										
										
										
											2017-12-02 02:10:21 +08:00
										 |  |  |   : Command(CommandId::Exit(), CmdUIOnlyFlag) | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-09 00:27:36 +08:00
										 |  |  | void ExitCommand::onExecute(Context* ctx) | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-11-15 04:01:41 +08:00
										 |  |  |   // Ignore ExitCommand when we are saving documents or doing a
 | 
					
						
							|  |  |  |   // background task
 | 
					
						
							|  |  |  |   if (Job::runningJobs() > 0) | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-09 00:27:36 +08:00
										 |  |  |   if (ctx->hasModifiedDocuments()) { | 
					
						
							| 
									
										
										
										
											2017-12-02 02:10:21 +08:00
										 |  |  |     Command* closeAll = Commands::instance()->byId(CommandId::CloseAllFiles()); | 
					
						
							| 
									
										
										
										
											2016-06-09 00:27:36 +08:00
										 |  |  |     Params params; | 
					
						
							|  |  |  |     params.set("quitting", "1"); | 
					
						
							|  |  |  |     ctx->executeCommand(closeAll, params); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // The user didn't save all documents (canceled the exit)
 | 
					
						
							|  |  |  |     if (ctx->hasModifiedDocuments()) | 
					
						
							|  |  |  |       return; | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Close the window
 | 
					
						
							| 
									
										
										
										
											2016-04-23 00:19:06 +08:00
										 |  |  |   App::instance()->mainWindow()->closeWindow(NULL); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Command* CommandFactory::createExitCommand() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return new ExitCommand; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-08-06 08:20:19 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | } // namespace app
 |