~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/editors/space_file/file_ops.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 *  \ingroup spfile
29
29
 */
30
30
 
 
31
#include "BLI_blenlib.h"
 
32
#include "BLI_utildefines.h"
31
33
 
32
34
#include "BKE_context.h"
33
35
#include "BKE_screen.h"
35
37
#include "BKE_report.h"
36
38
#include "BKE_main.h"
37
39
 
38
 
#include "BLI_blenlib.h"
39
 
#include "BLI_utildefines.h"
40
 
 
41
40
#ifdef WIN32
42
41
#  include "BLI_winstuff.h"
43
42
#endif
64
63
#include <stdio.h>
65
64
#include <ctype.h>
66
65
 
67
 
/* for events */
68
 
#define NOTACTIVEFILE                   0
69
 
#define ACTIVATE                        1
70
 
#define INACTIVATE                      2
71
 
 
72
66
/* ---------- FILE SELECTION ------------ */
73
 
static FileSelection find_file_mouse_rect(SpaceFile *sfile, struct ARegion* ar, const rcti* rect)
 
67
static FileSelection find_file_mouse_rect(SpaceFile *sfile, ARegion *ar, const rcti *rect)
74
68
{
75
69
        FileSelection sel;
76
 
        float fxmin,fymin,fxmax, fymax;
 
70
        float fxmin, fymin, fxmax, fymax;
77
71
        
78
 
        View2D* v2d = &ar->v2d;
 
72
        View2D *v2d = &ar->v2d;
79
73
        rcti rect_view;
80
74
 
81
75
        UI_view2d_region_to_view(v2d, rect->xmin, rect->ymin, &fxmin, &fymin);
82
76
        UI_view2d_region_to_view(v2d, rect->xmax, rect->ymax, &fxmax, &fymax);
83
77
 
84
 
        BLI_init_rcti(&rect_view, (int)(v2d->tot.xmin + fxmin), (int)(v2d->tot.xmin + fxmax), (int)(v2d->tot.ymax - fymin), (int)(v2d->tot.ymax - fymax));
 
78
        BLI_rcti_init(&rect_view, (int)(v2d->tot.xmin + fxmin), (int)(v2d->tot.xmin + fxmax), (int)(v2d->tot.ymax - fymin), (int)(v2d->tot.ymax - fymax));
85
79
 
86
80
        sel  = ED_fileselect_layout_offset_rect(sfile->layout, &rect_view);
87
81
        
88
82
        return sel;
89
83
}
90
84
 
91
 
static void file_deselect_all(SpaceFile* sfile, unsigned int flag)
 
85
static void file_deselect_all(SpaceFile *sfile, unsigned int flag)
92
86
{
93
87
        FileSelection sel;
94
88
        sel.first = 0;
95
 
        sel.last = filelist_numfiles(sfile->files)-1;
 
89
        sel.last = filelist_numfiles(sfile->files) - 1;
96
90
        
97
91
        filelist_select(sfile->files, &sel, FILE_SEL_REMOVE, flag, CHECK_ALL);
98
92
}
103
97
        FILE_SELECT_FILE = 2 
104
98
} FileSelect;
105
99
 
106
 
static void clamp_to_filelist(int numfiles, FileSelection* sel)
 
100
static void clamp_to_filelist(int numfiles, FileSelection *sel)
107
101
{
108
102
        /* border select before the first file */
109
 
        if ( (sel->first < 0) && (sel->last >=0 ) ) {
 
103
        if ( (sel->first < 0) && (sel->last >= 0) ) {
110
104
                sel->first = 0;
111
105
        }
112
106
        /* don't select if everything is outside filelist */
117
111
        
118
112
        /* fix if last file invalid */
119
113
        if ( (sel->first > 0) && (sel->last < 0) )
120
 
                sel->last = numfiles-1;
 
114
                sel->last = numfiles - 1;
121
115
 
122
116
        /* clamp */
123
117
        if ( (sel->first >= numfiles) ) {
124
 
                sel->first = numfiles-1;
 
118
                sel->first = numfiles - 1;
125
119
        }
126
120
        if ( (sel->last >= numfiles) ) {
127
 
                sel->last = numfiles-1;
 
121
                sel->last = numfiles - 1;
128
122
        }
129
123
}
130
124
 
131
 
static FileSelection file_selection_get(bContext* C, const rcti* rect, short fill)
 
125
static FileSelection file_selection_get(bContext *C, const rcti *rect, short fill)
132
126
{
133
 
        ARegion *ar= CTX_wm_region(C);
134
 
        SpaceFile *sfile= CTX_wm_space_file(C);
 
127
        ARegion *ar = CTX_wm_region(C);
 
128
        SpaceFile *sfile = CTX_wm_space_file(C);
135
129
        int numfiles = filelist_numfiles(sfile->files);
136
130
        FileSelection sel;
137
131
 
138
132
        sel = find_file_mouse_rect(sfile, ar, rect);
139
 
        if ( !((sel.first == -1) && (sel.last == -1)) ) {
 
133
        if (!((sel.first == -1) && (sel.last == -1)) ) {
140
134
                clamp_to_filelist(numfiles, &sel);
141
135
        }
142
136
 
143
137
 
144
138
        /* if desired, fill the selection up from the last selected file to the current one */
145
139
        if (fill && (sel.last >= 0) && (sel.last < numfiles) ) {
146
 
                int f= sel.last;
 
140
                int f = sel.last;
147
141
                while (f >= 0) {
148
 
                        if ( filelist_is_selected(sfile->files, f, CHECK_ALL) )
 
142
                        if (filelist_is_selected(sfile->files, f, CHECK_ALL) )
149
143
                                break;
150
144
                        f--;
151
145
                }
152
146
                if (f >= 0) {
153
 
                        sel.first = f+1;
 
147
                        sel.first = f + 1;
154
148
                }
155
149
        }
156
150
        return sel;
157
151
}
158
152
 
159
 
static FileSelect file_select_do(bContext* C, int selected_idx)
 
153
static FileSelect file_select_do(bContext *C, int selected_idx, short do_diropen)
160
154
{
161
155
        FileSelect retval = FILE_SELECT_NOTHING;
162
 
        SpaceFile *sfile= CTX_wm_space_file(C);
 
156
        SpaceFile *sfile = CTX_wm_space_file(C);
163
157
        FileSelectParams *params = ED_fileselect_get_params(sfile);
164
158
        int numfiles = filelist_numfiles(sfile->files);
165
 
        struct direntry* file;
 
159
        struct direntry *file;
166
160
 
167
161
        /* make the selected file active */
168
 
        if (            (selected_idx >= 0) &&
169
 
                    (selected_idx < numfiles) &&
170
 
                    (file= filelist_file(sfile->files, selected_idx)))
 
162
        if ((selected_idx >= 0) &&
 
163
            (selected_idx < numfiles) &&
 
164
            (file = filelist_file(sfile->files, selected_idx)))
171
165
        {
172
166
                params->active_file = selected_idx;
173
167
 
174
168
                if (S_ISDIR(file->type)) {
 
169
                        if (do_diropen == FALSE) {
 
170
                                params->file[0] = '\0';
 
171
                                retval = FILE_SELECT_DIR;
 
172
                        }
175
173
                        /* the path is too long and we are not going up! */
176
 
                        if (strcmp(file->relname, "..") && strlen(params->dir) + strlen(file->relname) >= FILE_MAX ) {
 
174
                        else if (strcmp(file->relname, "..") && strlen(params->dir) + strlen(file->relname) >= FILE_MAX) {
177
175
                                // XXX error("Path too long, cannot enter this directory");
178
176
                        }
179
177
                        else {
180
 
                                if (strcmp(file->relname, "..")==0) {
 
178
                                if (strcmp(file->relname, "..") == 0) {
181
179
                                        /* avoids /../../ */
182
180
                                        BLI_parent_dir(params->dir);
183
181
                                }
202
200
}
203
201
 
204
202
 
205
 
static FileSelect file_select(bContext* C, const rcti* rect, FileSelType select, short fill)
 
203
static FileSelect file_select(bContext *C, const rcti *rect, FileSelType select, short fill, short do_diropen)
206
204
{
207
 
        SpaceFile *sfile= CTX_wm_space_file(C);
 
205
        SpaceFile *sfile = CTX_wm_space_file(C);
208
206
        FileSelect retval = FILE_SELECT_NOTHING;
209
 
        FileSelection sel= file_selection_get(C, rect, fill); /* get the selection */
210
 
        const FileCheckType check_type= (sfile->params->flag & FILE_DIRSEL_ONLY) ? CHECK_DIRS : CHECK_ALL;
 
207
        FileSelection sel = file_selection_get(C, rect, fill); /* get the selection */
 
208
        const FileCheckType check_type = (sfile->params->flag & FILE_DIRSEL_ONLY) ? CHECK_DIRS : CHECK_ALL;
211
209
        
212
210
        /* flag the files as selected in the filelist */
213
211
        filelist_select(sfile->files, &sel, select, SELECTED_FILE, check_type);
219
217
        if ((sel.last >= 0) && ((select == FILE_SEL_ADD) || (select == FILE_SEL_TOGGLE))) {
220
218
                /* Check last selection, if selected, act on the file or dir */
221
219
                if (filelist_is_selected(sfile->files, sel.last, check_type)) {
222
 
                        retval = file_select_do(C, sel.last);
 
220
                        retval = file_select_do(C, sel.last, do_diropen);
223
221
                }
224
222
        }
225
223
 
231
229
 
232
230
static int file_border_select_modal(bContext *C, wmOperator *op, wmEvent *event)
233
231
{
234
 
        ARegion *ar= CTX_wm_region(C);
235
 
        SpaceFile *sfile= CTX_wm_space_file(C);
 
232
        ARegion *ar = CTX_wm_region(C);
 
233
        SpaceFile *sfile = CTX_wm_space_file(C);
236
234
        FileSelectParams *params = ED_fileselect_get_params(sfile);
237
235
        FileSelection sel;
238
236
        rcti rect;
239
237
 
240
238
        int result;
241
239
 
242
 
        result= WM_border_select_modal(C, op, event);
243
 
 
244
 
        if (result==OPERATOR_RUNNING_MODAL)     {
245
 
 
246
 
                rect.xmin = RNA_int_get(op->ptr, "xmin");
247
 
                rect.ymin = RNA_int_get(op->ptr, "ymin");
248
 
                rect.xmax = RNA_int_get(op->ptr, "xmax");
249
 
                rect.ymax = RNA_int_get(op->ptr, "ymax");
250
 
 
251
 
                BLI_isect_rcti(&(ar->v2d.mask), &rect, &rect);
 
240
        result = WM_border_select_modal(C, op, event);
 
241
 
 
242
        if (result == OPERATOR_RUNNING_MODAL) {
 
243
 
 
244
                WM_operator_properties_border_to_rcti(op, &rect);
 
245
 
 
246
                BLI_rcti_isect(&(ar->v2d.mask), &rect, &rect);
252
247
 
253
248
                sel = file_selection_get(C, &rect, 0);
254
249
                if ( (sel.first != params->sel_first) || (sel.last != params->sel_last) ) {
255
250
                        file_deselect_all(sfile, HILITED_FILE);
256
251
                        filelist_select(sfile->files, &sel, FILE_SEL_ADD, HILITED_FILE, CHECK_ALL);
257
 
                        WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_PARAMS, NULL);
 
252
                        WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL);
258
253
                }
259
254
                params->sel_first = sel.first; params->sel_last = sel.last;
260
255
 
263
258
                params->active_file = -1;
264
259
                params->sel_first = params->sel_last = -1;
265
260
                file_deselect_all(sfile, HILITED_FILE);
266
 
                WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_PARAMS, NULL);
 
261
                WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL);
267
262
        }
268
263
 
269
264
        return result;
271
266
 
272
267
static int file_border_select_exec(bContext *C, wmOperator *op)
273
268
{
274
 
        ARegion *ar= CTX_wm_region(C);
 
269
        ARegion *ar = CTX_wm_region(C);
275
270
        rcti rect;
276
271
        FileSelect ret;
277
 
        int extend= RNA_boolean_get(op->ptr, "extend");
278
 
        short select= (RNA_int_get(op->ptr, "gesture_mode")==GESTURE_MODAL_SELECT);
 
272
        int extend = RNA_boolean_get(op->ptr, "extend");
 
273
        short select = (RNA_int_get(op->ptr, "gesture_mode") == GESTURE_MODAL_SELECT);
279
274
 
280
 
        rect.xmin = RNA_int_get(op->ptr, "xmin");
281
 
        rect.ymin = RNA_int_get(op->ptr, "ymin");
282
 
        rect.xmax = RNA_int_get(op->ptr, "xmax");
283
 
        rect.ymax = RNA_int_get(op->ptr, "ymax");
 
275
        WM_operator_properties_border_to_rcti(op, &rect);
284
276
 
285
277
        if (!extend) {
286
 
                SpaceFile *sfile= CTX_wm_space_file(C);
 
278
                SpaceFile *sfile = CTX_wm_space_file(C);
287
279
 
288
280
                file_deselect_all(sfile, SELECTED_FILE);
289
281
        }
290
282
 
291
 
        BLI_isect_rcti(&(ar->v2d.mask), &rect, &rect);
 
283
        BLI_rcti_isect(&(ar->v2d.mask), &rect, &rect);
292
284
 
293
 
        ret = file_select(C, &rect, select ? FILE_SEL_ADD : FILE_SEL_REMOVE, 0);
 
285
        ret = file_select(C, &rect, select ? FILE_SEL_ADD : FILE_SEL_REMOVE, FALSE, FALSE);
294
286
        if (FILE_SELECT_DIR == ret) {
295
 
                WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
 
287
                WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);
296
288
        }
297
289
        else if (FILE_SELECT_FILE == ret) {
298
 
                WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_PARAMS, NULL);
 
290
                WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL);
299
291
        }
300
292
        return OPERATOR_FINISHED;
301
293
}
314
306
        ot->poll = ED_operator_file_active;
315
307
        ot->cancel = WM_border_select_cancel;
316
308
 
317
 
        /* rna */
 
309
        /* properties */
318
310
        WM_operator_properties_gesture_border(ot, 1);
319
311
}
320
312
 
321
313
static int file_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
322
314
{
323
 
        ARegion *ar= CTX_wm_region(C);
324
 
        SpaceFile *sfile= CTX_wm_space_file(C);
 
315
        ARegion *ar = CTX_wm_region(C);
 
316
        SpaceFile *sfile = CTX_wm_space_file(C);
325
317
        FileSelect ret;
326
318
        rcti rect;
327
319
        int extend = RNA_boolean_get(op->ptr, "extend");
328
320
        int fill = RNA_boolean_get(op->ptr, "fill");
 
321
        int do_diropen = RNA_boolean_get(op->ptr, "open");
329
322
 
330
323
        if (ar->regiontype != RGN_TYPE_WINDOW)
331
324
                return OPERATOR_CANCELLED;
333
326
        rect.xmin = rect.xmax = event->mval[0];
334
327
        rect.ymin = rect.ymax = event->mval[1];
335
328
 
336
 
        if (!BLI_in_rcti(&ar->v2d.mask, rect.xmin, rect.ymin))
 
329
        if (!BLI_rcti_isect_pt(&ar->v2d.mask, rect.xmin, rect.ymin))
337
330
                return OPERATOR_CANCELLED;
338
331
 
339
332
        /* single select, deselect all selected first */
340
333
        if (!extend) file_deselect_all(sfile, SELECTED_FILE);
341
334
 
342
 
        ret = file_select(C, &rect, extend ? FILE_SEL_TOGGLE : FILE_SEL_ADD, fill);
 
335
        ret = file_select(C, &rect, extend ? FILE_SEL_TOGGLE : FILE_SEL_ADD, fill, do_diropen);
343
336
        if (FILE_SELECT_DIR == ret)
344
 
                WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
 
337
                WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);
345
338
        else if (FILE_SELECT_FILE == ret)
346
 
                WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_PARAMS, NULL);
 
339
                WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL);
347
340
 
348
341
        WM_event_add_mousemove(C); /* for directory changes */
349
 
        WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_PARAMS, NULL);
 
342
        WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL);
350
343
 
351
344
        return OPERATOR_FINISHED;
352
345
}
353
346
 
354
347
void FILE_OT_select(wmOperatorType *ot)
355
348
{
 
349
        PropertyRNA *prop;
 
350
 
356
351
        /* identifiers */
357
352
        ot->name = "Activate/Select File";
358
353
        ot->description = "Activate/select file";
362
357
        ot->invoke = file_select_invoke;
363
358
        ot->poll = ED_operator_file_active;
364
359
 
365
 
        /* rna */
366
 
        RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend selection instead of deselecting everything first");
367
 
        RNA_def_boolean(ot->srna, "fill", 0, "Fill", "Select everything beginning with the last selection");
 
360
        /* properties */
 
361
        prop = RNA_def_boolean(ot->srna, "extend", FALSE, "Extend", "Extend selection instead of deselecting everything first");
 
362
        RNA_def_property_flag(prop, PROP_SKIP_SAVE);
 
363
        prop = RNA_def_boolean(ot->srna, "fill", FALSE, "Fill", "Select everything beginning with the last selection");
 
364
        RNA_def_property_flag(prop, PROP_SKIP_SAVE);
 
365
        prop = RNA_def_boolean(ot->srna, "open", TRUE, "Open", "Open a directory when selecting it");
 
366
        RNA_def_property_flag(prop, PROP_SKIP_SAVE);
368
367
}
369
368
 
370
369
static int file_select_all_exec(bContext *C, wmOperator *UNUSED(op))
371
370
{
372
 
        ScrArea *sa= CTX_wm_area(C);
373
 
        SpaceFile *sfile= CTX_wm_space_file(C);
 
371
        ScrArea *sa = CTX_wm_area(C);
 
372
        SpaceFile *sfile = CTX_wm_space_file(C);
374
373
        FileSelection sel;
375
374
        int numfiles = filelist_numfiles(sfile->files);
376
375
        int i;
377
376
        int is_selected = 0;
378
377
 
379
378
        sel.first = 0; 
380
 
        sel.last = numfiles-1;
 
379
        sel.last = numfiles - 1;
381
380
 
382
381
        /* Is any file selected ? */
383
 
        for ( i=0; i < numfiles; ++i) {
 
382
        for (i = 0; i < numfiles; ++i) {
384
383
                if (filelist_is_selected(sfile->files, i, CHECK_ALL)) {
385
384
                        is_selected = 1;
386
385
                        break;
391
390
                filelist_select(sfile->files, &sel, FILE_SEL_REMOVE, SELECTED_FILE, CHECK_ALL);
392
391
        }
393
392
        else {
394
 
                const FileCheckType check_type= (sfile->params->flag & FILE_DIRSEL_ONLY) ? CHECK_DIRS : CHECK_FILES;
 
393
                const FileCheckType check_type = (sfile->params->flag & FILE_DIRSEL_ONLY) ? CHECK_DIRS : CHECK_FILES;
395
394
                filelist_select(sfile->files, &sel, FILE_SEL_ADD, SELECTED_FILE, check_type);
396
395
        }
397
396
        ED_area_tag_redraw(sa);
409
408
        ot->exec = file_select_all_exec;
410
409
        ot->poll = ED_operator_file_active;
411
410
 
412
 
        /* rna */
413
 
 
414
 
        
 
411
        /* properties */
415
412
}
416
413
 
417
414
/* ---------- BOOKMARKS ----------- */
418
415
 
419
416
static int bookmark_select_exec(bContext *C, wmOperator *op)
420
417
{
421
 
        SpaceFile *sfile= CTX_wm_space_file(C);
 
418
        SpaceFile *sfile = CTX_wm_space_file(C);
422
419
 
423
420
        if (RNA_struct_find_property(op->ptr, "dir")) {
424
421
                char entry[256];
425
 
                FileSelectParams* params = sfile->params;
 
422
                FileSelectParams *params = sfile->params;
426
423
 
427
424
                RNA_string_get(op->ptr, "dir", entry);
428
425
                BLI_strncpy(params->dir, entry, sizeof(params->dir));
429
426
                BLI_cleanup_dir(G.main->name, params->dir);
430
427
                file_change_dir(C, 1);
431
428
 
432
 
                WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
 
429
                WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);
433
430
        }
434
431
        
435
432
        return OPERATOR_FINISHED;
437
434
 
438
435
void FILE_OT_select_bookmark(wmOperatorType *ot)
439
436
{
 
437
        PropertyRNA *prop;
 
438
 
440
439
        /* identifiers */
441
440
        ot->name = "Select Directory";
442
441
        ot->description = "Select a bookmarked directory";
446
445
        ot->exec = bookmark_select_exec;
447
446
        ot->poll = ED_operator_file_active;
448
447
 
449
 
        RNA_def_string(ot->srna, "dir", "", 256, "Dir", "");
 
448
        /* properties */
 
449
        prop = RNA_def_string(ot->srna, "dir", "", FILE_MAXDIR, "Dir", "");
 
450
        RNA_def_property_flag(prop, PROP_SKIP_SAVE);
450
451
}
451
452
 
452
453
static int bookmark_add_exec(bContext *C, wmOperator *UNUSED(op))
453
454
{
454
 
        ScrArea *sa= CTX_wm_area(C);
455
 
        SpaceFile *sfile= CTX_wm_space_file(C);
456
 
        struct FSMenu* fsmenu = fsmenu_get();
457
 
        struct FileSelectParams* params= ED_fileselect_get_params(sfile);
 
455
        ScrArea *sa = CTX_wm_area(C);
 
456
        SpaceFile *sfile = CTX_wm_space_file(C);
 
457
        struct FSMenu *fsmenu = fsmenu_get();
 
458
        struct FileSelectParams *params = ED_fileselect_get_params(sfile);
458
459
 
459
460
        if (params->dir[0] != '\0') {
460
461
                char name[FILE_MAX];
461
462
        
462
 
                fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, params->dir, 0, 1);
 
463
                fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, params->dir, FS_INSERT_SAVE);
463
464
                BLI_make_file_string("/", name, BLI_get_folder_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE);
464
465
                fsmenu_write_file(fsmenu, name);
465
466
        }
482
483
 
483
484
static int bookmark_delete_exec(bContext *C, wmOperator *op)
484
485
{
485
 
        ScrArea *sa= CTX_wm_area(C);
486
 
        struct FSMenu* fsmenu = fsmenu_get();
 
486
        ScrArea *sa = CTX_wm_area(C);
 
487
        struct FSMenu *fsmenu = fsmenu_get();
487
488
        int nentries = fsmenu_get_nentries(fsmenu, FS_CATEGORY_BOOKMARKS);
488
489
        
489
490
        if (RNA_struct_find_property(op->ptr, "index")) {
490
491
                int index = RNA_int_get(op->ptr, "index");
491
 
                if ( (index >-1) && (index < nentries)) {
 
492
                if ( (index > -1) && (index < nentries)) {
492
493
                        char name[FILE_MAX];
493
494
                        
494
495
                        fsmenu_remove_entry(fsmenu, FS_CATEGORY_BOOKMARKS, index);
503
504
 
504
505
void FILE_OT_delete_bookmark(wmOperatorType *ot)
505
506
{
 
507
        PropertyRNA *prop;
 
508
 
506
509
        /* identifiers */
507
510
        ot->name = "Delete Bookmark";
508
511
        ot->description = "Delete selected bookmark";
512
515
        ot->exec = bookmark_delete_exec;
513
516
        ot->poll = ED_operator_file_active;
514
517
 
515
 
        RNA_def_int(ot->srna, "index", -1, -1, 20000, "Index", "", -1, 20000);
516
 
}
517
 
 
518
 
int file_hilight_set(SpaceFile *sfile, ARegion *ar, int mx, int my)
519
 
{
520
 
        View2D* v2d = &ar->v2d;
521
 
        FileSelectParams* params;
522
 
        int numfiles, origfile; 
523
 
 
524
 
        if (sfile==NULL || sfile->files==NULL) return 0;
 
518
        /* properties */
 
519
        prop = RNA_def_int(ot->srna, "index", -1, -1, 20000, "Index", "", -1, 20000);
 
520
        RNA_def_property_flag(prop, PROP_SKIP_SAVE);
 
521
}
 
522
 
 
523
static int reset_recent_exec(bContext *C, wmOperator *UNUSED(op))
 
524
{
 
525
        ScrArea *sa = CTX_wm_area(C);
 
526
        char name[FILE_MAX];
 
527
        struct FSMenu *fsmenu = fsmenu_get();
 
528
        
 
529
        while (fsmenu_get_entry(fsmenu, FS_CATEGORY_RECENT, 0) != NULL) {
 
530
                fsmenu_remove_entry(fsmenu, FS_CATEGORY_RECENT, 0);
 
531
        }
 
532
        BLI_make_file_string("/", name, BLI_get_folder_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE);
 
533
        fsmenu_write_file(fsmenu, name);
 
534
        ED_area_tag_redraw(sa);
 
535
                
 
536
        return OPERATOR_FINISHED;
 
537
}
 
538
 
 
539
void FILE_OT_reset_recent(wmOperatorType *ot)
 
540
{
 
541
        /* identifiers */
 
542
        ot->name = "Reset Recent";
 
543
        ot->description = "Reset Recent files";
 
544
        ot->idname = "FILE_OT_reset_recent";
 
545
        
 
546
        /* api callbacks */
 
547
        ot->exec = reset_recent_exec;
 
548
        ot->poll = ED_operator_file_active;
 
549
 
 
550
}
 
551
 
 
552
int file_highlight_set(SpaceFile *sfile, ARegion *ar, int mx, int my)
 
553
{
 
554
        View2D *v2d = &ar->v2d;
 
555
        FileSelectParams *params;
 
556
        int numfiles, origfile;
 
557
 
 
558
        if (sfile == NULL || sfile->files == NULL) return 0;
525
559
 
526
560
        numfiles = filelist_numfiles(sfile->files);
527
561
        params = ED_fileselect_get_params(sfile);
528
562
 
529
 
        origfile= params->active_file;
 
563
        origfile = params->active_file;
530
564
 
531
565
        mx -= ar->winrct.xmin;
532
566
        my -= ar->winrct.ymin;
533
567
 
534
 
        if (BLI_in_rcti(&ar->v2d.mask, mx, my)) {
 
568
        if (BLI_rcti_isect_pt(&ar->v2d.mask, mx, my)) {
535
569
                float fx, fy;
536
570
                int active_file;
537
571
 
540
574
                active_file = ED_fileselect_layout_offset(sfile->layout, (int)(v2d->tot.xmin + fx), (int)(v2d->tot.ymax - fy));
541
575
 
542
576
                if ((active_file >= 0) && (active_file < numfiles))
543
 
                        params->active_file=active_file;
 
577
                        params->active_file = active_file;
544
578
                else
545
 
                        params->active_file= -1;
 
579
                        params->active_file = -1;
546
580
        }
547
581
        else
548
 
                params->active_file= -1;
 
582
                params->active_file = -1;
549
583
 
550
584
        return (params->active_file != origfile);
551
585
}
552
586
 
553
587
static int file_highlight_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
554
588
{
555
 
        ARegion *ar= CTX_wm_region(C);
556
 
        SpaceFile *sfile= CTX_wm_space_file(C);
 
589
        ARegion *ar = CTX_wm_region(C);
 
590
        SpaceFile *sfile = CTX_wm_space_file(C);
557
591
 
558
 
        if (!file_hilight_set(sfile, ar, event->x, event->y))
 
592
        if (!file_highlight_set(sfile, ar, event->x, event->y))
559
593
                return OPERATOR_CANCELLED;
560
594
 
561
595
        ED_area_tag_redraw(CTX_wm_area(C));
577
611
 
578
612
int file_cancel_exec(bContext *C, wmOperator *UNUSED(unused))
579
613
{
580
 
        SpaceFile *sfile= CTX_wm_space_file(C);
 
614
        SpaceFile *sfile = CTX_wm_space_file(C);
581
615
        wmOperator *op = sfile->op;
582
616
        
583
617
        sfile->op = NULL;
590
624
static int file_operator_poll(bContext *C)
591
625
{
592
626
        int poll = ED_operator_file_active(C);
593
 
        SpaceFile *sfile= CTX_wm_space_file(C);
 
627
        SpaceFile *sfile = CTX_wm_space_file(C);
594
628
 
595
 
        if (!sfile || !sfile->op) poll= 0;
 
629
        if (!sfile || !sfile->op) poll = 0;
596
630
 
597
631
        return poll;
598
632
}
634
668
         * they may be already set. */
635
669
        {
636
670
                PointerRNA itemptr;
637
 
                PropertyRNA *prop_files= RNA_struct_find_property(op->ptr, "files");
638
 
                PropertyRNA *prop_dirs= RNA_struct_find_property(op->ptr, "dirs");
 
671
                PropertyRNA *prop_files = RNA_struct_find_property(op->ptr, "files");
 
672
                PropertyRNA *prop_dirs = RNA_struct_find_property(op->ptr, "dirs");
639
673
                int i, numfiles = filelist_numfiles(sfile->files);
640
674
 
641
675
                if (prop_files) {
 
676
                        int num_files = 0;
642
677
                        RNA_property_collection_clear(op->ptr, prop_files);
643
 
                        for (i=0; i<numfiles; i++) {
 
678
                        for (i = 0; i < numfiles; i++) {
644
679
                                if (filelist_is_selected(sfile->files, i, CHECK_FILES)) {
645
 
                                        struct direntry *file= filelist_file(sfile->files, i);
 
680
                                        struct direntry *file = filelist_file(sfile->files, i);
646
681
                                        RNA_property_collection_add(op->ptr, prop_files, &itemptr);
647
682
                                        RNA_string_set(&itemptr, "name", file->relname);
 
683
                                        num_files++;
648
684
                                }
649
685
                        }
 
686
                        /* make sure the file specified in the filename button is added even if no files selected */
 
687
                        if (0 == num_files) {
 
688
                                RNA_property_collection_add(op->ptr, prop_files, &itemptr);
 
689
                                RNA_string_set(&itemptr, "name", sfile->params->file);
 
690
                        }
650
691
                }
651
692
 
652
693
                if (prop_dirs) {
 
694
                        int num_dirs = 0;
653
695
                        RNA_property_collection_clear(op->ptr, prop_dirs);
654
 
                        for (i=0; i<numfiles; i++) {
 
696
                        for (i = 0; i < numfiles; i++) {
655
697
                                if (filelist_is_selected(sfile->files, i, CHECK_DIRS)) {
656
 
                                        struct direntry *file= filelist_file(sfile->files, i);
 
698
                                        struct direntry *file = filelist_file(sfile->files, i);
657
699
                                        RNA_property_collection_add(op->ptr, prop_dirs, &itemptr);
658
700
                                        RNA_string_set(&itemptr, "name", file->relname);
 
701
                                        num_dirs++;
659
702
                                }
660
703
                        }
 
704
                        
 
705
                        /* make sure the directory specified in the button is added even if no directory selected */
 
706
                        if (0 == num_dirs) {
 
707
                                RNA_property_collection_add(op->ptr, prop_dirs, &itemptr);
 
708
                                RNA_string_set(&itemptr, "name", sfile->params->dir);
 
709
                        }
661
710
                }
662
711
 
663
712
 
669
718
        PropertyRNA *prop;
670
719
 
671
720
        /* If neither of the above are set, split the filepath back */
672
 
        if ((prop= RNA_struct_find_property(op->ptr, "filepath"))) {
 
721
        if ((prop = RNA_struct_find_property(op->ptr, "filepath"))) {
673
722
                char filepath[FILE_MAX];
674
723
                RNA_property_string_get(op->ptr, prop, filepath);
675
724
                BLI_split_dirfile(filepath, sfile->params->dir, sfile->params->file, sizeof(sfile->params->dir), sizeof(sfile->params->file));
676
725
        }
677
726
        else {
678
 
                if ((prop= RNA_struct_find_property(op->ptr, "filename"))) {
 
727
                if ((prop = RNA_struct_find_property(op->ptr, "filename"))) {
679
728
                        RNA_property_string_get(op->ptr, prop, sfile->params->file);
680
729
                }
681
 
                if ((prop= RNA_struct_find_property(op->ptr, "directory"))) {
 
730
                if ((prop = RNA_struct_find_property(op->ptr, "directory"))) {
682
731
                        RNA_property_string_get(op->ptr, prop, sfile->params->dir);
683
732
                }
684
733
        }
692
741
 
693
742
void file_draw_check_cb(bContext *C, void *UNUSED(arg1), void *UNUSED(arg2))
694
743
{
695
 
        SpaceFile *sfile= CTX_wm_space_file(C);
696
 
        wmOperator *op= sfile->op;
 
744
        SpaceFile *sfile = CTX_wm_space_file(C);
 
745
        wmOperator *op = sfile->op;
697
746
        if (op) { /* fail on reload */
698
747
                if (op->type->check) {
699
748
                        char filepath[FILE_MAX];
730
779
/* sends events now, so things get handled on windowqueue level */
731
780
int file_exec(bContext *C, wmOperator *exec_op)
732
781
{
733
 
        SpaceFile *sfile= CTX_wm_space_file(C);
 
782
        SpaceFile *sfile = CTX_wm_space_file(C);
734
783
        char filepath[FILE_MAX];
735
784
        
736
785
        if (sfile->op) {
737
 
                wmOperator *op= sfile->op;
 
786
                wmOperator *op = sfile->op;
738
787
        
739
788
                /* when used as a macro, for doubleclick, 
740
789
                 * to prevent closing when doubleclicking on .. item */
741
790
                if (RNA_boolean_get(exec_op->ptr, "need_active")) {
742
 
                        int i, active=0;
 
791
                        int i, active = 0;
743
792
                        
744
 
                        for (i=0; i<filelist_numfiles(sfile->files); i++) {
 
793
                        for (i = 0; i < filelist_numfiles(sfile->files); i++) {
745
794
                                if (filelist_is_selected(sfile->files, i, CHECK_ALL)) {
746
 
                                        active=1;
 
795
                                        active = 1;
747
796
                                        break;
748
797
                                }
749
798
                        }
755
804
 
756
805
                file_sfile_to_operator(op, sfile, filepath);
757
806
 
758
 
                if (BLI_exists(sfile->params->dir))
759
 
                        fsmenu_insert_entry(fsmenu_get(), FS_CATEGORY_RECENT, sfile->params->dir, 0, 1);
 
807
                if (BLI_exists(sfile->params->dir)) {
 
808
                        fsmenu_insert_entry(fsmenu_get(), FS_CATEGORY_RECENT, sfile->params->dir, FS_INSERT_SAVE | FS_INSERT_FIRST);
 
809
                }
760
810
 
761
811
                BLI_make_file_string(G.main->name, filepath, BLI_get_folder_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE);
762
812
                fsmenu_write_file(fsmenu_get(), filepath);
779
829
        /* api callbacks */
780
830
        ot->exec = file_exec;
781
831
        ot->poll = file_operator_poll; 
782
 
        
 
832
 
 
833
        /* properties */
783
834
        prop = RNA_def_boolean(ot->srna, "need_active", 0, "Need Active",
784
835
                               "Only execute if there's an active selected file in the file list");
785
836
        RNA_def_property_flag(prop, PROP_SKIP_SAVE);
788
839
 
789
840
int file_parent_exec(bContext *C, wmOperator *UNUSED(unused))
790
841
{
791
 
        SpaceFile *sfile= CTX_wm_space_file(C);
 
842
        SpaceFile *sfile = CTX_wm_space_file(C);
792
843
        
793
844
        if (sfile->params) {
794
845
                if (BLI_has_parent(sfile->params->dir)) {
795
846
                        BLI_parent_dir(sfile->params->dir);
796
847
                        BLI_cleanup_dir(G.main->name, sfile->params->dir);
797
848
                        file_change_dir(C, 0);
798
 
                        WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
 
849
                        WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);
799
850
                }
800
 
        }               
 
851
        }
801
852
        
802
853
        return OPERATOR_FINISHED;
803
854
 
819
870
 
820
871
static int file_refresh_exec(bContext *C, wmOperator *UNUSED(unused))
821
872
{
822
 
        SpaceFile *sfile= CTX_wm_space_file(C);
 
873
        SpaceFile *sfile = CTX_wm_space_file(C);
 
874
        struct FSMenu *fsmenu = fsmenu_get();
823
875
 
824
876
        ED_fileselect_clear(C, sfile);
825
877
 
826
 
        WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
 
878
        /* refresh system directory menu */
 
879
        fsmenu_refresh_system_category(fsmenu);
 
880
 
 
881
        WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);
827
882
 
828
883
        return OPERATOR_FINISHED;
829
884
 
843
898
 
844
899
int file_previous_exec(bContext *C, wmOperator *UNUSED(unused))
845
900
{
846
 
        SpaceFile *sfile= CTX_wm_space_file(C);
 
901
        SpaceFile *sfile = CTX_wm_space_file(C);
847
902
 
848
903
        if (sfile->params) {
849
904
                if (!sfile->folders_next)
855
910
 
856
911
                file_change_dir(C, 1);
857
912
        }
858
 
        WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
 
913
        WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);
859
914
 
860
915
        return OPERATOR_FINISHED;
861
916
}
874
929
 
875
930
int file_next_exec(bContext *C, wmOperator *UNUSED(unused))
876
931
{
877
 
        SpaceFile *sfile= CTX_wm_space_file(C);
 
932
        SpaceFile *sfile = CTX_wm_space_file(C);
878
933
        if (sfile->params) {
879
934
                if (!sfile->folders_next)
880
935
                        sfile->folders_next = folderlist_new();
886
941
                folderlist_pushdir(sfile->folders_prev, sfile->params->dir);
887
942
 
888
943
                file_change_dir(C, 1);
889
 
        }               
890
 
        WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
 
944
        }
 
945
        WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);
891
946
 
892
947
        return OPERATOR_FINISHED;
893
948
}
897
952
static int file_smoothscroll_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
898
953
{
899
954
        ScrArea *sa = CTX_wm_area(C);
900
 
        SpaceFile *sfile= CTX_wm_space_file(C);
901
 
        ARegion *ar, *oldar= CTX_wm_region(C);
 
955
        SpaceFile *sfile = CTX_wm_space_file(C);
 
956
        ARegion *ar, *oldar = CTX_wm_region(C);
902
957
        int offset;
903
958
        int numfiles, numfiles_layout;
904
959
        int edit_idx = 0;
905
960
        int i;
906
961
 
907
962
        /* escape if not our timer */
908
 
        if (sfile->smoothscroll_timer==NULL || sfile->smoothscroll_timer!=event->customdata)
 
963
        if (sfile->smoothscroll_timer == NULL || sfile->smoothscroll_timer != event->customdata)
909
964
                return OPERATOR_PASS_THROUGH;
910
965
        
911
966
        numfiles = filelist_numfiles(sfile->files);
912
967
 
913
968
        /* check if we are editing a name */
914
 
        for (i=0; i < numfiles; ++i)
915
 
        {
 
969
        for (i = 0; i < numfiles; ++i) {
916
970
                if (filelist_is_selected(sfile->files, i, CHECK_ALL) ) {
917
 
                        edit_idx=i;
 
971
                        edit_idx = i;
918
972
                        break;
919
973
                }
920
974
        }
921
975
 
922
976
        /* if we are not editing, we are done */
923
 
        if (0==edit_idx) {
 
977
        if (0 == edit_idx) {
924
978
                WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), sfile->smoothscroll_timer);
925
 
                sfile->smoothscroll_timer=NULL;
 
979
                sfile->smoothscroll_timer = NULL;
926
980
                return OPERATOR_PASS_THROUGH;
927
981
        }
928
982
 
930
984
        ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
931
985
        if (!ar || ar->regiontype != RGN_TYPE_WINDOW) {
932
986
                WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), sfile->smoothscroll_timer);
933
 
                sfile->smoothscroll_timer=NULL;
 
987
                sfile->smoothscroll_timer = NULL;
934
988
                return OPERATOR_PASS_THROUGH;
935
989
        }
936
990
 
937
991
        offset = ED_fileselect_layout_offset(sfile->layout, (int)ar->v2d.cur.xmin, (int)-ar->v2d.cur.ymax);
938
 
        if (offset<0) offset=0;
 
992
        if (offset < 0) offset = 0;
939
993
 
940
994
        /* scroll offset is the first file in the row/column we are editing in */
941
995
        if (sfile->scroll_offset == 0) {
942
996
                if (sfile->layout->flag & FILE_LAYOUT_HOR) {
943
 
                        sfile->scroll_offset = (edit_idx/sfile->layout->rows)*sfile->layout->rows;
 
997
                        sfile->scroll_offset = (edit_idx / sfile->layout->rows) * sfile->layout->rows;
944
998
                        if (sfile->scroll_offset <= offset) sfile->scroll_offset -= sfile->layout->rows;
945
999
                }
946
1000
                else {
947
 
                        sfile->scroll_offset = (edit_idx/sfile->layout->columns)*sfile->layout->columns;
 
1001
                        sfile->scroll_offset = (edit_idx / sfile->layout->columns) * sfile->layout->columns;
948
1002
                        if (sfile->scroll_offset <= offset) sfile->scroll_offset -= sfile->layout->columns;
949
1003
                }
950
1004
        }
954
1008
        /* check if we have reached our final scroll position */
955
1009
        if ( (sfile->scroll_offset >= offset) && (sfile->scroll_offset < offset + numfiles_layout) ) {
956
1010
                WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), sfile->smoothscroll_timer);
957
 
                sfile->smoothscroll_timer=NULL;
 
1011
                sfile->smoothscroll_timer = NULL;
958
1012
                return OPERATOR_FINISHED;
959
1013
        }
960
1014
 
1008
1062
/* create a new, non-existing folder name, returns 1 if successful, 0 if name couldn't be created.
1009
1063
 * The actual name is returned in 'name', 'folder' contains the complete path, including the new folder name.
1010
1064
 */
1011
 
static int new_folder_path(const char* parent, char *folder, char *name)
 
1065
static int new_folder_path(const char *parent, char *folder, char *name)
1012
1066
{
1013
1067
        int i = 1;
1014
1068
        int len = 0;
1018
1072
        /* check whether folder with the name already exists, in this case
1019
1073
         * add number to the name. Check length of generated name to avoid
1020
1074
         * crazy case of huge number of folders each named 'New Folder (x)' */
1021
 
        while (BLI_exists(folder) && (len<FILE_MAXFILE)) {
 
1075
        while (BLI_exists(folder) && (len < FILE_MAXFILE)) {
1022
1076
                len = BLI_snprintf(name, FILE_MAXFILE, "New Folder(%d)", i);
1023
1077
                BLI_join_dirfile(folder, FILE_MAX, parent, name); /* XXX, not real length */
1024
1078
                i++;
1025
1079
        }
1026
1080
 
1027
 
        return (len<FILE_MAXFILE);
 
1081
        return (len < FILE_MAXFILE);
1028
1082
}
1029
1083
 
1030
1084
int file_directory_new_exec(bContext *C, wmOperator *op)
1031
1085
{
1032
1086
        char name[FILE_MAXFILE];
1033
1087
        char path[FILE_MAX];
1034
 
        int generate_name= 1;
 
1088
        int generate_name = 1;
1035
1089
 
1036
 
        SpaceFile *sfile= CTX_wm_space_file(C);
 
1090
        SpaceFile *sfile = CTX_wm_space_file(C);
1037
1091
        
1038
1092
        if (!sfile->params) {
1039
 
                BKE_report(op->reports,RPT_WARNING, "No parent directory given");
 
1093
                BKE_report(op->reports, RPT_WARNING, "No parent directory given");
1040
1094
                return OPERATOR_CANCELLED;
1041
1095
        }
1042
1096
        
1044
1098
 
1045
1099
        if (RNA_struct_find_property(op->ptr, "directory")) {
1046
1100
                RNA_string_get(op->ptr, "directory", path);
1047
 
                if (path[0] != '\0') generate_name= 0;
 
1101
                if (path[0] != '\0') generate_name = 0;
1048
1102
        }
1049
1103
 
1050
1104
        if (generate_name) {
1051
1105
                /* create a new, non-existing folder name */
1052
1106
                if (!new_folder_path(sfile->params->dir, path, name)) {
1053
 
                        BKE_report(op->reports,RPT_ERROR, "Couldn't create new folder name");
 
1107
                        BKE_report(op->reports, RPT_ERROR, "Could not create new folder name");
1054
1108
                        return OPERATOR_CANCELLED;
1055
1109
                }
1056
1110
        }
1059
1113
        BLI_dir_create_recursive(path);
1060
1114
 
1061
1115
        if (!BLI_exists(path)) {
1062
 
                BKE_report(op->reports,RPT_ERROR, "Couldn't create new folder");
 
1116
                BKE_report(op->reports, RPT_ERROR, "Could not create new folder");
1063
1117
                return OPERATOR_CANCELLED;
1064
 
        } 
 
1118
        }
1065
1119
 
1066
1120
        /* now remember file to jump into editing */
1067
1121
        BLI_strncpy(sfile->params->renamefile, name, FILE_MAXFILE);
1068
1122
 
1069
1123
        /* set timer to smoothly view newly generated file */
1070
 
        sfile->smoothscroll_timer = WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER1, 1.0/1000.0);        /* max 30 frs/sec */
1071
 
        sfile->scroll_offset=0;
 
1124
        sfile->smoothscroll_timer = WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER1, 1.0 / 1000.0);    /* max 30 frs/sec */
 
1125
        sfile->scroll_offset = 0;
1072
1126
 
1073
1127
        /* reload dir to make sure we're seeing what's in the directory */
1074
1128
        ED_fileselect_clear(C, sfile);
1075
 
        WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
 
1129
        WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);
1076
1130
 
1077
1131
        return OPERATOR_FINISHED;
1078
1132
}
1080
1134
 
1081
1135
void FILE_OT_directory_new(struct wmOperatorType *ot)
1082
1136
{
 
1137
        PropertyRNA *prop;
 
1138
 
1083
1139
        /* identifiers */
1084
1140
        ot->name = "Create New Directory";
1085
1141
        ot->description = "Create a new directory";
1090
1146
        ot->exec = file_directory_new_exec;
1091
1147
        ot->poll = ED_operator_file_active; /* <- important, handler is on window level */
1092
1148
 
1093
 
        RNA_def_string_dir_path(ot->srna, "directory", "", FILE_MAX, "Directory", "Name of new directory");
 
1149
        prop = RNA_def_string_dir_path(ot->srna, "directory", "", FILE_MAX, "Directory", "Name of new directory");
 
1150
        RNA_def_property_flag(prop, PROP_SKIP_SAVE);
1094
1151
 
1095
1152
}
1096
1153
 
1097
1154
 
1098
1155
static void file_expand_directory(bContext *C)
1099
1156
{
1100
 
        SpaceFile *sfile= CTX_wm_space_file(C);
 
1157
        SpaceFile *sfile = CTX_wm_space_file(C);
1101
1158
        
1102
1159
        if (sfile->params) {
1103
 
                if ( sfile->params->dir[0] == '~' ) {
1104
 
                        char tmpstr[sizeof(sfile->params->dir)-1];
1105
 
                        BLI_strncpy(tmpstr, sfile->params->dir+1, sizeof(tmpstr));
 
1160
                /* TODO, what about // when relbase isn't valid? */
 
1161
                if (G.relbase_valid && BLI_path_is_rel(sfile->params->dir)) {
 
1162
                        BLI_path_abs(sfile->params->dir, G.main->name);
 
1163
                }
 
1164
                else if (sfile->params->dir[0] == '~') {
 
1165
                        char tmpstr[sizeof(sfile->params->dir) - 1];
 
1166
                        BLI_strncpy(tmpstr, sfile->params->dir + 1, sizeof(tmpstr));
1106
1167
                        BLI_join_dirfile(sfile->params->dir, sizeof(sfile->params->dir), BLI_getDefaultDocumentFolder(), tmpstr);
1107
1168
                }
1108
1169
 
1118
1179
                }
1119
1180
                /* change "C:" --> "C:\", [#28102] */
1120
1181
                else if (   (isalpha(sfile->params->dir[0]) &&
1121
 
                            (sfile->params->dir[1] == ':')) &&
 
1182
                             (sfile->params->dir[1] == ':')) &&
1122
1183
                            (sfile->params->dir[2] == '\0')
1123
1184
 
1124
 
                ) {
1125
 
                        sfile->params->dir[2]= '\\';
1126
 
                        sfile->params->dir[3]= '\0';
 
1185
                            ) {
 
1186
                        sfile->params->dir[2] = '\\';
 
1187
                        sfile->params->dir[3] = '\0';
1127
1188
                }
1128
1189
#endif
1129
1190
        }
1131
1192
 
1132
1193
static int file_directory_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
1133
1194
{
1134
 
        SpaceFile *sfile= CTX_wm_space_file(C);
 
1195
        SpaceFile *sfile = CTX_wm_space_file(C);
1135
1196
 
1136
1197
        if (sfile->params) {
1137
1198
                file_expand_directory(C);
1138
1199
                
1139
1200
                if (!BLI_exists(sfile->params->dir)) {
1140
1201
                        return WM_operator_confirm_message(C, op, "Create new directory?");
1141
 
                } 
 
1202
                }
1142
1203
 
1143
1204
                return file_directory_exec(C, op);
1144
1205
        }
1150
1211
 
1151
1212
int file_directory_exec(bContext *C, wmOperator *UNUSED(unused))
1152
1213
{
1153
 
        SpaceFile *sfile= CTX_wm_space_file(C);
 
1214
        SpaceFile *sfile = CTX_wm_space_file(C);
1154
1215
        
1155
1216
        if (sfile->params) {
1156
1217
                file_expand_directory(C);
1170
1231
                BLI_add_slash(sfile->params->dir);
1171
1232
                file_change_dir(C, 1);
1172
1233
 
1173
 
                WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
1174
 
        }               
1175
 
        
 
1234
                WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);
 
1235
        }
1176
1236
 
1177
1237
        return OPERATOR_FINISHED;
1178
1238
}
1179
1239
 
1180
1240
int file_filename_exec(bContext *C, wmOperator *UNUSED(unused))
1181
1241
{
1182
 
        SpaceFile *sfile= CTX_wm_space_file(C);
1183
 
        
 
1242
        SpaceFile *sfile = CTX_wm_space_file(C);
 
1243
        char matched_file[FILE_MAX];
1184
1244
        if (sfile->params) {
1185
 
                if (file_select_match(sfile, sfile->params->file)) {
 
1245
                matched_file[0] = '\0';
 
1246
                if (file_select_match(sfile, sfile->params->file, matched_file)) {
 
1247
                        /* int i, numfiles = filelist_numfiles(sfile->files); */ /* XXX UNUSED */
1186
1248
                        sfile->params->file[0] = '\0';
1187
 
                        WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_PARAMS, NULL);
 
1249
                        /* replace the pattern (or filename that the user typed in, with the first selected file of the match */
 
1250
                        BLI_strncpy(sfile->params->file, matched_file, sizeof(sfile->params->file));
 
1251
                        
 
1252
                        WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL);
1188
1253
                }
1189
 
        }               
 
1254
        }
1190
1255
 
1191
1256
        return OPERATOR_FINISHED;
1192
1257
}
1196
1261
static int file_directory_poll(bContext *C)
1197
1262
{
1198
1263
        /* sfile->files can be NULL on file load */
1199
 
        SpaceFile *sfile= CTX_wm_space_file(C);
1200
 
        return ED_operator_file_active(C) && (sfile->files==NULL || filelist_lib(sfile->files)==NULL);
 
1264
        SpaceFile *sfile = CTX_wm_space_file(C);
 
1265
        return ED_operator_file_active(C) && (sfile->files == NULL || filelist_lib(sfile->files) == NULL);
1201
1266
}
1202
1267
 
1203
1268
void FILE_OT_directory(struct wmOperatorType *ot)
1227
1292
 
1228
1293
static int file_hidedot_exec(bContext *C, wmOperator *UNUSED(unused))
1229
1294
{
1230
 
        SpaceFile *sfile= CTX_wm_space_file(C);
 
1295
        SpaceFile *sfile = CTX_wm_space_file(C);
1231
1296
        
1232
1297
        if (sfile->params) {
1233
1298
                sfile->params->flag ^= FILE_HIDE_DOT;
1234
1299
                ED_fileselect_clear(C, sfile);
1235
 
                WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
 
1300
                WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);
1236
1301
        }
1237
1302
        
1238
1303
        return OPERATOR_FINISHED;
1251
1316
        ot->poll = ED_operator_file_active; /* <- important, handler is on window level */
1252
1317
}
1253
1318
 
1254
 
struct ARegion *file_buttons_region(struct ScrArea *sa)
 
1319
ARegion *file_buttons_region(ScrArea *sa)
1255
1320
{
1256
1321
        ARegion *ar, *arnew;
1257
1322
        
1258
 
        for (ar= sa->regionbase.first; ar; ar= ar->next)
1259
 
                if (ar->regiontype==RGN_TYPE_CHANNELS)
 
1323
        for (ar = sa->regionbase.first; ar; ar = ar->next)
 
1324
                if (ar->regiontype == RGN_TYPE_CHANNELS)
1260
1325
                        return ar;
1261
1326
 
1262
1327
        /* add subdiv level; after header */
1263
 
        for (ar= sa->regionbase.first; ar; ar= ar->next)
1264
 
                if (ar->regiontype==RGN_TYPE_HEADER)
 
1328
        for (ar = sa->regionbase.first; ar; ar = ar->next)
 
1329
                if (ar->regiontype == RGN_TYPE_HEADER)
1265
1330
                        break;
1266
1331
        
1267
1332
        /* is error! */
1268
 
        if (ar==NULL) return NULL;
 
1333
        if (ar == NULL) return NULL;
1269
1334
        
1270
 
        arnew= MEM_callocN(sizeof(ARegion), "buttons for file panels");
 
1335
        arnew = MEM_callocN(sizeof(ARegion), "buttons for file panels");
1271
1336
        
1272
1337
        BLI_insertlinkafter(&sa->regionbase, ar, arnew);
1273
 
        arnew->regiontype= RGN_TYPE_CHANNELS;
1274
 
        arnew->alignment= RGN_ALIGN_LEFT;
 
1338
        arnew->regiontype = RGN_TYPE_CHANNELS;
 
1339
        arnew->alignment = RGN_ALIGN_LEFT;
1275
1340
        
1276
1341
        arnew->flag = RGN_FLAG_HIDDEN;
1277
1342
        
1280
1345
 
1281
1346
static int file_bookmark_toggle_exec(bContext *C, wmOperator *UNUSED(unused))
1282
1347
{
1283
 
        ScrArea *sa= CTX_wm_area(C);
1284
 
        ARegion *ar= file_buttons_region(sa);
 
1348
        ScrArea *sa = CTX_wm_area(C);
 
1349
        ARegion *ar = file_buttons_region(sa);
1285
1350
        
1286
1351
        if (ar)
1287
1352
                ED_region_toggle_hidden(C, ar);
1304
1369
 
1305
1370
static int file_filenum_exec(bContext *C, wmOperator *op)
1306
1371
{
1307
 
        SpaceFile *sfile= CTX_wm_space_file(C);
1308
 
        ScrArea *sa= CTX_wm_area(C);
 
1372
        SpaceFile *sfile = CTX_wm_space_file(C);
 
1373
        ScrArea *sa = CTX_wm_area(C);
1309
1374
        
1310
1375
        int inc = RNA_int_get(op->ptr, "increment");
1311
1376
        if (sfile->params && (inc != 0)) {
1331
1396
        ot->poll = ED_operator_file_active; /* <- important, handler is on window level */
1332
1397
 
1333
1398
        /* props */
1334
 
        RNA_def_int(ot->srna, "increment", 1, -100, 100, "Increment", "", -100,100);
 
1399
        RNA_def_int(ot->srna, "increment", 1, -100, 100, "Increment", "", -100, 100);
1335
1400
}
1336
1401
 
1337
1402
static int file_rename_exec(bContext *C, wmOperator *UNUSED(op))
1338
1403
{
1339
 
        ScrArea *sa= CTX_wm_area(C);
1340
 
        SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
 
1404
        ScrArea *sa = CTX_wm_area(C);
 
1405
        SpaceFile *sfile = (SpaceFile *)CTX_wm_space_data(C);
1341
1406
        
1342
1407
        if (sfile->params) {
1343
1408
                int idx = sfile->params->active_file;
1344
1409
                int numfiles = filelist_numfiles(sfile->files);
1345
 
                if ( (0<=idx) && (idx<numfiles) ) {
1346
 
                        struct direntry *file= filelist_file(sfile->files, idx);
 
1410
                if ( (0 <= idx) && (idx < numfiles) ) {
 
1411
                        struct direntry *file = filelist_file(sfile->files, idx);
1347
1412
                        filelist_select_file(sfile->files, idx, FILE_SEL_ADD, EDITING_FILE, CHECK_ALL);
1348
1413
                        BLI_strncpy(sfile->params->renameedit, file->relname, FILE_MAXFILE);
1349
 
                        sfile->params->renamefile[0]= '\0';
 
1414
                        sfile->params->renamefile[0] = '\0';
1350
1415
                }
1351
1416
                ED_area_tag_redraw(sa);
1352
1417
        }
1358
1423
static int file_rename_poll(bContext *C)
1359
1424
{
1360
1425
        int poll = ED_operator_file_active(C);
1361
 
        SpaceFile *sfile= CTX_wm_space_file(C);
 
1426
        SpaceFile *sfile = CTX_wm_space_file(C);
1362
1427
 
1363
1428
        if (sfile && sfile->params) {
1364
 
                if (sfile->params->active_file < 0) { 
1365
 
                        poll= 0;
 
1429
                if (sfile->params->active_file < 0) {
 
1430
                        poll = 0;
1366
1431
                }
1367
1432
                else {
1368
 
                        char dir[FILE_MAX], group[FILE_MAX];    
1369
 
                        if (filelist_islibrary(sfile->files, dir, group)) poll= 0;
 
1433
                        char dir[FILE_MAX], group[FILE_MAX];
 
1434
                        if (filelist_islibrary(sfile->files, dir, group)) poll = 0;
1370
1435
                }
1371
1436
        }
1372
1437
        else
1373
 
                poll= 0;
 
1438
                poll = 0;
1374
1439
        return poll;
1375
1440
}
1376
1441
 
1390
1455
static int file_delete_poll(bContext *C)
1391
1456
{
1392
1457
        int poll = ED_operator_file_active(C);
1393
 
        SpaceFile *sfile= CTX_wm_space_file(C);
1394
 
        struct direntry* file;
 
1458
        SpaceFile *sfile = CTX_wm_space_file(C);
 
1459
        struct direntry *file;
1395
1460
 
1396
1461
        if (sfile && sfile->params) {
1397
 
                if (sfile->params->active_file < 0) { 
1398
 
                        poll= 0;
 
1462
                if (sfile->params->active_file < 0) {
 
1463
                        poll = 0;
1399
1464
                }
1400
1465
                else {
1401
 
                        char dir[FILE_MAX], group[FILE_MAX];    
1402
 
                        if (filelist_islibrary(sfile->files, dir, group)) poll= 0;
 
1466
                        char dir[FILE_MAX], group[FILE_MAX];
 
1467
                        if (filelist_islibrary(sfile->files, dir, group)) poll = 0;
1403
1468
                        file = filelist_file(sfile->files, sfile->params->active_file);
1404
 
                        if (file && S_ISDIR(file->type)) poll= 0;
 
1469
                        if (file && S_ISDIR(file->type)) poll = 0;
1405
1470
                }
1406
1471
        }
1407
1472
        else
1408
 
                poll= 0;
 
1473
                poll = 0;
1409
1474
                
1410
1475
        return poll;
1411
1476
}
1413
1478
int file_delete_exec(bContext *C, wmOperator *UNUSED(op))
1414
1479
{
1415
1480
        char str[FILE_MAX];
1416
 
        SpaceFile *sfile= CTX_wm_space_file(C);
1417
 
        struct direntry* file;
 
1481
        SpaceFile *sfile = CTX_wm_space_file(C);
 
1482
        struct direntry *file;
1418
1483
        
1419
1484
        
1420
1485
        file = filelist_file(sfile->files, sfile->params->active_file);
1421
1486
        BLI_make_file_string(G.main->name, str, sfile->params->dir, file->relname);
1422
 
        BLI_delete(str, 0, 0);  
 
1487
        BLI_delete(str, 0, 0);
1423
1488
        ED_fileselect_clear(C, sfile);
1424
 
        WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
 
1489
        WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);
1425
1490
        
1426
1491
        return OPERATOR_FINISHED;
1427
1492