forked from enlightenment/edi
Add an open-as menu so we can override the mime type detection
The mime / type registration requires some work - there are a few magic values here that need to be formalised
This commit is contained in:
parent
16017019b3
commit
17b90a8876
1
TODO
1
TODO
|
@ -3,7 +3,6 @@ This project is in heavy development, we are currenty working towards the
|
|||
|
||||
* Opening editor in a new window
|
||||
* info panel with logs and useful output
|
||||
* Allow an "open as" so we can open text files that have a weird mime type
|
||||
* Remember last project and allow new project to be loaded (new window or current)
|
||||
* No screen waste (toolbar, menu, tab are out of the way of the developer)
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
static Elm_Genlist_Item_Class itc, itc2;
|
||||
static Evas_Object *list;
|
||||
static edi_filepanel_item_clicked_cb _open_cb;
|
||||
static edi_filepanel_item_type_clicked_cb _open_type_cb;
|
||||
|
||||
static Evas_Object *menu, *_main_win;
|
||||
static const char *_menu_cb_path;
|
||||
|
@ -45,6 +46,20 @@ _item_menu_xdgopen_cb(Elm_Object_Item *it EINA_UNUSED, Evas_Object *obj EINA_UNU
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_item_menu_open_as_text_cb(Elm_Object_Item *it EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
|
||||
void *event_info EINA_UNUSED)
|
||||
{
|
||||
_open_type_cb(_menu_cb_path, "text");
|
||||
}
|
||||
|
||||
static void
|
||||
_item_menu_open_as_image_cb(Elm_Object_Item *it EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
|
||||
void *event_info EINA_UNUSED)
|
||||
{
|
||||
_open_type_cb(_menu_cb_path, "image");
|
||||
}
|
||||
|
||||
static void
|
||||
_item_menu_dismissed_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
|
||||
void *ev EINA_UNUSED)
|
||||
|
@ -65,6 +80,9 @@ _item_menu_create(Evas_Object *win)
|
|||
|
||||
menu_it = elm_menu_item_add(menu, NULL, NULL, "xdg-open",
|
||||
_item_menu_xdgopen_cb, NULL);
|
||||
menu_it = elm_menu_item_add(menu, NULL, NULL, "open as", NULL, NULL);
|
||||
elm_menu_item_add(menu, menu_it, NULL, "text", _item_menu_open_as_text_cb, NULL);
|
||||
elm_menu_item_add(menu, menu_it, NULL, "image", _item_menu_open_as_image_cb, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -311,7 +329,8 @@ _populate(Evas_Object *obj,
|
|||
|
||||
void
|
||||
edi_filepanel_add(Evas_Object *parent, Evas_Object *win,
|
||||
const char *path, edi_filepanel_item_clicked_cb cb)
|
||||
const char *path, edi_filepanel_item_clicked_cb cb,
|
||||
edi_filepanel_item_type_clicked_cb type_cb)
|
||||
{
|
||||
list = elm_genlist_add(parent);
|
||||
evas_object_size_hint_min_set(list, 100, -1);
|
||||
|
@ -339,6 +358,7 @@ edi_filepanel_add(Evas_Object *parent, Evas_Object *win,
|
|||
itc2.func.del = _item_del;
|
||||
|
||||
_open_cb = cb;
|
||||
_open_type_cb = type_cb;
|
||||
_main_win = win;
|
||||
_populate(list, path, NULL, NULL);
|
||||
|
||||
|
|
|
@ -12,7 +12,10 @@ extern "C" {
|
|||
* @brief These routines are used for managing the Edi file panel.
|
||||
*/
|
||||
|
||||
typedef void (*edi_filepanel_item_clicked_cb)(const char *path);
|
||||
typedef void (*edi_filepanel_item_clicked_cb)(const char *path);
|
||||
|
||||
typedef void (*edi_filepanel_item_type_clicked_cb)(const char *path,
|
||||
const char *type);
|
||||
|
||||
/**
|
||||
* @brief UI management functions.
|
||||
|
@ -29,13 +32,15 @@ extern "C" {
|
|||
*
|
||||
* @param parent The panel into which the panel will be loaded.
|
||||
* @param win The main window of the application.
|
||||
* @param win The project path being opened.
|
||||
* @param win A callback to inform the app a file should be opened.
|
||||
* @param path The project path being opened.
|
||||
* @param cb A callback to inform the app a file should be opened.
|
||||
* @param type_cb A callback to inform the app a file should be opened with a specified type.
|
||||
*
|
||||
* @ingroup UI
|
||||
*/
|
||||
void edi_filepanel_add(Evas_Object *parent, Evas_Object *win,
|
||||
const char *path, edi_filepanel_item_clicked_cb cb);
|
||||
const char *path, edi_filepanel_item_clicked_cb cb,
|
||||
edi_filepanel_item_type_clicked_cb type_cb);
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
|
|
@ -35,6 +35,13 @@ _edi_file_open_cb(const char *path)
|
|||
edi_mainview_open_path(path);
|
||||
}
|
||||
|
||||
static void
|
||||
_edi_file_open_type_cb(const char *path, const char *type)
|
||||
{
|
||||
INF("Opening %s as %s", path, type);
|
||||
edi_mainview_open_path_type(path, type);
|
||||
}
|
||||
|
||||
static Evas_Object *
|
||||
edi_content_setup(Evas_Object *win, const char *path)
|
||||
{
|
||||
|
@ -75,7 +82,7 @@ edi_content_setup(Evas_Object *win, const char *path)
|
|||
evas_object_size_hint_weight_set(panel, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
evas_object_size_hint_align_set(panel, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
evas_object_show(panel);
|
||||
edi_filepanel_add(panel, win, path, _edi_file_open_cb);
|
||||
edi_filepanel_add(panel, win, path, _edi_file_open_cb, _edi_file_open_type_cb);
|
||||
|
||||
elm_object_part_content_set(panes, "left", panel);
|
||||
elm_panes_content_left_size_set(panes, 0.2);
|
||||
|
|
|
@ -108,6 +108,28 @@ _edi_mainview_open_stat_done(void *data, Eio_File *handler EINA_UNUSED, const Ei
|
|||
eina_stringshare_del(path);
|
||||
}
|
||||
|
||||
EAPI void
|
||||
edi_mainview_open_path_type(const char *path, const char *type)
|
||||
{
|
||||
Elm_Object_Item *it;
|
||||
|
||||
it = _get_item_for_path(path);
|
||||
if (it)
|
||||
{
|
||||
elm_naviframe_item_promote(it);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!strcmp(type, "text"))
|
||||
{
|
||||
_edi_mainview_open_file_text(path);
|
||||
}
|
||||
else if (!strcmp(type, "image"))
|
||||
{
|
||||
_edi_mainview_open_file_image(path);
|
||||
}
|
||||
}
|
||||
|
||||
EAPI void
|
||||
edi_mainview_open_path(const char *path)
|
||||
{
|
||||
|
|
|
@ -53,6 +53,17 @@ EAPI void edi_mainview_add(Evas_Object *parent);
|
|||
*/
|
||||
EAPI void edi_mainview_open_path(const char *path);
|
||||
|
||||
/**
|
||||
* Open the file at path for editing using the type specified.
|
||||
* Supported types are "text" and "image".
|
||||
*
|
||||
* @param path The absolute path of the file to open.
|
||||
* @param type The requested type to use when opening the file
|
||||
*
|
||||
* @ingroup Content
|
||||
*/
|
||||
EAPI void edi_mainview_open_path_type(const char *path, const char *type);
|
||||
|
||||
/**
|
||||
* Save the current file.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue