Skip to content

Commit

Permalink
Add removing files
Browse files Browse the repository at this point in the history
  • Loading branch information
keyroll-99 committed Jun 8, 2024
1 parent 503d42a commit 6ff760d
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 18 deletions.
1 change: 1 addition & 0 deletions ide/src/Fiona.IDE.ProjectManager/IProjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public interface IProjectManager
IEnumerable<ProjectFile> GetFiles();
ProjectFile GetProjectFileByNamespaceAndName(string @namespace, string name);
Task CreateFileAsync(string name, string folderPath);
Task RemoveFile(ProjectFile projectFile);

}
}
7 changes: 7 additions & 0 deletions ide/src/Fiona.IDE.ProjectManager/Models/FslnFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ internal async Task AddFile(string name, string path)
await SaveAsync();
}

internal async Task RemoveFile(ProjectFile file)
{
ProjectFiles!.Remove(file);
ProjectFilesPath.Remove(file.Path);
await SaveAsync();
}

private async Task SaveAsync()
{
await using FileStream fs = new($"{Path}{System.IO.Path.DirectorySeparatorChar}{Name}{Extension}",
Expand Down
1 change: 1 addition & 0 deletions ide/src/Fiona.IDE.ProjectManager/Models/ProjectFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ private void AddMethodContent(StringBuilder fileContentBuilder)
fileContentBuilder.AppendLine("bodyEnd;");
}
}
public override int GetHashCode() => HashCode.Combine(Path);
}

internal static class ProjectFileExtensions
Expand Down
4 changes: 4 additions & 0 deletions ide/src/Fiona.IDE.ProjectManager/ProjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public Task CreateFileAsync(string name, string folderPath)
{
return Project!.AddFile(name, folderPath);
}
public async Task RemoveFile(ProjectFile projectFile)
{
await Project!.RemoveFile(projectFile);
}

public bool IsLoaded()
=> Project is not null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@using Fiona.IDE.Components.Pages.Project
@using Fiona.IDE.ProjectManager
@using Fiona.IDE.ProjectManager
@using Fiona.IDE.ProjectManager.Exceptions
@inject NavigationManager NavManager

Expand Down
55 changes: 40 additions & 15 deletions ide/src/Fiona.IDE/Components/Pages/Project/Menu/ProjectMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,35 @@
@using Fiona.IDE.ProjectManager.Models
@inject NavigationManager NavManager


<BarItem>
<BarDropdown>
<BarDropdownToggle>Files</BarDropdownToggle>
<BarDropdownMenu>
<BarDropdownItem Clicked="OpenCreateNewFileModal">Create file</BarDropdownItem>
<DropdownDivider Class="divider" />
@foreach (ProjectFile projectFile in ProjectManager.GetFiles() ?? [])
{
<BarDropdownItem @onclick="() => OpenFile(projectFile)">@projectFile.Name</BarDropdownItem>
}
</BarDropdownMenu>
</BarDropdown>
</BarItem>

<ContextMenuTrigger MenuId="main-context-menu" CssClass="main-context-menu_trigger">
<BarItem>
<BarDropdown>
<BarDropdownToggle>Files</BarDropdownToggle>
<BarDropdownMenu>
<BarDropdownItem Clicked="OpenCreateNewFileModal">Create file</BarDropdownItem>
<DropdownDivider Class="divider"/>
@foreach (ProjectFile projectFile in ProjectManager.GetFiles() ?? [])
{
<ContextMenuTrigger MenuId="@projectFile.GetHashCode().ToString()">
<BarDropdownItem @onclick="() => OpenFile(projectFile)">@projectFile.Name</BarDropdownItem>
<ContextMenu Id=@projectFile.GetHashCode().ToString()>
<Item CssClass="context-menu-item" OnClick="@OnClick">Remove</Item>
</ContextMenu>
</ContextMenuTrigger>
}
</BarDropdownMenu>
</BarDropdown>
</BarItem>
</ContextMenuTrigger>
<ContextMenu Id="main-context-menu">
<Item CssClass="context-menu-item" OnClick="OpenCreateNewFileModal">Create file</Item>
</ContextMenu>

<CascadingValue Value="this">
<CreateFileModal/>
</CascadingValue>


@code
{
[Inject]
Expand All @@ -44,15 +54,30 @@
CloseCreateNewFileModal();
}


private void OpenFile(ProjectFile projectFile)
{
NavManager.NavigateTo($"/project-editor/{projectFile.Class.Namespace}/{projectFile.Class.Name}");

Check warning on line 60 in ide/src/Fiona.IDE/Components/Pages/Project/Menu/ProjectMenu.razor

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
}
async Task OnClick(ItemClickEventArgs e)
{
ProjectFile fileToRemove = ProjectManager.GetFiles().Single(x => x.GetHashCode().ToString() == e.ContextMenuId);
await ProjectManager.RemoveFile(fileToRemove);
StateHasChanged();
}
}

<style>
.divider{
background: grey !important; // override basic style
height: 1px;
}
.main-context-menu_trigger{
border: 1px solid gray;
}
.context-menu-item{
color: #000c17;
}
</style>
3 changes: 2 additions & 1 deletion ide/src/Fiona.IDE/Components/_Imports.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
@using Blazor.Diagrams.Options
@using Blazor.Diagrams
@using Blazor.Diagrams.Core.Anchors
@using Blazorise
@using Blazorise
@using BlazorContextMenu
1 change: 1 addition & 0 deletions ide/src/Fiona.IDE/Fiona.IDE.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Blazor.ContextMenu" Version="2.1.0" />
<PackageReference Include="Blazorise.Bootstrap5" Version="1.5.1" />
<PackageReference Include="Blazorise.Icons.FontAwesome" Version="1.5.1" />
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
Expand Down
1 change: 1 addition & 0 deletions ide/src/Fiona.IDE/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static MauiApp CreateMauiApp()
builder.Services.AddSingleton<MenuService>();
builder.Services.AddProjectManager();
builder.Services.AddCompiler();
builder.Services.AddBlazorContextMenu();
#if DEBUG
builder.Services.AddBlazorWebViewDeveloperTools();
builder.Logging.AddDebug();
Expand Down
2 changes: 2 additions & 0 deletions ide/src/Fiona.IDE/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<link href="_content/Blazorise.Bootstrap5/blazorise.bootstrap5.css" rel="stylesheet" />
<link href="_content/Z.Blazor.Diagrams/style.css" rel="stylesheet" />
<link href="_content/Z.Blazor.Diagrams/default.styles.min.css" rel="stylesheet" />
<link href="_content/Blazor.ContextMenu/blazorContextMenu.min.css" rel="stylesheet" />
</head>

<body>
Expand All @@ -38,6 +39,7 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/chartjs-plugin-datalabels/2.2.0/chartjs-plugin-datalabels.min.js" integrity="sha512-JPcRR8yFa8mmCsfrw4TNte1ZvF1e3+1SdGMslZvmrzDYxS69J7J49vkFL8u6u8PlPJK+H3voElBtUCzaXj+6ig==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="_content/Blazor.Bootstrap/blazor.bootstrap.js"></script>
<script src="_content/Z.Blazor.Diagrams/script.min.js"></script>
<script src="_content/Blazor.ContextMenu/blazorContextMenu.min.js"></script>
</body>

</html>

0 comments on commit 6ff760d

Please sign in to comment.