#include <stdio.h>
#include <stdlib.h>

#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>

#include "actions.h"
#include "xregal.h"
#include "searchtitle.h"
#include "searchname.h"
#include "cname.h"
#include "genre.h"
#include "keyword.h"
#include "find.h"
#include "file.h"
#include "history.h"

void AFindText(Widget w, XEvent *ev, String *s, Cardinal *num) {
	if (find_popped_up)
		return;
	PopupFind();
	}

void Asearchgenre(Widget w, XEvent *ev, String *s, Cardinal *num) {
	if (gs_popped_up)
		return;
	PopupGenre();
	}


void Asearchname(Widget w, XEvent *ev, String *s, Cardinal *num) {
	if (ts_popped_up)
		return;
	PopupSearchName();
	}

void Asearchkeyword(Widget w, XEvent *ev, String *s, Cardinal *num) {
    if (ks_popped_up)
        return;
    PopupKeyword();
    }

void Asearchcname(Widget w, XEvent *ev, String *s, Cardinal *num) {
	if (ts_popped_up)
		return;
	PopupSearchCharacterName();
	}

void Asearchtitle(Widget w, XEvent *ev, String *s, Cardinal *num) {
	if (ns_popped_up)
		return;
	PopupSearchTitle();
	}

void Asavetofile(Widget w, XEvent *ev, String *s, Cardinal *num) {
	if (fs_popped_up)
		return;
	PopupFileSave();
	}

void Abyebye(Widget w, XEvent *ev, String *s, Cardinal *num) {
	exit(0);
	}

void Aback(Widget w, XEvent *ev, String *s, Cardinal *num) {
	GoBack();
	}

void Aforward(Widget w, XEvent *ev, String *s, Cardinal *num) {
	GoForward();
	}

void Ahistory(Widget w, XEvent *ev, String *s, Cardinal *num) {
	PopupHistory();
	}

XtActionsRec xregal_actions[] = {
		{"byebye", (XtActionProc) Abyebye},
		{"goback", (XtActionProc) Aback},
		{"goforward", (XtActionProc) Aforward},
		{"history", (XtActionProc) Ahistory},
		{"searchname", (XtActionProc) Asearchname},
		{"searchcname", (XtActionProc) Asearchcname},
		{"searchtitle", (XtActionProc) Asearchtitle},
		{"findtext", (XtActionProc) AFindText},
		{"searchgenre", (XtActionProc) Asearchgenre},
        {"searchkeyword", (XtActionProc) Asearchkeyword},
		{"savetofile", (XtActionProc) Asavetofile}
		};

int xregal_actions_num = XtNumber(xregal_actions);

