2014-02-15 15:17:40 -08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <libgen.h>
|
|
|
|
|
|
|
|
#include <Eina.h>
|
2014-02-15 16:29:00 -08:00
|
|
|
#include <Eio.h>
|
2014-02-15 15:17:40 -08:00
|
|
|
|
2014-09-13 08:48:16 -07:00
|
|
|
#include "mainview/edi_mainview_item.h"
|
|
|
|
#include "mainview/edi_mainview.h"
|
2014-02-15 15:17:40 -08:00
|
|
|
|
2014-05-15 14:40:19 -07:00
|
|
|
#include "editor/edi_editor.h"
|
2014-11-28 15:34:36 -08:00
|
|
|
#include "edi_content_provider.h"
|
2014-05-15 14:40:19 -07:00
|
|
|
|
2014-02-15 15:17:40 -08:00
|
|
|
#include "edi_private.h"
|
2015-02-07 00:13:40 -08:00
|
|
|
#include "edi_config.h"
|
2014-02-15 15:17:40 -08:00
|
|
|
|
2016-09-10 14:28:31 -07:00
|
|
|
static Evas_Object *_content_frame, *_current_view, *tb, *_main_win, *_welcome_panel;
|
2015-07-16 14:36:15 -07:00
|
|
|
static Evas_Object *_edi_mainview_choose_popup, *_edi_mainview_goto_popup;
|
2014-03-16 09:01:35 -07:00
|
|
|
static Edi_Path_Options *_edi_mainview_choose_options;
|
2014-02-15 15:17:40 -08:00
|
|
|
|
2014-03-13 11:31:24 -07:00
|
|
|
static Eina_List *_edi_mainview_items = NULL;
|
|
|
|
|
2014-02-15 16:29:00 -08:00
|
|
|
static void
|
|
|
|
dummy()
|
|
|
|
{}
|
|
|
|
|
2015-01-10 09:43:12 -08:00
|
|
|
Edi_Mainview_Item *
|
2014-09-13 08:48:16 -07:00
|
|
|
edi_mainview_item_current_get()
|
|
|
|
{
|
|
|
|
Eina_List *item;
|
|
|
|
Edi_Mainview_Item *it;
|
|
|
|
|
|
|
|
EINA_LIST_FOREACH(_edi_mainview_items, item, it)
|
|
|
|
{
|
2016-09-10 14:28:31 -07:00
|
|
|
if (it && it->view == _current_view)
|
2014-09-13 08:48:16 -07:00
|
|
|
{
|
|
|
|
return it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-09-10 14:28:31 -07:00
|
|
|
static void
|
|
|
|
_edi_mainview_view_show(Evas_Object *view)
|
|
|
|
{
|
|
|
|
elm_box_unpack(_content_frame, _current_view);
|
|
|
|
evas_object_hide(_current_view);
|
|
|
|
|
|
|
|
_current_view = view;
|
|
|
|
elm_box_pack_end(_content_frame, view);
|
|
|
|
evas_object_show(view);
|
|
|
|
}
|
|
|
|
|
2015-01-10 09:43:12 -08:00
|
|
|
void
|
2014-05-15 14:40:19 -07:00
|
|
|
edi_mainview_item_prev()
|
2014-03-26 09:48:21 -07:00
|
|
|
{
|
|
|
|
Eina_List *item;
|
2015-02-08 13:38:46 -08:00
|
|
|
Edi_Mainview_Item *it, *first, *prev = NULL;
|
2014-03-26 09:48:21 -07:00
|
|
|
|
2015-02-08 13:38:46 -08:00
|
|
|
first = (Edi_Mainview_Item *)eina_list_nth(_edi_mainview_items, 0);
|
2016-09-10 14:28:31 -07:00
|
|
|
if (first->view == _current_view)
|
2016-02-15 16:16:34 -08:00
|
|
|
{
|
|
|
|
prev = eina_list_nth(_edi_mainview_items, eina_list_count(_edi_mainview_items)-1);
|
|
|
|
edi_mainview_item_select(prev);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-26 09:48:21 -07:00
|
|
|
EINA_LIST_FOREACH(_edi_mainview_items, item, it)
|
|
|
|
{
|
2016-09-10 14:28:31 -07:00
|
|
|
if (it && it->view == _current_view)
|
2014-03-26 09:48:21 -07:00
|
|
|
{
|
2014-11-29 12:00:45 -08:00
|
|
|
if (prev)
|
|
|
|
edi_mainview_item_select(prev);
|
2014-03-26 09:48:21 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
prev = it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-10 09:43:12 -08:00
|
|
|
void
|
2014-05-15 14:40:19 -07:00
|
|
|
edi_mainview_item_next()
|
2014-03-26 09:48:21 -07:00
|
|
|
{
|
|
|
|
Eina_List *item;
|
2015-02-08 13:38:46 -08:00
|
|
|
Edi_Mainview_Item *it, *last, *next;
|
2014-03-26 09:48:21 -07:00
|
|
|
Eina_Bool open_next = EINA_FALSE;
|
|
|
|
|
2015-02-08 13:38:46 -08:00
|
|
|
last = eina_list_nth(_edi_mainview_items, eina_list_count(_edi_mainview_items)-1);
|
2014-03-26 09:48:21 -07:00
|
|
|
|
2016-09-10 14:28:31 -07:00
|
|
|
if (last->view == _current_view)
|
2016-02-15 16:16:34 -08:00
|
|
|
{
|
|
|
|
next = eina_list_nth(_edi_mainview_items, 0);
|
|
|
|
edi_mainview_item_select(next);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-26 09:48:21 -07:00
|
|
|
EINA_LIST_FOREACH(_edi_mainview_items, item, it)
|
|
|
|
{
|
2016-02-15 16:16:34 -08:00
|
|
|
|
2014-03-26 09:48:21 -07:00
|
|
|
if (it && open_next)
|
|
|
|
{
|
|
|
|
edi_mainview_item_select(it);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-10 14:28:31 -07:00
|
|
|
if (it && it->view == _current_view)
|
2014-03-26 09:48:21 -07:00
|
|
|
open_next = EINA_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-10 09:43:12 -08:00
|
|
|
void
|
2014-03-26 09:48:21 -07:00
|
|
|
edi_mainview_item_select(Edi_Mainview_Item *item)
|
|
|
|
{
|
|
|
|
if (item->win)
|
|
|
|
{
|
|
|
|
elm_win_raise(item->win);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-09-10 14:28:31 -07:00
|
|
|
_edi_mainview_view_show(item->view);
|
2014-03-26 09:48:21 -07:00
|
|
|
elm_toolbar_item_selected_set(item->tab, EINA_TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-15 15:17:40 -08:00
|
|
|
static void
|
|
|
|
_promote(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
|
|
|
{
|
2016-09-10 14:28:31 -07:00
|
|
|
_edi_mainview_view_show(data);
|
2014-02-15 15:17:40 -08:00
|
|
|
}
|
|
|
|
|
2014-02-26 01:13:28 -08:00
|
|
|
static Edi_Mainview_Item *
|
2014-02-15 16:29:00 -08:00
|
|
|
_get_item_for_path(const char *path)
|
|
|
|
{
|
2014-03-13 11:31:24 -07:00
|
|
|
Eina_List *item;
|
|
|
|
Edi_Mainview_Item *it;
|
2014-02-15 16:31:10 -08:00
|
|
|
|
2014-03-13 11:31:24 -07:00
|
|
|
EINA_LIST_FOREACH(_edi_mainview_items, item, it)
|
2014-02-15 16:29:00 -08:00
|
|
|
{
|
2014-03-13 11:31:24 -07:00
|
|
|
if (it && !strcmp(it->path, path))
|
|
|
|
return it;
|
2014-02-15 16:29:00 -08:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-02-26 01:13:28 -08:00
|
|
|
static Edi_Mainview_Item *
|
2014-09-13 08:48:16 -07:00
|
|
|
_edi_mainview_item_add(Edi_Path_Options *path, const char *mime, Elm_Object_Item *tab, Elm_Object_Item *view,
|
2014-03-13 11:31:24 -07:00
|
|
|
Evas_Object *win)
|
2014-02-26 01:13:28 -08:00
|
|
|
{
|
|
|
|
Edi_Mainview_Item *item;
|
|
|
|
|
|
|
|
item = malloc(sizeof(Edi_Mainview_Item));
|
2015-05-18 07:45:28 -07:00
|
|
|
item->path = eina_stringshare_add(path->path);
|
2014-09-13 08:48:16 -07:00
|
|
|
item->editortype = path->type;
|
|
|
|
item->mimetype = mime;
|
2014-02-26 01:13:28 -08:00
|
|
|
item->tab = tab;
|
|
|
|
item->view = view;
|
2014-03-13 11:31:24 -07:00
|
|
|
item->win = win;
|
|
|
|
|
|
|
|
_edi_mainview_items = eina_list_append(_edi_mainview_items, item);
|
2014-02-26 01:13:28 -08:00
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2014-03-13 11:31:24 -07:00
|
|
|
static Evas_Object *
|
2014-09-13 08:48:16 -07:00
|
|
|
_edi_mainview_content_create(Edi_Mainview_Item *item, Evas_Object *parent)
|
2014-03-13 11:31:24 -07:00
|
|
|
{
|
2014-11-28 15:34:36 -08:00
|
|
|
Edi_Content_Provider *provider;
|
2014-03-13 11:31:24 -07:00
|
|
|
|
2014-11-28 15:34:36 -08:00
|
|
|
provider = edi_content_provider_for_id_get(item->editortype);
|
|
|
|
if (!provider)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return provider->content_ui_add(parent, item);
|
2014-03-13 11:31:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-09-13 08:48:16 -07:00
|
|
|
_edi_mainview_item_tab_add(Edi_Path_Options *options, const char *mime)
|
2014-03-13 11:31:24 -07:00
|
|
|
{
|
2016-09-11 06:00:31 -07:00
|
|
|
Evas_Object *content, *tab, *icon;
|
2014-03-13 11:31:24 -07:00
|
|
|
Edi_Mainview_Item *item;
|
2015-01-30 07:39:54 -08:00
|
|
|
Edi_Editor *editor;
|
2016-01-16 10:22:30 -08:00
|
|
|
Edi_Content_Provider *provider;
|
2014-03-13 11:31:24 -07:00
|
|
|
|
2014-09-13 08:48:16 -07:00
|
|
|
item = _edi_mainview_item_add(options, mime, NULL, NULL, NULL);
|
2016-01-16 10:22:30 -08:00
|
|
|
provider = edi_content_provider_for_id_get(item->editortype);
|
2016-09-10 14:28:31 -07:00
|
|
|
content = _edi_mainview_content_create(item, _content_frame);
|
2014-03-16 09:01:35 -07:00
|
|
|
|
2016-09-10 14:28:31 -07:00
|
|
|
_edi_mainview_view_show(content);
|
|
|
|
item->view = content;
|
2015-03-23 15:36:29 -07:00
|
|
|
|
2016-09-11 06:00:31 -07:00
|
|
|
tab = elm_button_add(tb);
|
|
|
|
evas_object_size_hint_weight_set(tab, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
|
|
|
evas_object_size_hint_align_set(tab, 0.0, EVAS_HINT_FILL);
|
|
|
|
|
|
|
|
elm_object_text_set(tab, basename((char*)options->path));
|
|
|
|
icon = elm_icon_add(tab);
|
|
|
|
elm_icon_standard_set(icon, provider->icon);
|
|
|
|
elm_object_part_content_set(tab, "icon", icon);
|
|
|
|
evas_object_smart_callback_add(tab, "clicked", _promote, content);
|
|
|
|
|
|
|
|
elm_box_pack_end(tb, tab);
|
|
|
|
evas_object_show(tab);
|
2014-09-13 08:48:16 -07:00
|
|
|
item->tab = tab;
|
2014-02-21 16:16:56 -08:00
|
|
|
elm_toolbar_item_selected_set(tab, EINA_TRUE);
|
2014-02-26 01:13:28 -08:00
|
|
|
|
2015-01-30 07:39:54 -08:00
|
|
|
// Set focus on the newly opening window so that one can just start typing
|
|
|
|
editor = (Edi_Editor *)evas_object_data_get(content, "editor");
|
|
|
|
if (editor)
|
|
|
|
elm_object_focus_set(editor->entry, EINA_TRUE);
|
|
|
|
|
2015-03-23 15:36:29 -07:00
|
|
|
if (options->line)
|
|
|
|
edi_mainview_goto(options->line);
|
2015-09-16 02:21:21 -07:00
|
|
|
|
|
|
|
_edi_project_config_tab_add(options->path, EINA_FALSE);
|
2014-02-21 16:16:56 -08:00
|
|
|
}
|
|
|
|
|
2014-03-13 11:31:24 -07:00
|
|
|
static void
|
|
|
|
_edi_mainview_win_exit(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Edi_Mainview_Item *it;
|
|
|
|
|
|
|
|
evas_object_hide(obj);
|
|
|
|
|
|
|
|
it = evas_object_data_get(obj, "edi_mainview_item");
|
|
|
|
_edi_mainview_items = eina_list_remove(_edi_mainview_items, it);
|
2015-05-18 08:32:46 -07:00
|
|
|
|
|
|
|
_edi_project_config_tab_remove(it->path);
|
2014-03-31 14:24:56 -07:00
|
|
|
eina_stringshare_del(it->path);
|
2016-07-03 13:06:22 -07:00
|
|
|
|
|
|
|
if (edi_noproject())
|
|
|
|
edi_close();
|
2014-03-13 11:31:24 -07:00
|
|
|
free(it);
|
|
|
|
}
|
|
|
|
|
2014-03-13 11:48:28 -07:00
|
|
|
static char *
|
|
|
|
_edi_mainview_win_title_get(const char *path)
|
|
|
|
{
|
|
|
|
char *winname, *filename;
|
|
|
|
|
2014-10-22 12:08:57 -07:00
|
|
|
filename = basename((char*)path);
|
2014-03-13 11:48:28 -07:00
|
|
|
winname = malloc((8 + strlen(filename)) * sizeof(char));
|
|
|
|
snprintf(winname, 8 + strlen(filename), "Edi :: %s", filename);
|
|
|
|
|
|
|
|
return winname;
|
|
|
|
}
|
|
|
|
|
2014-03-13 11:31:24 -07:00
|
|
|
static void
|
2014-09-13 08:48:16 -07:00
|
|
|
_edi_mainview_item_win_add(Edi_Path_Options *options, const char *mime)
|
2014-03-13 11:31:24 -07:00
|
|
|
{
|
|
|
|
Evas_Object *win, *content;
|
|
|
|
Edi_Mainview_Item *item;
|
2015-01-30 07:39:54 -08:00
|
|
|
Edi_Editor *editor;
|
2014-03-13 11:31:24 -07:00
|
|
|
|
2014-03-16 09:01:35 -07:00
|
|
|
win = elm_win_util_standard_add("mainview", _edi_mainview_win_title_get(options->path));
|
2014-03-13 11:31:24 -07:00
|
|
|
if (!win) return;
|
|
|
|
|
|
|
|
elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
|
|
|
|
evas_object_smart_callback_add(win, "delete,request", _edi_mainview_win_exit, NULL);
|
2014-09-13 08:48:16 -07:00
|
|
|
item = _edi_mainview_item_add(options, mime, NULL, NULL, win);
|
2014-03-13 11:31:24 -07:00
|
|
|
evas_object_data_set(win, "edi_mainview_item", item);
|
|
|
|
|
2014-09-13 08:48:16 -07:00
|
|
|
content = _edi_mainview_content_create(item, win);
|
2014-03-13 11:31:24 -07:00
|
|
|
elm_win_resize_object_add(win, content);
|
|
|
|
|
2015-01-30 07:39:54 -08:00
|
|
|
// Set focus on the newly opening window so that one can just start typing
|
|
|
|
editor = (Edi_Editor *)evas_object_data_get(content, "editor");
|
|
|
|
if (editor)
|
|
|
|
elm_object_focus_set(editor->entry, EINA_TRUE);
|
|
|
|
|
2014-05-19 15:52:50 -07:00
|
|
|
evas_object_resize(win, 380 * elm_config_scale_get(), 260 * elm_config_scale_get());
|
2014-03-13 11:31:24 -07:00
|
|
|
evas_object_show(win);
|
2015-09-16 02:21:21 -07:00
|
|
|
|
|
|
|
_edi_project_config_tab_add(options->path, EINA_TRUE);
|
2014-03-13 11:31:24 -07:00
|
|
|
}
|
|
|
|
|
2014-03-14 03:30:36 -07:00
|
|
|
static void
|
|
|
|
_edi_mainview_choose_type_tab_cb(void *data,
|
|
|
|
Evas_Object *obj EINA_UNUSED,
|
|
|
|
void *event_info EINA_UNUSED)
|
|
|
|
{
|
|
|
|
evas_object_del(_edi_mainview_choose_popup);
|
|
|
|
|
2014-03-16 09:01:35 -07:00
|
|
|
_edi_mainview_choose_options->type = (const char *) data;
|
2015-02-07 00:13:40 -08:00
|
|
|
_edi_config_mime_add(efreet_mime_type_get(_edi_mainview_choose_options->path), _edi_mainview_choose_options->type);
|
2014-03-16 09:01:35 -07:00
|
|
|
edi_mainview_open(_edi_mainview_choose_options);
|
2014-03-14 03:30:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_edi_mainview_choose_type_win_cb(void *data,
|
|
|
|
Evas_Object *obj EINA_UNUSED,
|
|
|
|
void *event_info EINA_UNUSED)
|
|
|
|
{
|
|
|
|
evas_object_del(_edi_mainview_choose_popup);
|
2014-03-16 09:01:35 -07:00
|
|
|
|
|
|
|
_edi_mainview_choose_options->type = (const char *) data;
|
2015-02-07 00:13:40 -08:00
|
|
|
_edi_config_mime_add(efreet_mime_type_get(_edi_mainview_choose_options->path), _edi_mainview_choose_options->type);
|
2014-03-16 09:01:35 -07:00
|
|
|
edi_mainview_open_window(_edi_mainview_choose_options);
|
2014-03-14 03:30:36 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_edi_mainview_choose_type_close_cb(void *data EINA_UNUSED,
|
|
|
|
Evas_Object *obj EINA_UNUSED,
|
|
|
|
void *event_info EINA_UNUSED)
|
|
|
|
{
|
|
|
|
evas_object_del(_edi_mainview_choose_popup);
|
|
|
|
}
|
|
|
|
|
2016-09-10 14:28:31 -07:00
|
|
|
static void
|
|
|
|
_edi_mainview_item_close(Edi_Mainview_Item *item)
|
|
|
|
{
|
|
|
|
if (!item)
|
|
|
|
return;
|
|
|
|
|
|
|
|
edi_mainview_item_prev();
|
|
|
|
evas_object_del(item->view);
|
2016-09-11 06:00:31 -07:00
|
|
|
evas_object_del(item->tab);
|
2016-09-10 14:28:31 -07:00
|
|
|
_edi_mainview_items = eina_list_remove(_edi_mainview_items, item);
|
|
|
|
|
|
|
|
_edi_project_config_tab_remove(item->path);
|
|
|
|
eina_stringshare_del(item->path);
|
|
|
|
free(item);
|
|
|
|
|
|
|
|
if (eina_list_count(_edi_mainview_items) == 0)
|
|
|
|
_edi_mainview_view_show(_welcome_panel);
|
|
|
|
}
|
|
|
|
|
2015-02-22 06:17:51 -08:00
|
|
|
static void
|
|
|
|
_edi_mainview_filetype_create(Evas_Object *popup, const char *type, void *cb)
|
|
|
|
{
|
|
|
|
Edi_Content_Provider *provider;
|
|
|
|
Evas_Object *icon;
|
|
|
|
|
|
|
|
provider = edi_content_provider_for_id_get(type);
|
|
|
|
if (!provider)
|
|
|
|
return;
|
|
|
|
|
|
|
|
icon = elm_icon_add(popup);
|
|
|
|
elm_icon_standard_set(icon, provider->icon);
|
|
|
|
elm_popup_item_append(popup, type, icon, cb, type);
|
|
|
|
}
|
|
|
|
|
2014-03-14 03:30:36 -07:00
|
|
|
static void
|
2014-05-19 11:19:12 -07:00
|
|
|
_edi_mainview_choose_type(Evas_Object *parent EINA_UNUSED, Edi_Path_Options *options, void *cb)
|
2014-03-14 03:30:36 -07:00
|
|
|
{
|
2015-02-22 06:17:51 -08:00
|
|
|
Evas_Object *popup, *cancel;
|
2014-03-14 03:30:36 -07:00
|
|
|
|
2014-03-14 06:44:09 -07:00
|
|
|
popup = elm_popup_add(_main_win);
|
2014-03-14 03:30:36 -07:00
|
|
|
_edi_mainview_choose_popup = popup;
|
2014-03-16 09:01:35 -07:00
|
|
|
_edi_mainview_choose_options = options;
|
2014-03-14 03:30:36 -07:00
|
|
|
|
|
|
|
// popup title
|
|
|
|
elm_object_part_text_set(popup, "title,text",
|
2015-09-16 02:21:21 -07:00
|
|
|
"Unrecognised file type");
|
2014-03-14 03:30:36 -07:00
|
|
|
|
2015-02-22 06:17:51 -08:00
|
|
|
_edi_mainview_filetype_create(popup, "text", cb);
|
|
|
|
_edi_mainview_filetype_create(popup, "code", cb);
|
|
|
|
_edi_mainview_filetype_create(popup, "image", cb);
|
2014-03-14 03:30:36 -07:00
|
|
|
|
|
|
|
cancel = elm_button_add(popup);
|
|
|
|
elm_object_text_set(cancel, "cancel");
|
|
|
|
elm_object_part_content_set(popup, "button1", cancel);
|
|
|
|
evas_object_smart_callback_add(cancel, "clicked",
|
|
|
|
_edi_mainview_choose_type_close_cb, NULL);
|
|
|
|
|
|
|
|
evas_object_show(popup);
|
|
|
|
}
|
|
|
|
|
2014-03-13 11:31:24 -07:00
|
|
|
static void
|
|
|
|
_edi_mainview_tab_stat_done(void *data, Eio_File *handler EINA_UNUSED, const Eina_Stat *stat)
|
|
|
|
{
|
2014-03-16 09:01:35 -07:00
|
|
|
Edi_Path_Options *options;
|
2014-11-28 15:34:36 -08:00
|
|
|
Edi_Content_Provider *provider;
|
2014-03-16 09:01:35 -07:00
|
|
|
const char *mime;
|
2014-03-13 11:31:24 -07:00
|
|
|
|
2014-03-16 09:01:35 -07:00
|
|
|
options = data;
|
2030-07-09 16:04:01 -07:00
|
|
|
if (!S_ISREG(stat->mode))
|
|
|
|
return;
|
|
|
|
|
|
|
|
mime = efreet_mime_type_get(options->path);
|
2014-11-28 15:34:36 -08:00
|
|
|
provider = edi_content_provider_for_mime_get(mime);
|
|
|
|
if (!provider)
|
2014-03-13 11:31:24 -07:00
|
|
|
{
|
2016-09-10 14:28:31 -07:00
|
|
|
_edi_mainview_choose_type(_content_frame, options, _edi_mainview_choose_type_tab_cb);
|
2030-07-09 16:04:01 -07:00
|
|
|
return;
|
2014-03-13 11:31:24 -07:00
|
|
|
}
|
|
|
|
|
2014-11-28 15:34:36 -08:00
|
|
|
options->type = provider->id;
|
2014-09-13 08:48:16 -07:00
|
|
|
_edi_mainview_item_tab_add(options, mime);
|
2014-03-13 11:31:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_edi_mainview_win_stat_done(void *data, Eio_File *handler EINA_UNUSED, const Eina_Stat *stat)
|
2014-02-15 16:29:00 -08:00
|
|
|
{
|
2014-03-16 09:01:35 -07:00
|
|
|
Edi_Path_Options *options;
|
2014-11-28 15:34:36 -08:00
|
|
|
Edi_Content_Provider *provider;
|
2014-03-16 09:01:35 -07:00
|
|
|
const char *mime;
|
2014-02-15 16:31:10 -08:00
|
|
|
|
2014-03-16 09:01:35 -07:00
|
|
|
options = data;
|
2030-07-09 16:04:01 -07:00
|
|
|
if (!S_ISREG(stat->mode))
|
|
|
|
return;
|
|
|
|
|
|
|
|
mime = efreet_mime_type_get(options->path);
|
2014-11-28 15:34:36 -08:00
|
|
|
provider = edi_content_provider_for_mime_get(mime);
|
|
|
|
if (!provider)
|
2014-02-15 16:29:00 -08:00
|
|
|
{
|
2016-09-10 14:28:31 -07:00
|
|
|
_edi_mainview_choose_type(_content_frame, options, _edi_mainview_choose_type_win_cb);
|
2030-07-09 16:04:01 -07:00
|
|
|
return;
|
2014-02-15 16:29:00 -08:00
|
|
|
}
|
2014-02-15 16:31:10 -08:00
|
|
|
|
2014-11-28 15:34:36 -08:00
|
|
|
options->type = provider->id;
|
2014-09-13 08:48:16 -07:00
|
|
|
_edi_mainview_item_win_add(options, mime);
|
2014-02-15 16:29:00 -08:00
|
|
|
}
|
|
|
|
|
2015-01-10 09:43:12 -08:00
|
|
|
void
|
2014-03-16 09:01:35 -07:00
|
|
|
edi_mainview_open_path(const char *path)
|
2014-02-25 23:28:24 -08:00
|
|
|
{
|
2014-03-16 09:01:35 -07:00
|
|
|
Edi_Path_Options *options;
|
2014-02-25 23:28:24 -08:00
|
|
|
|
2014-03-16 09:01:35 -07:00
|
|
|
options = edi_path_options_create(path);
|
2015-06-09 14:31:33 -07:00
|
|
|
edi_mainview_open(options);
|
2014-03-16 09:01:35 -07:00
|
|
|
}
|
|
|
|
|
2015-01-10 09:43:12 -08:00
|
|
|
void
|
2014-03-16 09:01:35 -07:00
|
|
|
edi_mainview_open(Edi_Path_Options *options)
|
|
|
|
{
|
|
|
|
Edi_Mainview_Item *it;
|
|
|
|
|
|
|
|
it = _get_item_for_path(options->path);
|
|
|
|
if (it)
|
2014-02-26 00:17:44 -08:00
|
|
|
{
|
2014-03-16 09:01:35 -07:00
|
|
|
edi_mainview_item_select(it);
|
|
|
|
if (options->line)
|
|
|
|
edi_mainview_goto(options->line);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options->type == NULL)
|
|
|
|
{
|
|
|
|
eio_file_direct_stat(options->path, _edi_mainview_tab_stat_done, dummy, options);
|
2014-02-26 00:17:44 -08:00
|
|
|
}
|
2014-03-13 11:31:24 -07:00
|
|
|
else
|
2014-02-25 23:28:24 -08:00
|
|
|
{
|
2014-09-13 08:48:16 -07:00
|
|
|
_edi_mainview_item_tab_add(options, NULL);
|
2014-02-25 23:28:24 -08:00
|
|
|
}
|
2014-03-13 11:31:24 -07:00
|
|
|
}
|
|
|
|
|
2015-01-10 09:43:12 -08:00
|
|
|
void
|
2014-03-16 09:01:35 -07:00
|
|
|
edi_mainview_open_window_path(const char *path)
|
2014-03-13 11:31:24 -07:00
|
|
|
{
|
2014-03-16 09:01:35 -07:00
|
|
|
Edi_Path_Options *options;
|
2014-03-13 11:31:24 -07:00
|
|
|
|
2014-03-16 09:01:35 -07:00
|
|
|
options = edi_path_options_create(path);
|
|
|
|
|
2015-06-09 14:31:33 -07:00
|
|
|
edi_mainview_open_window(options);
|
2014-03-16 09:01:35 -07:00
|
|
|
}
|
|
|
|
|
2015-01-10 09:43:12 -08:00
|
|
|
void
|
2014-03-16 09:01:35 -07:00
|
|
|
edi_mainview_open_window(Edi_Path_Options *options)
|
|
|
|
{
|
|
|
|
Edi_Mainview_Item *it;
|
|
|
|
|
|
|
|
it = _get_item_for_path(options->path);
|
|
|
|
if (it)
|
|
|
|
{
|
|
|
|
edi_mainview_item_select(it);
|
2016-09-10 14:28:31 -07:00
|
|
|
_edi_mainview_item_close(it);
|
2014-03-16 09:01:35 -07:00
|
|
|
_edi_mainview_items = eina_list_remove(_edi_mainview_items, it);
|
2015-05-18 07:45:28 -07:00
|
|
|
|
|
|
|
eina_stringshare_del(it->path);
|
2014-03-16 09:01:35 -07:00
|
|
|
free(it);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options->type == NULL)
|
2014-02-25 23:28:24 -08:00
|
|
|
{
|
2014-03-16 09:01:35 -07:00
|
|
|
eio_file_direct_stat(options->path, _edi_mainview_win_stat_done, dummy, options);
|
2014-03-13 11:31:24 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-09-13 08:48:16 -07:00
|
|
|
_edi_mainview_item_win_add(options, NULL);
|
2014-02-25 23:28:24 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-10 09:43:12 -08:00
|
|
|
void
|
2014-02-16 09:09:55 -08:00
|
|
|
edi_mainview_save()
|
|
|
|
{
|
2014-06-07 13:50:14 -07:00
|
|
|
Edi_Editor *editor;
|
2015-03-21 12:53:21 -07:00
|
|
|
Elm_Code *code;
|
2014-02-16 09:09:55 -08:00
|
|
|
|
2016-09-10 15:41:14 -07:00
|
|
|
editor = (Edi_Editor *)evas_object_data_get(_current_view, "editor");
|
2014-06-07 13:50:14 -07:00
|
|
|
|
2015-03-21 12:53:21 -07:00
|
|
|
if (!editor)
|
|
|
|
return;
|
|
|
|
|
2015-06-02 00:22:36 -07:00
|
|
|
code = elm_code_widget_code_get(editor->entry);
|
2015-03-21 12:53:21 -07:00
|
|
|
elm_code_file_save(code->file);
|
2014-02-16 09:09:55 -08:00
|
|
|
}
|
|
|
|
|
2015-01-10 09:43:12 -08:00
|
|
|
void
|
2014-03-13 11:31:24 -07:00
|
|
|
edi_mainview_new_window()
|
|
|
|
{
|
|
|
|
Edi_Mainview_Item *item;
|
|
|
|
|
2014-09-13 08:48:16 -07:00
|
|
|
item = edi_mainview_item_current_get();
|
2014-03-13 11:31:24 -07:00
|
|
|
if (!item)
|
|
|
|
return;
|
|
|
|
|
2014-03-16 09:01:35 -07:00
|
|
|
edi_mainview_open_window_path(item->path);
|
2014-03-13 11:31:24 -07:00
|
|
|
}
|
|
|
|
|
2016-02-15 16:15:52 -08:00
|
|
|
void
|
|
|
|
edi_mainview_close()
|
|
|
|
{
|
|
|
|
Edi_Mainview_Item *item;
|
|
|
|
|
|
|
|
item = edi_mainview_item_current_get();
|
|
|
|
|
2016-09-10 14:28:31 -07:00
|
|
|
_edi_mainview_item_close(item);
|
2016-02-15 16:15:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
edi_mainview_closeall()
|
|
|
|
{
|
|
|
|
Eina_List *list, *next;
|
|
|
|
Edi_Mainview_Item *item;
|
|
|
|
|
|
|
|
EINA_LIST_FOREACH_SAFE(_edi_mainview_items, list, next, item)
|
|
|
|
{
|
2016-09-10 14:28:31 -07:00
|
|
|
_edi_mainview_item_close(item);
|
2016-02-15 16:15:52 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-21 15:46:44 -08:00
|
|
|
void
|
|
|
|
edi_mainview_undo()
|
|
|
|
{
|
|
|
|
Edi_Editor *editor;
|
|
|
|
|
2016-09-10 15:41:14 -07:00
|
|
|
editor = (Edi_Editor *)evas_object_data_get(_current_view, "editor");
|
2016-02-21 15:46:44 -08:00
|
|
|
|
|
|
|
if (editor)
|
|
|
|
elm_code_widget_undo(editor->entry);
|
|
|
|
}
|
|
|
|
|
2015-01-10 09:43:12 -08:00
|
|
|
void
|
2014-02-16 09:09:55 -08:00
|
|
|
edi_mainview_cut()
|
|
|
|
{
|
2014-06-07 13:50:14 -07:00
|
|
|
Edi_Editor *editor;
|
2014-02-16 09:09:55 -08:00
|
|
|
|
2016-09-10 15:41:14 -07:00
|
|
|
editor = (Edi_Editor *)evas_object_data_get(_current_view, "editor");
|
2014-06-07 13:50:14 -07:00
|
|
|
|
|
|
|
if (editor)
|
2015-03-28 10:57:47 -07:00
|
|
|
elm_code_widget_selection_cut(editor->entry);
|
2014-02-16 09:09:55 -08:00
|
|
|
}
|
|
|
|
|
2015-01-10 09:43:12 -08:00
|
|
|
void
|
2014-02-16 09:09:55 -08:00
|
|
|
edi_mainview_copy()
|
|
|
|
{
|
2014-06-07 13:50:14 -07:00
|
|
|
Edi_Editor *editor;
|
2014-02-16 09:09:55 -08:00
|
|
|
|
2016-09-10 15:41:14 -07:00
|
|
|
editor = (Edi_Editor *)evas_object_data_get(_current_view, "editor");
|
2014-06-07 13:50:14 -07:00
|
|
|
|
|
|
|
if (editor)
|
2015-03-28 10:57:47 -07:00
|
|
|
elm_code_widget_selection_copy(editor->entry);
|
2014-02-16 09:09:55 -08:00
|
|
|
}
|
|
|
|
|
2015-01-10 09:43:12 -08:00
|
|
|
void
|
2014-02-16 09:09:55 -08:00
|
|
|
edi_mainview_paste()
|
|
|
|
{
|
2014-06-07 13:50:14 -07:00
|
|
|
Edi_Editor *editor;
|
2014-02-16 09:09:55 -08:00
|
|
|
|
2016-09-10 15:41:14 -07:00
|
|
|
editor = (Edi_Editor *)evas_object_data_get(_current_view, "editor");
|
2014-06-07 13:50:14 -07:00
|
|
|
|
|
|
|
if (editor)
|
2015-03-28 10:57:47 -07:00
|
|
|
elm_code_widget_selection_paste(editor->entry);
|
2014-02-16 09:09:55 -08:00
|
|
|
}
|
|
|
|
|
2015-01-10 09:43:12 -08:00
|
|
|
void
|
2014-04-30 15:06:16 -07:00
|
|
|
edi_mainview_search()
|
|
|
|
{
|
2014-06-07 13:50:14 -07:00
|
|
|
Edi_Editor *editor;
|
2014-04-30 15:06:16 -07:00
|
|
|
|
2016-09-10 15:41:14 -07:00
|
|
|
editor = (Edi_Editor *)evas_object_data_get(_current_view, "editor");
|
2014-06-07 13:50:14 -07:00
|
|
|
|
|
|
|
if (editor)
|
2015-02-08 15:21:27 -08:00
|
|
|
edi_editor_search(editor);
|
2014-04-30 15:06:16 -07:00
|
|
|
}
|
|
|
|
|
2015-01-10 09:43:12 -08:00
|
|
|
void
|
2014-03-15 06:12:34 -07:00
|
|
|
edi_mainview_goto(int line)
|
|
|
|
{
|
2014-06-07 13:50:14 -07:00
|
|
|
Edi_Editor *editor;
|
2014-03-15 06:12:34 -07:00
|
|
|
|
2016-09-10 15:41:14 -07:00
|
|
|
editor = (Edi_Editor *)evas_object_data_get(_current_view, "editor");
|
|
|
|
if (!editor || line <= 0)
|
2014-03-15 06:12:34 -07:00
|
|
|
return;
|
|
|
|
|
2015-06-02 00:22:36 -07:00
|
|
|
elm_code_widget_cursor_position_set(editor->entry, 1, line);
|
2014-06-07 13:50:14 -07:00
|
|
|
elm_object_focus_set(editor->entry, EINA_TRUE);
|
2014-03-15 06:12:34 -07:00
|
|
|
}
|
|
|
|
|
2015-07-16 14:36:15 -07:00
|
|
|
static void
|
|
|
|
_edi_mainview_goto_popup_go_cb(void *data,
|
|
|
|
Evas_Object *obj EINA_UNUSED,
|
|
|
|
void *event_info EINA_UNUSED)
|
|
|
|
{
|
|
|
|
int number;
|
|
|
|
|
|
|
|
number = atoi(elm_entry_entry_get((Evas_Object *) data));
|
|
|
|
edi_mainview_goto(number);
|
|
|
|
|
|
|
|
evas_object_del(_edi_mainview_goto_popup);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_edi_mainview_goto_popup_cancel_cb(void *data EINA_UNUSED,
|
|
|
|
Evas_Object *obj EINA_UNUSED,
|
|
|
|
void *event_info EINA_UNUSED)
|
|
|
|
{
|
|
|
|
evas_object_del(_edi_mainview_goto_popup);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_edi_mainview_goto_popup_key_up_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED,
|
|
|
|
Evas_Object *obj, void *event_info)
|
|
|
|
{
|
|
|
|
Evas_Event_Key_Up *ev = (Evas_Event_Key_Up *)event_info;
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
str = elm_object_text_get(obj);
|
|
|
|
|
|
|
|
if (strlen(str) && (!strcmp(ev->key, "KP_Enter") || !strcmp(ev->key, "Return")))
|
|
|
|
_edi_mainview_goto_popup_go_cb(obj, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
edi_mainview_goto_popup_show()
|
|
|
|
{
|
2016-01-21 12:06:49 -08:00
|
|
|
Evas_Object *popup, *box, *input, *button;
|
2015-07-16 14:36:15 -07:00
|
|
|
|
|
|
|
popup = elm_popup_add(_main_win);
|
|
|
|
_edi_mainview_goto_popup = popup;
|
|
|
|
elm_object_part_text_set(popup, "title,text",
|
|
|
|
"Enter line number");
|
|
|
|
|
2016-01-21 12:06:49 -08:00
|
|
|
box = elm_box_add(popup);
|
|
|
|
elm_box_horizontal_set(box, EINA_FALSE);
|
|
|
|
elm_object_content_set(popup, box);
|
|
|
|
|
|
|
|
input = elm_entry_add(box);
|
2015-07-16 14:36:15 -07:00
|
|
|
elm_entry_single_line_set(input, EINA_TRUE);
|
|
|
|
evas_object_event_callback_add(input, EVAS_CALLBACK_KEY_UP, _edi_mainview_goto_popup_key_up_cb, NULL);
|
2016-01-21 12:06:49 -08:00
|
|
|
evas_object_size_hint_weight_set(input, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
|
|
|
evas_object_size_hint_align_set(input, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
|
|
|
evas_object_show(input);
|
|
|
|
elm_box_pack_end(box, input);
|
2015-07-16 14:36:15 -07:00
|
|
|
|
|
|
|
button = elm_button_add(popup);
|
|
|
|
elm_object_text_set(button, "cancel");
|
|
|
|
elm_object_part_content_set(popup, "button1", button);
|
|
|
|
evas_object_smart_callback_add(button, "clicked",
|
|
|
|
_edi_mainview_goto_popup_cancel_cb, NULL);
|
|
|
|
|
|
|
|
button = elm_button_add(popup);
|
|
|
|
elm_object_text_set(button, "go");
|
|
|
|
elm_object_part_content_set(popup, "button2", button);
|
|
|
|
evas_object_smart_callback_add(button, "clicked",
|
|
|
|
_edi_mainview_goto_popup_go_cb, input);
|
|
|
|
|
|
|
|
evas_object_show(popup);
|
|
|
|
elm_object_focus_set(input, EINA_TRUE);
|
|
|
|
}
|
|
|
|
|
2015-01-10 09:43:12 -08:00
|
|
|
void
|
2014-03-14 06:44:09 -07:00
|
|
|
edi_mainview_add(Evas_Object *parent, Evas_Object *win)
|
2014-02-15 15:17:40 -08:00
|
|
|
{
|
2016-09-10 14:28:31 -07:00
|
|
|
Evas_Object *box, *txt, *nf;
|
2014-02-15 15:17:40 -08:00
|
|
|
|
2014-03-14 06:44:09 -07:00
|
|
|
_main_win = win;
|
|
|
|
|
2014-02-15 15:17:40 -08:00
|
|
|
box = elm_box_add(parent);
|
|
|
|
evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
|
|
|
evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
|
|
|
evas_object_show(box);
|
2015-09-16 02:21:21 -07:00
|
|
|
elm_box_pack_end(parent, box);
|
|
|
|
|
2016-09-11 06:00:31 -07:00
|
|
|
tb = elm_box_add(parent);
|
2014-02-15 15:17:40 -08:00
|
|
|
evas_object_size_hint_weight_set(tb, EVAS_HINT_EXPAND, 0.0);
|
2016-09-11 06:00:31 -07:00
|
|
|
evas_object_size_hint_align_set(tb, 0.0, EVAS_HINT_FILL);
|
|
|
|
elm_box_horizontal_set(tb, EINA_TRUE);
|
2014-02-15 15:17:40 -08:00
|
|
|
elm_box_pack_end(box, tb);
|
|
|
|
evas_object_show(tb);
|
|
|
|
|
2016-09-10 14:28:31 -07:00
|
|
|
nf = elm_box_add(parent);
|
2014-02-15 15:17:40 -08:00
|
|
|
evas_object_size_hint_weight_set(nf, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
|
|
|
evas_object_size_hint_align_set(nf, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
|
|
|
elm_box_pack_end(box, nf);
|
|
|
|
evas_object_show(nf);
|
2016-09-10 14:28:31 -07:00
|
|
|
_content_frame = nf;
|
2014-02-15 15:17:40 -08:00
|
|
|
|
|
|
|
txt = elm_label_add(parent);
|
2016-02-24 02:27:03 -08:00
|
|
|
elm_object_text_set(txt, "Welcome - click on a file to edit");
|
2014-02-15 15:17:40 -08:00
|
|
|
evas_object_size_hint_weight_set(txt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
|
|
|
evas_object_size_hint_align_set(txt, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
|
|
|
evas_object_show(txt);
|
|
|
|
|
2016-09-10 14:28:31 -07:00
|
|
|
elm_box_pack_end(_content_frame, txt);
|
|
|
|
_welcome_panel = _current_view = txt;
|
2014-02-15 15:17:40 -08:00
|
|
|
}
|