edn/jni/appl/Gui/MainWindows.cpp

336 lines
13 KiB
C++
Raw Normal View History

/**
*******************************************************************************
* @file MainWindows.cpp
2011-07-21 22:14:20 +02:00
* @brief Editeur De N'ours : main Windows diplayer (Sources)
* @author Edouard DUPIN
* @date 04/01/2011
* @par Project
* Edn
*
* @par Copyright
* Copyright 2010 Edouard DUPIN, all right reserved
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY.
*
* Licence summary :
* You can modify and redistribute the sources code and binaries.
* You can send me the bug-fix
* You can not earn money with this Software (if the source extract from Edn
* represent less than 50% of original Sources)
* Term of the licence in in the file licence.txt.
*
*******************************************************************************
*/
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>
#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-02-16 23:29:48 +01:00
#include <ewol/widget/Menu.h>
#include <ewol/widgetMeta/FileChooser.h>
#include <ewol/WidgetManager.h>
2012-02-28 18:22:49 +01:00
#include <ewol/EObject.h>
#undef __class__
#define __class__ "MainWindows"
extern const char * const TYPE_EOBJECT_EDN_MAIN_WINDOWS = "MainWindows";
MainWindows::MainWindows(void)
{
2012-04-23 10:15:43 +02:00
APPL_DEBUG("CREATE WINDOWS ... ");
ewol::SizerVert * mySizerVert = NULL;
ewol::SizerHori * mySizerHori = NULL;
2012-02-17 18:25:38 +01:00
//ewol::Button * myButton = NULL;
CodeView * myCodeView = NULL;
BufferView * myBufferView = NULL;
2012-02-16 23:29:48 +01:00
ewol::Menu * myMenu = NULL;
mySizerVert = new ewol::SizerVert();
SetSubWidget(mySizerVert);
mySizerHori = new ewol::SizerHori();
mySizerVert->SubWidgetAdd(mySizerHori);
2012-02-16 23:29:48 +01:00
2012-02-16 18:18:04 +01:00
myMenu = new ewol::Menu();
mySizerHori->SubWidgetAdd(myMenu);
2012-02-16 23:29:48 +01:00
int32_t idMenuFile = myMenu->AddTitle("File");
2012-03-29 17:48:48 +02:00
(void)myMenu->Add(idMenuFile, "New", "iconEdn.bmp", ednMsgGuiNew);
2012-02-17 18:25:38 +01:00
(void)myMenu->AddSpacer();
(void)myMenu->Add(idMenuFile, "Open", "icon/Load.svg", ednMsgGuiOpen);
(void)myMenu->Add(idMenuFile, "Close", "icon/Close.svg", ednMsgGuiClose, "current");
(void)myMenu->Add(idMenuFile, "Close (all)", "", ednMsgGuiClose, "All");
(void)myMenu->Add(idMenuFile, "Save", "icon/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);
2012-02-16 23:29:48 +01:00
int32_t idMenuEdit = myMenu->AddTitle("Edit");
(void)myMenu->Add(idMenuEdit, "Undo", "icon/Undo.svg", ednMsgGuiUndo);
(void)myMenu->Add(idMenuEdit, "Redo", "icon/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");
(void)myMenu->Add(idMenuSearch, "Search", "icon/Search.svg", ednMsgGuiSearch);
2012-02-17 18:25:38 +01:00
(void)myMenu->Add(idMenuSearch, "Replace", "", ednMsgGuiReplace);
(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-02-17 18:25:38 +01:00
(void)myMenu->AddTitle("?", "", ednMsgGuiAbout);
2012-02-27 18:15:56 +01:00
m_widgetLabelFileName = new ewol::Label("FileName");
m_widgetLabelFileName->SetExpendX(true);
m_widgetLabelFileName->SetFillY(true);
mySizerHori->SubWidgetAdd(m_widgetLabelFileName);
mySizerHori = new ewol::SizerHori();
mySizerVert->SubWidgetAdd(mySizerHori);
myBufferView = new BufferView();
myBufferView->SetExpendX(false);
myBufferView->SetExpendY(true);
myBufferView->SetFillX(true);
myBufferView->SetFillY(true);
mySizerHori->SubWidgetAdd(myBufferView);
myCodeView = new CodeView();
myCodeView->SetExpendX(true);
myCodeView->SetExpendY(true);
myCodeView->SetFillX(true);
myCodeView->SetFillY(true);
myCodeView->SetFontSize(11);
myCodeView->SetFontNameNormal( "freefont/FreeMono.ttf");
myCodeView->SetFontNameBold( "freefont/FreeMonoBold.ttf");
myCodeView->SetFontNameItalic( "freefont/FreeMonoOblique.ttf");
myCodeView->SetFontNameBoldItalic("freefont/FreeMonoBoldOblique.ttf");
/*
myCodeView->SetFontSize(11);
myCodeView->SetFontNameNormal( "ubuntu/UbuntuMono-R.ttf");
myCodeView->SetFontNameBold( "ubuntu/UbuntuMono-B.ttf");
myCodeView->SetFontNameItalic( "ubuntu/UbuntuMono-RI.ttf");
myCodeView->SetFontNameBoldItalic("ubuntu/UbuntuMono-BI.ttf");
*/
mySizerHori->SubWidgetAdd(myCodeView);
// Generic event ...
2012-02-29 18:06:08 +01:00
RegisterMultiCast(ednMsgGuiSaveAs);
RegisterMultiCast(ednMsgGuiOpen);
RegisterMultiCast(ednMsgGuiAbout);
2012-02-23 18:05:57 +01:00
// to update the title ...
2012-02-29 18:06:08 +01:00
RegisterMultiCast(ednMsgBufferState);
RegisterMultiCast(ednMsgBufferId);
}
MainWindows::~MainWindows(void)
{
}
/**
* @brief Check if the object has the specific type.
* @note In Embended platforme, it is many time no -rtti flag, then it is not possible to use dynamic cast ==> this will replace it
* @param[in] objectType type of the object we want to check
* @return true if the object is compatible, otherwise false
*/
bool MainWindows::CheckObjectType(const char * const objectType)
{
if (NULL == objectType) {
2012-04-23 10:15:43 +02:00
APPL_ERROR("check error : \"" << TYPE_EOBJECT_EDN_MAIN_WINDOWS << "\" != NULL(pointer) ");
return false;
}
if (objectType == TYPE_EOBJECT_EDN_MAIN_WINDOWS) {
return true;
} else {
if(true == ewol::Windows::CheckObjectType(objectType)) {
return true;
}
2012-04-23 10:15:43 +02:00
APPL_ERROR("check error : \"" << TYPE_EOBJECT_EDN_MAIN_WINDOWS << "\" != \"" << objectType << "\"");
return false;
}
}
/**
* @brief Get the current Object type of the EObject
* @note In Embended platforme, it is many time no -rtti flag, then it is not possible to use dynamic cast ==> this will replace it
* @param[in] objectType type description
* @return true if the object is compatible, otherwise false
*/
const char * const MainWindows::GetObjectType(void)
{
return TYPE_EOBJECT_EDN_MAIN_WINDOWS;
}
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-04-23 10:15:43 +02:00
//APPL_INFO("Receive Event from the main windows ... : widgetid=" << CallerObject << "\"" << eventId << "\" ==> data=\"" << data << "\"" );
// Open file Section ...
2012-02-29 18:06:08 +01:00
if (eventId == ednMsgGuiOpen) {
ewol::FileChooser* tmpWidget = new ewol::FileChooser();
tmpWidget->SetTitle("Open Files ...");
tmpWidget->SetValidateLabel("Open");
// TODO : Set the good folder ...
//tmpWidget->SetFolder("/");
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) {
// get widget:
2012-03-13 14:37:05 +01:00
ewol::FileChooser * tmpWidget = EWOL_CAST_WIDGET_FILE_CHOOSER(CallerObject);
if (NULL == tmpWidget) {
2012-04-23 10:15:43 +02:00
APPL_ERROR("impossible to get pop_upWidget " << CallerObject);
2012-03-01 18:23:45 +01:00
return;
}
// get the filename :
2012-02-15 16:23:20 +01:00
etk::UString tmpData = tmpWidget->GetCompleateFileName();
2012-04-23 10:15:43 +02:00
APPL_DEBUG("Request opening the file : " << tmpData);
2012-03-01 18:23:45 +01:00
SendMultiCast(ednMsgOpenFile, tmpData);
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 {
2012-02-29 18:06:08 +01:00
sscanf(data.Utf8Data(), "%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 {
Buffer * myBuffer = BufferManager::Get(m_currentSavingAsIdBuffer);
ewol::FileChooser* tmpWidget = new ewol::FileChooser();
tmpWidget->SetTitle("Save Files As...");
tmpWidget->SetValidateLabel("Save");
2012-02-15 16:23:20 +01:00
etk::UString folder = "/home/";
etk::UString fileName = "";
if (true == myBuffer->HaveName()) {
etk::File tmpName = myBuffer->GetFileName();
folder = tmpName.GetFolder();
fileName = tmpName.GetShortFilename();
}
tmpWidget->SetFolder(folder);
tmpWidget->SetFileName(fileName);
PopUpWidgetPush(tmpWidget);
2012-02-27 18:15:56 +01:00
tmpWidget->RegisterOnEvent(this, ewolEventFileChooserValidate, ednEventPopUpFileSaveAs);
}
}
2012-02-29 18:06:08 +01:00
} else if (eventId == ednEventPopUpFileSaveAs) {
// get widget:
2012-03-13 14:37:05 +01:00
ewol::FileChooser * tmpWidget = EWOL_CAST_WIDGET_FILE_CHOOSER(CallerObject);
if (NULL == tmpWidget) {
2012-04-23 10:15:43 +02:00
APPL_ERROR("impossible to get pop_upWidget " << CallerObject);
2012-03-01 18:23:45 +01:00
return;
}
// get the filename :
2012-02-15 16:23:20 +01:00
etk::UString tmpData = tmpWidget->GetCompleateFileName();
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
Buffer* tmpBuffer = BufferManager::Get(BufferManager::GetSelected());
if (NULL != tmpBuffer) {
etk::File compleateName = tmpBuffer->GetFileName();
2012-02-24 12:45:39 +01:00
bool isModify = tmpBuffer->IsModify();
etk::UString directName = compleateName.GetCompleateName();
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 ....
2012-02-29 18:06:08 +01:00
} else if (eventId == ednMsgGuiAbout) {
2012-02-18 00:35:15 +01:00
/*
//Title
"Edn"
// version
VERSION_TAG_NAME
// comments:
"Editeur De N'ours\n"
"L'Editeur Desoxyribo-Nucleique.\n"
"Source Code Editor\n"
"Build Time : " VERSION_BUILD_TIME;
// copyright
"Copyright 2010 Edouard DUPIN, all right reserved";
// licence
"This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY\n\n"
"You can:\n"
" * Redistribute the sources code and binaries.\n"
" * Modify the Sources code.\n"
" * Use a part of the sources (less than 50%) in an other software, just write somewhere \"Edn is great\" visible by the user (on your product or on your website with a link to my page).\n"
" * Redistribute the modification only if you want.\n"
" * Send me the bug-fix (it could be great).\n"
" * Pay me a beer or some other things.\n"
" * Print the source code on WC paper ...\n\n"
"You can NOT:\n"
" * Earn money with this Software (But I can).\n"
" * Add malware in the Sources.\n"
" * Do something bad with the sources.\n"
" * Use it to travel in the space with a toaster.\n\n"
"I reserve the right to change this licence. If it change the version of the copy you have keep its own license."
*/
}
2011-08-19 16:09:58 +02:00
2012-02-29 18:06:08 +01:00
return;
2011-07-21 18:03:41 +02:00
}