From 57e4a8dd73f6deac02c97f83ee39fc51ba5d150a Mon Sep 17 00:00:00 2001 From: RKrom Date: Fri, 7 Dec 2012 16:31:20 +0000 Subject: [PATCH] Cleanup of the AboutForm, changed the Style to a "FixedToolWindow", I find this more professional. Changed the AnimatingForm to have a flag, EnableAnimation, which is false by default and makes it possible to make the Form the base form of all GreenshotForm forms. Renamed the conf -> coreConfiguration, as this is already in the base class. Also added some comments. git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2367 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4 --- Greenshot/Forms/AboutForm.Designer.cs | 2 +- Greenshot/Forms/AboutForm.cs | 35 +++++++++++++++-------- Greenshot/Forms/CaptureForm.cs | 3 ++ Greenshot/Forms/ImageEditorForm.cs | 16 +++++------ Greenshot/Forms/MainForm.cs | 33 ++++++++++++++++++++- Greenshot/Forms/PrintOptionsDialog.cs | 4 +-- Greenshot/Forms/SettingsForm.cs | 1 - GreenshotPlugin/Controls/AnimatingForm.cs | 19 ++++++++---- GreenshotPlugin/Controls/GreenshotForm.cs | 9 +++++- 9 files changed, 89 insertions(+), 33 deletions(-) diff --git a/Greenshot/Forms/AboutForm.Designer.cs b/Greenshot/Forms/AboutForm.Designer.cs index 2d0cfc2ec..7f8f529a7 100644 --- a/Greenshot/Forms/AboutForm.Designer.cs +++ b/Greenshot/Forms/AboutForm.Designer.cs @@ -211,7 +211,7 @@ namespace Greenshot { this.Controls.Add(this.lblHost); this.Controls.Add(this.lblLicense); this.Controls.Add(this.lblTitle); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; this.LanguageKey = "about_title"; this.MaximizeBox = false; this.MinimizeBox = false; diff --git a/Greenshot/Forms/AboutForm.cs b/Greenshot/Forms/AboutForm.cs index 0af809860..dbc33998c 100644 --- a/Greenshot/Forms/AboutForm.cs +++ b/Greenshot/Forms/AboutForm.cs @@ -30,7 +30,7 @@ using Greenshot.IniFile; namespace Greenshot { /// - /// Description of AboutForm. + /// The about form /// public partial class AboutForm : BaseForm { private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(AboutForm)); @@ -39,31 +39,42 @@ namespace Greenshot { // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); - this.Icon = GreenshotPlugin.Core.GreenshotResources.getGreenshotIcon(); + // Not needed for a Tool Window: + //this.Icon = GreenshotPlugin.Core.GreenshotResources.getGreenshotIcon(); this.pictureBox1.Image = GreenshotPlugin.Core.GreenshotResources.getGreenshotImage(); Version v = Assembly.GetExecutingAssembly().GetName().Version; // Format is like this: AssemblyVersion("Major.Minor.Build.Revision")] lblTitle.Text = "Greenshot " + v.Major + "." + v.Minor + "." + v.Build + " Build " + v.Revision + (IniConfig.IsPortable?" Portable":"") + (" (" + OSInfo.Bits +" bit)"); } + /// + /// This is called when a link is clicked + /// + /// + /// void LinkLabelClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e) { - openLink((LinkLabel)sender); - } - - private void openLink(LinkLabel link) { - try { - link.LinkVisited = true; - System.Diagnostics.Process.Start(link.Text); - } catch (Exception) { - MessageBox.Show(Language.GetFormattedString(LangKey.error_openlink, link.Text), Language.GetString(LangKey.error)); + LinkLabel linkLabel = sender as LinkLabel; + if (linkLabel != null) { + try { + linkLabel.LinkVisited = true; + System.Diagnostics.Process.Start(linkLabel.Text); + } catch (Exception) { + MessageBox.Show(Language.GetFormattedString(LangKey.error_openlink, linkLabel.Text), Language.GetString(LangKey.error)); + } } } + /// + /// CmdKey handler + /// + /// + /// + /// protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { try { switch (keyData) { case Keys.Escape: - DialogResult = DialogResult.Cancel; + DialogResult = DialogResult.Cancel; break; case Keys.E: MessageBox.Show(EnvironmentInfo.EnvironmentToString(true)); diff --git a/Greenshot/Forms/CaptureForm.cs b/Greenshot/Forms/CaptureForm.cs index 2bb917d9d..098cb0a9d 100644 --- a/Greenshot/Forms/CaptureForm.cs +++ b/Greenshot/Forms/CaptureForm.cs @@ -127,6 +127,9 @@ namespace Greenshot.Forms { } currentForm = this; + // Enable the AnimatingForm + EnableAnimation = true; + // Using 32bppPArgb speeds up the drawing. //capturedImage = ImageHelper.Clone(capture.Image, PixelFormat.Format32bppPArgb); // comment the clone, uncomment the assignment and the original bitmap is used. diff --git a/Greenshot/Forms/ImageEditorForm.cs b/Greenshot/Forms/ImageEditorForm.cs index ebdb37107..935a93e3b 100644 --- a/Greenshot/Forms/ImageEditorForm.cs +++ b/Greenshot/Forms/ImageEditorForm.cs @@ -47,10 +47,8 @@ namespace Greenshot { /// Description of ImageEditorForm. /// public partial class ImageEditorForm : BaseForm, IImageEditor { - private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ImageEditorForm)); private static EditorConfiguration editorConfiguration = IniConfig.GetIniSection(); - private static CoreConfiguration coreConf = IniConfig.GetIniSection(); private static List ignoreDestinations = new List() {PickerDestination.DESIGNATION, EditorDestination.DESIGNATION}; private static List editorList = new List(); @@ -161,10 +159,10 @@ namespace Greenshot { this.Icon = GreenshotPlugin.Core.GreenshotResources.getGreenshotIcon(); // Disable access to the settings, for feature #3521446 - preferencesToolStripMenuItem.Visible = !coreConf.DisableSettings; - toolStripSeparator12.Visible = !coreConf.DisableSettings; - toolStripSeparator11.Visible = !coreConf.DisableSettings; - btnSettings.Visible = !coreConf.DisableSettings; + preferencesToolStripMenuItem.Visible = !coreConfiguration.DisableSettings; + toolStripSeparator12.Visible = !coreConfiguration.DisableSettings; + toolStripSeparator11.Visible = !coreConfiguration.DisableSettings; + btnSettings.Visible = !coreConfiguration.DisableSettings; // Make sure Double-buffer is enabled SetStyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true); @@ -655,7 +653,7 @@ namespace Greenshot { } void AboutToolStripMenuItemClick(object sender, System.EventArgs e) { - new AboutForm().Show(); + new AboutForm().ShowDialog(this); } void PreferencesToolStripMenuItemClick(object sender, System.EventArgs e) { @@ -1096,7 +1094,7 @@ namespace Greenshot { void SaveElementsToolStripMenuItemClick(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Greenshot templates (*.gst)|*.gst"; - saveFileDialog.FileName = FilenameHelper.GetFilenameWithoutExtensionFromPattern(coreConf.OutputFileFilenamePattern, surface.CaptureDetails); + saveFileDialog.FileName = FilenameHelper.GetFilenameWithoutExtensionFromPattern(coreConfiguration.OutputFileFilenamePattern, surface.CaptureDetails); DialogResult dialogResult = saveFileDialog.ShowDialog(); if(dialogResult.Equals(DialogResult.OK)) { using (Stream streamWrite = File.OpenWrite(saveFileDialog.FileName)) { @@ -1173,7 +1171,7 @@ namespace Greenshot { } windowToCapture = CaptureHelper.SelectCaptureWindow(windowToCapture); if (windowToCapture != null) { - capture = CaptureHelper.CaptureWindow(windowToCapture, capture, coreConf.WindowCaptureMode); + capture = CaptureHelper.CaptureWindow(windowToCapture, capture, coreConfiguration.WindowCaptureMode); this.Activate(); WindowDetails.ToForeground(this.Handle); if (capture!= null && capture.Image != null) { diff --git a/Greenshot/Forms/MainForm.cs b/Greenshot/Forms/MainForm.cs index 1821b7fa3..fd7561192 100644 --- a/Greenshot/Forms/MainForm.cs +++ b/Greenshot/Forms/MainForm.cs @@ -897,18 +897,31 @@ namespace Greenshot { }); } + /// + /// Context menu entry "Support Greenshot" + /// + /// + /// void Contextmenu_donateClick(object sender, EventArgs e) { BeginInvoke((MethodInvoker)delegate { Process.Start("http://getgreenshot.org/support/"); }); } + /// + /// Context menu entry "Preferences" + /// + /// + /// void Contextmenu_settingsClick(object sender, EventArgs e) { BeginInvoke((MethodInvoker)delegate { ShowSetting(); }); } + /// + /// This is called indirectly from the context menu "Preferences" + /// public void ShowSetting() { if (settingsForm != null) { WindowDetails.ToForeground(settingsForm.Handle); @@ -925,13 +938,18 @@ namespace Greenshot { } } + /// + /// The "About Greenshot" entry is clicked + /// + /// + /// void Contextmenu_aboutClick(object sender, EventArgs e) { if (aboutForm != null) { WindowDetails.ToForeground(aboutForm.Handle); } else { try { using (aboutForm = new AboutForm()) { - aboutForm.ShowDialog(); + aboutForm.ShowDialog(this); } } finally { aboutForm = null; @@ -939,14 +957,27 @@ namespace Greenshot { } } + /// + /// The "Help" entry is clicked + /// + /// + /// void Contextmenu_helpClick(object sender, EventArgs e) { HelpFileLoader.LoadHelp(); } + /// + /// The "Exit" entry is clicked + /// + /// + /// void Contextmenu_exitClick(object sender, EventArgs e) { Exit(); } + /// + /// This needs to be called to initialize the quick settings menu entries + /// private void InitializeQuickSettingsMenu() { this.contextmenu_quicksettings.DropDownItems.Clear(); diff --git a/Greenshot/Forms/PrintOptionsDialog.cs b/Greenshot/Forms/PrintOptionsDialog.cs index 531fd71aa..839018965 100644 --- a/Greenshot/Forms/PrintOptionsDialog.cs +++ b/Greenshot/Forms/PrintOptionsDialog.cs @@ -29,8 +29,6 @@ namespace Greenshot.Forms { /// Description of PrintOptionsDialog. /// public partial class PrintOptionsDialog : BaseForm { - private static CoreConfiguration conf = IniConfig.GetIniSection(); - public PrintOptionsDialog() { // // The InitializeComponent() call is required for Windows Forms designer support. @@ -43,7 +41,7 @@ namespace Greenshot.Forms { void Button_okClick(object sender, EventArgs e) { // update config - conf.OutputPrintPromptOptions = !this.checkbox_dontaskagain.Checked; + coreConfiguration.OutputPrintPromptOptions = !this.checkbox_dontaskagain.Checked; IniConfig.Save(); DialogResult = DialogResult.OK; } diff --git a/Greenshot/Forms/SettingsForm.cs b/Greenshot/Forms/SettingsForm.cs index 3d465271c..27176272a 100644 --- a/Greenshot/Forms/SettingsForm.cs +++ b/Greenshot/Forms/SettingsForm.cs @@ -41,7 +41,6 @@ namespace Greenshot { /// public partial class SettingsForm : BaseForm { private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(SettingsForm)); - private static CoreConfiguration coreConfiguration = IniConfig.GetIniSection(); private static EditorConfiguration editorConfiguration = IniConfig.GetIniSection(); private ToolTip toolTip = new ToolTip(); private bool inHotkey = false; diff --git a/GreenshotPlugin/Controls/AnimatingForm.cs b/GreenshotPlugin/Controls/AnimatingForm.cs index 9f9efe1c3..cc689d0c6 100644 --- a/GreenshotPlugin/Controls/AnimatingForm.cs +++ b/GreenshotPlugin/Controls/AnimatingForm.cs @@ -33,6 +33,14 @@ namespace GreenshotPlugin.Controls { private int vRefresh = 0; private Timer timer = null; + /// + /// This flag specifies if any animation is used + /// + protected bool EnableAnimation { + get; + set; + } + /// /// Vertical Refresh Rate /// @@ -74,12 +82,13 @@ namespace GreenshotPlugin.Controls { /// Initialize the animation /// protected AnimatingForm() { - timer = new Timer(); - timer.Interval = 1000 / VRefresh; - timer.Tick += new EventHandler(timer_Tick); - this.Load += delegate { - timer.Start(); + if (EnableAnimation) { + timer = new Timer(); + timer.Interval = 1000 / VRefresh; + timer.Tick += new EventHandler(timer_Tick); + timer.Start(); + } }; // Unregister at close diff --git a/GreenshotPlugin/Controls/GreenshotForm.cs b/GreenshotPlugin/Controls/GreenshotForm.cs index fa6b4c528..886b6827f 100644 --- a/GreenshotPlugin/Controls/GreenshotForm.cs +++ b/GreenshotPlugin/Controls/GreenshotForm.cs @@ -30,7 +30,7 @@ using System.ComponentModel.Design; using System.IO; namespace GreenshotPlugin.Controls { - public abstract class GreenshotForm : Form, IGreenshotLanguageBindable { + public abstract class GreenshotForm : AnimatingForm, IGreenshotLanguageBindable { private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(GreenshotForm)); private static IDictionary reflectionCache = new Dictionary(); private IComponentChangeService m_changeService; @@ -64,6 +64,13 @@ namespace GreenshotPlugin.Controls { } } + /// + /// Normally a Greenshot form doesn't animate + /// + protected override void Animate() { + throw new NotImplementedException(); + } + /// /// Code to initialize the language etc during design time ///