edn/sources/appl/Gui/MainWindows.cpp

410 lines
15 KiB
C++
Raw Normal View History

/**
* @author Edouard DUPIN
2012-11-25 11:55:06 +01:00
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
2012-11-25 11:55:06 +01:00
2012-04-23 10:15:43 +02:00
#include <appl/Debug.h>
2012-04-24 09:42:14 +02:00
#include <appl/global.h>
#include <MainWindows.h>
#include <CodeView.h>
#include <BufferView.h>
2012-07-01 17:54:50 +02:00
#include <Search.h>
#include <ewol/widget/Button.h>
#include <ewol/widget/CheckBox.h>
#include <ewol/widget/SizerHori.h>
#include <ewol/widget/SizerVert.h>
#include <ewol/widget/Label.h>
#include <ewol/widget/Entry.h>
#include <ewol/widget/List.h>
2012-02-16 18:18:04 +01:00
#include <ewol/widget/ContextMenu.h>
#include <ewol/widget/PopUp.h>
#include <ewol/widget/Spacer.h>
2012-09-07 16:31:49 +02:00
#include <ewol/widget/Slider.h>
2012-02-16 23:29:48 +01:00
#include <ewol/widget/Menu.h>
#include <ewol/widget/meta/FileChooser.h>
#include <ewol/widget/meta/Parameter.h>
#include <ewol/widget/WidgetManager.h>
#include <ewol/eObject/EObject.h>
2012-07-24 13:01:40 +02:00
#undef __class__
#define __class__ "AboutGui"
#include <ewol/widget/Label.h>
#include <ewol/widget/Spacer.h>
2012-11-25 11:55:06 +01:00
class ParameterAboutGui : public widget::SizerVert
2012-07-24 13:01:40 +02:00
{
public :
ParameterAboutGui(void)
{
2012-11-25 11:55:06 +01:00
widget::Spacer* mySpacer = NULL;
2012-07-24 13:01:40 +02:00
2012-11-25 11:55:06 +01:00
mySpacer = new widget::Spacer();
2012-07-24 13:01:40 +02:00
if (NULL == mySpacer) {
APPL_ERROR("Can not allocate widget ==> display might be in error");
} else {
mySpacer->SetExpendX(true);
mySpacer->SetExpendY(true);
SubWidgetAdd(mySpacer);
}
AddElement(" libPng");
AddElement(" ogg-tremor");
AddElement(" portaudio");
AddElement(" libZip");
AddElement(" tinyXml");
AddElement(" freetype");
AddElement(" agg2.4");
AddElement(" etk (BSD)");
AddElement(" ewol is based on");
AddElement(" Website : https://github.com/HeeroYui/ewol");
AddElement(" Licence : BSD like");
AddElement(" Copyright 2010 Edouard DUPIN, all right reserved");
2012-10-11 18:05:56 +02:00
AddElement(" Supported OS : Linux, Windows, Android" );
2012-07-24 13:01:40 +02:00
AddElement(etk::UString(" OpenGl librairy : v") + ewol::GetVersion() );
AddElement("Ewol", true);
AddElement("");
AddElement(" Website : https://github.com/HeeroYui/edn");
AddElement(" Licence : GPL");
AddElement(" Copyright 2010 Edouard DUPIN, all right reserved");
AddElement(etk::UString(" Build Time : ") + etk::UString(BUILD_TIME));
AddElement(" Source Code Editor");
AddElement(etk::UString(" Editeur De N'ours : v") + etk::UString(APPL_VERSION_TAG_NAME));
AddElement("Edn", true);
};
~ParameterAboutGui(void) { };
void AddElement(etk::UString label, bool bold=false, bool italic=false)
{
2012-11-25 11:55:06 +01:00
widget::Label* myLabel = new widget::Label(label);
2012-07-24 13:01:40 +02:00
if (NULL == myLabel) {
APPL_ERROR("Can not allocate widget ==> display might be in error");
} else {
myLabel->SetExpendX(true);
SubWidgetAdd(myLabel);
}
};
};
2012-09-07 16:31:49 +02:00
const char * l_smoothChick = "tmpEvent_smooth";
const char * l_smoothMin = "tmpEvent_minChange";
const char * l_smoothMax = "tmpEvent_maxChange";
#undef __class__
#define __class__ "MainWindows"
MainWindows::MainWindows(void)
{
2012-04-23 10:15:43 +02:00
APPL_DEBUG("CREATE WINDOWS ... ");
2012-11-25 11:55:06 +01:00
widget::SizerVert * mySizerVert = NULL;
widget::SizerVert * mySizerVert2 = NULL;
widget::SizerHori * mySizerHori = NULL;
2012-02-17 18:25:38 +01:00
//ewol::Button * myButton = NULL;
CodeView * myCodeView = NULL;
BufferView * myBufferView = NULL;
2012-11-25 11:55:06 +01:00
widget::Menu * myMenu = NULL;
2012-11-25 11:55:06 +01:00
mySizerVert = new widget::SizerVert();
SetSubWidget(mySizerVert);
2012-11-25 11:55:06 +01:00
mySizerHori = new widget::SizerHori();
mySizerVert->SubWidgetAdd(mySizerHori);
myBufferView = new BufferView();
myBufferView->SetExpendX(false);
myBufferView->SetExpendY(true);
myBufferView->SetFillX(true);
myBufferView->SetFillY(true);
mySizerHori->SubWidgetAdd(myBufferView);
2012-11-25 11:55:06 +01:00
mySizerVert2 = new widget::SizerVert();
mySizerHori->SubWidgetAdd(mySizerVert2);
// main buffer Area :
myCodeView = new CodeView("FreeMono", 11);
myCodeView->SetExpendX(true);
myCodeView->SetExpendY(true);
myCodeView->SetFillX(true);
myCodeView->SetFillY(true);
mySizerVert2->SubWidgetAdd(myCodeView);
// search area :
Search * mySearch = new Search();
mySizerVert2->SubWidgetAdd(mySearch);
#ifdef APPL_BUFFER_FONT_DISTANCE_FIELD
2012-09-07 16:31:49 +02:00
{
2012-11-25 11:55:06 +01:00
widget::SizerHori * mySizerHori2 = new widget::SizerHori();
2012-09-07 16:31:49 +02:00
mySizerVert2->SubWidgetAdd(mySizerHori2);
2012-11-25 11:55:06 +01:00
widget::CheckBox* tmpCheck = new widget::CheckBox("smooth");
2012-09-07 16:31:49 +02:00
mySizerHori2->SubWidgetAdd(tmpCheck);
tmpCheck->RegisterOnEvent(this, ewolEventCheckBoxClicked, l_smoothChick);
2012-11-25 11:55:06 +01:00
widget::Slider* tmpSlider = new widget::Slider();
2012-09-07 16:31:49 +02:00
mySizerHori2->SubWidgetAdd(tmpSlider);
tmpSlider->RegisterOnEvent(this, ewolEventSliderChange, l_smoothMin);
tmpSlider->SetExpendX(true);
tmpSlider->SetMin(0);
tmpSlider->SetMax(1000);
tmpSlider->SetValue(0450);
tmpSliderMin = tmpSlider;
2012-11-25 11:55:06 +01:00
tmpSlider = new widget::Slider();
2012-09-07 16:31:49 +02:00
mySizerHori2->SubWidgetAdd(tmpSlider);
tmpSlider->RegisterOnEvent(this, ewolEventSliderChange, l_smoothMax);
tmpSlider->SetExpendX(true);
tmpSlider->SetMin(0);
tmpSlider->SetMax(1000);
tmpSlider->SetValue(0550);
tmpSliderMax = tmpSlider;
}
#endif
2012-11-25 11:55:06 +01:00
mySizerHori = new widget::SizerHori();
mySizerVert->SubWidgetAdd(mySizerHori);
2012-02-16 23:29:48 +01:00
2012-11-25 11:55:06 +01:00
myMenu = new widget::Menu();
2012-02-16 18:18:04 +01:00
mySizerHori->SubWidgetAdd(myMenu);
2012-02-16 23:29:48 +01:00
int32_t idMenuFile = myMenu->AddTitle("File");
(void)myMenu->Add(idMenuFile, "New", "", ednMsgGuiNew);
2012-02-17 18:25:38 +01:00
(void)myMenu->AddSpacer();
2012-11-25 11:55:06 +01:00
(void)myMenu->Add(idMenuFile, "Open", "THEME:GUI:Load.svg", ednMsgGuiOpen);
(void)myMenu->Add(idMenuFile, "Close", "THEME:GUI:Close.svg", ednMsgGuiClose, "current");
(void)myMenu->Add(idMenuFile, "Close (all)", "", ednMsgGuiClose, "All");
2012-11-25 11:55:06 +01:00
(void)myMenu->Add(idMenuFile, "Save", "THEME:GUI:Save.svg", ednMsgGuiSave, "current");
(void)myMenu->Add(idMenuFile, "Save As ...", "", ednMsgGuiSaveAs);
2012-02-17 18:25:38 +01:00
(void)myMenu->AddSpacer();
//(void)myMenu->Add(idMenuFile, "Exit", "", ednMsgGuiExit);
(void)myMenu->AddSpacer();
2012-11-25 11:55:06 +01:00
(void)myMenu->Add(idMenuFile, "Properties", "THEME:GUI:Parameter.svg", ednMsgProperties);
2012-02-16 23:29:48 +01:00
int32_t idMenuEdit = myMenu->AddTitle("Edit");
2012-11-25 11:55:06 +01:00
(void)myMenu->Add(idMenuEdit, "Undo", "THEME:GUI:Undo.svg", ednMsgGuiUndo);
(void)myMenu->Add(idMenuEdit, "Redo", "THEME:GUI:Redo.svg", ednMsgGuiRedo);
2012-02-17 18:25:38 +01:00
(void)myMenu->AddSpacer();
(void)myMenu->Add(idMenuEdit, "Copy", "", ednMsgGuiCopy, "STD");
(void)myMenu->Add(idMenuEdit, "Cut", "", ednMsgGuiCut, "STD");
(void)myMenu->Add(idMenuEdit, "Paste", "", ednMsgGuiPaste, "STD");
(void)myMenu->Add(idMenuEdit, "Remove", "", ednMsgGuiRm);
2012-02-17 18:25:38 +01:00
(void)myMenu->AddSpacer();
(void)myMenu->Add(idMenuEdit, "Select All","", ednMsgGuiSelect, "ALL");
(void)myMenu->Add(idMenuEdit, "Un-Select","", ednMsgGuiSelect, "NONE");
(void)myMenu->Add(idMenuEdit, "Goto line ...","", ednMsgGuiGotoLine, "???");
2012-02-16 23:29:48 +01:00
int32_t idMenuSearch = myMenu->AddTitle("Search");
2012-11-25 11:55:06 +01:00
(void)myMenu->Add(idMenuSearch, "Search", "THEME:GUI:Search.svg", ednMsgGuiSearch);
(void)myMenu->Add(idMenuSearch, "Replace", "THEME:GUI:Replace.svg", ednMsgGuiReplace);
2012-02-17 18:25:38 +01:00
(void)myMenu->AddSpacer();
(void)myMenu->Add(idMenuSearch, "Find (previous)","", ednMsgGuiFind, "Previous");
(void)myMenu->Add(idMenuSearch, "Find (next)", "", ednMsgGuiFind, "Next");
(void)myMenu->Add(idMenuSearch, "Find (all)", "", ednMsgGuiFind, "All");
(void)myMenu->Add(idMenuSearch, "Un-Select", "", ednMsgGuiFind, "None");
2012-02-16 23:29:48 +01:00
int32_t idMenuCTags = myMenu->AddTitle("C-tags");
2012-02-17 18:25:38 +01:00
(void)myMenu->Add(idMenuCTags, "Load", "", ednMsgGuiCtags, "Load");
(void)myMenu->Add(idMenuCTags, "ReLoad", "", ednMsgGuiCtags, "ReLoad");
(void)myMenu->Add(idMenuCTags, "Jump", "", ednMsgGuiCtags, "Jump");
(void)myMenu->Add(idMenuCTags, "Back", "", ednMsgGuiCtags, "Back");
2012-04-17 11:01:26 +02:00
int32_t idMenugDisplay = myMenu->AddTitle("Display");
(void)myMenu->Add(idMenugDisplay, "Charset UTF-8", "", ednMsgGuiChangeCharset, "UTF-8");
(void)myMenu->Add(idMenugDisplay, "Charset ISO-8859-1", "", ednMsgGuiChangeCharset, "ISO-8859-1");
(void)myMenu->Add(idMenugDisplay, "Charset ISO-8859-15", "", ednMsgGuiChangeCharset, "ISO-8859-15");
(void)myMenu->AddSpacer();
(void)myMenu->Add(idMenugDisplay, "Color Black", "", ednMsgGuiChangeColor, "Black");
(void)myMenu->Add(idMenugDisplay, "Color White", "", ednMsgGuiChangeColor, "White");
2012-10-11 18:05:56 +02:00
(void)myMenu->AddSpacer();
(void)myMenu->Add(idMenugDisplay, "Reload OpenGl Shader", "", ednMsgGuiReloadShader);
2012-11-25 11:55:06 +01:00
m_widgetLabelFileName = new widget::Label("FileName");
2012-02-27 18:15:56 +01:00
m_widgetLabelFileName->SetExpendX(true);
m_widgetLabelFileName->SetFillY(true);
mySizerHori->SubWidgetAdd(m_widgetLabelFileName);
2012-11-25 11:55:06 +01:00
// add generic shortcut ...
// (shift, control, alt, meta, uniChar_t unicodeValue, const char * generateEventId, etk::UString& data)
ShortCutAdd("ctrl+o", ednMsgGuiOpen, "", true);
ShortCutAdd("ctrl+n", ednMsgGuiNew, "", true);
ShortCutAdd("ctrl+s", ednMsgGuiSave, "current", true);
ShortCutAdd("ctrl+shift+s", ednMsgGuiSave, "All", true);
ShortCutAdd("ctrl+q", ednMsgGuiClose, "current", true);
ShortCutAdd("ctrl+shift+q", ednMsgGuiClose, "All", true);
ShortCutAdd("ctrl+z", ednMsgGuiUndo, "", true);
ShortCutAdd("ctrl+shift+z", ednMsgGuiRedo, "", true);
ShortCutAdd("ctrl+l", ednMsgGuiGotoLine, "???", true);
ShortCutAdd("ctrl+f", ednMsgGuiSearch, "", true);
ShortCutAdd("F12", ednMsgGuiReloadShader, "", true);
ShortCutAdd("ctrl+d", ednMsgGuiCtags, "Jump", true);
// Generic event ...
2012-02-29 18:06:08 +01:00
RegisterMultiCast(ednMsgGuiSaveAs);
RegisterMultiCast(ednMsgProperties);
2012-02-29 18:06:08 +01:00
RegisterMultiCast(ednMsgGuiOpen);
2012-02-23 18:05:57 +01:00
// to update the title ...
2012-02-29 18:06:08 +01:00
RegisterMultiCast(ednMsgBufferState);
RegisterMultiCast(ednMsgBufferId);
2012-10-11 18:05:56 +02:00
RegisterMultiCast(ednMsgGuiReloadShader);
}
MainWindows::~MainWindows(void)
{
}
2012-02-17 18:25:38 +01:00
const char *const ednEventPopUpFileSelected = "edn-mainWindows-openSelected";
const char *const ednEventPopUpFileSaveAs = "edn-mainWindows-saveAsSelected";
2012-02-29 18:06:08 +01:00
/**
* @brief Receive a message from an other EObject with a specific eventId and data
* @param[in] CallerObject Pointer on the EObject that information came from
* @param[in] eventId Message registered by this class
* @param[in] data Data registered by this class
* @return ---
*/
void MainWindows::OnReceiveMessage(ewol::EObject * CallerObject, const char * eventId, etk::UString data)
{
2012-02-29 18:06:08 +01:00
ewol::Windows::OnReceiveMessage(CallerObject, eventId, data);
2012-10-11 18:05:56 +02:00
//APPL_INFO("Receive Event from the main windows ... : \"" << eventId << "\" ==> data=\"" << data << "\"" );
// Open file Section ...
2012-02-29 18:06:08 +01:00
if (eventId == ednMsgGuiOpen) {
2012-11-25 11:55:06 +01:00
widget::FileChooser* tmpWidget = new widget::FileChooser();
tmpWidget->SetTitle("Open Files ...");
tmpWidget->SetValidateLabel("Open");
2012-08-31 01:30:34 +02:00
if (BufferManager::GetSelected()!=-1) {
BufferText * myBuffer = BufferManager::Get(BufferManager::GetSelected());
2012-08-31 01:30:34 +02:00
if (NULL!=myBuffer) {
2012-11-01 10:47:36 +01:00
etk::FSNode tmpFile = myBuffer->GetFileName();
tmpWidget->SetFolder(tmpFile.GetNameFolder());
2012-08-31 01:30:34 +02:00
}
}
PopUpWidgetPush(tmpWidget);
2012-02-27 18:15:56 +01:00
tmpWidget->RegisterOnEvent(this, ewolEventFileChooserValidate, ednEventPopUpFileSelected);
2012-02-29 18:06:08 +01:00
} else if (eventId == ednEventPopUpFileSelected) {
2012-10-09 18:00:44 +02:00
APPL_DEBUG("Request opening the file : " << data);
SendMultiCast(ednMsgOpenFile, data);
2012-02-29 18:06:08 +01:00
} else if (eventId == ednMsgGuiSaveAs) {
if (data == "") {
2012-04-23 10:15:43 +02:00
APPL_ERROR("Null data for Save As file ... ");
} else {
m_currentSavingAsIdBuffer = -1;
2012-02-29 18:06:08 +01:00
if (data == "current") {
m_currentSavingAsIdBuffer = BufferManager::GetSelected();
} else {
sscanf(data.c_str(), "%d", &m_currentSavingAsIdBuffer);
}
if (false == BufferManager::Exist(m_currentSavingAsIdBuffer)) {
2012-04-23 10:15:43 +02:00
APPL_ERROR("Request saveAs on non existant Buffer ID=" << m_currentSavingAsIdBuffer);
} else {
BufferText* myBuffer = BufferManager::Get(m_currentSavingAsIdBuffer);
2012-11-25 11:55:06 +01:00
widget::FileChooser* tmpWidget = new widget::FileChooser();
if (NULL == tmpWidget) {
APPL_ERROR("Can not allocate widget ==> display might be in error");
} else {
tmpWidget->SetTitle("Save Files As...");
tmpWidget->SetValidateLabel("Save");
etk::UString folder = "/home/";
etk::UString fileName = "";
if (true == myBuffer->HaveName()) {
2012-11-01 10:47:36 +01:00
etk::FSNode tmpName = myBuffer->GetFileName();
folder = tmpName.GetNameFolder();
fileName = tmpName.GetNameFile();
}
tmpWidget->SetFolder(folder);
tmpWidget->SetFileName(fileName);
PopUpWidgetPush(tmpWidget);
tmpWidget->RegisterOnEvent(this, ewolEventFileChooserValidate, ednEventPopUpFileSaveAs);
}
}
}
2012-02-29 18:06:08 +01:00
} else if (eventId == ednEventPopUpFileSaveAs) {
// get the filename :
2012-07-24 17:48:18 +02:00
etk::UString tmpData = data;
2012-04-23 10:15:43 +02:00
APPL_DEBUG("Request Saving As file : " << tmpData);
BufferManager::Get(m_currentSavingAsIdBuffer)->SetFileName(tmpData);
2012-03-01 18:23:45 +01:00
SendMultiCast(ednMsgGuiSave, m_currentSavingAsIdBuffer);
2012-02-29 18:06:08 +01:00
} else if( eventId == ednMsgBufferState
|| eventId == ednMsgBufferId) {
2012-02-23 18:05:57 +01:00
// the buffer change we need to update the widget string
BufferText* tmpBuffer = BufferManager::Get(BufferManager::GetSelected());
2012-02-23 18:05:57 +01:00
if (NULL != tmpBuffer) {
2012-11-01 10:47:36 +01:00
etk::FSNode compleateName = tmpBuffer->GetFileName();
2012-02-24 12:45:39 +01:00
bool isModify = tmpBuffer->IsModify();
2012-11-01 10:47:36 +01:00
etk::UString directName = compleateName.GetName();
2012-02-24 12:45:39 +01:00
if (true == isModify) {
directName += " *";
}
2012-02-27 18:15:56 +01:00
if (NULL == m_widgetLabelFileName) {
2012-02-29 18:06:08 +01:00
return;
2012-02-23 18:05:57 +01:00
}
2012-02-27 18:15:56 +01:00
m_widgetLabelFileName->SetLabel(directName);
2012-03-29 17:48:48 +02:00
etk::UString windowsTitle = "edn - ";
windowsTitle += directName;
ewol::SetTitle(windowsTitle);
2012-02-29 18:06:08 +01:00
return;
2012-03-29 17:48:48 +02:00
} else {
m_widgetLabelFileName->SetLabel("");
ewol::SetTitle("edn");
2012-02-23 18:05:57 +01:00
}
2012-02-29 18:06:08 +01:00
return;
2012-02-23 18:05:57 +01:00
// TODO : Set the Title ....
} else if (eventId == ednMsgProperties) {
// Request the parameter GUI
2012-11-25 11:55:06 +01:00
widget::Parameter* tmpWidget = new widget::Parameter();
if (NULL == tmpWidget) {
APPL_ERROR("Can not allocate widget ==> display might be in error");
} else {
tmpWidget->SetTitle("Properties");
PopUpWidgetPush(tmpWidget);
2012-07-20 14:37:46 +02:00
tmpWidget->MenuAddGroup("Editor");
2012-07-23 17:21:44 +02:00
ewol::Widget* tmpSubWidget = new globals::ParameterGlobalsGui();
tmpWidget->MenuAdd("Editor", "", tmpSubWidget);
tmpWidget->MenuAdd("Polices & Color", "", NULL);
tmpWidget->MenuAdd("Highlight", "", NULL);
2012-07-20 14:37:46 +02:00
tmpWidget->MenuAddGroup("Genral");
tmpWidget->MenuAdd("Affichage", "", NULL);
2012-07-24 13:01:40 +02:00
tmpSubWidget = new ParameterAboutGui();
tmpWidget->MenuAdd("About", "", tmpSubWidget);
}
2012-12-02 20:34:00 +01:00
} else if (eventId == ednMsgGuiReloadShader) {
2012-10-11 18:05:56 +02:00
ewol::resource::ReLoadResources();
ewol::ForceRedrawAll();
2012-07-24 13:01:40 +02:00
}
2012-02-29 18:06:08 +01:00
return;
2011-07-21 18:03:41 +02:00
}
/**
* @brief Inform object that an other object is removed ...
* @param[in] removeObject Pointer on the EObject remeved ==> the user must remove all reference on this EObject
* @note : Sub classes must call this class
* @return ---
*/
void MainWindows::OnObjectRemove(ewol::EObject * removeObject)
{
ewol::Windows::OnObjectRemove(removeObject);
if (m_widgetLabelFileName == removeObject) {
m_widgetLabelFileName = NULL;
}
}