Skip to content

Commit

Permalink
Merge pull request #2 from PintaProject/master
Browse files Browse the repository at this point in the history
Updating fork
  • Loading branch information
thekolian1996 authored Sep 7, 2020
2 parents 0fc7593 + ea2df81 commit 39cc8f1
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ Thanks to the following contributors who worked on this release:
- @cameronwhite
- @darkdragon-001
- @JamiKettunen
- @thekolian1996

### Added
- The canvas can now be scrolled horizontally by holding Shift while using the mouse wheel (#141)
- Added a more user-friendly dialog when attempting to open an unsupported file format (#143, [#1856821](https://bugs.launchpad.net/pinta/+bug/1856821))

### Changed

Expand Down
12 changes: 12 additions & 0 deletions Pinta.Core/Managers/ChromeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class ChromeManager
private MenuBar main_menu;
private Toolbar main_toolbar;
private ErrorDialogHandler error_dialog_handler;
private UnsupportedFormatDialogHandler unsupported_format_dialog_handler;

public Toolbar ToolToolBar { get { return tool_toolbar; } }
public Toolbar MainToolBar { get { return main_toolbar; } }
Expand Down Expand Up @@ -108,11 +109,21 @@ public void InitializeErrorDialogHandler (ErrorDialogHandler handler)
error_dialog_handler = handler;
}

public void InitializeUnsupportedFormatDialog (UnsupportedFormatDialogHandler handler)
{
unsupported_format_dialog_handler = handler;
}

public void ShowErrorDialog (Window parent, string message, string details)
{
error_dialog_handler (parent, message, details);
}

public void ShowUnsupportedFormatDialog (Window parent, string message, string details)
{
unsupported_format_dialog_handler (parent, message, details);
}

public void SetStatusBarText (string text)
{
OnStatusBarTextChanged (text);
Expand Down Expand Up @@ -150,4 +161,5 @@ public interface IProgressDialog
}

public delegate void ErrorDialogHandler(Window parent, string message, string details);
public delegate void UnsupportedFormatDialogHandler(Window parent, string message, string details);
}
25 changes: 24 additions & 1 deletion Pinta.Core/Managers/WorkspaceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ public bool OpenFile (string file, Window parent = null)
fileOpened = true;
} catch (UnauthorizedAccessException e) {
ShowOpenFileErrorDialog (parent, file, Catalog.GetString ("Permission denied"), e.ToString ());
} catch (FormatException e) {
ShowUnsupportedFormatDialog (parent, file, e.Message, e.ToString());
} catch (Exception e) {
ShowOpenFileErrorDialog (parent, file, e.Message, e.ToString ());
}
Expand Down Expand Up @@ -351,7 +353,28 @@ private void ShowOpenFileErrorDialog (Window parent, string filename, string pri
PintaCore.Chrome.ShowErrorDialog(parent, message, details);
}

#region Public Events
private void ShowUnsupportedFormatDialog (Window parent, string filename, string primaryText, string details)
{
string markup = "<span weight=\"bold\" size=\"larger\">{0}</span>\n\n{1}";

string secondaryText = string.Format(Catalog.GetString("Could not open file: {0}"), filename);
secondaryText += string.Format(Catalog.GetString($"{Environment.NewLine}{Environment.NewLine}Pinta supports the following file formats:{Environment.NewLine}"));
var extensions = from format in PintaCore.System.ImageFormats.Formats
where format.Importer != null
from extension in format.Extensions
where char.IsLower(extension.FirstOrDefault())
orderby extension
select extension;

foreach (var extension in extensions)
secondaryText += extension + ", ";
secondaryText = secondaryText.Substring(0, secondaryText.Length - 2);

string message = string.Format (markup, primaryText, secondaryText);
PintaCore.Chrome.ShowUnsupportedFormatDialog(parent, message, details);
}

#region Public Events
public event EventHandler ActiveDocumentChanged;
public event EventHandler<DocumentEventArgs> DocumentCreated;
public event EventHandler<DocumentEventArgs> DocumentOpened;
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Core/Pinta.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>

</ItemGroup>
<!-- Source files -->
<ItemGroup>
<Compile Include="Actions\AddinActions.cs" />
Expand Down
84 changes: 84 additions & 0 deletions Pinta/Dialogs/FileUnsupportedFormatDialog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//
// FileUnsupportedFormatDialog.cs
//
// Author:
// Mykola Franchuk <[email protected]>
//
// Copyright (c) 2020 Mykola Franchuk
//
// 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
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System;
using Gtk;
using Pinta.Core;

namespace Pinta
{
class FileUnsupportedFormatDialog : Gtk.Dialog
{
private Label description_label;

public FileUnsupportedFormatDialog(Window parent) : base("Pinta", parent, DialogFlags.Modal | DialogFlags.DestroyWithParent)
{
Build();

TransientFor = parent;
}

public void SetMessage(string message)
{
description_label.Markup = message;
}

private void Build()
{
var hbox = new HBox();
hbox.Spacing = 6;
hbox.BorderWidth = 12;

var error_icon = new Image();
error_icon.Pixbuf = PintaCore.Resources.GetIcon(Stock.DialogError, 32);
error_icon.Yalign = 0;
hbox.PackStart(error_icon, false, false, 0);

var vbox = new VBox();
vbox.Spacing = 6;

description_label = new Label();
description_label.Wrap = true;
description_label.Xalign = 0;
vbox.PackStart(description_label, false, false, 0);

hbox.Add(vbox);
this.VBox.Add(hbox);

//PintaCore.System.ImageFormats.Formats

var ok_button = new Button(Gtk.Stock.Ok);
ok_button.CanDefault = true;
AddActionWidget(ok_button, ResponseType.Ok);

DefaultWidth = 600;
DefaultHeight = 142;

ShowAll();
}

}
}
15 changes: 15 additions & 0 deletions Pinta/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,21 @@ public MainWindow ()
}
);

PintaCore.Chrome.InitializeUnsupportedFormatDialog((parent, message, details) => {
System.Console.Error.WriteLine("Pinta: {0}", details);
FileUnsupportedFormatDialog unsupportedFormDialog = new FileUnsupportedFormatDialog(parent);
try
{
unsupportedFormDialog.SetMessage(message);
unsupportedFormDialog.Run();
}
finally
{
unsupportedFormDialog.Destroy();
}
}
);

PintaCore.Initialize ();

// Initialize extensions
Expand Down
1 change: 1 addition & 0 deletions Pinta/Pinta.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<Compile Include="Dialogs\AboutDialog.cs" />
<Compile Include="Dialogs\AboutPintaTabPage.cs" />
<Compile Include="Dialogs\ErrorDialog.cs" />
<Compile Include="Dialogs\FileUnsupportedFormatDialog.cs" />
<Compile Include="Dialogs\JpegCompressionDialog.cs" />
<Compile Include="Dialogs\LayerPropertiesDialog.cs" />
<Compile Include="Dialogs\NewImageDialog.cs" />
Expand Down

0 comments on commit 39cc8f1

Please sign in to comment.