mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-10-03 10:36:30 +13:00
Reenable scrolling (partially)
This commit is contained in:
parent
1f985c53aa
commit
ada694c611
5 changed files with 75 additions and 23 deletions
|
@ -163,7 +163,6 @@ namespace SystemTrayMenu.Business
|
||||||
|
|
||||||
Menu menuLoading = Create(menuDataLoading, new DirectoryInfo(rowData.Path).Name);
|
Menu menuLoading = Create(menuDataLoading, new DirectoryInfo(rowData.Path).Name);
|
||||||
menuLoading.IsLoadingMenu = true;
|
menuLoading.IsLoadingMenu = true;
|
||||||
AdjustMenusSizeAndLocation();
|
|
||||||
menus[rowData.Level + 1] = menuLoading;
|
menus[rowData.Level + 1] = menuLoading;
|
||||||
menuLoading.Tag = menuDataLoading.RowDataParent = rowData;
|
menuLoading.Tag = menuDataLoading.RowDataParent = rowData;
|
||||||
menuDataLoading.RowDataParent.SubMenu = menuLoading;
|
menuDataLoading.RowDataParent.SubMenu = menuLoading;
|
||||||
|
@ -614,8 +613,8 @@ namespace SystemTrayMenu.Business
|
||||||
menu.AdjustControls(title, menuData.Validity);
|
menu.AdjustControls(title, menuData.Validity);
|
||||||
menu.UserClickedOpenFolder += () => OpenFolder(path);
|
menu.UserClickedOpenFolder += () => OpenFolder(path);
|
||||||
menu.Level = menuData.Level;
|
menu.Level = menuData.Level;
|
||||||
#if TODO // MouseWeel and Misc MouseEvents
|
menu.Scrolled += AdjustMenusSizeAndLocation; // TODO: Only update vertical location while scrolling?
|
||||||
menu.MouseWheel += AdjustMenusSizeAndLocation;
|
#if TODO // Misc MouseEvents
|
||||||
menu.MouseLeave += waitLeave.Start;
|
menu.MouseLeave += waitLeave.Start;
|
||||||
menu.MouseEnter += waitLeave.Stop;
|
menu.MouseEnter += waitLeave.Stop;
|
||||||
#endif
|
#endif
|
||||||
|
@ -663,7 +662,7 @@ namespace SystemTrayMenu.Business
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
menu.IsVisibleChanged += (sender, _) => MenuVisibleChanged(sender, new EventArgs());
|
menu.IsVisibleChanged += (sender, _) => MenuVisibleChanged((Menu)sender);
|
||||||
|
|
||||||
AddItemsToMenu(menuData.RowDatas, menu, out int foldersCount, out int filesCount);
|
AddItemsToMenu(menuData.RowDatas, menu, out int foldersCount, out int filesCount);
|
||||||
|
|
||||||
|
@ -691,9 +690,8 @@ namespace SystemTrayMenu.Business
|
||||||
return menu;
|
return menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MenuVisibleChanged(object sender, EventArgs e)
|
private void MenuVisibleChanged(Menu menu)
|
||||||
{
|
{
|
||||||
Menu menu = (Menu)sender;
|
|
||||||
if (menu.IsUsable)
|
if (menu.IsUsable)
|
||||||
{
|
{
|
||||||
AdjustMenusSizeAndLocation();
|
AdjustMenusSizeAndLocation();
|
||||||
|
@ -703,7 +701,6 @@ namespace SystemTrayMenu.Business
|
||||||
menu.SetType(Menu.MenuType.Main);
|
menu.SetType(Menu.MenuType.Main);
|
||||||
menu.ResetSearchText();
|
menu.ResetSearchText();
|
||||||
menu.ResetHeight();
|
menu.ResetHeight();
|
||||||
AdjustMenusSizeAndLocation();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -141,7 +141,7 @@
|
||||||
</Button>
|
</Button>
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
|
|
||||||
<ListView x:Name="dgv" x:FieldModifier="internal" Margin="6,0" d:ItemsSource="{d:SampleData ItemCount=5}" ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Auto" BorderBrush="{x:Null}" Background="{x:Null}">
|
<ListView x:Name="dgv" x:FieldModifier="internal" Margin="6,0" d:ItemsSource="{d:SampleData ItemCount=5}" ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Auto" BorderBrush="{x:Null}" Background="{x:Null}" ScrollViewer.ScrollChanged="HandleScrollChanged">
|
||||||
<ListView.ItemTemplate>
|
<ListView.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<StackPanel Orientation="Horizontal" Height="{DynamicResource RowHeight}">
|
<StackPanel Orientation="Horizontal" Height="{DynamicResource RowHeight}">
|
||||||
|
|
|
@ -133,9 +133,7 @@ namespace SystemTrayMenu.UserInterface
|
||||||
MouseDown += Menu_MouseDown;
|
MouseDown += Menu_MouseDown;
|
||||||
MouseUp += Menu_MouseUp;
|
MouseUp += Menu_MouseUp;
|
||||||
MouseMove += Menu_MouseMove;
|
MouseMove += Menu_MouseMove;
|
||||||
#if TODO // MouseWeel
|
|
||||||
labelTitle.MouseWheel += new MouseEventHandler(DgvMouseWheel);
|
|
||||||
#endif
|
|
||||||
SolidColorBrush foreColor = new(Colors.Black);
|
SolidColorBrush foreColor = new(Colors.Black);
|
||||||
SolidColorBrush backColor = AppColors.Background.ToSolidColorBrush();
|
SolidColorBrush backColor = AppColors.Background.ToSolidColorBrush();
|
||||||
SolidColorBrush backColorSearch = AppColors.SearchField.ToSolidColorBrush();
|
SolidColorBrush backColorSearch = AppColors.SearchField.ToSolidColorBrush();
|
||||||
|
@ -224,9 +222,9 @@ namespace SystemTrayMenu.UserInterface
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#if TODO // MouseWeel and Misc MouseEvents
|
internal new event Action Scrolled;
|
||||||
internal new event Action MouseWheel;
|
|
||||||
|
|
||||||
|
#if TODO // Misc MouseEvents
|
||||||
internal new event Action MouseEnter;
|
internal new event Action MouseEnter;
|
||||||
|
|
||||||
internal new event Action MouseLeave;
|
internal new event Action MouseLeave;
|
||||||
|
@ -601,7 +599,18 @@ namespace SystemTrayMenu.UserInterface
|
||||||
changeDirectionWhenOutOfBounds = false;
|
changeDirectionWhenOutOfBounds = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Loaded += (_, _) =>
|
if (IsLoaded)
|
||||||
|
{
|
||||||
|
AdjustSizeAndLocationInternal();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Layout cannot be calculated during loading, postpone this event
|
||||||
|
// TODO: Make sure lampa capture is registered only once
|
||||||
|
Loaded += (_, _) => AdjustSizeAndLocationInternal();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AdjustSizeAndLocationInternal()
|
||||||
{
|
{
|
||||||
// Calculate X position
|
// Calculate X position
|
||||||
double x;
|
double x;
|
||||||
|
@ -707,10 +716,49 @@ namespace SystemTrayMenu.UserInterface
|
||||||
y = menuPredecessor.Location.Y;
|
y = menuPredecessor.Location.Y;
|
||||||
if (dgv.Items.Count > trigger.RowIndex)
|
if (dgv.Items.Count > trigger.RowIndex)
|
||||||
{
|
{
|
||||||
|
// TODO: Optimize calculation and fix calculation for items that are listed "beyond" the initial window size
|
||||||
|
|
||||||
|
// When item is not found, it might be invalidated due to resizing or moving
|
||||||
|
// After updating the layout the location should be available again.
|
||||||
|
menuPredecessor.UpdateLayout();
|
||||||
|
|
||||||
ListViewItem? lvi = dgv.FindVisualChildOfType<ListViewItem>(trigger.RowIndex);
|
ListViewItem? lvi = dgv.FindVisualChildOfType<ListViewItem>(trigger.RowIndex);
|
||||||
if (lvi != null)
|
if (lvi != null)
|
||||||
{
|
{
|
||||||
y += menuPredecessor.GetRelativeChildPositionTo(lvi).Y;
|
double offset;
|
||||||
|
|
||||||
|
ScrollViewer? scrollViewer = (VisualTreeHelper.GetChild(dgv, 0) as Decorator)?.Child as ScrollViewer;
|
||||||
|
if (scrollViewer != null)
|
||||||
|
{
|
||||||
|
if (scrollViewer.VerticalOffset > 0)
|
||||||
|
{
|
||||||
|
offset = 0D;
|
||||||
|
for (int i = 0; i < scrollViewer.VerticalOffset; i++)
|
||||||
|
{
|
||||||
|
ListViewItem? item = dgv.FindVisualChildOfType<ListViewItem>(i);
|
||||||
|
if (item != null)
|
||||||
|
{
|
||||||
|
offset += item.ActualHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
y -= (int)offset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
y += menuPredecessor.GetRelativeChildPositionTo(dgv).Y;
|
||||||
|
|
||||||
|
offset = 0D;
|
||||||
|
for (int i = 0; i < trigger.RowIndex; i++)
|
||||||
|
{
|
||||||
|
ListViewItem? item = dgv.FindVisualChildOfType<ListViewItem>(i);
|
||||||
|
if (item != null)
|
||||||
|
{
|
||||||
|
offset += item.ActualHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
y += (int)offset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -748,14 +796,21 @@ namespace SystemTrayMenu.UserInterface
|
||||||
|
|
||||||
// Keep its size when once created.
|
// Keep its size when once created.
|
||||||
SizeToContent = SizeToContent.Manual;
|
SizeToContent = SizeToContent.Manual;
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void ResetHeight()
|
internal void ResetHeight()
|
||||||
{
|
{
|
||||||
|
if (IsLoaded)
|
||||||
|
{
|
||||||
|
// TODO: WPF Check if this "reset" works
|
||||||
|
SizeToContent = SizeToContent.WidthAndHeight;
|
||||||
|
UpdateLayout();
|
||||||
|
SizeToContent = SizeToContent.Manual;
|
||||||
#if TODO // SEARCH
|
#if TODO // SEARCH
|
||||||
dgvHeightSet = false;
|
dgvHeightSet = false;
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void SetCounts(int foldersCount, int filesCount)
|
internal void SetCounts(int foldersCount, int filesCount)
|
||||||
|
@ -922,13 +977,14 @@ namespace SystemTrayMenu.UserInterface
|
||||||
((CollectionView)CollectionViewSource.GetDefaultView(dgv.ItemsSource)).Filter = null;
|
((CollectionView)CollectionViewSource.GetDefaultView(dgv.ItemsSource)).Filter = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if TODO // MouseWheel
|
private void HandleScrollChanged(object sender, ScrollChangedEventArgs e)
|
||||||
private void DgvMouseWheel(object sender, MouseEventArgs e)
|
|
||||||
{
|
{
|
||||||
((HandledMouseEventArgs)e).Handled = true;
|
if (IsLoaded)
|
||||||
MouseWheel?.Invoke();
|
{
|
||||||
|
Scrolled?.Invoke();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
#if TODO // SEARCH
|
#if TODO // SEARCH
|
||||||
private void TextBoxSearch_KeyPress(object sender, KeyPressEventArgs e)
|
private void TextBoxSearch_KeyPress(object sender, KeyPressEventArgs e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -858,7 +858,6 @@ namespace SystemTrayMenu.Utilities
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
handled = false;
|
handled = false;
|
||||||
return IntPtr.Zero;
|
return IntPtr.Zero;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace SystemTrayMenu.Utilities
|
||||||
{
|
{
|
||||||
if (Properties.Settings.Default.SendHotkeyInsteadKillOtherInstances)
|
if (Properties.Settings.Default.SendHotkeyInsteadKillOtherInstances)
|
||||||
{
|
{
|
||||||
#if TODO //HOTKEY
|
#if TODO // HOTKEY
|
||||||
Key modifiers = HotkeyControl.HotkeyModifiersFromString(Properties.Settings.Default.HotKey);
|
Key modifiers = HotkeyControl.HotkeyModifiersFromString(Properties.Settings.Default.HotKey);
|
||||||
Key hotkey = HotkeyControl.HotkeyFromString(Properties.Settings.Default.HotKey);
|
Key hotkey = HotkeyControl.HotkeyFromString(Properties.Settings.Default.HotKey);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue