Gotten some files back, in the end they were referenced from the xaml

This commit is contained in:
Robin Krom 2022-10-25 22:28:45 +02:00
commit 52d122eb13
No known key found for this signature in database
GPG key ID: BCC01364F1371490
5 changed files with 176 additions and 92 deletions

View file

@ -0,0 +1,69 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2021 Thomas Braun, Jens Klingen, Robin Krom
*
* For more information see: https://getgreenshot.org/
* 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
* 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 <https://www.gnu.org/licenses/>.
*/
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace Greenshot.Editor.Controls.Emoji;
/// <summary>
/// This seems to enumerate multiple IEnumerables.
/// TODO: Replace this with LINQ
/// </summary>
/// <typeparam name="T"></typeparam>
internal sealed class ChunkHelper<T> : IEnumerable<IEnumerable<T>>
{
private readonly IEnumerable<T> _elements;
private readonly int _size;
private bool _hasMore;
public ChunkHelper(IEnumerable<T> elements, int size)
{
_elements = elements;
_size = size;
}
public IEnumerator<IEnumerable<T>> GetEnumerator()
{
using var enumerator = _elements.GetEnumerator();
_hasMore = enumerator.MoveNext();
while (_hasMore)
{
yield return GetNextBatch(enumerator).ToList();
}
}
private IEnumerable<T> GetNextBatch(IEnumerator<T> enumerator)
{
for (int i = 0; i < _size; ++i)
{
yield return enumerator.Current;
_hasMore = enumerator.MoveNext();
if (!_hasMore)
{
yield break;
}
}
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}

View file

@ -1,4 +1,4 @@
<StackPanel x:Class="Greenshot.Editor.Controls.EmojiPicker"
<StackPanel x:Class="Greenshot.Editor.Controls.Emoji.EmojiPicker"
x:Name="StackPanel_INTERNAL"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

View file

@ -17,28 +17,27 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using Greenshot.Editor.Controls.Emoji;
namespace Greenshot.Editor.Controls
namespace Greenshot.Editor.Controls.Emoji;
/// <summary>
/// The event which is created when the emoji is picked
/// </summary>
public class EmojiPickedEventArgs : EventArgs
{
/// <summary>
/// The event which is created when the emoji is picked
/// </summary>
public class EmojiPickedEventArgs : EventArgs
{
public EmojiPickedEventArgs() { }
public EmojiPickedEventArgs(string emoji) => Emoji = emoji;
public string Emoji;
}
}
public delegate void EmojiPickedEventHandler(object sender, EmojiPickedEventArgs e);
public delegate void EmojiPickedEventHandler(object sender, EmojiPickedEventArgs e);
/// <summary>
/// Interaction logic for Picker.xaml
/// </summary>
public partial class EmojiPicker : StackPanel
{
/// <summary>
/// Interaction logic for Picker.xaml
/// </summary>
public partial class EmojiPicker : StackPanel
{
public EmojiPicker()
{
InitializeComponent();
@ -78,8 +77,15 @@ namespace Greenshot.Editor.Controls
private void OnEmojiPicked(object sender, RoutedEventArgs e)
{
if (sender is not Control { DataContext: Emojis.Emoji emoji }) return;
if (emoji.Variations.Count != 0 && sender is not Button) return;
if (sender is not Control { DataContext: Emojis.Emoji emoji })
{
return;
}
if (emoji.Variations.Count != 0 && sender is not Button)
{
return;
}
Selection = emoji.Text;
Button_INTERNAL.IsChecked = false;
@ -125,5 +131,4 @@ namespace Greenshot.Editor.Controls
}
}
}
}
}

View file

@ -42,7 +42,11 @@ public class Emojis
[XmlElement(ElementName = "Emoji")]
public List<Emoji> Emojis { get; set; } = new();
public IEnumerable<IEnumerable<Emoji>> EmojiChunkList => new ChunkHelper<Emoji>(EmojiList, 8);
public string Icon => SubGroups.FirstOrDefault()?.Emojis.FirstOrDefault()?.Text;
public IEnumerable<Emoji> EmojiList => SubGroups.SelectMany(s => s.Emojis);
}
public class Emoji

View file

@ -26,7 +26,7 @@ using System.Windows.Forms;
using System.Windows.Forms.Integration;
using Greenshot.Base.Core;
using Greenshot.Base.Interfaces.Drawing;
using Greenshot.Editor.Controls;
using Greenshot.Editor.Controls.Emoji;
using Greenshot.Editor.Helpers;
using Image = System.Drawing.Image;
@ -95,7 +95,10 @@ namespace Greenshot.Editor.Drawing.Emoji
// Create one picker control by surface
// TODO: This is not ideal, as we need to controls from the surface, should replace this with a different solution.
_emojiPickerHost = _parent.Controls.Find("EmojiPickerHost", false).OfType<ElementHost>().FirstOrDefault();
if (_emojiPickerHost != null) return;
if (_emojiPickerHost != null)
{
return;
}
_emojiPicker = new EmojiPicker();
_emojiPicker.Picked += (_, args) =>
@ -136,7 +139,10 @@ namespace Greenshot.Editor.Drawing.Emoji
/// <param name="e">PropertyChangedEventArgs</param>
private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (!e.PropertyName.Equals(nameof(Selected))) return;
if (!e.PropertyName.Equals(nameof(Selected)))
{
return;
}
if (!Selected)
{