34 char *UnitTypes[5] = {"CLASS","PROCEDURE","FUNCTION","PROCESS","COROUTINE"};
39 My_Edit::My_Edit(QWidget *parent,const char *name)
40 : QMultiLineEdit(parent,name)
46 void My_Edit::keyPressEvent(QKeyEvent *ev)
48 QMultiLineEdit::keyPressEvent(ev);
53 void Editor::closeEvent ( QCloseEvent * e ) {
57 Editor::Editor( char *hdir,QWidget * parent , const char * name)
58 : QWidget( parent, name )
60 QFont f1("Helvetica",10,QFont::Bold);
66 m = new QMenuBar( this, "menu" );
68 QPopupMenu * file = new QPopupMenu();
69 QPopupMenu * comp = new QPopupMenu();
70 QPopupMenu * loglan = new QPopupMenu();
71 QPopupMenu *medit = new QPopupMenu();
79 m->insertItem( "&File ", file );
80 m->insertItem( "&Edit", medit );
81 m->insertItem( "&Compile", this,SLOT(cmp()) );
83 // m->insertItem( "&LOGLAN ", loglan );
84 m->insertItem( "&Properties", this, SLOT(props()));
89 file->insertItem( "New ", this, SLOT(create()), CTRL+Key_N);
90 file->insertItem( "Open ", this, SLOT(load()), CTRL+Key_O);
91 file->insertItem( "Save ", this, SLOT(save()),CTRL+Key_S);
92 file->insertItem( "Save as", this, SLOT(save_as()),CTRL+Key_A);
93 file->insertSeparator();
94 file->insertItem( "Quit ", qApp, SLOT(quit()));
96 // comp->insertItem( "Compile ", this, SLOT(cmp()), CTRL+Key_C);
97 // comp->insertItem( "Gen ", this, SLOT(gen()), CTRL+Key_G);
98 // comp->insertItem( "Compile & Gen ", this, SLOT(comp_all()));
100 // loglan->insertItem( "Program structure", this, SLOT(log_prog()));
101 // loglan->insertItem( "Unit structure", this, SLOT(log_unit()));
105 e = new My_Edit( this, "editor" );
106 connect(e,SIGNAL(cursorMove()),this,SLOT(updateline()));
107 medit->insertItem("Copy ",e,SLOT(copy()),CTRL+Key_Insert);
108 medit->insertItem("Paste ",e,SLOT(paste()), SHIFT+Key_Insert);
109 medit->insertItem("Cut ",e,SLOT(cut()), CTRL+Key_Delete);
110 medit->insertItem("Clear All ",e,SLOT(clear()));
111 medit->insertSeparator();
112 medit->insertItem("Find ",this,SLOT(findText()), CTRL+Key_F);
113 medit->insertItem("Find Next ",this,SLOT(find_next()),CTRL+Key_L);
115 msg = new QMultiLineEdit( this, "messages" );
116 msg->setReadOnly(TRUE);
117 compiler_path.sprintf("%s/%s",HomeDir,"compile/logcomp");
118 gen_path.sprintf("%s/%s",HomeDir,"compile/gen");
119 file_path.sprintf("%s",HomeDir);
121 QFont f2("Times",14,QFont::Bold);
123 QColor col(200,200,200);
124 QColorGroup grp(black,col,col.light(),col.dark(),col.dark(),black,col);
126 msg->setPalette(QPalette(grp,grp,grp));
127 position = new QLabel(this);
128 position->setFont(f2);
129 position->setFrameStyle(QFrame::NoFrame);
130 position->setAutoResize(TRUE);
144 void Editor::updateline()
149 e->getCursorPosition(&cx,&cy);
150 sprintf(pom," %d:%d ",cx,cy);
151 position->setText(pom);
154 void Editor::resizeEvent( QResizeEvent * )
158 e->setGeometry( 0, m->height(), width(), 3*(int)(( height() - m->height() )/4) );
159 msg->setGeometry( 0, m->height()+ e->height(), width(), (int)(( height() - m->height() )/4) );
160 position->setGeometry(width()-80,m->height()+ e->height()-10,
161 position->width(),position->height());
168 QString fn = QFileDialog::getOpenFileName(file_path.data(),"*.log");
174 void Editor::load( const char *fileName )
176 fname.sprintf("%s",fileName);
180 if ( !f.open( IO_ReadOnly ) )
183 e->setAutoUpdate( FALSE );
188 QString s = t.readLine();
193 e->setAutoUpdate( TRUE );
195 setCaption( fileName );
203 QString fn = QFileDialog::getSaveFileName(file_path.data(),"*.log");
206 fname.sprintf("%s",fn.data());
215 void Editor::save_as()
217 QString fn = QFileDialog::getSaveFileName(file_path.data(),"*.log");
220 fname.sprintf("%s",fn.data());
226 void Editor::save(const char *fileName)
230 if (!f.open(IO_WriteOnly)) return;
232 f.writeBlock( e->text().data(),e->text().length() );
239 void Editor::create()
242 fname.sprintf("%s","");
264 void Editor::comp_all()
271 void Editor::compile(int mode)
275 msg->setAutoUpdate( FALSE );
276 msg->setReadOnly(FALSE);
281 //i = fname.find('.');
284 QString fn = fname.data();
291 sprintf(cmd,"%s %s > comp_data!",compiler_path.data(),fname.data());
294 sprintf(cmd,"%s %s > comp_data!",gen_path.data(),fn.data());
297 sprintf(cmd,"%s %s > comp_data!",compiler_path.data(),fn.data());
299 sprintf(cmd,"%s %s >> comp_data!",gen_path.data(),fn.data());
305 QFile f( "comp_data!" );
306 if ( !f.open( IO_ReadOnly ) )
312 QString s = t.readLine();
316 msg->setReadOnly(TRUE);
317 msg->setAutoUpdate( TRUE );
319 unlink("comp_data!");
327 QDialog dlg(this,"Properties",TRUE);
331 files = new QLineEdit( &dlg, "f_path" );
332 files->setGeometry( 130, 20, 250, 30 );
333 files->setText( file_path.data() );
334 files->setMaxLength( 32767 );
335 files->setEchoMode( QLineEdit::Normal );
336 files->setFrame( TRUE );
339 tmpQLabel = new QLabel( &dlg, "Label_1" );
340 tmpQLabel->setGeometry( 10, 20, 100, 30 );
341 tmpQLabel->setText( "Path to files:" );
342 tmpQLabel->setAlignment( 289 );
343 tmpQLabel->setMargin( -1 );
345 tmpQLabel = new QLabel( &dlg, "Label_2" );
346 tmpQLabel->setGeometry( 10, 60, 100, 30 );
347 tmpQLabel->setText( "Path to compiler:" );
348 tmpQLabel->setAlignment( 289 );
349 tmpQLabel->setMargin( -1 );
351 /* tmpQLabel = new QLabel( &dlg, "Label_3" );
352 tmpQLabel->setGeometry( 10, 100, 100, 30 );
353 tmpQLabel->setText( "Path to gen:" );
354 tmpQLabel->setAlignment( 289 );
355 tmpQLabel->setMargin( -1 );*/
358 compp = new QLineEdit( &dlg, "l_path" );
359 compp->setGeometry( 130, 60, 250, 30 );
360 compp->setText( compiler_path.data() );
361 compp->setMaxLength( 32767 );
362 compp->setEchoMode( QLineEdit::Normal );
363 compp->setFrame( TRUE );
366 genp = new QLineEdit( &dlg, "g_path" );
367 genp->setGeometry( 130, 100, 250, 30 );
368 genp->setText( gen_path.data() );
369 genp->setMaxLength( 32767 );
370 genp->setEchoMode( QLineEdit::Normal );
371 genp->setFrame( TRUE );*/
374 QPushButton* tmpQPushButton;
375 tmpQPushButton = new QPushButton( &dlg, "OkBtn" );
376 tmpQPushButton->setGeometry( 90, 100, 70, 30 );
377 tmpQPushButton->setText( "Ok" );
378 tmpQPushButton->setAutoRepeat( FALSE );
379 tmpQPushButton->setAutoResize( FALSE );
380 connect(tmpQPushButton,SIGNAL(clicked()),&dlg,SLOT(accept()));
382 tmpQPushButton = new QPushButton( &dlg, "CancelBtn" );
383 tmpQPushButton->setGeometry( 180, 100, 70, 30 );
384 tmpQPushButton->setText( "Cancel" );
385 tmpQPushButton->setAutoRepeat( FALSE );
386 tmpQPushButton->setAutoResize( FALSE );
387 connect(tmpQPushButton,SIGNAL(clicked()),&dlg,SLOT(reject()));
392 compiler_path.sprintf("%s",compp->text().ascii());
393 // gen_path.sprintf("%s",genp->text());
394 file_path.sprintf("%s",files->text().ascii());
398 /* --------------------------------------- */
404 void Editor::log_unit()
407 QDialog dlg(this,"unit",TRUE);
413 files = new QLineEdit( &dlg, "f_path" );
414 files->setGeometry( 130, 20, 250, 30 );
416 files->setMaxLength( 32767 );
417 files->setEchoMode( QLineEdit::Normal );
418 files->setFrame( TRUE );
421 tmpQLabel = new QLabel( &dlg, "Label_1" );
422 tmpQLabel->setGeometry( 10, 20, 100, 30 );
423 tmpQLabel->setText( "Unit name:" );
424 tmpQLabel->setAlignment( 289 );
425 tmpQLabel->setMargin( -1 );
427 QPushButton* tmpQPushButton;
428 tmpQPushButton = new QPushButton( &dlg, "OkBtn" );
429 tmpQPushButton->setGeometry( 40, 170, 70, 30 );
430 tmpQPushButton->setText( "Ok" );
431 tmpQPushButton->setAutoRepeat( FALSE );
432 tmpQPushButton->setAutoResize( FALSE );
433 connect(tmpQPushButton,SIGNAL(clicked()),&dlg,SLOT(accept()));
435 tmpQPushButton = new QPushButton( &dlg, "CancelBtn" );
436 tmpQPushButton->setGeometry( 130, 170, 100, 30 );
437 tmpQPushButton->setText( "Cancel" );
438 tmpQPushButton->setAutoRepeat( FALSE );
439 tmpQPushButton->setAutoResize( FALSE );
440 connect(tmpQPushButton,SIGNAL(clicked()),&dlg,SLOT(reject()));
442 tmpQLabel = new QLabel( &dlg, "Label_1" );
443 tmpQLabel->setGeometry( 10, 50, 100, 60 );
444 tmpQLabel->setText( "Unit type:" );
447 QListBox lst(&dlg,"type");
448 for(i=0;i<TYPENUM;i++) lst.insertItem(UnitTypes[i]);
449 lst.setGeometry(130,60,180,80);
450 lst.setCurrentItem(0);
454 strcpy(uname,files->text());
455 e->getCursorPosition(&cx,&cy);
457 txt.sprintf("UNIT %s : %s( <params> );\nBEGIN\n\nEND %s;",uname,
458 lst.text(lst.currentItem()).ascii(), uname);
459 e->insertAt(txt,cx,cy);
464 void Editor::log_prog()
467 QDialog dlg(this,"unit",TRUE);
473 files = new QLineEdit( &dlg, "f_path" );
474 files->setGeometry( 130, 20, 250, 30 );
476 files->setMaxLength( 32767 );
477 files->setEchoMode( QLineEdit::Normal );
478 files->setFrame( TRUE );
481 tmpQLabel = new QLabel( &dlg, "Label_1" );
482 tmpQLabel->setGeometry( 10, 20, 100, 30 );
483 tmpQLabel->setText( "Program name:" );
485 QPushButton* tmpQPushButton;
486 tmpQPushButton = new QPushButton( &dlg, "OkBtn" );
487 tmpQPushButton->setGeometry( 40, 70, 70, 30 );
488 tmpQPushButton->setText( "Ok" );
489 tmpQPushButton->setAutoRepeat( FALSE );
490 tmpQPushButton->setAutoResize( FALSE );
491 connect(tmpQPushButton,SIGNAL(clicked()),&dlg,SLOT(accept()));
493 tmpQPushButton = new QPushButton( &dlg, "CancelBtn" );
494 tmpQPushButton->setGeometry( 130, 70, 100, 30 );
495 tmpQPushButton->setText( "Cancel" );
496 tmpQPushButton->setAutoRepeat( FALSE );
497 tmpQPushButton->setAutoResize( FALSE );
498 connect(tmpQPushButton,SIGNAL(clicked()),&dlg,SLOT(reject()));
503 strcpy(uname,files->text());
504 e->getCursorPosition(&cx,&cy);
506 txt.sprintf("PROGRAM %s\n\nBEGIN\n\nEND ",uname);
507 e->insertAt(txt,cx,cy);
513 void Editor::findText()
515 QDialog dlg(this,"",TRUE);
520 QLineEdit* tmpQLineEdit;
521 tmpQLineEdit = new QLineEdit( &dlg, "LineEdit_1" );
522 tmpQLineEdit->setGeometry( 60, 10, 180, 30 );
523 tmpQLineEdit->setText( "" );
526 tmpQLabel = new QLabel( &dlg, "Label_1" );
527 tmpQLabel->setGeometry( 10, 10, 50, 30 );
529 QFont font( "helvetica", 12, 75, 0 );
530 font.setStyleHint( (QFont::StyleHint)0 );
531 //font.setCharSet( (QFont::CharSet)0 );
532 tmpQLabel->setFont( font );
534 tmpQLabel->setText( "Text:" );
536 QCheckBox* tmpQRadioButton;
537 tmpQRadioButton = new QCheckBox( &dlg, "RadioButton_1" );
538 tmpQRadioButton->setGeometry( 70, 50, 150, 30 );
539 tmpQRadioButton->setText( "Case sensitive" );
540 tmpQRadioButton->setAutoRepeat( FALSE );
541 tmpQRadioButton->setAutoResize( FALSE );
543 QPushButton *okbtn, *cbtn;
544 okbtn = new QPushButton( &dlg, "PushButton_1" );
545 okbtn->setGeometry( 260, 10, 100, 30 );
546 okbtn->setText( "Find" );
547 okbtn->setDefault(TRUE);
548 connect(okbtn,SIGNAL(clicked()),&dlg,SLOT(accept()));
550 cbtn = new QPushButton( &dlg, "PushButton_2" );
551 cbtn->setGeometry( 260, 50, 100, 30 );
552 cbtn->setText( "Close" );
553 connect(cbtn,SIGNAL(clicked()),&dlg,SLOT(reject()));
554 dlg.resize( 380, 90 );
558 e->getCursorPosition(&pom,&res);
559 sensitive=tmpQRadioButton->isChecked();
560 for(line=pom+1;line<e->numLines();line++)
562 txt = new QString(e->textLine(line));
563 if (tmpQRadioButton->isChecked())
564 res=txt->find(tmpQLineEdit->text(),0,TRUE);
566 res=txt->find(tmpQLineEdit->text(),0,FALSE);
568 if (res>=0) { e->setCursorPosition(line,1);strcpy(find_text,tmpQLineEdit->text());
575 void Editor::find_next()
580 e->getCursorPosition(&pom,&res);
581 for(line=pom+1;line<e->numLines();line++)
583 txt = new QString(e->textLine(line));
585 res=txt->find(find_text,0,TRUE);
587 res=txt->find(find_text,0,FALSE);
589 if (res>=0) { e->setCursorPosition(line,1);
595 int main( int argc, char **argv )
597 QApplication a( argc, argv );
598 //a.setStyle(WindowsStyle);
599 e = new Editor(argv[1]);
600 e->resize( 600, 400 );