34 char *UnitTypes[5] = {"CLASS","PROCEDURE","FUNCTION","PROCESS","COROUTINE"};
37 My_Edit::My_Edit(QWidget *parent=0,const char *name=0)
38 : QMultiLineEdit(parent,name)
42 void My_Edit::keyPressEvent(QKeyEvent *ev)
44 QMultiLineEdit::keyPressEvent(ev);
49 Editor::Editor( char *hdir,QWidget * parent , const char * name)
50 : QWidget( parent, name )
52 QFont f1("Helvetica",12,QFont::Bold);
58 m = new QMenuBar( this, "menu" );
60 QPopupMenu * file = new QPopupMenu();
61 QPopupMenu * comp = new QPopupMenu();
62 QPopupMenu * loglan = new QPopupMenu();
63 QPopupMenu *medit = new QPopupMenu();
71 m->insertItem( "&File ", file );
72 m->insertItem( "&Edit", medit );
73 m->insertItem( "&Compile", this,SLOT(cmp()) );
75 // m->insertItem( "&LOGLAN ", loglan );
76 m->insertItem( "&Properties", this, SLOT(props()));
81 file->insertItem( "New ", this, SLOT(create()), CTRL+Key_N);
82 file->insertItem( "Open ", this, SLOT(load()), CTRL+Key_O);
83 file->insertItem( "Save ", this, SLOT(save()),CTRL+Key_S);
84 file->insertItem( "Save as", this, SLOT(save_as()),CTRL+Key_A);
85 file->insertSeparator();
86 file->insertItem( "Quit ", qApp, SLOT(quit()));
88 // comp->insertItem( "Compile ", this, SLOT(cmp()), CTRL+Key_C);
89 // comp->insertItem( "Gen ", this, SLOT(gen()), CTRL+Key_G);
90 // comp->insertItem( "Compile & Gen ", this, SLOT(comp_all()));
92 // loglan->insertItem( "Program structure", this, SLOT(log_prog()));
93 // loglan->insertItem( "Unit structure", this, SLOT(log_unit()));
97 e = new My_Edit( this, "editor" );
98 connect(e,SIGNAL(cursorMove()),this,SLOT(updateline()));
99 medit->insertItem("Copy ",e,SLOT(copyText()),CTRL+Key_Insert);
100 medit->insertItem("Paste ",e,SLOT(paste()), SHIFT+Key_Insert);
101 medit->insertItem("Cut ",e,SLOT(cut()), CTRL+Key_Delete);
102 medit->insertItem("Clear All ",e,SLOT(clear()));
103 medit->insertSeparator();
104 medit->insertItem("Find ",this,SLOT(findText()), CTRL+Key_F);
105 medit->insertItem("Find Next ",this,SLOT(find_next()),CTRL+Key_L);
107 msg = new QMultiLineEdit( this, "messages" );
108 msg->setReadOnly(TRUE);
109 compiler_path.sprintf("%s/%s",HomeDir,"compile/logcomp");
110 gen_path.sprintf("%s/%s",HomeDir,"compile/gen");
111 file_path.sprintf("%s",HomeDir);
113 QFont f2("Times",14,QFont::Bold);
115 QColor col(200,200,200);
116 QColorGroup grp(black,col,col.light(),col.dark(),col.dark(),black,col);
118 msg->setPalette(QPalette(grp,grp,grp));
119 position = new QLabel(this);
120 position->setFont(f2);
121 position->setFrameStyle(QFrame::NoFrame);
122 position->setAutoResize(TRUE);
136 void Editor::updateline()
141 e->getCursorPosition(&cx,&cy);
142 sprintf(pom," %d:%d ",cx,cy);
143 position->setText(pom);
146 void Editor::resizeEvent( QResizeEvent * )
150 e->setGeometry( 0, m->height(), width(), 3*(int)(( height() - m->height() )/4) );
151 msg->setGeometry( 0, m->height()+ e->height(), width(), (int)(( height() - m->height() )/4) );
152 position->setGeometry(width()-80,m->height()+ e->height()-10,
153 position->width(),position->height());
160 QString fn = QFileDialog::getOpenFileName(file_path.data(),"*.log");
166 void Editor::load( const char *fileName )
168 fname.sprintf("%s",fileName);
172 if ( !f.open( IO_ReadOnly ) )
175 e->setAutoUpdate( FALSE );
180 QString s = t.readLine();
185 e->setAutoUpdate( TRUE );
187 setCaption( fileName );
195 QString fn = QFileDialog::getSaveFileName(file_path.data(),"*.log");
198 fname.sprintf("%s",fn.data());
207 void Editor::save_as()
209 QString fn = QFileDialog::getSaveFileName(file_path.data(),"*.log");
212 fname.sprintf("%s",fn.data());
218 void Editor::save(const char *fileName)
222 if (!f.open(IO_WriteOnly)) return;
224 f.writeBlock( e->text().data(),e->text().size() );
231 void Editor::create()
234 fname.sprintf("%s","");
256 void Editor::comp_all()
263 void Editor::compile(int mode)
267 msg->setAutoUpdate( FALSE );
268 msg->setReadOnly(FALSE);
273 //i = fname.find('.');
276 QString fn = fname.data();
283 sprintf(cmd,"%s %s > comp_data!",compiler_path.data(),fname.data());
286 sprintf(cmd,"%s %s > comp_data!",gen_path.data(),fn.data());
289 sprintf(cmd,"%s %s > comp_data!",compiler_path.data(),fn.data());
291 sprintf(cmd,"%s %s >> comp_data!",gen_path.data(),fn.data());
297 QFile f( "comp_data!" );
298 if ( !f.open( IO_ReadOnly ) )
304 QString s = t.readLine();
308 msg->setReadOnly(TRUE);
309 msg->setAutoUpdate( TRUE );
311 unlink("comp_data!");
319 QDialog dlg(this,"Properties",TRUE);
323 files = new QLineEdit( &dlg, "f_path" );
324 files->setGeometry( 130, 20, 250, 30 );
325 files->setText( file_path.data() );
326 files->setMaxLength( 32767 );
327 files->setEchoMode( QLineEdit::Normal );
328 files->setFrame( TRUE );
331 tmpQLabel = new QLabel( &dlg, "Label_1" );
332 tmpQLabel->setGeometry( 10, 20, 100, 30 );
333 tmpQLabel->setText( "Path to files:" );
334 tmpQLabel->setAlignment( 289 );
335 tmpQLabel->setMargin( -1 );
337 tmpQLabel = new QLabel( &dlg, "Label_2" );
338 tmpQLabel->setGeometry( 10, 60, 100, 30 );
339 tmpQLabel->setText( "Path to compiler:" );
340 tmpQLabel->setAlignment( 289 );
341 tmpQLabel->setMargin( -1 );
343 /* tmpQLabel = new QLabel( &dlg, "Label_3" );
344 tmpQLabel->setGeometry( 10, 100, 100, 30 );
345 tmpQLabel->setText( "Path to gen:" );
346 tmpQLabel->setAlignment( 289 );
347 tmpQLabel->setMargin( -1 );*/
350 compp = new QLineEdit( &dlg, "l_path" );
351 compp->setGeometry( 130, 60, 250, 30 );
352 compp->setText( compiler_path.data() );
353 compp->setMaxLength( 32767 );
354 compp->setEchoMode( QLineEdit::Normal );
355 compp->setFrame( TRUE );
358 genp = new QLineEdit( &dlg, "g_path" );
359 genp->setGeometry( 130, 100, 250, 30 );
360 genp->setText( gen_path.data() );
361 genp->setMaxLength( 32767 );
362 genp->setEchoMode( QLineEdit::Normal );
363 genp->setFrame( TRUE );*/
366 QPushButton* tmpQPushButton;
367 tmpQPushButton = new QPushButton( &dlg, "OkBtn" );
368 tmpQPushButton->setGeometry( 90, 100, 70, 30 );
369 tmpQPushButton->setText( "Ok" );
370 tmpQPushButton->setAutoRepeat( FALSE );
371 tmpQPushButton->setAutoResize( FALSE );
372 connect(tmpQPushButton,SIGNAL(clicked()),&dlg,SLOT(accept()));
374 tmpQPushButton = new QPushButton( &dlg, "CancelBtn" );
375 tmpQPushButton->setGeometry( 180, 100, 70, 30 );
376 tmpQPushButton->setText( "Cancel" );
377 tmpQPushButton->setAutoRepeat( FALSE );
378 tmpQPushButton->setAutoResize( FALSE );
379 connect(tmpQPushButton,SIGNAL(clicked()),&dlg,SLOT(reject()));
384 compiler_path.sprintf("%s",compp->text());
385 // gen_path.sprintf("%s",genp->text());
386 file_path.sprintf("%s",files->text());
390 /* --------------------------------------- */
396 void Editor::log_unit()
399 QDialog dlg(this,"unit",TRUE);
405 files = new QLineEdit( &dlg, "f_path" );
406 files->setGeometry( 130, 20, 250, 30 );
408 files->setMaxLength( 32767 );
409 files->setEchoMode( QLineEdit::Normal );
410 files->setFrame( TRUE );
413 tmpQLabel = new QLabel( &dlg, "Label_1" );
414 tmpQLabel->setGeometry( 10, 20, 100, 30 );
415 tmpQLabel->setText( "Unit name:" );
416 tmpQLabel->setAlignment( 289 );
417 tmpQLabel->setMargin( -1 );
419 QPushButton* tmpQPushButton;
420 tmpQPushButton = new QPushButton( &dlg, "OkBtn" );
421 tmpQPushButton->setGeometry( 40, 170, 70, 30 );
422 tmpQPushButton->setText( "Ok" );
423 tmpQPushButton->setAutoRepeat( FALSE );
424 tmpQPushButton->setAutoResize( FALSE );
425 connect(tmpQPushButton,SIGNAL(clicked()),&dlg,SLOT(accept()));
427 tmpQPushButton = new QPushButton( &dlg, "CancelBtn" );
428 tmpQPushButton->setGeometry( 130, 170, 100, 30 );
429 tmpQPushButton->setText( "Cancel" );
430 tmpQPushButton->setAutoRepeat( FALSE );
431 tmpQPushButton->setAutoResize( FALSE );
432 connect(tmpQPushButton,SIGNAL(clicked()),&dlg,SLOT(reject()));
434 tmpQLabel = new QLabel( &dlg, "Label_1" );
435 tmpQLabel->setGeometry( 10, 50, 100, 60 );
436 tmpQLabel->setText( "Unit type:" );
439 QListBox lst(&dlg,"type");
440 for(i=0;i<TYPENUM;i++) lst.insertItem(UnitTypes[i]);
441 lst.setGeometry(130,60,180,80);
442 lst.setCurrentItem(0);
446 strcpy(uname,files->text());
447 e->getCursorPosition(&cx,&cy);
449 txt.sprintf("UNIT %s : %s( <params> );\nBEGIN\n\nEND %s;",uname,
450 lst.text(lst.currentItem()), uname);
451 e->insertAt(txt,cx,cy);
456 void Editor::log_prog()
459 QDialog dlg(this,"unit",TRUE);
465 files = new QLineEdit( &dlg, "f_path" );
466 files->setGeometry( 130, 20, 250, 30 );
468 files->setMaxLength( 32767 );
469 files->setEchoMode( QLineEdit::Normal );
470 files->setFrame( TRUE );
473 tmpQLabel = new QLabel( &dlg, "Label_1" );
474 tmpQLabel->setGeometry( 10, 20, 100, 30 );
475 tmpQLabel->setText( "Program name:" );
477 QPushButton* tmpQPushButton;
478 tmpQPushButton = new QPushButton( &dlg, "OkBtn" );
479 tmpQPushButton->setGeometry( 40, 70, 70, 30 );
480 tmpQPushButton->setText( "Ok" );
481 tmpQPushButton->setAutoRepeat( FALSE );
482 tmpQPushButton->setAutoResize( FALSE );
483 connect(tmpQPushButton,SIGNAL(clicked()),&dlg,SLOT(accept()));
485 tmpQPushButton = new QPushButton( &dlg, "CancelBtn" );
486 tmpQPushButton->setGeometry( 130, 70, 100, 30 );
487 tmpQPushButton->setText( "Cancel" );
488 tmpQPushButton->setAutoRepeat( FALSE );
489 tmpQPushButton->setAutoResize( FALSE );
490 connect(tmpQPushButton,SIGNAL(clicked()),&dlg,SLOT(reject()));
495 strcpy(uname,files->text());
496 e->getCursorPosition(&cx,&cy);
498 txt.sprintf("PROGRAM %s\n\nBEGIN\n\nEND ",uname);
499 e->insertAt(txt,cx,cy);
505 void Editor::findText()
507 QDialog dlg(this,"",TRUE);
512 QLineEdit* tmpQLineEdit;
513 tmpQLineEdit = new QLineEdit( &dlg, "LineEdit_1" );
514 tmpQLineEdit->setGeometry( 60, 10, 180, 30 );
515 tmpQLineEdit->setText( "" );
518 tmpQLabel = new QLabel( &dlg, "Label_1" );
519 tmpQLabel->setGeometry( 10, 10, 50, 30 );
521 QFont font( "helvetica", 12, 75, 0 );
522 font.setStyleHint( (QFont::StyleHint)0 );
523 font.setCharSet( (QFont::CharSet)0 );
524 tmpQLabel->setFont( font );
526 tmpQLabel->setText( "Text:" );
528 QCheckBox* tmpQRadioButton;
529 tmpQRadioButton = new QCheckBox( &dlg, "RadioButton_1" );
530 tmpQRadioButton->setGeometry( 70, 50, 150, 30 );
531 tmpQRadioButton->setText( "Case sensitive" );
532 tmpQRadioButton->setAutoRepeat( FALSE );
533 tmpQRadioButton->setAutoResize( FALSE );
535 QPushButton *okbtn, *cbtn;
536 okbtn = new QPushButton( &dlg, "PushButton_1" );
537 okbtn->setGeometry( 260, 10, 100, 30 );
538 okbtn->setText( "Find" );
539 okbtn->setDefault(TRUE);
540 connect(okbtn,SIGNAL(clicked()),&dlg,SLOT(accept()));
542 cbtn = new QPushButton( &dlg, "PushButton_2" );
543 cbtn->setGeometry( 260, 50, 100, 30 );
544 cbtn->setText( "Close" );
545 connect(cbtn,SIGNAL(clicked()),&dlg,SLOT(reject()));
546 dlg.resize( 380, 90 );
550 e->getCursorPosition(&pom,&res);
551 sensitive=tmpQRadioButton->isChecked();
552 for(line=pom+1;line<e->numLines();line++)
554 txt = new QString(e->textLine(line));
555 if (tmpQRadioButton->isChecked())
556 res=txt->find(tmpQLineEdit->text(),0,TRUE);
558 res=txt->find(tmpQLineEdit->text(),0,FALSE);
560 if (res>=0) { e->setCursorPosition(line,1);strcpy(find_text,tmpQLineEdit->text());
567 void Editor::find_next()
572 e->getCursorPosition(&pom,&res);
573 for(line=pom+1;line<e->numLines();line++)
575 txt = new QString(e->textLine(line));
577 res=txt->find(find_text,0,TRUE);
579 res=txt->find(find_text,0,FALSE);
581 if (res>=0) { e->setCursorPosition(line,1);
587 int main( int argc, char **argv )
589 QApplication a( argc, argv );
590 a.setStyle(WindowsStyle);
591 e = new Editor(argv[1]);
592 e->resize( 600, 400 );