diff --git a/src/ui/windows/TogglDesktop/TogglDesktop/ui/Behaviors/TimelineTimeEntryPopupHelper.cs b/src/ui/windows/TogglDesktop/TogglDesktop/ui/Behaviors/TimelineTimeEntryPopupHelper.cs index 6d12451c3f..c47795d9f8 100644 --- a/src/ui/windows/TogglDesktop/TogglDesktop/ui/Behaviors/TimelineTimeEntryPopupHelper.cs +++ b/src/ui/windows/TogglDesktop/TogglDesktop/ui/Behaviors/TimelineTimeEntryPopupHelper.cs @@ -1,27 +1,43 @@ using System; using System.Windows; using System.Windows.Controls; +using System.Windows.Controls.Primitives; using TogglDesktop.ViewModels; namespace TogglDesktop.Behaviors { public static class TimelineTimeEntryPopupHelper { - public static void OpenPopup(this TimelineTimeEntryBlockPopup popup, FrameworkElement placementTarget, ScrollViewer scroll) + public static void OpenPopupWithRightPlacement(this TimelineTimeEntryBlockPopup popup, FrameworkElement placementTarget, ScrollViewer scroll) { if (placementTarget.DataContext is TimeEntryBlock curBlock) { - popup.DataContext = curBlock; - popup.Popup.PlacementTarget = placementTarget; - popup.Popup.IsOpen = true; var visibleTopOffset = scroll.VerticalOffset + 10; var visibleBottomOffset = scroll.VerticalOffset + scroll.ActualHeight - 10; var offset = curBlock.VerticalOffset + placementTarget.ActualHeight / 2; - popup.Popup.VerticalOffset = Math.Min(Math.Max(visibleTopOffset, offset), visibleBottomOffset) - - curBlock.VerticalOffset; + popup.OpenPopup(PlacementMode.Right, placementTarget, curBlock, 0, Math.Min(Math.Max(visibleTopOffset, offset), visibleBottomOffset) - + curBlock.VerticalOffset); } } + public static void OpenPopup(this TimelineTimeEntryBlockPopup popup, PlacementMode mode, + FrameworkElement placementTarget, object dataContext, double horizontal, double vertical) + { + popup.DataContext = dataContext; + popup.PlacePopup(mode, placementTarget, horizontal, vertical); + popup.Popup.IsOpen = true; + } + + public static void PlacePopup(this TimelineTimeEntryBlockPopup popup, PlacementMode mode, + FrameworkElement placementTarget, + double horizontal, double vertical) + { + popup.Popup.Placement = mode; + popup.Popup.PlacementTarget = placementTarget; + popup.Popup.VerticalOffset = vertical; + popup.Popup.HorizontalOffset = horizontal; + } + public static void ClosePopup(this TimelineTimeEntryBlockPopup popup) { popup.Popup.IsOpen = false; diff --git a/src/ui/windows/TogglDesktop/TogglDesktop/ui/controls/TimelineRunningTimeEntryBlock.xaml.cs b/src/ui/windows/TogglDesktop/TogglDesktop/ui/controls/TimelineRunningTimeEntryBlock.xaml.cs index 86e1ca96de..f3ebefc356 100644 --- a/src/ui/windows/TogglDesktop/TogglDesktop/ui/controls/TimelineRunningTimeEntryBlock.xaml.cs +++ b/src/ui/windows/TogglDesktop/TogglDesktop/ui/controls/TimelineRunningTimeEntryBlock.xaml.cs @@ -46,7 +46,7 @@ private void OnThumbDragStarted(object sender, DragStartedEventArgs e) protected override void OnMouseEnter(MouseEventArgs e) { _scroll ??= this.FindParent(); - _popupContainer.OpenPopup(this, _scroll); + _popupContainer.OpenPopupWithRightPlacement(this, _scroll); } protected override void OnMouseLeave(MouseEventArgs e) diff --git a/src/ui/windows/TogglDesktop/TogglDesktop/ui/controls/TimelineTimeEntryBlockPopup.xaml b/src/ui/windows/TogglDesktop/TogglDesktop/ui/controls/TimelineTimeEntryBlockPopup.xaml index 8fe9dedaa9..01eaf2fc8b 100644 --- a/src/ui/windows/TogglDesktop/TogglDesktop/ui/controls/TimelineTimeEntryBlockPopup.xaml +++ b/src/ui/windows/TogglDesktop/TogglDesktop/ui/controls/TimelineTimeEntryBlockPopup.xaml @@ -7,9 +7,7 @@ mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800" d:DataContext="{d:DesignInstance viewModels:TimeEntryBlock, IsDesignTimeCreatable=False}"> - @@ -31,7 +29,8 @@ - + - + diff --git a/src/ui/windows/TogglDesktop/TogglDesktop/ui/controls/TimelineTimeEntryInfo.xaml b/src/ui/windows/TogglDesktop/TogglDesktop/ui/controls/TimelineTimeEntryInfo.xaml index 6e393c8bdb..95010c44ff 100644 --- a/src/ui/windows/TogglDesktop/TogglDesktop/ui/controls/TimelineTimeEntryInfo.xaml +++ b/src/ui/windows/TogglDesktop/TogglDesktop/ui/controls/TimelineTimeEntryInfo.xaml @@ -9,13 +9,13 @@ d:DataContext="{d:DesignInstance viewModels:TimeEntryBlock, IsDesignTimeCreatable=False}"> - + + DockPanel.Dock="Left" + Margin="0 0 5 0" + VerticalAlignment="Center" + Fill="{Binding Color, Converter={StaticResource AdaptProjectColorConverter}}" + Visibility="{Binding ProjectName, Converter={StaticResource EmptyStringToCollapsedConverter}}"/> @@ -25,7 +25,8 @@ FontSize="12" Visibility="{Binding TaskName, Converter={StaticResource EmptyStringToCollapsedConverter}}"/> - + @@ -39,7 +40,7 @@ - + diff --git a/src/ui/windows/TogglDesktop/TogglDesktop/ui/views/Timeline.xaml.cs b/src/ui/windows/TogglDesktop/TogglDesktop/ui/views/Timeline.xaml.cs index ccac0f8f3b..d546f292cd 100644 --- a/src/ui/windows/TogglDesktop/TogglDesktop/ui/views/Timeline.xaml.cs +++ b/src/ui/windows/TogglDesktop/TogglDesktop/ui/views/Timeline.xaml.cs @@ -3,6 +3,7 @@ using System.Reactive.Linq; using System.Windows; using System.Windows.Controls; +using System.Windows.Controls.Primitives; using System.Windows.Input; using DynamicData.Binding; using ReactiveUI; @@ -89,7 +90,7 @@ private void OnTimeEntryBlockMouseEnter(object sender, MouseEventArgs e) { if (sender is FrameworkElement uiElement) { - TimeEntryPopupContainer.OpenPopup(uiElement, MainViewScroll); + TimeEntryPopupContainer.OpenPopupWithRightPlacement(uiElement, MainViewScroll); } } @@ -105,9 +106,9 @@ private void OnTimeEntryCanvasMouseDown(object sender, MouseButtonEventArgs e) if (e.LeftButton == MouseButtonState.Pressed) { Mouse.Capture(sender as UIElement); - _dragStartedPoint = e.GetPosition(TimeEntryBlocks).Y; + var point = e.GetPosition(TimeEntryBlocks); + _dragStartedPoint = point.Y; _timeEntryId = TimelineViewModel.AddNewTimeEntry(_dragStartedPoint.Value, 0, ViewModel.SelectedScaleMode, ViewModel.SelectedDate); - ViewModel.TimeEntryBlocks[_timeEntryId].IsDragged = true; } } @@ -115,10 +116,17 @@ private void OnTimeEntryCanvasMouseMove(object sender, MouseEventArgs e) { if (_dragStartedPoint != null && _timeEntryId != null && e.LeftButton == MouseButtonState.Pressed) { - var verticalChange = Math.Abs(e.GetPosition(TimeEntryBlocks).Y - _dragStartedPoint.Value); + ViewModel.TimeEntryBlocks[_timeEntryId].IsDragged = true; + var point = e.GetPosition(TimeEntryBlocks); + var verticalChange = Math.Abs(point.Y - _dragStartedPoint.Value); ViewModel.TimeEntryBlocks[_timeEntryId].VerticalOffset = - Math.Min(_dragStartedPoint.Value, e.GetPosition(TimeEntryBlocks).Y); + Math.Min(_dragStartedPoint.Value, point.Y); ViewModel.TimeEntryBlocks[_timeEntryId].Height = verticalChange; + if (!TimeEntryPopupContainer.Popup.IsOpen) + TimeEntryPopupContainer.OpenPopup(PlacementMode.Relative, TimeEntryBlocks, ViewModel.TimeEntryBlocks[_timeEntryId], + point.X + 15, point.Y); + else + TimeEntryPopupContainer.PlacePopup(PlacementMode.Relative, TimeEntryBlocks, point.X + 15, point.Y); } } @@ -134,6 +142,7 @@ private void OnTimeEntryCanvasMouseUp(object sender, MouseButtonEventArgs mouseB ViewModel.TimeEntryBlocks[_timeEntryId].IsDragged = false; Toggl.Edit(_timeEntryId, false, Toggl.Description); } + TimeEntryPopupContainer.ClosePopup(); _dragStartedPoint = null; _timeEntryId = null; Mouse.Capture(null);