mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 20:01:10 +00:00
Implements directory browser dialog, part 5: file system items selection
This commit is contained in:
1 parent
beb66ac65e
commit
7dedec0f9b
10 files changed
+640
-349
No files matched your search
@@ -41,7 +41,7 @@
|
||||
/// </summary>
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
_comboboxService.ComboboxOpened += CloseIfNotThis;
|
||||
_comboboxService.ComboboxOpened += CloseIfNotThisAsync;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -61,12 +61,12 @@
|
||||
/// Closes the dropdown if the provided <paramref name="openedId"/> is not the current <see cref="Id"/>, or if it's <see langword="null"/>.
|
||||
/// </summary>
|
||||
/// <param name="openedId">The optional id of the combobox that initiated the dropdown state change.</param>
|
||||
private void CloseIfNotThis(string? openedId)
|
||||
private async Task CloseIfNotThisAsync(string? openedId)
|
||||
{
|
||||
if (openedId != "combobox_checkbox_" + Id && IsOpen)
|
||||
{
|
||||
IsOpen = false;
|
||||
StateHasChanged();
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,6 +86,6 @@
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
_comboboxService.ComboboxOpened -= CloseIfNotThis;
|
||||
_comboboxService.ComboboxOpened -= CloseIfNotThisAsync;
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
await JSRuntime.InvokeVoidAsync("windowKeyDownHandler", inputElement, DotNetObjectReference.Create(this));
|
||||
await JSRuntime.InvokeVoidAsync("windowKeyDownHandler", inputElement, DotNetObjectReference.Create(this)).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
@using Lumina.Presentation.Web.Common.Api
|
||||
@using Lumina.Presentation.Web.Common.Models.Common
|
||||
@using Lumina.Presentation.Web.Common.Api
|
||||
@using Lumina.Presentation.Web.Common.Enums.FileSystem
|
||||
@using Lumina.Presentation.Web.Common.Enums.Notifications
|
||||
@using Lumina.Presentation.Web.Common.Exceptions
|
||||
@using Lumina.Presentation.Web.Common.Models.Common
|
||||
@using Lumina.Presentation.Web.Common.Models.FileManagement
|
||||
@using Lumina.Presentation.Web.Common.Models.UI
|
||||
@using Lumina.Presentation.Web.Common.Services
|
||||
@@ -21,15 +21,15 @@
|
||||
<div id="file-system-browser-header">
|
||||
<div id="file-system-browser-shine-spark"></div>
|
||||
<div id="file-system-browser-shine-effect"></div>
|
||||
<div id="file-system-browser-header-navigation-container">
|
||||
<div id="file-system-browser-header-navigation-container">
|
||||
<!--File System Navigator-->
|
||||
<div id="navigator-view-mode-container">
|
||||
<img src="images/ui/list.png" id="navigator-list-view" alt="List View" title="List View" @onclick="@(() => ChangeViewModeAsync(FileSystemViewMode.List))" />
|
||||
<img src="images/ui/details.png" id="navigator-details-view" alt="Details View" title="Details View" @onclick="@(() => ChangeViewModeAsync(FileSystemViewMode.Details))" />
|
||||
<img src="images/ui/small-icons.png" id="navigator-small-icons-view" alt="Small Icons View" title="Small Icons View" @onclick="@(() => ChangeIconSize(FileSystemIconSize.Small))" />
|
||||
<img src="images/ui/medium-icons.png" id="navigator-medium-icons-view" alt="Medium Icons View" title="Medium Icons View" @onclick="@(() => ChangeIconSize(FileSystemIconSize.Medium))" />
|
||||
<img src="images/ui/large-icons.png" id="navigator-large-icons-view" alt="Large Icons View" title="Large Icons View" @onclick="@(() => ChangeIconSize(FileSystemIconSize.Large))" />
|
||||
<img src="images/ui/extra-large-icons.png" id="navigator-extra-large-icons-view" alt="Extra Large Icons View" title="Extra Large Icons View" @onclick="@(() => ChangeIconSize(FileSystemIconSize.ExtraLarge))" />
|
||||
<img src="images/ui/small-icons.png" id="navigator-small-icons-view" alt="Small Icons View" title="Small Icons View" @onclick="@(() => ChangeIconSizeAsync(FileSystemIconSize.Small))" />
|
||||
<img src="images/ui/medium-icons.png" id="navigator-medium-icons-view" alt="Medium Icons View" title="Medium Icons View" @onclick="@(() => ChangeIconSizeAsync(FileSystemIconSize.Medium))" />
|
||||
<img src="images/ui/large-icons.png" id="navigator-large-icons-view" alt="Large Icons View" title="Large Icons View" @onclick="@(() => ChangeIconSizeAsync(FileSystemIconSize.Large))" />
|
||||
<img src="images/ui/extra-large-icons.png" id="navigator-extra-large-icons-view" alt="Extra Large Icons View" title="Extra Large Icons View" @onclick="@(() => ChangeIconSizeAsync(FileSystemIconSize.ExtraLarge))" />
|
||||
</div>
|
||||
<div id="navigator-navigation-controls-container">
|
||||
<div id="navigator-history">
|
||||
@@ -40,13 +40,56 @@
|
||||
<img src="images/ui/toggle-tree-view.svg" id="navigator-toggle-tree-view-button" alt="Toggle Tree View" title="Toggle Tree View" class="navigator-icon" />
|
||||
<img src="images/ui/toggle-thumbnails.svg" id="navigator-toggle-thumbnails-button" alt="Toggle Thumbnails" title="Toggle Thumbanils" class="navigator-icon" />
|
||||
<img src="images/ui/toggle-hidden.svg" id="navigator-toggle-hidden-button" alt="Toggle Hidden Files" title="Toggle Hidden Files" class="navigator-icon" />
|
||||
@* <img src="images/ui/toggle-selection.svg" id="navigator-toggle-selection-button" alt="Toggle Selection Mode" title="Toggle Selection Mode" class="navigator-icon" /> *@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<svg @onclick="ToggleSelectionModeAsync" id="navigator-toggle-selection-button" alt="Toggle Selection Mode" title="Toggle Selection Mode" class="navigator-icon" width="30" height="30" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<defs>
|
||||
<filter id="glow" x="-50%" y="-50%" width="200%" height="200%">
|
||||
<feComponentTransfer in="SourceAlpha" result="adjustedAlpha">
|
||||
<feFuncA type="table" tableValues="0 0.5 1" />
|
||||
</feComponentTransfer>
|
||||
<feGaussianBlur in="adjustedAlpha" stdDeviation="2" result="blur" />
|
||||
<feFlood flood-color="#039bfc" result="color" />
|
||||
<feComposite in="color" in2="blur" operator="in" result="softGlowColored" />
|
||||
<feMerge>
|
||||
<feMergeNode in="softGlowColored" />
|
||||
<feMergeNode in="SourceGraphic" />
|
||||
</feMerge>
|
||||
</filter>
|
||||
<linearGradient id="linearGradient1299" x1="5" x2="195" y1="174.76" y2="174.76" gradientTransform="matrix(.32632 0 0 .095367 -.63187 42.834)" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="#039bfc" stop-opacity="0" offset="0" />
|
||||
<stop stop-color="#039bfc" offset=".225" />
|
||||
<stop stop-color="#039bfc" offset=".5" />
|
||||
<stop stop-color="#039bfc" offset=".775" />
|
||||
<stop stop-color="#039bfc" stop-opacity="0" offset="1" />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
|
||||
<g transform="translate(0,-0.5) scale(0.475)">
|
||||
<rect x=".99971" y="59" width="62.001" height="1" ry="0" fill="url(#linearGradient1299)" stroke-width="3.7796" style="mix-blend-mode:normal;paint-order:stroke fill markers" filter="url(#glow)" />
|
||||
</g>
|
||||
<g stroke-linecap="round" stroke-linejoin="round" stroke-width="0.5">
|
||||
<rect x="4.5" y="4.5" width="21" height="21" ry="2.5" fill="none" stroke="#039bfc" style="paint-order:stroke fill markers" filter="url(#glow)" />
|
||||
</g>
|
||||
<g transform="translate(8,8) scale(0.030)">
|
||||
<path xmlns="http://www.w3.org/2000/svg" style="fill:currentColor;" class="navigator-icon-fill @(isSelectionMode ? " enabled" : string.Empty)" filter="url(#glow)" d="M161.9,21.9v21.9h131.2V0H161.9v43.7V21.9v21.9h131.2V0H161.9v43.7V21.9z M406.6,425.9L393,408.7l-52.4,41.6l-79.4-102.1 l-53,61.8l-38.9-217.9l198.1,99.1l-78.6,26.2l100.9,122.4L406.6,425.9L393,408.7L406.6,425.9l16.9-13.9l-60.4-73.2l118.3-39.4 L110.8,114l70.4,394.5l78.2-91.2l73.7,94.7l104.5-82.9l-14.2-17.2L406.6,425.9z M424.3,87.5V0h-87.5v43.7l43.7,0l0,43.7H424.3 L424.3,87.5z M118.1,0H30.7v87.5h43.7l0-43.7l43.7,0V0L118.1,0z M30.7,306.2v87.5h87.5v-43.7l-43.7,0l0-43.7H30.7z M402.5,131.2 h-21.9v87.5h43.7v-87.5h-43.7H402.5h-21.9v87.5h43.7v-87.5h-43.7H402.5z M52.5,262.4h21.9V131.2H30.7v131.2h43.7H52.5h21.9V131.2 H30.7v131.2h43.7H52.5z" />
|
||||
</g>
|
||||
</svg>
|
||||
|
||||
@* <img src="images/ui/toggle-selection.svg" @onclick="ToggleColor"
|
||||
style="@($"--text-color: {_currentTextColor}; --stroke-color: {_currentStrokeColor};")" id="navigator-toggle-selection-button" alt="Toggle Selection Mode" title="Toggle Selection Mode" class="navigator-icon" /> *@
|
||||
@* <object data="images/ui/toggle-selection.svg" type="image/svg+xml" id="navigator-toggle-selection-button" alt="Toggle Selection Mode" title="Toggle Selection Mode" class="navigator-icon ColorScheme-Text" /> *@
|
||||
</div>
|
||||
<div id="navigator-address-bar-container">
|
||||
<div id="navigator-address-bar-group">
|
||||
@if (isNavigationPathEditMode)
|
||||
{
|
||||
<EnlightenmentInput CssClass="navigator-address-bar-input" Type="text" @bind-Value="@Path" Name="navigator-address-bar-input"
|
||||
AutoComplete="true" OnEnterPressed="ExitNavigationPathEditModeAsync" OnEscapePressed="HandleNavigatorInputEscapePressed" Id="navigator-address-bar-input" />
|
||||
AutoComplete="true" OnEnterPressed="ExitNavigationPathEditModeAsync" OnEscapePressed="HandleNavigatorInputEscapePressedAsync" Id="navigator-address-bar-input" />
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -129,7 +172,7 @@
|
||||
iconSizeClass = "extra-large-icons";
|
||||
}
|
||||
string itemType = fileSystemItem is FileModel ? "file" : "directory";
|
||||
<div class="e @iconSizeClass" data-path="@fileSystemItem.Path" data-type="@itemType">
|
||||
<div class="e @iconSizeClass" data-path="@fileSystemItem.Path" data-type="@itemType" onmouseup="handleFileSystemEntityMouseUp(event)" onmousedown="handleFileSystemEntityMouseDown(event)">
|
||||
<div class="icon"><img src="/images/icons/Lyra/@(itemType).svg"></div>
|
||||
<div class="text"><span class="@(itemType == "directory" ? "d" : "f") t">@fileSystemItem.Name</span></div>
|
||||
<div class="date-modified @(itemType == "directory" ? "d" : "f")" style="display: none;">@fileSystemItem.DateModified</div>
|
||||
@@ -158,11 +201,13 @@
|
||||
<EnlightenmentButton IsConfirmButton="false">Cancel</EnlightenmentButton>
|
||||
<EnlightenmentButton>Confirm</EnlightenmentButton> *@
|
||||
</div>
|
||||
<div id="visible-selection-rectangle"></div>
|
||||
<div id="selection-rectangle"></div>
|
||||
|
||||
<!--The drop down for the navigator path segments needs to be absolute, such that it is not affected by the parent clipping-->
|
||||
@if (showPathSegmentDowpDown && expandedPathSegmentIndex.HasValue && pathSegmentsSubdirectoriesCache.ContainsKey(expandedPathSegmentIndex.Value))
|
||||
{
|
||||
<div class="navigator-dropdown opened" id="navigatorDropdown" data-path-segment-id="path-segment-@expandedPathSegmentIndex">
|
||||
<div class="navigator-dropdown opened" id="navigatorDropdown" data-path-segment-id="path-segment-@expandedPathSegmentIndex">
|
||||
@foreach (var directory in pathSegmentsSubdirectoriesCache[expandedPathSegmentIndex.Value])
|
||||
{
|
||||
<div class="navigator-option" data-path="@directory.Path" @onclick="@(() => NavigateToPathAsync(directory.Path, isForwardNavigation: false, isBackwardNavigation: false))">@directory.Name</div>
|
||||
@@ -171,7 +216,7 @@
|
||||
}
|
||||
@code {
|
||||
[Parameter] public string? Path { get; set; }
|
||||
[Parameter] public bool IncludeFiles { get; set; }
|
||||
[Parameter] public bool IncludeFiles { get; set; }
|
||||
|
||||
public EventCallback<string> OnNodeSelected { get; set; }
|
||||
|
||||
@@ -183,6 +228,7 @@
|
||||
private string pathSeparator = "/";
|
||||
private string? selectedNodePath;
|
||||
private string? _path;
|
||||
private bool isSelectionMode;
|
||||
private bool showPathSegmentDowpDown;
|
||||
private bool isNavigationPathEditMode;
|
||||
private int? expandedPathSegmentIndex;
|
||||
@@ -190,8 +236,8 @@
|
||||
private FileSystemIconSize iconSize;
|
||||
private Dictionary<int, List<FileSystemTreeNodeModel>> pathSegmentsSubdirectoriesCache = [];
|
||||
private DotNetObjectReference<FileSystemBrowser>? reference;
|
||||
private readonly Stack<string> undoStack = new();
|
||||
private readonly Stack<string> redoStack = new();
|
||||
private readonly Stack<string> undoStack = [];
|
||||
private readonly Stack<string> redoStack = [];
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the component.
|
||||
@@ -206,8 +252,6 @@
|
||||
await NavigateToPathAsync(Path, isForwardNavigation: false, isBackwardNavigation: false).ConfigureAwait(false);
|
||||
}
|
||||
await ChangeViewModeAsync(viewMode).ConfigureAwait(false);
|
||||
// make the navigator path segments horizontally scrollable
|
||||
await JSRuntime.InvokeVoidAsync("addHorizontalScrolling", "navigator-address-bar").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -220,7 +264,12 @@
|
||||
if (firstRender)
|
||||
{
|
||||
reference = DotNetObjectReference.Create(this);
|
||||
await JSRuntime.InvokeVoidAsync("windowClickHandler", reference);
|
||||
// assign the elements of this component instance to javascript variables, for memoization
|
||||
await JSRuntime.InvokeVoidAsync("initializeFileSystemBrowser", reference).ConfigureAwait(false);
|
||||
// make the navigator path segments horizontally scrollable
|
||||
await JSRuntime.InvokeVoidAsync("addHorizontalScrolling", "navigator-address-bar").ConfigureAwait(false);
|
||||
// subscribe to window clicks
|
||||
await JSRuntime.InvokeVoidAsync("windowClickHandler", reference).ConfigureAwait(false);
|
||||
}
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
}
|
||||
@@ -230,7 +279,7 @@
|
||||
/// </summary>
|
||||
/// <param name="e">The event arguments.</param>
|
||||
[JSInvokable]
|
||||
public void OnWindowClick(dynamic e)
|
||||
public async Task OnWindowClickAsync(dynamic e)
|
||||
{
|
||||
// parse the event args and get the initiator of the event
|
||||
var jsonElement = (JsonElement)e;
|
||||
@@ -245,7 +294,7 @@
|
||||
// exit navigator path edit mode when clicking anywhere outside of it, or on elements that should not exit it
|
||||
if (sender is null || (sender is not null && !sender.Contains("navigator-path-segments") && !sender.Contains("navigator-edit-icon") && !sender.Contains("navigator-address-bar-input")))
|
||||
isNavigationPathEditMode = false;
|
||||
StateHasChanged();
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -258,7 +307,7 @@
|
||||
{
|
||||
node.Children = new List<FileSystemTreeNodeModel>();
|
||||
node.IsExpanded = true;
|
||||
StateHasChanged();
|
||||
await InvokeAsync(StateHasChanged);
|
||||
if (await CheckPathAsync(node.Path).ConfigureAwait(false))
|
||||
{
|
||||
try
|
||||
@@ -268,7 +317,7 @@
|
||||
if (childNode is not null)
|
||||
{
|
||||
node.Children.Add(childNode);
|
||||
StateHasChanged();
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
if (IncludeFiles)
|
||||
@@ -278,7 +327,7 @@
|
||||
if (childNode is not null)
|
||||
{
|
||||
node.Children.Add(childNode);
|
||||
StateHasChanged();
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -295,7 +344,7 @@
|
||||
}
|
||||
else
|
||||
node.IsExpanded = !node.IsExpanded;
|
||||
StateHasChanged();
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -335,7 +384,7 @@
|
||||
if (!concatenatedPath.EndsWith(pathSeparator))
|
||||
concatenatedPath += pathSeparator;
|
||||
// add current and parent directories too
|
||||
List<FileSystemTreeNodeModel> directories = [ new() { Path = concatenatedPath, Name = ".", }, new() { Path = parentConcatenatedPath, Name = ".." } ];
|
||||
List<FileSystemTreeNodeModel> directories = [new() { Path = concatenatedPath, Name = ".", }, new() { Path = parentConcatenatedPath, Name = ".." }];
|
||||
// add the rest of the subdirectories of the expanded path node
|
||||
await foreach (FileSystemTreeNodeModel? directory in _apiHttpClient.GetAsyncEnumerable<FileSystemTreeNodeModel>($"directories/get-tree-directories?path={Uri.EscapeDataString(concatenatedPath)}").ConfigureAwait(false))
|
||||
if (directory is not null)
|
||||
@@ -344,7 +393,7 @@
|
||||
pathSegmentsSubdirectoriesCache[toggledIndex] = directories;
|
||||
expandedPathSegmentIndex = toggledIndex;
|
||||
showPathSegmentDowpDown = true;
|
||||
StateHasChanged();
|
||||
await InvokeAsync(StateHasChanged);
|
||||
// invoke the javascript function that positions the dropdown underneath the toggled path segment
|
||||
await JSRuntime.InvokeVoidAsync("updateDropdownPosition", $"path-segment-{toggledIndex}").ConfigureAwait(false);
|
||||
}
|
||||
@@ -352,7 +401,7 @@
|
||||
{
|
||||
expandedPathSegmentIndex = null;
|
||||
showPathSegmentDowpDown = false;
|
||||
StateHasChanged();
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -419,16 +468,23 @@
|
||||
}
|
||||
}
|
||||
_path = path; // we are about to navigate to the new path, store its value in the control variable
|
||||
await GetNavigatorPathAsync(path).ConfigureAwait(false);
|
||||
await GetFileSystemTreeAsync(path).ConfigureAwait(false);
|
||||
await GetFileSystemItemsAsync(path).ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
await GetNavigatorPathAsync(path).ConfigureAwait(false);
|
||||
await GetFileSystemTreeAsync(path).ConfigureAwait(false);
|
||||
await GetFileSystemItemsAsync(path).ConfigureAwait(false);
|
||||
}
|
||||
catch (ApiException ex)
|
||||
{
|
||||
HandleApiException(ex);
|
||||
}
|
||||
}
|
||||
selectedNodePath = _path;
|
||||
Path = _path; // also update the navigation input address
|
||||
if (Path is not null && !Path.EndsWith(pathSeparator))
|
||||
Path += pathSeparator;
|
||||
await OnNodeSelected.InvokeAsync(path).ConfigureAwait(false);
|
||||
StateHasChanged();
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -478,6 +534,16 @@
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the file system directories double click event.
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the double clicked directory.</param>
|
||||
[JSInvokable()]
|
||||
public async Task OnDirectoryDoubleClickAsync(string path)
|
||||
{
|
||||
await NavigateToPathAsync(path, isForwardNavigation: false, isBackwardNavigation: false).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the properties of the file system.
|
||||
/// </summary>
|
||||
@@ -528,7 +594,7 @@
|
||||
private async Task GetNavigatorPathAsync(string path)
|
||||
{
|
||||
pathSegments = await _apiHttpClient.GetAsync<PathSegmentModel[]>($"path/split?path={Uri.EscapeDataString(path!)}").ConfigureAwait(false);
|
||||
StateHasChanged();
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -548,12 +614,12 @@
|
||||
{
|
||||
// on UNIX, just add the root "/"
|
||||
treeViewRootNodes.Add(new FileSystemTreeNodeModel()
|
||||
{
|
||||
Path = pathSeparator!,
|
||||
IsExpanded = true,
|
||||
ItemType = FileSystemItemType.Root,
|
||||
Name = pathSeparator!
|
||||
});
|
||||
{
|
||||
Path = pathSeparator!,
|
||||
IsExpanded = true,
|
||||
ItemType = FileSystemItemType.Root,
|
||||
Name = pathSeparator!
|
||||
});
|
||||
}
|
||||
// if there was an initial path saved from a previous session, load the full tree up to that initial path
|
||||
List<FileSystemTreeNodeModel> initialTree = await _apiHttpClient.GetAsync<List<FileSystemTreeNodeModel>>($"directories/get-directory-tree?path={Uri.EscapeDataString(path!)}&includeFiles={IncludeFiles}").ConfigureAwait(false);
|
||||
@@ -590,7 +656,7 @@
|
||||
if (directory is not null)
|
||||
{
|
||||
fileSystemItems.Add(directory);
|
||||
StateHasChanged();
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
if (IncludeFiles)
|
||||
@@ -600,7 +666,7 @@
|
||||
if (file is not null)
|
||||
{
|
||||
fileSystemItems.Add(file);
|
||||
StateHasChanged();
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -622,18 +688,18 @@
|
||||
await JSRuntime.InvokeVoidAsync("addHorizontalScrolling", "file-system-browser-file-system-explorer").ConfigureAwait(false);
|
||||
else
|
||||
await JSRuntime.InvokeVoidAsync("removeHorizontalScrolling", "file-system-browser-file-system-explorer").ConfigureAwait(false);
|
||||
StateHasChanged();
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the icon size for the file system items.
|
||||
/// </summary>
|
||||
/// <param name="newIconSize">Thew new icon size to change to.</param>
|
||||
private void ChangeIconSize(FileSystemIconSize newIconSize)
|
||||
private async Task ChangeIconSizeAsync(FileSystemIconSize newIconSize)
|
||||
{
|
||||
viewMode = FileSystemViewMode.Icons;
|
||||
iconSize = newIconSize;
|
||||
StateHasChanged();
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -642,9 +708,9 @@
|
||||
private async Task EnterNavigationPathEditModeAsync()
|
||||
{
|
||||
isNavigationPathEditMode = true;
|
||||
StateHasChanged();
|
||||
await InvokeAsync(StateHasChanged);
|
||||
await InvokeAsync(async () =>
|
||||
{
|
||||
{
|
||||
await Task.Delay(50); // a small delay is necessary to ensure the DOM has updated
|
||||
await SetFocusOnNavigatorAddressInputAsync().ConfigureAwait(false);
|
||||
});
|
||||
@@ -656,7 +722,7 @@
|
||||
private async Task ExitNavigationPathEditModeAsync()
|
||||
{
|
||||
isNavigationPathEditMode = false;
|
||||
StateHasChanged();
|
||||
await InvokeAsync(StateHasChanged);
|
||||
if (Path is not null)
|
||||
{
|
||||
if (!Path.EndsWith(pathSeparator))
|
||||
@@ -671,7 +737,7 @@
|
||||
/// <param name="path">The path of the newly selected node.</param>
|
||||
private async Task HandleFileSystemTreeViewNodeSelectedAsync(string path)
|
||||
{
|
||||
StateHasChanged();
|
||||
await InvokeAsync(StateHasChanged);
|
||||
if (selectedNodePath is not null)
|
||||
{
|
||||
Path = path;
|
||||
@@ -684,11 +750,11 @@
|
||||
/// <summary>
|
||||
/// Handles the Escape key being pressed in the navigator address input.
|
||||
/// </summary>
|
||||
private void HandleNavigatorInputEscapePressed()
|
||||
private async Task HandleNavigatorInputEscapePressedAsync()
|
||||
{
|
||||
Path = _path;
|
||||
isNavigationPathEditMode = false;
|
||||
StateHasChanged();
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -696,7 +762,16 @@
|
||||
/// </summary>
|
||||
public async Task SetFocusOnNavigatorAddressInputAsync()
|
||||
{
|
||||
await JSRuntime.InvokeVoidAsync("focusNavigatorInputElement");
|
||||
await JSRuntime.InvokeVoidAsync("focusNavigatorInputElement").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enables or disables selection mode.
|
||||
/// </summary>
|
||||
private async Task ToggleSelectionModeAsync()
|
||||
{
|
||||
isSelectionMode = !isSelectionMode;
|
||||
await JSRuntime.InvokeVoidAsync("toggleSelectionMode").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
padding: 10px;
|
||||
border: 1px solid var(--border-color-dialog);
|
||||
box-shadow: 30px 30px 25px var(--shadow-color);
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
#file-system-browser-content {
|
||||
@@ -186,12 +187,6 @@
|
||||
|
||||
#file-system-browser-file-system-explorer-container {
|
||||
background-color: #232323;
|
||||
/*border-right-color: #000000;
|
||||
border-right-style: solid;
|
||||
border-right-width: 1px;
|
||||
border-left-color: #777777;
|
||||
border-left-style: solid;
|
||||
border-left-width: 1px;*/
|
||||
margin: auto;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
@@ -498,6 +493,18 @@ div[id^="file-system-browser-file-system-explorer"]:not([id*="container"]) {
|
||||
border-left-color: #999999;
|
||||
}
|
||||
|
||||
.e.selection-hover {
|
||||
background-color: #0048D7;
|
||||
}
|
||||
|
||||
.e.cut {
|
||||
background-color: #19233b;
|
||||
}
|
||||
|
||||
.e.cut img {
|
||||
opacity: 30%;
|
||||
}
|
||||
|
||||
/*directory*/
|
||||
.d {
|
||||
color: #6DCBFE;
|
||||
@@ -619,7 +626,7 @@ div[id^="file-system-browser-file-system-explorer"]:not([id*="container"]) {
|
||||
|
||||
/*File System Navigator*/
|
||||
#navigator-navigation-controls-container {
|
||||
width: 195px;
|
||||
width: 225px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
@@ -646,6 +653,14 @@ div[id^="file-system-browser-file-system-explorer"]:not([id*="container"]) {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.navigator-icon-fill {
|
||||
color: #039bfc;
|
||||
}
|
||||
|
||||
.navigator-icon-fill.enabled {
|
||||
color: #f00;
|
||||
}
|
||||
|
||||
#navigator-new-directory-icon {
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
@@ -829,7 +844,7 @@ div[id^="file-system-browser-file-system-explorer"]:not([id*="container"]) {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.navigator-arrow { /**/
|
||||
.navigator-arrow {
|
||||
display: inline-block;
|
||||
width: 12px;
|
||||
height: 9px;
|
||||
@@ -840,7 +855,7 @@ div[id^="file-system-browser-file-system-explorer"]:not([id*="container"]) {
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.navigator-toggle-checkbox:checked + .navigator-toggle .navigator-arrow { /**/
|
||||
.navigator-toggle-checkbox:checked + .navigator-toggle .navigator-arrow {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
@@ -884,7 +899,6 @@ div[id^="file-system-browser-file-system-explorer"]:not([id*="container"]) {
|
||||
color: #FFFFFF;
|
||||
padding: 5px 10px;
|
||||
min-width: 100%;
|
||||
/*width: auto;*/
|
||||
box-sizing: border-box;
|
||||
user-select: none;
|
||||
cursor: pointer;
|
||||
@@ -956,6 +970,30 @@ div[id^="file-system-browser-file-system-explorer"]:not([id*="container"]) {
|
||||
}
|
||||
|
||||
|
||||
#selection-rectangle {
|
||||
background-color: transparent;
|
||||
border: 0px;
|
||||
pointer-events: none;
|
||||
position: absolute;
|
||||
top: 0px;
|
||||
left: 0px;
|
||||
width: 0px;
|
||||
height: 0px;
|
||||
}
|
||||
|
||||
#visible-selection-rectangle {
|
||||
background-color: #0078D777;
|
||||
border: 1px solid #0078D7;
|
||||
pointer-events: none; /* so it doesn't interfere with the mouse events */
|
||||
position: absolute;
|
||||
top: 0px;
|
||||
left: 0px;
|
||||
width: 0px;
|
||||
height: 0px;
|
||||
visibility: hidden;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.scroll-vertical {
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
@@ -1047,7 +1085,7 @@ div[id^="file-system-browser-file-system-explorer"]:not([id*="container"]) {
|
||||
margin-left: 10px;
|
||||
}
|
||||
|
||||
#navigator-toggle-hidden-button {
|
||||
#navigator-toggle-selection-button {
|
||||
margin-right: 4px;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
@using Lumina.Presentation.Web.Common.Models.FileManagement
|
||||
|
||||
<div id="navigator-view-mode-container">
|
||||
<img src="images/ui/list.png" id="navigator-list-view" alt="List View" title="List View" />
|
||||
<img src="images/ui/details.png" id="navigator-details-view" alt="Details View" title="Details View" />
|
||||
<img src="images/ui/small-icons.png" id="navigator-small-icons-view" alt="Small Icons View" title="Small Icons View" />
|
||||
<img src="images/ui/medium-icons.png" id="navigator-medium-icons-view" alt="Medium Icons View" title="Medium Icons View" />
|
||||
<img src="images/ui/large-icons.png" id="navigator-large-icons-view" alt="Large Icons View" title="Large Icons View" />
|
||||
<img src="images/ui/extra-large-icons.png" id="navigator-extra-large-icons-view" alt="Extra Large Icons View" title="Extra Large Icons View" />
|
||||
</div>
|
||||
<div id="navigator-navigation-controls-container">
|
||||
<div id="navigator-history">
|
||||
<img src="images/ui/back.svg" class="navigation-icon" alt="Back" title="Back" />
|
||||
<img src="images/ui/forward.svg" class="navigation-icon" alt="Forward" title="Forward" />
|
||||
<img src="images/ui/up.svg" class="navigation-icon" alt="Up One Level" title="Up One Level" />
|
||||
</div>
|
||||
<img src="images/ui/toggle-tree-view.svg" id="navigator-toggle-tree-view-button" alt="Toggle Tree View" title="Toggle Tree View" class="navigator-icon" />
|
||||
<img src="images/ui/toggle-thumbnails.svg" id="navigator-toggle-thumbnails-button" alt="Toggle Thumbnails" title="Toggle Thumbanils" class="navigator-icon" />
|
||||
<img src="images/ui/toggle-hidden.svg" id="navigator-toggle-hidden-button" alt="Toggle Hidden Files" title="Toggle Hidden Files" class="navigator-icon" />
|
||||
</div>
|
||||
<div id="navigator-address-bar-container">
|
||||
<div id="navigator-address-bar-group">
|
||||
<EnlightenmentInput CssClass="navigator-address-bar-input" Type="text" Value="@Path" Name="navigator-address-bar-input" AutoComplete="true" />
|
||||
<div id="navigator-address-bar">
|
||||
<ul id="navigator-path-segments"></ul>
|
||||
</div>
|
||||
</div>
|
||||
<EnlightenmentButton CssClass="navigator-edit-path-button" IsConfirmButton="false" Height="28" Width="35">
|
||||
<svg width="24" height="24" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path style="fill:#009BFC;fill-opacity:1;stroke:none"
|
||||
d="m22.27 4l-18.27 18.27v5.73h5.73c0 0 18.269-18.269 18.27-18.27zm-2.865 4.299l4.297 4.297-11.701 11.703v-2.299h-4v-2.299zm-12.404 12.402v2.299h4v2.299l-1.701 1.701h-2l-2.297-2.297v-2z" />
|
||||
</svg>
|
||||
</EnlightenmentButton>
|
||||
<EnlightenmentButton CssClass="navigator-navigate-button" Height="28" Width="35">
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M20 6L9 17L4 12" stroke="#0F9D58" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
|
||||
</svg>
|
||||
</EnlightenmentButton>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[CascadingParameter(Name = "Path")] private string? Path { get; set; }
|
||||
[CascadingParameter(Name = "PathSeparator")] private string? PathSeparator { get; set; }
|
||||
[CascadingParameter(Name = "FileSystemType")] private FileSystemTypeModel? FileSystemType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Method invoked when parameters receive values from the parent.
|
||||
/// </summary>
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
if (Path is not null && PathSeparator is not null && FileSystemType is not null)
|
||||
if (!Path.EndsWith(PathSeparator))
|
||||
Path += PathSeparator;
|
||||
await base.OnParametersSetAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
@@ -1,154 +0,0 @@
|
||||
#navigator-navigation-controls-container {
|
||||
width: 180px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
#navigator-history {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
#navigator-history, ::deep .navigator-navigate-button, ::deep .navigator-edit-path-button {
|
||||
flex-shrink: 0; /* don't let them shrink */
|
||||
}
|
||||
|
||||
#navigator-history img {
|
||||
width: 26px;
|
||||
height: 26px;
|
||||
margin-left: 5px;
|
||||
}
|
||||
|
||||
.navigator-icon {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
::deep .navigator-navigate-button, ::deep .navigator-edit-path-button {
|
||||
text-align: end !important;
|
||||
}
|
||||
|
||||
::deep .navigator-navigate-button {
|
||||
margin: 0px 10px 2px 0px;
|
||||
}
|
||||
|
||||
::deep .navigator-edit-path-button {
|
||||
margin: 0px 10px 2px 12px;
|
||||
}
|
||||
|
||||
#navigator-address-bar-container {
|
||||
flex-grow: 1;
|
||||
display: flex;
|
||||
height: 28px;
|
||||
align-items: center;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
|
||||
#navigator-address-bar-container::-webkit-scrollbar,
|
||||
#navigator-address-bar-group::-webkit-scrollbar {
|
||||
display: none;
|
||||
width: 0;
|
||||
}
|
||||
|
||||
#navigator-address-bar-container,
|
||||
#navigator-address-bar-group {
|
||||
scrollbar-width: none; /* Firefox 64+ */
|
||||
}
|
||||
|
||||
#navigator-address-bar-container,
|
||||
#navigator-address-bar-group {
|
||||
-ms-overflow-style: none; /* IE 10+ */
|
||||
}
|
||||
|
||||
|
||||
/* for Webkit browsers like Chrome, Safari */
|
||||
#navigator-address-bar::-webkit-scrollbar {
|
||||
height: 0;
|
||||
}
|
||||
|
||||
/* for Internet Explorer and Edge */
|
||||
#navigator-address-bar {
|
||||
-ms-overflow-style: none; /*IE and Edge */
|
||||
}
|
||||
|
||||
/* for Firefox */
|
||||
#navigator-address-bar ::-moz-scrollbar {
|
||||
width: 0;
|
||||
display: none;
|
||||
}
|
||||
|
||||
|
||||
#navigator-address-bar-group {
|
||||
flex-grow: 1; /* let it take the remaining space */
|
||||
display: flex; /* use flex for its children */
|
||||
flex-wrap: nowrap;
|
||||
align-items: center; /* vertically center its children */
|
||||
height: 30px;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
|
||||
#navigator-view-mode-container {
|
||||
display: flex;
|
||||
margin-right: 10px;
|
||||
align-items: center;
|
||||
width: 125px;
|
||||
}
|
||||
|
||||
#navigator-view-mode-container img {
|
||||
margin-right: 5px;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
|
||||
#navigator-address-bar-group, #navigator-view-mode-container {
|
||||
margin-left: 10px;
|
||||
}
|
||||
|
||||
|
||||
::deep .navigator-address-bar-input {
|
||||
display: none;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
|
||||
#navigator-address-bar {
|
||||
background-color: #23232355;
|
||||
margin-top: -2px;
|
||||
padding-left: 2px;
|
||||
vertical-align: middle;
|
||||
height: 30px;
|
||||
flex-grow: 1;
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
}
|
||||
|
||||
#navigator-address-bar ul {
|
||||
height: 100%;
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
#navigator-path-segments {
|
||||
margin: 0px !important;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
#navigator-view-mode-container {
|
||||
height: 26px;
|
||||
}
|
||||
|
||||
#navigator-address-bar-container {
|
||||
flex-basis: 100%; /* Make navigator-address-bar-container take the full width on wrap, hence pushing it to a new line */
|
||||
}
|
||||
|
||||
}
|
||||
@@ -46,9 +46,8 @@
|
||||
/// </summary>
|
||||
private async Task HandleNodeClick()
|
||||
{
|
||||
Console.WriteLine("===node selected: " + Node.Path + "; selected node path: " + SelectedNodePath + "; is selected: " + IsSelected);
|
||||
await OnNodeSelected.InvokeAsync(Node.Path).ConfigureAwait(false);
|
||||
StateHasChanged();
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Services.UI;
|
||||
@@ -10,7 +11,7 @@ namespace Lumina.Presentation.Web.Core.Services.UI;
|
||||
public class ComboboxService
|
||||
{
|
||||
#region ================================================================== FIELD MEMBERS ================================================================================
|
||||
public event Action<string>? ComboboxOpened;
|
||||
public event Func<string, Task>? ComboboxOpened;
|
||||
#endregion
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
|
||||
@@ -4,4 +4,4 @@
|
||||
|
||||
<PageTitle>Lumina - Home</PageTitle>
|
||||
|
||||
<FileSystemBrowserComponent IncludeFiles="false" />
|
||||
<FileSystemBrowser IncludeFiles="false" Path="C:\"/>
|
||||
@@ -1,28 +1,104 @@
|
||||
let windowWasClicked = false;
|
||||
const scrollbarHeight = getScrollbarHeight();
|
||||
const scrollbarWidth = getScrollbarWidth();
|
||||
|
||||
let selectionStartPosition = { x: 0, y: 0 };
|
||||
let currentMousePosition = { x: 0, y: 0 };
|
||||
let isSelecting = false;
|
||||
let isSelectionMode = false;
|
||||
|
||||
let fileSystemExplorer = null;
|
||||
let fileSystemExplorerContainer = null;
|
||||
let visibleSelectionRectangle = null;
|
||||
let selectionRectangle = null;
|
||||
|
||||
// =================== common helper function ===================
|
||||
|
||||
/**
|
||||
* Adjusts the height of a dropdown identified by `comboboxId` to fit in the available space.
|
||||
* @param {string} comboboxId The Id of the combobox whose dropdown should be adjusted.
|
||||
* Gets the current time
|
||||
* @returns the current time
|
||||
*/
|
||||
function adjustDropdownHeight(comboboxId = null) {
|
||||
const comboboxes = comboboxId
|
||||
? [document.getElementById(comboboxId)] // if comboboxId is provided, use only that element
|
||||
: document.querySelectorAll('[id^="combobox_"]:not([id^="combobox_checkbox_"])'); // otherwise, select all dropdowns
|
||||
if (comboboxes) {
|
||||
comboboxes.forEach(combobox => {
|
||||
if (!combobox) return; // skip if no element is found
|
||||
const dropdown = combobox.querySelector('.enlightenment-dropdown');
|
||||
if (!dropdown) return; // skip if there's no dropdown inside
|
||||
// get the bounds of the combobox and the height of the viewport
|
||||
const comboboxRect = combobox.getBoundingClientRect();
|
||||
const viewportHeight = window.innerHeight;
|
||||
// calculate the space available between the combobox and the bottom of the viewport, with a 10px margin
|
||||
const dropdownTopPosition = comboboxRect.top + comboboxRect.height;
|
||||
const availableSpace = viewportHeight - dropdownTopPosition - 10; // 10px margin
|
||||
// adjust the dropdown height
|
||||
dropdown.style.maxHeight = `${availableSpace}px`;
|
||||
});
|
||||
}
|
||||
function getCurrentTime() {
|
||||
const now = new Date();
|
||||
const hours = String(now.getHours()).padStart(2, '0');
|
||||
const minutes = String(now.getMinutes()).padStart(2, '0');
|
||||
const seconds = String(now.getSeconds()).padStart(2, '0');
|
||||
const milliseconds = String(now.getMilliseconds()).padStart(3, '0');
|
||||
return `${hours}:${minutes}:${seconds}:${milliseconds}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the given element has vertical and/or horizontal scrollbars.
|
||||
* @param {HTMLElement} element - The element to check for scrollbars.
|
||||
* @returns {Object} An object indicating the presence of vertical and horizontal scrollbars.
|
||||
* @property {boolean} vertical - True if the element has a vertical scrollbar, otherwise false.
|
||||
* @property {boolean} horizontal - True if the element has a horizontal scrollbar, otherwise false.
|
||||
*/
|
||||
function hasScrollbars(element) {
|
||||
const tolerance = 3;
|
||||
return {
|
||||
vertical: element.scrollHeight - element.clientHeight > tolerance,
|
||||
horizontal: element.scrollWidth - element.clientWidth > tolerance
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the height of the browser's scrollbar.
|
||||
* @returns {number} Height of the scrollbar in pixels.
|
||||
*/
|
||||
function getScrollbarHeight() {
|
||||
// create an outer div and set its height and overflowY properties
|
||||
const outer = document.createElement('div');
|
||||
outer.style.visibility = 'hidden';
|
||||
outer.style.height = '100px';
|
||||
outer.style.overflowY = 'scroll';
|
||||
document.body.appendChild(outer);
|
||||
const heightNoScroll = outer.offsetHeight;
|
||||
const heightWithScroll = outer.clientHeight;
|
||||
// cleanup after measuring
|
||||
outer.parentNode.removeChild(outer);
|
||||
return heightNoScroll - heightWithScroll;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the width of the browser's scrollbar.
|
||||
* @returns {number} Width of the scrollbar in pixels.
|
||||
*/
|
||||
function getScrollbarWidth() {
|
||||
// create an outer div and set its width
|
||||
const outer = document.createElement('div');
|
||||
outer.style.visibility = 'hidden';
|
||||
outer.style.width = '100px';
|
||||
document.body.appendChild(outer);
|
||||
const widthNoScroll = outer.offsetWidth;
|
||||
// apply overflow and append an inner div
|
||||
outer.style.overflow = 'scroll';
|
||||
const inner = document.createElement('div');
|
||||
inner.style.width = '100%';
|
||||
outer.appendChild(inner);
|
||||
const widthWithScroll = inner.offsetWidth;
|
||||
// cleanup and calculate the difference
|
||||
outer.parentNode.removeChild(outer);
|
||||
return widthNoScroll - widthWithScroll;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables horizontal scrolling to the element identified by the specified id.
|
||||
*/
|
||||
function addHorizontalScrolling(id) {
|
||||
document.getElementById(id).addEventListener('wheel', function (e) {
|
||||
e.preventDefault();
|
||||
this.scrollLeft += (e.deltaY > 0 ? 1 : -1) * 80;
|
||||
}, { passive: false });
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables horizontal scrolling to the element identified by the specified id.
|
||||
*/
|
||||
function removeHorizontalScrolling(id) {
|
||||
document.getElementById(id).removeEventListener('wheel', function (e) {
|
||||
e.preventDefault();
|
||||
this.scrollLeft += (e.deltaY > 0 ? 1 : -1) * 80;
|
||||
}, { passive: false });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,6 +125,49 @@ function getElementOffset(id) {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the position and size of an HTML element.
|
||||
* @param {string} id - The id of the element to get the rectangle of.
|
||||
* @returns {object} An object containing the element's X (left), Y (top), Width, and Height in pixels.
|
||||
*/
|
||||
function getElementRectangle(id) {
|
||||
const element = document.getElementById(id);
|
||||
const rect = element.getBoundingClientRect();
|
||||
return {
|
||||
x: rect.left,
|
||||
y: rect.top,
|
||||
width: rect.width,
|
||||
height: rect.height
|
||||
};
|
||||
}
|
||||
|
||||
// =================== file system browser dialog ===================
|
||||
|
||||
/**
|
||||
* Adjusts the height of a dropdown identified by `comboboxId` to fit in the available space.
|
||||
* @param {string} comboboxId The Id of the combobox whose dropdown should be adjusted.
|
||||
*/
|
||||
function adjustDropdownHeight(comboboxId = null) {
|
||||
const comboboxes = comboboxId
|
||||
? [document.getElementById(comboboxId)] // if comboboxId is provided, use only that element
|
||||
: document.querySelectorAll('[id^="combobox_"]:not([id^="combobox_checkbox_"])'); // otherwise, select all dropdowns
|
||||
if (comboboxes) {
|
||||
comboboxes.forEach(combobox => {
|
||||
if (!combobox) return; // skip if no element is found
|
||||
const dropdown = combobox.querySelector('.enlightenment-dropdown');
|
||||
if (!dropdown) return; // skip if there's no dropdown inside
|
||||
// get the bounds of the combobox and the height of the viewport
|
||||
const comboboxRect = combobox.getBoundingClientRect();
|
||||
const viewportHeight = window.innerHeight;
|
||||
// calculate the space available between the combobox and the bottom of the viewport, with a 10px margin
|
||||
const dropdownTopPosition = comboboxRect.top + comboboxRect.height;
|
||||
const availableSpace = viewportHeight - dropdownTopPosition - 10; // 10px margin
|
||||
// adjust the dropdown height
|
||||
dropdown.style.maxHeight = `${availableSpace}px`;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the position and height of the dropdown relative to the specified path segment.
|
||||
* @param {string} pathSegmentId - The ID of the path segment element to position the dropdown relative to.
|
||||
@@ -68,26 +187,6 @@ function updateDropdownPosition(pathSegmentId) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables horizontal scrolling to the file system browser explorer tab.
|
||||
*/
|
||||
function addHorizontalScrolling(id) {
|
||||
document.getElementById(id).addEventListener('wheel', function (event) {
|
||||
event.preventDefault();
|
||||
this.scrollLeft += (event.deltaY > 0 ? 1 : -1) * 80;
|
||||
}, { passive: false });
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables horizontal scrolling to the file system browser explorer tab.
|
||||
*/
|
||||
function removeHorizontalScrolling(id) {
|
||||
document.getElementById(id).removeEventListener('wheel', function (event) {
|
||||
event.preventDefault();
|
||||
this.scrollLeft += (event.deltaY > 0 ? 1 : -1) * 80;
|
||||
}, { passive: false });
|
||||
}
|
||||
|
||||
/**
|
||||
* Focuses the navigator address bar input.
|
||||
*/
|
||||
@@ -118,6 +217,323 @@ function closeNavigatorPathSegments() {
|
||||
checkboxes[i].checked = false;
|
||||
}
|
||||
|
||||
// =================== file system browser dialog selection ===================
|
||||
|
||||
/**
|
||||
* Function called at the initialization of fle system browser dialog
|
||||
* @param {any} dotnetHelper - .NET object to invoke methods asynchronously.
|
||||
*/
|
||||
function initializeFileSystemBrowser(dotnetHelper) {
|
||||
// cache frequently accessed elements
|
||||
if (!selectionRectangle)
|
||||
selectionRectangle = document.getElementById('selection-rectangle');
|
||||
if (!visibleSelectionRectangle)
|
||||
visibleSelectionRectangle = document.getElementById('visible-selection-rectangle');
|
||||
if (!fileSystemExplorer) {
|
||||
fileSystemExplorer = document.getElementById('file-system-browser-file-system-explorer');
|
||||
if (fileSystemExplorer)
|
||||
fileSystemExplorer.addEventListener('mouseup', fileSystemExplorerMouseUp);
|
||||
}
|
||||
// event handlers needed for selection
|
||||
if (!fileSystemExplorerContainer) {
|
||||
fileSystemExplorerContainer = document.getElementById('file-system-browser-file-system-explorer-container');
|
||||
if (fileSystemExplorerContainer) {
|
||||
fileSystemExplorerContainer.addEventListener('mousedown', startSelection);
|
||||
fileSystemExplorerContainer.addEventListener('mousemove', updateSelection);
|
||||
fileSystemExplorerContainer.addEventListener('mouseup', endSelection);
|
||||
fileSystemExplorerContainer.addEventListener('wheel', handleSelection);
|
||||
fileSystemExplorerContainer.addEventListener('scroll', handleSelection);
|
||||
}
|
||||
}
|
||||
// handler for the mouse down event of file system browser dialog files and directories elements
|
||||
window.handleFileSystemEntityMouseDown = function (e) {
|
||||
// stop the event from bubbling up to the explorer - we dont want to start selection rectangles when clicking files or directories
|
||||
e.stopPropagation();
|
||||
};
|
||||
|
||||
// handler for the mouse up event of file system browser dialog files and directories elements
|
||||
window.handleFileSystemEntityMouseUp = function (e) {
|
||||
e.preventDefault();
|
||||
if (!isSelecting)
|
||||
e.stopPropagation();
|
||||
const allEClassElements = Array.from(fileSystemExplorer.querySelectorAll('.e'));
|
||||
const currentIndex = allEClassElements.indexOf(e.currentTarget);
|
||||
|
||||
// If a previous click timestamp exists, check the time difference
|
||||
const previousTime = parseInt(e.currentTarget.dataset.selectionStartTime || 0);
|
||||
const currentTime = new Date().getTime();
|
||||
const timeDifference = currentTime - previousTime;
|
||||
|
||||
// TODO: needs to account for when the element is already selected, and a double click occurs - on first click it would check the difference and go to rename -
|
||||
// maybe just wait half second before performing action
|
||||
|
||||
// if time difference is less than 300ms, treat it as a double-click
|
||||
if (timeDifference < 300) {
|
||||
if (e.currentTarget.dataset.type === 'directory') { // directories
|
||||
dotnetHelper.invokeMethodAsync('OnDirectoryDoubleClickAsync', e.currentTarget.dataset.path);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{ // files
|
||||
|
||||
}
|
||||
// reset the timestamp used to track double clicks
|
||||
e.currentTarget.dataset.selectionStartTime = 0;
|
||||
return;
|
||||
}
|
||||
else
|
||||
e.currentTarget.dataset.selectionStartTime = currentTime; // element was single clicked, update the selection start time to now
|
||||
if (e.ctrlKey || isSelectionMode) { // when CTRL key is pressed
|
||||
// toggle selection for the current clicked item
|
||||
e.currentTarget.classList.toggle('selected');
|
||||
// set the selection start if it's not already set
|
||||
if (fileSystemExplorer.dataset.selectionStart === undefined)
|
||||
fileSystemExplorer.dataset.selectionStart = currentIndex;
|
||||
}
|
||||
else if ((e.shiftKey && fileSystemExplorer.dataset.selectionStart !== undefined) || isSelectionMode) { // when SHIFT key is pressed
|
||||
const start = parseInt(fileSystemExplorer.dataset.selectionStart);
|
||||
// remove all selections
|
||||
allEClassElements.forEach(elem => {
|
||||
elem.classList.remove('selected');
|
||||
});
|
||||
// define the range to select items from and to
|
||||
const [from, to] = start < currentIndex ? [start, currentIndex] : [currentIndex, start];
|
||||
// add the 'selected' class to items in the range
|
||||
for (let i = from; i <= to; i++)
|
||||
allEClassElements[i].classList.add('selected');
|
||||
}
|
||||
else
|
||||
{ // when neither CTRL nor SHIFT keys are pressed
|
||||
if (!isSelectionMode) {
|
||||
// get all elements that are selected
|
||||
const selectedElements = allEClassElements.filter(element => element.classList.contains('selected'));
|
||||
// add 'selected' class to the current clicked item
|
||||
e.currentTarget.classList.add('selected');
|
||||
// if there are no selected elements, or if there are more than one, deselect all of them, and select just the clicked one
|
||||
if ((selectedElements.length === 1 && e.currentTarget !== selectedElements[0]) || selectedElements.length !== 1) {
|
||||
// deselect all items
|
||||
selectedElements.forEach(elem => {
|
||||
if (elem !== e.currentTarget) {
|
||||
elem.classList.remove('selected');
|
||||
// remove selectionStartTime from all items
|
||||
delete elem.dataset.selectionStartTime;
|
||||
}
|
||||
});
|
||||
// set the current item as the selection start
|
||||
fileSystemExplorer.dataset.selectionStart = currentIndex;
|
||||
// store the current timestamp for future double-click checks
|
||||
e.currentTarget.dataset.selectionStartTime = currentTime;
|
||||
}
|
||||
}
|
||||
else // if its selection mode, just toggle selection of item, when clicked
|
||||
e.currentTarget.classList.toggle('selected');
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for the mouse up event of the file system browser dialog explorer
|
||||
* @param {MouseEvent} e - The mouseup event object.
|
||||
*/
|
||||
function fileSystemExplorerMouseUp(e) {
|
||||
const explorerScrollbars = hasScrollbars(fileSystemExplorer);
|
||||
// check if clicked on the horizontal scrollbar
|
||||
if (explorerScrollbars.horizontal && e.clientY > fileSystemExplorer.getBoundingClientRect().top + fileSystemExplorer.offsetHeight - scrollbarHeight)
|
||||
return;
|
||||
if (!e.ctrlKey && !e.shiftKey && !isSelectionMode) {
|
||||
// deselect all file system elements when their explorer is clicked
|
||||
fileSystemExplorer.querySelectorAll('.e.selected').forEach(item => {
|
||||
item.classList.remove('selected');
|
||||
});
|
||||
// do not store information about what item was clicked first, in context of Shift-selection
|
||||
fileSystemExplorer.removeAttribute('data-selection-start');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for the file system browser dialog selection start.
|
||||
* @param {MouseEvent} e - The mousedown event object.
|
||||
*/
|
||||
function startSelection(e) {
|
||||
const explorerScrollbars = hasScrollbars(fileSystemExplorer);
|
||||
const containerExplorerScrollbars = hasScrollbars(fileSystemExplorerContainer);
|
||||
// check if clicked on the horizontal or vertical scrollbar
|
||||
if (explorerScrollbars.horizontal && e.clientY > fileSystemExplorer.getBoundingClientRect().top + fileSystemExplorer.offsetHeight - scrollbarHeight)
|
||||
return;
|
||||
if (containerExplorerScrollbars.vertical && e.clientX > fileSystemExplorerContainer.getBoundingClientRect().left + fileSystemExplorerContainer.offsetWidth - scrollbarWidth)
|
||||
return;
|
||||
// store information about selection start
|
||||
isSelecting = true;
|
||||
document.body.style.overflowY = 'hidden'; // needed in order to not put a vertical scrollbar on the document, while in vertical layout selection
|
||||
document.documentElement.style.overflowY = 'hidden';
|
||||
selectionStartPosition.x = e.pageX + fileSystemExplorer.scrollLeft;
|
||||
selectionStartPosition.y = e.pageY + fileSystemExplorerContainer.scrollTop; // not a mistake - in vertical mode, this is the overflow container!
|
||||
// place the selection rectangle at the clicked location (relative to the whole page, and taking into account scroll offset), with 0 size
|
||||
visibleSelectionRectangle.style.left = e.pageX + 'px';
|
||||
visibleSelectionRectangle.style.top = e.pageY + 'px';
|
||||
visibleSelectionRectangle.style.width = '0px';
|
||||
visibleSelectionRectangle.style.height = '0px';
|
||||
visibleSelectionRectangle.style.visibility = 'visible';
|
||||
|
||||
selectionRectangle.style.left = e.pageX + 'px';
|
||||
selectionRectangle.style.top = e.pageY + 'px';
|
||||
selectionRectangle.style.width = '0px';
|
||||
selectionRectangle.style.height = '0px';
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for the file system browser dialog selection update.
|
||||
* @param {MouseEvent} e - The mousemove event object.
|
||||
*/
|
||||
function updateSelection(e) {
|
||||
if (!isSelecting)
|
||||
return;
|
||||
currentMousePosition.x = e.pageX;
|
||||
currentMousePosition.y = e.pageY;
|
||||
handleSelection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for the file system browser dialog selection end.
|
||||
* @param {MouseEvent} e - The mouseup event object.
|
||||
*/
|
||||
function endSelection(e) {
|
||||
// selection ended, hide the selection rectangle
|
||||
isSelecting = false;
|
||||
document.body.style.removeProperty('overflow-y');
|
||||
document.documentElement.style.removeProperty('overflow-y');
|
||||
|
||||
visibleSelectionRectangle.style.visibility = 'hidden';
|
||||
selectionRectangle.style.visibility = 'hidden';
|
||||
|
||||
selectionRectangle.style.left = '0px';
|
||||
selectionRectangle.style.top = '0px';
|
||||
selectionRectangle.style.width = '0px';
|
||||
selectionRectangle.style.height = '0px';
|
||||
visibleSelectionRectangle.style.left = '0px';
|
||||
visibleSelectionRectangle.style.top = '0px';
|
||||
visibleSelectionRectangle.style.width = '0px';
|
||||
visibleSelectionRectangle.style.height = '0px';
|
||||
// go through each .e item that was inside the selection rectangle, and mark it as selected
|
||||
fileSystemExplorer.querySelectorAll('.e.selection-hover').forEach(item => {
|
||||
item.classList.add('selected');
|
||||
item.classList.remove('selection-hover');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for handling the file system browser dialog selection.
|
||||
*/
|
||||
function handleSelection() {
|
||||
if (!isSelecting) // only relevant when we have a selection initialized
|
||||
return;
|
||||
// calculate dimensions of the selection rectangle
|
||||
const currentX = currentMousePosition.x;
|
||||
const currentY = currentMousePosition.y;
|
||||
const width = currentX - (selectionStartPosition.x - fileSystemExplorer.scrollLeft);
|
||||
const height = currentY - (selectionStartPosition.y - fileSystemExplorerContainer.scrollTop);
|
||||
|
||||
// update selection rectangle dimensions
|
||||
visibleSelectionRectangle.style.width = Math.abs(width) + 'px';
|
||||
visibleSelectionRectangle.style.height = Math.abs(height) + 'px';
|
||||
selectionRectangle.style.width = Math.abs(width) + 'px';
|
||||
selectionRectangle.style.height = Math.abs(height) + 'px';
|
||||
|
||||
// adjust position based on selection direction
|
||||
if (width < 0) {
|
||||
selectionRectangle.style.left = currentX + 'px';
|
||||
visibleSelectionRectangle.style.left = currentX + 'px';
|
||||
} else {
|
||||
selectionRectangle.style.left = (selectionStartPosition.x - fileSystemExplorer.scrollLeft) + 'px';
|
||||
visibleSelectionRectangle.style.left = (selectionStartPosition.x - fileSystemExplorer.scrollLeft) + 'px';
|
||||
}
|
||||
if (height < 0) {
|
||||
selectionRectangle.style.top = currentY + 'px';
|
||||
visibleSelectionRectangle.style.top = currentY + 'px';
|
||||
} else {
|
||||
selectionRectangle.style.top = (selectionStartPosition.y - fileSystemExplorerContainer.scrollTop) + 'px';
|
||||
visibleSelectionRectangle.style.top = (selectionStartPosition.y - fileSystemExplorerContainer.scrollTop) + 'px';
|
||||
}
|
||||
|
||||
// do not let the selection rectangle go outside of explorer container, clip it if needed
|
||||
const containerRect = fileSystemExplorerContainer.getBoundingClientRect();
|
||||
const left = parseFloat(visibleSelectionRectangle.style.left);
|
||||
const top = parseFloat(visibleSelectionRectangle.style.top) + 1;
|
||||
const right = left + parseFloat(visibleSelectionRectangle.style.width);
|
||||
const bottom = top + parseFloat(visibleSelectionRectangle.style.height);
|
||||
|
||||
if (left < containerRect.left) {
|
||||
const difference = containerRect.left - left;
|
||||
visibleSelectionRectangle.style.width = (parseFloat(visibleSelectionRectangle.style.width) - difference) + 'px';
|
||||
visibleSelectionRectangle.style.left = containerRect.left + 'px';
|
||||
}
|
||||
if (right > containerRect.right)
|
||||
visibleSelectionRectangle.style.width = (containerRect.right - left) + 'px';
|
||||
|
||||
if (top < containerRect.top) {
|
||||
const difference = containerRect.top - top;
|
||||
visibleSelectionRectangle.style.height = (parseFloat(visibleSelectionRectangle.style.height) - difference) + 'px';
|
||||
visibleSelectionRectangle.style.top = containerRect.top + 'px';
|
||||
}
|
||||
if (bottom > containerRect.bottom)
|
||||
visibleSelectionRectangle.style.height = (containerRect.bottom - top) + 'px';
|
||||
|
||||
// change color of items that fall within selection rectangle
|
||||
const selectionRect = selectionRectangle.getBoundingClientRect();
|
||||
// go through each .e item which has not had its thumbnail retrieved yet
|
||||
fileSystemExplorer.querySelectorAll('.e').forEach(item => {
|
||||
const itemRect = item.getBoundingClientRect();
|
||||
// check if the item is fully or partially visible horizontally and vertically
|
||||
const isFullyVisibleHorizontally = itemRect.left >= selectionRect.left && itemRect.right <= selectionRect.right;
|
||||
const isFullyVisibleVertically = itemRect.top >= selectionRect.top && itemRect.bottom <= selectionRect.bottom;
|
||||
const isPartiallyVisibleHorizontally = itemRect.left < selectionRect.right && itemRect.right > selectionRect.left;
|
||||
const isPartiallyVisibleVertically = itemRect.top < selectionRect.bottom && itemRect.bottom > selectionRect.top;
|
||||
// if the item is fully or partially visible in both directions, add it to our list
|
||||
if ((isFullyVisibleHorizontally || isPartiallyVisibleHorizontally) && (isFullyVisibleVertically || isPartiallyVisibleVertically))
|
||||
item.classList.add('selection-hover');
|
||||
else
|
||||
item.classList.remove('selection-hover');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the state of selection mode.
|
||||
* @param {MouseEvent} e - The mouseup event object.
|
||||
*/
|
||||
function toggleSelectionMode(e) {
|
||||
isSelectionMode = !isSelectionMode;
|
||||
}
|
||||
|
||||
// =================== window functions ===================
|
||||
|
||||
/**
|
||||
* Attaches a click event listener to the window, invoking a .NET method when the window is clicked.
|
||||
* @param {any} dotnetHelper - .NET object to invoke methods asynchronously.
|
||||
*/
|
||||
function windowClickHandler(dotnetHelper) {
|
||||
window.addEventListener('click', (e) => {
|
||||
dotnetHelper.invokeMethodAsync('OnWindowClickAsync', {
|
||||
x: e.clientX,
|
||||
y: e.clientY,
|
||||
sender: e.target.getAttribute('id')
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Attaches a keydown event listener to the given element, invoking a .NET method when 'Escape' is pressed.
|
||||
* @param {HTMLElement} element - The HTML element to attach the keydown listener to.
|
||||
* @param {any} dotnetHelper - .NET object to invoke methods asynchronously.
|
||||
*/
|
||||
function windowKeyDownHandler(element, dotnetHelper) {
|
||||
element.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Escape') {
|
||||
e.preventDefault();
|
||||
dotnetHelper.invokeMethodAsync('EscapePressed');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the window resize event.
|
||||
*/
|
||||
@@ -130,32 +546,4 @@ window.addEventListener('resize', function () {
|
||||
if (pathSegmentId)
|
||||
updateDropdownPosition(pathSegmentId);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Attaches a click event listener to the window, invoking a .NET method when the window is clicked.
|
||||
* @param {any} dotnetHelper - .NET object to invoke methods asynchronously.
|
||||
*/
|
||||
window.windowClickHandler = (dotnetHelper) => {
|
||||
window.addEventListener('click', (event) => {
|
||||
dotnetHelper.invokeMethodAsync('OnWindowClick', {
|
||||
x: event.clientX,
|
||||
y: event.clientY,
|
||||
sender: event.target.getAttribute('id')
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Attaches a keydown event listener to the given element, invoking a .NET method when 'Escape' is pressed.
|
||||
* @param {HTMLElement} element - The HTML element to attach the keydown listener to.
|
||||
* @param {any} dotnetHelper - .NET object to invoke methods asynchronously.
|
||||
*/
|
||||
window.windowKeyDownHandler = (element, dotnetHelper) => {
|
||||
element.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Escape') {
|
||||
e.preventDefault();
|
||||
dotnetHelper.invokeMethodAsync('EscapePressed');
|
||||
}
|
||||
});
|
||||
};
|
||||
});
|
||||
Reference in new issue
Block a user