Elm_Text_Format format;
Ecore_Timer *delay_write;
Eina_Bool can_write : 1;
- Eina_Bool auto_write : 1;
+ Eina_Bool autosave : 1;
};
static const char *widtype = NULL;
if (wd->delay_write)
{
ecore_timer_del(wd->delay_write);
- _save(obj);
+ if (wd->autosave) _save(obj);
}
free(wd);
}
char *buf2 = realloc(buf, *alloc + len2 + 512);
if (!buf2) return NULL;
buf = buf2;
- *alloc += 512 + len2;
+ *alloc += (512 + len2);
}
strcpy(buf + *len, str);
*len += len2;
FILE *f;
size_t size;
int alloc = 0, len = 0;
- char *text = NULL, buf[4096];
+ char *text = NULL, buf[PATH_MAX];
f = fopen(file, "rb");
if (!f) return NULL;
static char *
_load_plain(const char *file)
{
- char *text, *text2;
+ char *text;
text = _load_file(file);
if (text)
{
+ char *text2;
+
text2 = elm_entry_utf8_to_markup(text);
free(text);
return text2;
text = _load_file(wd->file);
break;
default:
- elm_entry_entry_set(wd->entry, "Unknown Text Format");
text = NULL;
+ break;
}
if (text)
{
}
}
-static int
+static Eina_Bool
_delay_write(void *data)
{
Widget_Data *wd = elm_widget_data_get(data);
- if (!wd) return 0;
+ if (!wd) return ECORE_CALLBACK_CANCEL;
_save(data);
wd->delay_write = NULL;
- return 0;
+ return ECORE_CALLBACK_CANCEL;
}
static void
ecore_timer_del(wd->delay_write);
wd->delay_write = NULL;
}
- if (!wd->auto_write) return;
+ if (!wd->autosave) return;
wd->delay_write = ecore_timer_add(2.0, _delay_write, data);
}
wd->scr = elm_scroller_add(parent);
elm_widget_resize_object_set(obj, wd->scr);
+
wd->entry = elm_entry_add(parent);
evas_object_size_hint_weight_set(wd->entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(wd->entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
- wd->auto_write = EINA_TRUE;
+ wd->autosave = EINA_TRUE;
_sizing_eval(obj);
return obj;
/**
* This sets the file (and implicitly loads it) for the text to display and
- * then edit. All changes are written back to the file after a short delay.
+ * then edit. All changes are written back to the file after a short delay if
+ * the notepad object is set to autosave.
*
* @param obj The notepad object
* @param file The path to the file to load and save
* @param format The file format
*
- *
* @ingroup Notepad
*/
EAPI void
ecore_timer_del(wd->delay_write);
wd->delay_write = NULL;
}
- _save(obj);
+ if (wd->autosave) _save(obj);
eina_stringshare_replace(&wd->file, file);
wd->format = format;
_load(obj);
}
/**
+ * This function writes any changes made to the file.
+ * All changes are written back to the file after a short delay.
+ *
+ * @param obj The notepad object
+ * @param file The path to the file to save
+ * @param format The file format
+ *
+ * @ingroup Notepad
+ */
+EAPI void
+elm_notepad_file_save(Evas_Object *obj, const char *file, Elm_Text_Format format)
+{
+ ELM_CHECK_WIDTYPE(obj, widtype);
+ Widget_Data *wd = elm_widget_data_get(obj);
+ if ((!wd) || (!file)) return;
+ if (wd->delay_write)
+ {
+ ecore_timer_del(wd->delay_write);
+ wd->delay_write = NULL;
+ }
+ wd->format = format;
+ eina_stringshare_replace(&wd->file, file);
+ wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
+}
+
+/**
* This will enable or disable the scroller bounce mode for the notepad. See
* elm_scroller_bounce_set() for details
*
if (!wd) return;
elm_scroller_bounce_set(wd->scr, h_bounce, v_bounce);
}
+
+/**
+ * This sets the notepad object to 'autosave' the loaded text file or not.
+ *
+ * @param obj The notepad object
+ * @param autosave Autosave the loaded file or not
+ *
+ * @ingroup Notepad
+ */
+EAPI void
+elm_notepad_autosave_set(Evas_Object *obj, Eina_Bool autosave)
+{
+ ELM_CHECK_WIDTYPE(obj, widtype);
+ Widget_Data *wd = elm_widget_data_get(obj);
+ if (!wd) return;
+ wd->autosave = autosave;
+}