contexts.txt 3.8 KB
Newer Older
1 2 3 4 5 6
contexts.txt
============

Introduction
------------

7
This file describes how GimpContexts are used in GIMP.
8 9 10 11 12


Overview
--------

Jehan's avatar
Jehan committed
13
One important context is the so called "user context",
14 15 16 17 18 19 20 21 22 23
gimp_get_user_context(). This context keeps track on what image the
user currently has active, for example. Dock windows have their own
context which does not necessarily mirror the user context. A dock
window can be set to show information for a specific image. Plug-ins
also have their own context.


Communication between contexts
------------------------------

24
So how do the various contexts synchronize and propagate changes?
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
This is most easily explained by a sequence diagram. Let's say there
are two image windows with different images opened in GIMP. Call them
A and B. Let's say A is currently active. When the user activates B,
this is the sequence of events from the focus event to the layers
dockable have been updated with the new image. To understand the
diagram, you have to know that the dock window has connected signal
handlers to image changes in the user context (through a dialog
factory getter), and the layer dockable have connected a signal
handler to image changes in the dock window context. The sequence of
events is as follows:

                    GimpContext                  GimpContext   GimpItemTreeView,
 GimpDisplayShell      user      GimpDockWindow  dock window   GimpLayerTreeView

        |                |              |              |             |
 focus event             |              |              |             |
------->|                |              |              |             |
        |  gimp_context_set_display()   |              |             |
        |--------------->|----------+   |              |             |
        |                |          |   |              |             |
        |  gimp_context_set_image() |   |              |             |
        |                |<---------+   |              |             |
        |                |              |              |             |
        |                |    "image-changed"          |             |
        |                |------------->|              |             |
        |                |              |  gimp_context_set_image()  |
        |                |              |------------->|             |
        |                |              |              |      "image-changed" /
        |                |              |              |         set_image()
        |                |              |              |------------>|
        |                |              |              |             |

57
In single-window mode, the dockables listen directly to the user
58
context. When switching between single-window and multi-window modes,
59
the dockables are updated with their new context, just as when moving
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
a dockable between different dock windows and thus also different
contexts. The sequence diagram for single-window mode is:

                    GimpContext  GimpItemTreeView
 GimpDisplayShell      user      GimpLayerTreeView

        |                |              |
 focus event             |              |
------->|                |              |
        |  gimp_context_set_display()   |
        |--------------->|----------+   |
        |                |          |   |
        |  gimp_context_set_image() |   |
        |                |<---------+   |
        |                |              |
        |                |    "image-changed" /
        |                |       set_image()
        |                |------------->|
        |                |              |
        |                |              |
        |                |              |
        |                |              |
        |                |              |
        |                |              |

85 86 87 88 89

Parent/child relationships
--------------------------

TODO