Warn if the passed parameter is not a valid project location.

Currently EDI can only open existing directories or create them - no single file mode
This commit is contained in:
Andy Williams 2014-10-22 22:41:23 +01:00
parent 50b9cd16f7
commit 95958caa31
3 changed files with 39 additions and 4 deletions

View File

@ -386,7 +386,11 @@ edi_open(const char *path)
Evas_Object *win, *vbx, *content, *tb; Evas_Object *win, *vbx, *content, *tb;
const char *winname; const char *winname;
edi_project_set(path); if (!edi_project_set(path))
{
fprintf(stderr, "Project path must be a directory\n");
return NULL;
}
elm_need_ethumb(); elm_need_ethumb();
elm_need_efreet(); elm_need_efreet();
@ -481,7 +485,7 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
if (args < argc) if (args < argc)
{ {
project_path = realpath(argv[args], NULL); project_path = argv[args];
} }
elm_app_info_set(elm_main, "edi", "images/edi.png"); elm_app_info_set(elm_main, "edi", "images/edi.png");

View File

@ -2,6 +2,7 @@
# define EDI_H_ # define EDI_H_
#include <Elementary.h> #include <Elementary.h>
#include <Eina.h>
#ifdef EAPI #ifdef EAPI
# undef EAPI # undef EAPI
@ -98,12 +99,15 @@ EAPI int edi_shutdown(void);
* @{ * @{
* *
* Set the current edi project that is loaded. * Set the current edi project that is loaded.
* Any directory is deemed a valid project.
* *
* @param path The path to the current project being loaded. * @param path The path to the current project being loaded.
* @return EINA_TRUE if the path represented a valid project,
* EINA_FALSE otherwise
* *
* @ingroup Main * @ingroup Main
*/ */
EAPI void edi_project_set(const char *path); EAPI Eina_Bool edi_project_set(const char *path);
/** /**
* Get the current edi project that is loaded. * Get the current edi project that is loaded.

View File

@ -2,6 +2,10 @@
# include "config.h" # include "config.h"
#endif #endif
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "Edi.h" #include "Edi.h"
#include "edi_private.h" #include "edi_private.h"
@ -58,13 +62,36 @@ edi_shutdown(void)
return _edi_init; return _edi_init;
} }
EAPI void static Eina_Bool
_edi_path_isdir(const char *path)
{
struct stat buf;
if (!path)
return EINA_FALSE;
stat(path, &buf);
return S_ISDIR(buf.st_mode);
}
EAPI Eina_Bool
edi_project_set(const char *path) edi_project_set(const char *path)
{ {
char *real = NULL;
real = realpath(real, NULL);
if (!_edi_path_isdir(path))
{
free(real);
return EINA_FALSE;
}
if (_edi_project_path) if (_edi_project_path)
eina_stringshare_del(_edi_project_path); eina_stringshare_del(_edi_project_path);
_edi_project_path = eina_stringshare_add(path); _edi_project_path = eina_stringshare_add(path);
free(real);
return EINA_TRUE;
} }
EAPI const char * EAPI const char *