mirror of
https://github.com/QL-Win/QuickLook.git
synced 2026-05-08 03:06:29 +08:00
Merged QuickLook.Common from submodule
https://github.com/QL-Win/QuickLook.Common/commit/529d07b56577b88329481cdac8f2a6a175b6c21a
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
// Copyright © 2017-2026 QL-Win Contributors
|
||||
//
|
||||
// This file is part of QuickLook program.
|
||||
//
|
||||
// This program 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.
|
||||
//
|
||||
// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace QuickLook.Common.Plugin.MoreMenu;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a menu item that can be added to the QuickLook viewer's context menu.
|
||||
/// </summary>
|
||||
public interface IMenuItem : INotifyPropertyChanged
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the icon for the menu item. Can be a string (for Unicode symbols)
|
||||
/// String, <seealso cref="Wpf.Ui.Controls.FontSymbols"/> check from https://learn.microsoft.com/en-us/windows/apps/design/style/segoe-fluent-icons-font
|
||||
/// ImageSource, or null for no icon.
|
||||
/// </summary>
|
||||
public object Icon { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the display text for the menu item.
|
||||
/// </summary>
|
||||
public object Header { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of menu items.
|
||||
/// </summary>
|
||||
public IEnumerable<IMenuItem> MenuItems { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the menu item is visible.
|
||||
/// This allows dynamic show/hide based on file context.
|
||||
/// </summary>
|
||||
public bool IsVisible { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the menu item is enabled.
|
||||
/// </summary>
|
||||
public bool IsEnabled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the command to execute when the menu item is clicked.
|
||||
/// </summary>
|
||||
public ICommand Command { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the command parameter for the Command.
|
||||
/// </summary>
|
||||
public object CommandParameter { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the tooltip text for the menu item.
|
||||
/// </summary>
|
||||
public string ToolTip { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this menu item represents a separator.
|
||||
/// When true, other properties are ignored and a separator line is shown.
|
||||
/// </summary>
|
||||
public bool IsSeparator { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Copyright © 2017-2026 QL-Win Contributors
|
||||
//
|
||||
// This file is part of QuickLook program.
|
||||
//
|
||||
// This program 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.
|
||||
//
|
||||
// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QuickLook.Common.Plugin.MoreMenu;
|
||||
|
||||
/// <summary>
|
||||
/// Interface implemented by QuickLook plugins that want to provide custom context menu items.
|
||||
/// Plugins implementing this interface can add menu items to the viewer's title bar context menu.
|
||||
/// </summary>
|
||||
public interface IMoreMenu
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the collection of menu items that this plugin provides.
|
||||
/// This property will be queried after the Prepare method is called.
|
||||
/// </summary>
|
||||
public IEnumerable<IMenuItem> MenuItems { get; }
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// Copyright © 2017-2026 QL-Win Contributors
|
||||
//
|
||||
// This file is part of QuickLook program.
|
||||
//
|
||||
// This program 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.
|
||||
//
|
||||
// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace QuickLook.Common.Plugin.MoreMenu;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the extended version of IMoreMenu means that
|
||||
/// the insertion operation will be performed regardless of whether it is a matching plugin or not.
|
||||
/// </summary>
|
||||
public interface IMoreMenuExtended : IMoreMenu;
|
||||
@@ -0,0 +1,135 @@
|
||||
// Copyright © 2017-2026 QL-Win Contributors
|
||||
//
|
||||
// This file is part of QuickLook program.
|
||||
//
|
||||
// This program 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.
|
||||
//
|
||||
// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
using QuickLook.Common.Annotations;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace QuickLook.Common.Plugin.MoreMenu;
|
||||
|
||||
/// <summary>
|
||||
/// Base class for QuickLook menu items that provides common functionality
|
||||
/// and implements INotifyPropertyChanged for dynamic property updates.
|
||||
/// </summary>
|
||||
public class MoreMenuItem : IMenuItem
|
||||
{
|
||||
private object _icon;
|
||||
private object _header;
|
||||
private IEnumerable<IMenuItem> _menuItems;
|
||||
private bool _isVisible = true;
|
||||
private bool _isEnabled = true;
|
||||
private ICommand _command;
|
||||
private object _commandParameter;
|
||||
private string _toolTip;
|
||||
private bool _isSeparator;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual object Icon
|
||||
{
|
||||
get => _icon;
|
||||
set => SetProperty(ref _icon, value);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual object Header
|
||||
{
|
||||
get => _header;
|
||||
set => SetProperty(ref _header, value);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IEnumerable<IMenuItem> MenuItems
|
||||
{
|
||||
get => _menuItems;
|
||||
set => SetProperty(ref _menuItems, value);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual bool IsVisible
|
||||
{
|
||||
get => _isVisible;
|
||||
set => SetProperty(ref _isVisible, value);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual bool IsEnabled
|
||||
{
|
||||
get => _isEnabled;
|
||||
set => SetProperty(ref _isEnabled, value);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual ICommand Command
|
||||
{
|
||||
get => _command;
|
||||
set => SetProperty(ref _command, value);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual object CommandParameter
|
||||
{
|
||||
get => _commandParameter;
|
||||
set => SetProperty(ref _commandParameter, value);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual string ToolTip
|
||||
{
|
||||
get => _toolTip;
|
||||
set => SetProperty(ref _toolTip, value);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual bool IsSeparator
|
||||
{
|
||||
get => _isSeparator;
|
||||
set => SetProperty(ref _isSeparator, value);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Raises the PropertyChanged event for the specified property.
|
||||
/// </summary>
|
||||
/// <param name="propertyName">The name of the property that changed.</param>
|
||||
[NotifyPropertyChangedInvocator]
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the property value and raises PropertyChanged if the value has changed.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the property.</typeparam>
|
||||
/// <param name="field">The backing field for the property.</param>
|
||||
/// <param name="value">The new value.</param>
|
||||
/// <param name="propertyName">The name of the property.</param>
|
||||
/// <returns>True if the property value was changed; otherwise, false.</returns>
|
||||
protected bool SetProperty<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
|
||||
{
|
||||
if (Equals(field, value))
|
||||
return false;
|
||||
|
||||
field = value;
|
||||
OnPropertyChanged(propertyName);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user