File tree Expand file tree Collapse file tree 3 files changed +24
-4
lines changed Expand file tree Collapse file tree 3 files changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -1375,7 +1375,9 @@ public bool ContainsUrl
13751375 }
13761376 private string GetUrlFromSelectedComment ( )
13771377 {
1378- var selectedComment = SelectedComment ;
1378+ // CopyComment と同じ理由
1379+ var commentDataGrid = GetActiveWindowContextAsCommentDataGrid ( ) ;
1380+ var selectedComment = commentDataGrid . SelectedComment ;
13791381 if ( selectedComment == null )
13801382 {
13811383 return null ;
@@ -1401,14 +1403,27 @@ private void OpenUrl()
14011403 }
14021404 private void CopyComment ( )
14031405 {
1404- var message = SelectedComment . MessageItems . ToText ( ) ;
1406+ // 本当はこのModel (this) が CommentDataGridViewModelBase を継承しているのでこんなのは不要だが
1407+ // CommentDataGrid 用のコードが UserView に無いのでこうなっている (中途半端な共通化の埋め合わせ)
1408+ var commentDataGrid = GetActiveWindowContextAsCommentDataGrid ( ) ;
1409+
1410+ var message = commentDataGrid . SelectedComment . MessageItems . ToText ( ) ;
14051411 try
14061412 {
14071413 System . Windows . Clipboard . SetText ( message ) ;
14081414 }
14091415 catch ( System . Runtime . InteropServices . COMException ) { }
14101416 SetSystemInfo ( "copy: " + message , InfoType . Debug ) ;
14111417 }
1418+
1419+ private static CommentDataGridViewModelBase GetActiveWindowContextAsCommentDataGrid ( )
1420+ {
1421+ var activeWindow = Application . Current . Windows
1422+ . OfType < Window > ( )
1423+ . SingleOrDefault ( x => x . IsActive ) ;
1424+
1425+ return activeWindow . DataContext as CommentDataGridViewModelBase ;
1426+ }
14121427 #region ConnectionsView
14131428 #region ConnectionsViewSelection
14141429 public int ConnectionsViewSelectionDisplayIndex
Original file line number Diff line number Diff line change 6060 <SolidColorBrush x : Key =" {x:Static SystemColors.HighlightTextBrushKey}" Color =" {Binding SelectedRowForeColor}" />
6161 <SolidColorBrush x : Key =" {x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color =" {Binding SelectedRowBackColor}" />
6262 <SolidColorBrush x : Key =" {x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}" Color =" {Binding SelectedRowForeColor}" />
63- <ContextMenu x : Key =" commentContext" DataContext = " {Binding DataContext, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}} " >
63+ <ContextMenu x : Key =" commentContext" Opened = " ContextMenu_Opened " >
6464 <MenuItem Header =" コメントをコピー" Command =" {Binding CommentCopyCommand}" />
6565 <MenuItem Header =" URLを開く" Command =" {Binding OpenUrlCommand}" />
6666 <MenuItem Header =" 日本語に翻訳する" Command =" {Binding TranslateCommand}" />
Original file line number Diff line number Diff line change @@ -46,7 +46,12 @@ await _dispatcher.BeginInvoke((Action)(() =>
4646 } ;
4747 }
4848
49-
49+ private void ContextMenu_Opened ( object sender , RoutedEventArgs e )
50+ {
51+ if ( sender is ContextMenu contextMenu ) {
52+ contextMenu . DataContext = Application . Current . MainWindow . DataContext ;
53+ }
54+ }
5055
5156 public bool IsShowUserInfoMenuItem
5257 {
You can’t perform that action at this time.
0 commit comments