mirror of
https://github.com/greenshot/greenshot
synced 2025-08-20 13:33:27 -07:00
Made the re/undo code from the branch work in this, this is a manual copy as something went horribly wrong with the repository. Before building I first want to check if everything is there.[skip ci]
This commit is contained in:
parent
9702ac730f
commit
45615275cf
35 changed files with 1890 additions and 922 deletions
|
@ -3,7 +3,7 @@
|
|||
* Copyright (C) 2007-2015 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/
|
||||
* The Greenshot project is hosted on GitHub https://github.com/greenshot/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
|
||||
|
@ -19,14 +19,18 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Greenshot.Configuration;
|
||||
using Greenshot.IniFile;
|
||||
using Greenshot.Plugin;
|
||||
using Greenshot.Plugin.Drawing;
|
||||
using GreenshotPlugin.Interfaces;
|
||||
using GreenshotPlugin.Interfaces.Drawing;
|
||||
using log4net;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
|
||||
using Greenshot.Configuration;
|
||||
using Greenshot.IniFile;
|
||||
using Greenshot.Plugin.Drawing;
|
||||
|
||||
namespace Greenshot.Drawing.Fields {
|
||||
namespace Greenshot.Drawing.Fields
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the current set of properties for the editor.
|
||||
/// When one of EditorProperties' properties is updated, the change will be promoted
|
||||
|
@ -38,35 +42,47 @@ namespace Greenshot.Drawing.Fields {
|
|||
/// Properties that do not apply for ALL selected elements are null (or 0 respectively)
|
||||
/// If the property values of the selected elements differ, the value of the last bound element wins.
|
||||
/// </summary>
|
||||
public class FieldAggregator : AbstractFieldHolder {
|
||||
|
||||
private readonly List<IDrawableContainer> boundContainers;
|
||||
private bool internalUpdateRunning;
|
||||
public class FieldAggregator : AbstractFieldHolder
|
||||
{
|
||||
|
||||
private static readonly EditorConfiguration editorConfiguration = IniConfig.GetIniSection<EditorConfiguration>();
|
||||
private IDrawableContainerList boundContainers;
|
||||
private bool internalUpdateRunning = false;
|
||||
|
||||
public FieldAggregator() {
|
||||
foreach(FieldType fieldType in FieldType.Values) {
|
||||
enum Status { IDLE, BINDING, UPDATING };
|
||||
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(FieldAggregator));
|
||||
private static EditorConfiguration editorConfiguration = IniConfig.GetIniSection<EditorConfiguration>();
|
||||
|
||||
public FieldAggregator(ISurface parent)
|
||||
{
|
||||
foreach (FieldType fieldType in FieldType.Values)
|
||||
{
|
||||
Field field = new Field(fieldType, GetType());
|
||||
AddField(field);
|
||||
}
|
||||
boundContainers = new List<IDrawableContainer>();
|
||||
boundContainers = new DrawableContainerList();
|
||||
boundContainers.Parent = parent;
|
||||
}
|
||||
|
||||
public override void AddField(Field field) {
|
||||
|
||||
public override void AddField(IField field)
|
||||
{
|
||||
base.AddField(field);
|
||||
field.PropertyChanged += OwnPropertyChanged;
|
||||
}
|
||||
|
||||
public void BindElements(DrawableContainerList dcs) {
|
||||
foreach(DrawableContainer dc in dcs) {
|
||||
|
||||
public void BindElements(IDrawableContainerList dcs)
|
||||
{
|
||||
foreach (DrawableContainer dc in dcs)
|
||||
{
|
||||
BindElement(dc);
|
||||
}
|
||||
}
|
||||
|
||||
public void BindElement(IDrawableContainer dc) {
|
||||
public void BindElement(IDrawableContainer dc)
|
||||
{
|
||||
DrawableContainer container = dc as DrawableContainer;
|
||||
if (container != null && !boundContainers.Contains(container)) {
|
||||
if (container != null && !boundContainers.Contains(container))
|
||||
{
|
||||
boundContainers.Add(container);
|
||||
container.ChildrenChanged += delegate {
|
||||
UpdateFromBoundElements();
|
||||
|
@ -74,101 +90,126 @@ namespace Greenshot.Drawing.Fields {
|
|||
UpdateFromBoundElements();
|
||||
}
|
||||
}
|
||||
|
||||
public void BindAndUpdateElement(IDrawableContainer dc) {
|
||||
|
||||
public void BindAndUpdateElement(IDrawableContainer dc)
|
||||
{
|
||||
UpdateElement(dc);
|
||||
BindElement(dc);
|
||||
}
|
||||
|
||||
public void UpdateElement(IDrawableContainer dc) {
|
||||
|
||||
public void UpdateElement(IDrawableContainer dc)
|
||||
{
|
||||
DrawableContainer container = dc as DrawableContainer;
|
||||
if (container == null) {
|
||||
if (container == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
internalUpdateRunning = true;
|
||||
foreach(Field field in GetFields()) {
|
||||
if (container.HasField(field.FieldType) && field.HasValue) {
|
||||
foreach (Field field in GetFields())
|
||||
{
|
||||
if (container.HasField(field.FieldType) && field.HasValue)
|
||||
{
|
||||
//if(LOG.IsDebugEnabled) LOG.Debug(" "+field+ ": "+field.Value);
|
||||
container.SetFieldValue(field.FieldType, field.Value);
|
||||
}
|
||||
}
|
||||
internalUpdateRunning = false;
|
||||
}
|
||||
|
||||
public void UnbindElement(IDrawableContainer dc) {
|
||||
if (boundContainers.Contains(dc)) {
|
||||
|
||||
public void UnbindElement(IDrawableContainer dc)
|
||||
{
|
||||
if (boundContainers.Contains(dc))
|
||||
{
|
||||
boundContainers.Remove(dc);
|
||||
UpdateFromBoundElements();
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear() {
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
ClearFields();
|
||||
boundContainers.Clear();
|
||||
boundContainers.Clear();
|
||||
UpdateFromBoundElements();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// sets all field values to null, however does not remove fields
|
||||
/// </summary>
|
||||
private void ClearFields() {
|
||||
private void ClearFields()
|
||||
{
|
||||
internalUpdateRunning = true;
|
||||
foreach(Field field in GetFields()) {
|
||||
foreach (Field field in GetFields())
|
||||
{
|
||||
field.Value = null;
|
||||
}
|
||||
internalUpdateRunning = false;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Updates this instance using the respective fields from the bound elements.
|
||||
/// Fields that do not apply to every bound element are set to null, or 0 respectively.
|
||||
/// All other fields will be set to the field value of the least bound element.
|
||||
/// </summary>
|
||||
private void UpdateFromBoundElements() {
|
||||
private void UpdateFromBoundElements()
|
||||
{
|
||||
ClearFields();
|
||||
internalUpdateRunning = true;
|
||||
foreach(Field field in FindCommonFields()) {
|
||||
foreach (Field field in FindCommonFields())
|
||||
{
|
||||
SetFieldValue(field.FieldType, field.Value);
|
||||
}
|
||||
internalUpdateRunning = false;
|
||||
}
|
||||
|
||||
private List<Field> FindCommonFields() {
|
||||
List<Field> returnFields = null;
|
||||
if (boundContainers.Count > 0) {
|
||||
|
||||
private IList<IField> FindCommonFields()
|
||||
{
|
||||
IList<IField> returnFields = null;
|
||||
if (boundContainers.Count > 0)
|
||||
{
|
||||
// take all fields from the least selected container...
|
||||
DrawableContainer leastSelectedContainer = boundContainers[boundContainers.Count - 1] as DrawableContainer;
|
||||
if (leastSelectedContainer != null) {
|
||||
if (leastSelectedContainer != null)
|
||||
{
|
||||
returnFields = leastSelectedContainer.GetFields();
|
||||
for (int i = 0; i < boundContainers.Count - 1; i++) {
|
||||
for (int i = 0; i < boundContainers.Count - 1; i++)
|
||||
{
|
||||
DrawableContainer dc = boundContainers[i] as DrawableContainer;
|
||||
if (dc != null) {
|
||||
List<Field> fieldsToRemove = new List<Field>();
|
||||
foreach (Field f in returnFields) {
|
||||
if (dc != null)
|
||||
{
|
||||
IList<IField> fieldsToRemove = new List<IField>();
|
||||
foreach (IField field in returnFields)
|
||||
{
|
||||
// ... throw out those that do not apply to one of the other containers
|
||||
if (!dc.HasField(f.FieldType)) {
|
||||
fieldsToRemove.Add(f);
|
||||
if (!dc.HasField(field.FieldType))
|
||||
{
|
||||
fieldsToRemove.Add(field);
|
||||
}
|
||||
}
|
||||
foreach (Field f in fieldsToRemove) {
|
||||
returnFields.Remove(f);
|
||||
foreach (IField field in fieldsToRemove)
|
||||
{
|
||||
returnFields.Remove(field);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (returnFields == null) {
|
||||
returnFields = new List<Field>();
|
||||
if (returnFields == null)
|
||||
{
|
||||
returnFields = new List<IField>();
|
||||
}
|
||||
return returnFields;
|
||||
}
|
||||
|
||||
public void OwnPropertyChanged(object sender, PropertyChangedEventArgs ea) {
|
||||
Field field = (Field) sender;
|
||||
if (!internalUpdateRunning && field.Value != null) {
|
||||
foreach(DrawableContainer drawableContainer in boundContainers) {
|
||||
if (drawableContainer.HasField(field.FieldType)) {
|
||||
Field drawableContainerField = drawableContainer.GetField(field.FieldType);
|
||||
|
||||
public void OwnPropertyChanged(object sender, PropertyChangedEventArgs ea)
|
||||
{
|
||||
IField field = (IField)sender;
|
||||
if (!internalUpdateRunning && field.Value != null)
|
||||
{
|
||||
foreach (DrawableContainer drawableContainer in boundContainers)
|
||||
{
|
||||
if (drawableContainer.HasField(field.FieldType))
|
||||
{
|
||||
IField drawableContainerField = drawableContainer.GetField(field.FieldType);
|
||||
// Notify before change, so we can e.g. invalidate the area
|
||||
drawableContainer.BeforeFieldChange(drawableContainerField, field.Value);
|
||||
|
||||
|
@ -180,5 +221,5 @@ namespace Greenshot.Drawing.Fields {
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue