ajwillia-ms pushed a commit to branch master.

http://git.enlightenment.org/tools/edi.git/commit/?id=2f0347b1085698bb259cc3b5267dbd4afdc822af

commit 2f0347b1085698bb259cc3b5267dbd4afdc822af
Author: Andy Williams <a...@andywilliams.me>
Date:   Sat Aug 29 14:46:18 2015 +0100

    [editor] Make whitespace trimming an option
    
    Add a global setting to turn off the behaviour
---
 elm_code/src/lib/elm_code_common.h |  7 +++++++
 elm_code/src/lib/elm_code_file.c   |  5 ++++-
 src/bin/edi_config.c               |  2 ++
 src/bin/edi_config.h               |  1 +
 src/bin/editor/edi_editor.c        |  5 +++++
 src/bin/screens/edi_settings.c     | 20 ++++++++++++++++++++
 6 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/elm_code/src/lib/elm_code_common.h 
b/elm_code/src/lib/elm_code_common.h
index 9c8ec5a..5efe685 100644
--- a/elm_code/src/lib/elm_code_common.h
+++ b/elm_code/src/lib/elm_code_common.h
@@ -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;
 };
 
 /**
diff --git a/elm_code/src/lib/elm_code_file.c b/elm_code/src/lib/elm_code_file.c
index 07ff643..5db1bfa 100644
--- a/elm_code/src/lib/elm_code_file.c
+++ b/elm_code/src/lib/elm_code_file.c
@@ -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);
 
diff --git a/src/bin/edi_config.c b/src/bin/edi_config.c
index 3153640..19c3404 100644
--- a/src/bin/edi_config.c
+++ b/src/bin/edi_config.c
@@ -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;
diff --git a/src/bin/edi_config.h b/src/bin/edi_config.h
index e93f1ec..f880ca7 100644
--- a/src/bin/edi_config.h
+++ b/src/bin/edi_config.h
@@ -39,6 +39,7 @@ struct _Edi_Config
    int version;
 
    Eina_Bool autosave;
+   Eina_Bool trim_whitespace;
 
    Eina_List *projects;
    Eina_List *mime_assocs;
diff --git a/src/bin/editor/edi_editor.c b/src/bin/editor/edi_editor.c
index 699c29f..e9d2fda 100644
--- a/src/bin/editor/edi_editor.c
+++ b/src/bin/editor/edi_editor.c
@@ -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),
diff --git a/src/bin/screens/edi_settings.c b/src/bin/screens/edi_settings.c
index f510ac0..24b3362 100644
--- a/src/bin/screens/edi_settings.c
+++ b/src/bin/screens/edi_settings.c
@@ -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;
 }
 

-- 


Reply via email to