Merge branch 'master' into pre-commit

This commit is contained in:
Michael Becker 2021-05-21 19:50:26 -04:00
commit aadca49721
No known key found for this signature in database
GPG Key ID: 98C333A81F18C22C
26 changed files with 757 additions and 337 deletions

View File

@ -0,0 +1,87 @@
//
// Program.cs - the main entry point for the Universal Editor Extension Compiler
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// Copyright (c) 2020 Mike Becker's Software
//
// 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;
using System.Collections.Generic;
using UniversalEditor;
using UniversalEditor.Accessors;
using UniversalEditor.DataFormats.Package.OpenDocument;
using UniversalEditor.DataFormats.UEPackage;
using UniversalEditor.DataFormats.UEPackage.Binary;
using UniversalEditor.ObjectModels.Package;
using UniversalEditor.ObjectModels.UEPackage;
namespace UniversalEditor.Compiler
{
public class Program
{
public static void Main(string[] args)
{
Console.Error.WriteLine("uex started...");
List<string> listFileNames = new List<string>();
string outputFileName = "output.uex";
bool foundFileName = false;
for (int i = 0; i < args.Length; i++)
{
if (args[i].StartsWith("/") && !foundFileName)
{
if (args[i].StartsWith("/out:"))
{
outputFileName = args[i].Substring(5);
}
}
else
{
// is file name
foundFileName = true;
listFileNames.Add(args[i]);
}
}
PackageObjectModel ue = new PackageObjectModel();
OpenDocumentDataFormat odf = new OpenDocumentDataFormat();
System.Text.StringBuilder sb = new System.Text.StringBuilder();
int totalInstances = 0;
string exefilename = System.Environment.GetCommandLineArgs()[0];
string workingdir = System.IO.Path.GetDirectoryName(exefilename);
for (int i = 0; i < listFileNames.Count; i++)
{
string relpath = listFileNames[i];
if (relpath.StartsWith(workingdir))
{
relpath = relpath.Substring(workingdir.Length);
}
relpath = "Content/" + relpath;
byte[] filedata = System.IO.File.ReadAllBytes(listFileNames[i]);
ue.FileSystem.AddFile(relpath, filedata);
}
FileAccessor faout = new FileAccessor(outputFileName, true, true);
Document.Save(ue, odf, faout);
Console.Error.WriteLine("uex written to {0}!", outputFileName);
}
}
}

View File

@ -0,0 +1,46 @@
//
// AssemblyInfo.cs
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// Copyright (c) 2020 Mike Becker's Software
//
// 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.Reflection;
using System.Runtime.CompilerServices;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle("Mocha.Compiler")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Mike Becker's Software")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("Mike Becker's Software")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion("1.0.*")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

View File

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{5E639F63-97B0-4B34-8928-29A5A3C661F4}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>UniversalEditor.Compiler</RootNamespace>
<AssemblyName>uecc</AssemblyName>
<ReleaseVersion>4.0.2019.12</ReleaseVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\Output\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>..\..\Output\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\UniversalEditor\Libraries\UniversalEditor.Core\UniversalEditor.Core.csproj">
<Project>{2D4737E6-6D95-408A-90DB-8DFF38147E85}</Project>
<Name>UniversalEditor.Core</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\UniversalEditor\Libraries\UniversalEditor.Essential\UniversalEditor.Essential.csproj">
<Project>{30467E5C-05BC-4856-AADC-13906EF4CADD}</Project>
<Name>UniversalEditor.Essential</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -1,35 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.2 -->
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkWindow">
<property name="can_focus">False</property>
<child type="titlebar">
<placeholder/>
</child>
<property name="can-focus">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkPaned">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can-focus">True</property>
<property name="orientation">vertical</property>
<property name="position">240</property>
<property name="position_set">True</property>
<property name="wide_handle">True</property>
<property name="position-set">True</property>
<property name="wide-handle">True</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkDrawingArea" id="txtQuery">
<property name="name">MBS.Framework.UserInterface.Controls.SyntaxTextBox</property>
<property name="name">MBS.Framework.UserInterface.Controls.SyntaxTextBox.SyntaxTextBoxControl</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="can-focus">False</property>
</object>
<packing>
<property name="expand">True</property>
@ -46,26 +43,26 @@
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkNotebook">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can-focus">True</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<property name="can-focus">True</property>
<property name="shadow-type">in</property>
<child>
<object class="GtkTreeView" id="lvResults">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can-focus">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
@ -83,23 +80,23 @@
<child type="tab">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Results</property>
</object>
<packing>
<property name="tab_fill">False</property>
<property name="tab-fill">False</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkDrawingArea">
<property name="name">MBS.Framework.UserInterface.Controls.Label</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="can-focus">False</property>
</object>
<packing>
<property name="expand">True</property>
@ -115,12 +112,12 @@
<child type="tab">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Spatial Results</property>
</object>
<packing>
<property name="position">1</property>
<property name="tab_fill">False</property>
<property name="tab-fill">False</property>
</packing>
</child>
</object>

View File

@ -2,6 +2,20 @@
<!-- Generated with glade 3.22.2 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkTreeStore" id="tm">
<columns>
<!-- column-name colFileName -->
<column type="gchararray"/>
<!-- column-name colFileSize -->
<column type="gchararray"/>
<!-- column-name colFileType -->
<column type="gchararray"/>
<!-- column-name colFileDateModified -->
<column type="gchararray"/>
<!-- column-name colImage -->
<column type="GdkPixbuf"/>
</columns>
</object>
<object class="GtkWindow">
<property name="can_focus">False</property>
<child type="titlebar">
@ -45,6 +59,12 @@
<property name="title" translatable="yes">Name</property>
<property name="clickable">True</property>
<property name="reorderable">True</property>
<child>
<object class="GtkCellRendererPixbuf"/>
<attributes>
<attribute name="pixbuf">4</attribute>
</attributes>
</child>
<child>
<object class="GtkCellRendererText"/>
<attributes>
@ -107,16 +127,4 @@
</object>
</child>
</object>
<object class="GtkTreeStore" id="tm">
<columns>
<!-- column-name colFileName -->
<column type="gchararray"/>
<!-- column-name colFileSize -->
<column type="gchararray"/>
<!-- column-name colFileType -->
<column type="gchararray"/>
<!-- column-name colFileDateModified -->
<column type="gchararray"/>
</columns>
</object>
</interface>

View File

@ -94,8 +94,8 @@ namespace UniversalEditor.UserInterface.Controls
lv = new ListViewControl();
lv.Model = tm;
lv.Columns.Add (new ListViewColumnText (lv.Model.Columns [0], "Name"));
lv.Columns.Add (new ListViewColumnText (lv.Model.Columns [1], "Description"));
lv.Columns.Add(new ListViewColumn("Name", new CellRenderer[] { new CellRendererText(lv.Model.Columns[0]) }));
lv.Columns.Add(new ListViewColumn("Description", new CellRenderer[] { new CellRendererText(lv.Model.Columns[1]) }));
lv.HeaderStyle = ColumnHeaderStyle.None;
ctObjectModel.Controls.Add (lv, new BoxLayout.Constraints (true, true));

View File

@ -87,16 +87,19 @@ namespace UniversalEditor.UserInterface.Dialogs
private ObjectModel mvarObjectModel = null;
public ObjectModel ObjectModel { get { return mvarObjectModel; } set { mvarObjectModel = value; mvarInitialObjectModel = value; } }
public bool ObjectModelSelectionEnabled { get; set; } = true;
private DataFormat mvarInitialDataFormat = null;
private DataFormat mvarDataFormat = null;
public DataFormat DataFormat { get { return mvarDataFormat; } set { mvarDataFormat = value; mvarInitialDataFormat = value; } }
public bool DataFormatSelectionEnabled { get; set; } = true;
private Accessor mvarInitialAccesor = null;
private Accessor mvarAccessor = null;
public Accessor Accessor { get { return mvarAccessor; } set { mvarAccessor = value; mvarInitialAccesor = value; } }
public bool AccessorSelectionEnabled { get; set; } = true;
[EventHandler(nameof(cmdObjectModel), "Click")]
private void cmdObjectModel_Click(object sender, EventArgs e)
@ -198,6 +201,15 @@ namespace UniversalEditor.UserInterface.Dialogs
break;
}
}
cmdObjectModel.Enabled = cmdObjectModel.Enabled && ObjectModelSelectionEnabled;
txtObjectModel.Enabled = txtObjectModel.Enabled && ObjectModelSelectionEnabled;
cmdDataFormat.Enabled = cmdDataFormat.Enabled && DataFormatSelectionEnabled;
txtDataFormat.Enabled = txtDataFormat.Enabled && DataFormatSelectionEnabled;
cmdAccessor.Enabled = cmdAccessor.Enabled && AccessorSelectionEnabled;
txtAccessor.Enabled = txtAccessor.Enabled && AccessorSelectionEnabled;
}
private string DataFormatReferenceToString(DataFormatReference dfr)

View File

@ -353,7 +353,7 @@ namespace UniversalEditor.UserInterface.Editors.Database.Views
DefaultTreeModel tmResults = new DefaultTreeModel(list.ToArray());
for (int i = 0; i < db.Tables[0].Fields.Count; i++)
{
lvResults.Columns.Add(new ListViewColumnText(tmResults.Columns[i], db.Tables[0].Fields[i].Name));
lvResults.Columns.Add(new ListViewColumn(db.Tables[0].Fields[i].Name, new CellRenderer[] { new CellRendererText(tmResults.Columns[i]) }));
}
foreach (DatabaseRecord rec in db.Tables[0].Records)
{

View File

@ -38,6 +38,7 @@ using MBS.Framework;
using MBS.Framework.UserInterface.Controls;
using System.Text;
using System.Diagnostics.Contracts;
using MBS.Framework.UserInterface.Drawing;
namespace UniversalEditor.Editors.FileSystem
{
@ -48,6 +49,8 @@ namespace UniversalEditor.Editors.FileSystem
private DefaultTreeModel tm = null;
private TextBox txtPath;
private const int DELIVERED_COLUMNS_COUNT = 5;
[EventHandler(nameof(txtPath), "KeyDown")]
private void txtPath_KeyDown(object sender, KeyEventArgs e)
{
@ -337,7 +340,8 @@ namespace UniversalEditor.Editors.FileSystem
new TreeModelRowColumn(tm.Columns[0], f.Name),
new TreeModelRowColumn(tm.Columns[1], String.Format("{0} items", (f.Files.Count + f.Folders.Count))),
new TreeModelRowColumn(tm.Columns[2], "Folder"),
new TreeModelRowColumn(tm.Columns[3], now.ToString())
new TreeModelRowColumn(tm.Columns[3], now.ToString()),
new TreeModelRowColumn(tm.Columns[4], Image.FromStock(StockType.Folder, 16))
});
row.RowColumns[1].RawValue = (f.Folders.Count + f.Files.Count);
row.RowColumns[3].RawValue = now.ToBinary();
@ -606,7 +610,8 @@ namespace UniversalEditor.Editors.FileSystem
new TreeModelRowColumn(tm.Columns[0], f.Name),
new TreeModelRowColumn(tm.Columns[1], (f.Folders.Count + f.Files.Count).ToString() + " items"),
new TreeModelRowColumn(tm.Columns[2], "Folder"),
new TreeModelRowColumn(tm.Columns[3], "")
new TreeModelRowColumn(tm.Columns[3], ""),
new TreeModelRowColumn(tm.Columns[4], Image.FromStock(StockType.Folder, 16))
});
r.RowColumns[1].RawValue = (long)(f.Folders.Count + f.Files.Count);
r.RowColumns[3].RawValue = (long)0;
@ -633,14 +638,15 @@ namespace UniversalEditor.Editors.FileSystem
new TreeModelRowColumn(tm.Columns[0], f.Name),
new TreeModelRowColumn(tm.Columns[1], UserInterface.Common.FileInfo.FormatSize(f.Size)),
new TreeModelRowColumn(tm.Columns[2], "File"),
new TreeModelRowColumn(tm.Columns[3], f.ModificationTimestamp.ToString())
new TreeModelRowColumn(tm.Columns[3], f.ModificationTimestamp.ToString()),
new TreeModelRowColumn(tm.Columns[4], Image.FromStock(StockType.File, 16))
});
r.RowColumns[1].RawValue = f.Size;
r.RowColumns[3].RawValue = f.ModificationTimestamp.ToBinary();
for (int i = 0; i < fsom.AdditionalDetails.Count; i++)
{
r.RowColumns.Add(new TreeModelRowColumn(tm.Columns[4 + i], f.GetAdditionalDetail(fsom.AdditionalDetails[i].Name)));
r.RowColumns.Add(new TreeModelRowColumn(tm.Columns[DELIVERED_COLUMNS_COUNT + i], f.GetAdditionalDetail(fsom.AdditionalDetails[i].Name)));
}
}
r.SetExtraData<IFileSystemObject>("item", fso);
@ -769,14 +775,14 @@ namespace UniversalEditor.Editors.FileSystem
FileSystemObjectModel fsom = (ObjectModel as FileSystemObjectModel);
if (fsom == null) return;
for (int i = 4; i < tv.Columns.Count; i++)
for (int i = DELIVERED_COLUMNS_COUNT; i < tv.Columns.Count; i++)
{
tv.Columns.Remove(tv.Columns[i]);
}
for (int i = 0; i < fsom.AdditionalDetails.Count; i++)
{
tm.Columns.Add(new TreeModelColumn(typeof(string)));
tv.Columns.Add(new ListViewColumnText(tm.Columns[tm.Columns.Count - 1], fsom.AdditionalDetails[i].Title));
tv.Columns.Add(new ListViewColumn(fsom.AdditionalDetails[i].Title, new CellRenderer[] { new CellRendererText(tm.Columns[tm.Columns.Count - 1]) }));
}
tv.Model = tm;
@ -917,7 +923,7 @@ namespace UniversalEditor.Editors.FileSystem
if (!IsCreated) return;
for (int i = 4; i < tm.Columns.Count; i++)
for (int i = DELIVERED_COLUMNS_COUNT; i < tm.Columns.Count; i++)
{
tm.Columns.RemoveAt(i);
}

View File

@ -196,6 +196,7 @@ namespace UniversalEditor.UserInterface
{
Layout = new BoxLayout(Orientation.Vertical);
this.IconName = "universal-editor";
LogoutInhibitor = new Inhibitor(InhibitorType.SystemLogout, "There are unsaved documents", this);
this.CommandDisplayMode = CommandDisplayMode.CommandBar;
@ -215,7 +216,7 @@ namespace UniversalEditor.UserInterface
ListViewControl lvToolbox = new ListViewControl();
lvToolbox.RowActivated += LvToolbox_RowActivated;
lvToolbox.Model = tmToolbox;
lvToolbox.Columns.Add(new ListViewColumnText(tmToolbox.Columns[0], "Item"));
lvToolbox.Columns.Add(new ListViewColumn("Item", new CellRenderer[] { new CellRendererText(tmToolbox.Columns[0]) }));
lvToolbox.HeaderStyle = ColumnHeaderStyle.None;
AddPanel("Toolbox", DockingItemPlacement.Left, lvToolbox);
@ -1041,6 +1042,9 @@ namespace UniversalEditor.UserInterface
OpenFile(documents);
}
private Inhibitor LogoutInhibitor = null;
private int logoutInhibitorI = 0;
public void OpenFile(params Document[] documents)
{
foreach (Document doc in documents)
@ -1049,6 +1053,15 @@ namespace UniversalEditor.UserInterface
{
InitEditorPage(doc);
if (logoutInhibitorI == 0)
{
(Application.Instance as UIApplication).Inhibitors.Add(LogoutInhibitor);
}
logoutInhibitorI++;
if (doc == null)
continue;
if (doc.Accessor is FileAccessor)
{
// FIXME: support Accessors other than FileAccessor
@ -1171,8 +1184,12 @@ namespace UniversalEditor.UserInterface
{
if (document.IsSaved)
{
bool inputClosed = false;
if (document.InputAccessor != null && document.InputAccessor.IsOpen)
{
inputClosed = true;
document.InputAccessor.Close();
}
if (document.OutputAccessor is FileAccessor)
{
@ -1180,9 +1197,33 @@ namespace UniversalEditor.UserInterface
(document.OutputAccessor as FileAccessor).AllowWrite = true;
(document.OutputAccessor as FileAccessor).ForceOverwrite = true;
}
document.OutputAccessor.Open();
document.Save();
document.OutputAccessor.Close();
try
{
document.OutputAccessor.Open();
document.Save();
document.OutputAccessor.Close();
}
catch (UnauthorizedAccessException ex)
{
if (inputClosed)
{
if (document.InputAccessor is FileAccessor)
{
// FIXME: ewww
(document.InputAccessor as FileAccessor).AllowWrite = false;
(document.InputAccessor as FileAccessor).ForceOverwrite = false;
}
document.InputAccessor.Open();
}
switch (HandleUnauthorizedAccessException(document, ex))
{
case MultipleDocumentErrorHandling.CancelAll: return false;
case MultipleDocumentErrorHandling.CancelOne: return true;
case MultipleDocumentErrorHandling.Ignore: break;
}
}
DockingWindow di = dckContainer.Items[GetCurrentEditorPage()] as DockingWindow;
if (di != null)
@ -1271,7 +1312,20 @@ namespace UniversalEditor.UserInterface
page.Document.DataFormat = df;
page.Document.Accessor = accessor;
}
page.Document.Save();
try
{
page.Document.Save();
}
catch (UnauthorizedAccessException ex)
{
switch (HandleUnauthorizedAccessException(page.Document, ex))
{
case MultipleDocumentErrorHandling.CancelAll: return false;
case MultipleDocumentErrorHandling.CancelOne: return true;
case MultipleDocumentErrorHandling.Ignore: break;
}
}
GetCurrentEditor().Document = page.Document;
DockingWindow di = dckContainer.Items[page] as DockingWindow;
@ -1282,6 +1336,25 @@ namespace UniversalEditor.UserInterface
}
return true;
}
private MultipleDocumentErrorHandling HandleUnauthorizedAccessException(Document document, UnauthorizedAccessException ex)
{
DialogResult dr = MessageDialog.ShowDialog(String.Format("Cannot save the file in its current location. Would you like to choose another location?\r\n\r\n{0}", ex.Message), "Unauthorized", MessageDialogButtons.YesNoCancel, MessageDialogIcon.Warning);
if (dr == DialogResult.Yes)
{
SaveFileAs(document);
}
else if (dr == DialogResult.No)
{
return MultipleDocumentErrorHandling.CancelOne;
}
else if (dr == DialogResult.Cancel)
{
return MultipleDocumentErrorHandling.CancelAll;
}
return MultipleDocumentErrorHandling.Ignore;
}
public bool SaveFileAs(Accessor accessor, DataFormat df)
{
return SaveFileAs(accessor, df, GetCurrentEditor()?.ObjectModel);
@ -1376,6 +1449,12 @@ namespace UniversalEditor.UserInterface
dckContainer.Items.Remove(dw);
documentWindowCount--;
logoutInhibitorI--;
if (logoutInhibitorI == 0)
{
(Application.Instance as UIApplication).Inhibitors.Remove(LogoutInhibitor);
}
if (documentWindowCount == 0)
{
CloseWindow ();

View File

@ -0,0 +1,46 @@
//
// MultipleDocumentErrorHandling.cs
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// Copyright (c) 2021 Mike Becker's Software
//
// 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;
namespace UniversalEditor.UserInterface
{
/// <summary>
/// Describes the way in which to handle an <see cref="Exception" /> when
/// there are additional <see cref="Document" />s to be processed afterward.
/// </summary>
public enum MultipleDocumentErrorHandling
{
/// <summary>
/// Ignore the error for the current <see cref="Document" /> and proceed
/// to processing the next <see cref="Document" />.
/// </summary>
Ignore,
/// <summary>
/// Cancels the operation for a single <see cref="Document" />. Other
/// <see cref="Document" />s will continue to be processed.
/// </summary>
CancelOne,
/// <summary>
/// Cancels the entire operation, including any <see cref="Document" />s
/// that still have yet to be processed.
/// </summary>
CancelAll
}
}

View File

@ -23,7 +23,7 @@ namespace UniversalEditor.UserInterface.Panels
tm = new DefaultTreeModel(new Type[] { typeof(string) });
lv.Model = tm;
lv.HeaderStyle = ColumnHeaderStyle.None;
lv.Columns.Add(new ListViewColumnText(tm.Columns[0], "Item"));
lv.Columns.Add(new ListViewColumn("Item", new CellRenderer[] { new CellRendererText(tm.Columns[0]) }));
Controls.Add(lv, new BoxLayout.Constraints(true, true));
}

View File

@ -53,12 +53,12 @@ namespace UniversalEditor.UserInterface.Panels
tvErrorList.Model = tm;
tvErrorList.Columns.Add(new ListViewColumnText(tm.Columns[0], "Line"));
tvErrorList.Columns.Add(new ListViewColumnText(tm.Columns[1], "Description"));
tvErrorList.Columns.Add(new ListViewColumnText(tm.Columns[2], "File"));
tvErrorList.Columns.Add(new ListViewColumnText(tm.Columns[3], "Project"));
tvErrorList.Columns.Add(new ListViewColumnText(tm.Columns[4], "Path"));
tvErrorList.Columns.Add(new ListViewColumnText(tm.Columns[5], "Category"));
tvErrorList.Columns.Add(new ListViewColumn("Line", new CellRenderer[] { new CellRendererText(tm.Columns[0]) }));
tvErrorList.Columns.Add(new ListViewColumn("Description", new CellRenderer[] { new CellRendererText(tm.Columns[1]) } ));
tvErrorList.Columns.Add(new ListViewColumn("File", new CellRenderer[] { new CellRendererText(tm.Columns[2]) } ));
tvErrorList.Columns.Add(new ListViewColumn("Project", new CellRenderer[] { new CellRendererText(tm.Columns[3]) } ));
tvErrorList.Columns.Add(new ListViewColumn("Path", new CellRenderer[] { new CellRendererText(tm.Columns[4]) } ));
tvErrorList.Columns.Add(new ListViewColumn("Category", new CellRenderer[] { new CellRendererText(tm.Columns[5]) }));
(Application.Instance as IHostApplication).Messages.MessageAdded += (sender, e) =>
{

View File

@ -184,7 +184,7 @@ namespace UniversalEditor.UserInterface.Panels
tvSolutionExplorer.RowActivated += tvSolutionExplorer_RowActivated;
// (UniversalEditor.exe:24867): Gtk-CRITICAL **: 21:28:56.913: gtk_tree_store_set_value: assertion 'G_IS_VALUE (value)' failed
tvSolutionExplorer.Columns.Add(new ListViewColumnText(tmSolutionExplorer.Columns[0], "File Name"));
tvSolutionExplorer.Columns.Add(new ListViewColumn("File name", new CellRenderer[] { new CellRendererText(tmSolutionExplorer.Columns[0]) }));
this.Controls.Add(tvSolutionExplorer, new BoxLayout.Constraints(true, true));

View File

@ -136,6 +136,7 @@
<Compile Include="EditorChangingEvent.cs" />
<Compile Include="EditorPropertiesPanel.cs" />
<Compile Include="Editors\FileSystem\FileSystemEditorSettingsGuids.cs" />
<Compile Include="MultipleDocumentErrorHandling.cs" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">

View File

@ -148,7 +148,7 @@ namespace UniversalEditor.Editors.Contact
tmAddresses = new DefaultTreeModel(new Type[] { typeof(string) });
lvPhysicalAddresses = new ListViewControl();
lvPhysicalAddresses.Columns.Add(new ListViewColumnText(tmAddresses.Columns[0], "Address"));
lvPhysicalAddresses.Columns.Add(new ListViewColumn("Address", new CellRenderer[] { new CellRendererText(tmAddresses.Columns[0]) }));
lvPhysicalAddresses.Model = tmAddresses;
ct.Controls.Add(lvPhysicalAddresses, new BoxLayout.Constraints(true, true));
@ -167,7 +167,7 @@ namespace UniversalEditor.Editors.Contact
tmAddresses = new DefaultTreeModel(new Type[] { typeof(string) });
ListViewControl lvAddresses = new ListViewControl();
lvAddresses.Columns.Add(new ListViewColumnText(tmAddresses.Columns[0], "Address"));
lvAddresses.Columns.Add(new ListViewColumn("Address", new CellRenderer[] { new CellRendererText(tmAddresses.Columns[0]) }));
ct.Controls.Add(lvAddresses, new BoxLayout.Constraints(true, true));
StackSidebarPanel panel = new StackSidebarPanel();
@ -185,7 +185,7 @@ namespace UniversalEditor.Editors.Contact
tmAddresses = new DefaultTreeModel(new Type[] { typeof(string) });
ListViewControl lvAddresses = new ListViewControl();
lvAddresses.Columns.Add(new ListViewColumnText(tmAddresses.Columns[0], "Address"));
lvAddresses.Columns.Add(new ListViewColumn("Address", new CellRenderer[] { new CellRendererText(tmAddresses.Columns[0]) }));
ct.Controls.Add(lvAddresses, new BoxLayout.Constraints(true, true));
StackSidebarPanel panel = new StackSidebarPanel();

View File

@ -76,10 +76,10 @@ namespace UniversalEditor.Plugins.Executable.UserInterface.Editors.Executable
tvSections = new ListViewControl();
tvSections.Model = tmSections;
tvSections.Columns.Add(new ListViewColumnText(tmSections.Columns[0], "Name"));
tvSections.Columns.Add(new ListViewColumnText(tmSections.Columns[1], "Physical address"));
tvSections.Columns.Add(new ListViewColumnText(tmSections.Columns[2], "Virtual address"));
tvSections.Columns.Add(new ListViewColumnText(tmSections.Columns[3], "Size"));
tvSections.Columns.Add(new ListViewColumn("Name", new CellRenderer[] { new CellRendererText(tmSections.Columns[0]) }));
tvSections.Columns.Add(new ListViewColumn("Physical address", new CellRenderer[] { new CellRendererText(tmSections.Columns[1]) }));
tvSections.Columns.Add(new ListViewColumn("Virtual address", new CellRenderer[] { new CellRendererText(tmSections.Columns[2]) }));
tvSections.Columns.Add(new ListViewColumn("Size", new CellRenderer[] { new CellRendererText(tmSections.Columns[3]) }));
tvSections.BeforeContextMenu += tvSections_BeforeContextMenu;
tbs = new TabContainer();
@ -125,8 +125,8 @@ namespace UniversalEditor.Plugins.Executable.UserInterface.Editors.Executable
ListViewControl lvOtherInformation = new ListViewControl();
lvOtherInformation.Model = tmOtherInformation;
lvOtherInformation.Columns.Add(new ListViewColumnText(tmOtherInformation.Columns[0], "Name"));
lvOtherInformation.Columns.Add(new ListViewColumnText(tmOtherInformation.Columns[1], "Value"));
lvOtherInformation.Columns.Add(new ListViewColumn("Name", new CellRenderer[] { new CellRendererText(tmOtherInformation.Columns[0]) }));
lvOtherInformation.Columns.Add(new ListViewColumn("Value", new CellRenderer[] { new CellRendererText(tmOtherInformation.Columns[1]) }));
tabVersion.Controls.Add(lvOtherInformation, new GridLayout.Constraints(4, 0, 1, 2, ExpandMode.Both));
tbs.TabPages.Add(tabVersion);

View File

@ -260,8 +260,8 @@ namespace UniversalEditor.Plugins.Executable.UserInterface.Editors.Executable
tmTypes = new DefaultTreeModel(new Type[] { typeof(string), typeof(string) });
tvTypes.Model = tmTypes;
tvTypes.Columns.Add(new ListViewColumnText(tmTypes.Columns[0], "Name"));
tvTypes.Columns.Add(new ListViewColumnText(tmTypes.Columns[1], "Type"));
tvTypes.Columns.Add(new ListViewColumn("Name", new CellRenderer[] { new CellRendererText(tmTypes.Columns[0]) }));
tvTypes.Columns.Add(new ListViewColumn("Type", new CellRenderer[] { new CellRendererText(tmTypes.Columns[1]) }));
scLeftRight.Panel1.Controls.Add(tvTypes, new BoxLayout.Constraints(true, true));
scLeftRight.Panel2.Layout = new BoxLayout(Orientation.Vertical);

View File

@ -47,10 +47,10 @@ namespace UniversalEditor.Plugins.Multimedia.UserInterface.Editors.Multimedia.Au
lvSamples = new ListViewControl();
lvSamples.SelectionMode = SelectionMode.Multiple;
lvSamples.BeforeContextMenu += lvSamples_BeforeContextMenu;
lvSamples.Columns.Add(new ListViewColumnText(tmSamples.Columns[0], "Name"));
lvSamples.Columns.Add(new ListViewColumnText(tmSamples.Columns[1], "Frequency"));
lvSamples.Columns.Add(new ListViewColumnText(tmSamples.Columns[2], "Channels"));
lvSamples.Columns.Add(new ListViewColumnText(tmSamples.Columns[3], "Size"));
lvSamples.Columns.Add(new ListViewColumn("Name", new CellRenderer[] { new CellRendererText(tmSamples.Columns[0]) }));
lvSamples.Columns.Add(new ListViewColumn("Frequency", new CellRenderer[] { new CellRendererText(tmSamples.Columns[1]) }));
lvSamples.Columns.Add(new ListViewColumn("Channels", new CellRenderer[] { new CellRendererText(tmSamples.Columns[2]) }));
lvSamples.Columns.Add(new ListViewColumn("Size", new CellRenderer[] { new CellRendererText(tmSamples.Columns[3]) }));
lvSamples.Model = tmSamples;
Controls.Add(lvSamples, new BoxLayout.Constraints(true, true));

View File

@ -256,6 +256,16 @@ namespace UniversalEditor.Plugins.Multimedia.UserInterface.Editors.Multimedia.Pi
cmdSave.Enabled = coll.Pictures.Count > 0;
cmdSaveAll.Enabled = coll.Pictures.Count > 0;
txtQuickAnimateStartFrame.Minimum = 0;
txtQuickAnimateStartFrame.Maximum = coll.Pictures.Count - 1;
txtQuickAnimateStartFrame.Value = 0;
txtQuickAnimateEndFrame.Minimum = 0;
txtQuickAnimateEndFrame.Maximum = coll.Pictures.Count - 1;
txtQuickAnimateEndFrame.Value = coll.Pictures.Count - 1;
txtQuickAnimateFrameDuration.Value = 500;
if (coll.Pictures.Count > 0)
picFrame.ObjectModel = coll.Pictures[0];
}
@ -279,24 +289,27 @@ namespace UniversalEditor.Plugins.Multimedia.UserInterface.Editors.Multimedia.Pi
private UniversalEditor.Editors.Multimedia.Picture.PictureEditor picFrame = null;
[EventHandler(nameof(cmdSave), "Click")]
void CmdSave_Click(object sender, EventArgs e)
private void cmdSave_Click(object sender, EventArgs e)
{
PictureCollectionObjectModel coll = ObjectModel as PictureCollectionObjectModel;
if (SelectedFrameIndex < 0 || SelectedFrameIndex >= coll.Pictures.Count)
return;
FileDialog dlg = new FileDialog();
dlg.Mode = FileDialogMode.Save;
UniversalEditor.UserInterface.Dialogs.DocumentPropertiesDialog dlg = new UniversalEditor.UserInterface.Dialogs.DocumentPropertiesDialog();
dlg.ObjectModel = coll.Pictures[SelectedFrameIndex];
dlg.DataFormat = new BitmapDataFormat();
dlg.ObjectModelSelectionEnabled = false;
dlg.Mode = UniversalEditor.UserInterface.Dialogs.DocumentPropertiesDialogMode.Save;
if (dlg.ShowDialog() == DialogResult.OK)
{
PictureObjectModel pic = coll.Pictures[SelectedFrameIndex];
BitmapDataFormat bmp = new BitmapDataFormat();
FileAccessor fa = new FileAccessor(dlg.SelectedFileNames[dlg.SelectedFileNames.Count - 1]);
fa.AllowWrite = true;
fa.ForceOverwrite = true;
fa.Open();
Document.Save(pic, bmp, fa, true);
if (dlg.Accessor is FileAccessor)
{
// FIXME: this should not be necessary
(dlg.Accessor as FileAccessor).AllowWrite = true;
(dlg.Accessor as FileAccessor).ForceOverwrite = true;
}
Document.Save(dlg.ObjectModel, dlg.DataFormat, dlg.Accessor, true);
}
}
[EventHandler(nameof(cmdSaveAll), "Click")]

View File

@ -99,7 +99,7 @@ namespace UniversalEditor.Plugins.Scientific.UserInterface.Editors.DataSetCollec
for (int i = 0; i < ds.Dimensions; i++)
{
tv.Columns.Add(new ListViewColumnText(tm.Columns[i], i.ToString()));
tv.Columns.Add(new ListViewColumn(i.ToString(), new CellRenderer[] { new CellRendererText(tm.Columns[i]) }));
for (int j = 0; j < ds.Sizes[i]; j++)
{

View File

@ -45,5 +45,9 @@ namespace UniversalEditor.DataFormats.Multimedia.Picture.Targa
public List<int> ScanLineTable { get; } = new List<int>();
public List<Color> ColorCorrectionTable { get; } = new List<Color>();
public int AttributesType { get; set; } = 0;
public string AuthorName { get; set; } = null;
public string AuthorComments { get; set; } = null;
public string JobName { get; set; } = null;
}
}

View File

@ -0,0 +1,29 @@
//
// TargaFormatVersion.cs
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// Copyright (c) 2021 Mike Becker's Software
//
// 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;
namespace UniversalEditor.DataFormats.Multimedia.Picture.Targa
{
public enum TargaFormatVersion
{
Original = 100,
TrueVisionXFile = 200
}
}

View File

@ -45,16 +45,45 @@ namespace UniversalEditor.DataFormats.Multimedia.Picture.Targa
private const int EXTENSION_AREA_COLOR_CORRECTION_TABLE_VALUE_LENGTH = 41;
public TargaExtensionArea ExtensionArea { get; } = new TargaExtensionArea();
public TargaFirstPixelDestination PixelOrigin { get; } = TargaFirstPixelDestination.TopLeft;
public TargaFormatVersion FormatVersion { get; set; } = TargaFormatVersion.Original;
protected override DataFormatReference MakeReferenceInternal()
{
DataFormatReference dfr = base.MakeReferenceInternal();
dfr.Capabilities.Add(typeof(PictureObjectModel), DataFormatCapabilities.All);
dfr.ExportOptions.Add(new CustomOptionChoice(nameof(ImageType), "Image _type", true, new CustomOptionFieldChoice[]
{
new CustomOptionFieldChoice("Compressed grayscale", TargaImageType.CompressedGrayscale),
new CustomOptionFieldChoice("Compressed indexed", TargaImageType.CompressedIndexed),
new CustomOptionFieldChoice("Compressed true color", TargaImageType.CompressedTrueColor),
new CustomOptionFieldChoice("Uncompressed grayscale", TargaImageType.UncompressedGrayscale),
new CustomOptionFieldChoice("Uncompressed indexed", TargaImageType.UncompressedIndexed),
new CustomOptionFieldChoice("Uncompressed true color", TargaImageType.UncompressedTrueColor)
}));
dfr.ExportOptions.Add(new CustomOptionChoice(nameof(PixelDepth), "Pixel _depth", true, new CustomOptionFieldChoice[]
{
new CustomOptionFieldChoice("8bpp", (byte)8),
new CustomOptionFieldChoice("16bpp", (byte)16),
new CustomOptionFieldChoice("24bpp", (byte)24),
new CustomOptionFieldChoice("32bpp", (byte)32)
}));
dfr.ExportOptions.Add(new CustomOptionChoice(nameof(PixelOrigin), "Pixel o_rigin", true, new CustomOptionFieldChoice[]
{
new CustomOptionFieldChoice("Bottom-left", TargaFirstPixelDestination.BottomLeft),
new CustomOptionFieldChoice("Bottom-right", TargaFirstPixelDestination.BottomRight),
new CustomOptionFieldChoice("Top-left", TargaFirstPixelDestination.TopLeft),
new CustomOptionFieldChoice("Top-right", TargaFirstPixelDestination.TopRight)
}));
dfr.ExportOptions.Add(new CustomOptionChoice(nameof(FormatVersion), "Format _version", true, new CustomOptionFieldChoice[]
{
new CustomOptionFieldChoice("Original (100)", TargaFormatVersion.Original),
new CustomOptionFieldChoice("TrueVision-XFile (200)", TargaFormatVersion.TrueVisionXFile)
}));
dfr.ContentTypes.Add("image/x-targa");
dfr.ContentTypes.Add("image/x-tga");
return dfr;
}
public int FormatVersion { get; set; } = 100; // ORIGINAL_TGA
private int GetImageDataOffset(int colorMapLength, byte imageIDLength, byte colorMapEntrySize)
{
@ -110,9 +139,8 @@ namespace UniversalEditor.DataFormats.Multimedia.Picture.Targa
}
}
private int mvarPadding = 0;
public TargaImageType ImageType { get; set; } = TargaImageType.None;
public string ImageID { get; set; } = null;
protected override void LoadInternal(ref ObjectModel objectModel)
{
@ -141,7 +169,7 @@ namespace UniversalEditor.DataFormats.Multimedia.Picture.Targa
if (Signature == "TRUEVISION-XFILE")
{
// this is a NEW targa file.
FormatVersion = 200;
FormatVersion = TargaFormatVersion.TrueVisionXFile;
// set cursor to beginning of footer info
br.Accessor.Seek((-1 * FOOTER_BYTE_LENGTH), SeekOrigin.End);
@ -164,7 +192,7 @@ namespace UniversalEditor.DataFormats.Multimedia.Picture.Targa
else
{
// this is not an ORIGINAL targa file.
FormatVersion = 100;
FormatVersion = TargaFormatVersion.Original;
}
}
#endregion
@ -216,7 +244,7 @@ namespace UniversalEditor.DataFormats.Multimedia.Picture.Targa
// load ImageID value if any
if (imageIDLength > 0)
{
string ImageID = br.ReadNullTerminatedString(imageIDLength);
ImageID = br.ReadNullTerminatedString(imageIDLength);
}
imageDataOffset = GetImageDataOffset(colorMapLength, imageIDLength, colorMapEntrySize);
@ -234,52 +262,7 @@ namespace UniversalEditor.DataFormats.Multimedia.Picture.Targa
{
for (int i = 0; i < colorMapLength; i++)
{
int a = 0;
int r = 0;
int g = 0;
int b = 0;
// load each color map entry based on the ColorMapEntrySize value
switch (colorMapEntrySize)
{
case 15:
{
byte[] color15 = br.ReadBytes(2);
// remember that the bytes are stored in reverse order
pic.ColorMap.Add(GetColorFrom2Bytes(color15[1], color15[0]));
break;
}
case 16:
{
byte[] color16 = br.ReadBytes(2);
// remember that the bytes are stored in reverse order
pic.ColorMap.Add(GetColorFrom2Bytes(color16[1], color16[0]));
break;
}
case 24:
{
b = Convert.ToInt32(br.ReadByte());
g = Convert.ToInt32(br.ReadByte());
r = Convert.ToInt32(br.ReadByte());
pic.ColorMap.Add(Color.FromRGBAInt32(r, g, b));
break;
}
case 32:
{
a = Convert.ToInt32(br.ReadByte());
b = Convert.ToInt32(br.ReadByte());
g = Convert.ToInt32(br.ReadByte());
r = Convert.ToInt32(br.ReadByte());
pic.ColorMap.Add(Color.FromRGBAInt32(a, r, g, b));
break;
}
default:
{
throw new ArgumentOutOfRangeException("TargaImage only supports ColorMap Entry Sizes of 15, 16, 24 or 32 bits.");
}
}
pic.ColorMap.Add(DecodeColor(br, colorMapEntrySize));
}
}
else
@ -287,8 +270,6 @@ namespace UniversalEditor.DataFormats.Multimedia.Picture.Targa
throw new InvalidOperationException("Image Type requires a Color Map and Color Map Length is zero.");
}
}
}
else
{
@ -416,7 +397,7 @@ namespace UniversalEditor.DataFormats.Multimedia.Picture.Targa
// calculate the padding, in bytes, of the image
// number of bytes to add to make each row a 32bit aligned row
// padding in bytes
mvarPadding = intStride - ((((int)imageWidth * (int)PixelDepth) + 7) / 8);
int paddingLength = intStride - ((((int)imageWidth * (int)PixelDepth) + 7) / 8);
// get the image data bytes
byte[] bimagedata = null;
@ -431,7 +412,7 @@ namespace UniversalEditor.DataFormats.Multimedia.Picture.Targa
byte[] data = null;
// padding bytes
byte[] padding = new byte[mvarPadding];
byte[] padding = new byte[paddingLength];
System.IO.MemoryStream msData = null;
// seek to the beginning of the image data using the ImageDataOffset value
@ -616,34 +597,34 @@ namespace UniversalEditor.DataFormats.Multimedia.Picture.Targa
// get the image byte array
data = msData.ToArray();
}
int x = 0, y = 0;
for (int z = 0; z < data.Length; z += 3)
int x = 0, y = 0;
for (int z = 0; z < data.Length; z += 3)
{
int r = data[z + 2];
int g = data[z + 1];
int b = data[z];
int a = 255;
if (PixelDepth == 32)
{
int r = data[z + 2];
int g = data[z + 1];
int b = data[z];
int a = 255;
a = data[z + 3];
z++;
}
if (PixelDepth == 32)
Color color = Color.FromRGBAInt32(r, g, b, a);
pic.SetPixel(color, x, y);
x++;
if (x == imageWidth)
{
x = 0;
y++;
if (y == imageHeight)
{
a = data[z + 3];
z++;
}
Color color = Color.FromRGBAInt32(r, g, b, a);
pic.SetPixel(color, x, y);
x++;
if (x == imageWidth)
{
x = 0;
y++;
if (y == imageHeight)
{
break;
}
break;
}
}
}
@ -653,6 +634,42 @@ namespace UniversalEditor.DataFormats.Multimedia.Picture.Targa
#endregion
}
private Color DecodeColor(Reader br, byte colorMapEntrySize)
{
// load each color map entry based on the ColorMapEntrySize value
switch (colorMapEntrySize)
{
case 15:
{
byte[] color15 = br.ReadBytes(2);
// remember that the bytes are stored in reverse order
return GetColorFrom2Bytes(color15[1], color15[0]);
}
case 16:
{
byte[] color16 = br.ReadBytes(2);
// remember that the bytes are stored in reverse order
return GetColorFrom2Bytes(color16[1], color16[0]);
}
case 24:
{
int b = Convert.ToInt32(br.ReadByte());
int g = Convert.ToInt32(br.ReadByte());
int r = Convert.ToInt32(br.ReadByte());
return Color.FromRGBAInt32(r, g, b);
}
case 32:
{
int a = Convert.ToInt32(br.ReadByte());
int b = Convert.ToInt32(br.ReadByte());
int g = Convert.ToInt32(br.ReadByte());
int r = Convert.ToInt32(br.ReadByte());
return Color.FromRGBAInt32(a, r, g, b);
}
}
throw new ArgumentOutOfRangeException(nameof(colorMapEntrySize), "TargaImage only supports ColorMap Entry Sizes of 15, 16, 24 or 32 bits.");
}
private TargaFirstPixelDestination GetFirstPixelDestination(TargaVerticalTransferOrder verticalTransferOrder, TargaHorizontalTransferOrder horizontalTransferOrder)
{
if (verticalTransferOrder == TargaVerticalTransferOrder.Unknown || horizontalTransferOrder == TargaHorizontalTransferOrder.Unknown)
@ -715,61 +732,80 @@ namespace UniversalEditor.DataFormats.Multimedia.Picture.Targa
// return the resulting Color
return Color.FromRGBAInt32(r, g, b, a);
}
private static byte[] EncodeR5G5B5A1(Color color)
{
// FIXME: not implemented
ushort u = 0;
byte b1 = 0, b2 = 0;
b1 |= color.GetRedByte();
b1 <<= 5;
b1 |= color.GetGreenByte();
return new byte[] { b1, b2 };
}
protected override void SaveInternal(ObjectModel objectModel)
{
IO.Writer bw = base.Accessor.Writer;
PictureObjectModel pic = (objectModel as PictureObjectModel);
/*
#region Targa Header
{
// set the cursor at the beginning of the file.
br.Accessor.Seek(0, SeekOrigin.Begin);
// read the header properties from the file
byte imageIDLength = br.ReadByte();
bool colorMapEnabled = br.ReadBoolean();
mvarImageType = (TargaImageType)br.ReadByte();
short colorMapFirstEntryIndex = br.ReadInt16();
short colorMapLength = br.ReadInt16();
byte colorMapEntrySize = br.ReadByte();
short originX = br.ReadInt16();
short originY = br.ReadInt16();
imageWidth = br.ReadInt16();
imageHeight = br.ReadInt16();
pic.Width = imageWidth;
pic.Height = imageHeight;
mvarPixelDepth = br.ReadByte();
switch (mvarPixelDepth)
if (ImageID != null)
{
bw.WriteByte((byte)ImageID.Length);
}
else
{
bw.WriteByte(0);
}
bool colorMapEnabled = true;
bw.WriteBoolean(colorMapEnabled);
bw.WriteByte((byte)ImageType);
short colorMapFirstEntryIndex = 0;
bw.WriteInt16(colorMapFirstEntryIndex);
short colorMapLength = 0;
bw.WriteInt16(colorMapLength);
byte colorMapEntrySize = 0;
bw.WriteByte(colorMapEntrySize);
short originX = 0;
bw.WriteInt16(originX);
short originY = 0;
bw.WriteInt16(originY);
bw.WriteInt16((short)pic.Width);
bw.WriteInt16((short)pic.Height);
if (!(PixelDepth == 8 || PixelDepth == 16 || PixelDepth == 24 || PixelDepth == 32))
{
case 8:
case 16:
case 24:
case 32:
break;
default:
throw new InvalidOperationException("Targa image file format only supports 8, 16, 24, or 32 bit pixel depths");
}
bw.WriteByte(PixelDepth);
byte ImageDescriptor = GetImageDescriptor(0, PixelOrigin);
bw.WriteByte(ImageDescriptor);
// int attributeBits = ImageDescriptor.GetBits(0, 4);
byte ImageDescriptor = br.ReadByte();
int attributeBits = ImageDescriptor.GetBits(0, 4);
verticalTransferOrder = (TargaVerticalTransferOrder)ImageDescriptor.GetBits(5, 1);
horizontalTransferOrder = (TargaHorizontalTransferOrder)ImageDescriptor.GetBits(4, 1);
// verticalTransferOrder = (TargaVerticalTransferOrder)ImageDescriptor.GetBits(5, 1);
// horizontalTransferOrder = (TargaHorizontalTransferOrder)ImageDescriptor.GetBits(4, 1);
// load ImageID value if any
if (imageIDLength > 0)
if (ImageID != null)
{
string ImageID = br.ReadNullTerminatedString(imageIDLength);
bw.WriteNullTerminatedString(ImageID);
}
else
{
bw.WriteNullTerminatedString(String.Empty);
}
imageDataOffset = GetImageDataOffset(colorMapLength, imageIDLength, colorMapEntrySize);
#region Load Colormap
{
@ -778,71 +814,61 @@ namespace UniversalEditor.DataFormats.Multimedia.Picture.Targa
// image types. If color map is included for other file types we can ignore it.
if (colorMapEnabled)
{
if (mvarImageType == TargaImageType.UncompressedIndexed || mvarImageType == TargaImageType.CompressedIndexed)
if (ImageType == TargaImageType.UncompressedIndexed || ImageType == TargaImageType.CompressedIndexed)
{
if (colorMapLength > 0)
for (int i = 0; i < pic.ColorMap.Count; i++)
{
for (int i = 0; i < colorMapLength; i++)
// load each color map entry based on the ColorMapEntrySize value
switch (colorMapEntrySize)
{
int a = 0;
int r = 0;
int g = 0;
int b = 0;
// load each color map entry based on the ColorMapEntrySize value
switch (colorMapEntrySize)
case 15:
{
case 15:
{
byte[] color15 = br.ReadBytes(2);
// remember that the bytes are stored in reverse order
pic.ColorMap.Add(GetColorFrom2Bytes(color15[1], color15[0]));
break;
}
case 16:
{
byte[] color16 = br.ReadBytes(2);
// remember that the bytes are stored in reverse order
pic.ColorMap.Add(GetColorFrom2Bytes(color16[1], color16[0]));
break;
}
case 24:
{
b = Convert.ToInt32(br.ReadByte());
g = Convert.ToInt32(br.ReadByte());
r = Convert.ToInt32(br.ReadByte());
pic.ColorMap.Add(Color.FromRGBA(r, g, b));
break;
}
case 32:
{
a = Convert.ToInt32(br.ReadByte());
b = Convert.ToInt32(br.ReadByte());
g = Convert.ToInt32(br.ReadByte());
r = Convert.ToInt32(br.ReadByte());
pic.ColorMap.Add(Color.FromRGBA(a, r, g, b));
break;
}
default:
{
throw new ArgumentOutOfRangeException("TargaImage only supports ColorMap Entry Sizes of 15, 16, 24 or 32 bits.");
}
Console.Error.WriteLine("ERROR: TGA R5G5B5A1 not supported yet");
// byte[] color15 = EncodeR5G5B5A1(pic.ColorMap[i]);
// remember that the bytes are stored in reverse order
// bw.WriteBytes(new byte[] { color15[1], color15[0] });
bw.WriteBytes(new byte[] { 0, 0 });
break;
}
case 16:
{
Console.Error.WriteLine("ERROR: TGA R5G6B5 not supported yet");
// byte[] color16 = EncodeR5G6B5(pic.ColorMap[i]);
// remember that the bytes are stored in reverse order
// bw.WriteBytes(new byte[] { color15[1], color15[0] });
bw.WriteBytes(new byte[] { 0, 0 });
break;
}
case 24:
{
bw.WriteByte(pic.ColorMap[i].GetBlueByte());
bw.WriteByte(pic.ColorMap[i].GetGreenByte());
bw.WriteByte(pic.ColorMap[i].GetRedByte());
break;
}
case 32:
{
bw.WriteByte(pic.ColorMap[i].GetAlphaByte());
bw.WriteByte(pic.ColorMap[i].GetBlueByte());
bw.WriteByte(pic.ColorMap[i].GetGreenByte());
bw.WriteByte(pic.ColorMap[i].GetRedByte());
break;
}
default:
{
throw new ArgumentOutOfRangeException("TargaImage only supports ColorMap Entry Sizes of 15, 16, 24 or 32 bits.");
}
}
}
else
{
throw new InvalidOperationException("Image Type requires a Color Map and Color Map Length is zero.");
}
}
else
{
throw new InvalidOperationException("Image Type requires a Color Map and Color Map Length is zero.");
}
}
else
{
if (mvarImageType == TargaImageType.UncompressedIndexed || mvarImageType == TargaImageType.CompressedIndexed)
if (ImageType == TargaImageType.UncompressedIndexed || ImageType == TargaImageType.CompressedIndexed)
{
throw new InvalidOperationException("Indexed image type requires a colormap and there was not a colormap included in the file.");
}
@ -860,19 +886,15 @@ namespace UniversalEditor.DataFormats.Multimedia.Picture.Targa
// In your loop, you copy the pixels one scanline at a time and take into
// consideration the amount of padding that occurs due to memory alignment.
// calculate the stride, in bytes, of the image (32bit aligned width of each image row)
int intStride = (((int)pic.Width * (int)mvarPixelDepth + 31) & ~31) >> 3; // width in bytes
int intStride = (((int)pic.Width * (int)PixelDepth + 31) & ~31) >> 3; // width in bytes
// calculate the padding, in bytes, of the image
// number of bytes to add to make each row a 32bit aligned row
// padding in bytes
mvarPadding = intStride - ((((int)pic.Width * (int)mvarPixelDepth) + 7) / 8);
// get the image data bytes
byte[] bimagedata = null;
int paddingLength = intStride - ((((int)pic.Width * (int)PixelDepth) + 7) / 8);
#region Image Data Bytes
{
// read the image data into a byte array
// take into account stride has to be a multiple of 4
// use padding to make sure multiple of 4
@ -880,7 +902,7 @@ namespace UniversalEditor.DataFormats.Multimedia.Picture.Targa
byte[] data = null;
// padding bytes
byte[] padding = new byte[mvarPadding];
byte[] padding = new byte[paddingLength];
System.IO.MemoryStream msData = null;
// get the size in bytes of each row in the image
@ -893,8 +915,10 @@ namespace UniversalEditor.DataFormats.Multimedia.Picture.Targa
// is this a RLE compressed image type
#region COMPRESSED
if (mvarImageType == TargaImageType.CompressedGrayscale || mvarImageType == TargaImageType.CompressedIndexed || mvarImageType == TargaImageType.CompressedTrueColor)
if (ImageType == TargaImageType.CompressedGrayscale || ImageType == TargaImageType.CompressedIndexed || ImageType == TargaImageType.CompressedTrueColor)
{
Console.Error.WriteLine("ERROR: TGA RLE compression not implemented yet");
/*
// RLE Packet info
byte bRLEPacket = 0;
int intRLEPacketType = -1;
@ -970,26 +994,26 @@ namespace UniversalEditor.DataFormats.Multimedia.Picture.Targa
}
}
}
*/
}
#endregion
#region NON-COMPRESSED
else
{
// loop through each row in the image
for (int i = 0; i < (int)pic.Height; i++)
{
// create a new row
System.Collections.Generic.List<byte> row = new System.Collections.Generic.List<byte>();
List<byte> row = new List<byte>();
// loop through each byte in the row
for (int j = 0; j < intImageRowByteSize; j++)
for (int j = 0; j < (int)pic.Width; j++)
{
// add the byte to the row
row.Add(br.ReadByte());
}
Color color = pic.GetPixel(j, i);
// add row to the list of rows
row.Add(color.GetRedByte());
row.Add(color.GetGreenByte());
row.Add(color.GetBlueByte());
}
rows.Add(row);
}
}
@ -1003,7 +1027,7 @@ namespace UniversalEditor.DataFormats.Multimedia.Picture.Targa
// use FirstPixelDestination to determine the alignment of the
// image data byte
switch (GetFirstPixelDestination(verticalTransferOrder, horizontalTransferOrder))
switch (PixelOrigin)
{
case TargaFirstPixelDestination.TopLeft:
{
@ -1061,36 +1085,7 @@ namespace UniversalEditor.DataFormats.Multimedia.Picture.Targa
// get the image byte array
data = msData.ToArray();
int x = 0, y = 0;
for (int z = 0; z < data.Length; z += 3)
{
int r = data[z + 2];
int g = data[z + 1];
int b = data[z];
int a = 255;
if (mvarPixelDepth == 32)
{
a = data[z + 3];
z++;
}
Color color = Color.FromRGBA(a, r, g, b);
pic.SetPixel(color, x, y);
x++;
if (x == pic.Width)
{
x = 0;
y++;
if (y == pic.Height)
{
break;
}
}
}
bw.WriteBytes(data);
}
}
#endregion
@ -1099,60 +1094,61 @@ namespace UniversalEditor.DataFormats.Multimedia.Picture.Targa
#region Targa extension area
{
// is there an Extension Area in file
if (mvarExtensionArea.Enabled)
if (ExtensionArea.Enabled)
{
short extensionAreaSize = 164;
bw.Write(extensionAreaSize);
bw.WriteInt16(extensionAreaSize);
bw.WriteFixedLengthString(mvarExtensionArea.AuthorName, EXTENSION_AREA_AUTHOR_NAME_LENGTH);
bw.WriteFixedLengthString(mvarExtensionArea.AuthorComments, EXTENSION_AREA_AUTHOR_NAME_LENGTH);
bw.WriteFixedLengthString(ExtensionArea.AuthorName, EXTENSION_AREA_AUTHOR_NAME_LENGTH);
bw.WriteFixedLengthString(ExtensionArea.AuthorComments, EXTENSION_AREA_AUTHOR_NAME_LENGTH);
bw.Write((short)mvarExtensionArea.DateCreated.Month);
bw.Write((short)mvarExtensionArea.DateCreated.Day);
bw.Write((short)mvarExtensionArea.DateCreated.Year);
bw.Write((short)mvarExtensionArea.DateCreated.Hour);
bw.Write((short)mvarExtensionArea.DateCreated.Minute);
bw.Write((short)mvarExtensionArea.DateCreated.Second);
bw.WriteInt16((short)ExtensionArea.DateCreated.Month);
bw.WriteInt16((short)ExtensionArea.DateCreated.Day);
bw.WriteInt16((short)ExtensionArea.DateCreated.Year);
bw.WriteInt16((short)ExtensionArea.DateCreated.Hour);
bw.WriteInt16((short)ExtensionArea.DateCreated.Minute);
bw.WriteInt16((short)ExtensionArea.DateCreated.Second);
bw.WriteFixedLengthString(mvarExtensionArea.JobName, EXTENSION_AREA_JOB_NAME_LENGTH);
bw.WriteFixedLengthString(ExtensionArea.JobName, EXTENSION_AREA_JOB_NAME_LENGTH);
bw.Write((short)mvarExtensionArea.JobTime.Hours);
bw.Write((short)mvarExtensionArea.JobTime.Minutes);
bw.Write((short)mvarExtensionArea.JobTime.Seconds);
bw.WriteInt16((short)ExtensionArea.JobTime.Hours);
bw.WriteInt16((short)ExtensionArea.JobTime.Minutes);
bw.WriteInt16((short)ExtensionArea.JobTime.Seconds);
bw.WriteFixedLengthString(mvarExtensionArea.SoftwareID, EXTENSION_AREA_SOFTWARE_ID_LENGTH);
bw.WriteFixedLengthString(ExtensionArea.SoftwareID, EXTENSION_AREA_SOFTWARE_ID_LENGTH);
// get the version number and letter from file
float iVersionNumber = 1.0f;
short sVersionNumber = (short)(iVersionNumber * 100.0F);
bw.Write(sVersionNumber);
bw.Write((char)'A');
bw.WriteInt16(sVersionNumber);
bw.WriteChar((char)'A');
// bw.WriteFixedLengthString(mvarExtensionArea.VersionString.Substring(mvarExtensionArea.VersionString.Length - 1, 1));
// mvarExtensionArea.VersionString = (iVersionNumber.ToString(@"F2") + strVersionLetter);
// get the color key of the file
bw.Write((byte)(mvarExtensionArea.ColorKey.Alpha * 255));
bw.Write((byte)(mvarExtensionArea.ColorKey.Red * 255));
bw.Write((byte)(mvarExtensionArea.ColorKey.Blue * 255));
bw.Write((byte)(mvarExtensionArea.ColorKey.Green * 255));
bw.WriteByte((byte)(ExtensionArea.ColorKey.A * 255));
bw.WriteByte((byte)(ExtensionArea.ColorKey.R * 255));
bw.WriteByte((byte)(ExtensionArea.ColorKey.B * 255));
bw.WriteByte((byte)(ExtensionArea.ColorKey.G * 255));
bw.Write((short)mvarExtensionArea.PixelAspectRatioNumerator);
bw.Write((short)mvarExtensionArea.PixelAspectRatioDenominator);
bw.Write((short)mvarExtensionArea.GammaNumerator);
bw.Write((short)mvarExtensionArea.GammaDenominator);
bw.WriteInt16((short)ExtensionArea.PixelAspectRatioNumerator);
bw.WriteInt16((short)ExtensionArea.PixelAspectRatioDenominator);
bw.WriteInt16((short)ExtensionArea.GammaNumerator);
bw.WriteInt16((short)ExtensionArea.GammaDenominator);
int extensionAreaColorCorrectionOffset = 0;
bw.Write(extensionAreaColorCorrectionOffset);
bw.WriteInt32(extensionAreaColorCorrectionOffset);
int extensionAreaPostageStampOffset = 0;
bw.Write(extensionAreaPostageStampOffset);
bw.WriteInt32(extensionAreaPostageStampOffset);
int extensionAreaScanLineOffset = 0;
bw.Write(extensionAreaScanLineOffset);
bw.Write((byte)mvarExtensionArea.AttributesType);
bw.WriteInt32(extensionAreaScanLineOffset);
bw.WriteByte((byte)ExtensionArea.AttributesType);
// load Scan Line Table from file if any
/*
if (extensionAreaScanLineOffset > 0)
{
br.Accessor.Seek(extensionAreaScanLineOffset, SeekOrigin.Begin);
@ -1176,26 +1172,67 @@ namespace UniversalEditor.DataFormats.Multimedia.Picture.Targa
mvarExtensionArea.ColorCorrectionTable.Add(Color.FromRGBA(a, r, g, b));
}
}
*/
}
}
#endregion
#region Targa Footer
{
if (mvarFormatVersion == 200)
if (FormatVersion == TargaFormatVersion.TrueVisionXFile)
{
int extensionAreaOffset = 0;
bw.Write(extensionAreaOffset);
bw.WriteInt32(extensionAreaOffset);
int developerDirectoryOffset = 0;
bw.Write(developerDirectoryOffset);
bw.WriteInt32(developerDirectoryOffset);
bw.WriteFixedLengthString("TRUEVISION-XFILE");
}
}
#endregion
bw.Flush();
*/
throw new NotImplementedException();
}
private byte GetImageDescriptor(byte alphaChannelDepth, TargaFirstPixelDestination pixelOrigin)
{
TargaVerticalTransferOrder verticalTransferOrder = TargaVerticalTransferOrder.Unknown;
TargaHorizontalTransferOrder horizontalTransferOrder = TargaHorizontalTransferOrder.Unknown;
switch (PixelOrigin)
{
case TargaFirstPixelDestination.TopLeft:
{
verticalTransferOrder = TargaVerticalTransferOrder.TopToBottom;
horizontalTransferOrder = TargaHorizontalTransferOrder.LeftToRight;
break;
}
case TargaFirstPixelDestination.TopRight:
{
verticalTransferOrder = TargaVerticalTransferOrder.TopToBottom;
horizontalTransferOrder = TargaHorizontalTransferOrder.RightToLeft;
break;
}
case TargaFirstPixelDestination.BottomLeft:
{
verticalTransferOrder = TargaVerticalTransferOrder.BottomToTop;
horizontalTransferOrder = TargaHorizontalTransferOrder.LeftToRight;
break;
}
case TargaFirstPixelDestination.BottomRight:
{
verticalTransferOrder = TargaVerticalTransferOrder.BottomToTop;
horizontalTransferOrder = TargaHorizontalTransferOrder.RightToLeft;
break;
}
}
return GetImageDescriptor(alphaChannelDepth, verticalTransferOrder, horizontalTransferOrder);
}
private byte GetImageDescriptor(byte alphaChannelDepth, TargaVerticalTransferOrder verticalTransferOrder, TargaHorizontalTransferOrder horizontalTransferOrder)
{
byte ImageDescriptor = 0;
return ImageDescriptor;
}
}
}

View File

@ -340,6 +340,7 @@
<Compile Include="DataFormats\Multimedia\Palette\Adobe\ACO\ACODataFormat.cs" />
<Compile Include="DataFormats\Multimedia\Palette\Adobe\ACT\ACTDataFormat.cs" />
<Compile Include="DataFormats\Multimedia\Palette\Adobe\SwatchExchange\ASEDataFormat.cs" />
<Compile Include="DataFormats\Multimedia\Picture\Targa\TargaFormatVersion.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Libraries\UniversalEditor.Compression\UniversalEditor.Compression.csproj">

View File

@ -207,6 +207,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.Plugins.Blo
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.Plugins.AutoSave", "Plugins\UniversalEditor.Plugins.AutoSave\UniversalEditor.Plugins.AutoSave.csproj", "{385AB5A6-3EB6-4DF6-A7BF-DF9FFE43F192}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.Compiler", "Applications\UniversalEditor.Compiler\UniversalEditor.Compiler.csproj", "{5E639F63-97B0-4B34-8928-29A5A3C661F4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -599,6 +601,10 @@ Global
{385AB5A6-3EB6-4DF6-A7BF-DF9FFE43F192}.Debug|Any CPU.Build.0 = Debug|Any CPU
{385AB5A6-3EB6-4DF6-A7BF-DF9FFE43F192}.Release|Any CPU.ActiveCfg = Release|Any CPU
{385AB5A6-3EB6-4DF6-A7BF-DF9FFE43F192}.Release|Any CPU.Build.0 = Release|Any CPU
{5E639F63-97B0-4B34-8928-29A5A3C661F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5E639F63-97B0-4B34-8928-29A5A3C661F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5E639F63-97B0-4B34-8928-29A5A3C661F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5E639F63-97B0-4B34-8928-29A5A3C661F4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{6F0AB1AF-E1A1-4D19-B19C-05BBB15C94B2} = {05D15661-E684-4EC9-8FBD-C014BA433CC5}
@ -697,6 +703,7 @@ Global
{C54F6BCD-60CD-4603-B0C9-CD0864455CB1} = {2ED32D16-6C06-4450-909A-40D32DA67FB4}
{B6E600F5-E5BC-4DC2-8B41-7B11EB0A11B3} = {7B535D74-5496-4802-B809-89ED88274A91}
{385AB5A6-3EB6-4DF6-A7BF-DF9FFE43F192} = {2ED32D16-6C06-4450-909A-40D32DA67FB4}
{5E639F63-97B0-4B34-8928-29A5A3C661F4} = {05D15661-E684-4EC9-8FBD-C014BA433CC5}
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
Policies = $0