changeset 26:55d4f16c982b

Fixes #250: QtSharp app doesn't always quit properly * Override Close event to dispose of file dialogs (open and save) * Remove unnecessary event handler hooked to close * Change app initialisation to match pattern used by Synapse * Create file dialogs without specifying "this" as parent - seems to be main fix, for some reason.
author IBBoard <dev@ibboard.co.uk>
date Sat, 31 Jul 2010 16:03:14 +0000
parents 4ec2083eb755
children 7eaa8a1715e2
files Main.cs MainWindow.cs qt-gui/MainWindowLayout.cs qt-gui/MainWindowLayout.ui
diffstat 4 files changed, 26 insertions(+), 36 deletions(-) [+]
line diff
     1.1 --- a/Main.cs	Sat Mar 06 15:23:40 2010 +0000
     1.2 +++ b/Main.cs	Sat Jul 31 16:03:14 2010 +0000
     1.3 @@ -16,7 +16,6 @@
     1.4  	class MainClass
     1.5  	{
     1.6  		private static ILog logger = LogManager.GetLogger(typeof(MainClass));
     1.7 -		static MainWindow win;
     1.8  		static QApplication app;
     1.9  		
    1.10  		public static void Main(string[] args)
    1.11 @@ -24,17 +23,19 @@
    1.12  			try
    1.13  			{
    1.14  				logger.InfoFormat("Starting application with args: {0}", args.ToString());
    1.15 -				app = new QApplication(args);
    1.16 +				app = new QApplication(args, true);
    1.17 +				app.QuitOnLastWindowClosed = true;
    1.18 +				logger.Debug("Starting exec");
    1.19 +				QApplication.Invoke(delegate
    1.20 +				{
    1.21 +					SetUpWarFoundryEnvironment();
    1.22  				
    1.23 -				SetUpWarFoundryEnvironment();
    1.24 -				
    1.25 -				win = new MainWindow();
    1.26 -				win.Show();
    1.27 -				logger.Debug("Starting exec");
    1.28 -				int result = QApplication.Exec ();
    1.29 -				logger.Info("Closing application");
    1.30 -				Environment.Exit(result);
    1.31 -				logger.Info("Exited");
    1.32 +					MainWindow win = new MainWindow();
    1.33 +					win.Show();
    1.34 +					QApplication.SetActiveWindow(win);
    1.35 +				});
    1.36 +				int result = QApplication.Exec();
    1.37 +				logger.InfoFormat("Closing application - exit code {0}", result);
    1.38  			}
    1.39  			catch(Exception ex)
    1.40  			{
     2.1 --- a/MainWindow.cs	Sat Mar 06 15:23:40 2010 +0000
     2.2 +++ b/MainWindow.cs	Sat Jul 31 16:03:14 2010 +0000
     2.3 @@ -47,11 +47,11 @@
     2.4  			}
     2.5  			
     2.6  			SetAppTitle();
     2.7 -			saveArmyDialog = new QFileDialog(this);
     2.8 +			saveArmyDialog = new QFileDialog();
     2.9  			saveArmyDialog.acceptMode = QFileDialog.AcceptMode.AcceptSave;
    2.10  			saveArmyDialog.fileMode = QFileDialog.FileMode.AnyFile;
    2.11  			saveArmyDialog.SetDirectory(new QDir(Environment.GetFolderPath(Environment.SpecialFolder.Personal)));
    2.12 -			openArmyDialog = new QFileDialog(this);
    2.13 +			openArmyDialog = new QFileDialog();
    2.14  			openArmyDialog.acceptMode = QFileDialog.AcceptMode.AcceptOpen;
    2.15  			openArmyDialog.fileMode = QFileDialog.FileMode.ExistingFile;
    2.16  			openArmyDialog.SetNameFilter("*.army");
    2.17 @@ -64,6 +64,13 @@
    2.18  			CommandStack.CommandStackUpdated+= HandleCommandStackCommandStackUpdated;
    2.19  		}
    2.20  		
    2.21 +		protected override void CloseEvent(QCloseEvent arg1)
    2.22 +		{
    2.23 +			base.CloseEvent(arg1);
    2.24 +			saveArmyDialog.Dispose();
    2.25 +			openArmyDialog.Dispose();
    2.26 +		}
    2.27 +		
    2.28  		private void SetUpActionIcons()
    2.29  		{
    2.30  			layout.actionCreateArmy.icon = new QIcon("icons/ui/filenew.png");
     3.1 --- a/qt-gui/MainWindowLayout.cs	Sat Mar 06 15:23:40 2010 +0000
     3.2 +++ b/qt-gui/MainWindowLayout.cs	Sat Jul 31 16:03:14 2010 +0000
     3.3 @@ -1,8 +1,8 @@
     3.4  /********************************************************************************
     3.5  ** Form generated from reading ui file 'MainWindowLayout.ui'
     3.6  **
     3.7 -** Created: Sat Feb 13 10:32:31 2010
     3.8 -**      by: Qt User Interface Compiler for C# version 4.5.3
     3.9 +** Created: Sat Jul 31 16:07:24 2010
    3.10 +**      by: Qt User Interface Compiler for C# version 4.6.3
    3.11  **
    3.12  ** WARNING! All changes made in this file will be lost when recompiling ui file!
    3.13  ********************************************************************************/
    3.14 @@ -103,7 +103,7 @@
    3.15      MainWindowLayout.SetCentralWidget(mainContent);
    3.16      menubar = new QMenuBar(MainWindowLayout);
    3.17      menubar.ObjectName = "menubar";
    3.18 -    menubar.Geometry = new QRect(0, 0, 696, 23);
    3.19 +    menubar.Geometry = new QRect(0, 0, 696, 21);
    3.20      menuFile = new QMenu(menubar);
    3.21      menuFile.ObjectName = "menuFile";
    3.22      menuExportArmyAs = new QMenu(menuFile);
    3.23 @@ -141,7 +141,6 @@
    3.24      menuHelp.AddAction(actionAbout);
    3.25  
    3.26      RetranslateUi(MainWindowLayout);
    3.27 -    QObject.Connect(actionExit, Qt.SIGNAL("triggered()"), MainWindowLayout, Qt.SLOT("close()"));
    3.28  
    3.29      unitTabs.CurrentIndex = 0;
    3.30  
     4.1 --- a/qt-gui/MainWindowLayout.ui	Sat Mar 06 15:23:40 2010 +0000
     4.2 +++ b/qt-gui/MainWindowLayout.ui	Sat Jul 31 16:03:14 2010 +0000
     4.3 @@ -66,7 +66,7 @@
     4.4       <x>0</x>
     4.5       <y>0</y>
     4.6       <width>696</width>
     4.7 -     <height>23</height>
     4.8 +     <height>21</height>
     4.9      </rect>
    4.10     </property>
    4.11     <widget class="QMenu" name="menuFile">
    4.12 @@ -206,22 +206,5 @@
    4.13    </action>
    4.14   </widget>
    4.15   <resources/>
    4.16 - <connections>
    4.17 -  <connection>
    4.18 -   <sender>actionExit</sender>
    4.19 -   <signal>triggered()</signal>
    4.20 -   <receiver>MainWindowLayout</receiver>
    4.21 -   <slot>close()</slot>
    4.22 -   <hints>
    4.23 -    <hint type="sourcelabel">
    4.24 -     <x>-1</x>
    4.25 -     <y>-1</y>
    4.26 -    </hint>
    4.27 -    <hint type="destinationlabel">
    4.28 -     <x>399</x>
    4.29 -     <y>299</y>
    4.30 -    </hint>
    4.31 -   </hints>
    4.32 -  </connection>
    4.33 - </connections>
    4.34 + <connections/>
    4.35  </ui>