mirror of
https://github.com/greenshot/greenshot
synced 2025-08-14 10:47:02 -07:00
Previous changes created problems with the context-menu, as it was still referencing an icon that we dispose at icon size change. This change introduces a PropertyChanged event object to the CoreConfiguration so those interested can register to changes (currently only the IconSize), and apply the correct menu image.
This commit is contained in:
parent
61c2921b2a
commit
e0c9fc1f7b
5 changed files with 96 additions and 66 deletions
|
@ -388,7 +388,8 @@ namespace Greenshot {
|
|||
}
|
||||
SoundHelper.Initialize();
|
||||
|
||||
MainForm.ResetImageScalingSize();
|
||||
coreConfiguration.PropertyChanged += OnIconSizeChanged;
|
||||
OnIconSizeChanged(this, new PropertyChangedEventArgs("IconSize"));
|
||||
|
||||
// Set the Greenshot icon visibility depending on the configuration. (Added for feature #3521446)
|
||||
// Setting it to true this late prevents Problems with the context menu
|
||||
|
@ -552,12 +553,14 @@ namespace Greenshot {
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset ImageScalingSize
|
||||
/// Fix icon reference
|
||||
/// </summary>
|
||||
/// <returns>Used for fixing scaling issues</returns>
|
||||
public static void ResetImageScalingSize() {
|
||||
MainForm thisForm = MainForm.Instance;
|
||||
thisForm.contextMenu.ImageScalingSize = coreConfiguration.IconSize;
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void OnIconSizeChanged(object sender, PropertyChangedEventArgs e) {
|
||||
if (e.PropertyName == "IconSize") {
|
||||
contextMenu.ImageScalingSize = coreConfiguration.IconSize;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -368,7 +368,6 @@ namespace Greenshot {
|
|||
|
||||
numericUpDown_daysbetweencheck.Value = coreConfiguration.UpdateCheckInterval;
|
||||
numericUpDown_daysbetweencheck.Enabled = !coreConfiguration.Values["UpdateCheckInterval"].IsFixed;
|
||||
coreConfiguration.FixIconSize();
|
||||
numericUpdownIconSize.Value = (coreConfiguration.IconSize.Width /16) * 16;
|
||||
CheckDestinationSettings();
|
||||
}
|
||||
|
@ -417,12 +416,6 @@ namespace Greenshot {
|
|||
Size previousValue = coreConfiguration.IconSize;
|
||||
coreConfiguration.IconSize = new Size((int)numericUpdownIconSize.Value, (int)numericUpdownIconSize.Value);
|
||||
|
||||
// Clear caches when changing the settings
|
||||
if (previousValue != coreConfiguration.IconSize) {
|
||||
PluginUtils.ClearExeIconCache();
|
||||
MainForm.ResetImageScalingSize();
|
||||
}
|
||||
coreConfiguration.FixIconSize();
|
||||
try {
|
||||
if (checkbox_autostartshortcut.Checked) {
|
||||
// It's checked, so we set the RunUser if the RunAll isn't set.
|
||||
|
|
|
@ -24,6 +24,7 @@ using Greenshot.Plugin;
|
|||
using GreenshotPlugin.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
|
@ -33,6 +34,7 @@ namespace ExternalCommand {
|
|||
/// </summary>
|
||||
public class ExternalCommandPlugin : IGreenshotPlugin {
|
||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ExternalCommandPlugin));
|
||||
private static CoreConfiguration coreConfig = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
private static ExternalCommandConfiguration config = IniConfig.GetIniSection<ExternalCommandConfiguration>();
|
||||
private IGreenshotHost host;
|
||||
private PluginAttribute myAttributes;
|
||||
|
@ -121,24 +123,36 @@ namespace ExternalCommand {
|
|||
|
||||
|
||||
itemPlugInRoot = new ToolStripMenuItem();
|
||||
itemPlugInRoot.Text = Language.GetString("externalcommand", "contextmenu_configure");
|
||||
itemPlugInRoot.Tag = host;
|
||||
try {
|
||||
string exePath = PluginUtils.GetExePath("cmd.exe");
|
||||
if (exePath != null && File.Exists(exePath)) {
|
||||
itemPlugInRoot.Image = PluginUtils.GetCachedExeIcon(exePath, 0);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LOG.Warn("Couldn't get the cmd.exe image", ex);
|
||||
}
|
||||
OnIconSizeChanged(this, new PropertyChangedEventArgs("IconSize"));
|
||||
OnLanguageChanged(this, null);
|
||||
itemPlugInRoot.Click += new System.EventHandler(ConfigMenuClick);
|
||||
|
||||
PluginUtils.AddToContextMenu(host, itemPlugInRoot);
|
||||
Language.LanguageChanged += new LanguageChangedHandler(OnLanguageChanged);
|
||||
Language.LanguageChanged += OnLanguageChanged;
|
||||
coreConfig.PropertyChanged += OnIconSizeChanged;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void OnLanguageChanged(object sender, EventArgs e) {
|
||||
/// <summary>
|
||||
/// Fix icon reference
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void OnIconSizeChanged(object sender, PropertyChangedEventArgs e) {
|
||||
if (e.PropertyName == "IconSize") {
|
||||
try {
|
||||
string exePath = PluginUtils.GetExePath("cmd.exe");
|
||||
if (exePath != null && File.Exists(exePath)) {
|
||||
itemPlugInRoot.Image = PluginUtils.GetCachedExeIcon(exePath, 0);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LOG.Warn("Couldn't get the cmd.exe image", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnLanguageChanged(object sender, EventArgs e) {
|
||||
if (itemPlugInRoot != null) {
|
||||
itemPlugInRoot.Text = Language.GetString("externalcommand", "contextmenu_configure");
|
||||
}
|
||||
|
|
|
@ -18,14 +18,16 @@
|
|||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using Greenshot.IniFile;
|
||||
using Greenshot.Plugin;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace GreenshotPlugin.Core {
|
||||
public enum ClipboardFormat {
|
||||
|
@ -56,7 +58,9 @@ namespace GreenshotPlugin.Core {
|
|||
/// Description of CoreConfiguration.
|
||||
/// </summary>
|
||||
[IniSection("Core", Description="Greenshot core configuration")]
|
||||
public class CoreConfiguration : IniSection {
|
||||
public class CoreConfiguration : IniSection, INotifyPropertyChanged {
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
[IniProperty("Language", Description = "The language in IETF format (e.g. en-US)")]
|
||||
public string Language;
|
||||
|
||||
|
@ -256,8 +260,36 @@ namespace GreenshotPlugin.Core {
|
|||
[IniProperty("LastCapturedRegion", Description = "The last used region, for reuse in the capture last region")]
|
||||
public Rectangle LastCapturedRegion;
|
||||
|
||||
private Size _iconSize;
|
||||
[IniProperty("IconSize", Description = "Defines the size of the icons (e.g. for the buttons in the editor), default value 16,16 anything bigger will cause scaling", DefaultValue = "16,16")]
|
||||
public Size IconSize;
|
||||
public Size IconSize {
|
||||
get {
|
||||
return _iconSize;
|
||||
}
|
||||
set {
|
||||
Size newSize = value;
|
||||
if (newSize != Size.Empty) {
|
||||
if (newSize.Width < 16) {
|
||||
newSize.Width = 16;
|
||||
} else if (newSize.Width > 256) {
|
||||
newSize.Width = 256;
|
||||
}
|
||||
newSize.Width = (newSize.Width / 16) * 16;
|
||||
if (newSize.Height < 16) {
|
||||
newSize.Height = 16;
|
||||
} else if (IconSize.Height > 256) {
|
||||
newSize.Height = 256;
|
||||
}
|
||||
newSize.Height = (newSize.Height / 16) * 16;
|
||||
}
|
||||
if (_iconSize != newSize) {
|
||||
_iconSize = value;
|
||||
if (PropertyChanged != null) {
|
||||
PropertyChanged(this, new PropertyChangedEventArgs("IconSize"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Specifies what THIS build is
|
||||
public BuildStates BuildState = BuildStates.RELEASE_CANDIDATE;
|
||||
|
@ -441,32 +473,7 @@ namespace GreenshotPlugin.Core {
|
|||
if (OutputFileReduceColorsTo > 256) {
|
||||
OutputFileReduceColorsTo = 256;
|
||||
}
|
||||
FixIconSize();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validation & correction of the icon size
|
||||
/// </summary>
|
||||
public void FixIconSize() {
|
||||
if (IconSize == Size.Empty) {
|
||||
IconSize = new Size(16, 16);
|
||||
} else {
|
||||
if (IconSize.Width < 16) {
|
||||
IconSize.Width = 16;
|
||||
}
|
||||
if (IconSize.Width > 256) {
|
||||
IconSize.Width = 256;
|
||||
}
|
||||
IconSize.Width = (IconSize.Width / 16) * 16;
|
||||
if (IconSize.Height < 16) {
|
||||
IconSize.Height = 16;
|
||||
}
|
||||
if (IconSize.Height > 256) {
|
||||
IconSize.Height = 256;
|
||||
}
|
||||
IconSize.Height = (IconSize.Height/16)*16;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,6 +26,7 @@ using log4net;
|
|||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
@ -40,6 +41,10 @@ namespace GreenshotPlugin.Core {
|
|||
private const string PATH_KEY = @"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\";
|
||||
private static IDictionary<string, Image> exeIconCache = new Dictionary<string, Image>();
|
||||
|
||||
static PluginUtils() {
|
||||
conf.PropertyChanged += OnIconSizeChanged;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Simple global property to get the Greenshot host
|
||||
/// </summary>
|
||||
|
@ -48,18 +53,26 @@ namespace GreenshotPlugin.Core {
|
|||
set;
|
||||
}
|
||||
|
||||
public static void ClearExeIconCache() {
|
||||
List<Image> cachedImages = new List<Image>();
|
||||
lock (exeIconCache) {
|
||||
foreach (string key in exeIconCache.Keys) {
|
||||
cachedImages.Add(exeIconCache[key]);
|
||||
/// <summary>
|
||||
/// Clear icon cache
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private static void OnIconSizeChanged(object sender, PropertyChangedEventArgs e) {
|
||||
if (e.PropertyName == "IconSize") {
|
||||
List<Image> cachedImages = new List<Image>();
|
||||
lock (exeIconCache) {
|
||||
foreach (string key in exeIconCache.Keys) {
|
||||
cachedImages.Add(exeIconCache[key]);
|
||||
}
|
||||
exeIconCache.Clear();
|
||||
}
|
||||
exeIconCache.Clear();
|
||||
}
|
||||
foreach (Image cachedImage in cachedImages) {
|
||||
if (cachedImage != null) {
|
||||
cachedImage.Dispose();
|
||||
foreach (Image cachedImage in cachedImages) {
|
||||
if (cachedImage != null) {
|
||||
cachedImage.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue