Skip to content

Commit 0ae8219

Browse files
DYN-8326 - copy to clipboard button for warning bubble (#16304)
1 parent 4b6cbfa commit 0ae8219

11 files changed

Lines changed: 162 additions & 20 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ launchSettings.json
6767
# IDE #
6868
###############
6969
.idea
70+
.vscode/
7071

7172
#documentation files
7273
doc/html/

src/DynamoCoreWpf/Commands/InfoBubbleCommand.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Dynamo.UI.Commands;
1+
using Dynamo.UI.Commands;
22

33
namespace Dynamo.ViewModels
44
{
@@ -13,6 +13,17 @@ public partial class InfoBubbleViewModel : ViewModelBase
1313
private DelegateCommand openDocumentationLinkCommand;
1414
private DelegateCommand dismissMessageCommand;
1515
private DelegateCommand undismissMessageCommand;
16+
private DelegateCommand copyTextToClipboardCommand;
17+
18+
public DelegateCommand CopyTextToClipboardCommand
19+
{
20+
get
21+
{
22+
if (copyTextToClipboardCommand == null)
23+
copyTextToClipboardCommand = new DelegateCommand(CopyTextToClipboard, CanCopyTextToClipboard);
24+
return copyTextToClipboardCommand;
25+
}
26+
}
1627

1728
public DelegateCommand UpdateContentCommand
1829
{
@@ -127,4 +138,4 @@ public DelegateCommand UndismissMessageCommand
127138
}
128139
}
129140
}
130-
}
141+
}

src/DynamoCoreWpf/DynamoCoreWpf.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@
171171
<None Remove="UI\Images\close_16px.png" />
172172
<None Remove="UI\Images\caret_drop_down.png" />
173173
<None Remove="UI\Images\error_48px.png" />
174+
<None Remove="UI\Images\copy_16px_default.png" />
175+
<None Remove="UI\Images\copy_16px_hover.png" />
174176
<None Remove="UI\Images\file-generic-16px.png" />
175177
<None Remove="UI\Images\finished_checkmark_30px.png" />
176178
<None Remove="UI\Images\folder-generic-16px.png" />
@@ -1323,6 +1325,8 @@
13231325
<Resource Include="UI\Images\closetab_normal.png" />
13241326
<Resource Include="UI\Images\dynamonotext.png" />
13251327
<Resource Include="UI\Images\error_48px.png" />
1328+
<Resource Include="UI\Images\copy_16px_default.png" />
1329+
<Resource Include="UI\Images\copy_16px_hover.png" />
13261330
<Resource Include="UI\Images\file-generic-16px.png" />
13271331
<Resource Include="UI\Images\finished_checkmark_30px.png" />
13281332
<Resource Include="UI\Images\folder-generic-16px.png" />

src/DynamoCoreWpf/Properties/Resources.Designer.cs

Lines changed: 30 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/DynamoCoreWpf/Properties/Resources.en-US.resx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,12 @@ Don't worry, you'll have the option to save your work.</value>
447447
<data name="DownloadWarningMessageBoxTitle" xml:space="preserve">
448448
<value>Download Warning</value>
449449
</data>
450+
<data name="CopyToClipboardTooltip" xml:space="preserve">
451+
<value>Copy to clipboard</value>
452+
</data>
453+
<data name="CopyToClipboardFailedMessage" xml:space="preserve">
454+
<value>Copy to clipboard failed</value>
455+
</data>
450456
<data name="DynamoUpdateAvailableToolTip" xml:space="preserve">
451457
<value>A Dynamo update is available. Click to install.</value>
452458
</data>
@@ -4170,4 +4176,4 @@ To make this file into a new template, save it to a different folder, then move
41704176
<value>Node Icon Data is dumped to \"{0}\".</value>
41714177
<comment>Debug menu | Dump all node icons</comment>
41724178
</data>
4173-
</root>
4179+
</root>

src/DynamoCoreWpf/Properties/Resources.resx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,13 @@ Don't worry, you'll have the option to save your work.</value>
11261126
<data name="DownloadWarningMessageBoxTitle" xml:space="preserve">
11271127
<value>Download Warning</value>
11281128
</data>
1129-
<data name="DynamoUpdateAvailableToolTip" xml:space="preserve">
1129+
<data name="CopyToClipboardTooltip" xml:space="preserve">
1130+
<value>Copy to clipboard</value>
1131+
</data>
1132+
<data name="CopyToClipboardFailedMessage" xml:space="preserve">
1133+
<value>Copy to clipboard failed</value>
1134+
</data>
1135+
<data name="DynamoUpdateAvailableToolTip" xml:space="preserve">
11301136
<value>A Dynamo update is available. Click to install.</value>
11311137
</data>
11321138
<data name="EditNodeWindowTitle" xml:space="preserve">

src/DynamoCoreWpf/PublicAPI.Unshipped.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2362,6 +2362,7 @@ Dynamo.ViewModels.InfoBubbleViewModel.ConnectingDirection.get -> Dynamo.ViewMode
23622362
Dynamo.ViewModels.InfoBubbleViewModel.ConnectingDirection.set -> void
23632363
Dynamo.ViewModels.InfoBubbleViewModel.Content.get -> string
23642364
Dynamo.ViewModels.InfoBubbleViewModel.Content.set -> void
2365+
Dynamo.ViewModels.InfoBubbleViewModel.CopyTextToClipboardCommand.get -> Dynamo.UI.Commands.DelegateCommand
23652366
Dynamo.ViewModels.InfoBubbleViewModel.Direction
23662367
Dynamo.ViewModels.InfoBubbleViewModel.Direction.Bottom = 4 -> Dynamo.ViewModels.InfoBubbleViewModel.Direction
23672368
Dynamo.ViewModels.InfoBubbleViewModel.Direction.BottomLeft = 7 -> Dynamo.ViewModels.InfoBubbleViewModel.Direction
@@ -4618,6 +4619,8 @@ static Dynamo.Wpf.Properties.Resources.ContinueInstall.get -> string
46184619
static Dynamo.Wpf.Properties.Resources.ConverterMessageCurrentOffset.get -> string
46194620
static Dynamo.Wpf.Properties.Resources.ConverterMessageTransformOrigin.get -> string
46204621
static Dynamo.Wpf.Properties.Resources.ConverterMessageZoom.get -> string
4622+
static Dynamo.Wpf.Properties.Resources.CopyToClipboardTooltip.get -> string
4623+
static Dynamo.Wpf.Properties.Resources.CopyToClipboardFailedMessage.get -> string
46214624
static Dynamo.Wpf.Properties.Resources.CrashPromptDialogCopyButton.get -> string
46224625
static Dynamo.Wpf.Properties.Resources.CrashPromptDialogCrashMessage.get -> string
46234626
static Dynamo.Wpf.Properties.Resources.CrashPromptDialogDetailButton.get -> string
213 Bytes
Loading
208 Bytes
Loading

src/DynamoCoreWpf/ViewModels/Preview/InfoBubbleViewModel.cs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
using System.Linq;
55
using System.Text.RegularExpressions;
66
using System.Windows;
7+
using System.Windows.Input;
78
using Dynamo.Logging;
9+
using Dynamo.UI.Commands;
810
using Dynamo.Wpf.ViewModels.Core;
911

1012
namespace Dynamo.ViewModels
@@ -65,7 +67,7 @@ public enum State
6567
// In order to stay above these, we need a high ZIndex value.
6668
private double zIndex;
6769
private Style infoBubbleStyle;
68-
70+
6971
[Obsolete]
7072
public Direction connectingDirection;
7173

@@ -506,6 +508,39 @@ private void InitializeInfoBubble(DynamoViewModel dynamoViewModel)
506508

507509
RefreshNodeInformationalStateDisplay();
508510
}
511+
512+
/// <summary>
513+
/// Copies the text of an info bubble message to the clipboard
514+
/// </summary>
515+
/// <param name="parameter">The InfoBubbleDataPacket to copy</param>
516+
private void CopyTextToClipboard(object parameter)
517+
{
518+
if (parameter is InfoBubbleDataPacket infoBubbleDataPacket)
519+
{
520+
try
521+
{
522+
System.Windows.Clipboard.SetText(infoBubbleDataPacket.Text);
523+
Analytics.TrackEvent(Actions.Copy, Categories.NodeOperations,
524+
infoBubbleDataPacket.Style.ToString(), 1);
525+
}
526+
catch (Exception ex)
527+
{
528+
DynamoViewModel.Model.Logger.Log(Wpf.Properties.Resources.CopyToClipboardFailedMessage);
529+
DynamoViewModel.Model.Logger.Log(ex.Message);
530+
}
531+
}
532+
}
533+
534+
/// <summary>
535+
/// Determines if a message can be copied to clipboard
536+
/// </summary>
537+
/// <param name="parameter">The InfoBubbleDataPacket to check</param>
538+
/// <returns>True if the message can be copied</returns>
539+
private bool CanCopyTextToClipboard(object parameter)
540+
{
541+
return parameter is InfoBubbleDataPacket infoBubbleDataPacket &&
542+
!string.IsNullOrEmpty(infoBubbleDataPacket.Text);
543+
}
509544

510545
#endregion
511546

0 commit comments

Comments
 (0)