Skip to content

Commit

Permalink
Add page marker flags feature
Browse files Browse the repository at this point in the history
This feature is in GG2, and allows editing in a different
editor without losing the page break positions.

In particular, swapping between GG1 & GG2 should be
easy, but any other editor is OK too.
  • Loading branch information
windymilla committed Jun 4, 2024
1 parent ea5be11 commit d1573d7
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 7 deletions.
51 changes: 49 additions & 2 deletions src/lib/Guiguts/FileMenu.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ BEGIN {
&clearvars &savefile &_exit &file_mark_pages &file_guess_page_marks
&oppopupdate &opspop_up &confirmempty &openfile &readsettings &savesettings &file_export_pagemarkup
&file_import_markup &file_import_ocr &operationadd &isedited &setedited &charsuitespopup &charsuitecheck &charsuitefind &charsuiteenable
&cpcharactersubs &getsafelastpath);
&cpcharactersubs &getsafelastpath &add_page_marker_flags &remove_page_marker_flags);
}

#
Expand Down Expand Up @@ -477,7 +477,7 @@ sub file_mark_pages {
my $pagemark = 'Pg' . $page;

# Standardize page separator line format if necessary
unless ( $line =~ /^-----File: (\S+)\.(png|jpg)---/ ) {
unless ( $line =~ /^-----File: (\S+)\.(png|jpg)---/ or $line =~ /\[Pg\S+?\]/ ) {
$textwindow->ntdelete( $linestart, $lineend );
my $stdline = ( '-' x 5 ) . "File: $page.$ext";
$stdline .= '-' x ( 75 - length($stdline) );
Expand Down Expand Up @@ -636,6 +636,50 @@ sub file_guess_page_marks {
return;
}

#
# Add page marker flags to facilitate editing in another editor
sub add_page_marker_flags {

# Done in reverse order so two adjacent boundaries preserve their order.
my $mark = 'end';
while ( $mark = $::textwindow->markPrevious($mark) ) {
if ( $mark =~ /Pg\S+/ ) {
$::textwindow->insert( $mark, "[$mark]", 'pageflag' );
}
}
}

#
# Remove page marker flags
sub remove_page_marker_flags {
my $len;
while ( my $found =
$::textwindow->search( '-regexp', '-count', \$len, '--', '\[Pg\S+?\]', "1.0", "end" ) ) {
$::textwindow->delete( $found, "$found+${len}c" );
}
}

#
# Use page marker flags in file to locate page boundaries and set marks
sub update_page_markers_from_flags {
my $textwindow = $::textwindow;

my $len;
my $search_start = '1.0';
while (
my $found = $textwindow->search(
'-regexp', '-count', \$len, '--', '\[(Pg\S+?)\]', $search_start, 'end'
)
) {
$textwindow->tagAdd( 'pageflag', "$found", "$found+${len}c" );
my $pagemark = $textwindow->get( "$found+1c", "$found+${len}c-1c" );
$::pagenumbers{$pagemark}{offset} = 1;
$textwindow->markSet( $pagemark, $found );
$textwindow->markGravity( $pagemark, 'left' );
$search_start = $textwindow->index("$found+4c");
}
}

#
# Update the list of operations in the operation history dialog
sub oppopupdate {
Expand Down Expand Up @@ -810,6 +854,9 @@ sub openfile {
::highlight_scannos();
::highlight_quotbrac();
file_mark_pages() if $::auto_page_marks;

# If file contains "[Pg001]" flags, update page marker locations from flags
update_page_markers_from_flags();
::readlabels();

::operationadd("Open $::lglobal{global_filename}");
Expand Down
10 changes: 6 additions & 4 deletions src/lib/Guiguts/MenuStructure.pm
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@ sub menu_file_project {
[ 'command', 'Set Pro~ject ID...', -command => \&::setprojectid ],
[ 'command', 'Set I~mage Directory...', -command => \&::setpngspath ],
[ 'separator', '' ],
[ 'command', 'Display/~Adjust Page Markers...', -command => \&::togglepagenums ],
[ 'command', '~Guess Page Markers...', -command => \&::file_guess_page_marks ],
[ 'command', '~Set Page Markers', -command => \&::file_mark_pages ],
[ 'command', 'Configure Page La~bels...', -command => \&::pageadjust ],
[ 'command', 'Display/~Adjust Page Markers...', -command => \&::togglepagenums ],
[ 'command', '~Guess Page Markers...', -command => \&::file_guess_page_marks ],
[ 'command', '~Set Page Markers', -command => \&::file_mark_pages ],
[ 'command', '~Add Page Marker Flags', -command => \&::add_page_marker_flags ],
[ 'command', '~Remove Page Marker Flags', -command => \&::remove_page_marker_flags ],
[ 'command', 'Configure Page La~bels...', -command => \&::pageadjust ],
];
}

Expand Down
6 changes: 5 additions & 1 deletion src/lib/Guiguts/Utilities.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,11 @@ sub initialize {
-foreground => 'black',
-background => 'grey'
); # From TextEdit.pm

$textwindow->tagConfigure(
'pageflag',
-foreground => 'black',
-background => 'gold',
);
$textwindow->tagConfigure(
'pagenum',
-background => 'yellow',
Expand Down

0 comments on commit d1573d7

Please sign in to comment.