controls: simplify code

terminology-1.2
Boris Faure 5 years ago
parent d20e32c26f
commit 080ff8e261
  1. 363
      src/bin/controls.c
  2. 4
      src/bin/controls.h
  3. 4
      src/bin/win.c

@ -1,6 +1,7 @@
#include "private.h"
#include <Elementary.h>
#include <assert.h>
#include "controls.h"
#include "options.h"
#include "about.h"
@ -9,12 +10,13 @@
static Evas_Object *ct_frame = NULL, *ct_boxh = NULL, *ct_boxv = NULL;
static Evas_Object *ct_box = NULL, *ct_box2 = NULL, *ct_box3 = NULL, *ct_over = NULL;
static Eina_Bool ct_out = EINA_FALSE;
static Ecore_Timer *ct_del_timer = NULL;
static Evas_Object *ct_win = NULL, *ct_bg = NULL, *ct_term = NULL;
static void (*ct_donecb) (void *data) = NULL;
static void *ct_donedata = NULL;
static void
controls_hide(Eina_Bool call_cb);
static void
_cb_sel_on(void *_data EINA_UNUSED,
Evas_Object *_term EINA_UNUSED,
@ -36,19 +38,10 @@ _cb_sel_off(void *_data EINA_UNUSED,
}
static Eina_Bool
_cb_ct_del_delay(void *_data EINA_UNUSED)
_cb_ct_del_delay(void *data)
{
if (ct_over)
{
evas_object_del(ct_over);
ct_over = NULL;
}
if (ct_frame)
{
evas_object_del(ct_frame);
ct_frame = NULL;
}
ct_del_timer = NULL;
Evas_Object *frame = data;
evas_object_del(frame);
elm_cache_all_flush();
return EINA_FALSE;
}
@ -58,8 +51,8 @@ _cb_ct_copy(void *_data EINA_UNUSED,
Evas_Object *_obj EINA_UNUSED,
void *_event EINA_UNUSED)
{
controls_hide(EINA_TRUE);
termio_take_selection(ct_term, ELM_SEL_TYPE_CLIPBOARD);
controls_toggle(ct_win, ct_bg, ct_term, ct_donecb, ct_donedata);
}
static void
@ -67,8 +60,8 @@ _cb_ct_paste(void *_data EINA_UNUSED,
Evas_Object *_obj EINA_UNUSED,
void *_event EINA_UNUSED)
{
controls_hide(EINA_TRUE);
termio_paste_selection(ct_term, ELM_SEL_TYPE_CLIPBOARD);
controls_toggle(ct_win, ct_bg, ct_term, ct_donecb, ct_donedata);
}
static void
@ -108,7 +101,8 @@ _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));
controls_hide(EINA_TRUE);
term_set_title(termio_term_get(ct_term));
}
static void
@ -116,6 +110,7 @@ _cb_ct_close(void *_data EINA_UNUSED,
Evas_Object *_obj EINA_UNUSED,
void *_event EINA_UNUSED)
{
controls_hide(EINA_TRUE);
term_close(ct_win, ct_term, EINA_FALSE);
}
@ -124,7 +119,7 @@ _cb_ct_options(void *_data EINA_UNUSED,
Evas_Object *_obj EINA_UNUSED,
void *_event EINA_UNUSED)
{
controls_toggle(ct_win, ct_bg, ct_term, ct_donecb, ct_donedata);
controls_hide(EINA_FALSE);
options_toggle(ct_win, ct_bg, ct_term, ct_donecb, ct_donedata);
}
@ -133,7 +128,7 @@ _cb_ct_about(void *_data EINA_UNUSED,
Evas_Object *_obj EINA_UNUSED,
void *_event EINA_UNUSED)
{
controls_toggle(ct_win, ct_bg, ct_term, ct_donecb, ct_donedata);
controls_hide(EINA_FALSE);
about_toggle(ct_win, ct_bg, ct_term, ct_donecb, ct_donedata);
}
@ -143,82 +138,34 @@ _cb_mouse_down(void *_data EINA_UNUSED,
Evas_Object *_obj EINA_UNUSED,
void *_ev EINA_UNUSED)
{
controls_toggle(ct_win, ct_bg, ct_term, ct_donecb, ct_donedata);
controls_hide(EINA_TRUE);
}
static void
_cb_frame_del(void *_data EINA_UNUSED,
_cb_saved_del(void *data,
Evas *_e EINA_UNUSED,
Evas_Object *_obj EINA_UNUSED,
Evas_Object *obj EINA_UNUSED,
void *_ev EINA_UNUSED)
{
if (ct_win)
{
evas_object_smart_callback_del(ct_win, "selection,on", _cb_sel_on);
evas_object_smart_callback_del(ct_win, "selection,off", _cb_sel_off);
}
ct_frame = NULL;
}
static void
_cb_over_del(void *_data EINA_UNUSED,
Evas *_e EINA_UNUSED,
Evas_Object *_obj EINA_UNUSED,
void *_ev EINA_UNUSED)
{
ct_over = NULL;
}
if (data == ct_win)
ct_win = NULL;
else if (data == ct_term)
ct_term = NULL;
static void
_cb_saved_del(void *_data EINA_UNUSED,
Evas *_e EINA_UNUSED,
Evas_Object *obj,
void *_ev EINA_UNUSED)
{
if ((obj == ct_win) || (obj == ct_term))
{
if (obj == ct_term)
{
if (ct_out)
controls_toggle(ct_win, ct_bg, ct_term, ct_donecb, ct_donedata);
ct_term = NULL;
}
else
{
if (ct_frame)
{
evas_object_del(ct_frame);
ct_frame = NULL;
}
if (ct_del_timer)
{
ecore_timer_del(ct_del_timer);
ct_del_timer = NULL;
}
if (ct_over)
{
evas_object_del(ct_over);
ct_over = NULL;
}
evas_object_event_callback_del(ct_win, EVAS_CALLBACK_DEL, _cb_saved_del);
ct_win = NULL;
}
evas_object_event_callback_del(ct_term, EVAS_CALLBACK_DEL, _cb_saved_del);
ct_bg = NULL;
}
controls_hide(EINA_FALSE);
}
static Evas_Object *
_button_add(Evas_Object *win, const char *label, const char *icon, Evas_Smart_Cb cb, void *cbdata)
{
Evas_Object *o, *bt;
bt = o = elm_button_add(win);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
if (label) elm_object_text_set(o, label);
evas_object_smart_callback_add(o, "clicked", cb, cbdata);
if (icon)
{
o = elm_icon_add(win);
@ -227,7 +174,7 @@ _button_add(Evas_Object *win, const char *label, const char *icon, Evas_Smart_Cb
elm_object_part_content_set(bt, "icon", o);
evas_object_show(o);
}
evas_object_show(bt);
return bt;
}
@ -236,7 +183,7 @@ static Evas_Object *
_sep_add_v(Evas_Object *win)
{
Evas_Object *o = elm_separator_add(win);
evas_object_size_hint_weight_set(o, 0.0, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(o, 0.5, EVAS_HINT_FILL);
elm_separator_horizontal_set(o, EINA_FALSE);
@ -248,7 +195,7 @@ static Evas_Object *
_sep_add_h(Evas_Object *win)
{
Evas_Object *o = elm_separator_add(win);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5);
elm_separator_horizontal_set(o, EINA_TRUE);
@ -256,167 +203,155 @@ _sep_add_h(Evas_Object *win)
return o;
}
void
controls_toggle(Evas_Object *win, Evas_Object *bg, Evas_Object *term,
void (*donecb) (void *data), void *donedata)
static void
controls_hide(Eina_Bool call_cb)
{
Evas_Object *o;
if (!ct_frame)
return;
if (!ct_out)
if (ct_win)
{
if (options_is_active())
{
options_toggle(win, bg, term, ct_donecb, ct_donedata);
return;
}
evas_object_event_callback_del(ct_win, EVAS_CALLBACK_DEL, _cb_saved_del);
evas_object_smart_callback_del(ct_win, "selection,on", _cb_sel_on);
evas_object_smart_callback_del(ct_win, "selection,off", _cb_sel_off);
}
if ((win != ct_win) && (ct_frame))
if (ct_term)
{
evas_object_del(ct_frame);
ct_frame = NULL;
ct_win = NULL;
ct_term = NULL;
evas_object_event_callback_del(ct_term, EVAS_CALLBACK_DEL, _cb_saved_del);
}
if (!ct_frame)
if (ct_over)
{
ct_frame = o = elm_frame_add(win);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_object_text_set(o, _("Controls"));
ct_boxv = o = elm_box_add(win);
elm_box_horizontal_set(o, EINA_FALSE);
elm_object_content_set(ct_frame, o);
evas_object_show(o);
evas_object_del(ct_over);
}
ct_over = NULL;
edje_object_signal_emit(ct_bg, "controls,hide", "terminology");
elm_object_focus_set(ct_frame, EINA_FALSE);
ct_boxh = o = elm_box_add(win);
elm_box_pack_end(ct_boxv, o);
elm_box_horizontal_set(o, EINA_TRUE);
evas_object_show(o);
ecore_timer_add(10.0, _cb_ct_del_delay, ct_frame);
ct_frame = NULL;
ct_box = o = elm_box_add(win);
elm_box_pack_end(ct_boxh, o);
evas_object_show(o);
ct_win = NULL;
o = _button_add(win, _("New"), "window-new", _cb_ct_new, NULL);
elm_box_pack_end(ct_box, o);
if (call_cb && ct_donecb)
ct_donecb(ct_donedata);
ct_donecb = NULL;
ct_donedata = NULL;
}
o = _sep_add_h(win);
elm_box_pack_end(ct_box, o);
void
controls_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term,
void (*donecb) (void *data), void *donedata)
{
Evas_Object *o;
o = _button_add(win, _("Split V"), "object-flip-vertical", _cb_ct_split_v, NULL);
elm_box_pack_end(ct_box, o);
o = _button_add(win, _("Split H"), "object-flip-horizontal", _cb_ct_split_h, NULL);
elm_box_pack_end(ct_box, o);
if ((options_is_active()) || (ct_win && win != ct_win) || (ct_frame))
{
donecb(donedata);
return;
}
o = _sep_add_h(win);
elm_box_pack_end(ct_box, o);
ct_frame = o = elm_frame_add(win);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_object_text_set(o, _("Controls"));
o = _button_add(win, _("Miniview"), "view-restore", _cb_ct_miniview, NULL);
elm_box_pack_end(ct_box, o);
ct_boxv = o = elm_box_add(win);
elm_box_horizontal_set(o, EINA_FALSE);
elm_object_content_set(ct_frame, o);
evas_object_show(o);
o = _sep_add_h(win);
elm_box_pack_end(ct_box, o);
ct_boxh = o = elm_box_add(win);
elm_box_pack_end(ct_boxv, o);
elm_box_horizontal_set(o, EINA_TRUE);
evas_object_show(o);
o = _button_add(win, _("Set title"), "format-text-underline", _cb_ct_set_title, NULL);
elm_box_pack_end(ct_box, o);
ct_box = o = elm_box_add(win);
elm_box_pack_end(ct_boxh, o);
evas_object_show(o);
o = _sep_add_v(win);
elm_box_pack_end(ct_boxh, o);
o = _button_add(win, _("New"), "window-new", _cb_ct_new, NULL);
elm_box_pack_end(ct_box, o);
ct_box2 = o = elm_box_add(win);
elm_box_pack_end(ct_boxh, o);
evas_object_show(o);
o = _sep_add_h(win);
elm_box_pack_end(ct_box, o);
o = _button_add(win, _("Copy"), "edit-copy", _cb_ct_copy, NULL);
evas_object_data_set(ct_frame, "bt_copy", o);
if (!termio_selection_exists(term))
elm_object_disabled_set(o, EINA_TRUE);
elm_box_pack_end(ct_box2, o);
o = _button_add(win, _("Split V"), "object-flip-vertical", _cb_ct_split_v, NULL);
elm_box_pack_end(ct_box, o);
o = _button_add(win, _("Split H"), "object-flip-horizontal", _cb_ct_split_h, NULL);
elm_box_pack_end(ct_box, o);
o = _button_add(win, _("Paste"), "edit-paste", _cb_ct_paste, NULL);
elm_box_pack_end(ct_box2, o);
o = _sep_add_h(win);
elm_box_pack_end(ct_box, o);
o = _sep_add_h(win);
elm_box_pack_end(ct_box2, o);
o = _button_add(win, _("Miniview"), "view-restore", _cb_ct_miniview, NULL);
elm_box_pack_end(ct_box, o);
o = _button_add(win, _("Settings"), "preferences-desktop", _cb_ct_options, NULL);
elm_box_pack_end(ct_box2, o);
o = _sep_add_h(win);
elm_box_pack_end(ct_box, o);
o = _sep_add_h(win);
elm_box_pack_end(ct_box2, o);
o = _button_add(win, _("Set title"), "format-text-underline", _cb_ct_set_title, NULL);
elm_box_pack_end(ct_box, o);
o = _button_add(win, _("About"), "help-about", _cb_ct_about, NULL);
elm_box_pack_end(ct_box2, o);
o = _sep_add_v(win);
elm_box_pack_end(ct_boxh, o);
o = _sep_add_h(win);
elm_box_pack_end(ct_boxv, o);
ct_box2 = o = elm_box_add(win);
elm_box_pack_end(ct_boxh, o);
evas_object_show(o);
ct_box3 = o = elm_box_add(win);
elm_box_pack_end(ct_boxv, o);
evas_object_show(o);
o = _button_add(win, _("Copy"), "edit-copy", _cb_ct_copy, NULL);
evas_object_data_set(ct_frame, "bt_copy", o);
if (!termio_selection_exists(term))
elm_object_disabled_set(o, EINA_TRUE);
elm_box_pack_end(ct_box2, o);
o = _button_add(win, _("Close Terminal"), "window-close", _cb_ct_close, NULL);
elm_box_pack_end(ct_box3, o);
o = _button_add(win, _("Paste"), "edit-paste", _cb_ct_paste, NULL);
elm_box_pack_end(ct_box2, o);
evas_object_event_callback_add(ct_frame, EVAS_CALLBACK_DEL,
_cb_frame_del, NULL);
o = _sep_add_h(win);
elm_box_pack_end(ct_box2, o);
evas_object_smart_callback_add(win, "selection,on", _cb_sel_on,
NULL);
evas_object_smart_callback_add(win, "selection,off", _cb_sel_off,
NULL);
}
if (!ct_out)
{
edje_object_part_swallow(bg, "terminology.controls", ct_frame);
evas_object_show(ct_frame);
ct_over = o = evas_object_rectangle_add(evas_object_evas_get(win));
evas_object_color_set(o, 0, 0, 0, 0);
edje_object_part_swallow(bg, "terminology.dismiss", o);
evas_object_show(o);
evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN,
_cb_mouse_down, NULL);
evas_object_event_callback_add(o, EVAS_CALLBACK_DEL,
_cb_over_del, NULL);
ct_win = win;
ct_bg = bg;
ct_term = term;
ct_donecb = donecb;
ct_donedata = donedata;
edje_object_signal_emit(bg, "controls,show", "terminology");
ct_out = EINA_TRUE;
elm_object_focus_set(ct_frame, EINA_TRUE);
if (ct_del_timer)
{
ecore_timer_del(ct_del_timer);
ct_del_timer = NULL;
}
}
else
{
if (ct_over)
{
evas_object_del(ct_over);
ct_over = NULL;
}
edje_object_signal_emit(ct_bg, "controls,hide", "terminology");
ct_out = EINA_FALSE;
elm_object_focus_set(ct_frame, EINA_FALSE);
if (ct_donecb) ct_donecb(ct_donedata);
// elm_object_focus_set(ct_term, EINA_TRUE);
if (ct_del_timer) ecore_timer_del(ct_del_timer);
ct_del_timer = ecore_timer_add(10.0, _cb_ct_del_delay, NULL);
}
if (ct_win)
{
evas_object_event_callback_del(ct_win, EVAS_CALLBACK_DEL, _cb_saved_del);
evas_object_event_callback_del(ct_term, EVAS_CALLBACK_DEL, _cb_saved_del);
}
if (ct_out)
{
evas_object_event_callback_add(ct_win, EVAS_CALLBACK_DEL, _cb_saved_del, NULL);
evas_object_event_callback_add(ct_term, EVAS_CALLBACK_DEL, _cb_saved_del, NULL);
}
o = _button_add(win, _("Settings"), "preferences-desktop", _cb_ct_options, NULL);
elm_box_pack_end(ct_box2, o);
o = _sep_add_h(win);
elm_box_pack_end(ct_box2, o);
o = _button_add(win, _("About"), "help-about", _cb_ct_about, NULL);
elm_box_pack_end(ct_box2, o);
o = _sep_add_h(win);
elm_box_pack_end(ct_boxv, o);
ct_box3 = o = elm_box_add(win);
elm_box_pack_end(ct_boxv, o);
evas_object_show(o);
o = _button_add(win, _("Close Terminal"), "window-close", _cb_ct_close, NULL);
elm_box_pack_end(ct_box3, o);
evas_object_smart_callback_add(win, "selection,on", _cb_sel_on,
NULL);
evas_object_smart_callback_add(win, "selection,off", _cb_sel_off,
NULL);
edje_object_part_swallow(bg, "terminology.controls", ct_frame);
evas_object_show(ct_frame);
ct_over = o = evas_object_rectangle_add(evas_object_evas_get(win));
evas_object_color_set(o, 0, 0, 0, 0);
edje_object_part_swallow(bg, "terminology.dismiss", o);
evas_object_show(o);
evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN,
_cb_mouse_down, NULL);
ct_win = win;
ct_bg = bg;
ct_term = term;
ct_donecb = donecb;
ct_donedata = donedata;
edje_object_signal_emit(bg, "controls,show", "terminology");
elm_object_focus_set(ct_frame, EINA_TRUE);
evas_object_event_callback_add(ct_win, EVAS_CALLBACK_DEL, _cb_saved_del, ct_win);
evas_object_event_callback_add(ct_term, EVAS_CALLBACK_DEL, _cb_saved_del, ct_term);
}

@ -1,7 +1,7 @@
#ifndef _CONTROLS_H__
#define _CONTROLS_H__ 1
void controls_toggle(Evas_Object *win, Evas_Object *bg, Evas_Object *term,
void (*donecb) (void *data), void *donedata);
void controls_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term,
void (*donecb) (void *data), void *donedata);
#endif

@ -5009,8 +5009,8 @@ _cb_options(void *data,
{
Term *term = data;
controls_toggle(term->wn->win, term->wn->base, term->termio,
_cb_options_done, term->wn);
controls_show(term->wn->win, term->wn->base, term->termio,
_cb_options_done, term->wn);
}
void

Loading…
Cancel
Save