/******************************************************************************
 SyGMDIServer.cc

	<Description>

	BASE CLASS = public JXMDIServer

	Copyright © 1997 by Glenn W. Bach.  All rights reserved.
	
	Base code generated by Codemill v0.1.0

 *****************************************************************************/

#include <SyGMDIServer.h>
#include <SyGApplication.h>

#include <JString.h>

#include <jXGlobals.h>

#include <jDirUtil.h>
#include <jAssert.h>

const JCharacter* kFMSig = "system-g-mdi";

/******************************************************************************
 Constructor

 *****************************************************************************/

SyGMDIServer::SyGMDIServer
	(
	SyGApplication* app
	)
	:
	JXMDIServer(kFMSig)
{
	itsApp = app;
}

/******************************************************************************
 Destructor

 *****************************************************************************/

SyGMDIServer::~SyGMDIServer()
{
}

/******************************************************************************
 HandleMDIRequest

 *****************************************************************************/

void
SyGMDIServer::HandleMDIRequest
	(
	const JCharacter* dir,
	const JPtrArray<JString>& argList
	)
{
	JString cwd = JGetCurrentDirectory();
	JChangeDirectory(dir);
	JString base(dir);
	JAppendDirSeparator(&base);
	JSize count = argList.GetElementCount();
	if (count > 1)
		{
		for (JSize i = 2; i <= count; i++)
			{
			JString fm(*(argList.NthElement(i)));
			if (!fm.BeginsWith("/"))
				{
				fm.Prepend(base);
				}
			JCleanPath(&fm);
			itsApp->NewChildWindow(fm);
			}
		}
	else
		{
		JString homeDir;
		if (JGetHomeDirectory(&homeDir))
			{
			itsApp->NewChildWindow(homeDir);
			}
		else
			{
			JGetUserNotification()->ReportError("Can't find your home directory.");
			}
		}
	JChangeDirectory(cwd);
}
