Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions fluXis/Graphics/Containers/Markdown/FluXisMarkdownCodeBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,39 @@ namespace fluXis.Graphics.Containers.Markdown;
public partial class FluXisMarkdownCodeBlock : MarkdownCodeBlock
{
private FluXisMarkdown markdown { get; }
private CodeBlock codeBlock;
private FluXisMarkdownCopyButton copyButton;

public FluXisMarkdownCodeBlock(FluXisMarkdown markdown, [NotNull] CodeBlock codeBlock)
: base(codeBlock)
{
this.markdown = markdown;
this.codeBlock = codeBlock;
Margin = new MarginPadding { Bottom = 16 };
}

protected override void LoadComplete()
{
base.LoadComplete();

AddInternal
(
copyButton = new FluXisMarkdownCopyButton(codeBlock)
{
Alpha = 0,
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
}
);

Scheduler.AddDelayed(() =>
{
copyButton.Anchor = Anchor.TopRight;
copyButton.Origin = Anchor.TopRight;
copyButton.FadeTo(1f, 300, Easing.In);
}, 100);
}

protected override Drawable CreateBackground()
{
var container = new Container
Expand Down
98 changes: 98 additions & 0 deletions fluXis/Graphics/Containers/Markdown/FluXisMarkdownCopyButton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using osu.Framework.Platform;
using Markdig.Syntax;
using fluXis.Localization;
using fluXis.Graphics.Sprites.Icons;
using osu.Framework.Input.Events;
using osu.Framework.Allocation;
using fluXis.Overlay.Notifications;
using fluXis.Graphics.UserInterface.Buttons;
using osu.Framework.Graphics.Cursor;
using fluXis.Graphics.Sprites.Text;
using fluXis.Graphics.UserInterface.Text;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics;
using osuTK;
using fluXis.Overlay.Mouse;

namespace fluXis.Graphics.Containers.Markdown;

public partial class FluXisMarkdownCopyButton : IconButton, IHasCustomTooltip<FluXisMarkdownCopyButton>
{
[Resolved]
private Clipboard clipboard { get; set; }

[Resolved]
private NotificationManager notifications { get; set; }

private readonly CodeBlock codeBlock;
private readonly CopyButtonTooltip tooltip;

public FluXisMarkdownCopyButton TooltipContent => this;

public FluXisMarkdownCopyButton(CodeBlock codeBlock)
{
this.codeBlock = codeBlock;
tooltip = new CopyButtonTooltip();

Icon = FontAwesome6.Solid.Clipboard;
IconSize = 24;
ButtonSize = 46;
}

protected override bool OnClick(ClickEvent e)
{
clipboard.SetText(string.Join("\n", codeBlock.Lines));
notifications.SendSmallText("Copied text to Clipboard", FontAwesome6.Solid.Clipboard);
return base.OnClick(e);
}

public ITooltip<FluXisMarkdownCopyButton> GetCustomTooltip() => tooltip;

private partial class CopyButtonTooltip : CustomTooltipContainer<FluXisMarkdownCopyButton>
{
public CopyButtonTooltip()
{
Child = new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Margin = new MarginPadding { Horizontal = 10, Vertical = 6 },
Children = new Drawable[]
{
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(5),
Children = new Drawable[]
{
new FluXisSpriteIcon
{
Size = new Vector2(16),
Margin = new MarginPadding(4),
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Icon = FontAwesome6.Solid.Clipboard
},
new FluXisSpriteText
{
FontSize = 24,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = LocalizationStrings.General.CopyToClipboard
}
}
},
new FluXisTextFlow
{
AutoSizeAxes = Axes.Both,
FontSize = 18,
Text = LocalizationStrings.General.CopyToClipboardDescription
}
}
};
}

public override void SetContent(FluXisMarkdownCopyButton content) {} // Already set in constuctor so, this is pretty much implemented for the sake of it.
}
}
1 change: 1 addition & 0 deletions fluXis/Graphics/Sprites/Icons/FontAwesome6.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public static class Solid
public static IconUsage Images => GetSolid(0xf302);
public static IconUsage Info => GetSolid(0xf129);
public static IconUsage Keyboard => GetSolid(0xf11c);
public static IconUsage Clipboard => GetSolid(0xf328);
public static IconUsage LayerGroup => GetSolid(0xf5fd);
public static IconUsage LeftRight => GetSolid(0xf337);
public static IconUsage Link => GetSolid(0xf0c1);
Expand Down
3 changes: 3 additions & 0 deletions fluXis/Localization/Categories/GeneralStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ public class GeneralStrings : LocalizationCategory
public TranslatableString CanNotBeUndone => Get("can-not-be-undone", "This action cannot be undone.");

public TranslatableString LoginToUse => Get("login-to-use", "Log in to use this feature.");

public TranslatableString CopyToClipboard => Get("copy-clipboard", "Copy");
public TranslatableString CopyToClipboardDescription => Get("copy-clipboard-despcription", "Copy this to Clipboard.");
}
Loading