~ubuntu-branches/ubuntu/precise/gnat-gps/precise

« back to all changes in this revision

Viewing changes to completion/core/src/completion-history.ads

  • Committer: Package Import Robot
  • Author(s): Ludovic Brenta
  • Date: 2012-01-15 15:42:21 UTC
  • mfrom: (10.1.10 sid)
  • Revision ID: package-import@ubuntu.com-20120115154221-ccysuzvh02pkhuwq
Tags: 5.0-6
Rebuild against libgtkada 2.24.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
-----------------------------------------------------------------------
 
2
--                               G P S                               --
 
3
--                                                                   --
 
4
--                    Copyright (C) 2007-2010, AdaCore               --
 
5
--                                                                   --
 
6
-- GPS is free  software;  you can redistribute it and/or modify  it --
 
7
-- under the terms of the GNU General Public License as published by --
 
8
-- the Free Software Foundation; either version 2 of the License, or --
 
9
-- (at your option) any later version.                               --
 
10
--                                                                   --
 
11
-- This program is  distributed in the hope that it will be  useful, --
 
12
-- but  WITHOUT ANY WARRANTY;  without even the  implied warranty of --
 
13
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU --
 
14
-- General Public License for more details. You should have received --
 
15
-- a copy of the GNU General Public License along with this program; --
 
16
-- if not,  write to the  Free Software Foundation, Inc.,  59 Temple --
 
17
-- Place - Suite 330, Boston, MA 02111-1307, USA.                    --
 
18
-----------------------------------------------------------------------
 
19
 
 
20
--  This package offers an history capability to the completion engine. This is
 
21
--  an optional capability, enabled by implementing the interface
 
22
--  Storable_Proposal to the Completion_Proposal.
 
23
 
 
24
with Ada.Containers.Indefinite_Doubly_Linked_Lists;
 
25
use Ada.Containers;
 
26
 
 
27
package Completion.History is
 
28
 
 
29
   type Completion_History is new Completion_Resolver with private;
 
30
   --  A completion history has to be populated by user chosen completion.
 
31
   --  Later, the most recent proposals will be displayed in top of the list.
 
32
   --  This resolver has to be the first one referenced in the manager. It's
 
33
   --  implemented as a stack of unique stored proposals.
 
34
 
 
35
   type Completion_History_Access is access all Completion_History'Class;
 
36
 
 
37
   type Storable_Proposal is abstract new Completion_Proposal with null record;
 
38
   --  This is the root type of any completion proposal that's supposed to
 
39
   --  be able to manage history
 
40
   --  ??? This should really be an interface.
 
41
 
 
42
   type Stored_Proposal is abstract tagged null record;
 
43
   --  This is the base type for a proposal stored in the history. Such a
 
44
   --  proposal must have the capability of surviving during the whole
 
45
   --  lifecycle of a tool session, beyond the usual completion resolver and
 
46
   --  manager lifetime. The user is also responsible to check if the
 
47
   --  completion is still possible or not.
 
48
 
 
49
   type Stored_Proposal_Access is access all Stored_Proposal'Class;
 
50
 
 
51
   function To_Stored_Proposal
 
52
     (Proposal : Storable_Proposal) return Stored_Proposal_Access is abstract;
 
53
   --  Extract the stored proposal from a storable proposal.
 
54
 
 
55
   function Equal
 
56
     (Left : Stored_Proposal; Right : Stored_Proposal'Class)
 
57
      return Boolean is abstract;
 
58
   --  Return true if the two proposals are equals - the completion history
 
59
   --  will only store unique proposals.
 
60
 
 
61
   function From_Stored_Proposal
 
62
     (Stored  : Stored_Proposal;
 
63
      Manager : Completion_Manager_Access;
 
64
      Context : Completion_Context)
 
65
      return Completion_Proposal_Access is abstract;
 
66
   --  Recreates a completion proposal out of a stored proposal. If the
 
67
   --  proposal cannot be retreived anymore, the implementer may return a null
 
68
   --  value.
 
69
 
 
70
   function Is_Valid (Stored : Stored_Proposal) return Boolean is abstract;
 
71
   --  The proposals stored in the history may be no longer valid after a
 
72
   --  while - in which case, False should be return by this subprogram, True
 
73
   --  otherwise.
 
74
 
 
75
   procedure Free (Stored : in out Stored_Proposal) is abstract;
 
76
   --  Free the data associated to this stored proposal;
 
77
 
 
78
   overriding
 
79
   procedure Get_Completion_Root
 
80
     (Resolver   : access Completion_History;
 
81
      Offset     : String_Index_Type;
 
82
      Context    : Completion_Context;
 
83
      Result     : in out Completion_List);
 
84
   --  See inherited documentation
 
85
 
 
86
   overriding
 
87
   function Get_Id (Resolver : Completion_History) return String;
 
88
   --  See inherited documentation
 
89
 
 
90
   overriding
 
91
   procedure Free (Resolver : in out Completion_History);
 
92
   --  See inherited documentation
 
93
 
 
94
   procedure Prepend_Proposal
 
95
     (Resolver : access Completion_History;
 
96
      Proposal : Completion_Proposal'Class
 
97
      --  This proposal has to implement the interface Storable_Proposal in
 
98
      --  order to be stored. If not, the proposal won't be stored.
 
99
     );
 
100
   --  This function has to be called each time a completion is applied by
 
101
   --  the user. The proposal will be added in the front of the history list.
 
102
   --  If the proposal given in parameter is already in the list, then it will
 
103
   --  be moved to the front.
 
104
 
 
105
   procedure Set_History_Size
 
106
     (History : access Completion_History; Size : Natural);
 
107
   --  Sets the history maximum size. By default, it has 50 elements.
 
108
 
 
109
private
 
110
 
 
111
   package Proposal_Stack is new
 
112
     Indefinite_Doubly_Linked_Lists (Stored_Proposal_Access);
 
113
 
 
114
   use Proposal_Stack;
 
115
 
 
116
   type Completion_History is new Completion_Resolver with record
 
117
      Stack : Proposal_Stack.List;
 
118
      Size  : Natural := 50;
 
119
   end record;
 
120
 
 
121
end Completion.History;