From 17b90a8876600681ede27310c7aba1ed720040d1 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 26 Feb 2014 07:28:24 +0000 Subject: [PATCH] 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 --- TODO | 1 - src/bin/edi_filepanel.c | 22 +++++++++++++++++++++- src/bin/edi_filepanel.h | 13 +++++++++---- src/bin/edi_main.c | 9 ++++++++- src/bin/edi_mainview.c | 22 ++++++++++++++++++++++ src/bin/edi_mainview.h | 11 +++++++++++ 6 files changed, 71 insertions(+), 7 deletions(-) diff --git a/TODO b/TODO index 19e4a78..31ffebb 100644 --- a/TODO +++ b/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) diff --git a/src/bin/edi_filepanel.c b/src/bin/edi_filepanel.c index 16a6db5..f0f9a52 100644 --- a/src/bin/edi_filepanel.c +++ b/src/bin/edi_filepanel.c @@ -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); diff --git a/src/bin/edi_filepanel.h b/src/bin/edi_filepanel.h index 48ea63e..fe98fa1 100644 --- a/src/bin/edi_filepanel.h +++ b/src/bin/edi_filepanel.h @@ -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); /** * @} diff --git a/src/bin/edi_main.c b/src/bin/edi_main.c index 084ab8e..039bf62 100644 --- a/src/bin/edi_main.c +++ b/src/bin/edi_main.c @@ -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); diff --git a/src/bin/edi_mainview.c b/src/bin/edi_mainview.c index b968ee9..238efbc 100644 --- a/src/bin/edi_mainview.c +++ b/src/bin/edi_mainview.c @@ -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) { diff --git a/src/bin/edi_mainview.h b/src/bin/edi_mainview.h index 6828d9d..821a622 100644 --- a/src/bin/edi_mainview.h +++ b/src/bin/edi_mainview.h @@ -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. *