/* Copyright (C) 2014-2019 de4dot@gmail.com This file is part of dnSpy dnSpy is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. dnSpy is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with dnSpy. If not, see . */ using System; using System.Collections.ObjectModel; using System.Linq; namespace dnSpy.Contracts.Bookmarks { /// /// Bookmarks service /// public abstract class BookmarksService { /// /// Modifies a bookmark /// /// Bookmark /// New settings public void Modify(Bookmark bookmark, BookmarkSettings settings) => Modify(new[] { new BookmarkAndSettings(bookmark, settings) }); /// /// Modifies bookmarks /// /// New settings public abstract void Modify(BookmarkAndSettings[] settings); /// /// Raised when bookmarks are modified /// public abstract event EventHandler? BookmarksModified; /// /// Gets all bookmarks /// public abstract Bookmark[] Bookmarks { get; } /// /// Raised when is changed /// public abstract event EventHandler>? BookmarksChanged; /// /// Adds a bookmark. If the bookmark already exists, null is returned. /// /// Bookmark info /// public Bookmark? Add(BookmarkInfo bookmark) => Add(new[] { bookmark }).FirstOrDefault(); /// /// Adds bookmarks. Duplicate bookmarks are ignored. /// /// Bookmarks /// public abstract Bookmark[] Add(BookmarkInfo[] bookmarks); /// /// Removes a bookmark /// /// Bookmark to remove public void Remove(Bookmark bookmark) => Remove(new[] { bookmark ?? throw new ArgumentNullException(nameof(bookmark)) }); /// /// Removes bookmarks /// /// Bookmarks to remove public abstract void Remove(Bookmark[] bookmarks); /// /// Removes all bookmarks /// public abstract void Clear(); /// /// Closes /// /// Object to close public void Close(BMObject obj) => Close(new[] { obj ?? throw new ArgumentNullException(nameof(obj)) }); /// /// Closes /// /// Objects to close public abstract void Close(BMObject[] objs); } /// /// Bookmark and old settings /// public readonly struct BookmarkAndOldSettings { /// /// Gets the bookmark /// public Bookmark Bookmark { get; } /// /// Gets the old settings /// public BookmarkSettings OldSettings { get; } /// /// Constructor /// /// Bookmark /// Old settings public BookmarkAndOldSettings(Bookmark bookmark, BookmarkSettings oldSettings) { Bookmark = bookmark ?? throw new ArgumentNullException(nameof(bookmark)); OldSettings = oldSettings; } } /// /// Bookmarks modified event args /// public readonly struct BookmarksModifiedEventArgs { /// /// Gets the bookmarks /// public ReadOnlyCollection Bookmarks { get; } /// /// Constructor /// /// Bookmarks and old settings public BookmarksModifiedEventArgs(ReadOnlyCollection bookmarks) => Bookmarks = bookmarks ?? throw new ArgumentNullException(nameof(bookmarks)); } /// /// Bookmark and settings /// public readonly struct BookmarkAndSettings { /// /// Gets the bookmark /// public Bookmark Bookmark { get; } /// /// Gets the new settings /// public BookmarkSettings Settings { get; } /// /// Constructor /// /// Bookmark /// New settings public BookmarkAndSettings(Bookmark bookmark, BookmarkSettings settings) { Bookmark = bookmark ?? throw new ArgumentNullException(nameof(bookmark)); Settings = settings; } } /// /// Info needed to add a bookmark /// public readonly struct BookmarkInfo { /// /// Bookmark location /// public BookmarkLocation Location { get; } /// /// Bookmark settings /// public BookmarkSettings Settings { get; } /// /// Constructor /// /// Bookmark location /// Bookmark settings public BookmarkInfo(BookmarkLocation location, BookmarkSettings settings) { Location = location ?? throw new ArgumentNullException(nameof(location)); Settings = settings; } } /// /// Export an instance to get created when gets created /// public interface IBookmarksServiceListener { /// /// Called once by /// /// Bookmarks service void Initialize(BookmarksService bookmarksService); } }