xaizek / vifm (License: GPLv2+) (since 2018-12-07)
Vifm is a file manager with curses interface, which provides Vi[m]-like environment for managing objects within file systems, extended with some useful ideas from mutt.
Commit 7ee0c47766cdb4efcc6de9e1141bf202f17f8086

Extract filelist.c:set_position_by_path() function
Looks up entry by its path in main entry list of the view and
updates cursor position when such entry is found.
Author: xaizek
Author date (UTC): 2017-06-15 20:08
Committer name: xaizek
Committer date (UTC): 2017-06-15 20:08
Parent(s): 8a5b4b4a2d063dbfd02a7d5a9e1c50b997edfa7a
Signing key: 99DC5E4DB05F6BE2
Tree: c58d30d104d8b6e480fcaae111772215252538e3
File Lines added Lines deleted
src/filelist.c 21 16
File src/filelist.c changed (mode: 100644) (index d655d5194..0be60b56c)
... ... static dir_entry_t * pick_sibling(FileView *view, entries_t parent_dirs,
150 150 static int iter_entries(FileView *view, dir_entry_t **entry, static int iter_entries(FileView *view, dir_entry_t **entry,
151 151 entry_predicate pred); entry_predicate pred);
152 152 static void clear_marking(FileView *view); static void clear_marking(FileView *view);
153 static int set_position_by_path(FileView *view, const char path[]);
153 154 static int flist_load_tree_internal(FileView *view, const char path[], static int flist_load_tree_internal(FileView *view, const char path[],
154 155 int reload); int reload);
155 156 static int make_tree(FileView *view, const char path[], int reload, static int make_tree(FileView *view, const char path[], int reload,
 
... ... navigate_to_file_in_custom_view(FileView *view, const char dir[],
392 393 const char file[]) const char file[])
393 394 { {
394 395 char full_path[PATH_MAX]; char full_path[PATH_MAX];
395 dir_entry_t *entry;
396 396
397 397 snprintf(full_path, sizeof(full_path), "%s/%s", dir, file); snprintf(full_path, sizeof(full_path), "%s/%s", dir, file);
398 398
399 399 if(custom_list_is_incomplete(view)) if(custom_list_is_incomplete(view))
400 400 { {
401 const dir_entry_t *entry;
401 402 entry = entry_from_path(view, view->local_filter.entries, entry = entry_from_path(view, view->local_filter.entries,
402 403 view->local_filter.entry_count, full_path); view->local_filter.entry_count, full_path);
403 404 if(entry == NULL) if(entry == NULL)
 
... ... navigate_to_file_in_custom_view(FileView *view, const char dir[],
414 415 } }
415 416 } }
416 417
417 entry = entry_from_path(view, view->dir_entry, view->list_rows, full_path);
418 if(entry == NULL)
418 if(set_position_by_path(view, full_path) != 0)
419 419 { {
420 420 /* File might not exist anymore at that location. */ /* File might not exist anymore at that location. */
421 421 return 1; return 1;
422 422 } }
423 423
424 view->list_pos = entry_to_pos(view, entry);
425 424 ui_view_schedule_redraw(view); ui_view_schedule_redraw(view);
426 425 return 0; return 0;
427 426 } }
 
... ... void
1387 1386 flist_goto_by_path(FileView *view, const char path[]) flist_goto_by_path(FileView *view, const char path[])
1388 1387 { {
1389 1388 char full_path[PATH_MAX]; char full_path[PATH_MAX];
1390 dir_entry_t *entry;
1391 1389 const char *const name = get_last_path_component(path); const char *const name = get_last_path_component(path);
1392 1390
1393 1391 get_current_full_path(view, sizeof(full_path), full_path); get_current_full_path(view, sizeof(full_path), full_path);
 
... ... flist_goto_by_path(FileView *view, const char path[])
1411 1409 return; return;
1412 1410 } }
1413 1411
1414 entry = entry_from_path(view, view->dir_entry, view->list_rows, path);
1415 if(entry != NULL)
1416 {
1417 view->list_pos = entry_to_pos(view, entry);
1418 }
1412 (void)set_position_by_path(view, path);
1419 1413 } }
1420 1414
1421 1415 dir_entry_t * dir_entry_t *
 
... ... flist_load_tree(FileView *view, const char path[])
3350 3344
3351 3345 if(full_path[0] != '\0') if(full_path[0] != '\0')
3352 3346 { {
3353 const dir_entry_t *entry;
3354 entry = entry_from_path(view, view->dir_entry, view->list_rows, full_path);
3355 if(entry != NULL)
3356 {
3357 view->list_pos = entry_to_pos(view, entry);
3358 }
3347 (void)set_position_by_path(view, full_path);
3359 3348 } }
3360 3349
3361 3350 ui_view_schedule_redraw(view); ui_view_schedule_redraw(view);
3362 3351 return 0; return 0;
3363 3352 } }
3364 3353
3354 /* Looks up entry by its path in main entry list of the view and updates cursor
3355 * position when such entry is found. Returns zero if position was updated,
3356 * otherwise non-zero is returned. */
3357 static int
3358 set_position_by_path(FileView *view, const char path[])
3359 {
3360 const dir_entry_t *entry;
3361 entry = entry_from_path(view, view->dir_entry, view->list_rows, path);
3362 if(entry != NULL)
3363 {
3364 view->list_pos = entry_to_pos(view, entry);
3365 return 0;
3366 }
3367 return 1;
3368 }
3369
3365 3370 int int
3366 3371 flist_clone_tree(FileView *to, const FileView *from) flist_clone_tree(FileView *to, const FileView *from)
3367 3372 { {
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/vifm

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/vifm

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master