Skip to content

Commit 7bdf1e4

Browse files
committed
Fix drag issue
1 parent 2ba0c21 commit 7bdf1e4

3 files changed

Lines changed: 40 additions & 21 deletions

File tree

SioForgeCAD/Forms/LayoutBar.xaml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@
207207
Height="28"
208208
Cursor="Hand"
209209
MouseLeftButtonDown="Item_MouseLeftButtonDown"
210-
ToolTipOpening="Item_ToolTipOpening"
211-
MouseLeftButtonUp="Item_MouseLeftButtonUp">
210+
MouseLeftButtonUp="Item_MouseLeftButtonUp"
211+
ToolTipOpening="Item_ToolTipOpening">
212212

213213
<Grid.ContextMenu>
214214
<ContextMenu Opened="TabContextMenu_Opened">
@@ -277,9 +277,16 @@
277277

278278
<Grid.ToolTip>
279279
<ToolTip Placement="Top" VerticalOffset="-2">
280-
<Border Padding="6" Background="{StaticResource TabBarBackground}"
281-
BorderBrush="{StaticResource TabBackground}" BorderThickness="1">
282-
<Image x:Name="TooltipImage" Stretch="Uniform" MaxWidth="300" MaxHeight="200"/>
280+
<Border
281+
Padding="6"
282+
Background="{StaticResource TabBarBackground}"
283+
BorderBrush="{StaticResource TabBackground}"
284+
BorderThickness="1">
285+
<Image
286+
x:Name="TooltipImage"
287+
MaxWidth="300"
288+
MaxHeight="200"
289+
Stretch="Uniform" />
283290
</Border>
284291
</ToolTip>
285292
</Grid.ToolTip>

SioForgeCAD/Forms/LayoutBar.xaml.cs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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>())

SioForgeCAD/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
//Hot Reload and Edit & Continue are not compatible with using * in AssemblyVersionAttribute value.
2626
//Presence of * in the version means that the compiler generates a new version every build based on the current time.
2727
//The build then produces non-reproducible, non-deterministic outputs
28-
[assembly: AssemblyVersion("2026.4.15.10")]
29-
[assembly: AssemblyFileVersion("2026.4.15.10")]
28+
[assembly: AssemblyVersion("2026.4.15.16")]
29+
[assembly: AssemblyFileVersion("2026.4.15.16")]
3030
[assembly: NeutralResourcesLanguage("")]

0 commit comments

Comments
 (0)