com gtk/php-gtk: Fixed bug with GtkTextBuffer::set_text passing to many parameters Added colorized highl ighted output to source code viewer.: demos/php gtk2-demo.php
[email protected] (David Soria Parra) Sun, 09 Oct 2005 23:03:06 +0000
| Newsgroups | php.gtk.cvs |
|---|---|
| Message-ID | <[email protected]> |
Commit: b57f26c582e3639b428130a968145f1b830af12f=0AAuthor: Jeremy S. = Johnstone <[email protected]> Sun, 9 Oct 2005 23:03:06 +0000=0AParen= ts: 61f16601ba13a13f5234474957527494eae9ef04=0ABranches: master=0A=0ALin= k: http://git.php.net/?p=3Dgtk/php-gtk.git;a=3Dcommitdiff;h=3Db57f26c= 582e3639b428130a968145f1b830af12f=0A=0ALog:=0AFixed bug with GtkTextBuffer:= :set_text passing to many parameters=0AAdded colorized highlighted output t= o source code viewer.=0A=0AChanged paths:=0A M demos/phpgtk2-demo.php=0A= =0A=0ADiff:=0Ab57f26c582e3639b428130a968145f1b830af12f=0Adiff --git a/demos= /phpgtk2-demo.php b/demos/phpgtk2-demo.php=0Aindex d9c3067..e401865 100644= =0A--- a/demos/phpgtk2-demo.php=0A+++ b/demos/phpgtk2-demo.php=0A@@ -14,17 = +14,9 @@ class PHPGtk2Demo extends GtkWindow=0A protected $description_= buffer;=0A protected $demobox;=0A =0A- protected $cache =3D arra= y();=0A- =0A- protected static $highStrings =3D array(=0A- '('= =3D> '<blue>(</blue>',=0A- ')' =3D> '<green>)</green>'=0A- );=0A= - =0A- protected static $highTypes =3D array(=0A- T_COMMENT = =3D> '<green>%s</green>'=0A- );=0A+ static protected $colors =3D arra= y("blue", "red", "orange", "darkgreen", "black");=0A =0A+ protected = $cache =3D array();=0A =0A function __construct()=0A {=0A@@ -10= 7,6 +99,14 @@ class PHPGtk2Demo extends GtkWindow=0A $text_view->se= t_buffer($buffer);=0A $text_view->set_editable(false);=0A $= text_view->set_cursor_visible(false);=0A+=0A+=09=09$tag_table =3D $buffer->= get_tag_table();=09=0A+=09=0A+=09=09foreach(self::$colors as $color) {=0A+= =09=09=09$tag =3D new GtkTextTag($color);=0A+=09=09=09$tag->set_property("f= oreground", $color);=0A+=09=09=09$tag_table->add($tag);=0A+=09=09}=0A = =0A // $text_view->set_wrap_mode(false);=0A =0A@@ -131,7 = +131,11 @@ class PHPGtk2Demo extends GtkWindow=0A $info =3D $model-= >get_value($iter, 0);=0A =0A $text =3D $info->classname . "\r\n= \r\n" . $info->description;=0A- $this->description_buffer->set_text(= $text, strlen($text));=0A+=0A+=09// [JSJ]: I get a too many arguements err= or using this form, so changed to the later form=0A+=09// Seems silly we w= ould require the strlen() anyway as PHP should be storing that in the zval = already anyway=0A+ //=09$this->description_buffer->set_text($text, strle= n($text));=0A+ $this->description_buffer->set_text($text);=0A = =0A //source code highlighting=0A $this->highlightSource(= $info->file);=0A@@ -203,28 +207,109 @@ class PHPGtk2Demo extends GtkWindow= =0A protected function highlightSource($filename)=0A {=0A $= tokens =3D token_get_all(file_get_contents($filename));=0A- $highlig= hted =3D '';=0A+=0A+=09=09$highlighted =3D '';=0A+=09=09$color_codes =3D ar= ray();=0A+=09=09=0A+=09=09// this would be much easier if we had functions = which supported varargs (like insert_with_tags_by_name), but improvised sol= ution works in the meantime.=0A+=09=09=0A foreach ($tokens as $toke= n) {=0A+=09 $start =3D strlen($highlighted);=0A if (is_strin= g($token)) {=0A //single string=0A- if (isse= t(self::$highStrings[$token])) {=0A- $highlighted .=3D s= elf::$highStrings[$token];=0A- } else {=0A- = $highlighted .=3D $token;=0A- }=0A+=09=09=09=09if($token = =3D=3D "(" || $token =3D=3D ")" || $token =3D=3D "{" || $token =3D=3D "}" |= | $token =3D=3D ";" || $token =3D=3D "@" || $token =3D=3D "[" || $token =3D= =3D "]" || $token =3D=3D "!") {=0A+=09=09 =09=09$color =3D "darkgreen";= =0A+=09=09=09=09}=0A+=09=09=09=09else {=0A+=09=09 =09=09$color =3D "blac= k";=0A+=09=09=09=09}=0A+ $highlighted .=3D $token;=0A = } else {=0A list($type, $value) =3D $token;=0A- = if (isset(self::$highTypes[$type])) {=0A- $hig= hlighted .=3D sprintf(self::$highTypes[$type], $value);=0A- = } else {=0A- $highlighted .=3D $value;=0A- = }=0A+=09=09=09=09switch($type) {=0A+=09=09 =09=09case T_COMMENT:=0A+= =09=09 =09=09case T_DOC_COMMENT: {=0A+=09=09=09=09=09=09$color =3D "oran= ge";=0A+=09=09=09=09=09=09break;=0A+=09=09 =09=09}=0A+=09=09=09 =09ca= se T_CLASS:=0A+=09=09=09 =09case T_DOUBLE_ARROW:=0A+=09=09=09 =09case= T_NEW:=0A+=09=09=09 =09case T_PAAMAYIM_NEKUDOTAYIM:=0A+=09=09 =09=09= case T_IF:=0A+=09=09=09 =09case T_OBJECT_OPERATOR:=0A+=09=09=09 =09ca= se T_RETURN:=0A+=09=09=09 =09case T_EXTENDS:=0A+=09=09 =09=09case T_C= LASS_C:=0A+=09=09 =09=09case T_FUNC_C:=0A+=09=09 =09=09case T_WHILE:= =0A+=09=09 =09=09=09case T_EXIT:=0A+=09=09 =09=09=09case T_INC:=0A+=09= =09 =09=09=09case T_IS_EQUAL:=0A+=09=09 =09=09=09case T_IS_EQUAL:=0A+= =09=09 =09=09=09case T_IS_IDENTICAL:=0A+=09=09 =09=09=09case T_IS_NOT_E= QUAL:=0A+=09=09 =09=09=09case T_IS_NOT_IDENTICAL:=0A+=09=09 =09=09=09ca= se T_IS_SMALLER_OR_EQUAL:=0A+=09=09 =09=09=09case T_MINUS_EQUAL:=0A+=09= =09 =09=09=09case T_MOD_EQUAL:=0A+=09=09 =09=09=09case T_MUL_EQUAL:=0A+= =09=09 =09=09=09case T_OR_EQUAL:=0A+=09=09 =09=09=09case T_PLUS_EQUAL:= =0A+=09=09 =09=09=09case T_FOREACH:=0A+=09=09 =09=09=09case T_AS:=0A+= =09=09 =09=09case T_ELSE:=0A+=09=09 =09=09case T_ELSEIF:=0A+=09=09 = =09=09case T_ARRAY:=0A+=09=09 =09=09case T_BOOLEAN_AND:=0A+=09=09 = =09=09case T_BOOLEAN_OR:=0A+=09=09 =09=09case T_CONCAT_EQUAL:=0A+=09=09 = =09=09case T_DIV_EQUAL:=0A+=09=09 =09=09case T_CONST:=0A+=09=09 = =09=09case T_STATIC:=0A+=09=09 =09=09case T_AND_EQUAL:=0A+=09=09 =09= =09case T_FUNCTION: {=0A+=09=09=09=09=09=09$color =3D "darkgreen";=0A+=09= =09=09=09=09=09break;=0A+=09=09 =09=09}=0A+=09=09 =09=09case T_LNUMBE= R:=0A+=09=09 =09=09case T_OPEN_TAG:=0A+=09=09 =09=09case T_CLOSE_TAG:= =0A+=09=09 =09=09case T_NUM_STRING:=0A+=09=09 =09=09=09case T_DNUMBER:= =0A+=09=09 =09=09case T_VARIABLE:=0A+=09=09 =09=09case T_PRIVATE:=0A+= =09=09 =09=09case T_PUBLIC:=0A+=09=09 =09=09case T_PROTECTED:=0A+=09= =09 =09=09case T_VAR:=0A+=09=09 =09=09case T_INSTANCEOF:=0A+=09=09 = =09=09case T_STRING: {=0A+=09=09=09=09=09=09$color =3D "blue";=0A+=09=09= =09=09=09=09break;=0A+=09=09 =09=09}=0A+=09=09 =09=09case T_CONSTANT_= ENCAPSED_STRING: {=0A+=09=09=09=09=09=09$color =3D "red";=0A+=09=09=09=09= =09=09break;=0A+=09=09 =09=09}=0A+=09=09 =09=09default: {=0A+=09=09= =09=09=09=09$color =3D "black";=0A+=09=09=09=09=09=09break;=0A+=09=09 = =09=09}=0A+=09=09=09=09}=0A+ $highlighted .=3D $value;=0A+ = }=0A+=09 =09$end =3D strlen($highlighted);=0A+=09 =09$color= _codes[$color][] =3D $start . ":" . $end;=09 =0A+ }=0A+=09=09$thi= s->sourcebuffer->set_text($highlighted);=0A+ foreach($color_codes as= $color_code=3D>$positions) {=0A+=09 =09foreach($positions as $position)= {=0A+ list($start_pos,$end_pos) =3D explode(":", $position)= ;=0A+ $start =3D $this->sourcebuffer->get_iter_at_offset($st= art_pos);=0A+=09=09 =09=09$end =3D $this->sourcebuffer->get_iter_at_offset(= $end_pos);=0A+=09=09 =09=09$this->sourcebuffer->apply_tag_by_name($color_co= de, $start, $end);=0A }=0A }=0A-=0A-// $this->so= urcebuffer->insert_with_tags_by_name();=0A- $this->sourcebuffer->set= _text($highlighted, strlen($highlighted));=0A-// var_dump($highlight= ed);=0A }//protected function highlightSource($filename)=0A }//class PH= PGtk2Demo extends GtkWindow=0A