zehortigoza pushed a commit to branch master.

http://git.enlightenment.org/apps/terminology.git/commit/?id=ae7e96633a74324d0a41ad58e71ef6e88acdf959

commit ae7e96633a74324d0a41ad58e71ef6e88acdf959
Author: José Roberto de Souza <jose.so...@intel.com>
Date:   Wed Mar 2 11:37:02 2016 -0300

    Allow user to set the title of the each tab
---
 AUTHORS              |  2 +-
 src/bin/controls.c   | 12 ++++++++++++
 src/bin/termio.c     | 16 ++++++++++++++++
 src/bin/termio.h     |  1 +
 src/bin/termpty.c    |  1 +
 src/bin/termpty.h    |  2 +-
 src/bin/termptyesc.c |  3 ++-
 src/bin/win.c        | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/bin/win.h        |  1 +
 9 files changed, 89 insertions(+), 3 deletions(-)

diff --git a/AUTHORS b/AUTHORS
index 97d20c3..b159de5 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -23,7 +23,7 @@ Kai Huuhko <kai.huu...@gmail.com>
 Mike McCormack <m...@atratus.org>
 Iván Briano <ivan.bri...@intel.com>
 Jerome Pinot <ngc...@gmail.com>
-José Roberto de Souza <zehortig...@profusion.mobi>
+José Roberto de Souza <zehortig...@gmail.com>
 Leandro Pereira <lean...@profusion.mobi>
 Leif Middelschulte <leif.middelschu...@gmail.com>
 Markus Törnqvist <m...@fadconsulting.com>
diff --git a/src/bin/controls.c b/src/bin/controls.c
index d75041a..c9a62b3 100644
--- a/src/bin/controls.c
+++ b/src/bin/controls.c
@@ -92,6 +92,12 @@ _cb_ct_miniview(void *data EINA_UNUSED, Evas_Object *obj 
EINA_UNUSED, void *even
 }
 
 static void
+_cb_ct_set_title(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void 
*event EINA_UNUSED)
+{
+    term_set_title(termio_term_get(ct_term));
+}
+
+static void
 _cb_ct_close(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event 
EINA_UNUSED)
 {
    term_close(ct_win, ct_term, EINA_FALSE);
@@ -277,6 +283,12 @@ controls_toggle(Evas_Object *win, Evas_Object *bg, 
Evas_Object *term,
         o = _button_add(win, _("Miniview"), "mini-view", _cb_ct_miniview, 
NULL);
         elm_box_pack_end(ct_box, o);
 
+        o = _sep_add_h(win);
+        elm_box_pack_end(ct_box, o);
+
+        o = _button_add(win, _("Set title"), "document-edit", 
_cb_ct_set_title, NULL);
+        elm_box_pack_end(ct_box, o);
+
         o = _sep_add_v(win);
         elm_box_pack_end(ct_boxh, o);
 
diff --git a/src/bin/termio.c b/src/bin/termio.c
index 20d5759..2d3a941 100644
--- a/src/bin/termio.c
+++ b/src/bin/termio.c
@@ -348,9 +348,25 @@ termio_title_get(Evas_Object *obj)
 {
    Termio *sd = evas_object_smart_data_get(obj);
    EINA_SAFETY_ON_NULL_RETURN_VAL(sd, NULL);
+   if (sd->pty->prop.user_title)
+     return sd->pty->prop.user_title;
    return sd->pty->prop.title;
 }
 
+void
+termio_user_title_set(Evas_Object *obj, const char *title)
+{
+    Termio *sd = evas_object_smart_data_get(obj);
+    EINA_SAFETY_ON_NULL_RETURN(sd);
+
+    if (sd->pty->prop.user_title)
+      eina_stringshare_del(sd->pty->prop.user_title);
+
+    sd->pty->prop.user_title = eina_stringshare_add(title);
+    if (sd->pty->cb.set_title.func)
+      sd->pty->cb.set_title.func(sd->pty->cb.set_title.data);
+}
+
 const char *
 termio_icon_name_get(Evas_Object *obj)
 {
diff --git a/src/bin/termio.h b/src/bin/termio.h
index e4d8df6..3b660e9 100644
--- a/src/bin/termio.h
+++ b/src/bin/termio.h
@@ -35,6 +35,7 @@ Eina_Bool    termio_cwd_get(const Evas_Object *obj, char 
*buf, size_t size);
 Evas_Object *termio_textgrid_get(Evas_Object *obj);
 Evas_Object *termio_win_get(Evas_Object *obj);
 const char  *termio_title_get(Evas_Object *obj);
+void         termio_user_title_set(Evas_Object *obj, const char *title);
 const char  *termio_icon_name_get(Evas_Object *obj);
 void         termio_media_mute_set(Evas_Object *obj, Eina_Bool mute);
 void         termio_media_visualize_set(Evas_Object *obj, Eina_Bool visualize);
diff --git a/src/bin/termpty.c b/src/bin/termpty.c
index 612c0e9..d9373ae 100644
--- a/src/bin/termpty.c
+++ b/src/bin/termpty.c
@@ -603,6 +603,7 @@ termpty_free(Termpty *ty)
    if (ty->hand_exe_exit) ecore_event_handler_del(ty->hand_exe_exit);
    if (ty->hand_fd) ecore_main_fd_handler_del(ty->hand_fd);
    if (ty->prop.title) eina_stringshare_del(ty->prop.title);
+   if (ty->prop.user_title) eina_stringshare_del(ty->prop.user_title);
    if (ty->prop.icon) eina_stringshare_del(ty->prop.icon);
    if (ty->back)
      {
diff --git a/src/bin/termpty.h b/src/bin/termpty.h
index e841245..ac1f553 100644
--- a/src/bin/termpty.h
+++ b/src/bin/termpty.h
@@ -85,7 +85,7 @@ struct _Termpty
       } change, set_title, set_icon, cancel_sel, exited, bell, command;
    } cb;
    struct {
-      const char *title, *icon;
+      const char *title, *icon, *user_title;
    } prop;
    const char *cur_cmd;
    Termcell *screen, *screen2;
diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c
index 3b0552f..0daeda4 100644
--- a/src/bin/termptyesc.c
+++ b/src/bin/termptyesc.c
@@ -1326,7 +1326,8 @@ _handle_esc_xterm(Termpty *ty, const Eina_Unicode *c, 
Eina_Unicode *ce)
                   ty->prop.title = NULL;
                   ty->prop.icon = NULL;
                }
-             if (ty->cb.set_title.func) 
ty->cb.set_title.func(ty->cb.set_title.data);
+             if (ty->cb.set_title.func && !ty->prop.user_title)
+               ty->cb.set_title.func(ty->cb.set_title.data);
              if (ty->cb.set_icon.func) 
ty->cb.set_icon.func(ty->cb.set_icon.data);
           }
         break;
diff --git a/src/bin/win.c b/src/bin/win.c
index d31af83..3da03b2 100644
--- a/src/bin/win.c
+++ b/src/bin/win.c
@@ -3220,6 +3220,60 @@ term_miniview_toggle(Term *term)
 }
 
 static void
+_set_title_ok_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info 
EINA_UNUSED)
+{
+    Evas_Object *popup = data;
+    Term *term = evas_object_data_get(popup, "term");
+    Evas_Object *entry = elm_object_content_get(popup);
+    const char *title = elm_entry_entry_get(entry);
+
+    if (!title || !strlen(title))
+      title = NULL;
+
+    termio_user_title_set(term->termio, title);
+    evas_object_del(popup);
+}
+
+static void
+_set_title_cancel_cb(void *data, Evas_Object *obj EINA_UNUSED, void 
*event_info EINA_UNUSED)
+{
+    evas_object_del(data);
+}
+
+void
+term_set_title(Term *term)
+{
+    Evas_Object *o;
+    Evas_Object *popup;
+
+    EINA_SAFETY_ON_NULL_RETURN(term);
+
+    popup = elm_popup_add(term->wn->win);
+    evas_object_data_set(popup, "term", term);
+    elm_object_part_text_set(popup, "title,text", _("Set title"));
+
+    o = elm_button_add(popup);
+    evas_object_smart_callback_add(o, "clicked", _set_title_ok_cb, popup);
+    elm_object_text_set(o, _("Ok"));
+    elm_object_part_content_set(popup, "button1", o);
+
+    o = elm_button_add(popup);
+    evas_object_smart_callback_add(o, "clicked", _set_title_cancel_cb, popup);
+    elm_object_text_set(o, _("Cancel"));
+    elm_object_part_content_set(popup, "button2", o);
+
+    o = elm_entry_add(popup);
+    elm_entry_single_line_set(o, EINA_TRUE);
+    evas_object_smart_callback_add(o, "activated", _set_title_ok_cb, popup);
+    evas_object_smart_callback_add(o, "aborted", _set_title_cancel_cb, popup);
+    elm_object_content_set(popup, o);
+    evas_object_show(o);
+    elm_object_focus_set(o, EINA_TRUE);
+
+    evas_object_show(popup);
+}
+
+static void
 _popmedia_queue_process(Term *term)
 {
    const char *src;
diff --git a/src/bin/win.h b/src/bin/win.h
index 62c3c4b..9c5a91e 100644
--- a/src/bin/win.h
+++ b/src/bin/win.h
@@ -14,6 +14,7 @@ void term_unfocus(Term *term);
 Evas_Object *term_termio_get(Term *term);
 Evas_Object *term_miniview_get(Term *term);
 void term_miniview_toggle(Term *term);
+void term_set_title(Term *term);
 void term_miniview_hide(Term *term);
 Eina_Bool term_tab_go(Term *term, int tnum);
 

-- 


Reply via email to