@@ -45,7 +45,7 @@ public partial class LayoutBar : UserControl
4545 private LayoutItem _lastSelectedItem ;
4646
4747 // Variables Drag & Drop
48- private Point _dragStart ;
48+ private Point ? _dragStart ;
4949 private bool _isDragging ;
5050 private LayoutItem _dragSource ;
5151
@@ -277,6 +277,18 @@ private void ReloadTabs(Document doc)
277277 } ) ;
278278 }
279279
280+ private static void ExpandLayoutItemGroup ( LayoutItem item , bool IsExpanded )
281+ {
282+ if ( item is LayoutTab tab && tab . IsInGroup && tab . ParentGroup is LayoutGroup gp )
283+ {
284+ gp . IsExpanded = IsExpanded ;
285+ }
286+ else if ( item is LayoutGroup gp2 )
287+ {
288+ gp2 . IsExpanded = IsExpanded ;
289+ }
290+ }
291+
280292 private bool TryCreateNewLayout ( string title )
281293 {
282294 if ( IsSyncing ) return false ;
@@ -303,7 +315,8 @@ private void Item_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
303315 {
304316 if ( ( sender as FrameworkElement ) ? . DataContext is LayoutItem clickedItem )
305317 {
306- _dragStart = e . GetPosition ( null ) ;
318+ _dragStart = e . GetPosition ( this ) ;
319+ Debug . WriteLine ( "_dragStart to " + _dragStart . ToString ( ) ) ;
307320 _dragSource = GetTabFromRegularList ( clickedItem ) ;
308321 _isDragging = false ;
309322 }
@@ -437,14 +450,15 @@ private List<LayoutItem> GetVisibleItemsList(bool IncludePinnedItems = true)
437450
438451 #region Drag & Drop
439452
440- protected override void OnPreviewMouseMove ( MouseEventArgs e )
453+ protected override void OnMouseMove ( MouseEventArgs e )
441454 {
442- base . OnPreviewMouseMove ( e ) ;
455+ base . OnMouseMove ( e ) ;
443456
444- if ( e . LeftButton == MouseButtonState . Pressed && ! _isDragging && _dragSource != null )
457+ if ( e . LeftButton == MouseButtonState . Pressed && ! _isDragging && _dragSource != null && _dragStart is Point dragStart )
445458 {
446- Vector diff = _dragStart - e . GetPosition ( null ) ;
447-
459+ Point currentPos = e . GetPosition ( this ) ;
460+ Vector diff = dragStart - currentPos ;
461+ Debug . WriteLine ( "check _dragStart + current pos " + currentPos ) ;
448462 if ( Math . Abs ( diff . X ) > DRAG_THRESHOLD || Math . Abs ( diff . Y ) > DRAG_THRESHOLD )
449463 {
450464 _isDragging = true ;
@@ -461,13 +475,9 @@ protected override void OnPreviewMouseMove(MouseEventArgs e)
461475 . ToList ( ) ;
462476
463477 //Close all groups for preview
464- foreach ( var item in selectedItems )
465- {
466- if ( item is LayoutTab tab && tab . IsInGroup && tab . ParentGroup is LayoutGroup gp )
467- {
468- gp . IsExpanded = false ;
469- }
470- }
478+ selectedItems . ForEach ( t => ExpandLayoutItemGroup ( t , false ) ) ;
479+
480+ Debug . WriteLine ( "CreatePreviewWindow" ) ;
471481 CreatePreviewWindow ( selectedItems ) ;
472482 _autoScrollTimer . Start ( ) ;
473483
@@ -870,6 +880,8 @@ private void TabContextMenu_Opened(object sender, RoutedEventArgs e)
870880 {
871881 if ( sender is ContextMenu menu && menu . PlacementTarget is FrameworkElement fe && fe . DataContext is LayoutTab tab )
872882 {
883+ _dragStart = null ; //avoid drag
884+ Debug . WriteLine ( "_dragStart to null" ) ;
873885 var targetTabs = GetTargetedTabsForContextMenu ( sender ) ;
874886
875887 foreach ( MenuItem menuItem in menu . Items . OfType < MenuItem > ( ) )
0 commit comments