Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add page marker flags feature #1298

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading