SystemChangeNotifier.st
changeset 12221 5f71ad715ef8
child 12248 b67d795b6669
equal deleted inserted replaced
12220:c26b8b402a71 12221:5f71ad715ef8
       
     1 "{ Package: 'stx:libbasic' }"
       
     2 
       
     3 Object subclass:#SystemChangeNotifier
       
     4 	instanceVariableNames:'silenceLevel'
       
     5 	classVariableNames:'UniqueInstance'
       
     6 	poolDictionaries:''
       
     7 	category:'Kernel-Classes'
       
     8 !
       
     9 
       
    10 !SystemChangeNotifier class methodsFor:'documentation'!
       
    11 
       
    12 documentation
       
    13 "
       
    14     For now, this implementation is mostly for squeak compatibility.
       
    15     However, over time, we will move the change notification code from ClassDescription to here,
       
    16     to make things easier to understand, and classDescription a little bit more lightweight.
       
    17 "
       
    18 ! !
       
    19 
       
    20 !SystemChangeNotifier class methodsFor:'instance creaton'!
       
    21 
       
    22 uniqueInstance
       
    23     "I am a singleton"
       
    24 
       
    25     UniqueInstance isNil ifTrue: [UniqueInstance := self basicNew initialize].
       
    26     ^ UniqueInstance
       
    27 
       
    28     "
       
    29      UniqueInstance releaseAll.
       
    30      UniqueInstance := nil
       
    31     "
       
    32 ! !
       
    33 
       
    34 !SystemChangeNotifier methodsFor:'initialization'!
       
    35 
       
    36 initialize
       
    37     "/ eventSource := SystemEventManager new.
       
    38     silenceLevel := 0.
       
    39 ! !
       
    40 
       
    41 !SystemChangeNotifier methodsFor:'public'!
       
    42 
       
    43 doSilently: aBlock
       
    44     "Perform the block, and ensure that no system notification are broadcasted while doing so."
       
    45 
       
    46     |result|
       
    47 
       
    48     silenceLevel := silenceLevel + 1.
       
    49     [
       
    50         "/ temporary hack:
       
    51         Class withoutUpdatingChangesDo:[
       
    52             result := aBlock value
       
    53         ]
       
    54     ] ensure: [
       
    55         silenceLevel > 0 ifTrue: [
       
    56             silenceLevel := silenceLevel - 1
       
    57         ]
       
    58     ].
       
    59     ^ result.
       
    60 !
       
    61 
       
    62 isBroadcasting
       
    63     ^ silenceLevel = 0
       
    64 ! !
       
    65 
       
    66 !SystemChangeNotifier class methodsFor:'documentation'!
       
    67 
       
    68 version_CVS
       
    69     ^ '$Header: /cvs/stx/stx/libbasic/SystemChangeNotifier.st,v 1.1 2009-10-12 19:11:38 cg Exp $'
       
    70 ! !