mirror of
https://github.com/greenshot/greenshot
synced 2025-08-22 14:24:43 -07:00
Gotten some files back, in the end they were referenced from the xaml
This commit is contained in:
parent
84be12b826
commit
52d122eb13
5 changed files with 176 additions and 92 deletions
69
src/Greenshot.Editor/Controls/Emoji/ChunkHelper.cs
Normal file
69
src/Greenshot.Editor/Controls/Emoji/ChunkHelper.cs
Normal 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();
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
<StackPanel x:Class="Greenshot.Editor.Controls.EmojiPicker"
|
<StackPanel x:Class="Greenshot.Editor.Controls.Emoji.EmojiPicker"
|
||||||
x:Name="StackPanel_INTERNAL"
|
x:Name="StackPanel_INTERNAL"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
|
|
@ -17,113 +17,118 @@ using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Controls.Primitives;
|
using System.Windows.Controls.Primitives;
|
||||||
using System.Windows.Input;
|
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>
|
public EmojiPickedEventArgs() { }
|
||||||
/// The event which is created when the emoji is picked
|
public EmojiPickedEventArgs(string emoji) => Emoji = emoji;
|
||||||
/// </summary>
|
|
||||||
public class EmojiPickedEventArgs : EventArgs
|
|
||||||
{
|
|
||||||
public EmojiPickedEventArgs() { }
|
|
||||||
public EmojiPickedEventArgs(string emoji) => Emoji = emoji;
|
|
||||||
|
|
||||||
public string Emoji;
|
public string Emoji;
|
||||||
|
}
|
||||||
|
|
||||||
|
public delegate void EmojiPickedEventHandler(object sender, EmojiPickedEventArgs e);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for Picker.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class EmojiPicker : StackPanel
|
||||||
|
{
|
||||||
|
public EmojiPicker()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public delegate void EmojiPickedEventHandler(object sender, EmojiPickedEventArgs e);
|
public IList<Emojis.Group> EmojiGroups => EmojiData.Data.Groups;
|
||||||
|
|
||||||
/// <summary>
|
// Backwards compatibility for when the backend was a TextBlock.
|
||||||
/// Interaction logic for Picker.xaml
|
public double FontSize
|
||||||
/// </summary>
|
|
||||||
public partial class EmojiPicker : StackPanel
|
|
||||||
{
|
{
|
||||||
public EmojiPicker()
|
get => Image.Height * 0.75;
|
||||||
|
set => Image.Height = value / 0.75;
|
||||||
|
}
|
||||||
|
|
||||||
|
public event PropertyChangedEventHandler SelectionChanged;
|
||||||
|
|
||||||
|
public event EmojiPickedEventHandler Picked;
|
||||||
|
|
||||||
|
private static void OnSelectionPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
|
||||||
|
{
|
||||||
|
(source as EmojiPicker)?.OnSelectionChanged(e.NewValue as string);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Selection
|
||||||
|
{
|
||||||
|
get => (string)GetValue(SelectionProperty);
|
||||||
|
set => SetValue(SelectionProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnSelectionChanged(string s)
|
||||||
|
{
|
||||||
|
var isDisabled = string.IsNullOrEmpty(s);
|
||||||
|
Image.Emoji = isDisabled ? "???" : s;
|
||||||
|
Image.Opacity = isDisabled ? 0.3 : 1.0;
|
||||||
|
SelectionChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Selection)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnEmojiPicked(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (sender is not Control { DataContext: Emojis.Emoji emoji })
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IList<Emojis.Group> EmojiGroups => EmojiData.Data.Groups;
|
if (emoji.Variations.Count != 0 && sender is not Button)
|
||||||
|
|
||||||
// Backwards compatibility for when the backend was a TextBlock.
|
|
||||||
public double FontSize
|
|
||||||
{
|
{
|
||||||
get => Image.Height * 0.75;
|
return;
|
||||||
set => Image.Height = value / 0.75;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public event PropertyChangedEventHandler SelectionChanged;
|
Selection = emoji.Text;
|
||||||
|
Button_INTERNAL.IsChecked = false;
|
||||||
|
e.Handled = true;
|
||||||
|
Picked?.Invoke(this, new EmojiPickedEventArgs(Selection));
|
||||||
|
}
|
||||||
|
|
||||||
public event EmojiPickedEventHandler Picked;
|
public static readonly DependencyProperty SelectionProperty = DependencyProperty.Register(
|
||||||
|
nameof(Selection), typeof(string), typeof(EmojiPicker),
|
||||||
|
new FrameworkPropertyMetadata("☺", OnSelectionPropertyChanged));
|
||||||
|
|
||||||
private static void OnSelectionPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
|
private void OnPopupKeyDown(object sender, KeyEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Key != Key.Escape || sender is not Popup popup) return;
|
||||||
|
popup.IsOpen = false;
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnPopupLoaded(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (sender is not Popup popup) return;
|
||||||
|
|
||||||
|
var child = popup.Child;
|
||||||
|
IInputElement oldFocus = null;
|
||||||
|
child.Focusable = true;
|
||||||
|
child.IsVisibleChanged += (o, ea) =>
|
||||||
{
|
{
|
||||||
(source as EmojiPicker)?.OnSelectionChanged(e.NewValue as string);
|
if (!child.IsVisible) return;
|
||||||
}
|
oldFocus = Keyboard.FocusedElement;
|
||||||
|
Keyboard.Focus(child);
|
||||||
|
};
|
||||||
|
|
||||||
public string Selection
|
popup.Closed += (o, ea) => Keyboard.Focus(oldFocus);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ShowPopup(bool show)
|
||||||
|
{
|
||||||
|
foreach (var child in Children)
|
||||||
{
|
{
|
||||||
get => (string)GetValue(SelectionProperty);
|
if (child is ToggleButton button)
|
||||||
set => SetValue(SelectionProperty, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnSelectionChanged(string s)
|
|
||||||
{
|
|
||||||
var isDisabled = string.IsNullOrEmpty(s);
|
|
||||||
Image.Emoji = isDisabled ? "???" : s;
|
|
||||||
Image.Opacity = isDisabled ? 0.3 : 1.0;
|
|
||||||
SelectionChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Selection)));
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
Selection = emoji.Text;
|
|
||||||
Button_INTERNAL.IsChecked = false;
|
|
||||||
e.Handled = true;
|
|
||||||
Picked?.Invoke(this, new EmojiPickedEventArgs(Selection));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static readonly DependencyProperty SelectionProperty = DependencyProperty.Register(
|
|
||||||
nameof(Selection), typeof(string), typeof(EmojiPicker),
|
|
||||||
new FrameworkPropertyMetadata("☺", OnSelectionPropertyChanged));
|
|
||||||
|
|
||||||
private void OnPopupKeyDown(object sender, KeyEventArgs e)
|
|
||||||
{
|
|
||||||
if (e.Key != Key.Escape || sender is not Popup popup) return;
|
|
||||||
popup.IsOpen = false;
|
|
||||||
e.Handled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnPopupLoaded(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
if (sender is not Popup popup) return;
|
|
||||||
|
|
||||||
var child = popup.Child;
|
|
||||||
IInputElement oldFocus = null;
|
|
||||||
child.Focusable = true;
|
|
||||||
child.IsVisibleChanged += (o, ea) =>
|
|
||||||
{
|
{
|
||||||
if (!child.IsVisible) return;
|
button.IsChecked = show;
|
||||||
oldFocus = Keyboard.FocusedElement;
|
|
||||||
Keyboard.Focus(child);
|
|
||||||
};
|
|
||||||
|
|
||||||
popup.Closed += (o, ea) => Keyboard.Focus(oldFocus);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ShowPopup(bool show)
|
|
||||||
{
|
|
||||||
foreach (var child in Children)
|
|
||||||
{
|
|
||||||
if (child is ToggleButton button)
|
|
||||||
{
|
|
||||||
button.IsChecked = show;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -42,7 +42,11 @@ public class Emojis
|
||||||
[XmlElement(ElementName = "Emoji")]
|
[XmlElement(ElementName = "Emoji")]
|
||||||
public List<Emoji> Emojis { get; set; } = new();
|
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 string Icon => SubGroups.FirstOrDefault()?.Emojis.FirstOrDefault()?.Text;
|
||||||
|
|
||||||
|
public IEnumerable<Emoji> EmojiList => SubGroups.SelectMany(s => s.Emojis);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Emoji
|
public class Emoji
|
||||||
|
|
|
@ -26,7 +26,7 @@ using System.Windows.Forms;
|
||||||
using System.Windows.Forms.Integration;
|
using System.Windows.Forms.Integration;
|
||||||
using Greenshot.Base.Core;
|
using Greenshot.Base.Core;
|
||||||
using Greenshot.Base.Interfaces.Drawing;
|
using Greenshot.Base.Interfaces.Drawing;
|
||||||
using Greenshot.Editor.Controls;
|
using Greenshot.Editor.Controls.Emoji;
|
||||||
using Greenshot.Editor.Helpers;
|
using Greenshot.Editor.Helpers;
|
||||||
using Image = System.Drawing.Image;
|
using Image = System.Drawing.Image;
|
||||||
|
|
||||||
|
@ -95,7 +95,10 @@ namespace Greenshot.Editor.Drawing.Emoji
|
||||||
// Create one picker control by surface
|
// 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.
|
// 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();
|
_emojiPickerHost = _parent.Controls.Find("EmojiPickerHost", false).OfType<ElementHost>().FirstOrDefault();
|
||||||
if (_emojiPickerHost != null) return;
|
if (_emojiPickerHost != null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_emojiPicker = new EmojiPicker();
|
_emojiPicker = new EmojiPicker();
|
||||||
_emojiPicker.Picked += (_, args) =>
|
_emojiPicker.Picked += (_, args) =>
|
||||||
|
@ -136,7 +139,10 @@ namespace Greenshot.Editor.Drawing.Emoji
|
||||||
/// <param name="e">PropertyChangedEventArgs</param>
|
/// <param name="e">PropertyChangedEventArgs</param>
|
||||||
private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
|
private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||||
{
|
{
|
||||||
if (!e.PropertyName.Equals(nameof(Selected))) return;
|
if (!e.PropertyName.Equals(nameof(Selected)))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!Selected)
|
if (!Selected)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue