From 018324d4c45a5bfcad223b10d8f4bd7588e4b060 Mon Sep 17 00:00:00 2001 From: RKrom Date: Tue, 2 Dec 2014 16:51:07 +0100 Subject: [PATCH] BUG-1709: Suggestion for StringAlignment conversion issue. --- .../Fields/Binding/AlignmentConverter.cs | 89 ------------------- Greenshot/Drawing/SpeechbubbleContainer.cs | 4 +- Greenshot/Drawing/TextContainer.cs | 4 +- Greenshot/Forms/ImageEditorForm.Designer.cs | 20 ++--- Greenshot/Forms/ImageEditorForm.cs | 4 +- 5 files changed, 16 insertions(+), 105 deletions(-) delete mode 100644 Greenshot/Drawing/Fields/Binding/AlignmentConverter.cs diff --git a/Greenshot/Drawing/Fields/Binding/AlignmentConverter.cs b/Greenshot/Drawing/Fields/Binding/AlignmentConverter.cs deleted file mode 100644 index 64becc974..000000000 --- a/Greenshot/Drawing/Fields/Binding/AlignmentConverter.cs +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Greenshot - a free and open source screenshot tool - * Copyright (C) 2007-2014 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 . - */ -using Greenshot.Plugin; -using System; -using System.Drawing; -using System.Windows.Forms; - -namespace Greenshot.Drawing.Fields.Binding { - /// - /// Converting horizontal alignment to its StringAlignment representation and vice versa. - /// Beware: there's currently no RTL support. - /// - public class HorizontalAlignmentConverter : AbstractBindingConverter { - - private static HorizontalAlignmentConverter uniqueInstance; - - protected override HorizontalAlignment convert(StringAlignment stringAlignment) { - switch(stringAlignment) { - case StringAlignment.Near: return HorizontalAlignment.Left; - case StringAlignment.Center: return HorizontalAlignment.Center; - case StringAlignment.Far: return HorizontalAlignment.Right; - default: throw new NotImplementedException("Cannot handle: "+ stringAlignment); - } - } - - protected override StringAlignment convert(HorizontalAlignment horizontalAligment) { - switch(horizontalAligment) { - case HorizontalAlignment.Left: return StringAlignment.Near; - case HorizontalAlignment.Center: return StringAlignment.Center; - case HorizontalAlignment.Right: return StringAlignment.Far; - default: throw new NotImplementedException("Cannot handle: "+ horizontalAligment); - } - } - - public static HorizontalAlignmentConverter GetInstance() { - if(uniqueInstance == null) uniqueInstance = new HorizontalAlignmentConverter(); - return uniqueInstance; - } - } - - /// - /// Converting vertical alignment to its StringAlignment representation and vice versa. - /// - public class VerticalAlignmentConverter : AbstractBindingConverter { - - private static VerticalAlignmentConverter uniqueInstance; - - protected override VerticalAlignment convert(StringAlignment stringAlignment) { - switch(stringAlignment) { - case StringAlignment.Near: return VerticalAlignment.TOP; - case StringAlignment.Center: return VerticalAlignment.CENTER; - case StringAlignment.Far: return VerticalAlignment.BOTTOM; - default: throw new NotImplementedException("Cannot handle: "+ stringAlignment); - } - } - - protected override StringAlignment convert(VerticalAlignment verticalAligment) { - switch(verticalAligment) { - case VerticalAlignment.TOP: return StringAlignment.Near; - case VerticalAlignment.CENTER: return StringAlignment.Center; - case VerticalAlignment.BOTTOM: return StringAlignment.Far; - default: throw new NotImplementedException("Cannot handle: "+ verticalAligment); - } - } - - public static VerticalAlignmentConverter GetInstance() { - if(uniqueInstance == null) uniqueInstance = new VerticalAlignmentConverter(); - return uniqueInstance; - } - } -} diff --git a/Greenshot/Drawing/SpeechbubbleContainer.cs b/Greenshot/Drawing/SpeechbubbleContainer.cs index 9741a06bd..c263f86c2 100644 --- a/Greenshot/Drawing/SpeechbubbleContainer.cs +++ b/Greenshot/Drawing/SpeechbubbleContainer.cs @@ -81,8 +81,8 @@ namespace Greenshot.Drawing { AddField(GetType(), FieldType.FILL_COLOR, Color.White); AddField(GetType(), FieldType.FONT_FAMILY, FontFamily.GenericSansSerif.Name); AddField(GetType(), FieldType.FONT_SIZE, 20f); - AddField(GetType(), FieldType.TEXT_HORIZONTAL_ALIGNMENT, HorizontalAlignment.Center); - AddField(GetType(), FieldType.TEXT_VERTICAL_ALIGNMENT, VerticalAlignment.CENTER); + AddField(GetType(), FieldType.TEXT_HORIZONTAL_ALIGNMENT, StringAlignment.Center); + AddField(GetType(), FieldType.TEXT_VERTICAL_ALIGNMENT, StringAlignment.Center); } /// diff --git a/Greenshot/Drawing/TextContainer.cs b/Greenshot/Drawing/TextContainer.cs index 46a9dd4ef..1ab7b62b5 100644 --- a/Greenshot/Drawing/TextContainer.cs +++ b/Greenshot/Drawing/TextContainer.cs @@ -97,8 +97,8 @@ namespace Greenshot.Drawing { AddField(GetType(), FieldType.FILL_COLOR, Color.Transparent); AddField(GetType(), FieldType.FONT_FAMILY, FontFamily.GenericSansSerif.Name); AddField(GetType(), FieldType.FONT_SIZE, 11f); - AddField(GetType(), FieldType.TEXT_HORIZONTAL_ALIGNMENT, HorizontalAlignment.Center); - AddField(GetType(), FieldType.TEXT_VERTICAL_ALIGNMENT, VerticalAlignment.CENTER); + AddField(GetType(), FieldType.TEXT_HORIZONTAL_ALIGNMENT, StringAlignment.Center); + AddField(GetType(), FieldType.TEXT_VERTICAL_ALIGNMENT, StringAlignment.Center); } [OnDeserialized] diff --git a/Greenshot/Forms/ImageEditorForm.Designer.cs b/Greenshot/Forms/ImageEditorForm.Designer.cs index 908333836..10398447f 100644 --- a/Greenshot/Forms/ImageEditorForm.Designer.cs +++ b/Greenshot/Forms/ImageEditorForm.Designer.cs @@ -1254,8 +1254,8 @@ namespace Greenshot { this.textVerticalAlignmentButton.ImageTransparentColor = System.Drawing.Color.Magenta; this.textVerticalAlignmentButton.LanguageKey = "editor_align_vertical"; this.textVerticalAlignmentButton.Name = "textVerticalAlignmentButton"; - this.textVerticalAlignmentButton.SelectedTag = System.Windows.Forms.HorizontalAlignment.Center; - this.textVerticalAlignmentButton.Tag = Greenshot.Plugin.VerticalAlignment.CENTER; + this.textVerticalAlignmentButton.SelectedTag = System.Drawing.StringAlignment.Center; + this.textVerticalAlignmentButton.Tag = System.Drawing.StringAlignment.Center; // // alignTopToolStripMenuItem // @@ -1263,7 +1263,7 @@ namespace Greenshot { this.alignTopToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("btnAlignTop.Image"))); this.alignTopToolStripMenuItem.LanguageKey = "editor_align_top"; this.alignTopToolStripMenuItem.Name = "alignTopToolStripMenuItem"; - this.alignTopToolStripMenuItem.Tag = Greenshot.Plugin.VerticalAlignment.TOP; + this.alignTopToolStripMenuItem.Tag = System.Drawing.StringAlignment.Near; // // alignMiddleToolStripMenuItem // @@ -1271,7 +1271,7 @@ namespace Greenshot { this.alignMiddleToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("btnAlignMiddle.Image"))); this.alignMiddleToolStripMenuItem.LanguageKey = "editor_align_middle"; this.alignMiddleToolStripMenuItem.Name = "alignMiddleToolStripMenuItem"; - this.alignMiddleToolStripMenuItem.Tag = Greenshot.Plugin.VerticalAlignment.CENTER; + this.alignMiddleToolStripMenuItem.Tag = System.Drawing.StringAlignment.Center; // // alignBottomToolStripMenuItem // @@ -1279,7 +1279,7 @@ namespace Greenshot { this.alignBottomToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("btnAlignBottom.Image"))); this.alignBottomToolStripMenuItem.LanguageKey = "editor_align_bottom"; this.alignBottomToolStripMenuItem.Name = "alignBottomToolStripMenuItem"; - this.alignBottomToolStripMenuItem.Tag = Greenshot.Plugin.VerticalAlignment.BOTTOM; + this.alignBottomToolStripMenuItem.Tag = System.Drawing.StringAlignment.Far; // // blurRadiusLabel // @@ -1575,8 +1575,8 @@ namespace Greenshot { this.textHorizontalAlignmentButton.ImageTransparentColor = System.Drawing.Color.Magenta; this.textHorizontalAlignmentButton.LanguageKey = "editor_align_horizontal"; this.textHorizontalAlignmentButton.Name = "textHorizontalAlignmentButton"; - this.textHorizontalAlignmentButton.SelectedTag = System.Windows.Forms.HorizontalAlignment.Center; - this.textHorizontalAlignmentButton.Tag = System.Windows.Forms.HorizontalAlignment.Center; + this.textHorizontalAlignmentButton.SelectedTag = System.Drawing.StringAlignment.Center; + this.textHorizontalAlignmentButton.Tag = System.Drawing.StringAlignment.Center; // // alignLeftToolStripMenuItem // @@ -1584,7 +1584,7 @@ namespace Greenshot { this.alignLeftToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("btnAlignLeft.Image"))); this.alignLeftToolStripMenuItem.LanguageKey = "editor_align_left"; this.alignLeftToolStripMenuItem.Name = "alignLeftToolStripMenuItem"; - this.alignLeftToolStripMenuItem.Tag = System.Windows.Forms.HorizontalAlignment.Left; + this.alignLeftToolStripMenuItem.Tag = System.Drawing.StringAlignment.Near; // // alignCenterToolStripMenuItem // @@ -1592,7 +1592,7 @@ namespace Greenshot { this.alignCenterToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("btnAlignCenter.Image"))); this.alignCenterToolStripMenuItem.LanguageKey = "editor_align_center"; this.alignCenterToolStripMenuItem.Name = "alignCenterToolStripMenuItem"; - this.alignCenterToolStripMenuItem.Tag = System.Windows.Forms.HorizontalAlignment.Center; + this.alignCenterToolStripMenuItem.Tag = System.Drawing.StringAlignment.Center; // // alignRightToolStripMenuItem // @@ -1600,7 +1600,7 @@ namespace Greenshot { this.alignRightToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("btnAlignRight.Image"))); this.alignRightToolStripMenuItem.LanguageKey = "editor_align_right"; this.alignRightToolStripMenuItem.Name = "alignRightToolStripMenuItem"; - this.alignRightToolStripMenuItem.Tag = System.Windows.Forms.HorizontalAlignment.Right; + this.alignRightToolStripMenuItem.Tag = System.Drawing.StringAlignment.Far; // // ImageEditorForm // diff --git a/Greenshot/Forms/ImageEditorForm.cs b/Greenshot/Forms/ImageEditorForm.cs index c54676d9b..f5f09e565 100644 --- a/Greenshot/Forms/ImageEditorForm.cs +++ b/Greenshot/Forms/ImageEditorForm.cs @@ -998,8 +998,8 @@ namespace Greenshot { new BidirectionalBinding(fontSizeUpDown, "Value", surface.FieldAggregator.GetField(FieldType.FONT_SIZE), "Value", DecimalFloatConverter.GetInstance(), NotNullValidator.GetInstance()); new BidirectionalBinding(fontBoldButton, "Checked", surface.FieldAggregator.GetField(FieldType.FONT_BOLD), "Value", NotNullValidator.GetInstance()); new BidirectionalBinding(fontItalicButton, "Checked", surface.FieldAggregator.GetField(FieldType.FONT_ITALIC), "Value", NotNullValidator.GetInstance()); - new BidirectionalBinding(textHorizontalAlignmentButton, "SelectedTag", surface.FieldAggregator.GetField(FieldType.TEXT_HORIZONTAL_ALIGNMENT), "Value", HorizontalAlignmentConverter.GetInstance(), NotNullValidator.GetInstance()); - new BidirectionalBinding(textVerticalAlignmentButton, "SelectedTag", surface.FieldAggregator.GetField(FieldType.TEXT_VERTICAL_ALIGNMENT), "Value", VerticalAlignmentConverter.GetInstance(), NotNullValidator.GetInstance()); + new BidirectionalBinding(textHorizontalAlignmentButton, "SelectedTag", surface.FieldAggregator.GetField(FieldType.TEXT_HORIZONTAL_ALIGNMENT), "Value", NotNullValidator.GetInstance()); + new BidirectionalBinding(textVerticalAlignmentButton, "SelectedTag", surface.FieldAggregator.GetField(FieldType.TEXT_VERTICAL_ALIGNMENT), "Value", NotNullValidator.GetInstance()); new BidirectionalBinding(shadowButton, "Checked", surface.FieldAggregator.GetField(FieldType.SHADOW), "Value", NotNullValidator.GetInstance()); new BidirectionalBinding(previewQualityUpDown, "Value", surface.FieldAggregator.GetField(FieldType.PREVIEW_QUALITY), "Value", DecimalDoublePercentageConverter.GetInstance(), NotNullValidator.GetInstance()); new BidirectionalBinding(obfuscateModeButton, "SelectedTag", surface.FieldAggregator.GetField(FieldType.PREPARED_FILTER_OBFUSCATE), "Value");