mirror of
https://github.com/greenshot/greenshot
synced 2025-08-26 08:06:09 -07:00
Added expert mode for the configuration UI, added PrintConfigViewModel and updated some of the other configs.
This commit is contained in:
parent
1c805aea7f
commit
e2580b86b5
13 changed files with 246 additions and 26 deletions
|
@ -358,5 +358,8 @@ namespace Greenshot.Addons.Core
|
|||
[IniPropertyBehavior(Read = false, Write = false)]
|
||||
[DefaultValue(false)]
|
||||
bool IsPortable { get; set; }
|
||||
|
||||
[Description("The permissions for Greenshot functionality")]
|
||||
ISet<string> Permissions { get; set; }
|
||||
}
|
||||
}
|
|
@ -179,5 +179,8 @@ namespace Greenshot.Addons
|
|||
string LatestVersion { get; }
|
||||
[DefaultValue("Current version")]
|
||||
string CurrentVersion { get; }
|
||||
|
||||
[DefaultValue("I know what I am doing! (expert mode)")]
|
||||
string Expert { get; }
|
||||
}
|
||||
}
|
97
src/Greenshot/Components/AuthenticationProvider.cs
Normal file
97
src/Greenshot/Components/AuthenticationProvider.cs
Normal file
|
@ -0,0 +1,97 @@
|
|||
#region Greenshot GNU General License
|
||||
|
||||
// Greenshot - a free and open source screenshot tool
|
||||
// Copyright (C) 2007-2018 Thomas Braun, Jens Klingen, Robin Krom
|
||||
//
|
||||
// For more information see: http://getgreenshot.org/
|
||||
// The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General License as published by
|
||||
// the Free Software Foundation, either version 1 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 License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.Linq;
|
||||
using Caliburn.Micro;
|
||||
using Dapplo.CaliburnMicro.Security;
|
||||
using Greenshot.Addons.Core;
|
||||
|
||||
namespace Greenshot.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// This exports a IAuthenticationProvider which manages the rights in the configuration
|
||||
/// This is used to show or hide elements in the UI depending on the available rights
|
||||
/// </summary>
|
||||
[Export(typeof(IAuthenticationProvider))]
|
||||
public class AuthenticationProvider : PropertyChangedBase, IAuthenticationProvider
|
||||
{
|
||||
[Import]
|
||||
private ICoreConfiguration CoreConfiguration { get; set; }
|
||||
|
||||
public bool HasPermissions(IEnumerable<string> neededPermissions, PermissionOperations permissionOperation = PermissionOperations.Or)
|
||||
{
|
||||
// Argument check
|
||||
if (neededPermissions == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(neededPermissions));
|
||||
}
|
||||
|
||||
if (CoreConfiguration.Permissions== null || CoreConfiguration.Permissions.Count == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create a clean list of permissions needed
|
||||
var permissionsToCompare = neededPermissions.Where(s => !string.IsNullOrWhiteSpace(s)).Select(permission => permission.Trim().ToLowerInvariant()).ToList();
|
||||
|
||||
if (permissionOperation == PermissionOperations.Or)
|
||||
{
|
||||
return permissionsToCompare.Any(permission => CoreConfiguration.Permissions.Contains(permission));
|
||||
}
|
||||
return permissionsToCompare.All(permission => CoreConfiguration.Permissions.Contains(permission));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a permission and inform via INotifyPropertyChanged events of changes
|
||||
/// </summary>
|
||||
/// <param name="permission">string with the permission</param>
|
||||
public void AddPermission(string permission)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(permission))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(permission));
|
||||
}
|
||||
var newPermission = permission.Trim().ToLowerInvariant();
|
||||
CoreConfiguration.Permissions.Add(newPermission);
|
||||
NotifyOfPropertyChange(nameof(HasPermissions));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove a permission and inform via INotifyPropertyChanged events of changes
|
||||
/// </summary>
|
||||
/// <param name="permission">string with the permission</param>
|
||||
public void RemovePermission(string permission)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(permission))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(permission));
|
||||
}
|
||||
var removingPermission = permission.Trim().ToLowerInvariant();
|
||||
CoreConfiguration.Permissions.Remove(removingPermission);
|
||||
NotifyOfPropertyChange(nameof(HasPermissions));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -198,6 +198,7 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AssemblyInfo.cs" />
|
||||
<Compile Include="Components\AuthenticationProvider.cs" />
|
||||
<Compile Include="Components\CommandlineParser.cs" />
|
||||
<Compile Include="Components\GreenshotUiStartupOrder.cs" />
|
||||
<Compile Include="Components\MainFormStartup.cs" />
|
||||
|
@ -265,6 +266,7 @@
|
|||
<DependentUpon>BugReportForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Startup.cs" />
|
||||
<Compile Include="Ui\Configuration\ViewModels\PrintConfigViewModel.cs" />
|
||||
<Compile Include="Ui\Configuration\ViewModels\OutputConfigViewModel.cs" />
|
||||
<Compile Include="Ui\Configuration\ViewModels\NetworkConfigViewModel.cs" />
|
||||
<Compile Include="Ui\Configuration\ViewModels\GeneralConfigViewModel.cs" />
|
||||
|
@ -492,6 +494,10 @@
|
|||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Include="Ui\Configuration\Views\PrintConfigView.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Include="Ui\Configuration\Views\OutputConfigView.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
|
|
|
@ -94,13 +94,11 @@ namespace Greenshot.Ui.Configuration.ViewModels
|
|||
{
|
||||
// Prepare disposables
|
||||
_disposables?.Dispose();
|
||||
_disposables = new CompositeDisposable();
|
||||
|
||||
// automatically update the DisplayName
|
||||
var greenshotLanguageBinding = GreenshotLanguage.CreateDisplayNameBinding(this, nameof(IGreenshotLanguage.SettingsTitle));
|
||||
|
||||
// Make sure the greenshotLanguageBinding is disposed when this is no longer active
|
||||
_disposables.Add(greenshotLanguageBinding);
|
||||
_disposables = new CompositeDisposable
|
||||
{
|
||||
GreenshotLanguage.CreateDisplayNameBinding(this, nameof(IGreenshotLanguage.SettingsTitle))
|
||||
};
|
||||
|
||||
base.OnActivate();
|
||||
}
|
||||
|
|
|
@ -27,14 +27,11 @@ using System.Collections.ObjectModel;
|
|||
using System.ComponentModel.Composition;
|
||||
using System.Linq;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Windows;
|
||||
using Dapplo.CaliburnMicro.Configuration;
|
||||
using Dapplo.CaliburnMicro.Extensions;
|
||||
using GongSolutions.Wpf.DragDrop;
|
||||
using Greenshot.Addons;
|
||||
using Greenshot.Addons.Addons;
|
||||
using Greenshot.Addons.Core;
|
||||
using Greenshot.Addons.Extensions;
|
||||
using Greenshot.Configuration;
|
||||
|
||||
namespace Greenshot.Ui.Configuration.ViewModels
|
||||
|
@ -63,7 +60,6 @@ namespace Greenshot.Ui.Configuration.ViewModels
|
|||
{
|
||||
// Prepare disposables
|
||||
_disposables?.Dispose();
|
||||
_disposables = new CompositeDisposable();
|
||||
|
||||
// Place this under the Ui parent
|
||||
ParentId = nameof(ConfigIds.Destinations);
|
||||
|
@ -72,10 +68,10 @@ namespace Greenshot.Ui.Configuration.ViewModels
|
|||
config.Register(CoreConfiguration);
|
||||
|
||||
// automatically update the DisplayName
|
||||
var greenshotLanguageBinding = GreenshotLanguage.CreateDisplayNameBinding(this, nameof(IGreenshotLanguage.SettingsDestinationPicker));
|
||||
|
||||
// Make sure the greenshotLanguageBinding is disposed when this is no longer active
|
||||
_disposables.Add(greenshotLanguageBinding);
|
||||
_disposables = new CompositeDisposable
|
||||
{
|
||||
GreenshotLanguage.CreateDisplayNameBinding(this, nameof(IGreenshotLanguage.SettingsDestinationPicker))
|
||||
};
|
||||
|
||||
UsedDestinations.Clear();
|
||||
if (CoreConfiguration.PickerDestinations.Any())
|
||||
|
|
|
@ -25,9 +25,10 @@ using System.ComponentModel.Composition;
|
|||
using System.Reactive.Disposables;
|
||||
using Dapplo.CaliburnMicro.Configuration;
|
||||
using Dapplo.CaliburnMicro.Extensions;
|
||||
using Dapplo.CaliburnMicro.Security;
|
||||
using Greenshot.Addons;
|
||||
using Greenshot.Addons.Core;
|
||||
using Greenshot.Configuration;
|
||||
using Greenshot.Components;
|
||||
|
||||
namespace Greenshot.Ui.Configuration.ViewModels
|
||||
{
|
||||
|
@ -42,12 +43,12 @@ namespace Greenshot.Ui.Configuration.ViewModels
|
|||
[Import]
|
||||
public ICoreConfiguration CoreConfiguration { get; set; }
|
||||
|
||||
[Import]
|
||||
public IConfigTranslations ConfigTranslations { get; set; }
|
||||
|
||||
[Import]
|
||||
public IGreenshotLanguage GreenshotLanguage { get; set; }
|
||||
|
||||
[Import(typeof(IAuthenticationProvider))]
|
||||
public AuthenticationProvider AuthenticationProvider { get; set; }
|
||||
|
||||
public override void Initialize(IConfig config)
|
||||
{
|
||||
// Prepare disposables
|
||||
|
@ -70,5 +71,30 @@ namespace Greenshot.Ui.Configuration.ViewModels
|
|||
_disposables.Dispose();
|
||||
base.OnDeactivate(close);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Change the expert mode
|
||||
/// </summary>
|
||||
public bool Expert
|
||||
{
|
||||
get => AuthenticationProvider?.HasPermissions(new[] { "Expert" }) == true;
|
||||
set
|
||||
{
|
||||
if (AuthenticationProvider == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (value)
|
||||
{
|
||||
AuthenticationProvider.AddPermission("Expert");
|
||||
}
|
||||
else
|
||||
{
|
||||
AuthenticationProvider.RemovePermission("Expert");
|
||||
}
|
||||
NotifyOfPropertyChange();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,15 +23,17 @@
|
|||
|
||||
using System.ComponentModel.Composition;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Windows;
|
||||
using Dapplo.CaliburnMicro.Configuration;
|
||||
using Dapplo.CaliburnMicro.Extensions;
|
||||
using Dapplo.CaliburnMicro.Security;
|
||||
using Greenshot.Addons;
|
||||
using Greenshot.Addons.Core;
|
||||
|
||||
namespace Greenshot.Ui.Configuration.ViewModels
|
||||
{
|
||||
[Export(typeof(IConfigScreen))]
|
||||
public sealed class NetworkConfigViewModel : SimpleConfigScreen
|
||||
public sealed class NetworkConfigViewModel : AuthenticatedConfigNode<Visibility>
|
||||
{
|
||||
/// <summary>
|
||||
/// Here all disposables are registered, so we can clean the up
|
||||
|
@ -52,6 +54,8 @@ namespace Greenshot.Ui.Configuration.ViewModels
|
|||
// Make sure Commit/Rollback is called on the IUiConfiguration
|
||||
config.Register(NetworkConfiguration);
|
||||
|
||||
this.VisibleOnPermissions("Expert");
|
||||
|
||||
// automatically update the DisplayName
|
||||
_disposables = new CompositeDisposable
|
||||
{
|
||||
|
|
|
@ -28,7 +28,6 @@ using Dapplo.CaliburnMicro.Extensions;
|
|||
using Greenshot.Addons;
|
||||
using Greenshot.Addons.Core;
|
||||
using Greenshot.Addons.ViewModels;
|
||||
using Greenshot.Configuration;
|
||||
|
||||
namespace Greenshot.Ui.Configuration.ViewModels
|
||||
{
|
||||
|
@ -43,9 +42,6 @@ namespace Greenshot.Ui.Configuration.ViewModels
|
|||
[Import]
|
||||
public ICoreConfiguration CoreConfiguration { get; set; }
|
||||
|
||||
[Import]
|
||||
public IConfigTranslations ConfigTranslations { get; set; }
|
||||
|
||||
[Import]
|
||||
public IGreenshotLanguage GreenshotLanguage { get; set; }
|
||||
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
#region Greenshot GNU General Public License
|
||||
|
||||
// Greenshot - a free and open source screenshot tool
|
||||
// Copyright (C) 2007-2018 Thomas Braun, Jens Klingen, Robin Krom
|
||||
//
|
||||
// For more information see: http://getgreenshot.org/
|
||||
// The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
|
||||
//
|
||||
// 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 1 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/>.
|
||||
|
||||
#endregion
|
||||
|
||||
using System.ComponentModel.Composition;
|
||||
using System.Reactive.Disposables;
|
||||
using Dapplo.CaliburnMicro.Configuration;
|
||||
using Dapplo.CaliburnMicro.Extensions;
|
||||
using Greenshot.Addons;
|
||||
using Greenshot.Addons.Core;
|
||||
|
||||
namespace Greenshot.Ui.Configuration.ViewModels
|
||||
{
|
||||
[Export(typeof(IConfigScreen))]
|
||||
public sealed class PrintConfigViewModel : SimpleConfigScreen
|
||||
{
|
||||
/// <summary>
|
||||
/// Here all disposables are registered, so we can clean the up
|
||||
/// </summary>
|
||||
private CompositeDisposable _disposables;
|
||||
|
||||
[Import]
|
||||
public ICoreConfiguration CoreConfiguration { get; set; }
|
||||
|
||||
[Import]
|
||||
public IGreenshotLanguage GreenshotLanguage { get; set; }
|
||||
|
||||
public override void Initialize(IConfig config)
|
||||
{
|
||||
// Prepare disposables
|
||||
_disposables?.Dispose();
|
||||
|
||||
// Make sure Commit/Rollback is called on the IUiConfiguration
|
||||
config.Register(CoreConfiguration);
|
||||
|
||||
// automatically update the DisplayName
|
||||
_disposables = new CompositeDisposable
|
||||
{
|
||||
GreenshotLanguage.CreateDisplayNameBinding(this, nameof(IGreenshotLanguage.SettingsPrinter))
|
||||
};
|
||||
|
||||
base.Initialize(config);
|
||||
}
|
||||
|
||||
protected override void OnDeactivate(bool close)
|
||||
{
|
||||
_disposables.Dispose();
|
||||
base.OnDeactivate(close);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,7 +8,8 @@
|
|||
d:DataContext="{d:DesignInstance viewModels:GeneralConfigViewModel,IsDesignTimeCreatable=False}"
|
||||
>
|
||||
<StackPanel>
|
||||
<CheckBox Content="{Binding GreenshotLanguage.SettingsCheckperiod}" IsChecked="{Binding CoreConfiguration.CheckForUpdates}"></CheckBox>
|
||||
<CheckBox Content="{Binding GreenshotLanguage.Expert}" IsChecked="{Binding Expert}"/>
|
||||
<CheckBox Content="{Binding GreenshotLanguage.SettingsCheckperiod}" IsChecked="{Binding CoreConfiguration.CheckForUpdates}"/>
|
||||
<DockPanel LastChildFill="True">
|
||||
<Label Content="{Binding GreenshotLanguage.SettingsCheckperiod}" Width="100" />
|
||||
<TextBox Text="{Binding CoreConfiguration.UpdateCheckInterval}"/>
|
||||
|
|
20
src/Greenshot/Ui/Configuration/Views/PrintConfigView.xaml
Normal file
20
src/Greenshot/Ui/Configuration/Views/PrintConfigView.xaml
Normal file
|
@ -0,0 +1,20 @@
|
|||
<UserControl x:Class="Greenshot.Ui.Configuration.Views.PrintConfigView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:viewModels="clr-namespace:Greenshot.Ui.Configuration.ViewModels"
|
||||
mc:Ignorable="d"
|
||||
d:DataContext="{d:DesignInstance viewModels:PrintConfigViewModel,IsDesignTimeCreatable=False}"
|
||||
>
|
||||
<StackPanel>
|
||||
<CheckBox Content="{Binding GreenshotLanguage.PrintoptionsAllowenlarge}" IsChecked="{Binding CoreConfiguration.OutputPrintAllowEnlarge}" />
|
||||
<CheckBox Content="{Binding GreenshotLanguage.PrintoptionsAllowcenter}" IsChecked="{Binding CoreConfiguration.OutputPrintCenter}" />
|
||||
<CheckBox Content="{Binding GreenshotLanguage.PrintoptionsAllowshrink}" IsChecked="{Binding CoreConfiguration.OutputPrintAllowShrink}" />
|
||||
<CheckBox Content="{Binding GreenshotLanguage.PrintoptionsAllowrotate}" IsChecked="{Binding CoreConfiguration.OutputPrintAllowRotate}" />
|
||||
<CheckBox Content="{Binding GreenshotLanguage.PrintoptionsPrintgrayscale}" IsChecked="{Binding CoreConfiguration.OutputPrintGrayscale}" />
|
||||
<CheckBox Content="{Binding GreenshotLanguage.PrintoptionsPrintmonochrome}" IsChecked="{Binding CoreConfiguration.OutputPrintMonochrome}" />
|
||||
<CheckBox Content="{Binding GreenshotLanguage.PrintoptionsInverted}" IsChecked="{Binding CoreConfiguration.OutputPrintInverted}" />
|
||||
<CheckBox Content="{Binding GreenshotLanguage.SettingsPrintoptions}" IsChecked="{Binding CoreConfiguration.OutputPrintPromptOptions}" />
|
||||
</StackPanel>
|
||||
</UserControl>
|
|
@ -9,12 +9,12 @@
|
|||
>
|
||||
<StackPanel>
|
||||
<DockPanel>
|
||||
<Label x:Name="ConfigTranslations_Theme" Width="50" />
|
||||
<Label Content="{Binding ConfigTranslations.Theme}" Width="50" />
|
||||
<ComboBox ItemsSource="{Binding AvailableThemes}" SelectedValuePath="Item1" DisplayMemberPath="Item2" SelectedValue="{Binding MetroConfiguration.Theme}"/>
|
||||
<ComboBox ItemsSource="{Binding AvailableThemeAccents}" SelectedValuePath="Item1" DisplayMemberPath="Item2" SelectedValue="{Binding MetroConfiguration.ThemeAccent}"/>
|
||||
</DockPanel>
|
||||
<DockPanel LastChildFill="True">
|
||||
<Label x:Name="CoreTranslations_Language" Width="100" />
|
||||
<Label Content="{Binding GreenshotLanguage.SettingsLanguage}" Width="100" />
|
||||
<ComboBox x:Name="AvailableLanguages" SelectedValuePath="Key" DisplayMemberPath="Value"
|
||||
SelectedValue="{Binding CoreConfiguration.Language}" />
|
||||
</DockPanel>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue