ajwillia-ms pushed a commit to branch master.

http://git.enlightenment.org/tools/edi.git/commit/?id=557fb793969a821c7813de045aaea8e8003b32bb

commit 557fb793969a821c7813de045aaea8e8003b32bb
Author: Andy Williams <a...@andywilliams.me>
Date:   Tue Feb 9 00:32:16 2016 +0000

    [editor] Support space insertion instead of tabs
    
    Elm_Code support and option in Edi to use spaces when the
    Tab key is pressed - make this default too.
---
 NEWS                                              |  9 ++++++
 elm_code/src/lib/widget/elm_code_widget.c         | 39 +++++++++++++++++++++++
 elm_code/src/lib/widget/elm_code_widget.eo        | 11 +++++++
 elm_code/src/lib/widget/elm_code_widget_private.h |  2 +-
 src/bin/edi_config.c                              |  7 +++-
 src/bin/edi_config.h                              |  1 +
 src/bin/editor/edi_editor.c                       |  1 +
 src/bin/screens/edi_settings.c                    | 21 ++++++++++++
 8 files changed, 89 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index 84b0d2b..aa7d723 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,13 @@
 =======
+Edi 0.3
+=======
+
+Features:
+
+  * Option to inserts spaces instead of tabs
+
+
+=======
 Edi 0.2
 =======
 
diff --git a/elm_code/src/lib/widget/elm_code_widget.c 
b/elm_code/src/lib/widget/elm_code_widget.c
index 98811bd..a6cde05 100644
--- a/elm_code/src/lib/widget/elm_code_widget.c
+++ b/elm_code/src/lib/widget/elm_code_widget.c
@@ -1007,6 +1007,30 @@ _elm_code_widget_text_at_cursor_insert(Elm_Code_Widget 
*widget, const char *text
 }
 
 static void
+_elm_code_widget_tab_at_cursor_insert(Elm_Code_Widget *widget)
+{
+   Elm_Code_Widget_Data *pd;
+   unsigned int col, row;
+
+   pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS);
+   if (!pd->tab_inserts_spaces)
+     {
+        _elm_code_widget_text_at_cursor_insert(widget, "\t", 1);
+        return;
+     }
+
+   eo_do(widget,
+         elm_obj_code_widget_cursor_position_get(&col, &row));
+   col = (col - 1) % pd->tabstop;
+
+   while (col < pd->tabstop)
+     {
+        _elm_code_widget_text_at_cursor_insert(widget, " ", 1);
+        col++;
+     }
+}
+
+static void
 _elm_code_widget_newline(Elm_Code_Widget *widget)
 {
    Elm_Code *code;
@@ -1215,6 +1239,8 @@ _elm_code_widget_key_down_cb(void *data, Evas *evas 
EINA_UNUSED,
      _elm_code_widget_backspace(widget);
    else if (!strcmp(ev->key, "Delete"))
      _elm_code_widget_delete(widget);
+   else if (!strcmp(ev->key, "Tab"))
+     _elm_code_widget_tab_at_cursor_insert(widget);
 
    else if (ev->string && strlen(ev->string) == 1)
      _elm_code_widget_text_at_cursor_insert(widget, ev->string, 1);
@@ -1446,6 +1472,19 @@ _elm_code_widget_show_whitespace_get(Eo *obj 
EINA_UNUSED, Elm_Code_Widget_Data *
 }
 
 EOLIAN static void
+_elm_code_widget_tab_inserts_spaces_set(Eo *obj, Elm_Code_Widget_Data *pd, 
Eina_Bool spaces)
+{
+   pd->tab_inserts_spaces = spaces;
+   _elm_code_widget_fill(obj);
+}
+
+EOLIAN static Eina_Bool
+_elm_code_widget_tab_inserts_spaces_get(Eo *obj EINA_UNUSED, 
Elm_Code_Widget_Data *pd)
+{
+   return pd->tab_inserts_spaces;
+}
+
+EOLIAN static void
 _elm_code_widget_cursor_position_set(Eo *obj, Elm_Code_Widget_Data *pd, 
unsigned int col, unsigned int line)
 {
    _elm_code_widget_cursor_move(obj, pd, col, line, EINA_FALSE);
diff --git a/elm_code/src/lib/widget/elm_code_widget.eo 
b/elm_code/src/lib/widget/elm_code_widget.eo
index 1bbcc18..0e11331 100644
--- a/elm_code/src/lib/widget/elm_code_widget.eo
+++ b/elm_code/src/lib/widget/elm_code_widget.eo
@@ -130,6 +130,17 @@ class Elm.Code_Widget (Elm.Layout, 
Elm_Interface_Atspi_Text)
             show_whitespace: Eina_Bool; [[Whether or not we show whitespace 
characters]]
          }
       }
+      @property tab_inserts_spaces {
+         set {
+            [[Set whether space characters should be inserted instead of 
tabs.]]
+         }
+         get {
+            [[Get whether or not space characters will be inserted instead of 
tabs.]]
+         }
+         values {
+            tab_inserts_spaces: Eina_Bool; [[EINA_TRUE if we should insert 
space characters instead of a tab when the Tab key is pressed]]
+         }
+      }
       @property cursor_position {
          set {
             [[Set the current location of the text cursor.]]
diff --git a/elm_code/src/lib/widget/elm_code_widget_private.h 
b/elm_code/src/lib/widget/elm_code_widget_private.h
index b89973f..b9f8ad2 100644
--- a/elm_code/src/lib/widget/elm_code_widget_private.h
+++ b/elm_code/src/lib/widget/elm_code_widget_private.h
@@ -23,7 +23,7 @@ typedef struct
    Eina_Bool editable, focussed;
    Eina_Bool show_line_numbers;
    unsigned int line_width_marker, tabstop;
-   Eina_Bool show_whitespace;
+   Eina_Bool show_whitespace, tab_inserts_spaces;
 
    Elm_Code_Widget_Selection_Data *selection;
    Evas_Object *tooltip;
diff --git a/src/bin/edi_config.c b/src/bin/edi_config.c
index 19c3404..246f390 100644
--- a/src/bin/edi_config.c
+++ b/src/bin/edi_config.c
@@ -39,7 +39,7 @@
    ((EDI_CONFIG_FILE_EPOCH << 16) | EDI_CONFIG_FILE_GENERATION)
 
 #  define EDI_PROJECT_CONFIG_FILE_EPOCH 0x0001
-#  define EDI_PROJECT_CONFIG_FILE_GENERATION 0x0002
+#  define EDI_PROJECT_CONFIG_FILE_GENERATION 0x0003
 #  define EDI_PROJECT_CONFIG_FILE_VERSION \
    ((EDI_PROJECT_CONFIG_FILE_EPOCH << 16) | EDI_PROJECT_CONFIG_FILE_GENERATION)
 
@@ -250,6 +250,7 @@ _edi_config_init(void)
    EDI_CONFIG_VAL(D, T, gui.width_marker, EET_T_UINT);
    EDI_CONFIG_VAL(D, T, gui.tabstop, EET_T_UINT);
    EDI_CONFIG_VAL(D, T, gui.toolbar_hidden, EET_T_UCHAR);
+   EDI_CONFIG_VAL(D, T, gui.tab_inserts_spaces, EET_T_UCHAR);
 
    EDI_CONFIG_LIST(D, T, tabs, _edi_proj_cfg_tab_edd);
    EDI_CONFIG_VAL(D, T, launch.path, EET_T_STRING);
@@ -461,6 +462,10 @@ _edi_project_config_load()
    _edi_project_config->font.size = 12;
    IFPCFGEND;
 
+   IFPCFG(0x0003);
+   _edi_project_config->gui.tab_inserts_spaces = EINA_TRUE;
+   IFPCFGEND;
+
    /* limit config values so they are sane */
    EDI_CONFIG_LIMIT(_edi_project_config->font.size, EDI_FONT_MIN, 
EDI_FONT_MAX);
    EDI_CONFIG_LIMIT(_edi_project_config->gui.width, 150, 10000);
diff --git a/src/bin/edi_config.h b/src/bin/edi_config.h
index f880ca7..4b6cbc3 100644
--- a/src/bin/edi_config.h
+++ b/src/bin/edi_config.h
@@ -77,6 +77,7 @@ struct _Edi_Project_Config
         unsigned int width_marker, tabstop;
 
         Eina_Bool toolbar_hidden;
+        Eina_Bool tab_inserts_spaces;
      } gui;
 
    Eina_List *tabs;
diff --git a/src/bin/editor/edi_editor.c b/src/bin/editor/edi_editor.c
index e9d2fda..0fc4bb2 100644
--- a/src/bin/editor/edi_editor.c
+++ b/src/bin/editor/edi_editor.c
@@ -582,6 +582,7 @@ _edi_editor_config_changed(void *data, int type 
EINA_UNUSED, void *event EINA_UN
    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),
+         
elm_obj_code_widget_tab_inserts_spaces_set(_edi_project_config->gui.tab_inserts_spaces),
          
elm_obj_code_widget_line_width_marker_set(_edi_project_config->gui.width_marker),
          elm_obj_code_widget_tabstop_set(_edi_project_config->gui.tabstop));
 
diff --git a/src/bin/screens/edi_settings.c b/src/bin/screens/edi_settings.c
index 24b3362..482d320 100644
--- a/src/bin/screens/edi_settings.c
+++ b/src/bin/screens/edi_settings.c
@@ -61,6 +61,17 @@ _edi_settings_display_whitespace_cb(void *data EINA_UNUSED, 
Evas_Object *obj,
 }
 
 static void
+_edi_settings_display_tab_inserts_spaces_cb(void *data EINA_UNUSED, 
Evas_Object *obj,
+                                            void *event EINA_UNUSED)
+{
+   Evas_Object *check;
+
+   check = (Evas_Object *)obj;
+   _edi_project_config->gui.tab_inserts_spaces = elm_check_state_get(check);
+   _edi_project_config_save();
+}
+
+static void
 _edi_settings_display_widthmarker_cb(void *data EINA_UNUSED, Evas_Object *obj,
                                      void *event EINA_UNUSED)
 {
@@ -225,6 +236,16 @@ _edi_settings_display_create(Evas_Object *parent)
    evas_object_show(spinner);
 
    check = elm_check_add(box);
+   elm_object_text_set(check, "Insert spaces when tab is pressed");
+   elm_check_state_set(check, _edi_project_config->gui.tab_inserts_spaces);
+   elm_box_pack_end(box, check);
+   evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, 0.0);
+   evas_object_size_hint_align_set(check, 0.0, 0.5);
+   evas_object_smart_callback_add(check, "changed",
+                                  _edi_settings_display_tab_inserts_spaces_cb, 
NULL);
+   evas_object_show(check);
+
+   check = elm_check_add(box);
    elm_object_text_set(check, "Hide Toolbar");
    elm_check_state_set(check, _edi_project_config->gui.toolbar_hidden);
    elm_box_pack_end(box, check);

-- 


Reply via email to