forked from enlightenment/edi
[editor] Make whitespace trimming an option
Add a global setting to turn off the behaviour
This commit is contained in:
parent
fdd2a69333
commit
2f0347b108
|
@ -61,11 +61,18 @@ extern "C" {
|
|||
* @brief Common data structures and constants.
|
||||
*/
|
||||
|
||||
struct _Elm_Code_Config
|
||||
{
|
||||
Eina_Bool trim_whitespace;
|
||||
};
|
||||
|
||||
struct _Elm_Code
|
||||
{
|
||||
Elm_Code_File *file;
|
||||
Eina_List *widgets;
|
||||
Eina_List *parsers;
|
||||
|
||||
struct _Elm_Code_Config config;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -158,6 +158,7 @@ EAPI Elm_Code_File *elm_code_file_open(Elm_Code *code, const char *path)
|
|||
EAPI void elm_code_file_save(Elm_Code_File *file)
|
||||
{
|
||||
Eina_List *item;
|
||||
Elm_Code *code;
|
||||
Elm_Code_Line *line_item;
|
||||
const char *path, *content, *crchars;
|
||||
char *tmp;
|
||||
|
@ -165,6 +166,7 @@ EAPI void elm_code_file_save(Elm_Code_File *file)
|
|||
short crlength;
|
||||
FILE *out;
|
||||
|
||||
code = file->parent;
|
||||
path = elm_code_file_path_get(file);
|
||||
tmp = _elm_code_file_tmp_path_get(file);
|
||||
crchars = elm_code_file_line_ending_chars_get(file, &crlength);
|
||||
|
@ -178,7 +180,8 @@ EAPI void elm_code_file_save(Elm_Code_File *file)
|
|||
|
||||
EINA_LIST_FOREACH(file->lines, item, line_item)
|
||||
{
|
||||
if (!elm_code_line_contains_widget_cursor(line_item))
|
||||
if (code && code->config.trim_whitespace &&
|
||||
!elm_code_line_contains_widget_cursor(line_item))
|
||||
elm_code_line_text_trailing_whitespace_strip(line_item);
|
||||
content = elm_code_line_text_get(line_item, &length);
|
||||
|
||||
|
|
|
@ -217,6 +217,7 @@ _edi_config_init(void)
|
|||
#define D _edi_cfg_edd
|
||||
EDI_CONFIG_VAL(D, T, version, EET_T_INT);
|
||||
EDI_CONFIG_VAL(D, T, autosave, EET_T_UCHAR);
|
||||
EDI_CONFIG_VAL(D, T, trim_whitespace, EET_T_UCHAR);
|
||||
|
||||
EDI_CONFIG_LIST(D, T, projects, _edi_cfg_proj_edd);
|
||||
EDI_CONFIG_LIST(D, T, mime_assocs, _edi_cfg_mime_edd);
|
||||
|
@ -317,6 +318,7 @@ _edi_config_load(void)
|
|||
IFCFG(0x000c);
|
||||
|
||||
_edi_config->autosave = EINA_TRUE;
|
||||
_edi_config->trim_whitespace = EINA_TRUE;
|
||||
_edi_config->projects = NULL;
|
||||
_edi_config->mime_assocs = NULL;
|
||||
IFCFGEND;
|
||||
|
|
|
@ -39,6 +39,7 @@ struct _Edi_Config
|
|||
int version;
|
||||
|
||||
Eina_Bool autosave;
|
||||
Eina_Bool trim_whitespace;
|
||||
|
||||
Eina_List *projects;
|
||||
Eina_List *mime_assocs;
|
||||
|
|
|
@ -572,8 +572,13 @@ static Eina_Bool
|
|||
_edi_editor_config_changed(void *data, int type EINA_UNUSED, void *event EINA_UNUSED)
|
||||
{
|
||||
Elm_Code_Widget *widget;
|
||||
Elm_Code *code;
|
||||
|
||||
widget = (Elm_Code_Widget *) data;
|
||||
code = elm_code_widget_code_get(widget);
|
||||
|
||||
code->config.trim_whitespace = _edi_config->trim_whitespace;
|
||||
|
||||
eo_do(widget,
|
||||
elm_obj_code_widget_font_set(_edi_project_config->font.name, _edi_project_config->font.size),
|
||||
elm_obj_code_widget_show_whitespace_set(_edi_project_config->gui.show_whitespace),
|
||||
|
|
|
@ -352,6 +352,17 @@ _edi_settings_behaviour_autosave_cb(void *data EINA_UNUSED, Evas_Object *obj,
|
|||
_edi_config_save();
|
||||
}
|
||||
|
||||
static void
|
||||
_edi_settings_behaviour_trim_whitespace_cb(void *data EINA_UNUSED, Evas_Object *obj,
|
||||
void *event EINA_UNUSED)
|
||||
{
|
||||
Evas_Object *check;
|
||||
|
||||
check = (Evas_Object *)obj;
|
||||
_edi_config->trim_whitespace = elm_check_state_get(check);
|
||||
_edi_config_save();
|
||||
}
|
||||
|
||||
static Evas_Object *
|
||||
_edi_settings_behaviour_create(Evas_Object *parent)
|
||||
{
|
||||
|
@ -369,6 +380,15 @@ _edi_settings_behaviour_create(Evas_Object *parent)
|
|||
_edi_settings_behaviour_autosave_cb, NULL);
|
||||
evas_object_show(check);
|
||||
|
||||
check = elm_check_add(box);
|
||||
elm_object_text_set(check, "Trim trailing whitespace");
|
||||
elm_check_state_set(check, _edi_config->trim_whitespace);
|
||||
elm_box_pack_end(box, check);
|
||||
evas_object_size_hint_align_set(check, EVAS_HINT_FILL, 0.5);
|
||||
evas_object_smart_callback_add(check, "changed",
|
||||
_edi_settings_behaviour_trim_whitespace_cb, NULL);
|
||||
evas_object_show(check);
|
||||
|
||||
return frame;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue