forked from enlightenment/edi
[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.
This commit is contained in:
parent
5a3769b082
commit
557fb79396
9
NEWS
9
NEWS
|
@ -1,3 +1,12 @@
|
|||
=======
|
||||
Edi 0.3
|
||||
=======
|
||||
|
||||
Features:
|
||||
|
||||
* Option to inserts spaces instead of tabs
|
||||
|
||||
|
||||
=======
|
||||
Edi 0.2
|
||||
=======
|
||||
|
|
|
@ -1006,6 +1006,30 @@ _elm_code_widget_text_at_cursor_insert(Elm_Code_Widget *widget, const char *text
|
|||
eo_event_callback_call(ELM_CODE_WIDGET_EVENT_CHANGED_USER, NULL));
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
@ -1445,6 +1471,19 @@ _elm_code_widget_show_whitespace_get(Eo *obj EINA_UNUSED, Elm_Code_Widget_Data *
|
|||
return pd->show_whitespace;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -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.]]
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
|
|
@ -60,6 +60,17 @@ _edi_settings_display_whitespace_cb(void *data EINA_UNUSED, Evas_Object *obj,
|
|||
_edi_project_config_save();
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -224,6 +235,16 @@ _edi_settings_display_create(Evas_Object *parent)
|
|||
elm_box_pack_end(hbox, spinner);
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue