From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,133f1be3faff2123 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!a26g2000yqn.googlegroups.com!not-for-mail From: Vadim Godunko Newsgroups: comp.lang.ada Subject: Re: gtksourceview for gtkada Date: Tue, 14 Jul 2009 12:29:40 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <893a253b-fbf3-44ab-8b96-3ee6b6fc54fb@r36g2000vbn.googlegroups.com> NNTP-Posting-Host: 93.178.113.157 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1247599780 15339 127.0.0.1 (14 Jul 2009 19:29:40 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 14 Jul 2009 19:29:40 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: a26g2000yqn.googlegroups.com; posting-host=93.178.113.157; posting-account=niG3UgoAAAD7iQ3takWjEn_gw6D9X3ww User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.11) Gecko/2009060200 SUSE/3.0.11-0.1.1 Firefox/3.0.11,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:7052 Date: 2009-07-14T12:29:40-07:00 List-Id: On Jul 14, 10:09=A0pm, jpablo wrote: > Hi, > > I'm trying to make a simple text editor with syntax highlighting for a > specific language, and I'm using gtkada2 for it. The problem is that > gtkada2 doesn't seem to have the gtksourceview widget, that exists for > C, C++, python, etc. > > Does anyone knows if that widget has been added by someone to the > usual widgets of the gtkada2 package? > Alternatively, you can use QtAda and its QPlainTextEditor class. All you will need to do is provide your own subclass from QSyntaxHighlighter: 1 with Qt4.Objects; 2 with Qt4.Strings; 3 with Qt4.Syntax_Highlighters.Impl; 4 with Qt4.Text_Documents; 5 6 package Ada_Syntax_Highlighters is 7 8 type Ada_Syntax_Highlighter is new 9 Qt4.Syntax_Highlighters.Impl.Q_Syntax_Highlighter_Impl with null record; 10 11 overriding 12 procedure Highlight_Block 13 (Self : not null access Ada_Syntax_Highlighter; 14 Text : in Qt4.Strings.Q_String); 15 16 type Ada_Syntax_Highlighter_Access is access Ada_Syntax_Highlighter; 17 18 function Create 19 (Parent : access Qt4.Text_Documents.Q_Text_Document'Class :=3D null) 20 return not null Ada_Syntax_Highlighter_Access; 21 22 end; 1 with Qt4.Colors; 2 with Ada_Syntax_Highlighters.Moc; 3 with Ada.Wide_Text_IO; 4 5 with Asis.Extensions.Syntax_Highlight; 6 7 package body Ada_Syntax_Highlighters is 8 9 --------------------- 10 -- Highlight_Block -- 11 --------------------- 12 13 procedure Highlight_Block 14 (Self : not null access Ada_Syntax_Highlighter; 15 Text : in Qt4.Strings.Q_String) 16 is 17 use type Qt4.Q_Integer; 18 use Asis.Extensions.Syntax_Highlight; 19 20 -- Length : constant Qt4.Q_Integer :=3D Qt4.Strings.Length (Text); 21 22 Colors : constant array (Token_Kinds) of Qt4.Colors.Q_Color :=3D 23 (Comment =3D> Qt4.Colors.Create (0, 128, 128), 24 Identifier =3D> Qt4.Colors.Create (0, 0, 128), 25 Literal =3D> Qt4.Colors.Create (0, 128, 0), 26 Delimiter =3D> Qt4.Colors.Create (128, 128, 0), 27 Keyword =3D> Qt4.Colors.Create (128, 0, 128), 28 Error =3D> Qt4.Colors.Create (255, 0, 0)); 29 30 procedure Set_Token 31 (From : Positive; 32 Count : Positive; 33 Kind : Token_Kinds) is 34 begin 35 Set_Format (Self, 36 Qt4.Q_Integer (From) - 1, -- zero based index 37 Qt4.Q_Integer (Count), 38 Colors (Kind)); 39 end Set_Token; 40 41 procedure Go is new Parse (Set_Token); 42 43 State : Integer :=3D Integer (Previous_Block_State (Self)); 44 begin 45 if State =3D -1 then 46 State :=3D Default_State; 47 end if; 48 49 Go (Qt4.Strings.To_Utf_16 (Text), State); 50 51 Set_Current_Block_State (Self, Qt4.Q_Integer (State)); 52 Ada.Wide_Text_IO.Put_Line (">" & Qt4.Strings.To_Utf_16 (Text)); 53 end Highlight_Block; 54 55 ------------ 56 -- Create -- 57 ------------ 58 59 function Create 60 (Parent : access Qt4.Text_Documents.Q_Text_Document'Class :=3D null) 61 return not null Ada_Syntax_Highlighter_Access 62 is 63 Self : constant not null Ada_Syntax_Highlighter_Access 64 :=3D new Ada_Syntax_Highlighter; 65 66 begin 67 Qt4.Syntax_Highlighters.Impl.Constructors.Initialize (Self, Parent); 68 69 return Self; 70 end Create; 71 72 end Ada_Syntax_Highlighters; And attach it to QPlainTextEditor 23 with Qt_Ada.Application; 24 with Qt4.Core_Applications; 25 with Qt4.Fonts; 26 with Qt4.Objects; 27 with Qt4.Plain_Text_Edits.Constructors; 28 with Qt4.Strings; 29 30 with Ada_Syntax_Highlighters; 31 32 procedure Main is 33 Editor : Qt4.Plain_Text_Edits.Q_Plain_Text_Edit_Access; 34 Highlighter : Ada_Syntax_Highlighters.Ada_Syntax_Highlighter_Access; 35 36 begin 37 Qt_Ada.Application.Initialize; 38 39 Editor :=3D 40 Qt4.Plain_Text_Edits.Constructors.Create 41 (Qt4.Strings.From_Utf_16 ("Quit")); 42 Highlighter :=3D Ada_Syntax_Highlighters.Create (Editor.Document); 43 44 Editor.Resize (800, 600); 45 Editor.Show; 46 47 Qt_Ada.Application.Execute; 48 end Main; That's all... ;-)