Skip to content
Merged
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
6 changes: 3 additions & 3 deletions Pinta.Core/Actions/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public ToggleCommand (string name, string label, string? tooltip, string? stock_
{
Activated += (o, args) => {
bool active = !State.GetBoolean ();
Toggled?.Invoke (active);
Toggled?.Invoke (active, interactive: true);
Action.ChangeState (GLib.Variant.NewBoolean (active));
};
}
Expand All @@ -100,13 +100,13 @@ public bool Value {
get => State.GetBoolean ();
set {
if (value != Value) {
Toggled?.Invoke (value);
Toggled?.Invoke (value, interactive: false);
Action.ChangeState (GLib.Variant.NewBoolean (value));
}
}
}

public delegate void ToggledHandler (bool value);
public delegate void ToggledHandler (bool value, bool interactive);
public ToggledHandler? Toggled;

private GLib.Variant State => Action.GetState () ?? throw new InvalidOperationException ("Action should not be stateless!");
Expand Down
9 changes: 9 additions & 0 deletions Pinta.Core/Actions/ViewActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public sealed class ViewActions
public ToggleCommand ImageTabs { get; }
public ToggleCommand ToolWindows { get; }
public Command EditCanvasGrid { get; }
public ToggleCommand MenuBar { get; }
public ToggleCommand StatusBar { get; }
public ToggleCommand ToolBox { get; }
public ToggleCommand Rulers { get; }
Expand Down Expand Up @@ -124,6 +125,12 @@ public ViewActions (ChromeManager chrome, WorkspaceManager workspace)
null,
Resources.Icons.ViewGrid);

MenuBar = new ToggleCommand (
"MenuBar",
Translations.GetString ("Menu Bar"),
null,
null);

StatusBar = new ToggleCommand (
"Statusbar",
Translations.GetString ("Status Bar"),
Expand Down Expand Up @@ -226,6 +233,7 @@ public void RegisterActions (Gtk.Application app, Gio.Menu menu)

Gio.Menu show_hide_menu = Gio.Menu.New ();
show_hide_menu.AppendItem (Rulers.CreateMenuItem ());
show_hide_menu.AppendItem (MenuBar.CreateMenuItem ());
show_hide_menu.AppendItem (StatusBar.CreateMenuItem ());
show_hide_menu.AppendItem (ToolBox.CreateMenuItem ());
show_hide_menu.AppendItem (ImageTabs.CreateMenuItem ());
Expand Down Expand Up @@ -260,6 +268,7 @@ public void RegisterActions (Gtk.Application app, Gio.Menu menu)
Fullscreen,
EditCanvasGrid,
Rulers,
MenuBar,
StatusBar,
ToolBox,
ImageTabs,
Expand Down
1 change: 1 addition & 0 deletions Pinta/ActionHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public ActionHandlers ()
new RotateZoomLayerAction (chrome, actions.Layers, workspace, tools),

// View
new MenuBarToggledAction (actions.View, chrome),
new ToolBarToggledAction (actions.View, chrome),
new ImageTabsToggledAction (actions.View, chrome),
new ToolWindowsToggledAction (actions.View, chrome),
Expand Down
2 changes: 1 addition & 1 deletion Pinta/Actions/View/ImageTabsToggledAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void IActionHandler.Uninitialize ()
view.ImageTabs.Toggled -= Activated;
}

private void Activated (bool value)
private void Activated (bool value, bool interactive)
{
var notebook = (Docking.DockNotebook) chrome.ImageTabsNotebook;
notebook.EnableTabs = value;
Expand Down
43 changes: 43 additions & 0 deletions Pinta/Actions/View/MenuBarToggledAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Gio;
using Pinta.Core;

namespace Pinta.Actions;

internal sealed class MenuBarToggledAction : IActionHandler
{
private readonly ViewActions view;
private readonly ChromeManager chrome;

internal MenuBarToggledAction (
ViewActions view,
ChromeManager chrome)
{
this.view = view;
this.chrome = chrome;
}

void IActionHandler.Initialize ()
{
view.MenuBar.Toggled += Activated;
}

void IActionHandler.Uninitialize ()
{
view.MenuBar.Toggled -= Activated;
}

private async void Activated (bool value, bool interactive)
{
if (!interactive)
return;

// Changing the setting requires a restart since the application window is
// constructed differently (see WindowShell). Only show this when the user
// changes the option, not when the setting is loaded on startup!
await chrome.ShowMessageDialog (
chrome.MainWindow,
Translations.GetString ("Restart Pinta"),
Translations.GetString ("Please restart Pinta for the changes to take effect."));
}
}

2 changes: 1 addition & 1 deletion Pinta/Actions/View/StatusBarToggledAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void IActionHandler.Uninitialize ()
view.StatusBar.Toggled -= Activated;
}

private void Activated (bool value)
private void Activated (bool value, bool interactive)
{
chrome.StatusBar.Visible = value;
}
Expand Down
2 changes: 1 addition & 1 deletion Pinta/Actions/View/ToolBarToggledAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void IActionHandler.Uninitialize ()
view.ToolBar.Toggled -= Activated;
}

private void Activated (bool value)
private void Activated (bool value, bool interactive)
{
if (chrome.MainToolBar is not null)
chrome.MainToolBar.Visible = value;
Expand Down
2 changes: 1 addition & 1 deletion Pinta/Actions/View/ToolBoxToggledAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void IActionHandler.Uninitialize ()
view.ToolBox.Toggled -= Activated;
}

private void Activated (bool value)
private void Activated (bool value, bool interactive)
{
chrome.ToolBox.Visible = value;
}
Expand Down
4 changes: 1 addition & 3 deletions Pinta/Actions/View/ToolWindowsToggledAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ void IActionHandler.Uninitialize ()
view.ToolWindows.Toggled -= Activated;
}

private void Activated (bool value)
private void Activated (bool value, bool interactive)
{
var dock = (Docking.Dock) chrome.Dock;
dock.RightPanel.Visible = value;

System.Console.WriteLine ($"visible {value}");
}
}
2 changes: 2 additions & 0 deletions Pinta/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ private static void OpenMainWindow (int threads, IEnumerable<string> files, bool
if (threads > 0)
PintaCore.System.RenderThreads = threads;

app.OnStartup += (_, _) => main_window.Startup ();

app.OnActivate += (_, _) => {
main_window.Activate ();
OpenFilesFromCommandLine (files);
Expand Down
Loading