Let the user choose a file to view himself when started with no argument
This commit is contained in:
parent
d253f3b442
commit
24cdf377d6
34
src/view.c
34
src/view.c
@ -55,6 +55,7 @@ typedef struct _View
|
|||||||
|
|
||||||
/* prototypes */
|
/* prototypes */
|
||||||
static View * _view_new(char const * path);
|
static View * _view_new(char const * path);
|
||||||
|
static View * _view_new_open(void);
|
||||||
static void _view_delete(View * view);
|
static void _view_delete(View * view);
|
||||||
|
|
||||||
/* useful */
|
/* useful */
|
||||||
@ -251,6 +252,29 @@ static GtkWidget * _new_text(View * view, char const * path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* view_new_open */
|
||||||
|
static View * _view_new_open(void)
|
||||||
|
{
|
||||||
|
View * ret;
|
||||||
|
GtkWidget * dialog;
|
||||||
|
char * pathname = NULL;
|
||||||
|
|
||||||
|
dialog = gtk_file_chooser_dialog_new("View file...", NULL,
|
||||||
|
GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL,
|
||||||
|
GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN,
|
||||||
|
GTK_RESPONSE_ACCEPT, NULL);
|
||||||
|
if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
|
||||||
|
pathname = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(
|
||||||
|
dialog));
|
||||||
|
gtk_widget_destroy(dialog);
|
||||||
|
if(pathname == NULL)
|
||||||
|
return NULL;
|
||||||
|
ret = _view_new(pathname);
|
||||||
|
free(pathname);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* view_delete */
|
/* view_delete */
|
||||||
static void _view_delete(View * view)
|
static void _view_delete(View * view)
|
||||||
{
|
{
|
||||||
@ -579,9 +603,11 @@ int main(int argc, char * argv[])
|
|||||||
return _usage();
|
return _usage();
|
||||||
}
|
}
|
||||||
if(optind == argc)
|
if(optind == argc)
|
||||||
return _usage();
|
_view_new_open();
|
||||||
for(i = optind; i < argc; i++)
|
else
|
||||||
_view_new(argv[i]);
|
for(i = optind; i < argc; i++)
|
||||||
gtk_main();
|
_view_new(argv[i]);
|
||||||
|
if(_view_cnt)
|
||||||
|
gtk_main();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user