comp.lang.ada
 help / color / mirror / Atom feed
* gtksourceview for gtkada
@ 2009-07-14 18:09 jpablo
  2009-07-14 19:29 ` Vadim Godunko
  2009-07-16 17:47 ` Dmitry A. Kazakov
  0 siblings, 2 replies; 8+ messages in thread
From: jpablo @ 2009-07-14 18:09 UTC (permalink / raw)


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?

Thanks



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: gtksourceview for gtkada
  2009-07-14 18:09 gtksourceview for gtkada jpablo
@ 2009-07-14 19:29 ` Vadim Godunko
  2009-07-16 14:47   ` jpablo
  2009-07-16 17:47 ` Dmitry A. Kazakov
  1 sibling, 1 reply; 8+ messages in thread
From: Vadim Godunko @ 2009-07-14 19:29 UTC (permalink / raw)


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... ;-)



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: gtksourceview for gtkada
  2009-07-14 19:29 ` Vadim Godunko
@ 2009-07-16 14:47   ` jpablo
  0 siblings, 0 replies; 8+ messages in thread
From: jpablo @ 2009-07-16 14:47 UTC (permalink / raw)


Oh, thanks for your answer, but it's for a large work and it must be
done in GTK.


On Jul 14, 4:29 pm, Vadim Godunko <vgodu...@gmail.com> wrote:
> 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... ;-)




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: gtksourceview for gtkada
  2009-07-14 18:09 gtksourceview for gtkada jpablo
  2009-07-14 19:29 ` Vadim Godunko
@ 2009-07-16 17:47 ` Dmitry A. Kazakov
  2009-07-17 17:17   ` jpablo
  1 sibling, 1 reply; 8+ messages in thread
From: Dmitry A. Kazakov @ 2009-07-16 17:47 UTC (permalink / raw)


On Tue, 14 Jul 2009 11:09:56 -0700 (PDT), jpablo wrote:

> 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.

What is GtkAda2?

> Does anyone knows if that widget has been added by someone to the
> usual widgets of the gtkada2 package?

GtkAda is maintained by AdaCore. You should ask AdaCore if they plan to
support it in any foreseeable future. If not, then let me know, I would add
bindings to GtkSourceView in the next version of GtkAda contributions.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: gtksourceview for gtkada
  2009-07-16 17:47 ` Dmitry A. Kazakov
@ 2009-07-17 17:17   ` jpablo
  2009-08-05 13:54     ` jpablo
  0 siblings, 1 reply; 8+ messages in thread
From: jpablo @ 2009-07-17 17:17 UTC (permalink / raw)


On Jul 16, 2:47 pm, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> On Tue, 14 Jul 2009 11:09:56 -0700 (PDT), jpablo wrote:
> > 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.
>
> What is GtkAda2?
>
> > Does anyone knows if that widget has been added by someone to the
> > usual widgets of the gtkada2 package?
>
> GtkAda is maintained by AdaCore. You should ask AdaCore if they plan to
> support it in any foreseeable future. If not, then let me know, I would add
> bindings to GtkSourceView in the next version of GtkAda contributions.
>
> --
> Regards,
> Dmitry A. Kazakovhttp://www.dmitry-kazakov.de

Thanks Dmitry! I asked in the gtkada mailing list, I'll let you know
ASAP.

And... by the way, gtkada2 is the name of the gtkada package in
Debian :-P



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: gtksourceview for gtkada
  2009-07-17 17:17   ` jpablo
@ 2009-08-05 13:54     ` jpablo
  2009-08-05 14:33       ` Dmitry A. Kazakov
  0 siblings, 1 reply; 8+ messages in thread
From: jpablo @ 2009-08-05 13:54 UTC (permalink / raw)


On Jul 17, 2:17 pm, jpablo <jpablo.luc...@gmail.com> wrote:
> On Jul 16, 2:47 pm, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:
>
>
>
> > On Tue, 14 Jul 2009 11:09:56 -0700 (PDT), jpablo wrote:
> > > 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 thegtksourceviewwidget, that exists for
> > > C, C++, python, etc.
>
> > What is GtkAda2?
>
> > > Does anyone knows if that widget has been added by someone to the
> > > usual widgets of the gtkada2 package?
>
> > GtkAda is maintained by AdaCore. You should ask AdaCore if they plan to
> > support it in any foreseeable future. If not, then let me know, I would add
> > bindings toGtkSourceViewin the next version of GtkAda contributions.
>
> > --
> > Regards,
> > Dmitry A. Kazakovhttp://www.dmitry-kazakov.de
>
> Thanks Dmitry! I asked in the gtkada mailing list, I'll let you know
> ASAP.
>
> And... by the way, gtkada2 is the name of the gtkada package in
> Debian :-P

Adacore:

"No, we don't have bindings for gtksourceview at the moment. It might
be added to future releases of GtkAda, although we don't have a target
date for this. Maybe someone from the community will provide the
binding and accelerate the process..."



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: gtksourceview for gtkada
  2009-08-05 13:54     ` jpablo
@ 2009-08-05 14:33       ` Dmitry A. Kazakov
  2009-08-07 14:17         ` Dmitry A. Kazakov
  0 siblings, 1 reply; 8+ messages in thread
From: Dmitry A. Kazakov @ 2009-08-05 14:33 UTC (permalink / raw)


On Wed, 5 Aug 2009 06:54:36 -0700 (PDT), jpablo wrote:

> Adacore:
> 
> "No, we don't have bindings for gtksourceview at the moment. It might
> be added to future releases of GtkAda, although we don't have a target
> date for this. Maybe someone from the community will provide the
> binding and accelerate the process..."

OK, I will include a binding to it in the coming release of GtkAda
Contributions. It does not look very complex, just a bit lengthy...

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: gtksourceview for gtkada
  2009-08-05 14:33       ` Dmitry A. Kazakov
@ 2009-08-07 14:17         ` Dmitry A. Kazakov
  0 siblings, 0 replies; 8+ messages in thread
From: Dmitry A. Kazakov @ 2009-08-07 14:17 UTC (permalink / raw)


On Wed, 5 Aug 2009 16:33:22 +0200, Dmitry A. Kazakov wrote:

> On Wed, 5 Aug 2009 06:54:36 -0700 (PDT), jpablo wrote:
> 
>> Adacore:
>> 
>> "No, we don't have bindings for gtksourceview at the moment. It might
>> be added to future releases of GtkAda, although we don't have a target
>> date for this. Maybe someone from the community will provide the
>> binding and accelerate the process..."
> 
> OK, I will include a binding to it in the coming release of GtkAda
> Contributions. It does not look very complex, just a bit lengthy...

See:

http://www.dmitry-kazakov.de/ada/gtkada_contributions.htm

Note that GtkSourceView has to be installed, since it is not a part of the
standard GtkAda distribution. You can find some instructions at the site
above. A test program illustrating some trivial use of GtkSourceView is
provided.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-08-07 14:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-14 18:09 gtksourceview for gtkada jpablo
2009-07-14 19:29 ` Vadim Godunko
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

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