Skip to content

Commit

Permalink
Merge pull request #1274 from stevencohn/1273-scope-images-to-edit
Browse files Browse the repository at this point in the history
Logically collect images to adjust
  • Loading branch information
stevencohn authored Jan 20, 2024
2 parents d5a45f5 + 729a064 commit aca4db3
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 33 deletions.
51 changes: 44 additions & 7 deletions OneMore/Commands/Images/AdjustImagesCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ namespace River.OneMoreAddIn.Commands
/// </summary>
internal class AdjustImagesCommand : Command
{
private bool scopeFore;


public AdjustImagesCommand()
{
}
Expand All @@ -28,27 +31,57 @@ public override async Task Execute(params object[] args)
{
using var one = new OneNote(out var page, out var ns, OneNote.PageDetail.All);

// starting at Outline should exclude all background images
// find selected foreground images
var elements = page.Root
.Elements(ns + "Outline")
.Descendants(ns + "Image")?
.Where(e => e.Attribute("selected")?.Value == "all")
.ToList();

if ((elements == null) || !elements.Any())
if (elements.Any())
{
scopeFore = true;
}
else
{
// else find selected background images
elements = page.Root
.Elements(ns + "Outline").Descendants(ns + "Image")
.Elements(ns + "Image")
.Where(e => e.Attribute("selected")?.Value == "all")
.ToList();

if (elements.Any())
{
scopeFore = false;
}
else
{
// else find all foreground images
elements = page.Root
.Elements(ns + "Outline")
.Descendants(ns + "Image")
.ToList();

if (elements.Any())
{
scopeFore = true;
}
else
{
// else find all background images
elements = page.Root.Elements(ns + "Image").ToList();
scopeFore = false;
}
}
}

if (elements.Any())
if (elements != null && elements.Any())
{
var updated = elements.Count == 1
// single selected image
? ResizeOne(elements[0])
// multiple selections or all if none selected
: ResizeMany(elements, page, page.Root.Elements(ns + "Image").Any());
: ResizeMany(elements, page);

if (updated)
{
Expand Down Expand Up @@ -83,9 +116,13 @@ private bool ResizeOne(XElement element)
}


private bool ResizeMany(IEnumerable<XElement> elements, Page page, bool hasBgImages)
private bool ResizeMany(List<XElement> elements, Page page)
{
using var dialog = new AdjustImagesDialog(hasBgImages);
using var dialog = new AdjustImagesDialog()
{
ForegroundImages = scopeFore,
ImageCount = elements.Count
};

var result = dialog.ShowDialog(owner);
if (result != DialogResult.OK)
Expand Down
18 changes: 15 additions & 3 deletions OneMore/Commands/Images/AdjustImagesDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal partial class AdjustImagesDialog : UI.LocalizableForm
/// Initializes a new dialog to resize all images on the page to a standard width
/// and height with respective ratio
/// </summary>
public AdjustImagesDialog(bool hasBackgroundImages)
public AdjustImagesDialog()
{
Initialize();

Expand All @@ -45,6 +45,7 @@ public AdjustImagesDialog(bool hasBackgroundImages)
// hide controls that do not apply...

viewSizeLabel.Text = Resx.AdjustImagesDialog_appliesTo;

allLabel.Location = viewSizeLink.Location;
allLabel.Visible = true;

Expand All @@ -69,7 +70,7 @@ public AdjustImagesDialog(bool hasBackgroundImages)
presetRadio.Checked = true;
RadioClick(presetRadio, null);

repositionBox.Visible = hasBackgroundImages;
repositionBox.Visible = !ForegroundImages;

scaling = null;

Expand Down Expand Up @@ -127,7 +128,6 @@ private void Initialize()
"viewSizeLabel",
"imageSizeLabel",
"storageLabel=word_Storage",
"allLabel",
"limitsBox",
"autoSizeRadio",
"pctRadio",
Expand Down Expand Up @@ -216,13 +216,25 @@ private void LoadSettings(bool oneImage)
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);

if (allLabel.Visible)
{
allLabel.Text = string.Format(ForegroundImages
? Resx.AdjustImagesDialog_allLabelForeground
: Resx.AdjustImagesDialog_allLabelBackground, ImageCount);
}

suspended = false;
}
#endregion Lifecycle


// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

public bool ForegroundImages { private get; set; }

public int ImageCount { private get; set; }

public bool RepositionImages => repositionBox.Checked;


Expand Down
15 changes: 12 additions & 3 deletions OneMore/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions OneMore/Properties/Resources.ar-SA.resx
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,12 @@
<value>مطلق</value>
<comment>radio button</comment>
</data>
<data name="AdjustImagesDialog_allLabel.Text" xml:space="preserve">
<value>جميع الصور في هذه الصفحة</value>
<data name="AdjustImagesDialog_allLabelBackground" xml:space="preserve">
<value>{0} صور خلفية</value>
<comment>info label</comment>
</data>
<data name="AdjustImagesDialog_allLabelForeground" xml:space="preserve">
<value>{0} الصور الأمامية</value>
<comment>info label</comment>
</data>
<data name="AdjustImagesDialog_appliesTo" xml:space="preserve">
Expand Down
8 changes: 6 additions & 2 deletions OneMore/Properties/Resources.de-DE.resx
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,12 @@
<value>Absolut</value>
<comment>radio button</comment>
</data>
<data name="AdjustImagesDialog_allLabel.Text" xml:space="preserve">
<value>alle Bilder auf dieser Seite</value>
<data name="AdjustImagesDialog_allLabelBackground" xml:space="preserve">
<value>{0} Hintergrundbilder</value>
<comment>info label</comment>
</data>
<data name="AdjustImagesDialog_allLabelForeground" xml:space="preserve">
<value>{0} Vordergrundbilder</value>
<comment>info label</comment>
</data>
<data name="AdjustImagesDialog_appliesTo" xml:space="preserve">
Expand Down
8 changes: 6 additions & 2 deletions OneMore/Properties/Resources.es-ES.resx
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,12 @@ OneNote se cerrará automáticamente</value>
<value>Absoluto</value>
<comment>radio button</comment>
</data>
<data name="AdjustImagesDialog_allLabel.Text" xml:space="preserve">
<value>todas las imágenes en esta página</value>
<data name="AdjustImagesDialog_allLabelBackground" xml:space="preserve">
<value>{0} imágenes de fondo</value>
<comment>info label</comment>
</data>
<data name="AdjustImagesDialog_allLabelForeground" xml:space="preserve">
<value>{0} imágenes de primer plano</value>
<comment>info label</comment>
</data>
<data name="AdjustImagesDialog_appliesTo" xml:space="preserve">
Expand Down
8 changes: 6 additions & 2 deletions OneMore/Properties/Resources.fr-FR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,12 @@
<value>Absolu</value>
<comment>radio button</comment>
</data>
<data name="AdjustImagesDialog_allLabel.Text" xml:space="preserve">
<value>toutes les images sur cette page</value>
<data name="AdjustImagesDialog_allLabelBackground" xml:space="preserve">
<value>{0} images d'arrière-plan</value>
<comment>info label</comment>
</data>
<data name="AdjustImagesDialog_allLabelForeground" xml:space="preserve">
<value>{0} images de premier plan</value>
<comment>info label</comment>
</data>
<data name="AdjustImagesDialog_appliesTo" xml:space="preserve">
Expand Down
8 changes: 6 additions & 2 deletions OneMore/Properties/Resources.he-IL.resx
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,12 @@ OneNote ייסגר אוטומטית</value>
<value>מוּחלָט</value>
<comment>radio button</comment>
</data>
<data name="AdjustImagesDialog_allLabel.Text" xml:space="preserve">
<value>כל התמונות בדף זה</value>
<data name="AdjustImagesDialog_allLabelBackground" xml:space="preserve">
<value>{0} תמונות רקע</value>
<comment>info label</comment>
</data>
<data name="AdjustImagesDialog_allLabelForeground" xml:space="preserve">
<value>{0} תמונות קדמיות</value>
<comment>info label</comment>
</data>
<data name="AdjustImagesDialog_appliesTo" xml:space="preserve">
Expand Down
8 changes: 6 additions & 2 deletions OneMore/Properties/Resources.nl-NL.resx
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,12 @@ OneNote wordt automatisch gesloten</value>
<value>Absoluut</value>
<comment>radio button</comment>
</data>
<data name="AdjustImagesDialog_allLabel.Text" xml:space="preserve">
<value>alle afbeeldingen op deze pagina</value>
<data name="AdjustImagesDialog_allLabelBackground" xml:space="preserve">
<value>{0} achtergrondafbeeldingen</value>
<comment>info label</comment>
</data>
<data name="AdjustImagesDialog_allLabelForeground" xml:space="preserve">
<value>{0} voorgrondafbeeldingen</value>
<comment>info label</comment>
</data>
<data name="AdjustImagesDialog_appliesTo" xml:space="preserve">
Expand Down
8 changes: 6 additions & 2 deletions OneMore/Properties/Resources.pl-PL.resx
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,12 @@ OneNote zamknie się automatycznie</value>
<value>Absolutny</value>
<comment>radio button</comment>
</data>
<data name="AdjustImagesDialog_allLabel.Text" xml:space="preserve">
<value>Wszystkie obrazy na tej stronie</value>
<data name="AdjustImagesDialog_allLabelBackground" xml:space="preserve">
<value>{0} obrazy tła</value>
<comment>info label</comment>
</data>
<data name="AdjustImagesDialog_allLabelForeground" xml:space="preserve">
<value>{0} obrazów na pierwszym planie</value>
<comment>info label</comment>
</data>
<data name="AdjustImagesDialog_appliesTo" xml:space="preserve">
Expand Down
8 changes: 6 additions & 2 deletions OneMore/Properties/Resources.pt-BR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,12 @@ OneNote fechará automaticamente</value>
<value>Absoluto</value>
<comment>radio button</comment>
</data>
<data name="AdjustImagesDialog_allLabel.Text" xml:space="preserve">
<value>todas as imagens desta página</value>
<data name="AdjustImagesDialog_allLabelBackground" xml:space="preserve">
<value>{0} imagens de fundo</value>
<comment>info label</comment>
</data>
<data name="AdjustImagesDialog_allLabelForeground" xml:space="preserve">
<value>{0} imagens em primeiro plano</value>
<comment>info label</comment>
</data>
<data name="AdjustImagesDialog_appliesTo" xml:space="preserve">
Expand Down
8 changes: 6 additions & 2 deletions OneMore/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,12 @@ OneNote will close automatically</value>
<value>Absolute</value>
<comment>radio button</comment>
</data>
<data name="AdjustImagesDialog_allLabel.Text" xml:space="preserve">
<value>all images on this page</value>
<data name="AdjustImagesDialog_allLabelBackground" xml:space="preserve">
<value>{0} background images</value>
<comment>info label</comment>
</data>
<data name="AdjustImagesDialog_allLabelForeground" xml:space="preserve">
<value>{0} foreground images</value>
<comment>info label</comment>
</data>
<data name="AdjustImagesDialog_appliesTo" xml:space="preserve">
Expand Down
8 changes: 6 additions & 2 deletions OneMore/Properties/Resources.zh-CN.resx
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,12 @@ OneNote 将自动关闭</value>
<value>绝对</value>
<comment>radio button</comment>
</data>
<data name="AdjustImagesDialog_allLabel.Text" xml:space="preserve">
<value>此页面上的所有图像</value>
<data name="AdjustImagesDialog_allLabelBackground" xml:space="preserve">
<value>{0} 背景图片</value>
<comment>info label</comment>
</data>
<data name="AdjustImagesDialog_allLabelForeground" xml:space="preserve">
<value>{0} 前景图像</value>
<comment>info label</comment>
</data>
<data name="AdjustImagesDialog_appliesTo" xml:space="preserve">
Expand Down

0 comments on commit aca4db3

Please sign in to comment.