Skip to content

Commit

Permalink
fix updating original file during image processing [#54], fix global …
Browse files Browse the repository at this point in the history
…task not being set [#49], sort items by index after image processing, update index for pages
  • Loading branch information
t0815 committed Oct 9, 2024
1 parent e9e8d45 commit f175dcf
Show file tree
Hide file tree
Showing 10 changed files with 420 additions and 202 deletions.
24 changes: 24 additions & 0 deletions MyCBZ/Events/UpdatePageListViewSortingEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Win_CBZ.Events
{
internal class UpdatePageListViewSortingEvent
{
public int SortColumn { get; set; } = 1; // sort by index by default

public SortOrder Order { get; set; } = SortOrder.Ascending;

public UpdatePageListViewSortingEvent() { }

public UpdatePageListViewSortingEvent(int column, SortOrder order)
{
SortColumn = column;
Order = order;
}
}
}
20 changes: 20 additions & 0 deletions MyCBZ/Events/UpdateThumbnailsEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Win_CBZ.Events
{
class UpdateThumbnailsEvent
{
public List<Page> Pages { get; set; }

public UpdateThumbnailsEvent() { }

public UpdateThumbnailsEvent(List<Page> pages)
{
this.Pages = pages;
}
}
}
25 changes: 25 additions & 0 deletions MyCBZ/Extensions/ListBoxExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Versioning;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Documents;
using System.Windows.Forms;

namespace Win_CBZ.Extensions
{
[SupportedOSPlatform("windows")]
public static class ListBoxExtensions
{
public static void Sort(this ListBox lb, SortOrder order = SortOrder.Ascending)
{
var list = lb.Items.Cast<Page>().ToArray();
list = order == SortOrder.Descending
? list.OrderByDescending(x => x.Index).ToArray()
: list.OrderBy(x => x.Index).ToArray();
lb.Items.Clear();
lb.Items.AddRange(list);
}
}
}
61 changes: 57 additions & 4 deletions MyCBZ/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
using Win_CBZ.Properties;
using System.Drawing.Drawing2D;
using Microsoft.VisualBasic.Devices;
using Win_CBZ.Extensions;
using Win_CBZ.List;

namespace Win_CBZ
{
Expand Down Expand Up @@ -271,7 +273,9 @@ private ProjectModel NewProjectModel()
AppEventHandler.GlobalActionRequired += HandleGlobalActionRequired;
AppEventHandler.GeneralTaskProgress += HandleGlobalTaskProgress;
AppEventHandler.RedrawThumbnail += HandleRedrawThumbnail;
AppEventHandler.UpdateThumbnails += HandleUpdateThumbnails;
AppEventHandler.ImageAdjustmentsChanged += HandleImageAdjustmentsChanged;
AppEventHandler.UpdateListViewSorting += HandleListviewSorting;

newProjectModel.RenameStoryPagePattern = Win_CBZSettings.Default.StoryPageRenamePattern;
newProjectModel.RenameSpecialPagePattern = Win_CBZSettings.Default.SpecialPageRenamePattern;
Expand Down Expand Up @@ -1181,15 +1185,65 @@ private void HandleRedrawThumbnail(object sender, RedrawThumbEvent e)
PageImages.Images.RemoveByKey(e.Page.Id);
}
PageThumbsListBox.Items[pageIndex] = e.Page;


}
PageThumbsListBox.Invalidate();
PageThumbsListBox.Refresh();
}));
}
}

private void HandleUpdateThumbnails(object sender, UpdateThumbnailsEvent e)
{
if (!WindowClosed)
{
Invoke(new Action(() =>
{
if (e.Pages != null && e.Pages.Count > 0)
{
foreach (Page p in e.Pages)
{
p.Invalidated = true;
int pageIndex = PageThumbsListBox.Items.IndexOf(Program.ProjectModel.GetPageById(p.Id));
if (pageIndex > -1)
{
if (PageImages.Images.ContainsKey(p.Id))
{
PageImages.Images.RemoveByKey(p.Id);
}
PageThumbsListBox.Items[pageIndex] = p;
}
}
PageThumbsListBox.Invalidate();
PageThumbsListBox.Refresh();
}
}));
}
}

private void HandleListviewSorting(object sender, UpdatePageListViewSortingEvent e)
{
if (!WindowClosed)
{
Invoke(() =>
{
Program.ProjectModel.Pages.Sort((x, y) => x.Index.CompareTo(y.Index));

PagesList.ListViewItemSorter = new ListViewSorter(e.SortColumn);

PagesList.Sorting = e.Order;
PagesList.Sort();
PagesList.Sorting = SortOrder.None;

if (Win_CBZSettings.Default.PagePreviewEnabled)
{
PageThumbsListBox.Sort(e.Order);
}


});
}
}

public void ReloadPreviewThumbs()
{
if (!WindowClosed)
Expand Down Expand Up @@ -4693,10 +4747,9 @@ private void PagesList_ItemSelectionChanged(object sender, ListViewItemSelection
LabelH.Text = ((Page)selectedPages[0].Tag).Format.H.ToString();
}

selectedImageTasks = ((Page)selectedPages[0].Tag).ImageTask;

if (RadioApplyAdjustmentsPage.Checked && ((String)RadioApplyAdjustmentsPage.Tag) != ((Page)selectedPages[0].Tag).Id)
{
selectedImageTasks = ((Page)selectedPages[0].Tag).ImageTask;
UpdateImageAdjustments(sender, ((Page)selectedPages[0].Tag).Id, true);
}

Expand Down
Loading

0 comments on commit f175dcf

Please sign in to comment.