Fixed path completion

This commit is contained in:
Moritz Lipp 2009-12-28 17:14:23 +01:00
parent 414d3304d1
commit 92c59f4548

View File

@ -341,16 +341,13 @@ change_mode(int mode)
{ {
case INSERT: case INSERT:
mode_text = "-- INSERT --"; mode_text = "-- INSERT --";
gtk_editable_set_editable( GTK_EDITABLE(Zathura.UI.inputbar), FALSE);
break; break;
case VISUAL: case VISUAL:
mode_text = "-- VISUAL --"; mode_text = "-- VISUAL --";
gtk_editable_set_editable( GTK_EDITABLE(Zathura.UI.inputbar), FALSE);
break; break;
default: default:
mode_text = ""; mode_text = "";
mode = NORMAL; mode = NORMAL;
gtk_editable_set_editable( GTK_EDITABLE(Zathura.UI.inputbar), TRUE);
break; break;
} }
@ -378,8 +375,6 @@ void notify(int level, char* message)
if(message) if(message)
gtk_entry_set_text(Zathura.UI.inputbar, message); gtk_entry_set_text(Zathura.UI.inputbar, message);
gtk_editable_set_editable( GTK_EDITABLE(Zathura.UI.inputbar), FALSE);
} }
void void
@ -523,7 +518,6 @@ sc_focus_inputbar(Argument* argument)
notify(DEFAULT, argument->data); notify(DEFAULT, argument->data);
gtk_widget_grab_focus(GTK_WIDGET(Zathura.UI.inputbar)); gtk_widget_grab_focus(GTK_WIDGET(Zathura.UI.inputbar));
gtk_editable_set_position(GTK_EDITABLE(Zathura.UI.inputbar), -1); gtk_editable_set_position(GTK_EDITABLE(Zathura.UI.inputbar), -1);
gtk_editable_set_editable( GTK_EDITABLE(Zathura.UI.inputbar), TRUE);
} }
} }
@ -994,48 +988,51 @@ Completion* cc_open(char* input)
completion->groups = group; completion->groups = group;
/* read dir */ /* read dir */
char* path; char* path = "/";
char* file; char* file = "";
int file_length; int file_length = 0;
if(!input || strlen(input) == 0) /* parse input string */
if(input && strlen(input) > 0)
{ {
path = "/"; char* path_temp = dirname(strdup(input));
char* file_temp = basename(strdup(input));
char last_char = input[strlen(input) - 1];
if( !strcmp(path_temp, "/") && !strcmp(file_temp, "/") )
file = ""; file = "";
} else if( !strcmp(path_temp, "/") && strcmp(file_temp, "/") && last_char != '/')
file = file_temp;
else if( !strcmp(path_temp, "/") && strcmp(file_temp, "/") && last_char == '/')
path = g_strdup_printf("/%s/", file_temp);
else if(last_char == '/')
path = input;
else else
{ {
path = dirname(strdup(input)); path = g_strdup_printf("%s/", path_temp);
file = basename(strdup(input)); file = file_temp;
if(!strcmp(path, "/") && strlen(file) > 1)
{
path = g_strdup_printf("/%s/", file);
file = "";
}
else if(!strcmp(path, "/") && !strcmp(file, "/"))
{
path = "/";
file = "";
} }
} }
file_length = strlen(file); file_length = strlen(file);
/* open directory */
GDir* dir = g_dir_open(path, 0, NULL); GDir* dir = g_dir_open(path, 0, NULL);
if(!dir) if(!dir)
return NULL; return NULL;
char* name;
int element_counter = 0;
CompletionElement *last_element = NULL;
/* create element list */ /* create element list */
CompletionElement *last_element = NULL;
char* name = NULL;
int element_counter = 0;
while((name = (char*) g_dir_read_name(dir)) != NULL) while((name = (char*) g_dir_read_name(dir)) != NULL)
{ {
char* d_name = g_filename_display_name(name); char* d_name = g_filename_display_name(name);
int d_length = strlen(name); int d_length = strlen(name);
if( (file_length <= d_length) && !strncmp(file, d_name, file_length) )
if( ((file_length <= d_length) && !strncmp(file, d_name, file_length)) ||
(file_length == 0) )
{ {
CompletionElement* el = malloc(sizeof(CompletionElement)); CompletionElement* el = malloc(sizeof(CompletionElement));
el->value = g_strdup_printf("%s%s", path, d_name); el->value = g_strdup_printf("%s%s", path, d_name);
@ -1056,6 +1053,7 @@ Completion* cc_open(char* input)
return completion; return completion;
} }
/* buffer command implementation */ /* buffer command implementation */
void void
bcmd_goto(char* buffer, Argument* argument) bcmd_goto(char* buffer, Argument* argument)