Skip to content
Merged
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
19 changes: 17 additions & 2 deletions MultiCommentViewer/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,9 @@ public bool ContainsUrl
}
private string GetUrlFromSelectedComment()
{
var selectedComment = SelectedComment;
// CopyComment と同じ理由
var commentDataGrid = GetActiveWindowContextAsCommentDataGrid();
var selectedComment = commentDataGrid.SelectedComment;
if (selectedComment == null)
{
return null;
Expand All @@ -1401,14 +1403,27 @@ private void OpenUrl()
}
private void CopyComment()
{
var message = SelectedComment.MessageItems.ToText();
// 本当はこのModel (this) が CommentDataGridViewModelBase を継承しているのでこんなのは不要だが
// CommentDataGrid 用のコードが UserView に無いのでこうなっている (中途半端な共通化の埋め合わせ)
var commentDataGrid = GetActiveWindowContextAsCommentDataGrid();

var message = commentDataGrid.SelectedComment.MessageItems.ToText();
try
{
System.Windows.Clipboard.SetText(message);
}
catch (System.Runtime.InteropServices.COMException) { }
SetSystemInfo("copy: " + message, InfoType.Debug);
}

private static CommentDataGridViewModelBase GetActiveWindowContextAsCommentDataGrid()
{
var activeWindow = Application.Current.Windows
.OfType<Window>()
.SingleOrDefault(x => x.IsActive);

return activeWindow.DataContext as CommentDataGridViewModelBase;
}
#region ConnectionsView
#region ConnectionsViewSelection
public int ConnectionsViewSelectionDisplayIndex
Expand Down
2 changes: 1 addition & 1 deletion MultiCommentViewer/Views/CommentDataGrid.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="{Binding SelectedRowForeColor}" />
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="{Binding SelectedRowBackColor}"/>
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}" Color="{Binding SelectedRowForeColor}"/>
<ContextMenu x:Key="commentContext" DataContext="{Binding DataContext, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}">
<ContextMenu x:Key="commentContext" Opened="ContextMenu_Opened">
<MenuItem Header="コメントをコピー" Command="{Binding CommentCopyCommand}" />
<MenuItem Header="URLを開く" Command="{Binding OpenUrlCommand}" />
<MenuItem Header="日本語に翻訳する" Command="{Binding TranslateCommand}" />
Expand Down
7 changes: 6 additions & 1 deletion MultiCommentViewer/Views/CommentDataGrid.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ await _dispatcher.BeginInvoke((Action)(() =>
};
}


private void ContextMenu_Opened(object sender, RoutedEventArgs e)
{
if (sender is ContextMenu contextMenu) {
contextMenu.DataContext = Application.Current.MainWindow.DataContext;
}
}

public bool IsShowUserInfoMenuItem
{
Expand Down