Add mime or requested type to text editor status bar.

Some refactoring to start splitting out file management from UI
This commit is contained in:
Andy Williams 2014-09-13 16:48:16 +01:00
parent 85661fc2a6
commit 9ac976aa17
9 changed files with 144 additions and 57 deletions

View File

@ -17,7 +17,8 @@ welcome/edi_welcome.c \
edi_filepanel.c \
edi_logpanel.c \
edi_consolepanel.c \
edi_mainview.c \
mainview/edi_mainview_item.c \
mainview/edi_mainview.c \
edi_main.c
edi_LDADD = @EFL_LIBS@ $(top_builddir)/src/lib/libedi.la

View File

@ -11,7 +11,7 @@
#include <regex.h>
#include "edi_consolepanel.h"
#include "edi_mainview.h"
#include "mainview/edi_mainview.h"
#include "edi_private.h"

View File

@ -16,7 +16,7 @@
#include "edi_filepanel.h"
#include "edi_logpanel.h"
#include "edi_consolepanel.h"
#include "edi_mainview.h"
#include "mainview/edi_mainview.h"
#include "welcome/edi_welcome.h"
#include "edi_private.h"

View File

@ -9,7 +9,7 @@
#include "edi_editor.h"
#include "edi_mainview.h"
#include "mainview/edi_mainview.h"
#include "edi_private.h"
@ -204,9 +204,26 @@ _edit_cursor_moved(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
}
static void
_edi_editor_statusbar_add(Evas_Object *panel, Edi_Editor *editor)
_edi_editor_statusbar_add(Evas_Object *panel, Edi_Editor *editor, Edi_Mainview_Item *item)
{
Evas_Object *position;
Evas_Object *position, *mime;
elm_box_horizontal_set(panel, EINA_TRUE);
mime = elm_label_add(panel);
if (item->mimetype)
{
elm_object_text_set(mime, item->mimetype);
}
else
{
elm_object_text_set(mime, item->editortype);
}
evas_object_size_hint_align_set(mime, 0.0, 0.5);
evas_object_size_hint_weight_set(mime, EVAS_HINT_EXPAND, 0.0);
elm_box_pack_end(panel, mime);
evas_object_show(mime);
elm_object_disabled_set(mime, EINA_TRUE);
position = elm_label_add(panel);
evas_object_size_hint_align_set(position, 1.0, 0.5);
@ -219,7 +236,7 @@ _edi_editor_statusbar_add(Evas_Object *panel, Edi_Editor *editor)
evas_object_smart_callback_add(editor->entry, "cursor,changed", _edit_cursor_moved, position);
}
EAPI Evas_Object *edi_editor_add(Evas_Object *parent, const char *path)
EAPI Evas_Object *edi_editor_add(Evas_Object *parent, Edi_Mainview_Item *item)
{
Evas_Object *txt, *lines, *vbox, *box, *searchbar, *statusbar;
Evas_Modifier_Mask ctrl, shift, alt;
@ -267,7 +284,7 @@ EAPI Evas_Object *edi_editor_add(Evas_Object *parent, const char *path)
elm_entry_scrollable_set(txt, EINA_TRUE);
elm_entry_line_wrap_set(txt, EINA_FALSE);
elm_entry_text_style_user_push(txt, EDITOR_FONT);
elm_entry_file_set(txt, path, ELM_TEXT_FORMAT_PLAIN_UTF8);
elm_entry_file_set(txt, item->path, ELM_TEXT_FORMAT_PLAIN_UTF8);
elm_entry_autosave_set(txt, EDI_CONTENT_AUTOSAVE);
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);
@ -284,7 +301,7 @@ EAPI Evas_Object *edi_editor_add(Evas_Object *parent, const char *path)
evas_object_smart_callback_add(txt, "undo,request", _undo_cb, editor);
edi_editor_search_add(searchbar, editor);
_edi_editor_statusbar_add(statusbar, editor);
_edi_editor_statusbar_add(statusbar, editor, item);
e = evas_object_evas_get(txt);
ctrl = evas_key_modifier_mask_get(e, "Control");

View File

@ -3,6 +3,8 @@
#include <Evas.h>
#include "mainview/edi_mainview_item.h"
#ifdef __cplusplus
extern "C" {
#endif
@ -52,12 +54,12 @@ struct _Edi_Editor
* Initialize a new Edi editor and add it to the parent panel.
*
* @param parent The panel into which the panel will be loaded.
* @param path The file path to be loaded in the editor.
* @param item The item describing the file to be loaded in the editor.
* @return the created evas object that contains the editor.
*
* @ingroup Editor
*/
EAPI Evas_Object *edi_editor_add(Evas_Object *parent, const char *path);
EAPI Evas_Object *edi_editor_add(Evas_Object *parent, Edi_Mainview_Item *item);
/**
* @}

View File

@ -7,7 +7,8 @@
#include <Eina.h>
#include <Eio.h>
#include "edi_mainview.h"
#include "mainview/edi_mainview_item.h"
#include "mainview/edi_mainview.h"
#include "editor/edi_editor.h"
@ -23,6 +24,26 @@ static void
dummy()
{}
EAPI Edi_Mainview_Item *
edi_mainview_item_current_get()
{
Eina_List *item;
Elm_Object_Item *current;
Edi_Mainview_Item *it;
current = elm_naviframe_top_item_get(nf);
EINA_LIST_FOREACH(_edi_mainview_items, item, it)
{
if (it && it->view == current)
{
return it;
}
}
return NULL;
}
EAPI void
edi_mainview_item_prev()
{
@ -102,13 +123,15 @@ _get_item_for_path(const char *path)
}
static Edi_Mainview_Item *
_edi_mainview_item_add(const char *path, Elm_Object_Item *tab, Elm_Object_Item *view,
_edi_mainview_item_add(Edi_Path_Options *path, const char *mime, Elm_Object_Item *tab, Elm_Object_Item *view,
Evas_Object *win)
{
Edi_Mainview_Item *item;
item = malloc(sizeof(Edi_Mainview_Item));
item->path = path;
item->path = path->path;
item->editortype = path->type;
item->mimetype = mime;
item->tab = tab;
item->view = view;
item->win = win;
@ -119,7 +142,7 @@ _edi_mainview_item_add(const char *path, Elm_Object_Item *tab, Elm_Object_Item *
}
static Evas_Object *
_edi_mainview_content_image_create(const char *path, Evas_Object *parent)
_edi_mainview_content_image_create(Edi_Mainview_Item *item, Evas_Object *parent)
{
Evas_Object *img, *scroll;
@ -128,7 +151,7 @@ _edi_mainview_content_image_create(const char *path, Evas_Object *parent)
evas_object_size_hint_align_set(scroll, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(scroll);
img = elm_image_add(scroll);
elm_image_file_set(img, path, NULL);
elm_image_file_set(img, item->path, NULL);
elm_image_no_scale_set(img, EINA_TRUE);
elm_object_content_set(scroll, img);
evas_object_show(img);
@ -137,37 +160,39 @@ _edi_mainview_content_image_create(const char *path, Evas_Object *parent)
}
static Evas_Object *
_edi_mainview_content_create(const char *path, const char *type, Evas_Object *parent)
_edi_mainview_content_create(Edi_Mainview_Item *item, Evas_Object *parent)
{
if (!strcmp(type, "text"))
if (!strcmp(item->editortype, "text"))
{
return edi_editor_add(parent, path);
return edi_editor_add(parent, item);
}
else if (!strcmp(type, "image"))
else if (!strcmp(item->editortype, "image"))
{
return _edi_mainview_content_image_create(path, parent);
return _edi_mainview_content_image_create(item, parent);
}
return NULL;
}
static void
_edi_mainview_item_tab_add(Edi_Path_Options *options)
_edi_mainview_item_tab_add(Edi_Path_Options *options, const char *mime)
{
Evas_Object *content;
Elm_Object_Item *it, *tab;
Edi_Mainview_Item *item;
content = _edi_mainview_content_create(options->path, options->type, nf);
item = _edi_mainview_item_add(options, mime, NULL, NULL, NULL);
content = _edi_mainview_content_create(item, nf);
if (options->line)
edi_mainview_goto(options->line);
it = elm_naviframe_item_simple_push(nf, content);
elm_naviframe_item_style_set(it, "overlap");
tab = elm_toolbar_item_append(tb, NULL, basename(options->path), _promote, it);
item->view = it;
item->tab = tab;
elm_toolbar_item_selected_set(tab, EINA_TRUE);
item = _edi_mainview_item_add(options->path, tab, it, NULL);
elm_object_item_data_set(it, item);
}
@ -197,7 +222,7 @@ _edi_mainview_win_title_get(const char *path)
}
static void
_edi_mainview_item_win_add(Edi_Path_Options *options)
_edi_mainview_item_win_add(Edi_Path_Options *options, const char *mime)
{
Evas_Object *win, *content;
Edi_Mainview_Item *item;
@ -207,10 +232,10 @@ _edi_mainview_item_win_add(Edi_Path_Options *options)
elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
evas_object_smart_callback_add(win, "delete,request", _edi_mainview_win_exit, NULL);
item = _edi_mainview_item_add(options->path, NULL, NULL, win);
item = _edi_mainview_item_add(options, mime, NULL, NULL, win);
evas_object_data_set(win, "edi_mainview_item", item);
content = _edi_mainview_content_create(options->path, options->type, win);
content = _edi_mainview_content_create(item, win);
elm_win_resize_object_add(win, content);
evas_object_resize(win, 380 * elm_config_scale_get(), 260 * elm_config_scale_get());
@ -275,8 +300,6 @@ _edi_mainview_choose_type(Evas_Object *parent EINA_UNUSED, Edi_Path_Options *opt
evas_object_smart_callback_add(cancel, "clicked",
_edi_mainview_choose_type_close_cb, NULL);
// popup show should be called after adding all the contents and the buttons
// of popup to set the focus into popup's contents correctly.
evas_object_show(popup);
}
@ -303,7 +326,7 @@ _edi_mainview_tab_stat_done(void *data, Eio_File *handler EINA_UNUSED, const Ein
return;
}
_edi_mainview_item_tab_add(options);
_edi_mainview_item_tab_add(options, mime);
}
static void
@ -329,7 +352,7 @@ _edi_mainview_win_stat_done(void *data, Eio_File *handler EINA_UNUSED, const Ein
return;
}
_edi_mainview_item_win_add(options);
_edi_mainview_item_win_add(options, mime);
}
EAPI void
@ -370,7 +393,7 @@ edi_mainview_open(Edi_Path_Options *options)
}
else
{
_edi_mainview_item_tab_add(options);
_edi_mainview_item_tab_add(options, NULL);
}
}
@ -416,7 +439,7 @@ edi_mainview_open_window(Edi_Path_Options *options)
}
else
{
_edi_mainview_item_win_add(options);
_edi_mainview_item_win_add(options, NULL);
}
}
@ -440,7 +463,7 @@ edi_mainview_new_window()
{
Edi_Mainview_Item *item;
item = elm_object_item_data_get(elm_naviframe_top_item_get(nf));
item = edi_mainview_item_current_get();
if (!item)
return;
@ -450,17 +473,17 @@ edi_mainview_new_window()
EAPI void
edi_mainview_close()
{
Edi_Mainview_Item *it;
Edi_Mainview_Item *item;
it = elm_object_item_data_get(elm_naviframe_top_item_get(nf));
if (!it)
item = edi_mainview_item_current_get();
if (!item)
return;
elm_naviframe_item_pop(nf);
elm_object_item_del(elm_toolbar_selected_item_get(tb));
_edi_mainview_items = eina_list_remove(_edi_mainview_items, it);
eina_stringshare_del(it->path);
free(it);
_edi_mainview_items = eina_list_remove(_edi_mainview_items, item);
eina_stringshare_del(item->path);
free(item);
}
EAPI void

View File

@ -6,6 +6,8 @@
#include "Edi.h"
#include "mainview/edi_mainview_item.h"
#ifdef __cplusplus
extern "C" {
#endif
@ -15,23 +17,6 @@ extern "C" {
* @brief These routines are used for managing the main area of the Edi interface.
*/
/**
* @struct _Edi_Mainview_Item
* An item being displayed in the mainview.
*/
typedef struct _Edi_Mainview_Item
{
const char *path; /**< The path of the file in this mainview item */
Elm_Object_Item *tab; /**< The tab object connected to this view */
Elm_Object_Item *view; /**< The naviframe item that contains the view for this item */
Evas_Object *win; /**< The window for the item if it's displayed in a seperate window */
/* Private */
/* Add new members here. */
} Edi_Mainview_Item;
/**
* @brief UI management functions.
* @defgroup UI
@ -176,6 +161,8 @@ EAPI void edi_mainview_goto(int line);
*
*/
EAPI Edi_Mainview_Item *edi_mainview_item_current_get();
/**
* Select the passed item in the mainview UI.
* By definition this will already be an open file as the Edi_Mainview_Item will

View File

@ -0,0 +1,15 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <libgen.h>
#include <Eina.h>
#include <Eio.h>
#include "mainview/edi_mainview_item.h"
#include "editor/edi_editor.h"
#include "edi_private.h"

View File

@ -0,0 +1,42 @@
#ifndef EDI_MAINVIEW_ITEM_H_
# define EDI_MAINVIEW_ITEM_H_
#include <Elementary.h>
#include <Evas.h>
#include "Edi.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @file
* @brief These routines are used for managing views within the main area of the Edi interface.
*/
/**
* @struct _Edi_Mainview_Item
* An item being displayed in the mainview.
*/
typedef struct _Edi_Mainview_Item
{
const char *path; /**< The path of the file in this mainview item */
Elm_Object_Item *tab; /**< The tab object connected to this view */
Elm_Object_Item *view; /**< The naviframe item that contains the view for this item */
Evas_Object *win; /**< The window for the item if it's displayed in a seperate window */
const char *mimetype; /**< The detected mime type for the item */
const char *editortype; /**< The requested editor type for this item */
/* Private */
/* Add new members here. */
} Edi_Mainview_Item;
#ifdef __cplusplus
}
#endif
#endif /* EDI_MAINVIEW_ITEM_H_ */