2021-11-25 11:14:40 +01:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
#include <proto/exec.h>
|
|
|
|
|
#include <proto/dos.h>
|
|
|
|
|
#include <proto/intuition.h>
|
|
|
|
|
#include <proto/window.h>
|
|
|
|
|
#include <proto/layout.h>
|
|
|
|
|
#include <proto/texteditor.h>
|
2021-12-02 10:05:42 +01:00
|
|
|
|
#include <proto/requester.h>
|
2021-11-25 11:14:40 +01:00
|
|
|
|
|
|
|
|
|
#include <reaction/reaction_macros.h>
|
|
|
|
|
|
|
|
|
|
#include <classes/window.h>
|
2021-12-02 10:05:42 +01:00
|
|
|
|
#include <classes/requester.h>
|
2021-11-25 11:14:40 +01:00
|
|
|
|
|
|
|
|
|
#include <gadgets/texteditor.h>
|
|
|
|
|
|
|
|
|
|
#include "phed-init.h"
|
|
|
|
|
#include "phed-file.h"
|
2021-12-02 10:05:42 +01:00
|
|
|
|
#include "phed-req.h"
|
2021-11-25 11:14:40 +01:00
|
|
|
|
|
2021-12-02 10:05:42 +01:00
|
|
|
|
static const char *version = "$VER: phED Version 0.2";
|
2021-11-25 11:14:40 +01:00
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
GID_TEXTEDITOR = 0,
|
|
|
|
|
GID_LAST
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
struct Window *window;
|
|
|
|
|
struct Gadget *gadgets[GID_LAST];
|
|
|
|
|
|
2021-12-02 10:05:42 +01:00
|
|
|
|
Object *Win_Object, *beenden_object;
|
2021-11-25 11:14:40 +01:00
|
|
|
|
|
|
|
|
|
ULONG signal, result;
|
|
|
|
|
ULONG done = FALSE;
|
|
|
|
|
|
2021-12-02 10:05:42 +01:00
|
|
|
|
char *buf, *titel;
|
2021-11-25 11:14:40 +01:00
|
|
|
|
|
2021-12-02 10:05:42 +01:00
|
|
|
|
if(argc > 1)
|
2021-11-25 11:14:40 +01:00
|
|
|
|
{
|
2021-12-02 10:05:42 +01:00
|
|
|
|
titel = (char *) malloc(strlen(argv[1]));
|
|
|
|
|
strcpy(titel, argv[1]);
|
|
|
|
|
titel[strlen(argv[1])] = '\0';
|
2021-11-25 11:14:40 +01:00
|
|
|
|
|
2021-12-02 10:05:42 +01:00
|
|
|
|
buf = loadText(argv[1]);
|
2021-11-25 11:14:40 +01:00
|
|
|
|
}
|
2021-12-02 10:05:42 +01:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
titel = (char *) malloc(strlen("phED"));
|
|
|
|
|
strcpy(titel, "phED");
|
|
|
|
|
titel[strlen("phED")] = '\0';
|
|
|
|
|
|
|
|
|
|
buf = (char *) malloc(0);
|
|
|
|
|
}
|
2021-11-25 11:14:40 +01:00
|
|
|
|
|
|
|
|
|
if(openLibraries())
|
|
|
|
|
{
|
2021-12-02 10:05:42 +01:00
|
|
|
|
beenden_object = requesterNew("Beenden");
|
|
|
|
|
|
2021-11-25 11:14:40 +01:00
|
|
|
|
Win_Object = WindowObject,
|
|
|
|
|
WA_ScreenTitle, "Projekt Hirnfrei",
|
2021-12-02 10:05:42 +01:00
|
|
|
|
WA_Title, titel,
|
2021-11-25 11:14:40 +01:00
|
|
|
|
WA_SizeGadget, TRUE,
|
|
|
|
|
WA_DepthGadget, TRUE,
|
|
|
|
|
WA_DragBar, TRUE,
|
|
|
|
|
WA_CloseGadget, TRUE,
|
|
|
|
|
WA_Activate, TRUE,
|
|
|
|
|
WA_Width, 400,
|
|
|
|
|
WA_Height, 400,
|
|
|
|
|
WINDOW_ParentGroup, HGroupObject,
|
|
|
|
|
StartVGroup,
|
|
|
|
|
StartMember, gadgets[GID_TEXTEDITOR] = TextEditorObject,
|
|
|
|
|
GA_ID, GID_TEXTEDITOR,
|
|
|
|
|
GA_RelVerify, TRUE,
|
|
|
|
|
GA_TEXTEDITOR_Contents, (APTR) buf,
|
|
|
|
|
EndMember,
|
|
|
|
|
End,
|
|
|
|
|
EndMember,
|
|
|
|
|
EndWindow;
|
|
|
|
|
|
|
|
|
|
if(Win_Object)
|
|
|
|
|
{
|
|
|
|
|
if(window = (struct Window *) RA_OpenWindow(Win_Object))
|
|
|
|
|
{
|
2021-12-02 10:05:42 +01:00
|
|
|
|
ULONG wait, changed, ret;
|
2021-11-25 11:14:40 +01:00
|
|
|
|
UBYTE *buffer;
|
|
|
|
|
|
|
|
|
|
GetAttr(WINDOW_SigMask, Win_Object, &signal);
|
|
|
|
|
|
|
|
|
|
while(!done)
|
|
|
|
|
{
|
|
|
|
|
wait = Wait(signal|SIGBREAKF_CTRL_C);
|
|
|
|
|
|
|
|
|
|
if(wait & SIGBREAKF_CTRL_C) done = TRUE;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
while((result = RA_HandleInput(Win_Object, NULL)) != WMHI_LASTMSG)
|
|
|
|
|
{
|
2021-12-02 10:05:42 +01:00
|
|
|
|
switch(result & WMHI_CLASSMASK)
|
2021-11-25 11:14:40 +01:00
|
|
|
|
{
|
|
|
|
|
case WMHI_CLOSEWINDOW:
|
|
|
|
|
GetAttr(GA_TEXTEDITOR_HasChanged, gadgets[GID_TEXTEDITOR], &changed);
|
|
|
|
|
|
|
|
|
|
if(changed)
|
|
|
|
|
{
|
2021-12-02 10:05:42 +01:00
|
|
|
|
ret = beendenReq("\033cDer Text wurde ver<65>ndert!\n\nSoll der Text gespeichert werden?", beenden_object, window);
|
|
|
|
|
|
|
|
|
|
if(ret == 1)
|
|
|
|
|
{
|
|
|
|
|
buffer = (UBYTE *) DoGadgetMethod(gadgets[GID_TEXTEDITOR], window, NULL, GM_TEXTEDITOR_ExportText, NULL);
|
2021-11-25 11:14:40 +01:00
|
|
|
|
|
2021-12-02 10:05:42 +01:00
|
|
|
|
if(!argv[1]) saveText("unbenannt.txt", buffer);
|
|
|
|
|
else saveText(argv[1], buffer);
|
|
|
|
|
done = TRUE;
|
|
|
|
|
}
|
|
|
|
|
if(ret == 2)
|
|
|
|
|
{
|
|
|
|
|
done = TRUE;
|
|
|
|
|
}
|
|
|
|
|
if(ret == 0)
|
|
|
|
|
{
|
|
|
|
|
done = FALSE;
|
|
|
|
|
}
|
2021-11-25 11:14:40 +01:00
|
|
|
|
}
|
2021-12-02 10:05:42 +01:00
|
|
|
|
else done = TRUE;
|
2021-11-25 11:14:40 +01:00
|
|
|
|
break;
|
2021-12-02 10:05:42 +01:00
|
|
|
|
|
|
|
|
|
case WMHI_GADGETUP:
|
|
|
|
|
{
|
|
|
|
|
switch(result & WMHI_GADGETMASK)
|
|
|
|
|
{
|
|
|
|
|
case GID_TEXTEDITOR:
|
|
|
|
|
GetAttr(GA_TEXTEDITOR_HasChanged, gadgets[GID_TEXTEDITOR], &changed);
|
|
|
|
|
|
|
|
|
|
if(changed == 1) printf("Ge<EFBFBD>ndert\n");
|
|
|
|
|
if(changed == 0) printf("Nicht ge<67>ndert\n");
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-11-25 11:14:40 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-02 10:05:42 +01:00
|
|
|
|
DisposeObject(beenden_object);
|
2021-11-25 11:14:40 +01:00
|
|
|
|
DisposeObject(Win_Object);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
closeLibraries();
|
|
|
|
|
|
2021-12-02 10:05:42 +01:00
|
|
|
|
if(titel) free(titel);
|
2021-11-25 11:14:40 +01:00
|
|
|
|
if(buf) free(buf);
|
|
|
|
|
}
|