Glossary file bug

Everything related to our flagship word processor.
Post Reply
credneb
Posts: 192
Joined: 2007-03-28 07:30:34

Glossary file bug

Post by credneb »

which should be reproducible.

I frequently recycle glossaries between jobs. The following problem occurs regularly and should be reproducible. I just verified it again.

1. Create a new glossary file in the QuickFix panel and edit to add at least one entry.
2. Create or open a file and try the glossary file out. It works.
3. Quit NWP.
4. Move the glossary file out of the glossary folder.
5. Reboot NWP and go to QuickFix panel. The glossary, as expected, will not be there. Quit NWP.
6. Move the glossary file back into the glossary folder. (Or don't move it out and back in, just rename a glossary after quitting NWP.)
7. Reboot NWP, go to the QuickFix panel and the glossary will be there and enabled. It will work.

everything to here is as expected.

I've written a set of glossary editing files included in which are the following lines which enable me to present a dialog box of glossary files to edit.

Code: Select all

	#now get list of glossaries in glossary folder
$glossaryFolderPath = '~/Library/Application Support/Nisus Writer/Glossaries'
$glossariesInFolder = File.namesInFolderAtPath $glossaryFolderPath

	#and after some string manipulation

$gloss = Prompt Options $message, '', 'Select', $glossariesInFolder
The macro does some weening before presenting the dialog box. However, after step 6 above, NWP does NOT pick up the glossary that was either renamed or moved into the glossary folder before rebooting. But the glossary is there, enabled, and working. To get NWP to recognize the glossary again you must:

8. Go to QuickFix, select, edit (by typing at least one character), and save the glossary.

Calling the macro will now get the desired list of glossary files.

I'd be happy to post the entire macro if you are unable to reproduce the problem. This is the only instance in which the macro goes not present the expected list of glossaries. The same problem occurs if you create and save a new glossary file in QuickFix without adding at least one entry.

Cliff Bender
User avatar
martin
Official Nisus Person
Posts: 5230
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Glossary file bug

Post by martin »

Hi Cliff, I've not been able to reproduce this bug and I would be shocked if I were able to. The "namesInFolderAtPath" macro command is very low level, always reading the current files in the folder, so it's highly unlikely that its behavior will be linked to what you do in the QuickFix preference pane. I think you'd better post the rest of your macro so we can see how you process/cull the file names.
credneb
Posts: 192
Joined: 2007-03-28 07:30:34

Re: Glossary file bug

Post by credneb »

Martin,

Thanks for the reply, and for doing your magic.

This is the second time I've written about something not working, you being unable to reproduce it, and the problem then vanishing on this end without changing anything. I decided to write after several weeks of noticing the problem, and this morning cannot reproduce it here.

Thank you for fixing it so quickly. ;)

Just in case anyway, here is the macro that loads the file names.

Code: Select all

#load list of glossary files

Require Pro Version 1.2
$doc = Document.active
$hasDoc = Defined $doc
If ! $hasDoc
	Prompt "You need to open a document."
	Exit
End
$path = $doc.filePath
$hasPath = Defined $path
If ! $hasPath
	Prompt "Save the document first."
	Exit
End

	#get the name of the last glossary used; save the glossary used at the end
$registry = Registry.applicationRegistry
$lastSaved = 'com.j2e.glossaryMacros.lastGlossarySaved'
$lastUsed = $registry.loadValueWithName($lastSaved)
If $lastUsed == undefined
	$lastUsed = 'NewGlossary'
	$registry.saveValueWithName($lastUsed, $lastSaved)
end


	#extract the name of the glossary for the current job
$jobName = $doc.displayName
$loc = $jobName.rangeOfString('.')
if Defined($loc)
	$range = Range.new(0,$loc)
	$jobNumber = $jobName.subtextInRange($range)
	$currentJobGlossary = $jobNumber&'g.ngloss'
else
	$currentJobGlossary = $lastUsed
end

	#now get list of glossaries in glossary folder
$glossaryFolderPath = '~/Library/Application Support/Nisus Writer/Glossaries'
$glossariesInFolder = File.namesInFolderAtPath $glossaryFolderPath

	#strip backups marked with * from selection array
ForEach $index, $value in $glossariesInFolder
	$delete = $value.find('*')
		If Defined($delete)
			$glossariesInFolder.removeValueAtIndex($index)
		End
End

	#discover if job glossary is in folder
$index = $glossariesInFolder.indexOfValue($currentJobGlossary)
If $index > 0
		#move the glossary derived from document title to the
		#beginning of the array to make it the default
	$glossariesInFolder.removeValueAtIndex($index)
	$glossariesInFolder.prependValue $currentJobGlossary
end

If $lastUsed == $currentJobGlossary
	$glossaryPath = $glossaryFolderPath.filePathByAppendingComponent($currentJobGlossary)
	Open $glossaryPath
else
	$message = 'Select the glossary to edit.'
	$gloss = Prompt Options $message, '', 'Select', $glossariesInFolder
	$glossaryPath = $glossaryFolderPath.filePathByAppendingComponent($gloss)
	$registry.saveValueWithName($gloss, $lastSaved)
	Open $glossaryPath
end

Please note that each job file name is in the format M0123456.jobname, and every job glossary is named M0123456g (the .ngloss extension is as added by NWP).

Cliff Bender
Kino
Posts: 400
Joined: 2008-05-17 04:02:32

Re: Glossary file bug

Post by Kino »

This may not have anything to do with the problem but the first command of “#strip backups marked with * from selection array” should be

Code: Select all

ForEach $index, $value in reversed $glossariesInFolder
Try this to see what is happening:

Code: Select all

$alphabet = Array.new 'a', 'b', 'b', 'b', 'b', 'c', 'd'
foreach $index, $value in $alphabet
	if $value == 'b'
		$alphabet.removeValueAtIndex $index
	end
end
exit $alphabet
Kino
Posts: 400
Joined: 2008-05-17 04:02:32

Re: Glossary file bug

Post by Kino »

And the number of items Prompt Options dialog can display has a limit.

Code: Select all

$numbers = Array.new
$i = 100
while $i
	$numbers.appendValue $i
	$i -= 1
end
Prompt Options 'from 100 to 1', '', '', $numbers
If this is the cause of the problem, you have to do complicated coding for work it around. I'd like to have a scroll bar or [Previous] [Next] buttons in Prompt Options dialog box.
credneb
Posts: 192
Joined: 2007-03-28 07:30:34

Re: Glossary file bug

Post by credneb »

re: reversed

Thank you for pointing that out. It makes sense since deleting an item changes the index.

Also thanks for the note about the limit on the prompt. It's not the cause of the problem, and should never be a problem because there are only 5 - 10 files in the glossary folder.
Post Reply