@@ -20,19 +20,16 @@ const NoteBox = Me.imports.noteBox;
20
20
const Gettext = imports . gettext . domain ( 'notes-extension' ) ;
21
21
const _ = Gettext . gettext ;
22
22
23
- // ~/.local/share/notes@maestroschan .fr
23
+ //------------------------------------------------------------------------------
24
+
24
25
const PATH = GLib . build_pathv ( '/' , [ GLib . get_user_data_dir ( ) , 'notes@maestroschan.fr' ] ) ;
26
+ // which is usually ~/.local/share/notes@maestroschan .fr
25
27
26
28
var NOTES_MANAGER ;
27
- let GLOBAL_ARE_VISIBLE ;
28
29
let SETTINGS ;
29
30
var Z_POSITION ;
30
31
var AUTO_FOCUS ;
31
32
32
- //------------------------------------------------------------------------------
33
-
34
- var ALL_NOTES ;
35
-
36
33
function init ( ) {
37
34
Convenience . initTranslations ( ) ;
38
35
try {
@@ -48,8 +45,7 @@ function init() {
48
45
49
46
function enable ( ) {
50
47
SETTINGS = Convenience . getSettings ( ) ;
51
- AUTO_FOCUS = SETTINGS . get_boolean ( 'auto-focus' ) ;
52
- ALL_NOTES = new Array ( ) ; // TODO en attribut du manager
48
+ AUTO_FOCUS = SETTINGS . get_boolean ( 'auto-focus' ) ; // XXX crado
53
49
54
50
NOTES_MANAGER = new NotesManager ( ) ;
55
51
}
@@ -94,8 +90,9 @@ class NotesManager {
94
90
Main . panel . addToStatusArea ( 'NotesButton' , this . panel_button , 0 , 'right' ) ;
95
91
96
92
// Initialisation of the notes themselves
97
- GLOBAL_ARE_VISIBLE = false ; // XXX dégueu + cassé quand on update le layout
98
- this . _updateLayoutSetting ( ) ; // ALL_NOTES is empty but it inits Z_POSITION
93
+ this . _allNotes = new Array ( ) ;
94
+ this . _notesAreVisible = false ;
95
+ this . _updateLayoutSetting ( ) ; // it inits Z_POSITION
99
96
this . _loadAllNotes ( ) ;
100
97
101
98
// Initialisation of the signals connections
@@ -120,7 +117,7 @@ class NotesManager {
120
117
let i = 0 ;
121
118
let ended = false ;
122
119
while ( ! ended ) {
123
- let file2 = GLib . build_filenamev ( [ PATH , '/' + i . toString ( ) + '_state' ] ) ;
120
+ let file2 = GLib . build_filenamev ( [ PATH , i . toString ( ) + '_state' ] ) ;
124
121
if ( GLib . file_test ( file2 , GLib . FileTest . EXISTS ) ) {
125
122
this . createNote ( '' , 16 ) ;
126
123
} else {
@@ -134,10 +131,10 @@ class NotesManager {
134
131
//--------------------------------------------------------------------------
135
132
// "Public" methods, accessed by the NoteBox objects -----------------------
136
133
137
- createNote ( colorAsString , fontSize ) {
138
- let nextId = ALL_NOTES . length ;
134
+ createNote ( colorString , fontSize ) {
135
+ let nextId = this . _allNotes . length ;
139
136
try {
140
- ALL_NOTES . push ( new NoteBox . NoteBox ( nextId , colorAsString , fontSize ) ) ;
137
+ this . _allNotes . push ( new NoteBox . NoteBox ( nextId , colorString , fontSize ) ) ;
141
138
} catch ( e ) {
142
139
Main . notify ( _ ( "Notes extension error: failed to load a note" ) ) ;
143
140
log ( 'failed to create note n°' + nextId . toString ( ) ) ;
@@ -147,16 +144,17 @@ class NotesManager {
147
144
148
145
/*
149
146
* When a NoteBox object deletes itself, it calls this method to ensure the
150
- * files go from 0 to (ALL_NOTES .length - 1) without any "gap" in the
147
+ * files go from 0 to (this._allNotes .length - 1) without any "gap" in the
151
148
* numerotation.
152
149
*/
153
150
postDelete ( deletedNoteId ) {
154
- let lastNote = ALL_NOTES . pop ( ) ;
155
- if ( deletedNoteId < ALL_NOTES . length ) {
156
- ALL_NOTES [ deletedNoteId ] = lastNote ;
151
+ let lastNote = this . _allNotes . pop ( ) ;
152
+ if ( deletedNoteId < this . _allNotes . length ) {
153
+ this . _allNotes [ deletedNoteId ] = lastNote ;
157
154
lastNote . id = deletedNoteId ;
155
+ this . _allNotes [ deletedNoteId ] . onlySave ( ) ;
158
156
}
159
- this . _deleteNoteFiles ( ALL_NOTES . length ) ;
157
+ this . _deleteNoteFiles ( this . _allNotes . length ) ;
160
158
}
161
159
162
160
/*
@@ -167,7 +165,7 @@ class NotesManager {
167
165
*/
168
166
areCoordsUsable ( x , y ) {
169
167
let areaIsFree = true ;
170
- ALL_NOTES . forEach ( function ( n ) {
168
+ this . _allNotes . forEach ( function ( n ) {
171
169
if ( ( Math . abs ( n . _x - x ) < 230 ) && ( Math . abs ( n . _y - y ) < 100 ) ) {
172
170
areaIsFree = false ;
173
171
}
@@ -179,35 +177,35 @@ class NotesManager {
179
177
180
178
_toggleState ( ) {
181
179
// log('_toggleState');
182
- if ( ALL_NOTES . length == 0 ) {
180
+ if ( this . _allNotes . length == 0 ) {
183
181
this . createNote ( '' , 16 ) ;
184
182
this . _showNotes ( ) ;
185
- } else if ( GLOBAL_ARE_VISIBLE ) {
183
+ } else if ( this . _notesAreVisible ) {
186
184
this . _hideNotes ( ) ;
187
185
} else {
188
186
this . _showNotes ( ) ;
189
187
}
190
188
}
191
189
192
190
_showNotes ( ) {
193
- GLOBAL_ARE_VISIBLE = true ;
194
- ALL_NOTES . forEach ( function ( n ) {
191
+ this . _notesAreVisible = true ;
192
+ this . _allNotes . forEach ( function ( n ) {
195
193
n . show ( ) ;
196
194
} ) ;
197
195
}
198
196
199
197
_hideNotes ( ) {
200
198
this . _onlyHideNotes ( ) ;
201
- ALL_NOTES . forEach ( function ( n ) {
199
+ this . _allNotes . forEach ( function ( n ) {
202
200
n . onlySave ( ) ;
203
201
} ) ;
204
202
}
205
203
206
204
_onlyHideNotes ( ) {
207
- ALL_NOTES . forEach ( function ( n ) {
205
+ this . _allNotes . forEach ( function ( n ) {
208
206
n . onlyHide ( ) ;
209
207
} ) ;
210
- GLOBAL_ARE_VISIBLE = false ;
208
+ this . _notesAreVisible = false ;
211
209
}
212
210
213
211
_deleteNoteFiles ( id ) {
@@ -222,29 +220,29 @@ class NotesManager {
222
220
// Watch the gsettings values and update the extension if they change ------
223
221
224
222
_connectAllSignals ( ) {
225
- this . _SIGNALS = { } ;
223
+ this . _settingsSignals = { } ;
226
224
227
- this . _SIGNALS [ 'layout' ] = SETTINGS . connect (
225
+ this . _settingsSignals [ 'layout' ] = SETTINGS . connect (
228
226
'changed::layout-position' ,
229
227
this . _updateLayoutSetting . bind ( this )
230
228
) ;
231
- this . _SIGNALS [ 'bring-back' ] = SETTINGS . connect (
229
+ this . _settingsSignals [ 'bring-back' ] = SETTINGS . connect (
232
230
'changed::ugly-hack' ,
233
231
this . _bringToPrimaryMonitorOnly . bind ( this )
234
232
) ;
235
- this . _SIGNALS [ 'hide-icon' ] = SETTINGS . connect (
233
+ this . _settingsSignals [ 'hide-icon' ] = SETTINGS . connect (
236
234
'changed::hide-icon' ,
237
235
this . _updateIconVisibility . bind ( this )
238
236
) ;
239
- this . _SIGNALS [ 'kb-shortcut-1' ] = SETTINGS . connect (
237
+ this . _settingsSignals [ 'kb-shortcut-1' ] = SETTINGS . connect (
240
238
'changed::use-shortcut' ,
241
239
this . _updateShortcut . bind ( this )
242
240
) ;
243
- this . _SIGNALS [ 'kb-shortcut-2' ] = SETTINGS . connect (
241
+ this . _settingsSignals [ 'kb-shortcut-2' ] = SETTINGS . connect (
244
242
'changed::notes-kb-shortcut' ,
245
243
this . _updateShortcut . bind ( this )
246
244
) ;
247
- this . _SIGNALS [ 'auto-focus' ] = SETTINGS . connect (
245
+ this . _settingsSignals [ 'auto-focus' ] = SETTINGS . connect (
248
246
'changed::auto-focus' ,
249
247
this . _updateFocusSetting . bind ( this )
250
248
) ;
@@ -275,33 +273,43 @@ class NotesManager {
275
273
}
276
274
277
275
_bringToPrimaryMonitorOnly ( ) {
278
- ALL_NOTES . forEach ( function ( n ) {
276
+ this . _allNotes . forEach ( function ( n ) {
279
277
n . fixState ( ) ;
280
278
} ) ;
281
279
}
282
280
281
+ /*
282
+ * Remove all the notes from where they are, and add them to the layer that
283
+ * is actually set by the user. Possible values for the layers can be
284
+ * 'above-all', 'on-background' or 'cycle-layers'.
285
+ */
283
286
_updateLayoutSetting ( ) {
284
- ALL_NOTES . forEach ( function ( n ) {
287
+ this . _allNotes . forEach ( function ( n ) {
285
288
n . removeFromCorrectLayer ( ) ;
286
289
} ) ;
287
290
288
291
Z_POSITION = SETTINGS . get_string ( 'layout-position' ) ;
289
292
290
- ALL_NOTES . forEach ( function ( n ) {
293
+ this . _allNotes . forEach ( function ( n ) {
291
294
n . loadIntoCorrectLayer ( ) ;
292
295
} ) ;
296
+
297
+ if ( ! this . _notesAreVisible ) {
298
+ this . _onlyHideNotes ( ) ;
299
+ }
293
300
}
294
301
295
302
//--------------------------------------------------------------------------
296
303
297
304
destroy ( ) {
298
- SETTINGS . disconnect ( this . _SIGNALS [ 'layout' ] ) ;
299
- SETTINGS . disconnect ( this . _SIGNALS [ 'bring-back' ] ) ;
300
- SETTINGS . disconnect ( this . _SIGNALS [ 'hide-icon' ] ) ;
301
- SETTINGS . disconnect ( this . _SIGNALS [ 'kb-shortcut-1' ] ) ;
302
- SETTINGS . disconnect ( this . _SIGNALS [ 'kb-shortcut-2' ] ) ;
303
-
304
- ALL_NOTES . forEach ( function ( n ) {
305
+ SETTINGS . disconnect ( this . _settingsSignals [ 'layout' ] ) ;
306
+ SETTINGS . disconnect ( this . _settingsSignals [ 'bring-back' ] ) ;
307
+ SETTINGS . disconnect ( this . _settingsSignals [ 'hide-icon' ] ) ;
308
+ SETTINGS . disconnect ( this . _settingsSignals [ 'kb-shortcut-1' ] ) ;
309
+ SETTINGS . disconnect ( this . _settingsSignals [ 'kb-shortcut-2' ] ) ;
310
+ SETTINGS . disconnect ( this . _settingsSignals [ 'auto-focus' ] ) ;
311
+
312
+ this . _allNotes . forEach ( function ( n ) {
305
313
n . onlySave ( ) ;
306
314
n . destroy ( ) ;
307
315
} ) ;
0 commit comments