Skip to content

Commit

Permalink
filesystemwatcher fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikMennen committed Dec 15, 2023
1 parent fba2ba5 commit c9cb9d4
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 51 deletions.
17 changes: 11 additions & 6 deletions src/OneWare.Core/Views/DockViews/EditView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,33 +355,38 @@ private async Task PointerPressedAfterCaretUpdateAsync(object? sender, PointerEv
}

HoverBox.IsVisible = false;

contextMenuList.Add(new MenuItemViewModel("Cut")
{
Header = "Cut", IconObservable = this.GetResourceObservable("BoxIcons.RegularCut") ,
Header = "Cut",
IconObservable = this.GetResourceObservable("BoxIcons.RegularCut") ,
Command = new RelayCommand(CodeBox.Cut)
});
contextMenuList.Add(new MenuItemViewModel("Copy")
{
Header = "Copy", IconObservable = this.GetResourceObservable("BoxIcons.RegularCopy") ,
Header = "Copy",
IconObservable = this.GetResourceObservable("BoxIcons.RegularCopy") ,
Command = new RelayCommand(CodeBox.Copy)
});
contextMenuList.Add(new MenuItemViewModel("Paste")
{
Header = "Paste", IconObservable = this.GetResourceObservable("BoxIcons.RegularPaste") ,
Header = "Paste",
IconObservable = this.GetResourceObservable("BoxIcons.RegularPaste") ,
Command = new RelayCommand(CodeBox.Paste)
});
if (_typeAssistance != null)
{
contextMenuList.Add(new Separator());
contextMenuList.Add(new MenuItemViewModel("Comment")
{
Header = "Comment", IconObservable = this.GetResourceObservable("VsImageLib.CommentCode16X") ,
Header = "Comment",
IconObservable = this.GetResourceObservable("VsImageLib.CommentCode16X") ,
Command = new RelayCommand(_typeAssistance.Comment)
});
contextMenuList.Add(new MenuItemViewModel("Uncomment")
{
Header = "Uncomment", IconObservable = this.GetResourceObservable("VsImageLib.UncommentCode16X") ,
Header = "Uncomment",
IconObservable = this.GetResourceObservable("VsImageLib.UncommentCode16X") ,
Command = new RelayCommand(_typeAssistance.Uncomment)
});
}
Expand Down
61 changes: 34 additions & 27 deletions src/OneWare.PackageManager/ViewModels/PackageManagerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,39 +122,46 @@ private void RegisterPackage(Package package, string? installedVersion = null)
existing.Package = package;
return;
}

var model = package.Type switch
{
"Plugin" => ContainerLocator.Container.Resolve<PluginPackageViewModel>((typeof(Package), package)),
_ => throw new Exception($"Package Type invalid/missing for {package.Name}!")
};

if (installedVersion != null)
{
model.InstalledVersion = package.Versions!.First(x => x.Version == installedVersion);
model.Status = PackageStatus.Installed;
}
else
try
{
model.Status = PackageStatus.Available;
}
var model = package.Type switch
{
"Plugin" => ContainerLocator.Container.Resolve<PluginPackageViewModel>((typeof(Package), package)),
_ => throw new Exception($"Package Type invalid/missing for {package.Name}!")
};

var category = PackageCategories.FirstOrDefault(x =>
x.Header.Equals(package.Category, StringComparison.OrdinalIgnoreCase)) ?? PackageCategories.Last();
if (installedVersion != null)
{
model.InstalledVersion = package.Versions!.First(x => x.Version == installedVersion);
model.Status = PackageStatus.Installed;
}
else
{
model.Status = PackageStatus.Available;
}

var category = PackageCategories.FirstOrDefault(x =>
x.Header.Equals(package.Category, StringComparison.OrdinalIgnoreCase)) ?? PackageCategories.Last();

if(category != PackageCategories.First())
PackageCategories.First().Add(model);
Packages.Add(package.Id, model);
category.Add(model);
FilterPackages();
if(category != PackageCategories.First())
PackageCategories.First().Add(model);
Packages.Add(package.Id, model);
category.Add(model);
FilterPackages();

Observable.FromEventPattern(model, nameof(model.Installed))
.Subscribe(x => _ = SaveInstalledPackagesDatabaseAsync())
.DisposeWith(_packageRegistrationSubscription);
Observable.FromEventPattern(model, nameof(model.Installed))
.Subscribe(x => _ = SaveInstalledPackagesDatabaseAsync())
.DisposeWith(_packageRegistrationSubscription);

Observable.FromEventPattern(model, nameof(model.Removed))
.Subscribe(x => _ = SaveInstalledPackagesDatabaseAsync())
.DisposeWith(_packageRegistrationSubscription);
Observable.FromEventPattern(model, nameof(model.Removed))
.Subscribe(x => _ = SaveInstalledPackagesDatabaseAsync())
.DisposeWith(_packageRegistrationSubscription);
}
catch (Exception e)
{
_logger.Error(e.Message, e);
}
}

public async Task LoadPackagesAsync()
Expand Down
4 changes: 2 additions & 2 deletions src/OneWare.ProjectExplorer/Services/FileWatchInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class FileWatchInstance : IDisposable
private readonly IDockService _dockService;
private readonly IWindowService _windowService;
private readonly IFile _file;
private readonly FileSystemWatcher _fileSystemWatcher;
private readonly FileSystemWatcher? _fileSystemWatcher;
private readonly object _lock = new();
private DispatcherTimer? _timer;
private readonly List<FileSystemEventArgs> _changes = new();
Expand Down Expand Up @@ -109,6 +109,6 @@ private void Process(IReadOnlyCollection<FileSystemEventArgs> changes)
public void Dispose()
{
_timer?.Stop();
_fileSystemWatcher.Dispose();
_fileSystemWatcher?.Dispose();
}
}
26 changes: 14 additions & 12 deletions src/OneWare.ProjectExplorer/Services/ProjectWatchInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,12 @@ private async Task ProcessAsync(string path, IReadOnlyCollection<FileSystemEvent
{
try
{
if (!File.Exists(path))
if (File.Exists(path))
{
if(changes.Last().ChangeType is WatcherChangeTypes.Deleted && _root.Search(path) is {} deletedEntry)
await _projectExplorerService.RemoveAsync(deletedEntry);
return;
var attributes = File.GetAttributes(path);
if(attributes.HasFlag(FileAttributes.Hidden)) return;
}

var attributes = File.GetAttributes(path);
if(attributes.HasFlag(FileAttributes.Hidden)) return;

var entry = _root.Search(path);

var lastArg = changes.Last();
Expand Down Expand Up @@ -164,6 +160,10 @@ private async Task ProcessAsync(string path, IReadOnlyCollection<FileSystemEvent
case WatcherChangeTypes.Changed when changes.Any(x => x.ChangeType is WatcherChangeTypes.Created):
AddNew(path);
return;
case WatcherChangeTypes.Deleted:
if(_root.Search(path) is {} deletedEntry)
await _projectExplorerService.RemoveAsync(deletedEntry);
return;
}
}
}
Expand All @@ -177,18 +177,20 @@ private void AddNew(string path)
{
var attr = File.GetAttributes(path);
var relativePath = Path.GetRelativePath(_root.FullPath, path);

if (!_root.IsPathIncluded(relativePath)) return;


if (attr.HasFlag(FileAttributes.Hidden)) return;

if (attr.HasFlag(FileAttributes.Directory))
{
var folder = _root.AddFolder(relativePath);
ProjectHelper.ImportEntries(path, folder);
if(folder.Items.Count == 0) folder.TopFolder!.Remove(folder);
return;
}
else
_root.AddFile(relativePath);

if (!_root.IsPathIncluded(relativePath)) return;

_root.AddFile(relativePath);
}

public void Dispose()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,10 @@ private async Task RemoveAsync(IProjectEntry entry)

return;
}
else if (entry is IProjectFolder folder)
{
await RemoveAsync(folder.Items.ToArray());
}
else if (entry is IProjectFile file)
{
if (!await _dockService.CloseFileAsync(file)) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public override void Close()
if (!Service.IsLanguageServiceReady || offset > CodeBox.Document.TextLength) return menuItems;
var location = CodeBox.Document.GetLocation(offset);
var pos = CodeBox.Document.GetPositionFromOffset(offset);

//Quick Fixes
var error = GetErrorAtLocation(location);
if (error != null && error.Diagnostic != null)
Expand Down Expand Up @@ -712,8 +712,6 @@ void AfterComplete()
{
_ = ShowSignatureHelpAsync(SignatureHelpTriggerKind.Invoked, null, false, null);
}

Console.WriteLine(comp.LabelDetails);

var description = comp.Documentation != null ? (comp.Documentation.MarkupContent != null ? comp.Documentation.MarkupContent.Value : comp.Documentation.String) : null;

Expand Down
2 changes: 1 addition & 1 deletion src/OneWare.Settings/SettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void Load(string path)
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e);
}
}

Expand Down

0 comments on commit c9cb9d4

Please sign in to comment.