misc/vim: inform the user when no results are found
[nit.git] / lib / progression.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # This file is free software, which comes along with NIT. This software is
4 # distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
5 # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
6 # PARTICULAR PURPOSE. You can modify it is you want, provided this header
7 # is kept unaltered, and a notification of the changes is added.
8 # You are allowed to redistribute it and sell it, alone or is a part of
9 # another product.
10
11 # Event-based interface to track the progression of an operation.
12 module progression
13
14 # An operation that is trackable using a `ProgressionListener`.
15 abstract class Trackable
16
17 # Listen to the progression of the operation.
18 var progression_listeners: SimpleCollection[ProgressionListener] =
19 new Array[ProgressionListener]
20
21 # Notice the registered `ProgessionListener` that the operation started.
22 protected fun fire_started do
23 for l in progression_listeners do
24 l.started
25 l.progressed(0)
26 end
27 end
28
29 # Notice the registered `ProgessionListener` that the operation progressed.
30 #
31 # Parameter:
32 #
33 # * `done_part`: Indicates what is done.
34 # * `total`: Indicates what need to be done, `done_part` included.
35 protected fun fire_progressed(done_part: Int, total: Int) do
36 for l in progression_listeners do
37 l.progressed(done_part * l.progression_max / total)
38 end
39 end
40
41 # Notice the registered `ProgessionListener` that the operation is done.
42 protected fun fire_done do
43 for l in progression_listeners do
44 l.progressed(l.progression_max)
45 l.done
46 end
47 end
48 end
49
50 # Listens to the progression of a possibly long-running operation.
51 interface ProgressionListener
52 # The number that represents a completed operation.
53 fun progression_max: Int do return 100
54
55 # The operation started.
56 fun started do end
57
58 # The operation progressed.
59 #
60 # Parameter:
61 #
62 # * `progression`: Indicator of the progession, between `0` and
63 # `progression_max`.
64 fun progressed(progression: Int) do end
65
66 # The operation is done.
67 fun done do end
68 end