/*
 * Next_Dirty_Buffer.bsh - Changes the buffer in
 * the current EditPane to the next dirty buffer, if 
 * there is one.
 *
 * Copyright (C) 2002-2004 Ollie Rutherfurd <oliver@rutherfurd.net>
 *
 * $Id: Next_Dirty_Buffer.bsh 21353 2012-03-14 09:46:51Z jojaba_67 $
 */

// Localization
final static String NoOtherBufferDirtyMessage = jEdit.getProperty("macro.rs.NextDirtyBuffer.NoOtherBufferDirty.message", "No other buffers are dirty");
final static String NoBufferDirtyMessage = jEdit.getProperty("macro.rs.NextDirtyBuffer.NoBufferDirty.message", "No buffers are dirty");

// Process
void nextDirtyBuffer(View view)
{
	Buffer current = view.getBuffer();
	Buffer b = current.getNext();
	for(int i=0; i < jEdit.getBufferCount()-1; i++)
	{
		// Buffer.getNext() returns null on last
		if(b == null)
			b = jEdit.getFirstBuffer();
		if(b.isDirty())
		{
			view.getEditPane().setBuffer(b);
			return;
		}
		b = b.getNext();	// check next
	}
	// if we get here, we didn't switch
	if(current.isDirty())
		view.getStatus().setMessageAndClear(NoOtherBufferDirtyMessage);
	else
		view.getStatus().setMessageAndClear(NoBufferDirtyMessage);
}

nextDirtyBuffer(view);

/*

<listitem>
	<para><filename>Next_Dirty_Buffer.bsh</filename></para>
	<abstract><para>Switches to the next dirty buffer, if there is one.
	</para></abstract>
</listitem>

*/
