Skip to content

Commit

Permalink
Fix index getting mashed up upon page deletion
Browse files Browse the repository at this point in the history
bump version, make installer
  • Loading branch information
t0815 committed Aug 27, 2023
1 parent 0a7aa65 commit 6849e19
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 81 deletions.
2 changes: 1 addition & 1 deletion MyCBZ/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<applicationSettings>
<Win_CBZ.Win_CBZSettings>
<setting name="Version" serializeAs="String">
<value>0.11.45b</value>
<value>0.11.46b</value>
</setting>
<setting name="RenamerPlaceholders" serializeAs="Xml">
<value>
Expand Down
31 changes: 24 additions & 7 deletions MyCBZ/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1692,9 +1692,15 @@ private void MovePageTo(Page page, int newIndex)
updatePage = FindListViewItemForPage(PageView, page);
//updateImage = PageImages.Images[PageImages.Images.IndexOfKey(page.Id)];

originalItem = PagesList.Items[newIndex];
originalPage = FindListViewItemForPage(PageView, (Page)originalItem.Tag);
if (newIndex > -1)
{
originalItem = PagesList.Items[newIndex];
originalPage = FindListViewItemForPage(PageView, (Page)originalItem.Tag);
//originalImage = PageImages.Images[PageImages.Images.IndexOfKey(((Page)originalItem.Tag).Id)];
} else
{
return;
}

int IndexItemToMove = updateItem.Index;

Expand Down Expand Up @@ -1743,11 +1749,12 @@ private void MovePageTo(Page page, int newIndex)
}

PageChanged(this, new PageChangedEvent(page, PageChangedEvent.IMAGE_STATUS_CHANGED));
PageChanged(this, new PageChangedEvent((Page)originalPage.Tag, PageChangedEvent.IMAGE_STATUS_CHANGED));
if (originalPage != null)
{
PageChanged(this, new PageChangedEvent((Page)originalPage.Tag, PageChangedEvent.IMAGE_STATUS_CHANGED));
}
ArchiveStateChanged(this, new CBZArchiveStatusEvent(Program.ProjectModel, CBZArchiveStatusEvent.ARCHIVE_FILE_UPDATED));



HandleGlobalActionRequired(null, new GlobalActionRequiredEvent(Program.ProjectModel, 0, "Page order changed. Rebuild pageindex now?", "Rebuild", RebuildPageIndexMetaDataTask.UpdatePageIndexMetadata(Program.ProjectModel.Pages, Program.ProjectModel.MetaData, HandleGlobalTaskProgress, PageChanged)));

Program.ProjectModel.IsChanged = true;
Expand Down Expand Up @@ -2107,8 +2114,9 @@ private void TypeSelectionToolStripMenuItem_Click(object sender, EventArgs e)
private void ToolButtonEditImageProps_Click(object sender, EventArgs e)
{
Page page = (Page)PagesList.SelectedItem.Tag;
Page editPage = new Page(page);

PageSettingsForm pageSettingsForm = new PageSettingsForm(page);
PageSettingsForm pageSettingsForm = new PageSettingsForm(editPage);
DialogResult dlgResult = pageSettingsForm.ShowDialog();

if (dlgResult == DialogResult.OK)
Expand All @@ -2118,7 +2126,16 @@ private void ToolButtonEditImageProps_Click(object sender, EventArgs e)
if (pageToUpdate != null)
{
pageToUpdate.UpdatePage(pageResult);
MovePageTo(pageToUpdate, pageResult.Index);
if (!pageResult.Deleted)
{
MovePageTo(pageToUpdate, pageResult.Index);
}

if (pageResult.Deleted != editPage.Deleted)
{
HandleGlobalActionRequired(null, new GlobalActionRequiredEvent(Program.ProjectModel, 0, "Page order changed. Rebuild pageindex now?", "Rebuild", RebuildPageIndexMetaDataTask.UpdatePageIndexMetadata(Program.ProjectModel.Pages, Program.ProjectModel.MetaData, HandleGlobalTaskProgress, PageChanged)));
}

if (pageToUpdate.Deleted)
{
try
Expand Down
12 changes: 12 additions & 0 deletions MyCBZ/Forms/PageSettingsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ private void ButtonOk_Click(object sender, EventArgs e)
private void CheckBoxPageDeleted_CheckedChanged(object sender, EventArgs e)
{
Page.Deleted = CheckBoxPageDeleted.Checked;
if (Page.Deleted)
{
Page.Index = -1;
PageIndexTextbox.Text = "-1";

} else
{
Page.Index = Page.OriginalIndex;
PageIndexTextbox.Text = (Page.OriginalIndex + 1).ToString();
}

PageIndexTextbox.Enabled = !Page.Deleted;
}
}
}
43 changes: 43 additions & 0 deletions MyCBZ/Models/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ internal class Page

public int Index { get; set; }

public int OriginalIndex { get; set; }

public String Key { get; set; }

public DateTimeOffset LastModified { get; set; }
Expand Down Expand Up @@ -221,6 +223,7 @@ public Page(Page sourcePage, String RandomId, int ThumbWidth = 212, int ThumbHei
Size = sourcePage.Size;
Id = sourcePage.Id;
Index = sourcePage.Index;
OriginalIndex = sourcePage.OriginalIndex;
Number = sourcePage.Number;
Closed = sourcePage.Closed;

Expand All @@ -237,6 +240,45 @@ public Page(Page sourcePage, String RandomId, int ThumbWidth = 212, int ThumbHei
ImageTask = new ImageTask();
}

public Page(Page sourcePage)
{
WorkingDir = sourcePage.WorkingDir;
Name = sourcePage.Name;
EntryName = sourcePage.EntryName;
TempPath = sourcePage.TempPath;
Filename = sourcePage.Filename;
LocalPath = sourcePage.LocalPath;
ImageStream = sourcePage.ImageStream;
Compressed = sourcePage.Compressed;
TemporaryFileId = sourcePage.TemporaryFileId;
EntryName = sourcePage.EntryName;
ImageEntry = sourcePage.ImageEntry;
ImageStream = sourcePage.ImageStream;
IsMemoryCopy = sourcePage.IsMemoryCopy;
ImageStreamMemoryCopy = sourcePage.ImageStreamMemoryCopy;

Changed = sourcePage.Changed;
ReadOnly = sourcePage.ReadOnly;
Size = sourcePage.Size;
Id = sourcePage.Id;
Index = sourcePage.Index;
OriginalIndex = sourcePage.OriginalIndex;
Number = sourcePage.Number;
Closed = sourcePage.Closed;

Deleted = sourcePage.Deleted;
OriginalName = sourcePage.OriginalName;
W = sourcePage.W;
H = sourcePage.H;
Key = sourcePage.Key;
ThumbH = sourcePage.ThumbH;
ThumbW = sourcePage.ThumbW;
Thumbnail = sourcePage.Thumbnail;
ThumbnailInvalidated = sourcePage.ThumbnailInvalidated;

ImageTask = sourcePage.ImageTask;
}

public void UpdatePage(Page page, bool skipIndex = false)
{
Compressed = page.Compressed;
Expand All @@ -255,6 +297,7 @@ public void UpdatePage(Page page, bool skipIndex = false)
{
Index = page.Index;
}
//OriginalIndex = page.OriginalIndex;
TemporaryFileId = page.TemporaryFileId;
Changed = page.Changed;
}
Expand Down
3 changes: 3 additions & 0 deletions MyCBZ/Models/ProjectModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ public void AddImagesProc()
page = new Page(fi, FileAccess.ReadWrite);
page.Number = realNewIndex + 1;
page.Index = realNewIndex;
page.OriginalIndex = realNewIndex;
realNewIndex++;
} else
{
Expand Down Expand Up @@ -882,6 +883,7 @@ protected void UpdatePageIndicesProc()
isUpdated = true;
}
page.Index = newIndex;
page.OriginalIndex = newIndex;
page.Number = newIndex + 1;
newIndex++;
}
Expand Down Expand Up @@ -1308,6 +1310,7 @@ protected void OpenArchiveProc()

page.Number = index + 1;
page.Index = index;
page.OriginalIndex = index;

pageIndexEntry = MetaData.FindIndexEntryForPage(page);
if (pageIndexEntry != null)
Expand Down
4 changes: 2 additions & 2 deletions MyCBZ/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.11.45.0")]
[assembly: AssemblyFileVersion("0.11.45.0")]
[assembly: AssemblyVersion("0.11.46.0")]
[assembly: AssemblyFileVersion("0.11.46.0")]
[assembly: NeutralResourcesLanguage("en")]
1 change: 1 addition & 0 deletions MyCBZ/Tasks/RebuildPageIndexMetaDataTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static Task<TaskResult> UpdatePageIndexMetadata(List<Page> pages, MetaDat
isUpdated = true;
}
page.Index = newIndex;
//page.OriginalIndex = newIndex;
page.Number = newIndex + 1;
newIndex++;
}
Expand Down
2 changes: 1 addition & 1 deletion MyCBZ/Win_CBZSettings.Designer.cs

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

2 changes: 1 addition & 1 deletion MyCBZ/Win_CBZSettings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Value Profile="(Default)">%APPDATA%\CBZMage\Temp\</Value>
</Setting>
<Setting Name="Version" Type="System.String" Scope="Application">
<Value Profile="(Default)">0.11.45b</Value>
<Value Profile="(Default)">0.11.46b</Value>
</Setting>
<Setting Name="RenamerPlaceholders" Type="System.Collections.Specialized.StringCollection" Scope="Application">
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
Expand Down
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Microsoft Visual Studio [Community] 2022 (64-Bit)

## Latest Release

v0.11.45b released!
v0.11.46b released!

## Third party components

Expand Down
Loading

0 comments on commit 6849e19

Please sign in to comment.