Create code for Contenido-container

Ask questions about how to create a script or swap scripts with other users.
Post Reply
User avatar
Walti
Posts: 51
Joined: 06 Jul 2009 11:26
Location: Schweiz / Swiss / Swizerland
Contact:

Create code for Contenido-container

Post by Walti »

I made a script (cpp) to generate the code for a container for Contenido-CMS.

Code: Select all

TForm f;
TGroupbox g;
TRadioButton rb1,rb2;
TButton b;
TLabel idlabel;
TMemo id;
TLabel namelabel;
TMemo  name;
TRJDocument d;

void ButtonClick(TButton Sender)
{
       int fehler = 0;   string modus;
	   
  if (id.Lines[0] == "")        {  ShowMessage("Es wurde keine Modul-ID angegeben");    fehler = 1;  }
  else if (name.Lines[0] == "") {  ShowMessage("Es wurde keine Modul-Name angegeben");  fehler = 1;  }
  else
    {
      if (rb1.Checked) modus = "fixed";  else modus = "optional";

	  d.InsertText("<container id=\"");  d.InsertText(id.Lines[0]);
	  d.InsertText("\" name=\"");        d.InsertText(name.Lines[0]);
	  d.InsertText("\" types=\"content\" mode=\"");  d.InsertText(modus);
	  d.InsertText("\" default=\"");     d.InsertText(name.Lines[0]);
	  d.InsertText("\">");               d.InsertText(name.Lines[0]);
	  d.InsertText("</container>");
    }
  if (fehler == 0) f.ModalResult = mrOk;
}

{
   f = new TForm(nil);
   f.Caption = "Contenido - Container";
   f.BorderStyle = bsSizeable;
   f.Position = poScreenCenter;
   f.Width = 400;
   f.Height = 200;
   int w = f.ClientWidth;
   int h = f.ClientHeight;
   
   // Options ----------------------------
   g = new TGroupBox(f);
   g.Name = "gOptions";
   g.Parent = f;
   g.SetBounds(10, 10, 300, 50);
   g.Anchors = akLeft+akTop;
   g.Caption = "Typ";
   
   rb1 = new TRadioButton(g);
   rb1.Name = "rb1";
   rb1.Parent = g;
   rb1.Left = 10;
   rb1.Top = 20;
   rb1.Width = 100;
   rb1.Anchors = akLeft+akTop;
   rb1.Caption = "Fixed";
   rb1.Checked = True;
   
   rb2 = new TRadioButton(g);
   rb2.Name = "rb2";
   rb2.Parent = g;
   rb2.Parent = g;
   rb2.Left = 150;
   rb2.Top = 20;
   rb2.Width = 100;
   rb2.Anchors = akLeft+akTop;
   rb2.Caption = "Optional"; 
   //-------------------------------------

   // Input - ID
   idlabel = new TLabel(f);
   idlabel.Parent = f;
   idlabel.Left = 10;
   idlabel.Top  = 70;  
   idlabel.Width = 75;
   idlabel.Height = 20;
   idlabel.Caption = "ID-Nummer:";
   
   id = new TMemo(f);
   id.Parent = f;
   id.Left = 80;
   id.Top  = 70;  
   id.Width = 50;
   id.Height = 20;
   id.MaxLength = 6;
   //-------------------------------------

   // Input - Name
   namelabel = new TLabel(f);
   namelabel.Parent = f;
   namelabel.Left = 10;
   namelabel.Top  = 100;  
   namelabel.Width = 75;
   namelabel.Height = 20;
   namelabel.Caption = "Modul-Name:";
   
   name = new TMemo(f);
   name.Parent = f;
   name.Left = 80;
   name.Top  = 100;  
   name.Width = 250;
   name.Height = 20;
   name.MaxLength = 100;
   //-------------------------------------

   // Go button
   b = new TButton(f);
   b.Name = "btnGo";
   b.Parent = f;
   b.Left = 150;
   b.Top = 140;
   b.Width = 100;
   b.Caption = "Generieren";

   b.OnClick = &ButtonClick; 
   
   // Show the dialog
   f.ShowModal;
   f.Free;

}
How can i generate a Carriage-Return/Linefeed after output of the Codeline with d.InsertText(); ?
InsertText("\n"); don't works.

If no special char is working at the time, i would ask for this as future, so i can output a string like this:
s = "row1\nrow2\nrow3\n"; InsertText(s);
which should output 3 separetet lines of text plus cursor on a new line after that.

Thx a lot for this fine Editor

Walti
User avatar
Rickard Johansson
Site Admin
Posts: 6627
Joined: 19 Jul 2006 14:29

Post by Rickard Johansson »

You have to use d.InsertText("\r\n");

So,

s = "row1\r\nrow2\r\nrow3\r\n";
d.InsertText(s);

should work.
User avatar
Walti
Posts: 51
Joined: 06 Jul 2009 11:26
Location: Schweiz / Swiss / Swizerland
Contact:

Post by Walti »

thx Richard, it works
User avatar
Walti
Posts: 51
Joined: 06 Jul 2009 11:26
Location: Schweiz / Swiss / Swizerland
Contact:

Post by Walti »

the finish script to create a Contenido-CMS-Container (German):

Code: Select all

TForm f;
TGroupbox g;
TRadioButton rb1,rb2;
TButton b;
TLabel idlabel;
TMemo id;
TLabel namelabel;
TMemo  name;
TRJDocument d;

void ButtonClick(TButton Sender)
{
       int fehler = 0;   string modus;
	   
  if (id.Lines[0] == "")        {  ShowMessage("Es wurde keine Modul-ID angegeben");    fehler = 1;  }
  else if (name.Lines[0] == "") {  ShowMessage("Es wurde keine Modul-Name angegeben");  fehler = 1;  }
  else
    {
      if (rb1.Checked) modus = "fixed";  else modus = "optional";

	  d.InsertText("<container id=\"");  d.InsertText(id.Lines[0]);
	  d.InsertText("\" name=\"");        d.InsertText(name.Lines[0]);
	  d.InsertText("\" types=\"content\" mode=\"");  d.InsertText(modus);
	  d.InsertText("\" default=\"");     d.InsertText(name.Lines[0]);
	  d.InsertText("\">");               d.InsertText(name.Lines[0]);
	  d.InsertText("</container>\r\n");
    }
  if (fehler == 0) f.ModalResult = mrOk;
}

{
   f = new TForm(nil);
   f.Caption = "Contenido - Container";
   f.BorderStyle = bsSizeable;
   f.Position = poScreenCenter;
   f.Width = 400;
   f.Height = 200;
   int w = f.ClientWidth;
   int h = f.ClientHeight;
   
   // Options ----------------------------
   g = new TGroupBox(f);
   g.Name = "gOptions";
   g.Parent = f;
   g.SetBounds(10, 10, 300, 50);
   g.Anchors = akLeft+akTop;
   g.Caption = "Typ";
   
   rb1 = new TRadioButton(g);
   rb1.Name = "rb1";
   rb1.Parent = g;
   rb1.Left = 10;
   rb1.Top = 20;
   rb1.Width = 100;
   rb1.Anchors = akLeft+akTop;
   rb1.Caption = "Fixed";
   rb1.Checked = True;
   
   rb2 = new TRadioButton(g);
   rb2.Name = "rb2";
   rb2.Parent = g;
   rb2.Parent = g;
   rb2.Left = 150;
   rb2.Top = 20;
   rb2.Width = 100;
   rb2.Anchors = akLeft+akTop;
   rb2.Caption = "Optional"; 
   //-------------------------------------

   // Input - ID
   idlabel = new TLabel(f);
   idlabel.Parent = f;
   idlabel.Left = 10;
   idlabel.Top  = 70;  
   idlabel.Width = 75;
   idlabel.Height = 20;
   idlabel.Caption = "ID-Nummer:";
   
   id = new TMemo(f);
   id.Parent = f;
   id.Left = 80;
   id.Top  = 70;  
   id.Width = 50;
   id.Height = 20;
   id.MaxLength = 6;
   //-------------------------------------

   // Input - Name
   namelabel = new TLabel(f);
   namelabel.Parent = f;
   namelabel.Left = 10;
   namelabel.Top  = 100;  
   namelabel.Width = 75;
   namelabel.Height = 20;
   namelabel.Caption = "Modul-Name:";
   
   name = new TMemo(f);
   name.Parent = f;
   name.Left = 80;
   name.Top  = 100;  
   name.Width = 250;
   name.Height = 20;
   name.MaxLength = 100;
   //-------------------------------------

   // Go button
   b = new TButton(f);
   b.Name = "btnGo";
   b.Parent = f;
   b.Left = 150;
   b.Top = 140;
   b.Width = 100;
   b.Caption = "Generieren";

   b.OnClick = &ButtonClick; 
   
   // Show the dialog
   f.ShowModal;
   f.Free;

}
feel free to use and change it
Post Reply