<commit_before>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using System.Windows.Forms;

namespace RealBookExtracter {
    public partial class FormMain : Form {

        private string _jpgFolder;
        private string _firstPage;
        private string _lastPage;
        private UndoInfo[] _undoInfo;

        public FormMain() {
            InitializeComponent();
            setButtonStates();
        }

        protected override void OnLoad(EventArgs e) {
            base.OnLoad(e);
            if (!string.IsNullOrWhiteSpace(Settings.FolderPath) && Directory.Exists(Settings.FolderPath)) {
                textFolder.Text = Settings.FolderPath;
                btnLoad.PerformClick();
            }
        }

        private void setButtonStates() {
            btnLoad.Enabled = Directory.Exists(textFolder.Text);
            if (_firstPage == null) {
                cboArtist.Enabled = textTitle.Enabled = btnBack.Enabled
                    = btnNext.Enabled = btnSave.Enabled = btnDelete.Enabled = false;
                return;
            }
            cboArtist.Enabled = textTitle.Enabled = true;
            btnBack.Enabled = _firstPage != _lastPage;
            btnNext.Enabled = _lastPage != Path.GetFileName(Directory.GetFiles(_jpgFolder).Last());
            btnSave.Enabled = cboArtist.Text != "" && textTitle.Text != "";
            btnDelete.Enabled = true;
            if (btnSave.Enabled) AcceptButton = btnSave;
        }

        private void menuExtract_Click(object sender, EventArgs e) {
            using (var f = new FormExtract()) {
                if (f.ShowDialog(this) == DialogResult.OK) {
                    textFolder.Text = f.OutFolder;
                    btnLoad.PerformClick();
                }
            }
        }

        private void textFolder_TextChanged(object sender, EventArgs e) {
            setButtonStates();<commit_msg>Fix to handle reaching the end.<commit_after>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using System.Windows.Forms;

namespace RealBookExtracter {
    public partial class FormMain : Form {

        private string _jpgFolder;
        private string _firstPage;
        private string _lastPage;
        private UndoInfo[] _undoInfo;

        public FormMain() {
            InitializeComponent();
            setButtonStates();
        }

        protected override void OnLoad(EventArgs e) {
            base.OnLoad(e);
            if (!string.IsNullOrWhiteSpace(Settings.FolderPath) && Directory.Exists(Settings.FolderPath)) {
                textFolder.Text = Settings.FolderPath;
                btnLoad.PerformClick();
            }
        }

        private void setButtonStates() {
            btnLoad.Enabled = Directory.Exists(textFolder.Text);
            if (_firstPage == null || !getPages().Any()) {
                cboArtist.Enabled = textTitle.Enabled = btnBack.Enabled
                    = btnNext.Enabled = btnSave.Enabled = btnDelete.Enabled = false;
                return;
            }
            cboArtist.Enabled = textTitle.Enabled = true;
            btnBack.Enabled = _firstPage != _lastPage;
            btnNext.Enabled = _lastPage != getPages().Last();
            btnSave.Enabled = cboArtist.Text != "" && textTitle.Text != "";
            btnDelete.Enabled = true;
            if (btnSave.Enabled) AcceptButton = btnSave;
        }

        private void menuExtract_Click(object sender, EventArgs e) {
            using (var f = new FormExtract()) {
                if (f.ShowDialog(this) == DialogResult.OK) {
                    textFolder.Text = f.OutFolder;
                    btnLoad.PerformClick();
                }
            }
        }

        private void textFolder_TextChanged(object sender, EventArgs e) {
            setButtonStates();
{'fraction_non_alphanumeric': 0.09495047112829186, 'fraction_numerical': 0.0, 'mean_word_length': 2.008720930232558, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3454052', 'n_tokens_mistral': 1068, 'n_tokens_neox': 1051, 'n_words': 235}