~ubuntu-branches/ubuntu/quantal/clex/quantal

« back to all changes in this revision

Viewing changes to src/directory.c

  • Committer: Bazaar Package Importer
  • Author(s): Gabriel Puliatti
  • Date: 2006-10-10 21:00:45 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061010210045-ffvd59e6r74moead
Tags: 3.15-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 *
3
3
 * CLEX File Manager
4
4
 *
5
 
 * Copyright (C) 2001-2005 Vlado Potisk <vlado_potisk@clex.sk>
 
5
 * Copyright (C) 2001-2006 Vlado Potisk <vlado_potisk@clex.sk>
6
6
 *
7
7
 * CLEX is free software without warranty of any kind; see the
8
8
 * GNU General Public License as set out in the "COPYING" document
22
22
#include "directory.h"
23
23
 
24
24
#include "cfg.h"                        /* config_num() */
25
 
#include "completion.h"         /* compl_dir() */
 
25
#include "completion.h"         /* compl_file() */
26
26
#include "control.h"            /* get_current_mode() */
27
27
#include "edit.h"                       /* edit_setprompt() */
28
28
#include "filepanel.h"          /* changedir() */
48
48
 
49
49
/* additional entries to be allocated when the 'dirlist' table is full */
50
50
#define SAVEDIR_ALLOC_UNIT      32
 
51
#define SAVEDIR_ALLOC_MAX       384     /* 'dirlist' size limit */
51
52
 
52
53
typedef struct {
53
54
        USTRING dirname;                /* directory name */
91
92
}
92
93
 
93
94
/*
94
 
 * lenght of the common part of two directory names (FQDNs)
 
95
 * length of the common part of two directory names (FQDNs)
95
96
 * (this is not the same as common part of two strings)
96
97
 */
97
98
static size_t
172
173
 */
173
174
#define NO_COMPACT      5       /* preserve top 5 directory names */
174
175
void
175
 
dir_main_prepare(void)
 
176
dir_main_panel(void)
176
177
{
177
178
        int i, j, cnt, sub;
178
179
        FLAG store;
179
 
        const char *dirname, *prevdir;
 
180
        const char *dirname, *filter;
180
181
 
181
182
        /* D_PANEL_SIZE = AUTO */
182
183
        if (config_num(CFG_D_SIZE) == 0) {
188
189
                LIMIT_MAX(dp_max,dp_alloc);
189
190
        }
190
191
 
191
 
        cnt = 0;
192
 
        for (i = 0; i < dircnt; i++) {
 
192
        filter = panel_dir.pd->filtering ? panel_dir.pd->filter->line : 0;
 
193
 
 
194
        for (i = cnt = 0; i < dircnt; i++) {
193
195
                if (cnt == dp_max)
194
196
                        break;
195
197
                dirname = USTR(dirlist[i]->dirname);
 
198
                if (filter && !substring(dirname,filter,0))
 
199
                        continue;
196
200
                /* compacting */
197
201
                store = 1;
198
202
                if (i >= NO_COMPACT)
227
231
                        common_part(DP_LIST[i].name,DP_LIST[i - 1].name);
228
232
 
229
233
        panel_dir.pd->cnt = cnt;
 
234
}
 
235
 
 
236
void
 
237
dir_main_prepare(void)
 
238
{
 
239
        int i;
 
240
        const char *prevdir;
 
241
 
 
242
        panel_dir.pd->filtering = 0;
 
243
        dir_main_panel();
 
244
        panel_dir.pd->norev = 0;
230
245
        panel_dir.pd->top = panel_dir.pd->min;
231
246
        /* set cursor to previously used directory */
232
247
        panel_dir.pd->curs = 0;
233
248
        prevdir = USTR(dirlist[(dircnt >= 2)]->dirname);        /* [1] or [0] */
234
 
        for (i = 0; i < cnt; i++)
 
249
        for (i = 0; i < panel_dir.pd->cnt; i++)
235
250
                if (DP_LIST[i].name == prevdir) {
236
251
                        panel_dir.pd->curs = i;
237
252
                        break;
238
253
                }
239
 
        panel_dir.pd->norev = 0;
240
 
 
241
254
        panel = panel_dir.pd;
242
255
        textline = &line_dir;
243
256
        edit_nu_kill();
295
308
        panel_dir_split.pd->norev = 0;
296
309
 
297
310
        panel = panel_dir_split.pd;
 
311
 
298
312
        /* textline inherited */
299
313
}
300
314
 
309
323
        FLAG new;
310
324
        SAVEDIR *x, *top;
311
325
 
312
 
        if (dircnt == diralloc) {
 
326
        if (dircnt == diralloc && diralloc < SAVEDIR_ALLOC_MAX) {
313
327
                diralloc += SAVEDIR_ALLOC_UNIT;
314
328
                dirlist = erealloc(dirlist,diralloc * sizeof(SAVEDIR *));
315
329
                x = emalloc(SAVEDIR_ALLOC_UNIT * sizeof(SAVEDIR));
320
334
                }
321
335
        }
322
336
 
323
 
        for (new = 1, top = dirlist[0], i = 0; i <= dircnt; i++) {
 
337
        for (new = 1, top = dirlist[0], i = 0; i <= dircnt && i < SAVEDIR_ALLOC_MAX; i++) {
324
338
                x = dirlist[i];
325
339
                dirlist[i] = top;
326
340
                top = x;
387
401
static const char *
388
402
selected_dir(void)
389
403
{
390
 
        return get_current_mode() == MODE_DIR_SPLIT
391
 
          ? sub_dir(panel_dir_split.pd->curs)
392
 
          : DP_LIST[panel_dir.pd->curs].name;
 
404
        return get_current_mode() == MODE_DIR_SPLIT ?
 
405
          sub_dir(panel_dir_split.pd->curs) : DP_LIST[panel_dir.pd->curs].name;
393
406
}
394
407
 
395
408
void
398
411
        const char *dir;
399
412
 
400
413
        if (textline->size)
401
 
                compl_dir();
 
414
                compl_file(COMPL_TYPE_DIRPANEL);
402
415
        else if (panel->curs >= 0) {
403
416
                dir = selected_dir();
404
417
                edit_nu_insertstr(dir,0);
413
426
{
414
427
        const char *dir;
415
428
 
416
 
        if (textline->size)
 
429
        if (panel->norev) {
 
430
                /* focus on the input line */
 
431
                if (textline->size == 0)
 
432
                        return;
417
433
                dir = dir_tilde(USTR(textline->line));
418
 
        else if (panel->curs < 0) {
419
 
                if (get_current_mode() == MODE_DIR && panel->curs == -1)
420
 
                        next_mode = MODE_BM;
421
 
                else
422
 
                        next_mode = MODE_SPECIAL_RETURN;
423
 
                return;
424
434
        }
425
 
        else if (get_current_mode() == MODE_DIR_SPLIT)
426
 
                dir = sub_dir(panel_dir_split.pd->curs);
427
435
        else {
428
 
                /* DIR_MAIN -> DIR_SPLIT */
429
 
                next_mode = MODE_DIR_SPLIT;
430
 
                return;
 
436
                /* focus on the panel */
 
437
                if (panel->curs < 0)
 
438
                        /* next_mode is set by the EXTRA_LINE table */
 
439
                        return;
 
440
                if (get_current_mode() == MODE_DIR_SPLIT)
 
441
                        dir = sub_dir(panel_dir_split.pd->curs);
 
442
                else {
 
443
                        /* DIR_MAIN -> DIR_SPLIT */
 
444
                        cx_edit_kill();
 
445
                        next_mode = MODE_DIR_SPLIT;
 
446
                        return;
 
447
                }
431
448
        }
432
449
 
433
450
        if (changedir(dir) == 0) {
437
454
 
438
455
        if (dir[0] == ' ' || dir[strlen(dir) - 1] == ' ')
439
456
                /* common user error */
440
 
                win_remark("there are spaces before or after "
441
 
                  "the directory name");
 
457
                win_remark("check the spaces around the directory name");
 
458
        next_mode = 0;
442
459
}