forked from enlightenment/edi
Begin factoring out the text editor from the mainview code
This commit is contained in:
parent
dd4759d1b1
commit
d2117bac25
|
@ -11,6 +11,7 @@ AM_CPPFLAGS = -DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \
|
||||||
|
|
||||||
edi_SOURCES = \
|
edi_SOURCES = \
|
||||||
editor/edi_editor_search.c \
|
editor/edi_editor_search.c \
|
||||||
|
editor/edi_editor.c \
|
||||||
edi_filepanel.c \
|
edi_filepanel.c \
|
||||||
edi_logpanel.c \
|
edi_logpanel.c \
|
||||||
edi_consolepanel.c \
|
edi_consolepanel.c \
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
|
|
||||||
#include "edi_mainview.h"
|
#include "edi_mainview.h"
|
||||||
|
|
||||||
|
#include "editor/edi_editor.h"
|
||||||
|
|
||||||
#include "edi_private.h"
|
#include "edi_private.h"
|
||||||
|
|
||||||
static Evas_Object *nf, *tb, *_main_win;
|
static Evas_Object *nf, *tb, *_main_win;
|
||||||
|
@ -22,7 +24,7 @@ dummy()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
EAPI void
|
EAPI void
|
||||||
_edi_mainview_item_prev()
|
edi_mainview_item_prev()
|
||||||
{
|
{
|
||||||
Eina_List *item;
|
Eina_List *item;
|
||||||
Elm_Object_Item *current;
|
Elm_Object_Item *current;
|
||||||
|
@ -43,7 +45,7 @@ _edi_mainview_item_prev()
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI void
|
EAPI void
|
||||||
_edi_mainview_item_next()
|
edi_mainview_item_next()
|
||||||
{
|
{
|
||||||
Eina_List *item;
|
Eina_List *item;
|
||||||
Elm_Object_Item *current;
|
Elm_Object_Item *current;
|
||||||
|
@ -116,72 +118,6 @@ _edi_mainview_item_add(const char *path, Elm_Object_Item *tab, Evas_Object *view
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
_smart_cb_key_down(void *data, Evas *e EINA_UNUSED,
|
|
||||||
Evas_Object *obj EINA_UNUSED, void *event)
|
|
||||||
{
|
|
||||||
Eina_Bool ctrl, alt, shift;
|
|
||||||
Evas_Event_Key_Down *ev = event;
|
|
||||||
|
|
||||||
ctrl = evas_key_modifier_is_set(ev->modifiers, "Control");
|
|
||||||
alt = evas_key_modifier_is_set(ev->modifiers, "Alt");
|
|
||||||
shift = evas_key_modifier_is_set(ev->modifiers, "Shift");
|
|
||||||
|
|
||||||
if ((!alt) && (ctrl) && (!shift))
|
|
||||||
{
|
|
||||||
if (!strcmp(ev->key, "Prior"))
|
|
||||||
{
|
|
||||||
_edi_mainview_item_prev();
|
|
||||||
}
|
|
||||||
else if (!strcmp(ev->key, "Next"))
|
|
||||||
{
|
|
||||||
_edi_mainview_item_next();
|
|
||||||
}
|
|
||||||
else if (!strcmp(ev->key, "s"))
|
|
||||||
{
|
|
||||||
edi_mainview_save();
|
|
||||||
}
|
|
||||||
else if (!strcmp(ev->key, "f"))
|
|
||||||
{
|
|
||||||
edi_mainview_search();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static Evas_Object *
|
|
||||||
_edi_mainview_content_text_create(const char *path, Evas_Object *parent)
|
|
||||||
{
|
|
||||||
Evas_Object *txt;
|
|
||||||
Evas_Modifier_Mask ctrl, shift, alt;
|
|
||||||
Evas *e;
|
|
||||||
|
|
||||||
txt = elm_entry_add(parent);
|
|
||||||
elm_entry_editable_set(txt, EINA_TRUE);
|
|
||||||
elm_entry_scrollable_set(txt, EINA_TRUE);
|
|
||||||
elm_entry_line_wrap_set(txt, EINA_FALSE);
|
|
||||||
elm_entry_text_style_user_push(txt, "DEFAULT='font=Monospace font_size=12'");
|
|
||||||
elm_entry_file_set(txt, 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);
|
|
||||||
evas_object_show(txt);
|
|
||||||
|
|
||||||
evas_object_event_callback_add(txt, EVAS_CALLBACK_KEY_DOWN,
|
|
||||||
_smart_cb_key_down, txt);
|
|
||||||
|
|
||||||
e = evas_object_evas_get(txt);
|
|
||||||
ctrl = evas_key_modifier_mask_get(e, "Control");
|
|
||||||
alt = evas_key_modifier_mask_get(e, "Alt");
|
|
||||||
shift = evas_key_modifier_mask_get(e, "Shift");
|
|
||||||
|
|
||||||
evas_object_key_grab(txt, "Prior", ctrl, shift | alt, 1);
|
|
||||||
evas_object_key_grab(txt, "Next", ctrl, shift | alt, 1);
|
|
||||||
evas_object_key_grab(txt, "s", ctrl, shift | alt, 1);
|
|
||||||
evas_object_key_grab(txt, "f", ctrl, shift | alt, 1);
|
|
||||||
|
|
||||||
return txt;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Evas_Object *
|
static Evas_Object *
|
||||||
_edi_mainview_content_image_create(const char *path, Evas_Object *parent)
|
_edi_mainview_content_image_create(const char *path, Evas_Object *parent)
|
||||||
{
|
{
|
||||||
|
@ -205,7 +141,7 @@ _edi_mainview_content_create(const char *path, const char *type, Evas_Object *pa
|
||||||
{
|
{
|
||||||
if (!strcmp(type, "text"))
|
if (!strcmp(type, "text"))
|
||||||
{
|
{
|
||||||
return _edi_mainview_content_text_create(path, parent);
|
return edi_editor_add(parent, path);
|
||||||
}
|
}
|
||||||
else if (!strcmp(type, "image"))
|
else if (!strcmp(type, "image"))
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,80 @@
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <libgen.h>
|
||||||
|
|
||||||
|
#include <Eina.h>
|
||||||
|
#include <Eio.h>
|
||||||
|
|
||||||
|
#include "edi_editor.h"
|
||||||
|
|
||||||
|
#include "edi_mainview.h"
|
||||||
|
|
||||||
|
#include "edi_private.h"
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
_smart_cb_key_down(void *data, Evas *e EINA_UNUSED,
|
||||||
|
Evas_Object *obj EINA_UNUSED, void *event)
|
||||||
|
{
|
||||||
|
Eina_Bool ctrl, alt, shift;
|
||||||
|
Evas_Event_Key_Down *ev = event;
|
||||||
|
|
||||||
|
ctrl = evas_key_modifier_is_set(ev->modifiers, "Control");
|
||||||
|
alt = evas_key_modifier_is_set(ev->modifiers, "Alt");
|
||||||
|
shift = evas_key_modifier_is_set(ev->modifiers, "Shift");
|
||||||
|
|
||||||
|
if ((!alt) && (ctrl) && (!shift))
|
||||||
|
{
|
||||||
|
if (!strcmp(ev->key, "Prior"))
|
||||||
|
{
|
||||||
|
edi_mainview_item_prev();
|
||||||
|
}
|
||||||
|
else if (!strcmp(ev->key, "Next"))
|
||||||
|
{
|
||||||
|
edi_mainview_item_next();
|
||||||
|
}
|
||||||
|
else if (!strcmp(ev->key, "s"))
|
||||||
|
{
|
||||||
|
edi_mainview_save();
|
||||||
|
}
|
||||||
|
else if (!strcmp(ev->key, "f"))
|
||||||
|
{
|
||||||
|
edi_mainview_search();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EAPI Evas_Object *edi_editor_add(Evas_Object *parent, const char *path)
|
||||||
|
{
|
||||||
|
Evas_Object *txt;
|
||||||
|
Evas_Modifier_Mask ctrl, shift, alt;
|
||||||
|
Evas *e;
|
||||||
|
|
||||||
|
txt = elm_entry_add(parent);
|
||||||
|
elm_entry_editable_set(txt, EINA_TRUE);
|
||||||
|
elm_entry_scrollable_set(txt, EINA_TRUE);
|
||||||
|
elm_entry_line_wrap_set(txt, EINA_FALSE);
|
||||||
|
elm_entry_text_style_user_push(txt, "DEFAULT='font=Monospace font_size=12'");
|
||||||
|
elm_entry_file_set(txt, 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);
|
||||||
|
evas_object_show(txt);
|
||||||
|
|
||||||
|
evas_object_event_callback_add(txt, EVAS_CALLBACK_KEY_DOWN,
|
||||||
|
_smart_cb_key_down, txt);
|
||||||
|
|
||||||
|
e = evas_object_evas_get(txt);
|
||||||
|
ctrl = evas_key_modifier_mask_get(e, "Control");
|
||||||
|
alt = evas_key_modifier_mask_get(e, "Alt");
|
||||||
|
shift = evas_key_modifier_mask_get(e, "Shift");
|
||||||
|
|
||||||
|
evas_object_key_grab(txt, "Prior", ctrl, shift | alt, 1);
|
||||||
|
evas_object_key_grab(txt, "Next", ctrl, shift | alt, 1);
|
||||||
|
evas_object_key_grab(txt, "s", ctrl, shift | alt, 1);
|
||||||
|
evas_object_key_grab(txt, "f", ctrl, shift | alt, 1);
|
||||||
|
|
||||||
|
return txt;
|
||||||
|
}
|
|
@ -13,6 +13,27 @@ extern "C" {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @brief Editor.
|
||||||
|
* @defgroup Editor The main text editor functions
|
||||||
|
*
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
* @return the created evas object that contains the editor.
|
||||||
|
*
|
||||||
|
* @ingroup Editor
|
||||||
|
*/
|
||||||
|
EAPI Evas_Object *edi_editor_add(Evas_Object *parent, const char *path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*
|
||||||
* @brief Dialogs.
|
* @brief Dialogs.
|
||||||
* @defgroup Dialogs Functions that open other dialogs
|
* @defgroup Dialogs Functions that open other dialogs
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue