mirror of
https://github.com/greenshot/greenshot
synced 2025-08-20 13:33:27 -07:00
Added language binding support to ToolStripItem, also changed the behavior to use the name of the component if no language key is set.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1807 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
e687450dfc
commit
83a033ebd0
7 changed files with 281 additions and 184 deletions
|
@ -15,6 +15,7 @@ namespace GreenshotPlugin.Controls {
|
|||
private IComponentChangeService m_changeService;
|
||||
private bool isLanguageSet = false;
|
||||
private IDictionary<string, Control> designTimeControls;
|
||||
private IDictionary<string, ToolStripItem> designTimeToolStripItems;
|
||||
[Category("Greenshot"), DefaultValue(null), Description("Specifies key of the language file to use when displaying the text.")]
|
||||
public string LanguageKey {
|
||||
get;
|
||||
|
@ -27,6 +28,7 @@ namespace GreenshotPlugin.Controls {
|
|||
protected void InitializeForDesigner() {
|
||||
if (this.DesignMode) {
|
||||
designTimeControls = new Dictionary<string, Control>();
|
||||
designTimeToolStripItems = new Dictionary<string, ToolStripItem>();
|
||||
try {
|
||||
ITypeResolutionService typeResService = GetService(typeof(ITypeResolutionService)) as ITypeResolutionService;
|
||||
Assembly currentAssembly = this.GetType().Assembly;
|
||||
|
@ -138,7 +140,19 @@ namespace GreenshotPlugin.Controls {
|
|||
private void OnComponentChanged(object sender, ComponentChangedEventArgs ce) {
|
||||
if (ce.Component != null && ((IComponent)ce.Component).Site != null && ce.Member != null) {
|
||||
if ("LanguageKey".Equals(ce.Member.Name)) {
|
||||
ApplyLanguage(ce.Component as Control, (string)ce.NewValue);
|
||||
Control control = ce.Component as Control;
|
||||
if (control != null) {
|
||||
LOG.InfoFormat("Changing LanguageKey for {0} to {1}", control.Name, ce.NewValue);
|
||||
ApplyLanguage(control, (string)ce.NewValue);
|
||||
} else {
|
||||
ToolStripItem item = ce.Component as ToolStripItem;
|
||||
if (item != null) {
|
||||
LOG.InfoFormat("Changing LanguageKey for {0} to {1}", item.Name, ce.NewValue);
|
||||
ApplyLanguage(item, (string)ce.NewValue);
|
||||
} else {
|
||||
LOG.InfoFormat("Not possible to changing LanguageKey for {0} to {1}", ce.Component.GetType(), ce.NewValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -152,6 +166,13 @@ namespace GreenshotPlugin.Controls {
|
|||
} else {
|
||||
designTimeControls[control.Name] = control;
|
||||
}
|
||||
} else if (ce.Component is ToolStripItem) {
|
||||
ToolStripItem item = ce.Component as ToolStripItem;
|
||||
if (!designTimeControls.ContainsKey(item.Name)) {
|
||||
designTimeToolStripItems.Add(item.Name, item);
|
||||
} else {
|
||||
designTimeToolStripItems[item.Name] = item;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -164,9 +185,47 @@ namespace GreenshotPlugin.Controls {
|
|||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
protected void ApplyLanguage(ToolStripItem applyTo, string languageKey) {
|
||||
if (!string.IsNullOrEmpty(languageKey)) {
|
||||
if (!Language.hasKey(languageKey)) {
|
||||
LOG.WarnFormat("Wrong language key '{0}' configured for control '{1}'", languageKey, applyTo.Name);
|
||||
if (DesignMode) {
|
||||
MessageBox.Show(string.Format("Wrong language key '{0}' configured for control '{1}'", languageKey, applyTo.Name));
|
||||
}
|
||||
return;
|
||||
}
|
||||
applyTo.Text = Language.GetString(languageKey);
|
||||
} else {
|
||||
// Fallback to control name!
|
||||
if (Language.hasKey(applyTo.Name)) {
|
||||
applyTo.Text = Language.GetString(applyTo.Name);
|
||||
return;
|
||||
}
|
||||
if (this.DesignMode) {
|
||||
MessageBox.Show(string.Format("Greenshot control without language key: {0}", applyTo.Name));
|
||||
} else {
|
||||
LOG.DebugFormat("Greenshot control without language key: {0}", applyTo.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void ApplyLanguage(ToolStripItem applyTo) {
|
||||
IGreenshotLanguageBindable languageBindable = applyTo as IGreenshotLanguageBindable;
|
||||
if (languageBindable != null) {
|
||||
ApplyLanguage(applyTo, languageBindable.LanguageKey);
|
||||
}
|
||||
}
|
||||
|
||||
protected void ApplyLanguage(Control applyTo) {
|
||||
IGreenshotLanguageBindable languageBindable = applyTo as IGreenshotLanguageBindable;
|
||||
if (languageBindable == null) {
|
||||
// check if it's a menu!
|
||||
if (applyTo is ToolStrip) {
|
||||
ToolStrip toolStrip = applyTo as ToolStrip;
|
||||
foreach (ToolStripItem item in toolStrip.Items) {
|
||||
ApplyLanguage(item);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -222,6 +281,9 @@ namespace GreenshotPlugin.Controls {
|
|||
foreach (Control designControl in designTimeControls.Values) {
|
||||
ApplyLanguage(designControl);
|
||||
}
|
||||
foreach (ToolStripItem designToolStripItem in designTimeToolStripItems.Values) {
|
||||
ApplyLanguage(designToolStripItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -237,6 +299,11 @@ namespace GreenshotPlugin.Controls {
|
|||
}
|
||||
applyTo.Text = Language.GetString(languageKey);
|
||||
} else {
|
||||
// Fallback to control name!
|
||||
if (Language.hasKey(applyTo.Name)) {
|
||||
applyTo.Text = Language.GetString(applyTo.Name);
|
||||
return;
|
||||
}
|
||||
if (this.DesignMode) {
|
||||
MessageBox.Show(string.Format("Greenshot control without language key: {0}", applyTo.Name));
|
||||
} else {
|
||||
|
|
33
GreenshotPlugin/Controls/GreenshotToolStripMenuItem.cs
Normal file
33
GreenshotPlugin/Controls/GreenshotToolStripMenuItem.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom
|
||||
*
|
||||
* For more information see: http://getgreenshot.org/
|
||||
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 1 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* 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.ComponentModel;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace GreenshotPlugin.Controls {
|
||||
public class GreenshotToolStripMenuItem : ToolStripMenuItem, IGreenshotLanguageBindable {
|
||||
[Category("Greenshot"), DefaultValue(null), Description("Specifies key of the language file to use when displaying the text.")]
|
||||
public string LanguageKey {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue