comp.lang.ada
 help / color / mirror / Atom feed
From: Vadim Godunko <vgodunko@gmail.com>
Subject: Re: gtksourceview for gtkada
Date: Tue, 14 Jul 2009 12:29:40 -0700 (PDT)
Date: 2009-07-14T12:29:40-07:00	[thread overview]
Message-ID: <bfd9d9ff-112c-423e-a91e-6ca699bf71e1@a26g2000yqn.googlegroups.com> (raw)
In-Reply-To: 893a253b-fbf3-44ab-8b96-3ee6b6fc54fb@r36g2000vbn.googlegroups.com

On Jul 14, 10:09 pm, jpablo <jpablo.luc...@gmail.com> 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 :=
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 := Qt4.Strings.Length
(Text);
21
22	      Colors : constant array (Token_Kinds) of
Qt4.Colors.Q_Color :=
23	        (Comment     => Qt4.Colors.Create (0, 128, 128),
24	         Identifier  => Qt4.Colors.Create (0, 0, 128),
25	         Literal     => Qt4.Colors.Create (0, 128, 0),
26	         Delimiter   => Qt4.Colors.Create (128, 128, 0),
27	         Keyword     => Qt4.Colors.Create (128, 0, 128),
28	         Error       => 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 := Integer (Previous_Block_State (Self));
44	   begin
45	      if State = -1 then
46	         State := 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 :=
null)
61	      return not null Ada_Syntax_Highlighter_Access
62	   is
63	      Self : constant not null Ada_Syntax_Highlighter_Access
64	        := 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 :=
40	     Qt4.Plain_Text_Edits.Constructors.Create
41	      (Qt4.Strings.From_Utf_16 ("Quit"));
42	   Highlighter := 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... ;-)



  reply	other threads:[~2009-07-14 19:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-14 18:09 gtksourceview for gtkada jpablo
2009-07-14 19:29 ` Vadim Godunko [this message]
2009-07-16 14:47   ` jpablo
2009-07-16 17:47 ` Dmitry A. Kazakov
2009-07-17 17:17   ` jpablo
2009-08-05 13:54     ` jpablo
2009-08-05 14:33       ` Dmitry A. Kazakov
2009-08-07 14:17         ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox