svn merge -r 21041:21301 https://svn.blender.org/svnroot/bf-blender/branches/blender2...
[blender.git] / source / blender / editors / space_file / file_ops.c
1 /**
2  * $Id:
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (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
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2008 Blender Foundation.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Andrea Weikert (c) 2008 Blender Foundation
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include "BKE_context.h"
30 #include "BKE_screen.h"
31 #include "BKE_global.h"
32
33 #include "BLI_blenlib.h"
34 #include "BLI_storage_types.h"
35 #ifdef WIN32
36 #include "BLI_winstuff.h"
37 #endif
38 #include "DNA_space_types.h"
39 #include "DNA_userdef_types.h"
40
41 #include "ED_space_api.h"
42 #include "ED_screen.h"
43 #include "ED_fileselect.h"
44
45 #include "MEM_guardedalloc.h"
46
47 #include "RNA_access.h"
48 #include "RNA_define.h"
49
50 #include "UI_interface.h"
51 #include "UI_view2d.h"
52
53 #include "WM_api.h"
54 #include "WM_types.h"
55
56 #include "file_intern.h"
57 #include "filelist.h"
58 #include "fsmenu.h"
59
60 #include <stdlib.h>
61 #include <string.h>
62 #include <stdio.h>
63
64 /* for events */
65 #define NOTACTIVE                       0
66 #define ACTIVATE                        1
67 #define INACTIVATE                      2
68
69 /* ---------- FILE SELECTION ------------ */
70
71 static int find_file_mouse(SpaceFile *sfile, struct ARegion* ar, short x, short y, short clamp)
72 {
73         float fx,fy;
74         int active_file = -1;
75         int numfiles = filelist_numfiles(sfile->files);
76         View2D* v2d = &ar->v2d;
77
78         UI_view2d_region_to_view(v2d, x, y, &fx, &fy);
79
80         active_file = ED_fileselect_layout_offset(sfile->layout, v2d->tot.xmin + fx, v2d->tot.ymax - fy);
81
82         if(active_file < 0) {
83                 if(clamp)       active_file=  0;
84                 else            active_file= -1;
85         }
86         else if(active_file >= numfiles) {
87                 if(clamp)       active_file=  numfiles-1;
88                 else            active_file= -1;
89         }
90         
91         return active_file;
92 }
93
94
95 static void file_deselect_all(SpaceFile* sfile)
96 {
97         int numfiles = filelist_numfiles(sfile->files);
98         int i;
99
100         for ( i=0; i < numfiles; ++i) {
101                 struct direntry* file = filelist_file(sfile->files, i);
102                 if (file && (file->flags & ACTIVE)) {
103                         file->flags &= ~ACTIVE;
104                 }
105         }
106 }
107
108 static void file_select(SpaceFile* sfile, ARegion* ar, const rcti* rect, short val)
109 {
110         int first_file = -1;
111         int last_file = -1;
112         int act_file;
113         short selecting = (val == LEFTMOUSE);
114         FileSelectParams *params = ED_fileselect_get_params(sfile);
115         // FileLayout *layout = ED_fileselect_get_layout(sfile, ar);
116
117         int numfiles = filelist_numfiles(sfile->files);
118
119         params->selstate = NOTACTIVE;
120         first_file = find_file_mouse(sfile, ar, rect->xmin, rect->ymax, 1);
121         last_file = find_file_mouse(sfile, ar, rect->xmax, rect->ymin, 1);
122         
123         /* select all valid files between first and last indicated */
124         if ( (first_file >= 0) && (first_file < numfiles) && (last_file >= 0) && (last_file < numfiles) ) {
125                 for (act_file = first_file; act_file <= last_file; act_file++) {
126                         struct direntry* file = filelist_file(sfile->files, act_file);
127                         if (selecting) 
128                                 file->flags |= ACTIVE;
129                         else
130                                 file->flags &= ~ACTIVE;
131                 }
132         }
133
134         /* make the last file active */
135         if (selecting && (last_file >= 0 && last_file < numfiles)) {
136                 struct direntry* file = filelist_file(sfile->files, last_file);
137                 params->active_file = last_file;
138
139                 if(file && S_ISDIR(file->type)) {
140                         /* the path is too long! */
141                         if (strlen(params->dir) + strlen(file->relname) >= FILE_MAX ) 
142                         {
143                                 // XXX error("Path too long, cannot enter this directory");
144                         } else {
145                                 strcat(params->dir, file->relname);
146                                 strcat(params->dir,"/");
147                                 params->file[0] = '\0';
148                                 BLI_cleanup_dir(G.sce, params->dir);
149                                 filelist_setdir(sfile->files, params->dir);
150                                 filelist_free(sfile->files);
151                                 params->active_file = -1;
152                         }
153                 }
154                 else if (file)
155                 {
156                         if (file->relname) {
157                                 BLI_strncpy(params->file, file->relname, FILE_MAXFILE);
158                                 /* XXX
159                                 if(event==MIDDLEMOUSE && filelist_gettype(sfile->files)) 
160                                         imasel_execute(sfile);
161                                 */
162                         }
163                         
164                 }       
165                 /* XXX
166                 if(BIF_filelist_gettype(sfile->files)==FILE_MAIN) {
167                         active_imasel_object(sfile);
168                 }
169                 */
170         }
171 }
172
173
174
175 static int file_border_select_exec(bContext *C, wmOperator *op)
176 {
177         ARegion *ar= CTX_wm_region(C);
178         SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
179         short val;
180         rcti rect;
181
182         val= RNA_int_get(op->ptr, "event_type");
183         rect.xmin= RNA_int_get(op->ptr, "xmin");
184         rect.ymin= RNA_int_get(op->ptr, "ymin");
185         rect.xmax= RNA_int_get(op->ptr, "xmax");
186         rect.ymax= RNA_int_get(op->ptr, "ymax");
187
188         BLI_isect_rcti(&(ar->v2d.mask), &rect, &rect);
189         
190         file_select(sfile, ar, &rect, val );
191         WM_event_add_notifier(C, NC_WINDOW, NULL);
192         return OPERATOR_FINISHED;
193 }
194
195 void FILE_OT_select_border(wmOperatorType *ot)
196 {
197         /* identifiers */
198         ot->name= "Activate/Select File";
199         ot->idname= "FILE_OT_select_border";
200         
201         /* api callbacks */
202         ot->invoke= WM_border_select_invoke;
203         ot->exec= file_border_select_exec;
204         ot->modal= WM_border_select_modal;
205
206         /* rna */
207         RNA_def_int(ot->srna, "event_type", 0, INT_MIN, INT_MAX, "Event Type", "", INT_MIN, INT_MAX);
208         RNA_def_int(ot->srna, "xmin", 0, INT_MIN, INT_MAX, "X Min", "", INT_MIN, INT_MAX);
209         RNA_def_int(ot->srna, "xmax", 0, INT_MIN, INT_MAX, "X Max", "", INT_MIN, INT_MAX);
210         RNA_def_int(ot->srna, "ymin", 0, INT_MIN, INT_MAX, "Y Min", "", INT_MIN, INT_MAX);
211         RNA_def_int(ot->srna, "ymax", 0, INT_MIN, INT_MAX, "Y Max", "", INT_MIN, INT_MAX);
212
213         ot->poll= ED_operator_file_active;
214 }
215
216 static int file_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
217 {
218         ARegion *ar= CTX_wm_region(C);
219         SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
220         short val;
221         rcti rect;
222
223         rect.xmin = rect.xmax = event->x - ar->winrct.xmin;
224         rect.ymin = rect.ymax = event->y - ar->winrct.ymin;
225         val = event->val;
226
227         if (BLI_in_rcti(&ar->v2d.mask, rect.xmin, rect.ymin)) { 
228
229                 /* single select, deselect all selected first */
230                 file_deselect_all(sfile);
231                 file_select(sfile, ar, &rect, val );
232                 WM_event_add_notifier(C, NC_FILE|ND_PARAMS, NULL);
233         }
234         return OPERATOR_FINISHED;
235 }
236
237 void FILE_OT_select(wmOperatorType *ot)
238 {
239         /* identifiers */
240         ot->name= "Activate/Select File";
241         ot->idname= "FILE_OT_select";
242         
243         /* api callbacks */
244         ot->invoke= file_select_invoke;
245
246         /* rna */
247
248         ot->poll= ED_operator_file_active;
249 }
250
251 static int file_select_all_invoke(bContext *C, wmOperator *op, wmEvent *event)
252 {
253         ScrArea *sa= CTX_wm_area(C);
254         SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
255         int numfiles = filelist_numfiles(sfile->files);
256         int i;
257         int select = 1;
258
259         /* if any file is selected, deselect all first */
260         for ( i=0; i < numfiles; ++i) {
261                 struct direntry* file = filelist_file(sfile->files, i);
262                 if (file && (file->flags & ACTIVE)) {
263                         file->flags &= ~ACTIVE;
264                         select = 0;
265                         ED_area_tag_redraw(sa);
266                 }
267         }
268         /* select all only if previously no file was selected */
269         if (select) {
270                 for ( i=0; i < numfiles; ++i) {
271                         struct direntry* file = filelist_file(sfile->files, i);
272                         if(file && !S_ISDIR(file->type)) {
273                                 file->flags |= ACTIVE;
274                                 ED_area_tag_redraw(sa);
275                         }
276                 }
277         }
278         return OPERATOR_FINISHED;
279 }
280
281 void FILE_OT_select_all_toggle(wmOperatorType *ot)
282 {
283         /* identifiers */
284         ot->name= "Select/Deselect all files";
285         ot->idname= "FILE_OT_select_all_toggle";
286         
287         /* api callbacks */
288         ot->invoke= file_select_all_invoke;
289
290         /* rna */
291
292         ot->poll= ED_operator_file_active;
293 }
294
295 /* ---------- BOOKMARKS ----------- */
296
297 static int bookmark_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
298 {
299         SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
300
301         if(RNA_struct_find_property(op->ptr, "dir")) {
302                 char entry[256];
303                 FileSelectParams* params = sfile->params;
304
305                 RNA_string_get(op->ptr, "dir", entry);
306                 BLI_strncpy(params->dir, entry, sizeof(params->dir));
307                 BLI_cleanup_dir(G.sce, params->dir);
308                 filelist_free(sfile->files);    
309                 filelist_setdir(sfile->files, params->dir);
310                 params->file[0] = '\0';                 
311                 params->active_file = -1;
312
313                 WM_event_add_notifier(C, NC_FILE|ND_PARAMS, NULL);
314         }
315         
316         return OPERATOR_FINISHED;
317 }
318
319 void FILE_OT_select_bookmark(wmOperatorType *ot)
320 {
321         /* identifiers */
322         ot->name= "Select Directory";
323         ot->idname= "FILE_OT_select_bookmark";
324         
325         /* api callbacks */
326         ot->invoke= bookmark_select_invoke;
327         ot->poll= ED_operator_file_active;
328
329         RNA_def_string(ot->srna, "dir", "", 256, "Dir", "");
330 }
331
332 static int bookmark_add_invoke(bContext *C, wmOperator *op, wmEvent *event)
333 {
334         ScrArea *sa= CTX_wm_area(C);
335         SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
336         struct FSMenu* fsmenu = fsmenu_get();
337         struct FileSelectParams* params= ED_fileselect_get_params(sfile);
338
339         if (params->dir[0] != '\0') {
340                 char name[FILE_MAX];
341         
342                 fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, params->dir, 0, 1);
343                 BLI_make_file_string("/", name, BLI_gethome(), ".Bfs");
344                 fsmenu_write_file(fsmenu, name);
345         }
346
347         ED_area_tag_redraw(sa);
348         return OPERATOR_FINISHED;
349 }
350
351 void FILE_OT_add_bookmark(wmOperatorType *ot)
352 {
353         /* identifiers */
354         ot->name= "Add Bookmark";
355         ot->idname= "FILE_OT_add_bookmark";
356         
357         /* api callbacks */
358         ot->invoke= bookmark_add_invoke;
359         ot->poll= ED_operator_file_active;
360 }
361
362 static int bookmark_delete_invoke(bContext *C, wmOperator *op, wmEvent *event)
363 {
364         ScrArea *sa= CTX_wm_area(C);
365         SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
366         struct FSMenu* fsmenu = fsmenu_get();
367         int nentries = fsmenu_get_nentries(fsmenu, FS_CATEGORY_BOOKMARKS);
368         if(RNA_struct_find_property(op->ptr, "index")) {
369                 int index = RNA_int_get(op->ptr, "index");
370                 if ( (index >-1) && (index < nentries)) {
371                         char name[FILE_MAX];
372                         
373                         fsmenu_remove_entry(fsmenu, FS_CATEGORY_BOOKMARKS, index);
374                         BLI_make_file_string("/", name, BLI_gethome(), ".Bfs");
375                         fsmenu_write_file(fsmenu, name);
376                         ED_area_tag_redraw(sa);
377                 }
378         }
379
380         return OPERATOR_FINISHED;
381 }
382
383 void FILE_OT_delete_bookmark(wmOperatorType *ot)
384 {
385         /* identifiers */
386         ot->name= "Delete Bookmark";
387         ot->idname= "FILE_OT_delete_bookmark";
388         
389         /* api callbacks */
390         ot->invoke= bookmark_delete_invoke;
391         ot->poll= ED_operator_file_active;
392
393         RNA_def_int(ot->srna, "index", -1, -1, 20000, "Index", "", -1, 20000);
394 }
395
396
397 static int loadimages_invoke(bContext *C, wmOperator *op, wmEvent *event)
398 {
399         ScrArea *sa= CTX_wm_area(C);
400         SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
401         if (sfile->files) {
402                 filelist_loadimage_timer(sfile->files);
403                 if (filelist_changed(sfile->files)) {
404                         ED_area_tag_redraw(sa);
405                 }
406         }
407
408         return OPERATOR_FINISHED;
409 }
410
411 void FILE_OT_loadimages(wmOperatorType *ot)
412 {
413         
414         /* identifiers */
415         ot->name= "Load Images";
416         ot->idname= "FILE_OT_loadimages";
417         
418         /* api callbacks */
419         ot->invoke= loadimages_invoke;
420         
421         ot->poll= ED_operator_file_active;
422 }
423
424 int file_hilight_set(SpaceFile *sfile, ARegion *ar, int mx, int my)
425 {
426         FileSelectParams* params;
427         int numfiles, actfile;
428         
429         if(sfile==NULL || sfile->files==NULL) return 0;
430         
431         numfiles = filelist_numfiles(sfile->files);
432         params = ED_fileselect_get_params(sfile);
433
434         actfile = find_file_mouse(sfile, ar, mx , my, 0);
435         
436         if (params && (actfile >= 0) && (actfile < numfiles) ) {
437                 params->active_file=actfile;
438                 return 1;
439         } 
440         params->active_file= -1;
441         return 0;
442 }
443
444 static int file_highlight_invoke(bContext *C, wmOperator *op, wmEvent *event)
445 {
446         ARegion *ar= CTX_wm_region(C);
447         SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
448         
449         if( file_hilight_set(sfile, ar, event->x - ar->winrct.xmin, event->y - ar->winrct.ymin)) {
450                 ED_area_tag_redraw(CTX_wm_area(C));
451         }
452         
453         return OPERATOR_FINISHED;
454 }
455
456 void FILE_OT_highlight(struct wmOperatorType *ot)
457 {
458         /* identifiers */
459         ot->name= "Highlight File";
460         ot->idname= "FILE_OT_highlight";
461         
462         /* api callbacks */
463         ot->invoke= file_highlight_invoke;
464         ot->poll= ED_operator_file_active;
465 }
466
467 int file_cancel_exec(bContext *C, wmOperator *unused)
468 {
469         SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
470         
471         WM_event_fileselect_event(C, sfile->op, EVT_FILESELECT_CANCEL);
472         sfile->op = NULL;
473         
474         return OPERATOR_FINISHED;
475 }
476
477 void FILE_OT_cancel(struct wmOperatorType *ot)
478 {
479         /* identifiers */
480         ot->name= "Cancel File Load";
481         ot->idname= "FILE_OT_cancel";
482         
483         /* api callbacks */
484         ot->exec= file_cancel_exec;
485         ot->poll= ED_operator_file_active;
486 }
487
488 /* sends events now, so things get handled on windowqueue level */
489 int file_exec(bContext *C, wmOperator *unused)
490 {
491         SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
492         char name[FILE_MAX];
493         
494         if(sfile->op) {
495                 wmOperator *op= sfile->op;
496                 
497                 sfile->op = NULL;
498                 BLI_strncpy(name, sfile->params->dir, sizeof(name));
499                 strcat(name, sfile->params->file);
500                 RNA_string_set(op->ptr, "filename", name);
501                 
502                 /* some ops have multiple files to select */
503                 {
504                         PointerRNA itemptr;
505                         int i, numfiles = filelist_numfiles(sfile->files);
506                         struct direntry *file;
507                         if(RNA_struct_find_property(op->ptr, "files")) {
508                                 for (i=0; i<numfiles; i++) {
509                                         file = filelist_file(sfile->files, i);
510                                         if(file->flags & ACTIVE) {
511                                                 if ((file->type & S_IFDIR)==0) {
512                                                         RNA_collection_add(op->ptr, "files", &itemptr);
513                                                         RNA_string_set(&itemptr, "name", file->relname);
514                                                 }
515                                         }
516                                 }
517                         }
518                         
519                         if(RNA_struct_find_property(op->ptr, "dirs")) {
520                                 for (i=0; i<numfiles; i++) {
521                                         file = filelist_file(sfile->files, i);
522                                         if(file->flags & ACTIVE) {
523                                                 if ((file->type & S_IFDIR)) {
524                                                         RNA_collection_add(op->ptr, "dirs", &itemptr);
525                                                         RNA_string_set(&itemptr, "name", file->relname);
526                                                 }
527                                         }
528                                 }
529                         }
530                 }
531                 
532                 fsmenu_insert_entry(fsmenu_get(), FS_CATEGORY_RECENT, sfile->params->dir,0, 1);
533                 BLI_make_file_string(G.sce, name, BLI_gethome(), ".Bfs");
534                 fsmenu_write_file(fsmenu_get(), name);
535                 WM_event_fileselect_event(C, op, EVT_FILESELECT_EXEC);
536         }
537                                 
538         return OPERATOR_FINISHED;
539 }
540
541 void FILE_OT_exec(struct wmOperatorType *ot)
542 {
543         /* identifiers */
544         ot->name= "Execute File Window";
545         ot->idname= "FILE_OT_exec";
546         
547         /* api callbacks */
548         ot->exec= file_exec;
549         ot->poll= ED_operator_file_active; /* <- important, handler is on window level */
550 }
551
552
553 int file_parent_exec(bContext *C, wmOperator *unused)
554 {
555         SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
556         
557         if(sfile->params) {
558                 BLI_parent_dir(sfile->params->dir);
559                 filelist_setdir(sfile->files, sfile->params->dir);
560                 filelist_free(sfile->files);
561                 sfile->params->active_file = -1;
562         }               
563         WM_event_add_notifier(C, NC_FILE|ND_FILELIST, NULL);
564
565         return OPERATOR_FINISHED;
566
567 }
568
569
570 void FILE_OT_parent(struct wmOperatorType *ot)
571 {
572         /* identifiers */
573         ot->name= "Parent File";
574         ot->idname= "FILE_OT_parent";
575         
576         /* api callbacks */
577         ot->exec= file_parent_exec;
578         ot->poll= ED_operator_file_active; /* <- important, handler is on window level */
579 }
580
581
582 int file_refresh_exec(bContext *C, wmOperator *unused)
583 {
584         SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
585         
586         if(sfile->params) {
587                 filelist_setdir(sfile->files, sfile->params->dir);
588                 filelist_free(sfile->files);
589                 sfile->params->active_file = -1;
590         }
591         WM_event_add_notifier(C, NC_FILE|ND_FILELIST, NULL);
592
593         return OPERATOR_FINISHED;
594
595 }
596
597
598 void FILE_OT_refresh(struct wmOperatorType *ot)
599 {
600         /* identifiers */
601         ot->name= "Refresh Filelist";
602         ot->idname= "FILE_OT_refresh";
603         
604         /* api callbacks */
605         ot->exec= file_refresh_exec;
606         ot->poll= ED_operator_file_active; /* <- important, handler is on window level */
607 }
608
609 int file_hidedot_exec(bContext *C, wmOperator *unused)
610 {
611         SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
612         
613         if(sfile->params) {
614                 sfile->params->flag ^= FILE_HIDE_DOT;
615                 filelist_free(sfile->files);
616                 sfile->params->active_file = -1;
617                 WM_event_add_notifier(C, NC_FILE|ND_FILELIST, NULL);
618         }
619         
620         return OPERATOR_FINISHED;
621
622 }
623
624
625 void FILE_OT_hidedot(struct wmOperatorType *ot)
626 {
627         /* identifiers */
628         ot->name= "Toggle Hide Dot Files";
629         ot->idname= "FILE_OT_hidedot";
630         
631         /* api callbacks */
632         ot->exec= file_hidedot_exec;
633         ot->poll= ED_operator_file_active; /* <- important, handler is on window level */
634 }
635
636 struct ARegion *file_buttons_region(struct ScrArea *sa)
637 {
638         ARegion *ar, *arnew;
639         
640         for(ar= sa->regionbase.first; ar; ar= ar->next)
641                 if(ar->regiontype==RGN_TYPE_CHANNELS)
642                         return ar;
643
644         /* add subdiv level; after header */
645         for(ar= sa->regionbase.first; ar; ar= ar->next)
646                 if(ar->regiontype==RGN_TYPE_HEADER)
647                         break;
648         
649         /* is error! */
650         if(ar==NULL) return NULL;
651         
652         arnew= MEM_callocN(sizeof(ARegion), "buttons for file panels");
653         
654         BLI_insertlinkafter(&sa->regionbase, ar, arnew);
655         arnew->regiontype= RGN_TYPE_CHANNELS;
656         arnew->alignment= RGN_ALIGN_LEFT;
657         
658         arnew->flag = RGN_FLAG_HIDDEN;
659         
660         return arnew;
661 }
662
663 int file_bookmark_toggle_exec(bContext *C, wmOperator *unused)
664 {
665         ScrArea *sa= CTX_wm_area(C);
666         ARegion *ar= file_buttons_region(sa);
667         
668         if(ar) {
669                 ar->flag ^= RGN_FLAG_HIDDEN;
670                 ar->v2d.flag &= ~V2D_IS_INITIALISED; /* XXX should become hide/unhide api? */
671                 
672                 ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa);
673                 ED_area_tag_redraw(sa);
674         }
675         return OPERATOR_FINISHED;
676 }
677
678 void FILE_OT_bookmark_toggle(struct wmOperatorType *ot)
679 {
680         /* identifiers */
681         ot->name= "Toggle Bookmarks";
682         ot->idname= "FILE_OT_bookmark_toggle";
683         
684         /* api callbacks */
685         ot->exec= file_bookmark_toggle_exec;
686         ot->poll= ED_operator_file_active; /* <- important, handler is on window level */
687 }