From 0a589956d713c7adcc09b0276b564ca4d6159e52 Mon Sep 17 00:00:00 2001 From: RKrom Date: Sat, 31 Jul 2010 16:00:17 +0000 Subject: [PATCH] Some small fixes git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@757 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4 --- Greenshot/Forms/MainForm.Designer.cs | 1 + Greenshot/Forms/MainForm.cs | 65 +++++++++++++++++------- GreenshotCore/Helpers/HotkeyHelper.cs | 2 + GreenshotCore/Helpers/PluginHelper.cs | 1 + GreenshotEditor/Forms/ImageEditorForm.cs | 2 +- 5 files changed, 51 insertions(+), 20 deletions(-) diff --git a/Greenshot/Forms/MainForm.Designer.cs b/Greenshot/Forms/MainForm.Designer.cs index 06421d575..2728acd8f 100644 --- a/Greenshot/Forms/MainForm.Designer.cs +++ b/Greenshot/Forms/MainForm.Designer.cs @@ -219,6 +219,7 @@ namespace Greenshot { this.Text = "Greenshot"; this.TopMost = true; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainFormFormClosing); + this.Activated += new System.EventHandler(this.MainFormActivated); this.contextMenu.ResumeLayout(false); this.ResumeLayout(false); } diff --git a/Greenshot/Forms/MainForm.cs b/Greenshot/Forms/MainForm.cs index 07297a399..eb6e20543 100644 --- a/Greenshot/Forms/MainForm.cs +++ b/Greenshot/Forms/MainForm.cs @@ -63,7 +63,7 @@ namespace Greenshot { // Setup log4j, currently the file is called log4net.xml string log4netFilename = Path.Combine(Application.StartupPath, LOG4NET_FILE); if (File.Exists(log4netFilename)) { - log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(log4netFilename)); + log4net.Config.XmlConfigurator.Configure(new FileInfo(log4netFilename)); } else { MessageBox.Show("Can't find file " + LOG4NET_FILE); } @@ -230,7 +230,7 @@ namespace Greenshot { dataTransport = new DataTransport(CommandEnum.FirstLaunch, null); } MainForm mainForm = new MainForm(dataTransport); - Application.Run(); + Application.Run(mainForm); } catch(Exception ex) { LOG.Error("Exception in startup.", ex); Application_ThreadException(MainForm.ActiveForm, new ThreadExceptionEventArgs(ex)); @@ -336,9 +336,14 @@ namespace Greenshot { #region mainform events void MainFormFormClosing(object sender, FormClosingEventArgs e) { - LOG.Info("Closing with reason: " + e.CloseReason); + instance = null; exit(); } + + void MainFormActivated(object sender, EventArgs e) { + Hide(); + ShowInTaskbar = false; + } #endregion @@ -534,37 +539,59 @@ namespace Greenshot { } /// - /// Exit/cleanup + /// Shutdown / cleanup /// public void exit() { + LOG.Info("Exit: " + EnvironmentInfo.EnvironmentToString(false)); try { // Make sure hotkeys are disabled - HotkeyHelper.UnregisterHotkeys((int)this.Handle); + HotkeyHelper.UnregisterHotkeys(Handle.ToInt32()); + } catch (Exception e) { + LOG.Error("Error unregistering hotkeys!", e); + } + try { // Now the sound isn't needed anymore SoundHelper.Deinitialize(); + } catch (Exception e) { + LOG.Error("Error deinitializing sound!", e); + } - // Making sure all Windows are closed, gracefull shutdown - Application.Exit(); - + try { // Inform all registed plugins PluginHelper.instance.Shutdown(); - + } catch (Exception e) { + LOG.Error("Error shutting down plugins!", e); + } + try { + // Making sure all Windows are closed, gracefull shutdown + Application.Exit(); + } catch (Exception e) { + LOG.Error("Error closing application!", e); + } + + try { // Store any open configuration changes conf.Store(); - } finally { - // Remove the application mutex - if (applicationMutex != null) { - try { - applicationMutex.ReleaseMutex(); - } catch (Exception ex) { - LOG.Error("Error releasing Mutex!", ex); - } + } catch (Exception e) { + LOG.Error("Error storing configuration!", e); + } + // Remove the application mutex + if (applicationMutex != null) { + try { + applicationMutex.ReleaseMutex(); + applicationMutex = null; + } catch (Exception ex) { + LOG.Error("Error releasing Mutex!", ex); } + } - // make the icon invisible otherwise it stays even after exit!! + // make the icon invisible otherwise it stays even after exit!! + if (notifyIcon != null) { notifyIcon.Visible = false; + notifyIcon.Dispose(); + notifyIcon = null; } } } -} +} \ No newline at end of file diff --git a/GreenshotCore/Helpers/HotkeyHelper.cs b/GreenshotCore/Helpers/HotkeyHelper.cs index 69160660e..ae9a053ab 100644 --- a/GreenshotCore/Helpers/HotkeyHelper.cs +++ b/GreenshotCore/Helpers/HotkeyHelper.cs @@ -74,6 +74,8 @@ namespace Greenshot.Helpers { foreach(int hotkey in keyHandlers.Keys) { UnregisterHotKey(hnd, hotkey); } + // Remove all key handlers + keyHandlers.Clear(); } public static void HandleMessages(ref Message m) { diff --git a/GreenshotCore/Helpers/PluginHelper.cs b/GreenshotCore/Helpers/PluginHelper.cs index e89baf71b..e1b456a56 100644 --- a/GreenshotCore/Helpers/PluginHelper.cs +++ b/GreenshotCore/Helpers/PluginHelper.cs @@ -89,6 +89,7 @@ namespace Greenshot.Helpers { foreach(IGreenshotPlugin plugin in plugins.Values) { plugin.Shutdown(); } + plugins.Clear(); } // Add plugins to the Listview diff --git a/GreenshotEditor/Forms/ImageEditorForm.cs b/GreenshotEditor/Forms/ImageEditorForm.cs index 9a279bc79..f15fb5de8 100644 --- a/GreenshotEditor/Forms/ImageEditorForm.cs +++ b/GreenshotEditor/Forms/ImageEditorForm.cs @@ -570,7 +570,7 @@ namespace Greenshot.Forms { if (!saved) { MessageBoxButtons buttons = MessageBoxButtons.YesNoCancel; // Dissallow "CANCEL" if the application needs to shutdown - if (e.CloseReason == CloseReason.ApplicationExitCall || e.CloseReason == CloseReason.WindowsShutDown) { + if (e.CloseReason == CloseReason.ApplicationExitCall || e.CloseReason == CloseReason.WindowsShutDown || e.CloseReason == CloseReason.TaskManagerClosing) { buttons = MessageBoxButtons.YesNo; } DialogResult result = MessageBox.Show(lang.GetString(LangKey.editor_close_on_save), lang.GetString(LangKey.editor_close_on_save_title), buttons, MessageBoxIcon.Question);