Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions Pinta.Core/Actions/AppActions.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
//
//
// AppActions.cs
//
//
// Author:
// Jonathan Pobst <monkey@jpobst.com>
//
//
// Copyright (c) 2010 Jonathan Pobst
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -31,6 +31,7 @@ namespace Pinta.Core;
public sealed class AppActions
{
public Command About { get; }
public Command Preferences { get; }
public Command KeyboardShortcuts { get; }
public Command Exit { get; }

Expand All @@ -43,12 +44,17 @@ public AppActions ()
Translations.GetString ("About"),
null,
Resources.StandardIcons.HelpAbout);
Preferences = new Command (
"preferences",
Translations.GetString ("Preferences..."),
null,
Resources.StandardIcons.Preferences,
shortcuts: ["<Primary>comma"]);
KeyboardShortcuts = new Command (
"keyboardshortcuts",
Translations.GetString ("Keyboard Shortcuts"),
null,
Resources.StandardIcons.KeyboardShortcuts,
shortcuts: ["<Primary>comma"]);
null, null,
shortcuts: ["<Primary>question"]);
Exit = new Command (
"quit",
Translations.GetString ("Quit"),
Expand All @@ -61,6 +67,7 @@ public void RegisterActions (Gtk.Application app)
{
app.AddCommands ([
About,
Preferences,
KeyboardShortcuts,
Exit]);
}
Expand Down
15 changes: 6 additions & 9 deletions Pinta.Core/Actions/FileActions.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
//
//
// FileActions.cs
//
//
// Author:
// Jonathan Pobst <monkey@jpobst.com>
//
//
// Copyright (c) 2010 Jonathan Pobst
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -138,9 +138,6 @@ public void RegisterActions (Gtk.Application application, Gio.Menu menu)
SaveAs,

Close]);

if (!isMac)
application.AddCommand (app.Exit); // This is part of the application menu on macOS
}

public void RegisterHandlers () { }
Expand Down
20 changes: 7 additions & 13 deletions Pinta.Core/Actions/HelpActions.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
//
//
// HelpActions.cs
//
//
// Author:
// Jonathan Pobst <monkey@jpobst.com>
//
//
// Copyright (c) 2010 Jonathan Pobst
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -73,9 +73,6 @@ public void RegisterActions (Gtk.Application application, Gio.Menu menu)
{
menu.AppendItem (Contents.CreateMenuItem ());

if (system.OperatingSystem != OS.Mac) {
application.AddCommand (app.KeyboardShortcuts);
}
menu.AppendItem (app.KeyboardShortcuts.CreateMenuItem ());

menu.AppendItem (Website.CreateMenuItem ());
Expand All @@ -93,10 +90,7 @@ public void RegisterActions (Gtk.Application application, Gio.Menu menu)

var about_section = Gio.Menu.New ();
menu.AppendSection (null, about_section);

Command about = app.About;
application.AddCommand (about);
about_section.AppendItem (about.CreateMenuItem ());
about_section.AppendItem (app.About.CreateMenuItem ());
}
}

Expand Down
19 changes: 0 additions & 19 deletions Pinta.Core/Actions/ViewActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public sealed class ViewActions
public ToggleCommand ToolBox { get; }
public ToggleCommand Rulers { get; }
public Gio.SimpleAction RulerMetric { get; }
public Gio.SimpleAction ColorScheme { get; }
public Command Fullscreen { get; }

public ToolBarComboBox ZoomComboBox { get; }
Expand Down Expand Up @@ -155,11 +154,6 @@ public ViewActions (ChromeManager chrome, WorkspaceManager workspace)
GtkExtensions.IntVariantType,
GLib.Variant.NewInt32 (0));

ColorScheme = Gio.SimpleAction.NewStateful ( // TODO: Make `Command`
"colorscheme",
GtkExtensions.IntVariantType,
GLib.Variant.NewInt32 (0));

Fullscreen = new Command (
"Fullscreen",
Translations.GetString ("Fullscreen"),
Expand Down Expand Up @@ -242,22 +236,10 @@ public void RegisterActions (Gtk.Application app, Gio.Menu menu)
Gio.Menu show_hide_section = Gio.Menu.New ();
show_hide_section.AppendSubmenu (Translations.GetString ("Show/Hide"), show_hide_menu);

Gio.Menu color_scheme_menu = Gio.Menu.New ();
// Translators: This refers to using the system's default color scheme.
color_scheme_menu.Append (Translations.GetString ("Default"), $"app.{ColorScheme.Name}(0)");
// Translators: This refers to using a light variant of the color scheme.
color_scheme_menu.Append (Translations.GetString ("Light"), $"app.{ColorScheme.Name}(1)");
// Translators: This refers to using a dark variant of the color scheme.
color_scheme_menu.Append (Translations.GetString ("Dark"), $"app.{ColorScheme.Name}(2)");

Gio.Menu color_scheme_section = Gio.Menu.New ();
color_scheme_section.AppendSubmenu (Translations.GetString ("Color Scheme"), color_scheme_menu);

menu.AppendSection (null, zoom_section);
menu.AppendSection (null, grid_section);
menu.AppendSection (null, metric_section);
menu.AppendSection (null, show_hide_section);
menu.AppendSection (null, color_scheme_section);

app.AddCommands ([
ZoomIn,
Expand All @@ -276,7 +258,6 @@ public void RegisterActions (Gtk.Application app, Gio.Menu menu)

// TODO: Make `Command`s
app.AddAction (RulerMetric);
app.AddAction (ColorScheme);

if (mainToolbarPresent)
app.AddCommand (ToolBar);
Expand Down
14 changes: 14 additions & 0 deletions Pinta.Core/Managers/SettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@

namespace Pinta.Core;

public sealed class SettingChangedEventArgs (string key) : EventArgs
{
public string Key { get; } = key;
}

public interface ISettingsService
{
/// <summary>
Expand All @@ -57,6 +62,11 @@ public interface ISettingsService
/// a chance to call PutSetting to store setting.
/// </summary>
event EventHandler? SaveSettingsBeforeQuit;

/// <summary>
/// An event that is fired when a setting has been changed.
/// </summary>
event EventHandler<SettingChangedEventArgs>? SettingChanged;
}

public sealed class SettingsManager : ISettingsService
Expand All @@ -71,6 +81,8 @@ public sealed class SettingsManager : ISettingsService
/// </summary>
public event EventHandler? SaveSettingsBeforeQuit;

public event EventHandler<SettingChangedEventArgs>? SettingChanged;

public SettingsManager ()
{
var settings_file = Path.Combine (GetUserSettingsDirectory (), SETTINGS_FILE);
Expand Down Expand Up @@ -142,6 +154,8 @@ public T GetSetting<T> (string key, T defaultValue)
public void PutSetting (string key, object value)
{
settings[key] = value;

SettingChanged?.Invoke (this, new (key));
}

public void DoSaveSettingsBeforeQuit ()
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Resources/Icons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static class StandardIcons
public const string ImageGeneric = "image-x-generic-symbolic";
public const string ImageMissing = "image-missing-symbolic";

public const string KeyboardShortcuts = "preferences-system-symbolic";
public const string Preferences = "preferences-system-symbolic";

public const string LayerMoveUp = "pan-up-symbolic";
public const string LayerMoveDown = "pan-down-symbolic";
Expand Down
3 changes: 2 additions & 1 deletion Pinta/ActionHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public ActionHandlers ()
new PasteIntoNewImageAction (actions, chrome, workspace),
new ResizePaletteAction (actions.Edit, chrome, palette),
new AddinManagerAction (actions.Addins, chrome, system),
new PreferencesDialogAction(actions.App, chrome, settings),

// Image
new ResizeImageAction (actions.Image, chrome, workspace, settings),
Expand All @@ -84,7 +85,7 @@ public ActionHandlers ()
new ToolWindowsToggledAction (actions.View, chrome),
new StatusBarToggledAction (actions.View, chrome),
new ToolBoxToggledAction (actions.View, chrome),
new ColorSchemeChangedAction (actions.View),
new ColorSchemeChangedAction (settings),
new EditCanvasGridAction (actions.View, chrome, canvasGrid),

// Window
Expand Down
37 changes: 37 additions & 0 deletions Pinta/Actions/Edit/PreferencesDialogAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
namespace Pinta.Actions;

using System;
using Pinta.Core;

internal sealed class PreferencesDialogAction : IActionHandler
{
private readonly AppActions app;
private readonly IChromeService chrome;
private readonly ISettingsService settings;

internal PreferencesDialogAction (
AppActions app,
IChromeService chrome,
ISettingsService settings)
{
this.app = app;
this.chrome = chrome;
this.settings = settings;
}

void IActionHandler.Initialize ()
{
app.Preferences.Activated += Activated;
}

void IActionHandler.Uninitialize ()
{
app.Preferences.Activated -= Activated;
}

private void Activated (object sender, EventArgs e)
{
using PreferencesDialog dialog = PreferencesDialog.New (settings);
dialog.Present (chrome.MainWindow);
}
}
21 changes: 13 additions & 8 deletions Pinta/Actions/View/ColorSchemeChangedAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,32 @@ namespace Pinta.Actions;

internal sealed class ColorSchemeChangedAction : IActionHandler
{
private readonly ViewActions view;
internal ColorSchemeChangedAction (ViewActions view)
private readonly ISettingsService settings;
internal ColorSchemeChangedAction (ISettingsService settings)
{
this.view = view;
this.settings = settings;
}

void IActionHandler.Initialize ()
{
view.ColorScheme.OnActivate += Activated;
settings.SettingChanged += OnSettingChanged;

// Load the initial color scheme setting.
OnSettingChanged (null, new (SettingNames.COLOR_SCHEME));
}

void IActionHandler.Uninitialize ()
{
view.ColorScheme.OnActivate -= Activated;
settings.SettingChanged -= OnSettingChanged;
}

private void Activated (SimpleAction action, SimpleAction.ActivateSignalArgs args)
private void OnSettingChanged (object? sender, SettingChangedEventArgs e)
{
action.ChangeState (args.Parameter!);
if (e.Key != SettingNames.COLOR_SCHEME)
return;

Adw.ColorScheme scheme = args.Parameter!.GetInt32 () switch {
int schemeIndex = PintaCore.Settings.GetSetting (SettingNames.COLOR_SCHEME, 0);
Adw.ColorScheme scheme = schemeIndex switch {
1 => Adw.ColorScheme.ForceLight,
2 => Adw.ColorScheme.ForceDark,
_ => Adw.ColorScheme.Default,
Expand Down
44 changes: 44 additions & 0 deletions Pinta/Dialogs/PreferencesDialog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using GObject;

namespace Pinta;

using Pinta.Core;

[GObject.Subclass<Adw.PreferencesDialog> (qualifiedName: nameof (PreferencesDialog))]
[Gtk.Template<Gtk.AssemblyResource> ("PreferencesDialog.ui")]
internal sealed partial class PreferencesDialog
{
private ISettingsService settings = null!; // NRT - set by factory method

[Gtk.Connect ("color_scheme_comborow")]
private Adw.ComboRow color_scheme_row;

public static PreferencesDialog New (ISettingsService settings)
{
PreferencesDialog dialog = NewWithProperties ([]);
dialog.LoadSettings (settings);
return dialog;
}

partial void Initialize ()
{
Adw.ComboRow.SelectedPropertyDefinition.Notify (color_scheme_row, OnColorSchemeChanged);
}

/// <summary>
/// Initialize the UI widgets from the existing settings.
/// </summary>
private void LoadSettings (ISettingsService settingsService)
{
settings = settingsService;

int schemeIndex = settings.GetSetting (SettingNames.COLOR_SCHEME, 0);
color_scheme_row.SetSelected ((uint) schemeIndex);
}

private void OnColorSchemeChanged (Object sender, NotifySignalArgs args)
{
int schemeIndex = (int) color_scheme_row.Selected;
settings.PutSetting (SettingNames.COLOR_SCHEME, schemeIndex);
}
}
Loading
Loading