summaryrefslogtreecommitdiffstats
path: root/src/flowparts/embed.cpp
blob: 7e5f3a376cc84de298340d63f910519d468a25c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/***************************************************************************
 *   Copyright (C) 2003 by David Saxton                                    *
 *   david@bluehaze.org                                                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/

#include "embed.h"

#include "libraryitem.h"
#include "flowcode.h"

#include <klocale.h>

Item* Embed::construct( ItemDocument *itemDocument, bool newItem, const char *id )
{
	return new Embed( (ICNDocument*)itemDocument, newItem, id );
}

LibraryItem* Embed::libraryItem()
{
	return new LibraryItem(
		TQString("flow/embed"),
		i18n("Embed"),
		i18n("Common"),
		"embed.png",
		LibraryItem::lit_flowpart,
		Embed::construct
			);
}

Embed::Embed( ICNDocument *icnDocument, bool newItem, const char *id )
	: FlowPart( icnDocument, newItem, (id) ? id : "embed" )
{
	m_name = i18n("Embed");
	m_desc = i18n("Doubleclick on the item to edit the embedded code.");
	initProcessSymbol();
	createStdInput();
	createStdOutput();
	
	createProperty( "type", Variant::Type::Select );
	property("type")->setAllowed( TQStringList::split( ',', "Microbe,Assembly" ) );
	property("type")->setValue("Microbe");
	property("type")->setCaption( i18n("Type") ); // TODO: replace this with i18n( "the type", "Type" );
	
	createProperty( "code", Variant::Type::Multiline );
	property("code")->setCaption( i18n("Code") );
	property("code")->setValue( i18n("// Embedded code:") );
}

Embed::~Embed()
{
}


void Embed::dataChanged()
{
	const TQString sample = dataString("code").left(10).replace("\n"," ");
	setCaption( i18n("%1: %2...").arg(dataString("type")).arg(sample) );
}


bool Embed::typeIsMicrobe() const
{
	return dataString("type") == "Microbe";
}


void Embed::generateMicrobe( FlowCode *code )
{
	if ( typeIsMicrobe() )
		code->addCode( dataString("code") );
	
	else
	{
		// Is assembly code, we need to microbe as such
		code->addCode("asm\n{");
		code->addCode( dataString("code") );
		code->addCode("}");
	}
	
	code->addCodeBranch( outputPart("stdoutput") );
}