143 lines
3.1 KiB
C#
143 lines
3.1 KiB
C#
using System;
|
|
|
|
public class TextEditor : IDisposable
|
|
{
|
|
private efl.ui.IWin win;
|
|
private efl.ui.IText editor;
|
|
private efl.ui.IButton toolbarNew;
|
|
|
|
private bool edited = false;
|
|
|
|
|
|
private void GUIQuitCb(object sender, EventArgs ea)
|
|
{
|
|
efl.ui.Config.Exit();
|
|
}
|
|
|
|
private void EditorChangedCb(object sender, EventArgs ea)
|
|
{
|
|
edited = true;
|
|
GUIToolbarRefresh();
|
|
}
|
|
|
|
private efl.ui.IButton GUIToolbarButtonAdd(efl.ui.IBox toolbar, string name, string iconName, EventHandler func)
|
|
{
|
|
efl.ui.IButton button = new efl.ui.Button(toolbar);
|
|
button.SetText(name);
|
|
button.ClickedEvt += func;
|
|
|
|
toolbar.DoPack(button);
|
|
|
|
efl.ui.IImage img = new efl.ui.Image(toolbar);
|
|
img.SetIcon(iconName);
|
|
|
|
efl.Content.static_cast(button.GetPart("efl.content")).SetContent(img);
|
|
|
|
return button;
|
|
}
|
|
|
|
private void GUIToolbarSetup(efl.ui.IBox parent)
|
|
{
|
|
efl.ui.IBox bar = new efl.ui.Box(parent);
|
|
bar.SetHintWeight(1, 0);
|
|
bar.SetDirection(efl.ui.Dir.Horizontal);
|
|
parent.DoPack(bar);
|
|
|
|
toolbarNew = GUIToolbarButtonAdd(bar, "New", "document-new",
|
|
(object sender, EventArgs ea) =>
|
|
{
|
|
editor.SetText("");
|
|
edited = false;
|
|
GUIToolbarRefresh();
|
|
});
|
|
|
|
// spacer box
|
|
efl.ui.IBox box = new efl.ui.Box(parent);
|
|
box.SetHintWeight(10, 0);
|
|
bar.DoPack(box);
|
|
|
|
GUIToolbarButtonAdd(bar, "Quit", "application-exit", GUIQuitCb);
|
|
|
|
GUIToolbarRefresh();
|
|
}
|
|
|
|
private void GUIToolbarRefresh()
|
|
{
|
|
toolbarNew.SetDisabled(!edited);
|
|
}
|
|
|
|
public TextEditor()
|
|
{
|
|
win = new efl.ui.Win(null, (efl.ui.IWin ewin) => {
|
|
ewin.SetWinType(efl.ui.Win_Type.Basic);
|
|
ewin.SetText("Text Editor");
|
|
ewin.SetAutohide(true);
|
|
});
|
|
|
|
// when the user clicks "close" on a window there is a request to hide
|
|
win.HideEvt += GUIQuitCb;
|
|
|
|
efl.ui.IBox box = new efl.ui.Box(win);
|
|
eina.Size2D sz;
|
|
sz.W = 360;
|
|
sz.H = 240;
|
|
box.SetHintMin(sz);
|
|
|
|
win.SetContent(box);
|
|
|
|
GUIToolbarSetup(box);
|
|
|
|
editor = new efl.ui.Text(box);
|
|
editor.SetFont("Mono", 14);
|
|
editor.SetMultiline(true);
|
|
editor.SetEditable(true);
|
|
editor.SetScrollable(true);
|
|
editor.SetScrollable(true);
|
|
editor.ChangedEvt += EditorChangedCb;
|
|
editor.ChangedUserEvt += EditorChangedCb;
|
|
|
|
box.DoPack(editor);
|
|
}
|
|
|
|
~TextEditor()
|
|
{
|
|
Dispose(false);
|
|
}
|
|
|
|
protected void Dispose(bool disposing)
|
|
{
|
|
editor.Dispose();
|
|
toolbarNew.Dispose();
|
|
win.Dispose();
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
Dispose(true);
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
|
|
public void Run()
|
|
{
|
|
// start main loop
|
|
efl.ui.Config.Run();
|
|
}
|
|
}
|
|
|
|
public class Example
|
|
{
|
|
public static void Main()
|
|
{
|
|
efl.All.Init(efl.Components.Ui);
|
|
|
|
var textEditor = new TextEditor();
|
|
textEditor.Run();
|
|
|
|
// dispose after quit
|
|
textEditor.Dispose();
|
|
|
|
efl.All.Shutdown();
|
|
}
|
|
}
|
|
|