content: move alternative content to edi_content.c

Slight refactoring to complement the previous commits regarding tab sizing.
This commit is contained in:
Al Poole 2018-03-17 17:43:34 +00:00
parent 81165c426f
commit fa03323a20
7 changed files with 169 additions and 39 deletions

85
src/bin/edi_content.c Normal file
View File

@ -0,0 +1,85 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "editor/edi_editor.h"
#include "edi_content.h"
#include "edi_config.h"
#include "edi_private.h"
static Eina_Bool
_edi_content_diff_config_changed(void *data, int type EINA_UNUSED, void *event EINA_UNUSED)
{
Evas_Object *diff;
diff = (Evas_Object*) data;
elm_code_diff_widget_font_set(diff, _edi_project_config->font.name, _edi_project_config->font.size);
return ECORE_CALLBACK_RENEW;
}
Evas_Object *
edi_content_diff_add(Evas_Object *parent, Edi_Mainview_Item *item)
{
Elm_Code *code;
Evas_Object *diff;
code = elm_code_create();
elm_code_file_open(code, item->path);
diff = elm_code_diff_widget_add(parent, code);
elm_code_diff_widget_font_set(diff, _edi_project_config->font.name, _edi_project_config->font.size);
ecore_event_handler_add(EDI_EVENT_CONFIG_CHANGED, _edi_content_diff_config_changed, diff);
return diff;
}
Evas_Object *
edi_content_image_add(Evas_Object *parent, Edi_Mainview_Item *item)
{
Evas_Object *vbox, *box, *searchbar, *statusbar, *scroll, *img;
Edi_Editor *editor;
vbox = elm_box_add(parent);
evas_object_size_hint_weight_set(vbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(vbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(vbox);
searchbar = elm_box_add(vbox);
evas_object_size_hint_weight_set(searchbar, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(searchbar, EVAS_HINT_FILL, 0.0);
elm_box_pack_end(vbox, searchbar);
box = elm_box_add(vbox);
elm_box_horizontal_set(box, EINA_TRUE);
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);
elm_box_pack_end(vbox, box);
evas_object_show(box);
statusbar = elm_box_add(vbox);
evas_object_size_hint_weight_set(statusbar, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(statusbar, EVAS_HINT_FILL, 0.0);
elm_box_pack_end(vbox, statusbar);
evas_object_show(statusbar);
scroll = elm_scroller_add(parent);
evas_object_size_hint_weight_set(scroll, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(scroll, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(scroll);
img = elm_image_add(vbox);
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);
elm_box_pack_end(box, scroll);
editor = calloc(1, sizeof(*editor));
editor->mimetype = item->mimetype;
edi_editor_statusbar_add(statusbar, editor, item);
return vbox;
}

58
src/bin/edi_content.h Normal file
View File

@ -0,0 +1,58 @@
#ifndef EDI_CONTENT_H_
# define EDI_CONTENT_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "mainview/edi_mainview_item.h"
/**
* @file
* @brief These routines are used for managing various content.
*/
/**
* @brief Managing the creation of alternative content within EDI.
* @defgroup Content
*
* @{
*
* Adding alternative editor types, for example images or diff widgets.
*
*/
/**
* Create an object for displaying image content.
*
* @param parent the panel into which the image widget will be loaded.
* @param item the item describing the image file to be loaded in the canvas.
*
* @return an Evas_Object containing the image.
*
* @ingroup Content
*/
Evas_Object *edi_content_image_add(Evas_Object *parent, Edi_Mainview_Item *item);
/**
* Create an object for diff content.
*
* @param parent the panel into which the diff widget will be loaded.
* @param item the item describing the diff file to be loaded.
*
* @return an Evas_Object containing diff widget.
*
* @ingroup Content
*/
Evas_Object *edi_content_diff_add(Evas_Object *parent, Edi_Mainview_Item *item);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* EDI_CONTENT_H_ */

View File

@ -2,9 +2,7 @@
# include "config.h"
#endif
#include <Evas.h>
#include <Elementary.h>
#include "edi_content.h"
#include "edi_content_provider.h"
#include "editor/edi_editor.h"
@ -14,41 +12,12 @@
#include "edi_private.h"
// TODO move out to edi_content.c or similar just like the editor type
// (and the Evas include)
static Eina_Bool
_edi_content_provider_diff_config_changed(void *data, int type EINA_UNUSED, void *event EINA_UNUSED)
{
Evas_Object *diff;
diff = (Evas_Object*) data;
elm_code_diff_widget_font_set(diff, _edi_project_config->font.name, _edi_project_config->font.size);
return ECORE_CALLBACK_RENEW;
}
static Evas_Object *
_edi_content_provider_diff_add(Evas_Object *parent, Edi_Mainview_Item *item)
{
Elm_Code *code;
Evas_Object *diff;
code = elm_code_create();
elm_code_file_open(code, item->path);
diff = elm_code_diff_widget_add(parent, code);
elm_code_diff_widget_font_set(diff, _edi_project_config->font.name, _edi_project_config->font.size);
ecore_event_handler_add(EDI_EVENT_CONFIG_CHANGED, _edi_content_provider_diff_config_changed, diff);
return diff;
}
static Edi_Content_Provider _edi_content_provider_registry[] =
{
{"text", "text-x-generic", EINA_TRUE, EINA_TRUE, edi_editor_add},
{"code", "text-x-csrc", EINA_TRUE, EINA_TRUE, edi_editor_add},
{"image", "image-x-generic", EINA_FALSE, EINA_FALSE, edi_editor_image_add},
{"diff", "text-x-source", EINA_TRUE, EINA_FALSE, _edi_content_provider_diff_add},
{"image", "image-x-generic", EINA_FALSE, EINA_FALSE, edi_content_image_add},
{"diff", "text-x-source", EINA_TRUE, EINA_FALSE, edi_content_diff_add},
{NULL, NULL, EINA_FALSE, EINA_FALSE, NULL}
};

View File

@ -913,8 +913,8 @@ _edit_file_changed(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EI
free(word);
}
static void
_edi_editor_statusbar_add(Evas_Object *panel, Edi_Editor *editor, Edi_Mainview_Item *item)
void
edi_editor_statusbar_add(Evas_Object *panel, Edi_Editor *editor, Edi_Mainview_Item *item)
{
Edi_Language_Provider *provider;
Evas_Object *table, *rect, *tb, *position, *mime;
@ -1441,7 +1441,7 @@ edi_editor_image_add(Evas_Object *parent, Edi_Mainview_Item *item)
editor = calloc(1, sizeof(*editor));
editor->mimetype = item->mimetype;
_edi_editor_statusbar_add(statusbar, editor, item);
edi_editor_statusbar_add(statusbar, editor, item);
return vbox;
}
@ -1522,7 +1522,7 @@ edi_editor_add(Evas_Object *parent, Edi_Mainview_Item *item)
elm_box_pack_end(box, widget);
edi_editor_search_add(searchbar, editor);
_edi_editor_statusbar_add(statusbar, editor, item);
edi_editor_statusbar_add(statusbar, editor, item);
e = evas_object_evas_get(widget);
ctrl = evas_key_modifier_mask_get(e, "Control");

View File

@ -166,6 +166,16 @@ void edi_editor_doc_open(Edi_Editor *editor);
*/
void edi_editor_widget_config_get(Elm_Code_Widget *widget);
/**
* Add a statusbar to the panel for displaying statistics about loaded content.
*
* @param panel the panel in which the content resides and into which the statusbar is shown.
* @param editor the editor object.
* @param item the item containing information about the file's content.
*
* @ingroup Widgets
*/
void edi_editor_statusbar_add(Evas_Object *panel, Edi_Editor *editor, Edi_Mainview_Item *item);
/**
* @}

View File

@ -5,6 +5,8 @@ src = files([
'edi_config.h',
'edi_consolepanel.c',
'edi_consolepanel.h',
'edi_content.c',
'edi_content.h',
'edi_content_provider.c',
'edi_content_provider.h',
'edi_debug.c',

View File

@ -15,7 +15,13 @@ edi_editor_add(Evas_Object *parent EINA_UNUSED, Edi_Mainview_Item *item EINA_UNU
}
EAPI Evas_Object *
edi_editor_image_add(Evas_Object *parent EINA_UNUSED, Edi_Mainview_Item *item EINA_UNUSED)
edi_content_image_add(Evas_Object *parent EINA_UNUSED, Edi_Mainview_Item *item EINA_UNUSED)
{
return NULL;
}
EAPI Evas_Object *
edi_content_diff_add(Evas_Object *parent EINA_UNUSED, Edi_Mainview_Item *item EINA_UNUSED)
{
return NULL;
}