editor: When in Editor Mode Open in Same Window.
This means when an exiting editor sessions is open (in non-project mode), Edi will open additional files within the same Edi session. Editor mode, is as a "ordinary" text editor. If there is a problem, a timeout will occur and Edi will open as normal. There shouldn't be a problem :/
This commit is contained in:
parent
9ddb932c09
commit
9d077bc19c
|
@ -52,6 +52,8 @@ static Evas_Object *_edi_menu_init, *_edi_menu_commit, *_edi_menu_push, *_edi_me
|
|||
static Evas_Object *_edi_main_win, *_edi_main_box;
|
||||
static Eina_Bool _edi_toolbar_is_horizontal, _edi_toolbar_text_visible;
|
||||
|
||||
static void *_edi_listener = NULL;
|
||||
|
||||
int _edi_log_dom = -1;
|
||||
|
||||
static void
|
||||
|
@ -1744,11 +1746,133 @@ _win_delete_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event
|
|||
edi_close();
|
||||
}
|
||||
|
||||
Evas_Object *edi_main_win_get(void)
|
||||
Evas_Object *
|
||||
edi_main_win_get(void)
|
||||
{
|
||||
return _edi_main_win;
|
||||
}
|
||||
|
||||
typedef struct _Edi_Listen_Server {
|
||||
Ecore_Event_Handler *handler;
|
||||
Ecore_Con_Server *srv;
|
||||
} Edi_Listen_Server;
|
||||
|
||||
static Eina_Bool
|
||||
_edi_listen_server_client_connect_cb(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
|
||||
{
|
||||
Ecore_Con_Event_Client_Data *ev;
|
||||
const char *path;
|
||||
|
||||
ev = event;
|
||||
path = ev->data;
|
||||
|
||||
edi_mainview_open_path(path);
|
||||
ecore_con_client_del(ev->client);
|
||||
|
||||
return ECORE_CALLBACK_RENEW;
|
||||
}
|
||||
|
||||
void
|
||||
edi_listen_shutdown(void)
|
||||
{
|
||||
Edi_Listen_Server *server = _edi_listener;
|
||||
if (!server) return;
|
||||
|
||||
ecore_event_handler_del(server->handler);
|
||||
ecore_con_server_del(server->srv);
|
||||
free(server);
|
||||
}
|
||||
|
||||
Eina_Bool
|
||||
edi_listen_init(void)
|
||||
{
|
||||
Edi_Listen_Server *server = calloc(1, sizeof(Edi_Listen_Server));
|
||||
if (!server) return EINA_FALSE;
|
||||
|
||||
server->srv = ecore_con_server_add(ECORE_CON_LOCAL_USER, "listener", 0, NULL);
|
||||
if (!server->srv) return EINA_FALSE;
|
||||
|
||||
server->handler = ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DATA, _edi_listen_server_client_connect_cb, NULL);
|
||||
_edi_listener = server;
|
||||
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
typedef struct Edi_Listen_Client {
|
||||
char *path;
|
||||
Eina_Bool success;
|
||||
} Edi_Listen_Client;
|
||||
|
||||
static Eina_Bool
|
||||
_edi_listen_client_closed_cb(void *data, int type EINA_UNUSED, void *ev EINA_UNUSED)
|
||||
{
|
||||
Edi_Listen_Client *client = data;
|
||||
|
||||
client->success = EINA_TRUE;
|
||||
|
||||
return ECORE_CALLBACK_RENEW;
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_edi_listen_client_check_timer_cb(void *data EINA_UNUSED)
|
||||
{
|
||||
Edi_Listen_Client *client;
|
||||
static double total = 0.0;
|
||||
|
||||
client = data;
|
||||
total += 0.1;
|
||||
|
||||
if (total < 3.0)
|
||||
return ECORE_CALLBACK_RENEW;
|
||||
|
||||
if (client->success)
|
||||
ecore_main_loop_quit();
|
||||
else
|
||||
evas_object_show(edi_main_win_get());
|
||||
|
||||
return ECORE_CALLBACK_DONE;
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_edi_listen_client_connect_cb(void *data, int type EINA_UNUSED, void *event EINA_UNUSED)
|
||||
{
|
||||
Ecore_Con_Event_Server_Add *ev;
|
||||
Ecore_Con_Server *srv;
|
||||
Edi_Listen_Client *client;
|
||||
|
||||
ev = event;
|
||||
srv = ev->server;
|
||||
client = data;
|
||||
|
||||
ecore_con_server_send(srv, client->path, 1 + strlen(client->path));
|
||||
ecore_con_server_flush(srv);
|
||||
|
||||
return ECORE_CALLBACK_DONE;
|
||||
}
|
||||
|
||||
Eina_Bool
|
||||
edi_listen_client_add(char *path)
|
||||
{
|
||||
Edi_Listen_Client *client;
|
||||
Ecore_Con_Server *srv = ecore_con_server_connect(ECORE_CON_LOCAL_USER, "listener", 0, NULL);
|
||||
if (!srv)
|
||||
{
|
||||
free(path);
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
client = calloc(1, sizeof(Edi_Listen_Client));
|
||||
if (!client) return EINA_FALSE;
|
||||
|
||||
client->path = path;
|
||||
|
||||
ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, _edi_listen_client_connect_cb, client);
|
||||
ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DEL, _edi_listen_client_closed_cb, client);
|
||||
ecore_timer_add(0.1, _edi_listen_client_check_timer_cb, client);
|
||||
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
Eina_Bool
|
||||
edi_open(const char *inputpath)
|
||||
{
|
||||
|
@ -1756,6 +1880,7 @@ edi_open(const char *inputpath)
|
|||
Evas_Object *vbx_tb, *hbx_tb;
|
||||
char *winname;
|
||||
char *path;
|
||||
Eina_Bool show = EINA_TRUE;
|
||||
|
||||
edi_project_mode_set(EINA_TRUE);
|
||||
|
||||
|
@ -1763,6 +1888,14 @@ edi_open(const char *inputpath)
|
|||
{
|
||||
edi_project_set(eina_environment_home_get());
|
||||
edi_project_mode_set(EINA_FALSE);
|
||||
|
||||
path = realpath(inputpath, NULL);
|
||||
if (!path) return EINA_FALSE;
|
||||
|
||||
if (!edi_listen_client_add(path))
|
||||
edi_listen_init();
|
||||
else
|
||||
show = EINA_FALSE;
|
||||
}
|
||||
|
||||
path = realpath(inputpath, NULL);
|
||||
|
@ -1856,7 +1989,8 @@ edi_open(const char *inputpath)
|
|||
ERR("Loaded project at %s", path);
|
||||
evas_object_resize(win, _edi_project_config->gui.width * elm_config_scale_get(),
|
||||
_edi_project_config->gui.height * elm_config_scale_get());
|
||||
evas_object_show(win);
|
||||
if (show)
|
||||
evas_object_show(win);
|
||||
|
||||
if (!edi_project_mode_get())
|
||||
{
|
||||
|
@ -2039,6 +2173,7 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
|
|||
|
||||
end:
|
||||
_edi_log_shutdown();
|
||||
edi_listen_shutdown();
|
||||
elm_shutdown();
|
||||
edi_scm_shutdown();
|
||||
edi_shutdown();
|
||||
|
|
Loading…
Reference in New Issue