Add mark all operation
This commit is contained in:
parent
fcab4e35dd
commit
b01b5a2279
1 changed files with 16 additions and 10 deletions
26
ccc.c
26
ccc.c
|
@ -26,7 +26,7 @@ typedef struct {
|
||||||
/* functions' definitions */
|
/* functions' definitions */
|
||||||
void change_dir(const char *buf);
|
void change_dir(const char *buf);
|
||||||
int mkdir_p(const char *destdir);
|
int mkdir_p(const char *destdir);
|
||||||
void populate_files(const char *path);
|
void populate_files(const char *path, int ftype);
|
||||||
int get_directory_size(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf);
|
int get_directory_size(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf);
|
||||||
long add_file_stat(char *filepath, int ftype);
|
long add_file_stat(char *filepath, int ftype);
|
||||||
void highlight_current_line();
|
void highlight_current_line();
|
||||||
|
@ -95,7 +95,7 @@ int main(int argc, char** argv)
|
||||||
cwd = memalloc(PATH_MAX * sizeof(char));
|
cwd = memalloc(PATH_MAX * sizeof(char));
|
||||||
getcwd(cwd, PATH_MAX);
|
getcwd(cwd, PATH_MAX);
|
||||||
|
|
||||||
populate_files(cwd);
|
populate_files(cwd, 0);
|
||||||
highlight_current_line();
|
highlight_current_line();
|
||||||
|
|
||||||
/* set window name */
|
/* set window name */
|
||||||
|
@ -138,7 +138,7 @@ int main(int argc, char** argv)
|
||||||
case 'l':;
|
case 'l':;
|
||||||
file *file = get_file(current_selection);
|
file *file = get_file(current_selection);
|
||||||
if (file != NULL) {
|
if (file != NULL) {
|
||||||
/* check if it is directory or regular file */
|
/* check if it is directory or a regular file */
|
||||||
if (strncmp(file->type, "DIR", 3) == 0) {
|
if (strncmp(file->type, "DIR", 3) == 0) {
|
||||||
/* change cwd to directory */
|
/* change cwd to directory */
|
||||||
change_dir(file->path);
|
change_dir(file->path);
|
||||||
|
@ -238,15 +238,21 @@ int main(int argc, char** argv)
|
||||||
case 'v':
|
case 'v':
|
||||||
dirs_size = !dirs_size;
|
dirs_size = !dirs_size;
|
||||||
clear_files();
|
clear_files();
|
||||||
populate_files(cwd);
|
populate_files(cwd, 0);
|
||||||
highlight_current_line();
|
highlight_current_line();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* mark files by space */
|
/* mark one file */
|
||||||
case SPACE:;
|
case SPACE:;
|
||||||
add_file_stat(get_filepath(current_selection), 1);
|
add_file_stat(get_filepath(current_selection), 1);
|
||||||
highlight_current_line();
|
highlight_current_line();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/* mark all files in directory */
|
||||||
|
case 'a':;
|
||||||
|
populate_files(cwd, 1);
|
||||||
|
change_dir(cwd); /* reload current dir */
|
||||||
|
break;
|
||||||
|
|
||||||
/* escape */
|
/* escape */
|
||||||
case ESC:
|
case ESC:
|
||||||
|
@ -276,7 +282,7 @@ void change_dir(const char *buf)
|
||||||
{
|
{
|
||||||
strcpy(cwd, buf);
|
strcpy(cwd, buf);
|
||||||
clear_files();
|
clear_files();
|
||||||
populate_files(cwd);
|
populate_files(cwd, 0);
|
||||||
current_selection = 0;
|
current_selection = 0;
|
||||||
highlight_current_line();
|
highlight_current_line();
|
||||||
}
|
}
|
||||||
|
@ -332,7 +338,7 @@ int mkdir_p(const char *destdir)
|
||||||
* Read the provided directory and add all files in directory to linked list
|
* Read the provided directory and add all files in directory to linked list
|
||||||
* ep->d_name -> filename
|
* ep->d_name -> filename
|
||||||
*/
|
*/
|
||||||
void populate_files(const char *path)
|
void populate_files(const char *path, int ftype)
|
||||||
{
|
{
|
||||||
DIR *dp;
|
DIR *dp;
|
||||||
struct dirent *ep;
|
struct dirent *ep;
|
||||||
|
@ -356,7 +362,7 @@ void populate_files(const char *path)
|
||||||
strcat(filename, "/");
|
strcat(filename, "/");
|
||||||
strcat(filename, ep->d_name); /* add filename */
|
strcat(filename, ep->d_name); /* add filename */
|
||||||
|
|
||||||
add_file_stat(filename, 0);
|
add_file_stat(filename, ftype);
|
||||||
}
|
}
|
||||||
free(filename);
|
free(filename);
|
||||||
}
|
}
|
||||||
|
@ -508,10 +514,10 @@ void highlight_current_line()
|
||||||
long num_marked = marked_len();
|
long num_marked = marked_len();
|
||||||
if (num_marked > 0) {
|
if (num_marked > 0) {
|
||||||
/* Determine length of formatted string */
|
/* Determine length of formatted string */
|
||||||
int m_len = snprintf(NULL, 0, "(%ld selected)", num_marked);
|
int m_len = snprintf(NULL, 0, "[%ld] selected", num_marked);
|
||||||
char *selected = memalloc((m_len + 1) * sizeof(char));
|
char *selected = memalloc((m_len + 1) * sizeof(char));
|
||||||
|
|
||||||
snprintf(selected, m_len + 1, "(%ld selected)", num_marked);
|
snprintf(selected, m_len + 1, "[%ld] selected", num_marked);
|
||||||
wprintw(panel, "(%ld/%ld) %s %s", current_selection + 1, files_len(), selected, cwd);
|
wprintw(panel, "(%ld/%ld) %s %s", current_selection + 1, files_len(), selected, cwd);
|
||||||
} else {
|
} else {
|
||||||
wprintw(panel, "(%ld/%ld) %s", current_selection + 1, files_len(), cwd);
|
wprintw(panel, "(%ld/%ld) %s", current_selection + 1, files_len(), cwd);
|
||||||
|
|
Loading…
Reference in a new issue