/* mod_funcs.c
 * Copyright (C) 1990 Commodore-Amiga, Inc.
 * written by David N. Junod
 *
 * application specific functions
 *
 */

#include "mod.h"

/*--- check to see if the project has been changed ---*/
BOOL CheckForChanges (struct AppInfo * ai)
{
    BOOL cancel = FALSE;
    UBYTE pname[255];

    /* See if there is a name for our project */
    strcpy (pname, ai->ProjName);
    if (strlen (pname) < 1)
	strcpy (pname, "<untitled>");

    /* Check to see if any changes have been made to our project */
    if (ai->Changed)
    {

	/*
	 * project (pname) has been changed, do you want to save first?
	 * prompt for Yes | No | Cancel
	 * 
	 * Yes:		call the SaveFunc(NULL, win, NULL) function.
	 * No:		fall through.
	 * Cancel:	set cancel=TRUE.
	 */

	/*
	 * also set ai->pri_ret so that scripts can act accordingly
	 * 
	 * Yes:		0
	 * No:		0
	 * Cancel:	5
	 */
    }
    return (cancel);
}

VOID NewFunc (struct AppInfo *ai, struct Message *msg, UBYTE * args)
{
    BOOL cancel;

    printf ("`New' function\n");

    cancel = CheckForChanges (ai);
    if (!cancel)
    {
	/* Free up the previous project here... */

	/* Prepare for a New project here... */
	strcpy (ai->ProjName, "");
	ai->Changed = FALSE;
    }
}

VOID OpenFunc (struct AppInfo *ai, struct Message *msg, UBYTE * args)
{
    BOOL cancel;

    printf ("`Open' function\n");

    cancel = CheckForChanges (ai);
    if (!cancel)
    {
	/* see if an argument was passed */
	if (strlen (args) > 0)
	{
	    printf ("%s was passed\n", args);
	    strcpy (ai->ProjName, args);
	}
	else
	{

	    /*
	     * Bring up your file requester here. Remember to check for cancel
	     * being pressed...
	     */
	    strcpy (ai->ProjName, "Named");
	}

	/* Open a new project here... */
	ai->Changed = FALSE;
    }
}

VOID SaveFunc (struct AppInfo *ai, struct Message *msg, UBYTE * args)
{
    printf ("`Save' function\n");

    if (strlen (ai->ProjName) == 0)
    {
	/* Not named yet, so let's get a name */
	SaveAsFunc (ai, msg, args);
    }
    else if (ai->Changed)
    {
	/* Save your project here ... */
	ai->Changed = FALSE;
    }
}

VOID SaveAsFunc (struct AppInfo *ai, struct Message *msg, UBYTE * args)
{
    printf ("`Save As' function\n");

    /* see if an argument was passed */
    if (strlen (args) > 0)
    {
	/* they passed a file name to save as */
	printf ("%s was passed\n", args);
	strcpy (ai->ProjName, args);
    }
    else
    {
	/*
	 * Bring up your file requester here so that user can name the project.
	 * Only set the Changed flag to FALSE if the user successfully returns
	 * a file name (doesn't hit CANCEL).
	 */
	strcpy (ai->ProjName, "Named");
    }

    /* Save your project here ... */
    ai->Changed = FALSE;
}

VOID AboutFunc (struct AppInfo *ai, struct Message *msg, UBYTE * args)
{
    printf ("`About' function\n");

    /* return a text value */
    ai->textrtn = "ModEngine 1.00 23-Feb-90";
}

VOID QuitFunc (struct AppInfo *ai, struct Message *msg, UBYTE * args)
{
    printf ("`Quit' function\n");

    /* Inform the main loop that we are done */
    ai->Done = TRUE;
}

VOID ChooseFunc (struct AppInfo *ai, struct Message *msg, UBYTE * args)
{
    printf ("`Choose a Tool' function\n");
}

VOID DefineFunc (struct AppInfo *ai, struct Message *msg, UBYTE * args)
{
    printf ("`Change Tool Settings' function\n");
}

VOID UndoFunc (struct AppInfo *ai, struct Message *msg, UBYTE * args)
{
    printf ("`Undo' function\n");
}

VOID HelpFunc (struct AppInfo *ai, struct Message *msg, UBYTE * args)
{
    printf ("`Help' function\n");
}

VOID ArrowFunc (struct AppInfo *ai, struct Message *msg, UBYTE * args)
{
    printf ("`Arrow' function\n");
}

VOID ShellFunc (struct AppInfo *ai, struct Message *msg, UBYTE * args)
{
    printf ("`Shell' function\n");
    HandlerFunc (ai, "DOS", MH_OPEN);
}

VOID WindowFunc (struct AppInfo *ai, struct Message *msg, UBYTE * args)
{
    printf ("`Window' function\n");
    if (strcmpi (args, "CLOSE") == 0)
	HandlerFunc (ai, "IDCMP", MH_CLOSE);
    else
	HandlerFunc (ai, "IDCMP", MH_OPEN);
}

/* Abort current operation */
VOID AbortFunc (struct AppInfo *ai, struct Message *msg, UBYTE * args)
{
    printf ("`Abort' function\n");
}
