67 Commits
1.0 ... 1.1.0

Author SHA1 Message Date
803e2dbc82 Update version tag : 1.1.0 2013-11-28 22:41:47 +01:00
c86a5d89a3 [DEBUG] tag creation error correction 2013-11-28 22:23:42 +01:00
bb0003170b [DEV] add a real stable tag 2013-11-28 21:56:35 +01:00
02c6e75822 [DEV] Update position on undo/redo & write char 2013-11-27 21:45:56 +01:00
14419a521b [DEV] correction of the insert cursor mode 2013-11-27 21:33:42 +01:00
b78455c8fd [DEBUG] Remove some unused element of c++11 in MacOs 2013-11-28 00:52:51 +01:00
357a8baa9a [DEV] add extra compilation flags & correct warning 2013-11-27 21:33:34 +01:00
cb20c0af2d [DEBUG] correction of the first char selection 2013-11-26 21:33:45 +01:00
48260131d3 [DEV] Add ctags jumping 2013-11-26 21:22:06 +01:00
cc5afe2d55 [DEV] debug history manager 2013-11-26 21:06:01 +01:00
4d999bbb67 [DEV] add ctags and select all plugin and correct the undo/redo plugin 2013-11-25 22:18:06 +01:00
b79578b7e1 [DEBUG] remove open folder 2013-11-25 21:20:13 +01:00
9c4d936d76 [DEBUG] Change the title name when rename and status change of a buffer 2013-11-25 21:09:23 +01:00
771a8826c4 [DEV] Reorder BufferView 2013-11-25 21:03:21 +01:00
b3ffe8c212 [DEBUG] Indentation error 2013-11-25 21:03:02 +01:00
aa05234752 [DEV] add std hl of c++ 2013-11-25 21:02:24 +01:00
d3440c153b [DEV] remove dependency of frend in the text viewer 2013-11-24 16:07:43 +01:00
157bd7bcd2 [DEV] add ctrl+w in plgin list (with no frend dependency 2013-11-24 15:27:57 +01:00
16bf6e7648 [DEBUG] correction of the mouse position adter TAB 2013-11-24 15:26:47 +01:00
60903845c1 [DEV] review all the search bar 2013-11-23 18:30:52 +01:00
a95a1e8033 [DEBUG] correction of the end cursor position 2013-11-23 12:25:42 +01:00
26d206caae [DEV] some display update 2013-11-22 21:48:05 +01:00
e15cb8e4b6 [DEV] many small correction 2013-11-21 21:56:22 +01:00
069c457407 [DEBUG] correction of the scrolling wrong position 2013-11-21 21:22:38 +01:00
4efed97130 [DEV] remember multiple last lene in a buffer when change it 2013-11-21 21:18:30 +01:00
0bef90462b [DEBUG] correction of the tabulation error 2013-11-21 21:13:54 +01:00
50579a93a0 [DEBUG] assertion correction 2013-11-20 21:57:00 +01:00
4ea4d0dc55 [DEV] first good vertion from many time... 2013-11-20 21:57:00 +01:00
872fde6bc2 [DEV] sava and close multiple file done 2013-11-19 21:43:43 +01:00
9ca83d1718 [DEV] multiple save and close start to work 2013-11-17 20:37:06 +01:00
e32253cd98 [DEV] start creating worker for display multiple saving 2013-11-15 23:42:00 +01:00
dc652a6237 [DEV] add control before closing buffer not saved... (not ended) 2013-11-14 23:44:55 +01:00
101f77dc3d [DEV] work with std::string 2013-11-14 21:57:10 +01:00
a5b44ae974 [DEV] integarate std x11 2013-11-11 20:20:25 +01:00
4731dae6e4 [DEV] add store 2013-11-07 21:08:57 +01:00
4693119e7d [DEV] test multiple display of one buffer 2013-10-30 21:16:38 +01:00
50c1830696 [DEV] buffer manager better work 2013-10-29 21:13:45 +01:00
7ddaa68bb0 [DEV] start rework buffer manager in resource 2013-10-28 21:47:51 +01:00
01692bdd13 [DEV] correct display with highlight ==> maybe rework the highlight 2013-10-27 20:36:54 +01:00
4d35830559 [DEV] add highlight parsing file 2013-10-27 11:34:45 +01:00
49649329eb [DEV] Add buffer iterator out of bounds control 2013-10-26 13:16:30 +02:00
925fed77f1 [DEV] update Debug in debug 2013-10-25 20:49:26 +02:00
8eb4aff266 [DEV] work on highlight 2013-10-25 22:12:34 +02:00
6f4a67b47b [DEV] glyph pattern might be ended 2013-10-24 21:09:58 +02:00
79b8f594d6 [DEV] think paintin glyph api 2013-10-24 07:46:24 +02:00
8c57b28d73 [DEV] start rework color and highlight 2013-10-23 21:19:30 +02:00
c8fd4183cd [DEV] add missing history plugin 2013-10-22 22:01:31 +02:00
c76f396526 [DEV] add indent one space by one space 2013-10-22 21:44:33 +02:00
29815eb46d [DEV] undo & redo implemented 2013-10-22 21:34:13 +02:00
4c9fb8a74e [DEV] start dev of smart indent 2013-10-21 22:11:16 +02:00
e6480b8cac [DEV] add scrolling and multiline indent module 2013-10-21 21:47:28 +02:00
4704eca027 [DEV] add plugin and rewrite to support the plugin 2013-10-20 18:14:22 +02:00
408a22015c [DEV] simplyfy accec of element with adding iterator 2013-10-18 22:23:52 +02:00
cf8a720924 [DEV] UniChar ==> UChar & Hach ==> Hash 2013-10-18 21:15:02 +02:00
16f78eaef2 [DEV] add copy/cut/paste in std clipboard 2013-10-18 21:01:11 +02:00
0b022d62fc [DEV] add replace of element when selection availlable 2013-10-17 22:23:11 +02:00
8e6d0cc379 [DEV] corect up and down line moving and selection double and triple 2013-10-17 21:57:31 +02:00
171014c86a [DEV] add mouse event 2013-10-16 21:55:45 +02:00
730f637695 [DEV] coding style review 2013-10-09 22:00:24 +02:00
d677075e16 [DEV] code style step 1 2013-10-07 22:04:21 +02:00
211c253116 [DEV] Add the replace mode 2013-09-30 22:32:36 +02:00
7643f5a736 [DEV] display element utf8 and up-down cursor 2013-09-30 00:08:52 +02:00
bd066da738 [DEV] move in the text view widget 2013-09-27 23:02:30 +02:00
1a56f4c49c [DEV] add element availlable ==> bug when adding special char 2013-09-26 22:16:40 +02:00
19d3750f01 [DEV] first display of the cursor 2013-09-26 22:15:39 +02:00
40bf24a095 [DEV] start rework buffer display 2013-09-19 22:23:31 +02:00
b98ee05d2a [DEV] add line at 80 char limitation and set tab at 8 char (not configurable for now) 2013-09-19 09:21:58 +02:00
113 changed files with 8317 additions and 7674 deletions

View File

@@ -102,3 +102,7 @@ License (GPLv3)
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Annexe
==================
sudo cp data/edn.desktop /usr/share/applications/

28
data/GUI-Search.xml Normal file
View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<composer>
<sizer mode="hori" expand="true,false" fill="true" lock="true">
<button name="SEARCH:close">
<image src="THEME:GUI:Remove.svg" fill="true" size="7,7mm"/>
</button>
<entry name="SEARCH:search-entry" expand="true" fill="true"/>
<button name="SEARCH:search">
<image src="THEME:GUI:Search.svg" fill="true" size="7,7mm"/>
</button>
<entry name="SEARCH:replace-entry" expand="true" fill="true"/>
<button name="SEARCH:replace">
<image src="THEME:GUI:Replace.svg" fill="true" size="7,7mm"/>
</button>
<button name="SEARCH:case">
<image src="THEME:GUI:CaseSensitive.svg" fill="true" size="7,7mm" hover="Close search bar"/>
<image src="THEME:GUI:CaseSensitive.svg" fill="true" size="7,7mm" hover="Close search bar"/>
</button>
<button name="SEARCH:wrap">
<image src="THEME:GUI:WrapAround.svg" fill="true" size="7,7mm" hover="Close search bar"/>
<image src="THEME:GUI:WrapAround.svg" fill="true" size="7,7mm" hover="Close search bar"/>
</button>
<button name="SEARCH:up-down">
<image src="THEME:GUI:Up.svg" fill="true" size="7,7mm" hover="Close search bar"/>
<image src="THEME:GUI:Down.svg" fill="true" size="7,7mm" hover="Close search bar"/>
</button>
</sizer>
</composer>

View File

@@ -1,40 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<EdnColor version="0.1">
<gui> <!-- Doivent tous y <20>tre de prf<72>rence ... global system acces -->
<color name="CODE_basicBackgroung" val="#151515"/>
<color name="CODE_space" val="#333333"/>
<color name="CODE_tabulation" val="#444444"/>
<color name="CODE_cursor" val="#eadd05"/>
<color name="CODE_lineNumber" val="#fff725"/>
<!-- Buffer list property -->
<color name="LIST_backgroung1" val="#202020"/>
<color name="LIST_backgroung2" val="#000000"/>
<color name="LIST_backgroungSelected" val="#2f0ba4"/>
<color name="LIST_textNormal" val="#EEEEEE"/>
<color name="LIST_textModify" val="#FF0000"/>
</gui>
<syntax>
<color name="normal" FG="#EEEEEE"/>
<color name="SelectedText" FG="#AAAAAA" BG="#225a09"/>
<color name="error" FG="#FF0000"/>
<color name="doubleQuoteText" FG="#00fF00"/>
<!-- hightline description : -->
<color name="type" FG="#56bf10" bold="yes"/>
<color name="storageKeyword" FG="#5c8fed"/>
<color name="number" FG="#00ff00"/>
<color name="systemFunction" FG="#ffff00"/>
<color name="commonDefine" FG="#56bf10"/>
<color name="boolean" FG="#214cf1"/>
<color name="preprocesseur" FG="#FF0000"/>
<color name="comment" FG="#ef4def" italic="yes"/>
<color name="commentDoxygen" FG="#ef4d00" bold="yes" italic="yes"/>
<color name="keyword" FG="#5c8fed" bold="yes"/>
<color name="macro" FG="#6c09c8" bold="yes"/>
<color name="SYNTAX_ERROR" FG="#000000" BG="#FF0000" bold="yes"/>
<color name="functionName" FG="#24d1e0" bold="yes"/>
<color name="TestResultOK" FG="#000000" BG="#00FF00" bold="yes"/>
<color name="TestResultERROR" FG="#000000" BG="#FF0000" bold="yes"/>
</syntax>
</EdnColor>

View File

@@ -1,42 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<EdnColor version="0.1">
<gui> <!-- Doivent tous y <20>tre de prf<72>rence ... global system acces -->
<color name="CODE_basicBackgroung" val="#d9d7d7"/>
<color name="CODE_space" val="#b7b6b6"/>
<color name="CODE_tabulation" val="#a7a5a5"/>
<color name="CODE_cursor" val="#2a00ff"/>
<color name="CODE_lineNumber" val="#1a00a0"/>
<!-- Buffer list property -->
<color name="LIST_backgroung1" val="#d9d7d7"/>
<color name="LIST_backgroung2" val="#b7b6b6"/>
<color name="LIST_backgroungSelected" val="#3da3f9"/>
<color name="LIST_textNormal" val="#000000"/>
<color name="LIST_textModify" val="#FF0000"/>
</gui>
<syntax>
<color name="normal" FG="#000000"/>
<color name="SelectedText" FG="#292929" BG="#009ce7"/>
<color name="error" FG="#FF0000"/>
<color name="doubleQuoteText" FG="#008e00"/>
<!-- hightline description : -->
<color name="type" FG="#376d0a" bold="yes"/>
<color name="memberClass" FG="#7c5406" bold="yes"/>
<color name="inputFunction" FG="#B80000" bold="yes" italic="yes"/>
<color name="storageKeyword" FG="#466cb4"/>
<color name="number" FG="#007b00"/>
<color name="systemFunction" FG="#acaa00"/>
<color name="commonDefine" FG="#3c850b"/>
<color name="boolean" FG="#1633a3"/>
<color name="preprocesseur" FG="#ac0000"/>
<color name="comment" FG="#b704b5" italic="yes"/>
<color name="commentDoxygen" FG="#bf3e00" bold="yes" italic="yes"/>
<color name="keyword" FG="#215eb8" bold="yes"/>
<color name="macro" FG="#571793" bold="yes"/>
<color name="SYNTAX_ERROR" FG="#000000" BG="#c20000" bold="yes"/>
<color name="functionName" FG="#09857e" bold="yes"/>
<color name="TestResultOK" FG="#000000" BG="#009c00" bold="yes"/>
<color name="TestResultERROR" FG="#000000" BG="#c20000" bold="yes"/>
</syntax>
</EdnColor>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<EdnLang version="0.1" lang="boulou log">
<EdnLang version="0.1" lang="Boulou log">
<ext>*.boo</ext>
<pass1><!-- multiline section & parse all file (now) and when modification retrive previous modification -->
<rule name="comment ##">

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<EdnLang version="0.1" lang="c">
<EdnLang version="0.1" lang="C/C++">
<ext>*.c</ext>
<ext>*.cpp</ext>
<ext>*.cc</ext>
@@ -85,7 +85,11 @@
</rule>
<rule name="my type">
<color>type</color>
<start>\@bool|BOOL|char|double|float|u?int(8|16|32|64|128)?(_t)?|long|short|signed|size_t|unsigned|void|(I|U)(8|16|32|64|128)\@</start>
<start>\@bool|BOOL|char(16_t|32_t)?|double|float|u?int(8|16|32|64|128)?(_t)?|long|short|signed|size_t|unsigned|void|(I|U)(8|16|32|64|128)\@</start>
</rule>
<rule name="std type">
<color>type</color>
<start>\@std::(vector|(u16|u32|w)?string|codecvt_utf(16|8_utf16|8)+|complex|iterator(_traits)?|tuple(_element|_size)?|pair)\@</start>
</rule>
<rule name="my storage keyword">
<color>storageKeyword</color>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<EdnLang version="0.1" lang="glsl">
<EdnLang version="0.1" lang="Glsl">
<ext>*.glsl</ext>
<ext>*.vert</ext>
<ext>*.frag</ext>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<EdnLang version="0.1" lang="qconf configuration file">
<EdnLang version="0.1" lang="Kernel conf file">
<ext>*.in</ext>
<pass1><!-- multiline section & parse all file (now) and when modification retrive previous modification -->
<rule name="my preprocesseur">

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<EdnLang version="0.1" lang="java">
<EdnLang version="0.1" lang="Java">
<ext>*.java</ext>
<pass1><!-- multiline section & parse all file (now) and when modification retrive previous modification -->
<rule name="my comment multiline doxygen">

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<EdnLang version="0.1" lang="json">
<EdnLang version="0.1" lang="Json">
<ext>*.json</ext>
<pass1><!-- multiline section & parse all file (now) and when modification retrive previous modification -->
<rule name="doubleQuteText">
@@ -22,5 +22,13 @@
<color>functionName</color>
<start>([a-zA-Z0-9]|-|_)*</start>
</rule>
<rule name="numeric constant">
<color>number</color>
<start>\@((0(x|X)[0-9a-fA-F]*)|(\d+\.?\d*|\.\d+)((e|E)(\+|\-)?\d+)?)(L|l|UL|ul|u|U|F|f)?\@</start>
</rule>
<rule name="my boolean">
<color>boolean</color>
<start>\@true|false\@</start>
</rule>
</pass2>
</EdnLang>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<EdnLang version="0.1" lang="c">
<EdnLang version="0.1" lang="Lua">
<ext>*.lua</ext>
<pass1>
<rule name="Comment multiline">

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<EdnLang version="0.1" lang="matlab">
<EdnLang version="0.1" lang="Matlab">
<ext>*.m</ext>
<ext>*.M</ext>
<pass1><!-- multiline section & parse all file (now) and when modification retrive previous modification -->

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<EdnLang version="0.1" lang="php: pretty home page">
<EdnLang version="0.1" lang="Php: pretty home page">
<ext>*.php</ext>
<ext>*.php3</ext>
<ext>*.php4</ext>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<EdnLang version="0.1" lang="c">
<EdnLang version="0.1" lang="Python">
<ext>*.py</ext>
<pass1><!-- multiline section & parse all file (now) and when modification retrive previous modification -->
<rule name="my comment multiline">

View File

@@ -0,0 +1,9 @@
{
"ednColor": [
{ name:"backgroung1", foreground:"#202020" },
{ name:"backgroung2", foreground:"#000000" },
{ name:"backgroungSelected", foreground:"#2f0ba4" },
{ name:"textNormal", foreground:"#EEEEEE" },
{ name:"textModify", foreground:"#FF0000" },
]
}

View File

@@ -0,0 +1,31 @@
{
"ednColor": [
{ name:"CODE_basicBackgroung", foreground:"#151515" },
{ name:"CODE_space", foreground:"#333333" },
{ name:"CODE_tabulation", foreground:"#444444" },
{ name:"CODE_cursor", foreground:"#eadd05" },
{ name:"CODE_lineNumber", foreground:"#fff725", background:"#464646"},
{ name:"normal", foreground:"#EEEEEE"},
{ name:"SelectedText", foreground:"#AAAAAA", background:"#225a09"},
{ name:"error", foreground:"#FF0000"},
{ name:"doubleQuoteText", foreground:"#00FF00"},
{ name:"type", foreground:"#56bf10", bold:true},
{ name:"storageKeyword", foreground:"#5c8fed"},
{ name:"inputFunction", foreground:"#B80000", bold:true, italic:true},
{ name:"memberClass", foreground:"#7c5406", bold:true},
{ name:"number", foreground:"#00ff00"},
{ name:"systemFunction", foreground:"#ffff00"},
{ name:"commonDefine", foreground:"#56bf10"},
{ name:"boolean", foreground:"#214cf1"},
{ name:"preprocesseur", foreground:"#FF0000"},
{ name:"comment", foreground:"#ef4def", italic:true},
{ name:"commentDoxygen", foreground:"#ef4d00", bold:true, italic:true},
{ name:"keyword", foreground:"#5c8fed", bold:true},
{ name:"macro", foreground:"#6c09c8", bold:true},
{ name:"SYNTAX_ERROR", foreground:"#000000", background:"#FF0000", bold:true},
{ name:"functionName", foreground:"#24d1e0", bold:true},
{ name:"TestResultOK", foreground:"#000000", background:"#00FF00", bold:true},
{ name:"TestResultERROR", FG:"#000000", background:"#FF0000", bold:true}
]
}

View File

@@ -0,0 +1,9 @@
{
"ednColor": [
{ name:"backgroung1", foreground:"#d9d7d7"},
{ name:"backgroung2", foreground:"#b7b6b6"},
{ name:"backgroungSelected", foreground:"#3da3f9"},
{ name:"textNormal", foreground:"#000000"},
{ name:"textModify", foreground:"#FF0000"}
]
}

View File

@@ -0,0 +1,31 @@
{
"ednColor": [
{ name:"CODE_basicBackgroung", foreground:"#d9d7d7"},
{ name:"CODE_space", foreground:"#b7b6b6"},
{ name:"CODE_tabulation", foreground:"#a7a5a5"},
{ name:"CODE_cursor", foreground:"#2a00ff"},
{ name:"CODE_lineNumber", foreground:"#1a00a0", background:"#a2a2a2"},
{ name:"normal", foreground:"#000000"},
{ name:"SelectedText", foreground:"#292929", background:"#009ce7"},
{ name:"error", foreground:"#FF0000"},
{ name:"doubleQuoteText", foreground:"#008e00"},
{ name:"type", foreground:"#376d0a", bold:true},
{ name:"memberClass", foreground:"#7c5406", bold:true},
{ name:"inputFunction", foreground:"#B80000", bold:true, italic:true},
{ name:"storageKeyword", foreground:"#466cb4"},
{ name:"number", foreground:"#007b00"},
{ name:"systemFunction", foreground:"#acaa00"},
{ name:"commonDefine", foreground:"#3c850b"},
{ name:"boolean", foreground:"#1633a3"},
{ name:"preprocesseur", foreground:"#ac0000"},
{ name:"comment", foreground:"#b704b5", italic:true},
{ name:"commentDoxygen", foreground:"#bf3e00", bold:true, italic:true},
{ name:"keyword", foreground:"#215eb8", bold:true},
{ name:"macro", foreground:"#571793", bold:true},
{ name:"SYNTAX_ERROR", foreground:"#000000", background:"#c20000", bold:true},
{ name:"functionName", foreground:"#09857e", bold:true},
{ name:"TestResultOK", foreground:"#000000", background:"#009c00", bold:true},
{ name:"TestResultERROR", foreground:"#000000", background:"#c20000", bold:true}
]
}

987
sources/appl/Buffer.cpp Normal file
View File

@@ -0,0 +1,987 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/Buffer.h>
#include <appl/debug.h>
#include <ewol/clipBoard.h>
#include <appl/HighlightManager.h>
const char* const appl::Buffer::eventIsModify = "edn-is-modify";
const char* const appl::Buffer::eventIsSave = "edn-is-save";
const char* const appl::Buffer::eventSelectChange = "edn-select-change";
const char* const appl::Buffer::eventChangeName = "edn-buffer-name-change";
appl::Buffer::Iterator& appl::Buffer::Iterator::operator++ (void) {
m_value = etk::UChar::Null;
if (m_current < 0) {
m_current = 0;
return *this;
}
if (m_data != NULL) {
if (m_current < m_data->m_data.size() ) {
int8_t nbChar = etk::UChar::theoricUTF8Len(m_data->m_data[m_current]);
if (nbChar != 0) {
m_current+=nbChar;
} else {
m_current++;
}
}
if (m_current >= m_data->m_data.size()) {
m_current = m_data->m_data.size();
}
}
return *this;
}
appl::Buffer::Iterator& appl::Buffer::Iterator::operator-- (void) {
m_value = etk::UChar::Null;
if (m_data != NULL) {
if (m_current > 0) {
int32_t iii = -1;
while( etk::UChar::theoricUTF8First(m_data->m_data[m_current+iii]) == false
&& iii >= -6
&& m_current-iii>0) {
--iii;
};
m_current += iii;
} else {
m_current = -1;
}
return *this;
} else {
m_current = -1;
}
return *this;
}
char32_t appl::Buffer::Iterator::operator* (void) {
if (m_value != etk::UChar::Null) {
return m_value;
}
if (m_data == NULL) {
APPL_ERROR("request an element that iterator not link");
return m_value;
}
if ( m_current < 0
|| m_current >= m_data->m_data.size()) {
APPL_ERROR("request an element out of bounding !!! 0 <= " << m_current << " < " << m_data->m_data.size());
return m_value;
}
char tmpVal[5];
memset(tmpVal, 0, sizeof(tmpVal));
tmpVal[0] = m_data->m_data[m_current];
int8_t nbChar = etk::UChar::theoricUTF8Len(tmpVal[0]);
for (int32_t iii=1; iii<nbChar && m_current+iii<m_data->m_data.size(); ++iii) {
tmpVal[iii] = m_data->m_data[m_current+iii];
}
// transform ...
m_value = etk::setUtf8(tmpVal);
return m_value;
}
appl::Buffer::Iterator appl::Buffer::position(int64_t _pos) {
return appl::Buffer::Iterator(this, _pos);
}
appl::Buffer::Iterator appl::Buffer::begin(void) {
return position(0);
}
appl::Buffer::Iterator appl::Buffer::end(void) {
// TODO : chek the validity of the char ...
return position( m_data.size() );
}
appl::Buffer::Iterator appl::Buffer::cursor(void) {
if (m_cursorPos<= 0) {
return begin();
}
return position( m_cursorPos );
}
appl::Buffer::Iterator appl::Buffer::selectStart(void) {
return position( getStartSelectionPos() );
}
appl::Buffer::Iterator appl::Buffer::selectStop(void) {
return position( getStopSelectionPos() );
}
appl::Buffer::Buffer(void) :
m_hasFileName(false),
m_fileName(""),
m_isModify(false),
m_cursorPos(0),
m_cursorSelectPos(-1),
m_cursorPreferredCol(-1),
m_nbLines(1),
m_highlight(NULL) {
addObjectType("appl::Buffer");
static int32_t bufferBaseId = 0;
m_fileName = "No Name " + std::to_string(bufferBaseId);
bufferBaseId++;
addEventId(eventIsModify);
addEventId(eventIsSave);
addEventId(eventSelectChange);
addEventId(eventChangeName);
}
appl::Buffer::~Buffer(void) {
if (m_highlight == NULL) {
appl::Highlight::release(m_highlight);
}
}
bool appl::Buffer::loadFile(const std::string& _name) {
APPL_DEBUG("Load file : '" << _name << "'");
m_fileName = _name;
m_hasFileName = true;
m_isModify = true;
m_cursorPos = 0;
setHighlightType("");
etk::FSNode file(m_fileName);
if (file.exist() == false) {
APPL_INFO("File doesn not exist !!! " << file);
return false;
}
m_nbLines = 0;
if (true == m_data.dumpFrom(file) ) {
countNumberofLine();
tryFindHighlightType();
m_isModify = false;
return true;
}
return false;
}
void appl::Buffer::setFileName(const std::string& _name) {
if (m_fileName == _name) {
return;
}
m_fileName = _name;
m_hasFileName = true;
generateEventId(eventChangeName);
setModification(true);
}
bool appl::Buffer::storeFile(void) {
etk::FSNode file(m_fileName);
if (true == m_data.dumpIn(file) ) {
APPL_INFO("saving file : " << file);
setModification(false);
return true;
}
return false;
}
void appl::Buffer::setModification(bool _status) {
if (m_isModify == _status) {
return;
}
m_isModify = _status;
if (m_isModify == true) {
generateEventId(eventIsModify);
} else {
generateEventId(eventIsSave);
}
}
// TODO : Naming error
void appl::Buffer::countNumberofLine(void) {
m_nbLines = 1;
for (Iterator it = begin();
(bool)it == true;
++it) {
if (*it == etk::UChar::Return) {
++m_nbLines;
}
}
}
appl::Buffer::Iterator appl::Buffer::getStartLine(const appl::Buffer::Iterator& _pos) {
appl::Buffer::Iterator startPos;
if (false == searchBack(_pos, etk::UChar::Return, startPos)) {
return begin();
}
// note search will return the position of \n ==> the lione start just after ...
return startPos+1;
}
appl::Buffer::Iterator appl::Buffer::getEndLine(const appl::Buffer::Iterator& _pos) {
appl::Buffer::Iterator endPos;
if (false == search(_pos, etk::UChar::Return, endPos)) {
endPos = end();
}
// Note the line end at the \n
return endPos;
}
bool appl::Buffer::search(const appl::Buffer::Iterator& _pos, const char32_t& _search, appl::Buffer::Iterator& _result) {
// move in the string
for (Iterator it = _pos;
(bool)it == true;
++it) {
if (*it == _search) {
_result = it;
return true;
}
}
_result = end();
return false;
}
bool appl::Buffer::searchBack(const appl::Buffer::Iterator& _pos, const char32_t& _search, appl::Buffer::Iterator& _result) {
// move in the string
for (Iterator it = _pos - 1;
(bool)it == true;
--it) {
//APPL_DEBUG("compare : " << *it << " ?= " << _search);
if (*it == _search) {
//APPL_DEBUG("find : " << (int32_t)it);
_result = it;
return true;
}
}
_result = begin();
return false;
}
bool appl::Buffer::search(const appl::Buffer::Iterator& _pos,
const std::u32string& _search,
appl::Buffer::Iterator& _result,
bool _caseSensitive) {
if (_search.size() <= 0 ) {
return false;
}
if (_caseSensitive == true) {
// move in the string
for (Iterator it = _pos;
(bool)it == true;
++it) {
if (*it == _search[0]) {
// find the first char ==> check next...
bool find = true;
Iterator tmp = it;
for (size_t iii=0; iii<_search.size(); ++iii) {
if (*tmp != _search[iii]) {
find = false;
break;
}
++tmp;
if ((bool)tmp == false) {
if (iii != _search.size()-1) {
find = false;
}
break;
}
}
if (find == true) {
_result = it;
return true;
}
}
}
} else {
char32_t firstElement = tolower(_search[0]);
// move in the string
for (Iterator it = _pos;
(bool)it == true;
++it) {
if (tolower(*it) == firstElement) {
// find the first char ==> check next...
bool find = true;
Iterator tmp = it;
for (size_t iii=0; iii<_search.size(); ++iii) {
if (tolower(*tmp) != tolower(_search[iii])) {
find = false;
break;
}
++tmp;
if ((bool)tmp == false) {
if (iii != _search.size()-1) {
find = false;
}
break;
}
}
if (find == true) {
_result = it;
return true;
}
}
}
}
_result = end();
return false;
}
bool appl::Buffer::searchBack(const appl::Buffer::Iterator& _pos,
const std::u32string& _search,
appl::Buffer::Iterator& _result,
bool _caseSensitive) {
if (_search.size() <= 0 ) {
return false;
}
char32_t lastElement = _search[_search.size()-1];
if (_caseSensitive == true) {
// move in the string
for (Iterator it = _pos - 1;
(bool)it == true;
--it) {
//APPL_DEBUG("compare : " << *it << " ?= " << _search);
if (*it == lastElement) {
// find the last char ==> check previous...
bool find = true;
_result = it;
for (int64_t iii=_search.size()-1; iii>=0; --iii) {
if (*_result != _search[iii]) {
find = false;
break;
}
--_result;
if ((bool)_result == false) {
if (iii != 0) {
find = false;
}
break;
}
}
if (find == true) {
_result++;
return true;
}
}
}
} else {
lastElement = tolower(lastElement);
// move in the string
for (Iterator it = _pos - 1;
(bool)it == true;
--it) {
//APPL_DEBUG("compare : " << *it << " ?= " << _search);
if (tolower(*it) == lastElement) {
// find the last char ==> check previous...
bool find = true;
_result = it;
for (int64_t iii=_search.size()-1; iii>=0; --iii) {
if (tolower(*_result) != tolower(_search[iii])) {
find = false;
break;
}
--_result;
if ((bool)_result == false) {
if (iii != 0) {
find = false;
}
break;
}
}
if (find == true) {
_result++;
return true;
}
}
}
}
_result = begin();
return false;
}
void appl::Buffer::moveCursor(int64_t _pos) {
m_cursorPreferredCol = -1;
APPL_VERBOSE("move cursor : " << _pos << "/" << m_data.size());
// selecting mode ...
if (m_selectMode == true) {
if (m_cursorSelectPos == -1) {
m_cursorSelectPos = m_cursorPos;
if (m_cursorSelectPos < 0) {
m_cursorSelectPos = 0;
}
}
//APPL_DEBUG("Select : " << m_cursorSelectPos << " ==> " << _pos);
m_cursorPos = _pos;
if (m_cursorPos == m_cursorSelectPos) {
m_cursorSelectPos = -1;
}
generateEventId(eventSelectChange);
return;
}
// move mode
m_cursorPos = _pos;
m_cursorSelectPos = -1;
generateEventId(eventSelectChange);
}
bool appl::Buffer::getPosAround(const appl::Buffer::Iterator& _startPos,
appl::Buffer::Iterator &_beginPos,
appl::Buffer::Iterator &_endPos) {
char32_t currentValue = *position(_startPos);
_beginPos = begin();
_endPos = end();
if ( currentValue == etk::UChar::Tabulation
|| currentValue == etk::UChar::Space) {
APPL_DEBUG("select spacer");
// Search back
for (Iterator it = --position(_startPos);
(bool)it == true;
--it) {
currentValue = *it;
if ( currentValue != etk::UChar::Tabulation
&& currentValue != etk::UChar::Space) {
_beginPos = ++it;
break;
}
}
// Search forward
for (Iterator it = position(_startPos);
(bool)it == true;
++it) {
currentValue = *it;
if ( currentValue != etk::UChar::Tabulation
&& currentValue != etk::UChar::Space) {
_endPos = it;
break;
}
}
return true;
} else if( etk::isSpecialChar(currentValue) == false
|| currentValue == '_') {
APPL_DEBUG("select normal Char");
// Search back
for (Iterator it = --position(_startPos);
(bool)it == true;
--it) {
currentValue = *it;
if ( currentValue != '_'
&& true == etk::isSpecialChar(currentValue)) {
_beginPos = ++it;
break;
}
}
// Search forward
for (Iterator it = position(_startPos);
(bool)it == true;
++it) {
currentValue = *it;
if ( currentValue != '_'
&& true == etk::isSpecialChar(currentValue)) {
_endPos = it;
break;
}
}
return true;
} else {
APPL_DEBUG("select same char");
char32_t comparechar = currentValue;
// Search back
for (Iterator it = --position(_startPos);
(bool)it == true;
--it) {
currentValue = *it;
if (comparechar != currentValue) {
_beginPos = ++it;
break;
}
}
// Search forward
for (Iterator it = position(_startPos);
(bool)it == true;
++it) {
currentValue = *it;
if (comparechar != currentValue) {
_endPos = it;
break;
}
}
return true;
}
_beginPos = begin();
_endPos = begin();
return false;
}
void appl::Buffer::setSelectionPos(const appl::Buffer::Iterator& _pos) {
m_cursorSelectPos = _pos;
generateEventId(eventSelectChange);
}
void appl::Buffer::unSelect(void) {
m_cursorSelectPos = -1;
generateEventId(eventSelectChange);
}
static const char *ControlCodeTable[32] = {
"NUL", "soh", "stx", "etx", "eot", "enq", "ack", "bel", "bs", "ht", "nl", "vt", "np", "cr", "so", "si",
"dle", "dc1", "dc2", "dc3", "dc4", "nak", "syn", "etb", "can", "em", "sub", "esc", "fs", "gs", "rs", "us"};
void appl::Buffer::expand(int32_t& _indent, const char32_t& _value, std::u32string& _out) const {
_out.clear();
int32_t tabDist = 4;
if (_value == etk::UChar::Tabulation) {
int32_t nSpaces = tabDist - (_indent % tabDist);
for (int32_t iii=0; iii<nSpaces; iii++) {
_out += etk::UChar::Space;
}
return;
}
// convert ASCII control codes to readable character sequences
if (_value == etk::UChar::Null) {
_out += U"<nul>";
return;
}
if (_value == etk::UChar::Return) {
// nothing to display...
_out += etk::UChar::Return;
return;
}
if (_value <= 31) {
_out += '<';
const char * tmp = ControlCodeTable[_value];
while (*tmp!='\0') {
_out += *tmp;
tmp++;
}
_out += '>';
return;
}
if (_value == etk::UChar::Delete) {
_out += U"<del>";
return;
}
// nothing to do ...
_out += _value;
//APPL_DEBUG("plop : " << _out);
}
appl::Buffer::Iterator appl::Buffer::countForwardNLines(const appl::Buffer::Iterator& _startPos, int32_t _nLines) {
char32_t value;
int32_t lineCount = 0;
//APPL_INFO("startPos=" << startPos << " nLines=" << nLines);
for (Iterator it = position(_startPos);
(bool)it == true;
++it) {
value = *it;
if (value == etk::UChar::Return) {
lineCount++;
if (lineCount == _nLines) {
//APPL_INFO(" == > (1) at position=" << myPosIt.Position()+1 );
return ++it;
}
}
}
//APPL_INFO(" == > (2) at position=" << myPosIt.Position() );
return end();
}
appl::Buffer::Iterator appl::Buffer::countBackwardNLines(const appl::Buffer::Iterator& _startPos, int32_t _nLines) {
//APPL_INFO("startPos=" << startPos << " nLines=" << nLines);
char32_t value;
int32_t lineCount = 0;
for (Iterator it = --position(_startPos);
(bool)it == true;
--it) {
value = *it;
if (value == etk::UChar::Return) {
lineCount++;
if (lineCount >= _nLines) {
//APPL_INFO(" == > (1) at position=" << myPosIt.Position()+1 );
return ++it;
}
}
}
//APPL_INFO(" == > (2) at position=0");
return begin();
}
bool appl::Buffer::copy(std::string& _data) {
_data.clear();
if (hasTextSelected() == true) {
int32_t startPos = getStartSelectionPos();
int32_t endPos = getStopSelectionPos();
for (Iterator it = position(startPos);
it != position(endPos) &&
(bool)it == true;
++it) {
_data += *it;
}
return true;
}
return false;
}
void appl::Buffer::copy(std::string& _data, const appl::Buffer::Iterator& _pos, const appl::Buffer::Iterator& _posEnd) {
_data.clear();
int64_t startPos = getStartSelectionPos();
int64_t endPos = getStopSelectionPos();
for (Iterator it = _pos;
it != _posEnd &&
(bool)it == true;
++it) {
_data += *it;
}
}
bool appl::Buffer::write(const std::string& _data, const appl::Buffer::Iterator& _pos) {
int64_t position = (int64_t)_pos;
if (position < 0){
position = 0;
}
APPL_ERROR("writye at pos: " << (int64_t)_pos << " ==> " << position);
m_data.insert(position, (int8_t*)(_data.c_str()), _data.size());
if (m_cursorPos < 0) {
m_cursorPos = 0;
}
regenerateHighLightAt(position, 0, _data.size());
m_selectMode = false;
moveCursor(position+_data.size());
countNumberofLine(); // TODO : use more intelligent counter
setModification(true);
return true;
}
bool appl::Buffer::replace(const std::string& _data, const appl::Buffer::Iterator& _pos, const appl::Buffer::Iterator& _posEnd) {
int64_t position = (int64_t)_pos;
if (position < 0){
position = 0;
}
m_data.replace(position, (int64_t)_posEnd-(int64_t)_pos, (int8_t*)(_data.c_str()), _data.size());
regenerateHighLightAt(position, (int64_t)_posEnd-(int64_t)_pos, _data.size());
m_selectMode = false;
moveCursor(position+_data.size());
countNumberofLine(); // TODO : use more intelligent counter
setModification(true);
return true;
}
void appl::Buffer::removeSelection(void) {
if (hasTextSelected() == false) {
return;
}
int64_t startPos = getStartSelectionPos();
int64_t endPos = getStopSelectionPos();
m_data.remove(startPos, endPos-startPos);
regenerateHighLightAt(startPos, endPos-startPos, 0);
m_selectMode = false;
moveCursor(startPos);
countNumberofLine(); // TODO : use more intelligent counter
setModification(true);
}
void appl::Buffer::tryFindHighlightType(void) {
etk::FSNode file(m_fileName);
std::string type = appl::highlightManager::getTypeExtention(file.fileGetExtention());
if (type.size() == 0) {
return;
}
APPL_DEBUG("Find extention type: " << type);
setHighlightType(type);
}
void appl::Buffer::setHighlightType(const std::string& _type) {
m_highlightType = "";
cleanHighLight();
if (m_highlight == NULL) {
appl::Highlight::release(m_highlight);
}
std::string resourceName = appl::highlightManager::getFileWithTypeType(_type);
if (resourceName == "") {
return;
}
m_highlightType = _type;
m_highlight = appl::Highlight::keep(resourceName);
generateHighLightAt(0, m_data.size());
}
void appl::Buffer::regenerateHighLightAt(int64_t _pos, int64_t _nbDeleted, int64_t _nbAdded) {
// prevent ERROR...
if (NULL == m_highlight) {
return;
}
// prevent No data Call
if ( _nbDeleted == 0
&& _nbAdded == 0) {
return;
}
// normal case
//APPL_INFO("(pos="<<pos<<", nbDeleted="<<nbDeleted<<", nbAdded=" << nbAdded << "\");");
int64_t posEnd = _pos + _nbDeleted;
// search position of the old element to reparse IT...
int64_t startId;
int64_t stopId;
// clean data if needed
if (m_HLDataPass1.size() == 0) {
// Parse the new element ...
generateHighLightAt(0, m_data.size());
return;
}
// find element previous
findMainHighLightPosition(_pos, posEnd, startId, stopId, true);
// remove deprecated element
if ( startId == -1
&& stopId == -1) {
m_HLDataPass1.clear();
} else if (startId == -1) {
if (stopId == 0){
m_HLDataPass1.erase(m_HLDataPass1.begin());
//APPL_DEBUG("1 * Erase 0");
} else {
m_HLDataPass1.erase(m_HLDataPass1.begin(), m_HLDataPass1.begin()+stopId);
//APPL_DEBUG("2 * Erase 0->" << stopId);
}
} else if (stopId == -1) {
//APPL_DEBUG("3 * Erase " << startId+1 << "-> end");
m_HLDataPass1.erase(m_HLDataPass1.begin()+startId+1, m_HLDataPass1.end());
stopId = -1;
} else {
int32_t currentSize = m_HLDataPass1.size();
//APPL_DEBUG("4 * Erase " << startId+1 << "->" << stopId << " in " << currentSize << " elements" );
m_HLDataPass1.erase(m_HLDataPass1.begin()+startId+1, m_HLDataPass1.begin()+stopId);
if (stopId == currentSize-1) {
stopId = -1;
}
}
//APPL_DEBUG("new size=" << (int32_t)m_HLDataPass1.size()-1);
// update position after the range position :
int64_t elemStart;
if (startId == -1) {
elemStart = 0;
} else {
elemStart = startId+1;
}
for (int64_t iii = elemStart; iii < m_HLDataPass1.size(); ++iii) {
//APPL_DEBUG("move element=" << i);
m_HLDataPass1[iii].beginStart += _nbAdded - _nbDeleted;
m_HLDataPass1[iii].beginStop += _nbAdded - _nbDeleted;
m_HLDataPass1[iii].endStart += _nbAdded - _nbDeleted;
m_HLDataPass1[iii].endStop += _nbAdded - _nbDeleted;
}
//Regenerate Element inside range
if ( startId == -1
&& stopId == -1) {
//APPL_DEBUG("******* Regenerate ALL");
generateHighLightAt(0, m_data.size());
} else if(-1 == startId) {
//APPL_DEBUG("******* Regenerate START");
generateHighLightAt(0, m_HLDataPass1[0].beginStart, 0);
} else if(-1 == stopId) {
//APPL_DEBUG("******* Regenerate STOP");
generateHighLightAt(m_HLDataPass1[m_HLDataPass1.size() -1].endStop, m_data.size(), m_HLDataPass1.size());
} else {
//APPL_DEBUG("******* Regenerate RANGE");
generateHighLightAt(m_HLDataPass1[startId].endStop, m_HLDataPass1[startId+1].beginStart, startId+1);
}
}
void appl::Buffer::findMainHighLightPosition(int64_t _startPos,
int64_t _endPos,
int64_t& _startId,
int64_t& _stopId,
bool _backPreviousNotEnded) {
_startId = -1;
_stopId = -1;
/* rules to start stop:
HighLight data ----
remove area ****
Start pos S
End pos E
Some Case :
----------- ------------ ------------- ----------
S **** E
----------- ------------ ------------- ----------
S ********** E
----------- ------------ ------------- ----------
S **** E
----------- ------------ ------------- ----------
S ********* E
----------- ------------ ------------- ----------
S ********************* E
----------- ------------ ------------- ----------
S ************************ E
----------- ------------ ------------- ----------
S ***************** E
----------- ------------ ------------- ----------
S *************** E
----------- ------------
S *************** E=-1
------------ ------------- ----------
S=-1 *************** E
*/
for (int32_t iii = 0; iii < m_HLDataPass1.size(); ++iii) {
if (m_HLDataPass1[iii].endStop > _startPos) {
break;
}
_startId = iii;
}
// go back while the previous element is not eneded
if (_backPreviousNotEnded == true) {
for (int64_t iii = _startId; iii >= 0; --iii) {
if (m_HLDataPass1[iii].notEnded == false) {
break;
}
_startId = iii-1;
}
}
int64_t elemStart;
if(_startId == -1) {
elemStart = 0;
} else {
elemStart = _startId+1;
}
for (int32_t iii = elemStart; iii < m_HLDataPass1.size(); ++iii) {
if (m_HLDataPass1[iii].beginStart > _endPos) {
_stopId = iii;
break;
}
}
}
void appl::Buffer::generateHighLightAt(int64_t _pos, int64_t _endPos, int64_t _addingPos) {
if (NULL == m_highlight) {
return;
}
//APPL_DEBUG("area : ("<<pos<<","<<endPos<<") insert at : " << addingPos);
m_highlight->parse(_pos, _endPos, m_HLDataPass1, _addingPos, m_data);
}
void appl::Buffer::cleanHighLight(void) {
// remove all element in the list...
m_HLDataPass1.clear();
}
appl::HighlightInfo* appl::Buffer::getElementColorAtPosition(int64_t _pos, int64_t &_starPos) {
int32_t start = etk_max(0, _starPos-1);
for (int32_t iii = start; iii < m_HLDataPass1.size(); ++iii) {
_starPos = iii;
if ( m_HLDataPass1[iii].beginStart <= _pos
&& m_HLDataPass1[iii].endStop > _pos) {
return &m_HLDataPass1[iii];
}
if(m_HLDataPass1[iii].beginStart > _pos) {
return NULL;
}
}
return NULL;
}
void appl::Buffer::hightlightGenerateLines(appl::DisplayHLData& _MData, int64_t _HLStart, int64_t _nbLines) {
_MData.posHLPass1 = 0;
_MData.posHLPass2 = 0;
if (NULL == m_highlight) {
return;
}
//GTimeVal timeStart;
//g_get_current_time(&timeStart);
_HLStart = (int32_t)getStartLine(position(_HLStart));
_MData.HLData.clear();
int64_t HLStop = countForwardNLines(position(_HLStart), _nbLines);
int64_t startId = 0;
int64_t stopId = 0;
// find element previous
findMainHighLightPosition(_HLStart, HLStop, startId, stopId, true);
//APPL_DEBUG("List of section between : "<< startId << " & " << stopId);
int64_t endSearch = stopId+1;
if (stopId == -1) {
endSearch = m_HLDataPass1.size();
}
int64_t kkk;
for (kkk = etk_max(startId, 0); kkk < endSearch; ++kkk) {
// empty section :
if (kkk == 0) {
if (_HLStart < m_HLDataPass1[kkk].beginStart) {
//APPL_DEBUG(" == > (empty section 1 ) k="<<k<<" start="<<HLStart<<" stop="<<m_HLDataPass1[k].beginStart );
m_highlight->parse2(_HLStart,
m_HLDataPass1[kkk].beginStart,
_MData.HLData,
m_data);
} // else : nothing to do ...
} else {
//APPL_DEBUG(" == > (empty section 2 ) k="<<k<<" start="<<m_HLDataPass1[k-1].endStop<<" stop="<<m_HLDataPass1[k].beginStart );
m_highlight->parse2(m_HLDataPass1[kkk-1].endStop,
m_HLDataPass1[kkk].beginStart,
_MData.HLData,
m_data);
}
// under section :
//APPL_DEBUG(" == > (under section ) k="<<k<<" start="<<m_HLDataPass1[k].beginStart<<" stop="<<m_HLDataPass1[k].endStop << " subSectionOfID=" << 99999999);
// TODO : ...
}
if (endSearch == (int32_t)m_HLDataPass1.size() ){
//if( k < (int32_t)m_HLDataPass1.size()) {
if (m_HLDataPass1.size() != 0) {
//APPL_DEBUG(" == > (empty section 3 ) k="<<k<<" start="<<m_HLDataPass1[k-1].endStop<<" stop="<<HLStop );
m_highlight->parse2(m_HLDataPass1[kkk-1].endStop,
HLStop,
_MData.HLData,
m_data);
} else {
//APPL_DEBUG(" == > (empty section 4 ) k="<<k<<" start=0 stop="<<HLStop );
m_highlight->parse2(0,
HLStop,
_MData.HLData,
m_data);
}
}
//GTimeVal timeStop;
//g_get_current_time(&timeStop);
//APPL_DEBUG("Display reAnnalyse = " << timeStop.tv_usec - timeStart.tv_usec << " micro-s");
}
appl::HighlightInfo* appl::Buffer::getElementColorAtPosition(appl::DisplayHLData& _MData, int64_t _pos) {
int64_t start = etk_max(0, _MData.posHLPass2-1);
for (int64_t iii=start; iii<(int32_t)_MData.HLData.size(); iii++) {
_MData.posHLPass2 = iii;
if( _MData.HLData[iii].beginStart <= _pos
&& _MData.HLData[iii].endStop > _pos)
{
return &_MData.HLData[iii];
}
if(_MData.HLData[iii].beginStart > _pos) {
return getElementColorAtPosition(_pos, _MData.posHLPass1);
}
}
return getElementColorAtPosition(_pos, _MData.posHLPass1);
}
uint32_t appl::Buffer::getCursorLinesId(void) {
if (m_data.size() == 0) {
return 0;
}
uint32_t line = 0;
for (Iterator it = begin();
(bool)it == true && it <= cursor();
++it) {
if (*it == etk::UChar::Return) {
++line;
}
}
return line;
}

627
sources/appl/Buffer.h Normal file
View File

@@ -0,0 +1,627 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __APPL_BUFFER_H__
#define __APPL_BUFFER_H__
#include <etk/UString.h>
#include <etk/os/FSNode.h>
#include <etk/unicode.h>
#include <ewol/ewol.h>
#include <etk/Buffer.h>
#include <ewol/renderer/EObject.h>
#include <ewol/widget/Widget.h>
#include <ewol/compositing/Text.h>
#include <appl/Highlight.h>
namespace appl {
class DisplayHLData {
public:
std::vector<appl::HighlightInfo> HLData;
int64_t posHLPass1;
int64_t posHLPass2;
};
class Buffer : public ewol::EObject {
public:
class Iterator {
// Private data :
private:
int64_t m_current; //!< curent Id in the Buffer
appl::Buffer* m_data; //!< Pointer on the curent Buffer
char32_t m_value; //!< store vlue to prevent multiple calcule of getting the data
public:
/**
* @brief Basic itarator constructor with no link.
*/
Iterator(void):
m_current(0),
m_data(NULL),
m_value(etk::UChar::Null) {
// nothing to do ...
};
/**
* @brief Recopy constructor.
* @param[in] _obj The Iterator that might be copy
*/
Iterator(const Iterator & _obj):
m_current(_obj.m_current),
m_data(_obj.m_data),
m_value(etk::UChar::Null) {
// nothing to do ...
};
/**
* @brief Asignation operator.
* @param[in] _otherIterator The Iterator that might be copy
* @return reference on the curent Iterator
*/
Iterator& operator=(const Iterator & _obj) {
m_current = _obj.m_current;
m_data = _obj.m_data;
m_value = etk::UChar::Null;
return *this;
};
/**
* @brief Basic destructor
*/
~Iterator(void) {
m_current = 0;
m_data = NULL;
m_value = etk::UChar::Null;
};
/**
* @brief basic boolean cast
* @return true if the element is present in buffer
*/
operator bool (void) const {
if (m_data == NULL) {
return false;
}
if (m_current >= m_data->m_data.size()) {
return false;
}
if (m_current < 0) {
return false;
}
return true;
};
/**
* @brief basic boolean cast
* @return true if the element is present in buffer
*/
operator int64_t (void) const {
if (m_data == NULL) {
return 0;
}
if (m_current < 0) {
return 0;
}
if (m_current > m_data->m_data.size()) {
return m_data->m_data.size();
}
return m_current;
};
/**
* @brief Incremental operator
* @return Reference on the current iterator incremented
*/
Iterator& operator++ (void);
/**
* @brief Decremental operator
* @return Reference on the current iterator decremented
*/
Iterator& operator-- (void);
/**
* @brief Incremental operator
* @return Reference on a new iterator and increment the other one
*/
Iterator operator++ (int32_t) {
Iterator it(*this);
++(*this);
return it;
};
/**
* @brief Decremental operator
* @return Reference on a new iterator and decrement the other one
*/
Iterator operator-- (int32_t) {
Iterator it(*this);
--(*this);
return it;
};
/**
* @brief egality iterator
* @return true if the iterator is identical pos
*/
bool operator== (const Iterator& _obj) const {
if ( m_current == _obj.m_current
&& m_data == _obj.m_data) {
return true;
}
return false;
};
/**
* @brief egality iterator
* @return true if the iterator is identical pos
*/
bool operator!= (const Iterator& _obj) const {
if ( m_current != _obj.m_current
|| m_data != _obj.m_data) {
return true;
}
return false;
};
/**
* @brief <= iterator
* @return true if the iterator is identical pos
*/
bool operator<= (const Iterator& _obj) const {
if (m_data != _obj.m_data) {
return false;
}
if (m_current <= _obj.m_current) {
return true;
}
return false;
};
/**
* @brief >= iterator
* @return true if the iterator is identical pos
*/
bool operator>= (const Iterator& _obj) const {
if (m_data != _obj.m_data) {
return false;
}
if (m_current >= _obj.m_current) {
return true;
}
return false;
};
/**
* @brief < iterator
* @return true if the iterator is identical pos
*/
bool operator< (const Iterator& _obj) const {
if (m_data != _obj.m_data) {
return false;
}
if (m_current < _obj.m_current) {
return true;
}
return false;
};
/**
* @brief > iterator
* @return true if the iterator is identical pos
*/
bool operator> (const Iterator& _obj) const {
if (m_data != _obj.m_data) {
return false;
}
if (m_current > _obj.m_current) {
return true;
}
return false;
};
/**
* @brief Get the value on the current element
* @return The request element value
*/
char32_t operator* (void);
/**
* @brief Get the position in the buffer
* @return The requested position.
*/
int64_t getPos(void) const {
if (m_data == NULL) {
return 0;
}
if (m_current < 0) {
return 0;
}
if (m_current >= m_data->m_data.size()) {
return m_data->m_data.size()-1;
}
return m_current;
};
/**
* @brief move the element position
* @return a new iterator.
*/
Iterator operator+ (const int64_t _val) const {
Iterator tmpp(*this);
for (int64_t iii=0; iii<_val; ++iii) {
++tmpp;
}
return tmpp;
};
Iterator operator+ (const int32_t _val) const {
Iterator tmpp(*this);
for (int64_t iii=0; iii<_val; ++iii) {
++tmpp;
}
return tmpp;
};
Iterator operator+ (const size_t _val) const {
Iterator tmpp(*this);
for (int64_t iii=0; iii<_val; ++iii) {
++tmpp;
}
return tmpp;
};
/**
* @brief move the element position
* @return a new iterator.
*/
Iterator operator- (const int64_t _val) const {
Iterator tmpp(*this);
for (int64_t iii=0; iii<_val; ++iii) {
--tmpp;
}
return tmpp;
};
Iterator operator- (const int32_t _val) const {
Iterator tmpp(*this);
for (int64_t iii=0; iii<_val; ++iii) {
--tmpp;
}
return tmpp;
};
Iterator operator- (const size_t _val) const {
Iterator tmpp(*this);
for (int64_t iii=0; iii<_val; ++iii) {
--tmpp;
}
return tmpp;
};
private:
Iterator(Buffer* _obj, int64_t _pos) :
m_current(_pos),
m_data(_obj),
m_value(etk::UChar::Null) {
// nothing to do ...
};
friend class Buffer;
};
public:
static const char* const eventIsModify;
static const char* const eventIsSave;
static const char* const eventSelectChange;
static const char* const eventChangeName;
public:
Buffer(void);
~Buffer(void);
private:
bool m_hasFileName; //!< when new file, the buffer has no name ==> but it might be reference with a single name ...
std::string m_fileName; //!< name of the file (with his path)
public:
/**
* @brief get the curent filename of the Buffer
*/
const std::string& getFileName(void) {
return m_fileName;
}
/**
* @brief Check if the buffer has a real filename.
* @return the status of the existance of a name.
*/
bool hasFileName(void) {
return m_hasFileName;
}
/**
* @brief Load A specific file in this buffer.
* @param[in] _name name of the file.
* @return true if file corectly opened.
*/
bool loadFile(const std::string& _name);
/**
* @brief Set a file name at this buffer (no saving ...)
* @param[in] _name name of the file.
*/
void setFileName(const std::string& _name);
/**
* @brief save the file in the specify path.
* @return true is saving well done
*/
bool storeFile(void);
protected:
bool m_isModify; //!< true if the file is modify
public:
/**
* @breif get the status of file modification.
* @return true if file is modify.
*/
bool isModify(void) {
return m_isModify;
}
/**
* @brief Set the file modification status.
* @param[in] _status New modification status.
*/
void setModification(bool _status);
protected:
etk::Buffer m_data; //!< copy of the file buffer
public:
etk::Buffer& getData(void) {
return m_data;
};
protected:
int64_t m_cursorPos; //!< cursor position.
public:
void moveCursor(int64_t _pos);
protected:
int64_t m_cursorSelectPos; //!< cursor position.
public:
/**
* @brief Set the selection position in the buffer.
* @param[in] _pos Position of the selection.
*/
void setSelectionPos(const Iterator& _pos);
/**
* @brief Remove Selection of the buffer.
*/
void unSelect(void);
/**
* @brief Remove the selection of the buffer. (do nothing if no secection)
*/
void removeSelection(void);
/**
* @brief Get the status of selection.
* @return true if we have a curent selection, false otherwise.
*/
bool hasTextSelected(void) {
return m_cursorSelectPos >= 0;
}
/**
* @brief Get the Start position of the selection.
* @return position of the start selection.
*/
int64_t getStartSelectionPos(void) {
return etk_min(m_cursorPos, m_cursorSelectPos);
}
/**
* @brief Get the Stop position of the selection.
* @return position of the stop selection.
*/
int64_t getStopSelectionPos(void) {
return etk_max(m_cursorPos, m_cursorSelectPos);
}
protected:
float m_cursorPreferredCol; //!< position of the cursor when up and down is done.
public:
/**
* @brief Set the favorite up and down position (distance from the left of the screen.
* @param[in] _val New distance (in pixels).
*/
void setFavoriteUpDownPos(float _val) {
m_cursorPreferredCol = _val;
}
/**
* @brief Get the favorite distance from the left screen (For up and down moving).
* @return The distance in pixels.
*/
float getFavoriteUpDownPos(void) {
return m_cursorPreferredCol;
}
protected:
bool m_selectMode; //!< when true, the select mode keep the moving selecting
public:
/**
* @brief Set the selection mode (if true, the move event creata a selection)
* @param[in] _status New status of the section.
*/
void setSelectMode(bool _status) {
m_selectMode = _status;
}
/**
* @brief Get the selection mode (if true, the move event creata a selection)
* @return The selecting mode.
*/
bool getSelectMode(void) {
return m_selectMode;
}
public:
/**
* @brief Get the position of selection around (select word).
* @param[in] _startPos Position to start the selection.
* @param[out] _beginPos Position where the element start.
* @param[out] _endPos Position where the element stop.
* @return true if we find a selection around.
*/
bool getPosAround(const Iterator& _startPos, Iterator &_beginPos, Iterator &_endPos);
/**
* @brief Expand the specify char to have a user frendly display for special char and tabs
* @param[in] _indent Curent indentation in the line
* @param[in] _value Current value to transform
* @param[out] _out String that represent the curent value to display
*/
void expand(int32_t& _indent, const char32_t& _value, std::u32string& _out) const;
/**
* @brief get the start of a line with the position in the buffer.
* @param[in] _pos position in the buffer.
* @return The position in the buffer of the start of the line.
*/
Iterator getStartLine(const Iterator& _pos);
/**
* @brief get the end of a line with the position in the buffer.
* @param[in] _pos position in the buffer.
* @return The position in the buffer of the end of the line.
*/
Iterator getEndLine(const Iterator& _pos);
/**
* @brief Search a character in the buffer.
* @param[in] _pos Position to start the search of the element.
* @param[in] _search Character to search.
* @param[out] _result Research position.
* @return true if pos if fined.
*/
// TODO : rename find
bool search(const Iterator& _pos, const char32_t& _search, Iterator& _result);
/**
* @brief Search a character in the buffer in back mode.
* @param[in] _pos Position to start the search of the element.
* @param[in] _search Character to search.
* @param[out] _result Research position.
* @return true if pos if fined.
*/
// TODO : rename rfind
bool searchBack(const Iterator& _pos, const char32_t& _search, Iterator& _result);
/**
* @brief Search a string in the buffer.
* @param[in] _pos Position to start the search of the element.
* @param[in] _search String to search.
* @param[out] _result Research position.
* @param[in] _caseSensitive (optional) Search making attention of the case [default true]
* @return true if pos if fined.
*/
// TODO : rename find
bool search(const Iterator& _pos, const std::u32string& _search, Iterator& _result, bool _caseSensitive = true);
/**
* @brief Search a string in the buffer in back mode.
* @param[in] _pos Position to start the search of the element.
* @param[in] _search String to search.
* @param[out] _result Research position.
* @param[in] _caseSensitive (optional) Search making attention of the case [default true]
* @return true if pos if fined.
*/
// TODO : rename rfind
bool searchBack(const Iterator& _pos, const std::u32string& _search, Iterator& _result, bool _caseSensitive = true);
/**
* @brief find the first character of the line "nLines" forward
* @param[in] _startPos Start position.
* @param[in] _nLines Number of line to count.
* @return position of the starting the line.
*/
Iterator countForwardNLines(const Iterator& _startPos, int32_t _nLines);
/**
* @brief find the first character of the line "nLines" backwards
* @param[in] _startPos Start position to count (this caracter is not counted)
* @param[in] _nLines Number of line to count (if == 0 means find the beginning of the line)
* @return position of the starting the line
*/
Iterator countBackwardNLines(const Iterator& _startPos, int32_t _nLines);
public:
/**
* @brief copy data in the _data ref value.
* @param[out] _data Output stream to copy.
* @return true of no error occured.
*/
bool copy(std::string& _data);
/**
* @brief copy data in the _data ref value.
* @param[out] _data Output stream to copy.
* @param[in] _pos Position to add the data.
* @param[in] _posEnd End position to end replace the data.
*/
void copy(std::string& _data, const appl::Buffer::Iterator& _pos, const appl::Buffer::Iterator& _posEnd);
/**
* @brief Write data at a specific position
* @param[in] _data Data to insert in the buffer
* @param[in] _pos Position to add the data.
* @return true if the write is done corectly
*/
bool write(const std::string& _data, const appl::Buffer::Iterator& _pos);
/**
* @brief Write data at a specific position
* @param[in] _data Data to insert in the buffer
* @param[in] _pos Position to add the data.
* @param[in] _posEnd End position to end replace the data.
* @return true if the write is done corectly
*/
bool replace(const std::string& _data, const appl::Buffer::Iterator& _pos, const appl::Buffer::Iterator& _posEnd);
public: // iterator section :
/**
* @brief Get an iterator an an specific position
* @param[in] _pos Requested position of the iterator.
* @return The Iterator
*/
Iterator position(int64_t _pos);
/**
* @brief Get an Iterator on the start position.
* @return The Iterator
*/
Iterator begin(void);
/**
* @brief Get an Iterator on the end position.
* @return The Iterator
*/
Iterator end(void);
/**
* @brief Get an Iterator on the cursor position.
* @return The Iterator
*/
Iterator cursor(void);
/**
* @brief Get an Iterator on the start selection.
* @return The Iterator
*/
Iterator selectStart(void);
/**
* @brief Get an Iterator on the stop selection.
* @return The Iterator
*/
Iterator selectStop(void);
protected:
int32_t m_nbLines; //!< number of line in the buffer
public:
/**
* @brief Get the number of line in the buffer.
* @return number of line in the Buffer.
*/
int32_t getNumberOfLines(void) {
return m_nbLines;
}
/**
* @brief Get the cursor line numberin the buffer.
* @return the line id in the Buffer.
*/
uint32_t getCursorLinesId(void);
protected:
/**
* @brief Count the number of line in the buffer
*/
void countNumberofLine(void);
protected:
std::string m_highlightType; //!< Name of the highlight type
appl::Highlight* m_highlight; //!< internal link with the Highlight system
std::vector<appl::HighlightInfo> m_HLDataPass1; //!< colorisation position in the current buffer pass 1
public:
/**
* @brief Find the Highligh capability
*/
void tryFindHighlightType(void);
/**
* @brief Set type of highlight
* @param[in] _type type of the highlight
*/
void setHighlightType(const std::string& _type);
/**
* @brief Get type of highlight
* @return Type of the highlight
*/
const std::string& setHighlightType(void) {
return m_highlightType;
};
void regenerateHighLightAt(int64_t _pos, int64_t _nbDeleted, int64_t _nbAdded);
void findMainHighLightPosition(int64_t _startPos,
int64_t _endPos,
int64_t& _startId,
int64_t& _stopId,
bool _backPreviousNotEnded);
void generateHighLightAt(int64_t _pos, int64_t _endPos, int64_t _addingPos=0);
void cleanHighLight(void);
appl::HighlightInfo* getElementColorAtPosition(int64_t _pos, int64_t &_starPos);
void hightlightGenerateLines(appl::DisplayHLData& _MData, int64_t _HLStart, int64_t _nbLines);
appl::HighlightInfo* getElementColorAtPosition(appl::DisplayHLData& _MData, int64_t _pos);
};
};
#endif

View File

@@ -1,554 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/Debug.h>
#include <appl/global.h>
#include <BufferManager.h>
#include <ewol/renderer/EObject.h>
#include <ewol/renderer/EObjectManager.h>
#undef __class__
#define __class__ "classBufferManager"
class classBufferManager: public ewol::EObject
{
public:
// Constructeur
classBufferManager(void);
~classBufferManager(void);
const char * const GetObjectType(void)
{
return "ApplBufferManager";
}
public:
virtual void OnReceiveMessage(const ewol::EMessage& _msg);
private:
// return the ID of the buffer allocated
// create a buffer with no element
int32_t Create(void);
// open curent filename
int32_t Open(etk::FSNode &myFile);
bool Remove(int32_t BufferID);
public:
int32_t GetSelected(void) { return m_idSelected;};
//void SetSelected(int32_t id) {m_idSelected = id;};
BufferText* Get(int32_t BufferID);
bool Exist(int32_t BufferID);
bool Exist(etk::FSNode &myFile);
int32_t GetId(etk::FSNode &myFile);
// return the number of buffer (open in the past) if 5 buffer open and 4 close ==> return 5
uint32_t Size(void);
uint32_t SizeOpen(void);
int32_t WitchBuffer(int32_t iEmeElement);
private:
etk::Vector<BufferText*> listBuffer; //!< element List of the char Elements
void RemoveAll(void); //!< remove all buffer
int32_t m_idSelected;
};
// Constructeur
classBufferManager::classBufferManager(void)
{
m_idSelected = -1;
RegisterMultiCast(ednMsgGuiNew);
RegisterMultiCast(ednMsgOpenFile);
RegisterMultiCast(ednMsgGuiClose);
RegisterMultiCast(ednMsgGuiSave);
RegisterMultiCast(ednMsgCodeViewSelectedId);
RegisterMultiCast(ednMsgBufferId);
}
classBufferManager::~classBufferManager(void)
{
//clean All Buffer
APPL_INFO("~classBufferManager::RemoveAll();");
RemoveAll();
// clear The list of Buffer
APPL_INFO("~classBufferManager::listBuffer.Clear();");
listBuffer.Clear();
}
void classBufferManager::OnReceiveMessage(const ewol::EMessage& _msg)
{
ewol::EObject::OnReceiveMessage(_msg);
if (_msg.GetMessage() == ednMsgBufferId) {
// select a new buffer ID :
if (_msg.GetData() == "") {
APPL_ERROR("Request select buffer ID = \"\" ");
} else {
int32_t newID = -1;
sscanf(_msg.GetData().c_str(), "%d", &newID);
if(true == Exist(newID)) {
m_idSelected = newID;
} else {
m_idSelected = -1;
APPL_ERROR("Request a non existant ID : " << newID << " reset to -1...");
}
}
} else if (_msg.GetMessage() == ednMsgGuiNew) {
int32_t newOne = Create();
if (-1 != newOne) {
m_idSelected = newOne;
SendMultiCast(ednMsgBufferId, m_idSelected);
SendMultiCast(ednMsgBufferListChange);
}
} else if (_msg.GetMessage() == ednMsgOpenFile) {
if (_msg.GetData() != "" ) {
etk::FSNode myFile(_msg.GetData());
if (myFile.GetNodeType() == etk::FSN_FILE) {
APPL_DEBUG("request open file = \"" << _msg.GetData() << "\" ?= \"" << myFile << "\"");
int32_t newOne = Open(myFile);
if (-1 != newOne) {
m_idSelected = newOne;
SendMultiCast(ednMsgBufferId, m_idSelected);
SendMultiCast(ednMsgBufferListChange);
} else {
// TODO : notify user that we can not open the request file...
APPL_ERROR("Can not open the file : \"" << myFile << "\"");
}
} else {
APPL_ERROR("Request to open an Unknox element file : " << myFile << " type:" << myFile.GetNodeType());
}
}
} else if (_msg.GetMessage() == ednMsgGuiSave) {
if (_msg.GetData() == "") {
APPL_ERROR("Null data for close file ... ");
} else {
if (_msg.GetData() == "current") {
// Check buffer existence
if(true == Exist(m_idSelected)) {
// If no name ==> request a Gui display ...
if (Get(m_idSelected)->HaveName() == false) {
SendMultiCast(ednMsgGuiSaveAs, "current");
} else {
Get(m_idSelected)->Save();
}
}
} else {
int32_t newId;
sscanf(_msg.GetData().c_str(), "%d", &newId);
if (false == Exist(newId)) {
APPL_ERROR("Request a save As with a non existant ID=" << newId);
} else {
// If no name ==> request a Gui display ...
if (Get(newId)->HaveName() == false) {
SendMultiCast(ednMsgGuiSaveAs, newId);
} else {
Get(m_idSelected)->Save();
}
}
SendMultiCast(ednMsgBufferState, "saved");
}
}
} else if (_msg.GetMessage() == ednMsgGuiClose) {
if (_msg.GetData() == "") {
APPL_ERROR("Null data for close file ... ");
} else {
if (_msg.GetData() == "All") {
} else {
int32_t closeID = -1;
if (_msg.GetData() == "current") {
closeID = m_idSelected;
APPL_DEBUG("Close specific buffer ID" << closeID);
} else {
// close specific buffer ...
sscanf(_msg.GetData().c_str(), "%d", &closeID);
APPL_DEBUG("Close specific buffer ID="<< closeID);
}
if(true == Exist(closeID)) {
// Get the new display buffer
if (m_idSelected == closeID) {
// Try previous buffer
int32_t destBuffer = -1;
for(int32_t ii=closeID-1; ii >= 0; ii--) {
if (true == Exist(ii) ) {
destBuffer = ii;
break;
}
}
// try next buffer
if (-1 == destBuffer) {
for(int32_t ii=closeID+1; ii < listBuffer.Size(); ii++) {
if (true == Exist(ii) ) {
destBuffer = ii;
break;
}
}
}
// set it to the currect display
m_idSelected = destBuffer;
SendMultiCast(ednMsgBufferId, destBuffer);
}
// Remove requested buffer
Remove(closeID);
SendMultiCast(ednMsgBufferListChange);
} else {
APPL_ERROR("Request Close of a non existant ID : " << closeID);
}
}
}
} else if (_msg.GetMessage() == ednMsgCodeViewSelectedId) {
//Change the selected buffer
if (_msg.GetData() == "") {
APPL_ERROR("Null data for changing buffer ID file ... ");
} else {
int32_t newId;
sscanf(_msg.GetData().c_str(), "%d", &newId);
if (true == Exist(newId)) {
m_idSelected = newId;
} else {
APPL_ERROR("code biew request the selection of an non -existant buffer ==> reset to -1");
m_idSelected = -1;
}
SendMultiCast(ednMsgBufferId, m_idSelected);
SendMultiCast(ednMsgBufferListChange);
}
}
/*
switch (id)
{
// Check buffer existence
if(true == Exist(dataID)) {
// If no name ==> request a Gui display ...
if (Get(dataID)->HaveName() == false) {
SendMessage(APPL_MSG__GUI_SHOW_SAVE_AS, dataID);
} else {
Get(dataID)->Save();
}
}
break;
}
*/
}
/**
* @brief Remove all buffer opened
*
* @param[in,out] ---
*
* @return ---
*
*/
void classBufferManager::RemoveAll(void)
{
int32_t i;
for (i=0; i<listBuffer.Size(); i++) {
Remove(i);
}
SendMultiCast(ednMsgGuiClose, "All");
}
/**
* @brief Create a new buffer with no name and empty
*
* @param[in,out] ---
*
* @return The ID of the curent buffer where the file is loaded
*
*/
int32_t classBufferManager::Create(void)
{
// allocate a new Buffer
BufferText *myBuffer = new BufferText();
// Add at the list of element
listBuffer.PushBack(myBuffer);
int32_t basicID = listBuffer.Size() - 1;
return basicID;
}
/**
* @brief open a file with the name set in parameters
*
* @param[in] filename curent filename
*
* @return The ID of the curent buffer where the file is loaded
*
* @todo : check if this file is not curently open and return the old ID
*
*/
int32_t classBufferManager::Open(etk::FSNode &myFile)
{
if (false == Exist(myFile)) {
// allocate a new Buffer
BufferText *myBuffer = new BufferText(myFile);
// Add at the list of element
listBuffer.PushBack(myBuffer);
return listBuffer.Size() - 1;
} else {
// the buffer already existed ==> we open it ...
return GetId(myFile);
}
}
BufferText * classBufferManager::Get(int32_t BufferID)
{
// possible special case : -1;
if (-1 >= BufferID) {
return NULL;
}
// check if the Buffer existed
if (BufferID < listBuffer.Size()) {
// check if the buffer already existed
if (NULL != listBuffer[BufferID]) {
return listBuffer[BufferID];
} else {
APPL_ERROR("non existing Buffer " << BufferID);
}
} else {
APPL_ERROR("call an non existing Buffer number too hight : " << BufferID << " > " << listBuffer.Size());
}
return NULL;
}
bool classBufferManager::Exist(int32_t BufferID)
{
if (-1 >= BufferID) {
return false;
}
// check if the Buffer existed
if (BufferID < listBuffer.Size()) {
// check if the buffer already existed
if (NULL != listBuffer[BufferID]) {
return true;
}
}
return false;
}
bool classBufferManager::Exist(etk::FSNode &myFile )
{
if (-1 == GetId(myFile)) {
return false;
}
return true;
}
int32_t classBufferManager::GetId(etk::FSNode &myFile)
{
int32_t iii;
// check if the Buffer existed
for (iii=0; iii < listBuffer.Size(); iii++) {
// check if the buffer already existed
if (NULL != listBuffer[iii]) {
if ( listBuffer[iii]->GetFileName() == myFile) {
return iii;
}
}
}
return -1;
}
// return the number of buffer (open in the past) if 5 buffer open and 4 close ==> return 5
uint32_t classBufferManager::Size(void)
{
return listBuffer.Size();
}
// nb of opens file Now ...
uint32_t classBufferManager::SizeOpen(void)
{
uint32_t jjj = 0;
// check if the Buffer existed
for (int32_t iii=0; iii<listBuffer.Size(); iii++) {
// check if the buffer already existed
if (NULL != listBuffer[iii]) {
jjj++;
}
}
return jjj;
}
/**
* @brief
*
* @param[in,out] ---
*
* @return ---
*
*/
bool classBufferManager::Remove(int32_t BufferID)
{
if (-1 >= BufferID) {
return false;
}
// check if the Buffer existed
if (BufferID < listBuffer.Size()) {
// check if the buffer already existed
if (NULL != listBuffer[BufferID]) {
// TODO : Check if it saved...
/*
if (false == IsSaved(BufferID) ) {
APPL_INFO("Buffer " << BufferID << " : Not Saved", BufferID);
}
*/
// Delete the Buffer
delete( listBuffer[BufferID] );
listBuffer[BufferID] = NULL;
/*
ewol::widgetMessageMultiCast::Send(GetWidgetId(), ednMsgBufferListChange);
*/
return true;
} else {
APPL_INFO("non existing Buffer " << BufferID);
return false;
}
} else {
APPL_INFO("call an non existing Buffer number too hight : " << BufferID << " > " << listBuffer.Size());
return false;
}
}
/**
* @brief to get the element 14 in the buffer
*
* @param[in,out] ---
*
* @return ---
*
*/
int32_t classBufferManager::WitchBuffer(int32_t iEmeElement)
{
int32_t i;
for (i=0; i<listBuffer.Size(); i++) {
if (NULL != listBuffer[i]) {
iEmeElement--;
// find the element :
if (0 == iEmeElement) {
return i;
}
}
}
return -1;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Namespace part :
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static classBufferManager * localManager = NULL;
void BufferManager::Init(void)
{
if (NULL != localManager) {
EWOL_ERROR("classBufferManager ==> already exist, just unlink the previous ...");
localManager = NULL;
}
localManager = new classBufferManager();
if (NULL == localManager) {
EWOL_CRITICAL("Allocation of classBufferManager not done ...");
}
}
void BufferManager::UnInit(void)
{
if (NULL == localManager) {
EWOL_ERROR("classBufferManager ==> request UnInit, but does not exist ...");
return;
}
delete(localManager);
localManager = NULL;
}
int32_t BufferManager::GetSelected(void)
{
if (NULL == localManager) {
EWOL_ERROR("classBufferManager ==> request UnInit, but does not exist ...");
return -1;
}
return localManager->GetSelected();
}
BufferText * BufferManager::Get(int32_t BufferID)
{
if (NULL == localManager) {
EWOL_ERROR("classBufferManager ==> request UnInit, but does not exist ...");
return NULL;
}
return localManager->Get(BufferID);
}
bool BufferManager::Exist(int32_t BufferID)
{
if (NULL == localManager) {
EWOL_ERROR("classBufferManager ==> request UnInit, but does not exist ...");
return false;
}
return localManager->Exist(BufferID);
}
bool BufferManager::Exist(etk::FSNode &myFile)
{
if (NULL == localManager) {
EWOL_ERROR("classBufferManager ==> request UnInit, but does not exist ...");
return false;
}
return localManager->Exist(myFile);
}
int32_t BufferManager::GetId(etk::FSNode &myFile)
{
if (NULL == localManager) {
EWOL_ERROR("classBufferManager ==> request UnInit, but does not exist ...");
return -1;
}
return localManager->GetId(myFile);
}
uint32_t BufferManager::Size(void)
{
if (NULL == localManager) {
EWOL_ERROR("classBufferManager ==> request UnInit, but does not exist ...");
return 0;
}
return localManager->Size();
}
uint32_t BufferManager::SizeOpen(void)
{
if (NULL == localManager) {
EWOL_ERROR("classBufferManager ==> request UnInit, but does not exist ...");
return 0;
}
return localManager->SizeOpen();
}
int32_t BufferManager::WitchBuffer(int32_t iEmeElement)
{
if (NULL == localManager) {
EWOL_ERROR("classBufferManager ==> request UnInit, but does not exist ...");
return -1;
}
return localManager->WitchBuffer(iEmeElement);
}

View File

@@ -1,32 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __BUFFER_MANAGER_H__
#define __BUFFER_MANAGER_H__
#include <BufferText.h>
#include <appl/globalMsg.h>
#include <ewol/widget/Widget.h>
namespace BufferManager
{
void Init(void);
void UnInit(void);
int32_t GetSelected(void);
BufferText* Get(int32_t BufferID);
bool Exist(int32_t BufferID);
bool Exist(etk::FSNode &myFile);
int32_t GetId(etk::FSNode &myFile);
// return the number of buffer (open in the past) if 5 buffer open and 4 close ==> return 5
uint32_t Size(void);
uint32_t SizeOpen(void);
int32_t WitchBuffer(int32_t iEmeElement);
};
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,159 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __BUFFER_TEXT_H__
#define __BUFFER_TEXT_H__
#include <etk/UString.h>
#include <etk/os/FSNode.h>
#include <etk/unicode.h>
#include <ewol/ewol.h>
#include <ewol/compositing/Drawing.h>
#include <ewol/compositing/Text.h>
#include "ColorizeManager.h"
#include "EdnBuf.h"
typedef enum {
CURSOR_DISPLAY_MODE_NORMAL = 259,
CURSOR_DISPLAY_MODE_INSERT,
CURSOR_DISPLAY_MODE_NOT_FOCUS,
} cursorDisplayMode_te;
class CharElement
{
public:
float m_LineOffset; // TODO : DEPRECATED ...
int16_t m_yOffset;
int16_t m_xOffset;
int16_t m_ySize;
int32_t m_bufferPos;
};
typedef struct{
uint32_t nbTotalLine; //!< Number of line in the buffer
uint32_t nbTotalColomn; //!< Number of line in the buffer
uint32_t startLineDisplay; //!< First line display.
uint32_t startColomnDisplay; //!< First Colomn displayed
uint32_t diplayableColomn; //!< NB colomn that can be displayed
uint32_t diplayableLine; //!< NB Line that can be displayed
}infoStatBuffer_ts;
class BufferText
{
private:
bool m_fileModify; //!<
// naming
etk::FSNode m_fileName; //!< filename of the curent buffer
bool m_haveName; //!< to know if the file have a name or NOT
bool m_updatePositionRequested; //!< if a position xhange in the windows ...
vec2 m_maximumSize; //!< current maxSize of the buffer
public:
void SetModify(bool status);
virtual vec2 GetBorderSize(void);
void RequestUpdateOfThePosition(void) { m_updatePositionRequested = true; };
void SetMaximumSize(vec2 maxSize) { m_maximumSize = maxSize; };
bool NeedToUpdateDisplayPosition(void);
vec2 GetMaxSize(void) { return m_maximumSize; };
bool IsModify(void);
public:
etk::FSNode GetFileName(void)
{
return m_fileName;
};
void SetFileName(etk::FSNode &newName)
{
m_fileName = newName;
m_haveName = true;
NameChange();
};
void SetFileName(etk::UString &newName)
{
m_fileName.SetName(newName);
m_haveName = true;
NameChange();
};
bool HaveName(void)
{
return m_haveName;
}
public:
BufferText(void);
BufferText(etk::FSNode &fileName);
virtual ~BufferText(void);
void Save(void);
void GetInfo(infoStatBuffer_ts &infoToUpdate);
void SetLineDisplay(uint32_t lineNumber);
int32_t Display(ewol::Text& OOText,
int32_t offsetX, int32_t offsetY,
int32_t sizeX, int32_t sizeY);
void AddChar(uniChar_t unicodeData);
void cursorMove(ewol::keyEvent::keyboard_te moveTypeEvent);
void MouseSelectFromCursorTo(vec2 pos);
void MouseEvent(vec2 pos);
void MouseEventDouble(void);
void MouseEventTriple(void);
void Copy(ewol::clipBoard::clipboardListe_te clipboardID);
void Cut(ewol::clipBoard::clipboardListe_te clipboardID);
void Paste(ewol::clipBoard::clipboardListe_te clipboardID);
void Search(etk::UString &data, bool back, bool caseSensitive, bool wrap, bool regExp);
void Replace(etk::UString &data);
int32_t FindLine(etk::UString &data);
void JumpAtLine(int32_t newLine);
int32_t GetCurrentLine(void);
void RemoveLine(void);
void SelectAll(void);
void SelectNone(void);
void Undo(void);
void Redo(void);
void SetCharset(unicode::charset_te newCharset);
int32_t GetNumberOfLine(void);
protected:
void NameChange(void);
private:
int32_t GetLineNumberNumberOfElement(void);
// Direct buffer IO
EdnBuf m_EdnBuf; //!< buffer associated on this displayer
vec2 m_displaySize; //!< number of char displayable in the screan
// Cursor :
int32_t m_cursorPos; //!< position in the buffer of the cursor
int32_t m_cursorPreferredCol; //!< colomn of the last up and down ...
cursorDisplayMode_te m_cursorMode; //!< type of cursor Selected
etk::Vector<CharElement> m_elmentList; //!< Elemnt position for every char displayed
// internal function
void BasicInit(void);
private:
bool m_centerRequested;
public:
virtual vec2 GetPosition(int32_t fontId, bool& centerRequested);
private:
bool TextDMoveUp(int32_t offset);
bool TextDMoveDown(int32_t offset);
void SetInsertPosition(int32_t newPosition, bool insertChar = false);
int32_t GetMousePosition(vec2 pos);
void DrawLineNumber(ewol::Text* OOText, int32_t sizeX, int32_t sizeY, int32_t nbColomn, int32_t lineNumber, int32_t positionY);
};
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,193 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __EDN_BUF_H__
#define __EDN_BUF_H__
/* Maximum length in characters of a tab or control character expansion
of a single buffer character */
#define MAX_EXP_CHAR_LEN 20*4
class EdnBuf;
#include <etk/Buffer.h>
#include <EdnBufHistory.h>
#include <HighlightManager.h>
#include <etk/unicode.h>
/*
rectStart rectStart
start ************* *************
********** * xxxx*xxxxxx *
* ******** xxxx*xxxxxxxxxxx*xxxxx
end *************** *************
rectEnd rectEnd
*/
typedef struct {
bool selected; //!< True if the selection is active
bool rectangular; //!< True if the selection is rectangular
bool zeroWidth; //!< Width 0 selections aren't "real" selections, but they can be useful when creating rectangular selections from the keyboard.
int32_t start; //!< Pos. of start of selection, or if rectangular start of line containing it.
int32_t end; //!< Pos. of end of selection, or if rectangular end of line containing it.
int32_t rectStart; //!< Indent of left edge of rect. selection
int32_t rectEnd; //!< Indent of right edge of rect. selection
} selection;
typedef struct {
etk::Vector<colorInformation_ts> HLData;
int32_t posHLPass1;
int32_t posHLPass2;
}displayHLData_ts;
class EdnBuf {
// TODO : Set an iterator to acces at every data without knowin the system ...
public:
// constructer
EdnBuf(void);
// destructer
~EdnBuf(void);
// public function :
void GetAll( etk::Vector<int8_t> &text);
void SetAll( etk::Vector<int8_t> &text);
void GetRange( int32_t start, int32_t end, etk::Vector<int8_t> &output);
void GetRange( int32_t start, int32_t end, etk::UString &output);
bool DumpIn( etk::FSNode &file);
bool DumpFrom( etk::FSNode &file);
// replace with operator [] ...
int8_t operator[] (int32_t) const;
int32_t Insert( int32_t pos, etk::Vector<int8_t> &insertText);
int32_t Insert( int32_t pos, etk::UString &insertText);
int32_t Replace( int32_t start, int32_t end, etk::Vector<int8_t> &insertText);
int32_t Replace( int32_t start, int32_t end, etk::UString &insertText);
void Remove( int32_t start, int32_t end);
int32_t Indent( void);
int32_t UnIndent( void);
void GetLineText( int32_t pos, etk::Vector<int8_t> &text);
int32_t StartOfLine( int32_t pos);
int32_t EndOfLine( int32_t pos);
int32_t GetExpandedChar( int32_t &pos, int32_t indent, uniChar_t outUnicode[MAX_EXP_CHAR_LEN], uint32_t &currentChar);
int32_t GetExpandedChar( int32_t &pos, int32_t indent, char outUTF8[MAX_EXP_CHAR_LEN], uint32_t &currentChar);
int32_t ExpandCharacter( char c, int32_t indent, char outUTF8[MAX_EXP_CHAR_LEN]); // TODO : Remove
int32_t CharWidth( char c, int32_t indent); // TODO : rework this
int32_t CountDispChars( int32_t lineStartPos, int32_t targetPos);
int32_t CountForwardDispChars( int32_t lineStartPos, int32_t nChars);
int32_t CountLines( int32_t startPos, int32_t endPos);
int32_t CountLines( void);
int32_t CountLines( etk::Vector<int8_t> &data);
int32_t CountForwardNLines( int32_t startPos, int32_t nLines);
int32_t CountBackwardNLines( int32_t startPos, int32_t nLines);
bool SearchForward( int32_t startPos, etk::UString &search, int32_t *foundPos, int32_t *foundPosEnd, bool caseSensitive = true);
bool SearchBackward( int32_t startPos, etk::UString &search, int32_t *foundPos, int32_t *foundPosEnd, bool caseSensitive = true);
bool SearchForward( int32_t startPos, char searchChar, int32_t *foundPos);
bool SearchBackward( int32_t startPos, char searchChar, int32_t *foundPos);
bool SelectAround( int32_t startPos, int32_t &beginPos, int32_t &endPos);
// Buffer Size system :
int32_t Size(void) { return m_data.Size(); };
int32_t NumberOfLines(void) { return m_nbLine; };
// -----------------------------------------
// selection remember...
// -----------------------------------------
public:
bool SelectHasSelection(void);
void Select( int32_t start, int32_t end);
void Unselect( void);
void RectSelect( int32_t start, int32_t end, int32_t rectStart, int32_t rectEnd);
bool GetSelectionPos( int32_t &start, int32_t &end, bool &isRect, int32_t &rectStart, int32_t &rectEnd);
void GetSelectionText( etk::Vector<int8_t> &text);
void GetSelectionText( etk::UString &text);
void RemoveSelected( void);
int32_t ReplaceSelected( etk::Vector<int8_t> &text);
int32_t ReplaceSelected( etk::UString &text);
private:
// current selection of the buffer
selection m_selectionList; //!< Selection area of the buffer
void UpdateSelection( int32_t pos, int32_t nDeleted, int32_t nInserted);
// -----------------------------------------
// History section :
// -----------------------------------------
public:
int32_t Undo(void);
int32_t Redo(void);
private:
bool m_isUndoProcessing;
bool m_isRedoProcessing;
etk::Vector<EdnBufHistory*> m_historyUndo;
etk::Vector<EdnBufHistory*> m_historyRedo;
// -----------------------------------------
// hightlight section :
// -----------------------------------------
private:
Highlight * m_Highlight; //!< internal link with the Highlight system
etk::Vector<colorInformation_ts> m_HLDataPass1; //!< colorisation position in the current buffer pass 1
void RegenerateHighLightAt(int32_t pos, int32_t nbDeleted, int32_t nbAdded);
void GenerateHighLightAt(int32_t pos, int32_t endPos, int32_t addinPos=0);
void CleanHighLight(void);
void FindMainHighLightPosition(int32_t startPos, int32_t endPos, int32_t &startId, int32_t &stopId, bool backPreviousNotEnded);
public:
void SetHLSystem( Highlight * newHLSystem);
void HightlightGenerateLines(displayHLData_ts & MData, int32_t startPos, int32_t nbLines);
colorInformation_ts * GetElementColorAtPosition(displayHLData_ts & MData, int32_t pos);
private:
colorInformation_ts * GetElementColorAtPosition(int32_t pos, int32_t &starPos);
private:
etk::Buffer m_data; //!< buffer of the data in the mode int8_t
void CountNumberOfLines(void);
int32_t m_nbLine; //!< Number of line in the biffer
// -----------------------------------------
// Display property and charset ...
// -----------------------------------------
public:
int32_t GetTabDistance(void) { return m_tabDist; } ;
void SetTabDistance(int32_t tabDist) { m_tabDist = tabDist; };
unicode::charset_te GetCharsetType(void) { return m_charsetType; };
void SetCharsetType(unicode::charset_te newOne) { m_charsetType = newOne; if (unicode::EDN_CHARSET_UTF8==newOne){m_isUtf8=true;} else {m_isUtf8=false;} };
bool GetUTF8Mode(void) { return m_isUtf8; };
void SetUTF8Mode(bool newOne) { m_isUtf8 = newOne; m_charsetType=unicode::EDN_CHARSET_UTF8; };
private:
// Special mode of the buffer :
bool m_isUtf8; //!< true if we are in UTF8 mode ==> if true the size of a char is 0, otherwise .. 1->4 ( TODO : not now)
unicode::charset_te m_charsetType; //!< if UTF8 mode is at false : the charset type of the buffer
// Local Tabulation policies
int32_t m_tabDist; //!< equiv. number of characters in a tab
bool m_useTabs; //!< True if buffer routines are allowed to use tabs for padding in rectangular operations
// -----------------------------------------
// Local function :
// -----------------------------------------
private:
void findRectSelBoundariesForCopy( int32_t lineStartPos, int32_t rectStart, int32_t rectEnd, int32_t *selStart, int32_t *selEnd);
char * getSelectionText( selection &sel);
void removeSelected( selection &sel);
void replaceSelected( selection &sel, const char *text);
void eventModification( int32_t pos, int32_t nInserted, etk::Vector<int8_t> &deletedText);
int32_t LocalInsert( int32_t pos, etk::Vector<int8_t> &insertText);
int32_t LocalInsert( int32_t pos, etk::UString &insertText);
bool charMatch( char first, char second, bool caseSensitive = true);
};
#endif

View File

@@ -1,64 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/Debug.h>
#include <appl/global.h>
#include <EdnBufHistory.h>
#undef __class__
#define __class__ "EdnBufHistory"
EdnBufHistory::EdnBufHistory(void)
{
//APPL_INFO("EdnBufHistory new");
m_pos = 0;
m_nInserted = 0;
}
EdnBufHistory::EdnBufHistory(int32_t pos, int32_t nInserted, etk::Vector<int8_t> &deletedText)
{
//APPL_INFO("EdnBufHistory new + data");
m_pos = pos;
m_nInserted = nInserted;
m_deletedText = deletedText;
}
void EdnBufHistory::Set(int32_t pos, int32_t nInserted, etk::Vector<int8_t> &deletedText)
{
//APPL_INFO("EdnBufHistory new + data");
m_pos = pos;
m_nInserted = nInserted;
m_deletedText = deletedText;
}
EdnBufHistory::~EdnBufHistory(void)
{
// nothing to do ...
}
int32_t EdnBufHistory::getPos(void)
{
return m_pos;
}
int32_t EdnBufHistory::getnbDeleted(void)
{
return m_deletedText.Size();
}
int32_t EdnBufHistory::getnbInserted(void)
{
return m_nInserted;
}
void EdnBufHistory::getData(etk::Vector<int8_t> &deletedText)
{
deletedText = m_deletedText;
}

View File

@@ -1,32 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __EDN_BUFFER_HISTORY_H__
#define __EDN_BUFFER_HISTORY_H__
#include <etk/Vector.h>
class EdnBufHistory{
public:
EdnBufHistory(void);
EdnBufHistory(int32_t pos, int32_t nInserted, etk::Vector<int8_t> &deletedText);
~EdnBufHistory(void);
void Set(int32_t pos, int32_t nInserted, etk::Vector<int8_t> &deletedText);
int32_t getPos(void);
int32_t getnbDeleted(void);
int32_t getnbInserted(void);
void getData(etk::Vector<int8_t> &deletedText);
private:
int32_t m_pos;
int32_t m_nInserted;
etk::Vector<int8_t> m_deletedText;
};
#endif

View File

@@ -1,353 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/Debug.h>
#include <appl/global.h>
#include <EdnBuf.h>
#undef __class__
#define __class__ "EdnBuf{HighLight}"
void EdnBuf::SetHLSystem(Highlight * newHLSystem)
{
if (m_Highlight != newHLSystem) {
m_Highlight = newHLSystem;
m_HLDataPass1.Clear();
RegenerateHighLightAt(0, 0, m_data.Size());
}
}
// TODO : Check this fuction it have too many conditionnal inside ==> can do a better algo
void EdnBuf::RegenerateHighLightAt(int32_t pos, int32_t nbDeleted, int32_t nbAdded)
{
//GTimeVal timeStart;
//g_get_current_time(&timeStart);
// prevent ERROR...
if (NULL == m_Highlight) {
return;
}
// prevent No data Call
if( 0 == nbDeleted
&& 0 == nbAdded)
{
return;
}
// normal case
//APPL_INFO("(pos="<<pos<<", nbDeleted="<<nbDeleted<<", nbAdded=" << nbAdded << "\");");
int32_t i;
/*
for (i=0; i< (int32_t)m_HLDataPass1.Size(); i++) {
etk::UString ploppp;
if (NULL != m_HLDataPass1[i].patern ) {
ploppp = ((HighlightPattern*)m_HLDataPass1[i].patern)->GetName();
}
APPL_DEBUG("HighLight (previous) element id=" << i << " S=" << m_HLDataPass1[i].beginStart << " E=" << m_HLDataPass1[i].endStop << " patern name=" << ploppp );
}
*/
int32_t posEnd = pos + nbDeleted;
// search position of the old element to reparse IT...
int32_t startId;
int32_t stopId;
// clean data if needed
if (0 != m_HLDataPass1.Size()) {
// find element previous
FindMainHighLightPosition(pos, posEnd, startId, stopId, true);
// Remove deprecated element
if( -1 == startId
&& -1 == stopId)
{
m_HLDataPass1.Clear();
} else if(-1 == startId) {
if (0 == stopId){
m_HLDataPass1.Erase(0);
//APPL_DEBUG("1 * Erase 0");
} else {
m_HLDataPass1.EraseLen(0,stopId);
//APPL_DEBUG("2 * Erase 0->" << stopId);
}
} else if(-1 == stopId) {
//APPL_DEBUG("3 * Erase " << startId+1 << "-> end");
m_HLDataPass1.EraseLen(startId+1, m_HLDataPass1.Size() - startId);
stopId = -1;
} else {
int32_t currentSize = m_HLDataPass1.Size();
//APPL_DEBUG("4 * Erase " << startId+1 << "->" << stopId << " in " << currentSize << " elements" );
m_HLDataPass1.EraseLen(startId+1, stopId - startId);
if (stopId == currentSize-1) {
stopId = -1;
}
}
//APPL_DEBUG("new size=" << (int32_t)m_HLDataPass1.Size()-1);
/*
for (i=0; i< (int32_t)m_HLDataPass1.Size(); i++) {
etk::UString ploppp;
if (NULL != m_HLDataPass1[i].patern ) {
ploppp = ((HighlightPattern*)m_HLDataPass1[i].patern)->GetName();
}
APPL_DEBUG("HighLight (Middle) element id=" << i << " S=" << m_HLDataPass1[i].beginStart << " E=" << m_HLDataPass1[i].endStop << " patern name=" << ploppp );
}
*/
// update position after the range position :
int32_t elemStart;
if(-1 == startId) {
elemStart = 0;
} else {
elemStart = startId+1;
}
for (i=elemStart; i< (int32_t)m_HLDataPass1.Size(); i++) {
//APPL_DEBUG("move element=" << i);
m_HLDataPass1[i].beginStart += nbAdded - nbDeleted;
m_HLDataPass1[i].beginStop += nbAdded - nbDeleted;
m_HLDataPass1[i].endStart += nbAdded - nbDeleted;
m_HLDataPass1[i].endStop += nbAdded - nbDeleted;
}
//Regenerate Element inside range
if( -1 == startId
&& -1 == stopId)
{
//APPL_DEBUG("******* Regenerate ALL");
GenerateHighLightAt(0, m_data.Size());
} else if(-1 == startId) {
//APPL_DEBUG("******* Regenerate START");
GenerateHighLightAt(0, m_HLDataPass1[0].beginStart, 0);
} else if(-1 == stopId) {
//APPL_DEBUG("******* Regenerate STOP");
GenerateHighLightAt(m_HLDataPass1[m_HLDataPass1.Size() -1].endStop, m_data.Size(), m_HLDataPass1.Size());
} else {
//APPL_DEBUG("******* Regenerate RANGE");
GenerateHighLightAt(m_HLDataPass1[startId].endStop, m_HLDataPass1[startId+1].beginStart, startId+1);
}
} else {
// Parse the new element ...
GenerateHighLightAt(0, m_data.Size());
}
/*
for (i=0; i< (int32_t)m_HLDataPass1.Size(); i++) {
etk::UString ploppp;
if (NULL != m_HLDataPass1[i].patern ) {
ploppp = ((HighlightPattern*)m_HLDataPass1[i].patern)->GetName();
}
APPL_DEBUG("HighLight (end) element id=" << i << " S=" << m_HLDataPass1[i].beginStart << " E=" << m_HLDataPass1[i].endStop << " patern name=" << ploppp );
}
*/
//GTimeVal timeStop;
//g_get_current_time(&timeStop);
//APPL_DEBUG("HL General = " << timeStop.tv_usec - timeStart.tv_usec << " micro-s");
}
void EdnBuf::FindMainHighLightPosition(int32_t startPos, int32_t endPos, int32_t &startId, int32_t &stopId, bool backPreviousNotEnded)
{
startId = -1;
stopId = -1;
/* rules to start stop:
HighLight data ----
Remove area ****
Start pos S
End pos E
Some Case :
----------- ------------ ------------- ----------
S **** E
----------- ------------ ------------- ----------
S ********** E
----------- ------------ ------------- ----------
S **** E
----------- ------------ ------------- ----------
S ********* E
----------- ------------ ------------- ----------
S ********************* E
----------- ------------ ------------- ----------
S ************************ E
----------- ------------ ------------- ----------
S ***************** E
----------- ------------ ------------- ----------
S *************** E
----------- ------------
S *************** E=-1
------------ ------------- ----------
S=-1 *************** E
*/
int32_t i;
for (i=0; i< (int32_t)m_HLDataPass1.Size(); i++) {
if (m_HLDataPass1[i].endStop > startPos) {
break;
}
startId = i;
}
// go back while the previous element is not eneded
if (true == backPreviousNotEnded) {
for (i=startId; i>=0; i--) {
if (m_HLDataPass1[i].notEnded == false) {
break;
}
startId = i-1;
}
}
int32_t elemStart;
if(-1 == startId) {
elemStart = 0;
} else {
elemStart = startId+1;
}
for (i=elemStart; i< (int32_t)m_HLDataPass1.Size(); i++) {
if (m_HLDataPass1[i].beginStart > endPos)
{
stopId = i;
break;
}
}
/*
if (-1 != startId && startId < (int32_t)m_HLDataPass1.Size()) {
APPL_DEBUG("==> BEGIN : start="<<m_HLDataPass1[startId].beginStart<<", stop="<<m_HLDataPass1[startId].endStop<<" id=" << startId << "/" << (int32_t)m_HLDataPass1.Size()-1);
} else {
APPL_DEBUG("==> BEGIN : start=???, stop=??? id=" << startId);
}
if (-1 != stopId && stopId < (int32_t)m_HLDataPass1.Size()) {
APPL_DEBUG("==> END : start="<<m_HLDataPass1[stopId].beginStart<<", stop="<<m_HLDataPass1[stopId].endStop<<" id=" << stopId<< "/" << (int32_t)m_HLDataPass1.Size()-1);
} else {
APPL_DEBUG("==> END : start=???, stop=??? id=" << stopId);
}
*/
}
void EdnBuf::GenerateHighLightAt(int32_t pos, int32_t endPos, int32_t addinPos)
{
if (NULL == m_Highlight) {
return;
}
//APPL_DEBUG("area : ("<<pos<<","<<endPos<<") insert at : " << addinPos);
m_Highlight->Parse(pos, endPos, m_HLDataPass1, addinPos, m_data);
}
void EdnBuf::CleanHighLight(void)
{
// Remove all element in the list...
m_HLDataPass1.Clear();
}
colorInformation_ts *EdnBuf::GetElementColorAtPosition(int32_t pos, int32_t &starPos)
{
int32_t i;
int32_t start = etk_max(0, starPos-1);
for (i=start; i<(int32_t)m_HLDataPass1.Size(); i++) {
starPos = i;
if( m_HLDataPass1[i].beginStart <= pos
&& m_HLDataPass1[i].endStop > pos)
{
return &m_HLDataPass1[i];
}
if(m_HLDataPass1[i].beginStart > pos) {
return NULL;
}
}
return NULL;
}
void EdnBuf::HightlightGenerateLines(displayHLData_ts & MData, int32_t HLStart, int32_t nbLines)
{
MData.posHLPass1 = 0;
MData.posHLPass2 = 0;
if (NULL == m_Highlight) {
return;
}
//GTimeVal timeStart;
//g_get_current_time(&timeStart);
HLStart = StartOfLine(HLStart);
MData.HLData.Clear();
int32_t HLStop = CountForwardNLines(HLStart, nbLines);
int32_t startId, stopId;
// find element previous
FindMainHighLightPosition(HLStart, HLStop, startId, stopId, true);
int32_t k;
//APPL_DEBUG("List of section between : "<< startId << " & " << stopId);
int32_t endSearch = stopId+1;
if (-1 == stopId) {
endSearch = m_HLDataPass1.Size();
}
for (k=etk_max(startId, 0); k<endSearch; k++) {
// empty section :
if (0==k) {
if (HLStart < m_HLDataPass1[k].beginStart) {
//APPL_DEBUG(" ==> (empty section 1 ) k="<<k<<" start="<<HLStart<<" stop="<<m_HLDataPass1[k].beginStart );
m_Highlight->Parse2(HLStart,
m_HLDataPass1[k].beginStart,
MData.HLData,
m_data);
} // else : nothing to do ...
} else {
//APPL_DEBUG(" ==> (empty section 2 ) k="<<k<<" start="<<m_HLDataPass1[k-1].endStop<<" stop="<<m_HLDataPass1[k].beginStart );
m_Highlight->Parse2(m_HLDataPass1[k-1].endStop,
m_HLDataPass1[k].beginStart,
MData.HLData,
m_data);
}
// under section :
//APPL_DEBUG(" ==> (under section ) k="<<k<<" start="<<m_HLDataPass1[k].beginStart<<" stop="<<m_HLDataPass1[k].endStop << " subSectionOfID=" << 99999999);
// TODO : ...
}
if (endSearch == (int32_t)m_HLDataPass1.Size() ){
//if( k < (int32_t)m_HLDataPass1.Size()) {
if (m_HLDataPass1.Size() != 0) {
//APPL_DEBUG(" ==> (empty section 3 ) k="<<k<<" start="<<m_HLDataPass1[k-1].endStop<<" stop="<<HLStop );
m_Highlight->Parse2(m_HLDataPass1[k-1].endStop,
HLStop,
MData.HLData,
m_data);
} else {
//APPL_DEBUG(" ==> (empty section 4 ) k="<<k<<" start=0 stop="<<HLStop );
m_Highlight->Parse2(0,
HLStop,
MData.HLData,
m_data);
}
}
//GTimeVal timeStop;
//g_get_current_time(&timeStop);
//APPL_DEBUG("Display reAnnalyse = " << timeStop.tv_usec - timeStart.tv_usec << " micro-s");
}
colorInformation_ts * EdnBuf::GetElementColorAtPosition(displayHLData_ts & MData, int32_t pos)
{
int32_t i;
int32_t start = etk_max(0, MData.posHLPass2-1);
for (i=start; i<(int32_t)MData.HLData.Size(); i++) {
MData.posHLPass2 = i;
if( MData.HLData[i].beginStart <= pos
&& MData.HLData[i].endStop > pos)
{
return &MData.HLData[i];
}
if(MData.HLData[i].beginStart > pos) {
return GetElementColorAtPosition(pos, MData.posHLPass1);
}
}
return GetElementColorAtPosition(pos, MData.posHLPass1);
}

View File

@@ -1,116 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/Debug.h>
#include <appl/global.h>
#include <EdnBuf.h>
#undef __class__
#define __class__ "EdnBuf{History}"
int32_t EdnBuf::Undo(void)
{
int32_t nbElement = m_historyUndo.Size();
//APPL_DEBUG("EdnBuf::Undo Request id="<<nbElement);
int32_t posDest = -1;
if (0 == nbElement) {
// nothing to do ...
APPL_ERROR("EdnBuf::Undo No more History");
return -1;
}
nbElement--;
if (m_historyUndo[nbElement] == NULL) {
APPL_ERROR("EdnBuf::Undo Find empty history ==> remove it");
m_historyUndo.PopBack();
return -1;
}
int32_t pos = m_historyUndo[nbElement]->getPos();
int32_t nbDeleted = m_historyUndo[nbElement]->getnbDeleted();
int32_t nbInserted = m_historyUndo[nbElement]->getnbInserted();
etk::Vector<int8_t> deletedText;
m_historyUndo[nbElement]->getData(deletedText);
m_isUndoProcessing = true;
if (0 == nbInserted) {
// just add data at position ...
if (0 == nbDeleted) {
APPL_DEBUG("EdnBuf::Undo nothing to do in UNDO");
} else {
Insert(pos, deletedText);
posDest = pos + nbDeleted;
}
} else {
if (0 == nbDeleted) {
// only remove data
Remove(pos, pos+nbInserted);
posDest = pos;
} else {
// replace data
Replace(pos, pos+nbInserted, deletedText);
posDest = pos + nbDeleted;
}
}
// remove element in the list :
delete(m_historyUndo[nbElement]);
m_historyUndo.PopBack();
m_isUndoProcessing = false;
return posDest;
}
int32_t EdnBuf::Redo(void)
{
int32_t nbElement = m_historyRedo.Size();
//APPL_DEBUG("EdnBuf::Redo Request id="<<nbElement);
int32_t posDest = -1;
if (0 == nbElement) {
// nothing to do ...
APPL_DEBUG("EdnBuf::Redo No more History");
return -1;
}
nbElement--;
if (m_historyRedo[nbElement] == NULL) {
APPL_ERROR("EdnBuf::Redo Find empty history ==> remove it");
m_historyRedo.PopBack();
return -1;
}
int32_t pos = m_historyRedo[nbElement]->getPos();
int32_t nbDeleted = m_historyRedo[nbElement]->getnbDeleted();
int32_t nbInserted = m_historyRedo[nbElement]->getnbInserted();
etk::Vector<int8_t> deletedText;
m_historyRedo[nbElement]->getData(deletedText);
m_isRedoProcessing = true;
if (0 == nbInserted) {
// just add data at position ...
if (0 == nbDeleted) {
APPL_ERROR("EdnBuf::Redo nothing to do in REDO");
} else {
Insert(pos, deletedText);
posDest = pos + nbDeleted;
}
} else {
if (0 == nbDeleted) {
// only remove data
Remove(pos, pos+nbInserted);
posDest = pos;
} else {
// replace data
Replace(pos, pos+nbInserted, deletedText);
posDest = pos + nbDeleted;
}
}
// remove element in the list :
delete(m_historyRedo[nbElement]);
m_historyRedo.PopBack();
m_isRedoProcessing = false;
return posDest;
}

View File

@@ -1,293 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/Debug.h>
#include <appl/global.h>
#include <EdnBuf.h>
#undef __class__
#define __class__ "EdnBuf{Selection}"
/**
* @brief
*
* @param[in,out] ---
* @param[in,out] ---
*
* @return ---
*
*/
bool EdnBuf::SelectHasSelection(void)
{
return m_selectionList.selected;
}
/**
* @brief
*
* @param[in,out] ---
* @param[in,out] ---
*
* @return ---
*
*/
void EdnBuf::Select(int32_t start, int32_t end)
{
//selection oldSelection = m_selectionList[select];
m_selectionList.selected = start != end;
m_selectionList.zeroWidth = (start == end) ? true : false;
m_selectionList.rectangular = false;
m_selectionList.start = etk_min(start, end);
m_selectionList.end = etk_max(start, end);
}
/**
* @brief
*
* @param[in,out] ---
*
* @return ---
*
*/
void EdnBuf::Unselect(void)
{
//selection oldSelection = m_selectionList[select];
m_selectionList.selected = false;
m_selectionList.zeroWidth = false;
}
/**
* @brief
*
* @param[in,out] ---
* @param[in,out] ---
* @param[in,out] ---
* @param[in,out] ---
*
* @return ---
*
*/
void EdnBuf::RectSelect(int32_t start, int32_t end, int32_t rectStart, int32_t rectEnd)
{
m_selectionList.selected = rectStart < rectEnd;
m_selectionList.zeroWidth = (rectStart == rectEnd) ? false : true;
m_selectionList.rectangular = true;
m_selectionList.start = start;
m_selectionList.end = end;
m_selectionList.rectStart = rectStart;
m_selectionList.rectEnd = rectEnd;
}
/**
* @brief
*
* @param[in,out] ---
*
* @return ---
*
*/
bool EdnBuf::GetSelectionPos(int32_t &start, int32_t &end, bool &isRect, int32_t &rectStart, int32_t &rectEnd)
{
/* Always fill in the parameters (zero-width can be requested too). */
isRect = m_selectionList.rectangular;
start = m_selectionList.start;
end = m_selectionList.end;
if (m_selectionList.rectangular) {
rectStart = m_selectionList.rectStart;
rectEnd = m_selectionList.rectEnd;
}
return m_selectionList.selected;
}
/**
* @brief
*
* @param[in,out] ---
*
* @return ---
*
*/
void EdnBuf::GetSelectionText(etk::Vector<int8_t> &text)
{
int32_t start, end, rectStart, rectEnd;
bool isRect;
// remove output data
text.Clear();
bool isSelected = GetSelectionPos(start, end, isRect, rectStart, rectEnd);
// No data selected ...
if (false == isSelected) {
return;
}
// Rectangular selection
if (true == isRect) {
//GetTextInRect(start, end, rectStart, rectEnd, text);
// TODO : ...
} else {
GetRange(start, end, text);
}
}
void EdnBuf::GetSelectionText(etk::UString &text)
{
int32_t start, end, rectStart, rectEnd;
bool isRect;
// remove output data
text = "";
bool isSelected = GetSelectionPos(start, end, isRect, rectStart, rectEnd);
// No data selected ...
if (false == isSelected) {
return;
}
// Rectangular selection
if (true == isRect) {
//GetTextInRect(start, end, rectStart, rectEnd, text);
// TODO : ...
} else {
GetRange(start, end, text);
}
}
/**
* @brief
*
* @param[in,out] ---
*
* @return ---
*
*/
void EdnBuf::RemoveSelected(void)
{
int32_t start, end;
int32_t rectStart, rectEnd;
bool isRect;
bool isSelected = GetSelectionPos(start, end, isRect, rectStart, rectEnd);
// No data selected ...
if (false == isSelected) {
return;
}
// Rectangular selection
if (true == isRect) {
//RemoveRect(start, end, rectStart, rectEnd);
// TODO : ...
} else {
Remove(start, end);
}
Unselect();
}
/**
* @brief
*
* @param[in,out] ---
*
* @return ---
*
*/
int32_t EdnBuf::ReplaceSelected(etk::Vector<int8_t> &text)
{
int32_t start, end, rectStart, rectEnd;
bool isRect;
bool isSelected = GetSelectionPos(start, end, isRect, rectStart, rectEnd);
// No data selected ...
if (false == isSelected) {
return 0;
}
int32_t returnSize = 0;
// Rectangular selection
if (true == isRect) {
//ReplaceRect(start, end, rectStart, rectEnd, text);
// TODO : ...
} else {
returnSize = Replace(start, end, text);
}
// Clean selection
m_selectionList.selected = false;
return returnSize;
}
int32_t EdnBuf::ReplaceSelected(etk::UString &text)
{
int32_t start, end, rectStart, rectEnd;
bool isRect;
bool isSelected = GetSelectionPos(start, end, isRect, rectStart, rectEnd);
// No data selected ...
if (false == isSelected) {
return 0;
}
int32_t returnSize = 0;
// Rectangular selection
if (true == isRect) {
//ReplaceRect(start, end, rectStart, rectEnd, text);
// TODO : ...
} else {
returnSize = Replace(start, end, text);
}
// Clean selection
m_selectionList.selected = false;
return returnSize;
}
/*
** Update an individual selection for changes in the corresponding text
*/
/**
* @brief
*
* @param[in,out] ---
*
* @return ---
*
*/
void EdnBuf::UpdateSelection(int32_t pos, int32_t nDeleted, int32_t nInserted)
{
if( ( false == m_selectionList.selected
&& false == m_selectionList.zeroWidth)
|| pos > m_selectionList.end )
{
return;
}
if (pos+nDeleted <= m_selectionList.start) {
m_selectionList.start += nInserted - nDeleted;
m_selectionList.end += nInserted - nDeleted;
} else if( pos <= m_selectionList.start
&& pos+nDeleted >= m_selectionList.end)
{
m_selectionList.start = pos;
m_selectionList.end = pos;
m_selectionList.selected = false;
m_selectionList.zeroWidth = false;
} else if( pos <= m_selectionList.start
&& pos+nDeleted < m_selectionList.end)
{
m_selectionList.start = pos;
m_selectionList.end = nInserted + m_selectionList.end - nDeleted;
} else if(pos < m_selectionList.end) {
m_selectionList.end += nInserted - nDeleted;
if (m_selectionList.end <= m_selectionList.start) {
m_selectionList.selected = false;
}
}
}

View File

@@ -0,0 +1,145 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/debug.h>
#include <appl/global.h>
#include <appl/BufferManager.h>
#include <ewol/renderer/EObject.h>
#include <ewol/renderer/EObjectManager.h>
#undef __class__
#define __class__ "BufferManager"
appl::BufferManager::BufferManager(void) :
ewol::Resource("???BufferManager???"),
m_bufferSelected(NULL) {
addObjectType("appl::BufferManager");
}
appl::BufferManager::~BufferManager(void) {
int32_t previousCount = m_list.size();
for (int32_t iii = m_list.size()-1; iii >= 0 ; --iii) {
if (m_list[iii] == NULL) {
continue;
}
delete(m_list[iii]);
if (previousCount == m_list.size()) {
APPL_ERROR("Error in removing buffer !! ");
}
previousCount = m_list.size();
}
m_list.clear();
}
appl::Buffer* appl::BufferManager::createNewBuffer(void) {
appl::Buffer* tmp = new appl::Buffer();
if (tmp == NULL) {
APPL_ERROR("Can not allocate the Buffer (empty).");
return NULL;
}
m_list.push_back(tmp);
sendMultiCast(appl::MsgSelectNewFile, tmp->getFileName());
return tmp;
}
appl::Buffer* appl::BufferManager::get(const std::string& _fileName, bool _createIfNeeded) {
for (int32_t iii = 0; iii < m_list.size(); ++iii) {
if (m_list[iii] == NULL) {
continue;
}
if (m_list[iii]->getFileName() == _fileName) {
return m_list[iii];
}
}
if (_createIfNeeded == true) {
if (etk::FSNodeGetType(_fileName) == etk::FSN_FOLDER) {
APPL_INFO("try open a folder : " << _fileName);
return NULL;
}
appl::Buffer* tmp = new appl::Buffer();
if (tmp == NULL) {
APPL_ERROR("Can not allocate the Buffer class : " << _fileName);
return NULL;
}
tmp->loadFile(_fileName);
m_list.push_back(tmp);
return tmp;
}
return NULL;
}
void appl::BufferManager::setBufferSelected(appl::Buffer* _bufferSelected) {
m_bufferSelected = _bufferSelected;
sendMultiCast(appl::MsgSelectChange, "");
}
void appl::BufferManager::onObjectRemove(ewol::EObject * _removeObject) {
if (m_bufferSelected == _removeObject) {
setBufferSelected(NULL);
}
for (int32_t iii = 0; iii < m_list.size(); ++iii) {
if (m_list[iii] != _removeObject) {
continue;
}
m_list[iii] = NULL;
m_list.erase(m_list.begin()+iii);
return;
}
}
bool appl::BufferManager::exist(const std::string& _fileName) {
for (int32_t iii = 0; iii < m_list.size(); ++iii) {
if (m_list[iii] == NULL) {
continue;
}
if (m_list[iii]->getFileName() == _fileName) {
return true;
}
}
return false;
}
void appl::BufferManager::open(const std::string& _fileName) {
if (exist(_fileName) == true) {
return;
}
if (get(_fileName, true) == NULL) {
return;
}
sendMultiCast(appl::MsgSelectNewFile, _fileName);
}
void appl::BufferManager::onReceiveMessage(const ewol::EMessage& _msg) {
APPL_DEBUG("receive message !!! " << _msg);
}
appl::BufferManager* appl::BufferManager::keep(void) {
//EWOL_INFO("KEEP : appl::GlyphPainting : file : \"" << _filename << "\"");
appl::BufferManager* object = static_cast<appl::BufferManager*>(getManager().localKeep("???BufferManager???"));
if (NULL != object) {
return object;
}
// this element create a new one every time ....
EWOL_INFO("CREATE : appl::BufferManager: ???BufferManager???");
object = new appl::BufferManager();
if (NULL == object) {
EWOL_ERROR("allocation error of a resource : ???BufferManager???");
return NULL;
}
getManager().localAdd(object);
return object;
}
void appl::BufferManager::release(appl::BufferManager*& _object) {
if (NULL == _object) {
return;
}
ewol::Resource* object2 = static_cast<ewol::Resource*>(_object);
getManager().release(object2);
_object = NULL;
}

View File

@@ -0,0 +1,98 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __BUFFER_MANAGER_H__
#define __BUFFER_MANAGER_H__
#include <appl/Buffer.h>
#include <appl/globalMsg.h>
#include <ewol/widget/Widget.h>
#include <ewol/resources/Resource.h>
namespace appl {
class BufferManager : public ewol::Resource {
protected:
BufferManager(void);
~BufferManager(void);
private:
std::vector<appl::Buffer*> m_list; // list of all buffer curently open
public:
/**
* @brief Get a specific buffer with his name (can create a new buffer).
* @param[in] _fileName Name of the file to open.
* @param[in] _createIfNeeded Create the buffer if not existed.
* @return a pointer on the buffer
*/
appl::Buffer* get(const std::string& _fileName, bool _createIfNeeded=false);
/**
* @brief Load a specific file, event if it not existed:
* @param[in] _fileName Name of the file to open or create.
*/
void open(const std::string& _fileName);
/**
* @brief Check if a buffer is already open.
* @param[in] _fileName name of the file.
* @return true if the buffer is already open.
*/
bool exist(const std::string& _fileName);
/**
* @brief Get count of all buffer availlable.
* @return Number of buffer
*/
int32_t size(void) const {
return m_list.size();
}
/**
* @brief Get a pointer on a buffer Id (never remember this ID!!!).
* @param[in] _id Number of buffer
* @return pointer on the buffer
*/
appl::Buffer* get(int32_t _id) {
return m_list[_id];
}
/**
* @brief Create a new buffer empty.
* @return Created buffer or NULL.
*/
appl::Buffer* createNewBuffer(void);
private:
appl::Buffer* m_bufferSelected;
public:
/**
* @brief Set the current buffer selected
* @param[in] _bufferSelected Pointer on the buffer selected
*/
void setBufferSelected(appl::Buffer* _bufferSelected);
/**
* @brief Get the current buffer selected
* @return Pointer on the buffer selected
*/
appl::Buffer* getBufferSelected(void) {
return m_bufferSelected;
};
public: // herited function
void onReceiveMessage(const ewol::EMessage& _msg);
void onObjectRemove(ewol::EObject * _removeObject);
public: // resource manager
/**
* @brief keep the resource pointer.
* @note Never free this pointer by your own...
* @param[in] _filename Name of the configuration file.
* @return pointer on the resource or NULL if an error occured.
*/
static appl::BufferManager* keep(void);
/**
* @brief release the keeped resources
* @param[in,out] reference on the object pointer
*/
static void release(appl::BufferManager*& _object);
};
};
#endif

View File

@@ -1,53 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __COLORIZE_H__
#define __COLORIZE_H__
#include <etk/Color.h>
#include <etk/UString.h>
class Colorize {
public:
// Constructeur
Colorize(const etk::UString& _newColorName="no_name");
~Colorize(void) { };
private:
etk::UString m_colorName; //!< curent color Name
public:
void SetName(const etk::UString& _newColorName) { m_colorName = _newColorName; };
const etk::UString& GetName(void) { return m_colorName; };
private:
etk::Color<> m_colorFG;
public:
void SetFgColor(const etk::UString& _myColor) { m_colorFG=_myColor; };
const etk::Color<>& GetFG(void) { return m_colorFG; };
bool HaveFg(void) { return m_colorFG.a()!=0; };
private:
etk::Color<> m_colorBG;
public:
void SetBgColor(const etk::UString& _myColor) { m_colorBG=_myColor; };
const etk::Color<>& GetBG(void) { return m_colorBG; };
bool HaveBg(void) { return m_colorBG.a()!=0; };
private:
bool m_italic;
public:
void SetItalic(bool _enable);
bool GetItalic(void) { return m_italic; };
private:
bool m_bold;
public:
void SetBold(bool _enable);
bool GetBold(void) { return m_bold; };
void Display(int32_t _i) { APPL_INFO(" " << _i << " : fg="<< m_colorFG << " bold=" << m_italic << " bold=" << m_italic << "\"" << m_colorName << "\""); };
};
#endif

View File

@@ -1,321 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/Debug.h>
#include <appl/global.h>
#include <ColorizeManager.h>
#include <exml/exml.h>
#include <ewol/renderer/EObject.h>
#include <ewol/renderer/EObjectManager.h>
#include <etk/os/FSNode.h>
#define PFX "ColorizeManager "
class classColorManager: public ewol::EObject
{
private:
etk::UString m_fileColor;
etk::Vector<Colorize*> listMyColor; //!< List of ALL Color
Colorize * errorColor;
etk::Color<> basicColors[COLOR_NUMBER_MAX];
public:
// Constructeur
classColorManager(void)
{
//ewol::widgetMessageMultiCast::Add(GetWidgetId(), ednMsgGuiChangeColor);
}
~classColorManager(void)
{
delete(errorColor);
int32_t i;
// clean all Element
for (i=0; i< listMyColor.Size(); i++) {
if (NULL != listMyColor[i]) {
delete(listMyColor[i]);
listMyColor[i] = NULL;
}
}
// clear the compleate list
listMyColor.Clear();
}
const char * const GetObjectType(void)
{
return "Appl::ColorManager";
}
void OnReceiveMessage(const ewol::EMessage& _msg)
{
/*
switch (id)
{
case APPL_MSG__RELOAD_COLOR_FILE:
{
// Reaload File
// TODO : Check this : Pb in the recopy etk::UString element
etk::UString plop = m_fileColor;
LoadFile(plop);
}
break;
}
*/
}
public:
void LoadFile(const etk::UString& _xmlFilename);
Colorize* Get(const etk::UString& _colorName)
{
int32_t i;
for (i=0; i<listMyColor.Size(); i++) {
if (listMyColor[i]->GetName() == _colorName) {
return listMyColor[i];
}
}
APPL_ERROR(PFX"Color does not Existed ["<< _colorName<<"]" );
// an error
return errorColor;
}
etk::Color<>& Get(basicColor_te _myColor)
{
if (_myColor < COLOR_NUMBER_MAX) {
return basicColors[_myColor];
} else {
return basicColors[0];
}
}
bool Exist(const etk::UString& _colorName)
{
int32_t i;
for (i=0; i<listMyColor.Size(); i++) {
if (listMyColor[i]->GetName() == _colorName) {
return true;
}
}
return false;
}
void DisplayListOfColor(void)
{
int32_t i;
APPL_INFO(PFX"List of ALL COLOR : ");
for (i=0; i<listMyColor.Size(); i++) {
//etk::UString elementName = listMyColor[i]->GetName();
//APPL_INFO(i << " : \"" << elementName.c_str() << "\"" );
listMyColor[i]->Display(i);
}
}
};
void classColorManager::LoadFile(const etk::UString& _xmlFilename)
{
// Remove all old color :
for (int32_t iii=0; iii< listMyColor.Size(); iii++) {
if (NULL != listMyColor[iii]) {
delete(listMyColor[iii]);
listMyColor[iii] = NULL;
}
}
// clear the compleate list
listMyColor.Clear();
m_fileColor = _xmlFilename;
APPL_DEBUG("open file (COLOR) \"" << _xmlFilename << "\" ? = \"" << m_fileColor << "\"");
errorColor = new Colorize();
errorColor->SetBgColor("#00FF00FF");
errorColor->SetFgColor("#FF00FFFF");
// open the curent File
etk::UString fileName(etk::UString("DATA:color/") + _xmlFilename + etk::UString(".xml"));
exml::Document doc;
if (doc.Load(fileName)==false) {
APPL_ERROR(" can not load file XML : " << fileName);
return;
}
exml::Element* root = (exml::Element*)doc.GetNamed("EdnColor");
if (NULL == root ) {
APPL_ERROR("[" << GetId() << "] {" << GetObjectType() << "} (l ?) main node not find: \"EdnColor\" ...");
return;
}
// parse all the elements :
for(int32_t iii=0; iii< root->Size(); iii++) {
exml::Element* pNode = root->GetElement(iii);
if (pNode==NULL) {
// trash here all that is not element.
continue;
}
if (pNode->GetValue()=="gui") {
for(int32_t iii=0; iii< pNode->Size(); iii++) {
exml::Element* pGuiNode = pNode->GetElement(iii);
if (pGuiNode==NULL) {
// trash here all that is not element.
continue;
}
if (pGuiNode->GetValue()!="color") {
APPL_ERROR("(l "<<pGuiNode->GetPos()<<") node not suported : \""<<pGuiNode->GetValue()<<"\" must be [color]");
continue;
}
//--------------------------------------------------------------------------------------------
//<color name="basicBackground" val="#000000"/>
//--------------------------------------------------------------------------------------------
etk::UString colorName = pGuiNode->GetAttribute("name");
if (colorName.Size()==0) {
APPL_ERROR("(l "<< pGuiNode->GetPos() <<") node with no name");
continue;
}
int32_t id = 0;
if (colorName=="CODE_space") {
id = COLOR_CODE_SPACE;
} else if (colorName=="CODE_tabulation") {
id = COLOR_CODE_TAB;
} else if (colorName=="CODE_basicBackgroung") {
id = COLOR_CODE_BASIC_BG;
} else if (colorName=="CODE_cursor") {
id = COLOR_CODE_CURSOR;
} else if (colorName=="CODE_lineNumber") {
id = COLOR_CODE_LINE_NUMBER;
} else if (colorName=="LIST_backgroung1") {
id = COLOR_LIST_BG_1;
} else if (colorName=="LIST_backgroung2") {
id = COLOR_LIST_BG_2;
} else if (colorName=="LIST_backgroungSelected") {
id = COLOR_LIST_BG_SELECTED;
} else if (colorName=="LIST_textNormal") {
id = COLOR_LIST_TEXT_NORMAL;
} else if (colorName=="LIST_textModify") {
id = COLOR_LIST_TEXT_MODIFY;
} else {
APPL_ERROR("(l "<<pGuiNode->GetPos()<<") Unknown basic gui color : \"" << colorName << "\"" );
continue;
}
etk::UString color = pGuiNode->GetAttribute("val");
if (color.Size()!=0) {
basicColors[id] = color;
}
}
} else if (pNode->GetValue()=="syntax") {
for(int32_t iii=0; iii< pNode->Size(); iii++) {
exml::Element* pGuiNode = pNode->GetElement(iii);
if (pGuiNode==NULL) {
continue;
}
if (pGuiNode->GetValue()!="color") {
APPL_ERROR(PFX"(l "<<pGuiNode->GetPos()<<") node not suported : \""<<pGuiNode->GetValue()<<"\" must be [color]");
continue;
}
//--------------------------------------------------------------------------------------------
//<color name="basicBackground" FG="#000000" BG="#000000" bold="no" italic="no"/>
//--------------------------------------------------------------------------------------------
// get the name of the Chaine
etk::UString colorName = pGuiNode->GetAttribute("name");
if (colorName.Size()==0) {
APPL_ERROR(PFX"(l "<< pGuiNode->GetPos() <<") node with no name");
continue;
}
Colorize* myNewColor = new Colorize();
if (NULL==myNewColor) {
APPL_ERROR(PFX"(l "<< pGuiNode->GetPos() <<") ==> allocation error");
continue;
}
myNewColor->SetName(colorName);
etk::UString colorBG = pGuiNode->GetAttribute("BG");
if (colorBG.Size()!=0) {
myNewColor->SetBgColor(colorBG);
}
etk::UString colorFG = pGuiNode->GetAttribute("FG");
if (colorFG.Size()!=0) {
myNewColor->SetFgColor(colorFG);
}
etk::UString bold = pGuiNode->GetAttribute("bold");
if (bold.Size()!=0) {
myNewColor->SetBold(bold.ToBool());
}
etk::UString italic = pGuiNode->GetAttribute("italic");
if (italic.Size()!=0) {
myNewColor->SetItalic(italic.ToBool());
}
listMyColor.PushBack(myNewColor);
}
}
}
//SendMessage(APPL_MSG__COLOR_HAS_CHANGE);
//SendMessage(APPL_MSG__USER_DISPLAY_CHANGE);
}
static classColorManager * localManager = NULL;
void ColorizeManager::Init(void)
{
if (NULL != localManager) {
EWOL_ERROR("ColorizeManager ==> already exist, just unlink the previous ...");
localManager = NULL;
}
localManager = new classColorManager();
if (NULL == localManager) {
EWOL_CRITICAL("Allocation of HighlightManager not done ...");
}
}
void ColorizeManager::UnInit(void)
{
if (NULL == localManager) {
EWOL_ERROR("ColorizeManager ==> request UnInit, but does not exist ...");
return;
}
delete(localManager);
localManager = NULL;
}
void ColorizeManager::LoadFile(const etk::UString& _xmlFilename)
{
if (NULL == localManager) {
return;
}
localManager->LoadFile(_xmlFilename);
}
Colorize* ColorizeManager::Get(const etk::UString& _colorName)
{
if (NULL == localManager) {
return NULL;
}
return localManager->Get(_colorName);
}
etk::Color<>& ColorizeManager::Get(basicColor_te _myColor)
{
static etk::Color<> errorColor;
if (NULL == localManager) {
return errorColor;
}
return localManager->Get(_myColor);
}
bool ColorizeManager::Exist(const etk::UString& _colorName)
{
if (NULL == localManager) {
return false;
}
return localManager->Exist(_colorName);
}
void ColorizeManager::DisplayListOfColor(void)
{
if (NULL == localManager) {
return;
}
localManager->DisplayListOfColor();
}

View File

@@ -1,48 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __COLORIZE_MANAGER_H__
#define __COLORIZE_MANAGER_H__
#include <Colorize.h>
#include <appl/globalMsg.h>
#include <etk/Color.h>
#include <ewol/widget/Widget.h>
typedef enum {
// BASIC color for codeViewer
COLOR_CODE_SPACE,
COLOR_CODE_TAB,
COLOR_CODE_BASIC_BG,
COLOR_CODE_CURSOR,
COLOR_CODE_LINE_NUMBER,
// Basic color for list viewer
COLOR_LIST_BG_1,
COLOR_LIST_BG_2,
COLOR_LIST_BG_SELECTED,
COLOR_LIST_TEXT_NORMAL,
COLOR_LIST_TEXT_MODIFY,
// KNOW the number of BASIC color
COLOR_NUMBER_MAX,
}basicColor_te;
namespace ColorizeManager
{
void Init(void);
void UnInit(void);
void LoadFile(const etk::UString& _xmlFilename);
Colorize * Get(const etk::UString& _colorName);
etk::Color<>& Get(basicColor_te _myColor);
bool Exist(const etk::UString& _colorName);
void DisplayListOfColor(void);
};
#endif

View File

@@ -6,26 +6,25 @@
* @license GPL v3 (see license file)
*/
#include <appl/Debug.h>
#include <appl/debug.h>
#include <appl/global.h>
#include <Colorize.h>
#include <appl/GlyphDecoration.h>
#undef __class__
#define __class__ "Colorize"
#define __class__ "GlyphDecoration"
Colorize::Colorize(const etk::UString &_newColorName) :
appl::GlyphDecoration::GlyphDecoration(const std::string &_newColorName) :
m_colorName(_newColorName),
m_colorFG(etk::color::black),
m_colorBG(etk::color::none),
m_italic(false),
m_bold(false)
{
APPL_VERBOSE("New(Colorise)");
APPL_VERBOSE("New(" << __class__ << ")");
}
void Colorize::SetItalic(bool _enable)
void appl::GlyphDecoration::setItalic(bool _enable)
{
m_italic = _enable;
if (true == _enable) {
@@ -35,7 +34,7 @@ void Colorize::SetItalic(bool _enable)
}
}
void Colorize::SetBold(bool _enable)
void appl::GlyphDecoration::setBold(bool _enable)
{
m_bold = _enable;
if (true == _enable) {
@@ -45,5 +44,12 @@ void Colorize::SetBold(bool _enable)
}
}
etk::CCout& appl::operator <<(etk::CCout& _os, const appl::GlyphDecoration& _obj)
{
_os << "{fg=" << _obj.getForeground();
_os << ",bg=" << _obj.getBackground();
_os << ",italic=" << _obj.getItalic();
_os << ",bold=" << _obj.getBold();
_os << "name='" << _obj.getName() << "'}";
return _os;
}

View File

@@ -0,0 +1,124 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __GLYPH_DECORATION_H__
#define __GLYPH_DECORATION_H__
#include <etk/Color.h>
#include <etk/UString.h>
namespace appl {
class GlyphDecoration {
public:
// Constructeur
GlyphDecoration(const std::string& _newColorName = "no_name");
~GlyphDecoration(void) {
// nothing to do ...
};
private:
std::string m_colorName; //!< curent color Name
public:
/**
* @brief Set color name of the element.
* @param[in] _newColorName new color name.
*/
void setName(const std::string& _newColorName) {
m_colorName = _newColorName;
};
/**
* @brief Get the color name.
* @return The name of the color.
*/
const std::string& getName(void) const {
return m_colorName;
};
private:
etk::Color<> m_colorFG; //!< Foreground color
public:
/**
* @brief Set foreground color.
* @param[in] _myColor new color description.
*/
void setForeground(const std::string& _myColor) {
m_colorFG = _myColor;
};
/**
* @brief Get the foreground color.
* @return The color.
*/
const etk::Color<>& getForeground(void) const {
return m_colorFG;
};
/**
* @brief Get the foreground color status.
* @return true if the color is visible.
*/
bool haveFg(void) const {
return m_colorFG.a() != 0;
};
private:
etk::Color<> m_colorBG; //!< Background color
public:
/**
* @brief Set background color.
* @param[in] _myColor new color description.
*/
void setBackground(const std::string& _myColor) {
m_colorBG = _myColor;
};
/**
* @brief Get the background color.
* @return The color.
*/
const etk::Color<>& getBackground(void) const {
return m_colorBG;
};
/**
* @brief Get the background color status.
* @return true if the color is visible.
*/
bool haveBackground(void) const {
return m_colorBG.a()!=0;
};
private:
bool m_italic; //!< the gryph might be italic.
public:
/**
* @brief Set the italic status.
* @param[in] _enable new status of italic request.
*/
void setItalic(bool _enable);
/**
* @brief Get the italic status.
* @return true if the glyph might be display in italic.
*/
bool getItalic(void) const {
return m_italic;
};
private:
bool m_bold; //!< the gryph might be bold.
public:
/**
* @brief Set the bold status.
* @param[in] _enable new status of bold request.
*/
void setBold(bool _enable);
/**
* @brief Get the bold status.
* @return true if the glyph might be display in bold.
*/
bool getBold(void) const {
return m_bold;
};
};
etk::CCout& operator <<(etk::CCout& _os, const appl::GlyphDecoration& _obj);
}
#endif

View File

@@ -0,0 +1,123 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/debug.h>
#include <appl/global.h>
#include <appl/GlyphPainting.h>
#include <ejson/ejson.h>
#include <etk/os/FSNode.h>
#include <ewol/resources/ResourceManager.h>
#undef __class__
#define __class__ "GlyphPainting"
appl::GlyphPainting::GlyphPainting(const std::string& _filename) :
ewol::Resource(_filename) {
addObjectType("appl::GlyphPainting");
EWOL_DEBUG("SFP : load \"" << _filename << "\"");
reload();
}
appl::GlyphPainting::~GlyphPainting(void) {
}
void appl::GlyphPainting::reload(void) {
ejson::Document doc;
if (false == doc.load(m_name)) {
APPL_ERROR("Can not load file : '" << m_name << "' = " << etk::FSNode(m_name).getFileSystemName());
return;
}
// for debug only :
/*
APPL_WARNING("Load file : '" << m_name << "' = " << etk::FSNode(m_name).getFileSystemName());
std::string tmppppp;
doc.generate(tmppppp);
APPL_DEBUG(tmppppp);
*/
ejson::Array* baseArray = doc.getArray("ednColor");
if (baseArray == NULL) {
APPL_ERROR("Can not get basic array : 'ednColor'");
return;
}
for (int32_t iii = 0; iii < baseArray->size(); ++iii) {
ejson::Object* tmpObj = baseArray->getObject(iii);
if (tmpObj == NULL) {
APPL_DEBUG(" can not get object in 'ednColor' id=" << iii);
continue;
}
std::string name = tmpObj->getStringValue("name", "");
std::string background = tmpObj->getStringValue("background", "#FFF0");
std::string foreground = tmpObj->getStringValue("foreground", "#000F");
bool italic = tmpObj->getBooleanValue("italic", false);
bool bold = tmpObj->getBooleanValue("bold", false);
APPL_VERBOSE("find new color : '" << name << "' fg='" << foreground << "' bg='" << background << "' italic='" << italic << "' bold='" << bold << "'");
bool findElement = false;
for (int32_t jjj=0; jjj<m_list.size(); ++jjj) {
if (m_list[jjj].getName() != name) {
continue;
}
m_list[jjj].setForeground(foreground);
m_list[jjj].setBackground(background);
m_list[jjj].setItalic(italic);
m_list[jjj].setBold(bold);
findElement = true;
}
if (findElement == true) {
continue;
}
appl::GlyphDecoration tmpDeco(name);
tmpDeco.setForeground(foreground);
tmpDeco.setBackground(background);
tmpDeco.setItalic(italic);
tmpDeco.setBold(bold);
m_list.push_back(tmpDeco);
}
}
int32_t appl::GlyphPainting::request(const std::string& _name) {
for (int32_t iii=0; iii<m_list.size(); ++iii) {
if (m_list[iii].getName() == _name) {
return iii;
}
}
// create an empty deco ...
appl::GlyphDecoration tmpDeco(_name);
m_list.push_back(tmpDeco);
return m_list.size()-1;
}
appl::GlyphPainting* appl::GlyphPainting::keep(const std::string& _filename) {
//EWOL_INFO("KEEP : appl::GlyphPainting : file : \"" << _filename << "\"");
appl::GlyphPainting* object = static_cast<appl::GlyphPainting*>(getManager().localKeep(_filename));
if (NULL != object) {
return object;
}
// this element create a new one every time ....
EWOL_INFO("CREATE : appl::GlyphPainting : file : \"" << _filename << "\"");
object = new appl::GlyphPainting(_filename);
if (NULL == object) {
EWOL_ERROR("allocation error of a resource : ??GlyphPainting??");
return NULL;
}
getManager().localAdd(object);
return object;
}
void appl::GlyphPainting::release(appl::GlyphPainting*& _object) {
if (NULL == _object) {
return;
}
ewol::Resource* object2 = static_cast<ewol::Resource*>(_object);
getManager().release(object2);
_object = NULL;
}

View File

@@ -0,0 +1,68 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __APPL_GLYPH_PAINTING_H__
#define __APPL_GLYPH_PAINTING_H__
#include <etk/types.h>
#include <ewol/debug.h>
#include <ewol/resources/Resource.h>
#include <appl/GlyphDecoration.h>
namespace appl {
class GlyphPainting : public ewol::Resource {
private:
std::vector<appl::GlyphDecoration> m_list;
protected:
GlyphPainting(const std::string& _filename);
virtual ~GlyphPainting(void);
public:
/**
* @brief Load or reload data from config
*/
void reload(void);
/**
* @brief Register a decoration with his name and get the ref id.
* @param[in] _name Name of the deco.
* @return id of the deco.
*/
int32_t request(const std::string& _name);
/**
* @brief Get Decoration handle.
* @param[in] _id Id of the decoration.
* @return reference on deco.
*/
const appl::GlyphDecoration& get(int32_t _id) const {
return m_list[_id];
};
/**
* @brief Operator to get decoration handle.
* @param[in] _pos Id of the decoration.
* @return reference on deco.
*/
const appl::GlyphDecoration& operator[] (int32_t _pos) const {
return m_list[_pos];
}
public:
/**
* @brief keep the resource pointer.
* @note Never free this pointer by your own...
* @param[in] _filename Name of the configuration file.
* @return pointer on the resource or NULL if an error occured.
*/
static appl::GlyphPainting* keep(const std::string& _filename);
/**
* @brief release the keeped resources
* @param[in,out] reference on the object pointer
*/
static void release(appl::GlyphPainting*& _object);
};
};
#endif

View File

@@ -6,186 +6,296 @@
* @license GPL v3 (see license file)
*/
#include <appl/Debug.h>
#include <appl/debug.h>
#include <appl/global.h>
#include <BufferView.h>
#include <BufferManager.h>
#include <ColorizeManager.h>
#include <MainWindows.h>
#include <appl/Gui/BufferView.h>
#include <appl/BufferManager.h>
//#include <ColorizeManager.h>
#include <appl/Gui/MainWindows.h>
#include <ewol/renderer/EObject.h>
#undef __class__
#define __class__ "BufferView"
#define __class__ "BufferView"
static void SortElementList(etk::Vector<appl::dataBufferStruct *> &list)
{
etk::Vector<appl::dataBufferStruct *> tmpList = list;
list.Clear();
for(int32_t iii=0; iii<tmpList.Size(); iii++) {
if (NULL != tmpList[iii]) {
int32_t findPos = 0;
for(int32_t jjj=0; jjj<list.Size(); jjj++) {
//EWOL_DEBUG("compare : \""<<*tmpList[iii] << "\" and \"" << *m_listDirectory[jjj] << "\"");
if (list[jjj]!=NULL) {
if (tmpList[iii]->m_bufferName.GetNameFile() > list[jjj]->m_bufferName.GetNameFile()) {
findPos = jjj+1;
}
}
}
//EWOL_DEBUG("position="<<findPos);
list.Insert(findPos, tmpList[iii]);
static void SortElementList(std::vector<appl::dataBufferStruct*>& _list) {
std::vector<appl::dataBufferStruct *> tmpList = _list;
_list.clear();
for(int32_t iii=0; iii<tmpList.size(); iii++) {
if (NULL == tmpList[iii]) {
continue;
}
int32_t findPos = 0;
for(int32_t jjj=0; jjj<_list.size(); jjj++) {
//EWOL_DEBUG("compare : \""<<*tmpList[iii] << "\" and \"" << *m_listDirectory[jjj] << "\"");
if (_list[jjj] == NULL) {
continue;
}
if (tmpList[iii]->m_bufferName.getNameFile() > _list[jjj]->m_bufferName.getNameFile()) {
findPos = jjj+1;
}
}
//EWOL_DEBUG("position="<<findPos);
_list.insert(_list.begin()+findPos, tmpList[iii]);
}
}
BufferView::BufferView(void)
{
SetCanHaveFocus(true);
RegisterMultiCast(ednMsgBufferListChange);
RegisterMultiCast(ednMsgBufferState);
RegisterMultiCast(ednMsgBufferId);
BufferView::BufferView(void) :
m_openOrderMode(false) {
addObjectType("appl::BufferView");
setCanHaveFocus(true);
registerMultiCast(ednMsgBufferListChange);
registerMultiCast(ednMsgBufferState);
registerMultiCast(ednMsgBufferId);
registerMultiCast(appl::MsgSelectNewFile);
registerMultiCast(appl::MsgSelectChange);
registerMultiCast(appl::MsgNameChange);
m_selectedID = -1;
m_selectedIdRequested = -1;
// load buffer manager:
m_bufferManager = appl::BufferManager::keep();
// load color properties
m_paintingProperties = appl::GlyphPainting::keep("THEME:COLOR:bufferList.json");
// get all id properties ...
m_colorBackground1 = m_paintingProperties->request("backgroung1");
m_colorBackground2 = m_paintingProperties->request("backgroung2");
m_colorBackgroundSelect = m_paintingProperties->request("backgroungSelected");
m_colorTextNormal = m_paintingProperties->request("textNormal");
m_colorTextModify = m_paintingProperties->request("textModify");
}
BufferView::~BufferView(void)
{
RemoveAllElement();
BufferView::~BufferView(void) {
removeAllElement();
}
void BufferView::RemoveAllElement(void)
{
for(int32_t iii=0; iii<m_list.Size(); iii++) {
void BufferView::removeAllElement(void) {
for(int32_t iii=0; iii<m_list.size(); iii++) {
if (NULL!=m_list[iii]) {
delete(m_list[iii]);
m_list[iii] = NULL;
}
}
m_list.Clear();
m_list.clear();
if (m_bufferManager != NULL) {
appl::BufferManager::release(m_bufferManager);
}
}
void BufferView::OnReceiveMessage(const ewol::EMessage& _msg)
{
widget::List::OnReceiveMessage(_msg);
if (_msg.GetMessage() == ednMsgBufferListChange) {
void BufferView::insertAlphabetic(appl::dataBufferStruct* _dataStruct, bool _selectNewPosition) {
if (_dataStruct == NULL) {
return;
}
// alphabetical order:
for (size_t iii = 0; iii < m_list.size(); ++iii) {
if (m_list[iii] == NULL) {
continue;
}
if (to_lower(m_list[iii]->m_bufferName.getNameFile()) > to_lower(_dataStruct->m_bufferName.getNameFile())) {
m_list.insert(m_list.begin() + iii, _dataStruct);
_dataStruct = NULL;
if (_selectNewPosition == true) {
m_selectedID = iii;
}
break;
}
}
if (_dataStruct != NULL) {
m_list.push_back(_dataStruct);
if (_selectNewPosition == true) {
m_selectedID = m_list.size()-1;
}
}
}
void BufferView::onReceiveMessage(const ewol::EMessage& _msg) {
widget::List::onReceiveMessage(_msg);
if (_msg.getMessage() == appl::MsgSelectNewFile) {
appl::Buffer* buffer = m_bufferManager->get(_msg.getData());
if (buffer == NULL) {
APPL_ERROR("event on element nor exist : " << _msg.getData());
return;
}
buffer->registerOnEvent(this, appl::Buffer::eventIsSave);
buffer->registerOnEvent(this, appl::Buffer::eventIsModify);
buffer->registerOnEvent(this, appl::Buffer::eventChangeName);
appl::dataBufferStruct* tmp = new appl::dataBufferStruct(_msg.getData(), buffer);
if (tmp == NULL) {
APPL_ERROR("Allocation error of the tmp buffer list element");
return;
}
if (m_openOrderMode == true) {
m_list.push_back(tmp);
} else {
insertAlphabetic(tmp);
}
markToRedraw();
return;
}
if (_msg.getMessage() == appl::Buffer::eventChangeName) {
for (size_t iii = 0; iii < m_list.size(); ++iii) {
if (m_list[iii] == NULL) {
continue;
}
if (m_list[iii]->m_bufferName != m_list[iii]->m_buffer->getFileName()) {
m_list[iii]->m_bufferName = m_list[iii]->m_buffer->getFileName();
if (m_openOrderMode == false) {
// re-order the fine in the correct position
appl::dataBufferStruct* tmp = m_list[iii];
m_list[iii] = NULL;
m_list.erase(m_list.begin() + iii);
insertAlphabetic(tmp, (iii == m_selectedID));
break;
}
}
}
markToRedraw();
return;
}
if (_msg.getMessage() == appl::Buffer::eventIsSave) {
markToRedraw();
return;
}
if (_msg.getMessage() == appl::Buffer::eventIsModify) {
markToRedraw();
return;
}
APPL_DEBUG("message : " << _msg);
if (_msg.getMessage() == appl::MsgSelectChange) {
m_selectedID = -1;
appl::Buffer* tmpBuffer = NULL;
if (m_bufferManager != NULL) {
tmpBuffer = m_bufferManager->getBufferSelected();
}
if (tmpBuffer != NULL) {
for (int32_t iii=0; iii<m_list.size(); iii++) {
if (m_list[iii] == NULL) {
continue;
}
if (m_list[iii]->m_buffer != tmpBuffer) {
continue;
}
m_selectedID = iii;
break;
}
}
markToRedraw();
return;
}
if (_msg.getMessage() == ednMsgBufferListChange) {
// clean The list
RemoveAllElement();
// Get all the buffer name and properties:
int32_t nbBufferOpen = BufferManager::Size();
removeAllElement();
// get all the buffer name and properties:
int32_t nbBufferOpen = 0; // BufferManager::size();
for (int32_t iii=0; iii<nbBufferOpen; iii++) {
if (BufferManager::Exist(iii)) {
BufferText* tmpBuffer = BufferManager::Get(iii);
/*
if (BufferManager::exist(iii)) {
BufferText* tmpBuffer = BufferManager::get(iii);
if (NULL != tmpBuffer) {
bool isModify = tmpBuffer->IsModify();
etk::FSNode name = tmpBuffer->GetFileName();
bool isModify = tmpBuffer->isModify();
etk::FSNode name = tmpBuffer->getFileName();
appl::dataBufferStruct* tmpElement = new appl::dataBufferStruct(name, iii, isModify);
if (NULL != tmpElement) {
m_list.PushBack(tmpElement);
m_list.push_back(tmpElement);
} else {
APPL_ERROR("Allocation error of the tmp buffer list element");
}
}
}
*/
}
if (true == globals::OrderTheBufferList() ) {
SortElementList(m_list);
}
MarkToRedraw();
}else if (_msg.GetMessage() == ednMsgBufferId) {
m_selectedIdRequested = BufferManager::GetSelected();
MarkToRedraw();
}else if (_msg.GetMessage() == ednMsgBufferState) {
// Update list of modify section ...
for (int32_t iii=0; iii<m_list.Size(); iii++) {
markToRedraw();
}else if (_msg.getMessage() == ednMsgBufferId) {
m_selectedIdRequested = 0; //BufferManager::getSelected();
markToRedraw();
}else if (_msg.getMessage() == ednMsgBufferState) {
// update list of modify section ...
for (int32_t iii=0; iii<m_list.size(); iii++) {
if (NULL!=m_list[iii]) {
m_list[iii]->m_isModify = BufferManager::Get(m_list[iii]->m_bufferID)->IsModify();
//m_list[iii]->m_isModify = BufferManager::get(m_list[iii]->m_bufferID)->isModify();
}
}
MarkToRedraw();
markToRedraw();
}
}
void BufferView::onObjectRemove(ewol::EObject* _removeObject) {
widget::List::onObjectRemove(_removeObject);
for (int32_t iii=0; iii<m_list.size(); iii++) {
if (m_list[iii] == NULL) {
continue;
}
if (m_list[iii]->m_buffer != _removeObject) {
continue;
}
m_list.erase(m_list.begin()+iii);
markToRedraw();
return;
}
}
etk::Color<> BufferView::GetBasicBG(void)
{
return ColorizeManager::Get(COLOR_LIST_BG_1);
etk::Color<> BufferView::getBasicBG(void) {
return (*m_paintingProperties)[m_colorBackground1].getForeground();
}
uint32_t BufferView::GetNuberOfColomn(void)
{
uint32_t BufferView::getNuberOfColomn(void) {
return 1;
}
bool BufferView::GetTitle(int32_t colomn, etk::UString &myTitle, etk::Color<> &fg, etk::Color<> &bg)
{
myTitle = "Buffers : ";
bool BufferView::getTitle(int32_t _colomn, std::string &_myTitle, etk::Color<> &_fg, etk::Color<> &_bg) {
_myTitle = "Buffers : ";
return true;
}
uint32_t BufferView::GetNuberOfRaw(void)
{
return m_list.Size();
uint32_t BufferView::getNuberOfRaw(void) {
return m_list.size();
}
bool BufferView::GetElement(int32_t colomn, int32_t raw, etk::UString &myTextToWrite, etk::Color<> &fg, etk::Color<> &bg)
{
bool isModify;
basicColor_te selectFG = COLOR_LIST_TEXT_NORMAL;
basicColor_te selectBG = COLOR_LIST_BG_1;
// when requested a new display selection ==> reset the previous one ...
if (m_selectedIdRequested != -1) {
m_selectedID = -1;
}
if( raw>=0
&& raw<m_list.Size()
&& NULL != m_list[raw]) {
myTextToWrite = m_list[raw]->m_bufferName.GetNameFile();
bool BufferView::getElement(int32_t _colomn, int32_t _raw, std::string& _myTextToWrite, etk::Color<>& _fg, etk::Color<>& _bg) {
if( _raw >= 0
&& _raw<m_list.size()
&& NULL != m_list[_raw]) {
_myTextToWrite = m_list[_raw]->m_bufferName.getNameFile();
if (true == m_list[raw]->m_isModify) {
selectFG = COLOR_LIST_TEXT_MODIFY;
if ( m_list[_raw]->m_buffer != NULL
&& m_list[_raw]->m_buffer->isModify() == false) {
_fg = (*m_paintingProperties)[m_colorTextNormal].getForeground();
} else {
selectFG = COLOR_LIST_TEXT_NORMAL;
_fg = (*m_paintingProperties)[m_colorTextModify].getForeground();
}
if (raw%2==0) {
selectBG = COLOR_LIST_BG_1;
if (_raw%2 == 0) {
_bg = (*m_paintingProperties)[m_colorBackground1].getForeground();
} else {
selectBG = COLOR_LIST_BG_2;
_bg = (*m_paintingProperties)[m_colorBackground2].getForeground();
}
// the buffer change of selection ...
if (m_selectedIdRequested == m_list[raw]->m_bufferID) {
m_selectedID = raw;
// stop searching
m_selectedIdRequested = -1;
// set the raw visible :
SetRawVisible(m_selectedID);
}
if (m_selectedID == raw) {
selectBG = COLOR_LIST_BG_SELECTED;
if (m_selectedID == _raw) {
_bg = (*m_paintingProperties)[m_colorBackgroundSelect].getForeground();
}
} else {
myTextToWrite = "ERROR";
_myTextToWrite = "ERROR";
}
fg = ColorizeManager::Get(selectFG);
bg = ColorizeManager::Get(selectBG);
return true;
}
bool BufferView::OnItemEvent(int32_t IdInput, ewol::keyEvent::status_te typeEvent, int32_t colomn, int32_t raw, float x, float y)
bool BufferView::onItemEvent(int32_t _IdInput, enum ewol::keyEvent::status _typeEvent, int32_t _colomn, int32_t _raw, float _x, float _y)
{
if (1 == IdInput && typeEvent == ewol::keyEvent::statusSingle) {
APPL_INFO("Event on List : IdInput=" << IdInput << " colomn=" << colomn << " raw=" << raw );
if( raw>=0
&& raw<m_list.Size()
&& NULL != m_list[raw]) {
m_selectedIdRequested = m_list[raw]->m_bufferID;
SendMultiCast(ednMsgBufferId, m_list[raw]->m_bufferID);
if (1 == _IdInput && _typeEvent == ewol::keyEvent::statusSingle) {
APPL_INFO("Event on List : IdInput=" << _IdInput << " colomn=" << _colomn << " raw=" << _raw );
if( _raw >= 0
&& _raw<m_list.size()
&& NULL != m_list[_raw]) {
if (m_list[_raw]->m_buffer != NULL) {
sendMultiCast(appl::MsgSelectNewFile, m_list[_raw]->m_buffer->getFileName());
m_selectedID = _raw;
markToRedraw();
return true;
}
}
}
MarkToRedraw();
return false;
}

View File

@@ -9,9 +9,8 @@
#ifndef __BUFFER_VIEW_H__
#define __BUFFER_VIEW_H__
#include <appl/Debug.h>
#include <CodeView.h>
#include <BufferManager.h>
#include <appl/debug.h>
#include <appl/BufferManager.h>
#include <appl/globalMsg.h>
#include <ewol/widget/List.h>
#include <ewol/widget/Windows.h>
@@ -22,13 +21,10 @@ namespace appl
{
public:
etk::FSNode m_bufferName;
uint32_t m_bufferID;
bool m_isModify;
dataBufferStruct(etk::FSNode& bufferName, int32_t bufferID, bool isModify) :
m_bufferName(bufferName),
m_bufferID(bufferID),
m_isModify(isModify)
{
appl::Buffer* m_buffer;
dataBufferStruct(const std::string& _bufferName, appl::Buffer* _buffer) :
m_bufferName(_bufferName),
m_buffer(_buffer) {
};
~dataBufferStruct(void) { };
@@ -38,27 +34,42 @@ namespace appl
class BufferView : public widget::List
{
private:
int32_t m_selectedIdRequested;
int32_t m_selectedID;
etk::Vector<appl::dataBufferStruct*> m_list;
appl::BufferManager* m_bufferManager; //!< handle on the buffer manager
private:
appl::GlyphPainting* m_paintingProperties; //!< element painting property
int32_t m_colorBackground1;
int32_t m_colorBackground2;
int32_t m_colorBackgroundSelect;
int32_t m_colorTextNormal;
int32_t m_colorTextModify;
private:
int32_t m_selectedIdRequested;
int32_t m_selectedID;
std::vector<appl::dataBufferStruct*> m_list;
/**
* @brief Insert the element in the alphabetic order.
* @param[in] _dataStruct element to add.
*/
void insertAlphabetic(appl::dataBufferStruct* _dataStruct, bool _selectNewPosition = false);
public:
// Constructeur
BufferView(void);
~BufferView(void);
// Derived function
const char * const GetObjectType(void) { return "ApplBufferView"; };
// Derived function
virtual void OnReceiveMessage(const ewol::EMessage& _msg);
virtual void onReceiveMessage(const ewol::EMessage& _msg);
virtual void onObjectRemove(ewol::EObject* _removeObject);
private:
bool m_openOrderMode; //!< true if the order is the opening order mode, otherwise, Alphabetic order
protected:
// function call to display the list :
virtual etk::Color<> GetBasicBG(void);
void RemoveAllElement(void);
virtual etk::Color<> getBasicBG(void);
void removeAllElement(void);
// Derived function
virtual uint32_t GetNuberOfColomn(void);
virtual bool GetTitle(int32_t colomn, etk::UString &myTitle, etk::Color<> &fg, etk::Color<> &bg);
virtual uint32_t GetNuberOfRaw(void);
virtual bool GetElement(int32_t colomn, int32_t raw, etk::UString &myTextToWrite, etk::Color<> &fg, etk::Color<> &bg);
virtual bool OnItemEvent(int32_t IdInput, ewol::keyEvent::status_te typeEvent, int32_t colomn, int32_t raw, float x, float y);
virtual uint32_t getNuberOfColomn(void);
virtual bool getTitle(int32_t _colomn, std::string& _myTitle, etk::Color<>& _fg, etk::Color<>& _bg);
virtual uint32_t getNuberOfRaw(void);
virtual bool getElement(int32_t _colomn, int32_t _raw, std::string& _myTextToWrite, etk::Color<>& _fg, etk::Color<>& _bg);
virtual bool onItemEvent(int32_t _IdInput, enum ewol::keyEvent::status _typeEvent, int32_t _colomn, int32_t _raw, float _x, float _y);
};

View File

@@ -1,480 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <CodeView.h>
#include <appl/Debug.h>
#include <appl/global.h>
#include <CodeView.h>
#include <BufferManager.h>
#include <ColorizeManager.h>
#include <ewol/clipBoard.h>
#include <SearchData.h>
#include <ewol/widget/WidgetManager.h>
#include <ewol/renderer/EObject.h>
#undef __class__
#define __class__ "CodeView"
void CodeView::Init(void)
{
m_label = "CodeView is disable ...";
m_bufferID = -1;
m_buttunOneSelected = false;
m_lineNumberList.Clear();
m_textColorFg = etk::color::black;
m_textColorBg = etk::color::black;
m_textColorBg.SetA(0x40);
SetCanHaveFocus(true);
RegisterMultiCast(ednMsgBufferId);
RegisterMultiCast(ednMsgGuiCopy);
RegisterMultiCast(ednMsgGuiPaste);
RegisterMultiCast(ednMsgGuiCut);
RegisterMultiCast(ednMsgGuiRedo);
RegisterMultiCast(ednMsgGuiUndo);
RegisterMultiCast(ednMsgGuiRm);
RegisterMultiCast(ednMsgGuiSelect);
RegisterMultiCast(ednMsgGuiChangeCharset);
RegisterMultiCast(ednMsgGuiFind);
RegisterMultiCast(ednMsgGuiReplace);
RegisterMultiCast(ednMsgGuiGotoLine);
SetLimitScrolling(0.2);
ShortCutAdd("ctrl+w", ednMsgGuiRm, "Line");
ShortCutAdd("ctrl+shift+w", ednMsgGuiRm, "Paragraph");
ShortCutAdd("ctrl+x", ednMsgGuiCut, "STD");
ShortCutAdd("ctrl+c", ednMsgGuiCopy, "STD");
ShortCutAdd("ctrl+v", ednMsgGuiPaste, "STD");
ShortCutAdd("ctrl+a", ednMsgGuiSelect, "ALL");
ShortCutAdd("ctrl+shift+a", ednMsgGuiSelect, "NONE");
}
CodeView::CodeView(etk::UString fontName, int32_t fontSize) :
m_displayText(fontName, fontSize)
{
Init();
}
CodeView::CodeView(void)
{
Init();
}
CodeView::~CodeView(void)
{
}
/**
* @brief Check if the number of reference buffer is good or not ...
* @param[in] bufferID id of the current Buffer that needed to have a reference
*/
void CodeView::UpdateNumberOfLineReference(int32_t bufferID)
{
vec2 tmpCoord(0,0);
if (m_lineNumberList.Size()<=bufferID) {
// update the number of elements :
for (int32_t iii=m_lineNumberList.Size(); iii <= bufferID; iii++) {
// add start line at 0 :
m_lineNumberList.PushBack(tmpCoord);
}
}
}
bool CodeView::CalculateMinSize(void)
{
m_minSize.setValue(50,50);
return true;
}
void CodeView::CalculateMaxSize(void)
{
m_maxSize.setX(2048);
int32_t letterHeight = m_displayText.CalculateSize(etk::UniChar('A')).y();
BufferText* tmpBuffer = BufferManager::Get(m_bufferID);
if (NULL!=tmpBuffer) {
m_maxSize.setY(tmpBuffer->GetNumberOfLine() * letterHeight);
} else {
m_maxSize.setY(50);
}
}
void CodeView::OnDraw(void)
{
m_displayDrawing.Draw();
m_displayText.Draw();
WidgetScrooled::OnDraw();
}
void CodeView::OnRegenerateDisplay(void)
{
if (true == NeedRedraw()) {
int64_t startTime = ewol::GetTime();
// For the scrooling windows
CalculateMaxSize();
m_displayDrawing.Clear();
m_displayText.Clear();
// Reset the background :
m_displayDrawing.SetPos(vec3(-2048, -2048, 0));
m_displayDrawing.SetColor(ColorizeManager::Get(COLOR_CODE_BASIC_BG));
m_displayDrawing.RectangleWidth(vec3(4096, 4096, 0) );
BufferText* tmpBuffer = BufferManager::Get(m_bufferID);
if( NULL != tmpBuffer
&& true == tmpBuffer->NeedToUpdateDisplayPosition() ) {
vec2 borderWidth = BufferManager::Get(m_bufferID)->GetBorderSize();
bool centerRequested = false;
// TODO : set it back ...
vec2 currentPosition = BufferManager::Get(m_bufferID)->GetPosition(999/*m_OObjectTextNormal.GetFontID()*/, centerRequested);
SetScrollingPositionDynamic(borderWidth, currentPosition, centerRequested);
} // else : nothing to do ...
// generate the objects :
if (-1 == m_bufferID) {
m_displayText.SetTextAlignement(10, m_size.x()-20, ewol::Text::alignLeft);
m_displayDrawing.SetColor(0x00000022);
m_displayDrawing.SetPos(vec3(10, 0, 0));
m_displayDrawing.Rectangle(vec3((int32_t)m_size.x()-20, 1500, 0) );
m_displayText.SetRelPos(vec3(10, 0, 0));
// nothing to display :
etk::UString tmpString("<br/>\n"
"<font color=\"red\">\n"
" <b>\n"
" edn - Editeur De N'ours\n"
" </b>\n"
"</font>\n"
"<br/>\n"
"<br/>\n"
"<font color=\"indigo\">\n"
" <i>\n"
" No Buffer Availlable to display\n"
" </i>\n"
"</font>\n");
m_displayText.SetPos(vec3(0.0f, m_size.y(), 0.0f) );
m_displayText.ForceLineReturn();
m_displayText.PrintDecorated(tmpString);
} else {
BufferText* tmpBuffer = BufferManager::Get(m_bufferID);
if (NULL!=tmpBuffer) {
tmpBuffer->Display(m_displayText, m_originScrooled.x(), m_originScrooled.y(), m_size.x(), m_size.y());
}
// set the current size of the windows
SetMaxSize(BufferManager::Get(m_bufferID)->GetMaxSize());
}
int64_t stopTime = ewol::GetTime();
APPL_DEBUG("Display Code Generation = " << stopTime - startTime << " micro-s");
// call the herited class...
WidgetScrooled::OnRegenerateDisplay();
}
}
bool CodeView::OnEventEntry(const ewol::EventEntry& _event)
{
if (_event.GetType() == ewol::keyEvent::keyboardChar) {
//APPL_DEBUG("KB EVENT : \"" << UTF8_data << "\" size=" << strlen(UTF8_data) << "type=" << (int32_t)typeEvent);
if (_event.GetStatus() == ewol::keyEvent::statusDown) {
BufferText* tmpBuffer = BufferManager::Get(m_bufferID);
if (NULL!=tmpBuffer) {
tmpBuffer->AddChar(_event.GetChar());
}
MarkToRedraw();
}
return true;
}
// move events ...
if (_event.GetStatus() == ewol::keyEvent::statusDown) {
BufferText* tmpBuffer = BufferManager::Get(m_bufferID);
if (NULL!=tmpBuffer) {
tmpBuffer->cursorMove(_event.GetType());
}
MarkToRedraw();
}
return true;
}
void CodeView::OnEventClipboard(ewol::clipBoard::clipboardListe_te _clipboardID)
{
BufferText* tmpBuffer = BufferManager::Get(m_bufferID);
if (NULL!=tmpBuffer) {
tmpBuffer->Paste(_clipboardID);
}
MarkToRedraw();
}
bool CodeView::OnEventInput(const ewol::EventInput& _event)
{
vec2 relativePos = RelativePosition(_event.GetPos());
//APPL_DEBUG("Event at pos : " << _event.GetPos() << " ==> " << relativePos );
// corection for the openGl abstraction
//relativePos.y = m_size.y - relativePos.y;
vec2 limitedPos = relativePos;
limitedPos.setValue(etk_avg(1, limitedPos.x(), m_size.x()-1),
etk_avg(1, limitedPos.y(), m_size.y()-1));
if (true == WidgetScrooled::OnEventInput(_event)) {
KeepFocus();
// nothing to do ... done on upper widget ...
return true;
}
if (m_bufferID < 0) {
return false;
}
if (1 == _event.GetId()) {
if (ewol::keyEvent::typeMouse == _event.GetType()) {
if (ewol::keyEvent::statusDown == _event.GetStatus()) {
m_buttunOneSelected = true;
KeepFocus();
// TODO : Set something good
BufferText* tmpBuffer = BufferManager::Get(m_bufferID);
if (NULL!=tmpBuffer) {
tmpBuffer->MouseEvent(limitedPos);
}
MarkToRedraw();
} else if (ewol::keyEvent::statusUp == _event.GetStatus()) {
m_buttunOneSelected = false;
BufferText* tmpBuffer = BufferManager::Get(m_bufferID);
if (NULL!=tmpBuffer) {
tmpBuffer->Copy(ewol::clipBoard::clipboardSelection);
}
MarkToRedraw();
}
}
if (ewol::keyEvent::statusSingle == _event.GetStatus()) {
if (ewol::keyEvent::typeMouse == _event.GetType()) {
KeepFocus();
BufferText* tmpBuffer = BufferManager::Get(m_bufferID);
if (NULL!=tmpBuffer) {
tmpBuffer->MouseEvent(limitedPos);
}
MarkToRedraw();
} else {
// nothing to do ...
}
} else if (ewol::keyEvent::statusDouble == _event.GetStatus()) {
BufferText* tmpBuffer = BufferManager::Get(m_bufferID);
if (NULL!=tmpBuffer) {
tmpBuffer->MouseEventDouble();
}
MarkToRedraw();
} else if (ewol::keyEvent::statusTriple == _event.GetStatus()) {
BufferText* tmpBuffer = BufferManager::Get(m_bufferID);
if (NULL!=tmpBuffer) {
tmpBuffer->MouseEventTriple();
}
MarkToRedraw();
} else if (ewol::keyEvent::statusMove == _event.GetStatus()) {
if (true == m_buttunOneSelected) {
int xxx, yyy;
xxx = relativePos.x();
yyy = relativePos.y();
if (xxx<0) {
xxx = 0;
}
if (yyy<0) {
yyy = 0;
}
//APPL_INFO("mouse-motion BT1 %d, %d", xxx, yyy);
// TODO : Set something good
BufferText* tmpBuffer = BufferManager::Get(m_bufferID);
if (NULL!=tmpBuffer) {
tmpBuffer->MouseSelectFromCursorTo(limitedPos);
}
MarkToRedraw();
}
}
} else if (2 == _event.GetId()) {
if (ewol::keyEvent::statusSingle == _event.GetStatus()) {
// TODO : Set something good
BufferText* tmpBuffer = BufferManager::Get(m_bufferID);
if (NULL!=tmpBuffer) {
tmpBuffer->MouseEvent(limitedPos);
}
ewol::clipBoard::Request(ewol::clipBoard::clipboardSelection);
KeepFocus();
}
}
return true;
}
void CodeView::OnReceiveMessage(const ewol::EMessage& _msg)
{
widget::WidgetScrooled::OnReceiveMessage(_msg);
APPL_DEBUG("Extern Event : " << _msg.GetCaller() << " type : " << _msg.GetMessage() << " data=\"" << _msg.GetData() << "\"");
if(_msg.GetMessage() == ednMsgBufferId) {
//keep the reference of the display offset :
if( m_bufferID >=0
&& m_bufferID < m_lineNumberList.Size()) {
m_lineNumberList[m_bufferID] = m_originScrooled;
}
int32_t bufferID = 0;
sscanf(_msg.GetData().c_str(), "%d", &bufferID);
APPL_INFO("Select a new Buffer ... " << bufferID);
// set the new buffer ID
m_bufferID = bufferID;
// update the start display position...
UpdateNumberOfLineReference(m_bufferID);
// set back if needed the display position ...
if( m_bufferID >=0
&& m_bufferID < m_lineNumberList.Size()) {
m_originScrooled = m_lineNumberList[m_bufferID];
}
} else if (_msg.GetMessage() == ednMsgGuiCopy) {
BufferText* tmpBuffer = BufferManager::Get(m_bufferID);
if (NULL!=tmpBuffer) {
tmpBuffer->Copy(ewol::clipBoard::clipboardStd);
}
} else if (_msg.GetMessage() == ednMsgGuiCut) {
BufferText* tmpBuffer = BufferManager::Get(m_bufferID);
if (NULL!=tmpBuffer) {
tmpBuffer->Cut(ewol::clipBoard::clipboardStd);
}
} else if (_msg.GetMessage() == ednMsgGuiPaste) {
ewol::clipBoard::Request(ewol::clipBoard::clipboardStd);
} else if (_msg.GetMessage() == ednMsgGuiUndo) {
BufferText* tmpBuffer = BufferManager::Get(m_bufferID);
if (NULL!=tmpBuffer) {
tmpBuffer->Undo();
}
} else if (_msg.GetMessage() == ednMsgGuiRedo) {
BufferText* tmpBuffer = BufferManager::Get(m_bufferID);
if (NULL!=tmpBuffer) {
tmpBuffer->Redo();
}
} else if (_msg.GetMessage() == ednMsgGuiRm) {
// data : "Word" "Line" "Paragraph"
if (_msg.GetData() == "Word") {
APPL_WARNING(" on event " << _msg.GetMessage() << " data=\"" << _msg.GetData() << "\" ==> not coded" );
} else if (_msg.GetData() == "Line") {
BufferText* tmpBuffer = BufferManager::Get(m_bufferID);
if (NULL!=tmpBuffer) {
tmpBuffer->RemoveLine();
}
} else if (_msg.GetData() == "Paragraph") {
APPL_WARNING(" on event " << _msg.GetMessage() << " data=\"" << _msg.GetData() << "\" ==> not coded" );
} else {
APPL_ERROR(" on event " << _msg.GetMessage() << " unknow data=\"" << _msg.GetData() << "\"" );
}
} else if (_msg.GetMessage() == ednMsgGuiSelect) {
// data : "ALL" "NONE"
if (_msg.GetData() == "ALL") {
BufferText* tmpBuffer = BufferManager::Get(m_bufferID);
if (NULL!=tmpBuffer) {
tmpBuffer->SelectAll();
}
} else if (_msg.GetData() == "NONE") {
BufferText* tmpBuffer = BufferManager::Get(m_bufferID);
if (NULL!=tmpBuffer) {
tmpBuffer->SelectNone();
}
} else {
APPL_ERROR(" on event " << _msg.GetMessage() << " unknow data=\"" << _msg.GetData() << "\"" );
}
} else if (_msg.GetMessage() == ednMsgGuiChangeCharset) {
// data : "UTF-8" "ISO-8859-1" "ISO-8859-15"
if (_msg.GetData() == "UTF-8") {
BufferText* tmpBuffer = BufferManager::Get(m_bufferID);
if (NULL!=tmpBuffer) {
tmpBuffer->SetCharset(unicode::EDN_CHARSET_UTF8);
}
} else if (_msg.GetData() == "ISO-8859-1") {
BufferText* tmpBuffer = BufferManager::Get(m_bufferID);
if (NULL!=tmpBuffer) {
tmpBuffer->SetCharset(unicode::EDN_CHARSET_ISO_8859_1);
}
} else if (_msg.GetData() == "ISO-8859-15") {
BufferText* tmpBuffer = BufferManager::Get(m_bufferID);
if (NULL!=tmpBuffer) {
tmpBuffer->SetCharset(unicode::EDN_CHARSET_ISO_8859_15);
}
} else {
APPL_ERROR(" on event " << _msg.GetMessage() << " unknow data=\"" << _msg.GetData() << "\"" );
}
} else if (_msg.GetMessage() == ednMsgGuiFind) {
etk::UString myDataString;
SearchData::GetSearch(myDataString);
if (_msg.GetData() == "Next") {
BufferText* tmpBuffer = BufferManager::Get(m_bufferID);
if (NULL!=tmpBuffer) {
tmpBuffer->Search(myDataString, false, SearchData::GetCase(), SearchData::GetWrap(), SearchData::GetRegExp() );
}
} else if (_msg.GetData() == "Previous") {
BufferText* tmpBuffer = BufferManager::Get(m_bufferID);
if (NULL!=tmpBuffer) {
tmpBuffer->Search(myDataString, true, SearchData::GetCase(), SearchData::GetWrap(), SearchData::GetRegExp() );
}
}
} else if (_msg.GetMessage() == ednMsgGuiReplace) {
etk::UString myDataString;
SearchData::GetReplace(myDataString);
if (_msg.GetData() == "Normal") {
BufferText* tmpBuffer = BufferManager::Get(m_bufferID);
if (NULL!=tmpBuffer) {
tmpBuffer->Replace(myDataString);
}
} else if (_msg.GetData() == "All") {
}
} else if (_msg.GetMessage() == ednMsgGuiGotoLine) {
int32_t lineID = 0;
sscanf(_msg.GetData().c_str(), "%d", &lineID);
APPL_INFO("Goto line : " << lineID);
BufferText* tmpBuffer = BufferManager::Get(m_bufferID);
if (NULL!=tmpBuffer) {
tmpBuffer->JumpAtLine(lineID);
}
}
// Force redraw of the widget
MarkToRedraw();
}
void CodeView::OnGetFocus(void)
{
/*
ewol::widgetMessageMultiCast::Send(GetWidgetId(), ednMsgBufferId, m_bufferID);
*/
ShowKeyboard();
APPL_INFO("Focus - In");
}
void CodeView::OnLostFocus(void)
{
HideKeyboard();
APPL_INFO("Focus - out");
}
void CodeView::SetFontSize(int32_t size)
{
m_displayText.SetFontSize(size);
SetScrollingSize(size*3.0*1.46); // 1.46 is a magic nmber ...
}
void CodeView::SetFontName(etk::UString fontName)
{
m_displayText.SetFontName(fontName);
}

View File

@@ -1,59 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __CODE_VIEW_H__
#define __CODE_VIEW_H__
#include <appl/Debug.h>
#include <CodeView.h>
#include <BufferManager.h>
#include <appl/globalMsg.h>
#include <ewol/widget/WidgetScrolled.h>
#include <ewol/compositing/Text.h>
#include <ewol/compositing/Drawing.h>
class CodeView :public widget::WidgetScrooled
{
public:
void Init(void);
CodeView(etk::UString fontName, int32_t fontSize);
CodeView(void);
virtual ~CodeView(void);
private:
etk::UString m_label;
etk::Color<> m_textColorFg; //!< Text color
etk::Color<> m_textColorBg; //!< Background color
int32_t m_bufferID;
bool m_buttunOneSelected;
etk::Vector<vec2 > m_lineNumberList;
void UpdateNumberOfLineReference(int32_t bufferID);
// drawing elements :
ewol::Text m_displayText;
ewol::Drawing m_displayDrawing;
public:
void SetFontSize(int32_t size);
void SetFontName(etk::UString fontName);
private:
void CalculateMaxSize(void);
protected: // derived function
virtual void OnDraw(void);
public: // Derived function
const char * const GetObjectType(void) { return "ApplCodeView"; };
virtual bool CalculateMinSize(void);
virtual void OnRegenerateDisplay(void);
virtual void OnReceiveMessage(const ewol::EMessage& _msg);
virtual bool OnEventInput(const ewol::EventInput& _event);
virtual bool OnEventEntry(const ewol::EventEntry& _event);
virtual void OnEventClipboard(ewol::clipBoard::clipboardListe_te clipboardID);
virtual void OnGetFocus(void);
virtual void OnLostFocus(void);
};
#endif

View File

@@ -7,12 +7,12 @@
*/
#include <appl/Debug.h>
#include <appl/debug.h>
#include <appl/global.h>
#include <MainWindows.h>
#include <CodeView.h>
#include <BufferView.h>
#include <Search.h>
#include <appl/Gui/MainWindows.h>
#include <appl/Gui/BufferView.h>
#include <appl/Gui/TextViewer.h>
#include <appl/Gui/Search.h>
#include <ewol/widget/Button.h>
#include <ewol/widget/CheckBox.h>
@@ -31,17 +31,20 @@
#include <ewol/renderer/EObject.h>
#include <ewol/renderer/eContext.h>
#include <date/date.h>
#include <ewol/widget/meta/StdPopUp.h>
#include <appl/Gui/WorkerSaveFile.h>
#include <appl/Gui/WorkerSaveAllFile.h>
#include <appl/Gui/WorkerCloseFile.h>
#include <appl/Gui/WorkerCloseAllFile.h>
namespace appl
{
etk::UString GetVersion(void)
{
namespace appl {
std::string getVersion(void) {
#define FIRST_YEAR (2010)
etk::UString tmpOutput = (date::GetYear()-FIRST_YEAR);
std::string tmpOutput = std::to_string(date::getYear()-FIRST_YEAR);
tmpOutput += ".";
tmpOutput += date::GetMonth();
tmpOutput += std::to_string(date::getMonth());
tmpOutput += ".";
tmpOutput += date::GetDay();
tmpOutput += std::to_string(date::getDay());
return tmpOutput;
}
@@ -54,35 +57,33 @@ namespace appl
#include <ewol/widget/Label.h>
#include <ewol/widget/Spacer.h>
class ParameterAboutGui : public widget::Sizer
{
class ParameterAboutGui : public widget::Sizer {
public :
ParameterAboutGui(void) :
widget::Sizer(widget::Sizer::modeVert)
{
widget::Sizer(widget::Sizer::modeVert) {
widget::Spacer* mySpacer = NULL;
mySpacer = new widget::Spacer();
if (NULL == mySpacer) {
APPL_ERROR("Can not allocate widget ==> display might be in error");
APPL_ERROR("Can not allocate widget == > display might be in error");
} else {
mySpacer->SetExpand(bvec2(true,true));
SubWidgetAdd(mySpacer);
mySpacer->setExpand(bvec2(true,true));
subWidgetAdd(mySpacer);
}
etk::UString tmpLabel = "<left>";
std::string tmpLabel = "<left>";
tmpLabel += " <b>Editeur De N'ours</b> : v:";
tmpLabel += appl::GetVersion();
tmpLabel += appl::getVersion();
tmpLabel += "<br/>";
tmpLabel += " <b>Build Time</b> : ";
tmpLabel += date::GetYear();
tmpLabel += date::getYear();
tmpLabel += "/";
tmpLabel += date::GetMonth();
tmpLabel += date::getMonth();
tmpLabel += "/";
tmpLabel += date::GetDay();
tmpLabel += date::getDay();
tmpLabel += " ";
tmpLabel += date::GetHour();
tmpLabel += date::getHour();
tmpLabel += "h";
tmpLabel += date::GetMinute();
tmpLabel += date::getMinute();
tmpLabel += "<br/>";
tmpLabel += " <b>Website</b> : https://github.com/HeeroYui/edn<br/>";
tmpLabel += " <b>License</b> : GPL v3<br/>";
@@ -94,181 +95,196 @@ class ParameterAboutGui : public widget::Sizer
tmpLabel += "</left>";
widget::Label* myLabel = new widget::Label(tmpLabel);
if (NULL == myLabel) {
APPL_ERROR("Can not allocate widget ==> display might be in error");
APPL_ERROR("Can not allocate widget == > display might be in error");
} else {
myLabel->SetExpand(bvec2(true,false));
SubWidgetAdd(myLabel);
myLabel->setExpand(bvec2(true,false));
subWidgetAdd(myLabel);
}
};
~ParameterAboutGui(void) { };
~ParameterAboutGui(void) {
};
};
// Local main windows event :
static const char* mainWindowsRequestSaveFile = "appl-event-main-windows-save-file";
static const char* mainWindowsRequestSaveFileAs = "appl-event-main-windows-save-file-as";
static const char* mainWindowsRequestcloseFileNoCheck = "appl-event-main-windows-close-file-no-check";
const char * l_smoothChick = "tmpEvent_smooth";
const char * l_smoothMin = "tmpEvent_minChange";
const char * l_smoothMax = "tmpEvent_maxChange";
const char* l_smoothChick = "tmpEvent_smooth";
const char* l_smoothMin = "tmpEvent_minChange";
const char* l_smoothMax = "tmpEvent_maxChange";
#undef __class__
#define __class__ "MainWindows"
#define __class__ "MainWindows"
MainWindows::MainWindows(void)
{
MainWindows::MainWindows(void) {
addObjectType("appl::MainWindows");
APPL_DEBUG("CREATE WINDOWS ... ");
widget::Sizer * mySizerVert = NULL;
widget::Sizer * mySizerVert2 = NULL;
widget::Sizer * mySizerHori = NULL;
//ewol::Button * myButton = NULL;
CodeView * myCodeView = NULL;
appl::TextViewer * myTextView = NULL;
BufferView * myBufferView = NULL;
widget::Menu * myMenu = NULL;
// load buffer manager:
m_bufferManager = appl::BufferManager::keep();
mySizerVert = new widget::Sizer(widget::Sizer::modeVert);
SetSubWidget(mySizerVert);
setSubWidget(mySizerVert);
mySizerHori = new widget::Sizer(widget::Sizer::modeHori);
mySizerVert->SubWidgetAdd(mySizerHori);
mySizerVert->subWidgetAdd(mySizerHori);
myBufferView = new BufferView();
myBufferView->SetExpand(bvec2(false,true));
myBufferView->SetFill(bvec2(true,true));
mySizerHori->SubWidgetAdd(myBufferView);
myBufferView->setExpand(bvec2(false,true));
myBufferView->setFill(bvec2(true,true));
mySizerHori->subWidgetAdd(myBufferView);
mySizerVert2 = new widget::Sizer(widget::Sizer::modeVert);
mySizerHori->SubWidgetAdd(mySizerVert2);
mySizerHori->subWidgetAdd(mySizerVert2);
// main buffer Area :
myCodeView = new CodeView("FreeMono;DejaVuSansMono", 11);
myCodeView->SetExpand(bvec2(true,true));
myCodeView->SetFill(bvec2(true,true));
mySizerVert2->SubWidgetAdd(myCodeView);
myTextView = new appl::TextViewer("FreeMono;DejaVuSansMono;FreeSerif", 11);
myTextView->setExpand(bvec2(true,true));
myTextView->setFill(bvec2(true,true));
mySizerVert2->subWidgetAdd(myTextView);
/*
myTextView = new appl::TextViewer("FreeMono;DejaVuSansMono;FreeSerif", 11);
myTextView->setExpand(bvec2(true,true));
myTextView->setFill(bvec2(true,true));
mySizerVert2->subWidgetAdd(myTextView);
*/
// search area :
Search * mySearch = new Search();
mySizerVert2->SubWidgetAdd(mySearch);
mySizerVert2->subWidgetAdd(mySearch);
#ifdef APPL_BUFFER_FONT_DISTANCE_FIELD
{
widget::Sizer * mySizerHori2 = new widget::Sizer(widget::Sizer::modeHori);
mySizerVert2->SubWidgetAdd(mySizerHori2);
mySizerVert2->subWidgetAdd(mySizerHori2);
widget::CheckBox* tmpCheck = new widget::CheckBox("smooth");
mySizerHori2->SubWidgetAdd(tmpCheck);
tmpCheck->RegisterOnEvent(this, ewolEventCheckBoxClicked, l_smoothChick);
mySizerHori2->subWidgetAdd(tmpCheck);
tmpCheck->registerOnEvent(this, ewolEventCheckBoxClicked, l_smoothChick);
widget::Slider* tmpSlider = new widget::Slider();
mySizerHori2->SubWidgetAdd(tmpSlider);
tmpSlider->RegisterOnEvent(this, ewolEventSliderChange, l_smoothMin);
tmpSlider->SetExpand(bvec2(true,false));
tmpSlider->SetMin(0);
tmpSlider->SetMax(1000);
tmpSlider->SetValue(0450);
mySizerHori2->subWidgetAdd(tmpSlider);
tmpSlider->registerOnEvent(this, ewolEventSliderChange, l_smoothMin);
tmpSlider->setExpand(bvec2(true,false));
tmpSlider->setMin(0);
tmpSlider->setMax(1000);
tmpSlider->setValue(0450);
tmpSliderMin = tmpSlider;
tmpSlider = new widget::Slider();
mySizerHori2->SubWidgetAdd(tmpSlider);
tmpSlider->RegisterOnEvent(this, ewolEventSliderChange, l_smoothMax);
tmpSlider->SetExpand(bvec2(true,false));
tmpSlider->SetMin(0);
tmpSlider->SetMax(1000);
tmpSlider->SetValue(0550);
mySizerHori2->subWidgetAdd(tmpSlider);
tmpSlider->registerOnEvent(this, ewolEventSliderChange, l_smoothMax);
tmpSlider->setExpand(bvec2(true,false));
tmpSlider->setMin(0);
tmpSlider->setMax(1000);
tmpSlider->setValue(0550);
tmpSliderMax = tmpSlider;
}
#endif
mySizerHori = new widget::Sizer(widget::Sizer::modeHori);
mySizerVert->SubWidgetAdd(mySizerHori);
mySizerVert->subWidgetAdd(mySizerHori);
myMenu = new widget::Menu();
mySizerHori->SubWidgetAdd(myMenu);
int32_t idMenuFile = myMenu->AddTitle("File");
(void)myMenu->Add(idMenuFile, "New", "", ednMsgGuiNew);
(void)myMenu->AddSpacer();
(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");
(void)myMenu->Add(idMenuFile, "Save", "THEME:GUI:Save.svg", ednMsgGuiSave, "current");
(void)myMenu->Add(idMenuFile, "Save As ...", "", ednMsgGuiSaveAs);
(void)myMenu->AddSpacer();
//(void)myMenu->Add(idMenuFile, "Exit", "", ednMsgGuiExit);
(void)myMenu->AddSpacer();
(void)myMenu->Add(idMenuFile, "Properties", "THEME:GUI:Parameter.svg", ednMsgProperties);
int32_t idMenuEdit = myMenu->AddTitle("Edit");
(void)myMenu->Add(idMenuEdit, "Undo", "THEME:GUI:Undo.svg", ednMsgGuiUndo);
(void)myMenu->Add(idMenuEdit, "Redo", "THEME:GUI:Redo.svg", ednMsgGuiRedo);
(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);
(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, "???");
int32_t idMenuSearch = myMenu->AddTitle("Search");
(void)myMenu->Add(idMenuSearch, "Search", "THEME:GUI:Search.svg", ednMsgGuiSearch);
(void)myMenu->Add(idMenuSearch, "Replace", "THEME:GUI:Replace.svg", 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");
int32_t idMenuCTags = myMenu->AddTitle("C-tags");
(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");
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");
(void)myMenu->AddSpacer();
(void)myMenu->Add(idMenugDisplay, "Reload OpenGl Shader", "", ednMsgGuiReloadShader);
mySizerHori->subWidgetAdd(myMenu);
int32_t idMenuFile = myMenu->addTitle("File");
(void)myMenu->add(idMenuFile, "New", "", ednMsgGuiNew);
(void)myMenu->addSpacer();
(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");
(void)myMenu->add(idMenuFile, "Save", "THEME:GUI:Save.svg", ednMsgGuiSave, "current");
(void)myMenu->add(idMenuFile, "Save As ...", "", ednMsgGuiSaveAs);
(void)myMenu->addSpacer();
//(void)myMenu->add(idMenuFile, "Exit", "", ednMsgGuiExit);
(void)myMenu->addSpacer();
(void)myMenu->add(idMenuFile, "Properties", "THEME:GUI:Parameter.svg", ednMsgProperties);
int32_t idMenuEdit = myMenu->addTitle("Edit");
(void)myMenu->add(idMenuEdit, "Undo", "THEME:GUI:Undo.svg", ednMsgGuiUndo);
(void)myMenu->add(idMenuEdit, "Redo", "THEME:GUI:Redo.svg", ednMsgGuiRedo);
(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);
(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, "???");
int32_t idMenuSearch = myMenu->addTitle("Search");
(void)myMenu->add(idMenuSearch, "Search", "THEME:GUI:Search.svg", ednMsgGuiSearch);
(void)myMenu->add(idMenuSearch, "Replace", "THEME:GUI:Replace.svg", 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");
/* ==> must be in the pluggin list control ...
int32_t idMenuCTags = myMenu->addTitle("C-tags");
(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");
*/
int32_t idMenugDisplay = myMenu->addTitle("Display");
(void)myMenu->add(idMenugDisplay, "Color Black", "", appl::MsgNameGuiChangeColor, "colorBlack/");
(void)myMenu->add(idMenugDisplay, "Color White", "", appl::MsgNameGuiChangeColor, "colorWhite/");
(void)myMenu->addSpacer();
(void)myMenu->add(idMenugDisplay, "Reload openGl Shader", "", ednMsgGuiReloadShader);
m_widgetLabelFileName = new widget::Label("<left>FileName</left>");
m_widgetLabelFileName->SetExpand(bvec2(true,false));
m_widgetLabelFileName->SetFill(bvec2(false,true));;
mySizerHori->SubWidgetAdd(m_widgetLabelFileName);
m_widgetLabelFileName = new widget::Label("FileName");
m_widgetLabelFileName->setExpand(bvec2(true,false));
m_widgetLabelFileName->setFill(bvec2(true,false));;
mySizerHori->subWidgetAdd(m_widgetLabelFileName);
// 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);
// (shift, control, alt, meta, char32_t unicodeValue, const char * generateEventId, std::string& 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+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+q", ednMsgGuiClose, "current", true);
shortCutAdd("ctrl+shift+q", ednMsgGuiClose, "All", true);
ShortCutAdd("ctrl+z", ednMsgGuiUndo, "", true);
ShortCutAdd("ctrl+shift+z", ednMsgGuiRedo, "", true);
shortCutAdd("ctrl+z", ednMsgGuiUndo, "", true);
shortCutAdd("ctrl+shift+z", ednMsgGuiRedo, "", true);
ShortCutAdd("ctrl+l", ednMsgGuiGotoLine, "???", true);
shortCutAdd("ctrl+l", ednMsgGuiGotoLine, "???", true);
ShortCutAdd("ctrl+f", ednMsgGuiSearch, "", true);
ShortCutAdd("F12", ednMsgGuiReloadShader, "", true);
shortCutAdd("ctrl+f", ednMsgGuiSearch, "", true);
shortCutAdd("F12", ednMsgGuiReloadShader, "", true);
ShortCutAdd("ctrl+d", ednMsgGuiCtags, "Jump", true);
//shortCutAdd("ctrl+d", ednMsgGuiCtags, "Jump", true);
// Generic event ...
RegisterMultiCast(ednMsgGuiSaveAs);
RegisterMultiCast(ednMsgProperties);
RegisterMultiCast(ednMsgGuiOpen);
registerMultiCast(ednMsgGuiSave);
registerMultiCast(ednMsgGuiSaveAs);
registerMultiCast(ednMsgProperties);
registerMultiCast(ednMsgGuiNew);
registerMultiCast(ednMsgGuiOpen);
registerMultiCast(ednMsgGuiClose);
// to update the title ...
RegisterMultiCast(ednMsgBufferState);
RegisterMultiCast(ednMsgBufferId);
RegisterMultiCast(ednMsgGuiReloadShader);
registerMultiCast(ednMsgBufferState);
registerMultiCast(ednMsgBufferId);
registerMultiCast(ednMsgGuiReloadShader);
registerMultiCast(appl::MsgNameGuiChangeColor);
registerMultiCast(appl::MsgSelectNewFile);
}
MainWindows::~MainWindows(void)
{
MainWindows::~MainWindows(void) {
appl::BufferManager::release(m_bufferManager);
}
@@ -276,125 +292,206 @@ const char *const ednEventPopUpFileSelected = "edn-mainWindows-openSelected";
const char *const ednEventPopUpFileSaveAs = "edn-mainWindows-saveAsSelected";
void MainWindows::OnReceiveMessage(const ewol::EMessage& _msg)
{
ewol::Windows::OnReceiveMessage(_msg);
void MainWindows::onReceiveMessage(const ewol::EMessage& _msg) {
ewol::Windows::onReceiveMessage(_msg);
//APPL_INFO("Receive Event from the main windows ... : \"" << eventId << "\" ==> data=\"" << data << "\"" );
// Open file Section ...
if (_msg.GetMessage() == ednMsgGuiOpen) {
APPL_VERBOSE("Receive Event from the main windows: " << _msg );
// open file Section ...
if (_msg.getMessage() == ednMsgGuiOpen) {
widget::FileChooser* tmpWidget = new widget::FileChooser();
tmpWidget->SetTitle("Open Files ...");
tmpWidget->SetValidateLabel("Open");
if (BufferManager::GetSelected()!=-1) {
BufferText * myBuffer = BufferManager::Get(BufferManager::GetSelected());
if (NULL!=myBuffer) {
etk::FSNode tmpFile = myBuffer->GetFileName();
tmpWidget->SetFolder(tmpFile.GetNameFolder());
}
}
PopUpWidgetPush(tmpWidget);
tmpWidget->RegisterOnEvent(this, ewolEventFileChooserValidate, ednEventPopUpFileSelected);
} else if (_msg.GetMessage() == ednEventPopUpFileSelected) {
APPL_DEBUG("Request opening the file : " << _msg.GetData());
SendMultiCast(ednMsgOpenFile, _msg.GetData());
} else if (_msg.GetMessage() == ednMsgGuiSaveAs) {
if (_msg.GetData() == "") {
APPL_ERROR("Null data for Save As file ... ");
} else {
m_currentSavingAsIdBuffer = -1;
if (_msg.GetData() == "current") {
m_currentSavingAsIdBuffer = BufferManager::GetSelected();
} else {
sscanf(_msg.GetData().c_str(), "%d", &m_currentSavingAsIdBuffer);
}
if (false == BufferManager::Exist(m_currentSavingAsIdBuffer)) {
APPL_ERROR("Request saveAs on non existant Buffer ID=" << m_currentSavingAsIdBuffer);
} else {
BufferText* myBuffer = BufferManager::Get(m_currentSavingAsIdBuffer);
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()) {
etk::FSNode tmpName = myBuffer->GetFileName();
folder = tmpName.GetNameFolder();
fileName = tmpName.GetNameFile();
}
tmpWidget->SetFolder(folder);
tmpWidget->SetFileName(fileName);
PopUpWidgetPush(tmpWidget);
tmpWidget->RegisterOnEvent(this, ewolEventFileChooserValidate, ednEventPopUpFileSaveAs);
}
}
}
} else if (_msg.GetMessage() == ednEventPopUpFileSaveAs) {
// get the filename :
etk::UString tmpData = _msg.GetData();
APPL_DEBUG("Request Saving As file : " << tmpData);
BufferManager::Get(m_currentSavingAsIdBuffer)->SetFileName(tmpData);
SendMultiCast(ednMsgGuiSave, m_currentSavingAsIdBuffer);
} else if( _msg.GetMessage() == ednMsgBufferState
|| _msg.GetMessage() == ednMsgBufferId) {
// the buffer change we need to update the widget string
BufferText* tmpBuffer = BufferManager::Get(BufferManager::GetSelected());
if (NULL != tmpBuffer) {
etk::FSNode compleateName = tmpBuffer->GetFileName();
bool isModify = tmpBuffer->IsModify();
etk::UString directName = compleateName.GetName();
if (true == isModify) {
directName += " *";
}
if (NULL != m_widgetLabelFileName) {
m_widgetLabelFileName->SetLabel(etk::UString("<left>") + directName + "</left>");
}
etk::UString windowsTitle = "edn - ";
windowsTitle += directName;
SetTitle(windowsTitle);
if (tmpWidget == NULL) {
APPL_ERROR("Can not open File chooser !!! ");
return;
} else {
m_widgetLabelFileName->SetLabel("");
SetTitle("edn");
}
return;
// TODO : Set the Title ....
} else if (_msg.GetMessage() == ednMsgProperties) {
tmpWidget->setTitle("Open files ...");
tmpWidget->setValidateLabel("Open");
if (m_bufferManager == NULL) {
APPL_ERROR("can not call unexistant buffer manager ... ");
return;
}
// Get a ref on the buffer selected (if null, no buffer was selected ...)
appl::Buffer* tmpBuffer = m_bufferManager->getBufferSelected();
if (tmpBuffer != NULL) {
etk::FSNode tmpFile = tmpBuffer->getFileName();
tmpWidget->setFolder(tmpFile.getNameFolder());
}
// apply widget pop-up ...
popUpWidgetPush(tmpWidget);
tmpWidget->registerOnEvent(this, widget::FileChooser::eventValidate, ednEventPopUpFileSelected);
} else if (_msg.getMessage() == ednMsgProperties) {
// Request the parameter GUI
widget::Parameter* tmpWidget = new widget::Parameter();
if (NULL == tmpWidget) {
APPL_ERROR("Can not allocate widget ==> display might be in error");
APPL_ERROR("Can not allocate widget == > display might be in error");
} else {
tmpWidget->SetTitle("Properties");
PopUpWidgetPush(tmpWidget);
tmpWidget->MenuAddGroup("Editor");
tmpWidget->setTitle("Properties");
popUpWidgetPush(tmpWidget);
tmpWidget->menuAddGroup("Editor");
ewol::Widget* tmpSubWidget = new globals::ParameterGlobalsGui();
tmpWidget->MenuAdd("Editor", "", tmpSubWidget);
tmpWidget->MenuAdd("Font & Color", "", NULL);
tmpWidget->MenuAdd("Highlight", "", NULL);
tmpWidget->MenuAddGroup("General");
tmpWidget->MenuAdd("Display", "", NULL);
tmpWidget->menuAdd("Editor", "", tmpSubWidget);
tmpWidget->menuAdd("Font & Color", "", NULL);
tmpWidget->menuAdd("Highlight", "", NULL);
tmpWidget->menuAddGroup("General");
tmpWidget->menuAdd("Display", "", NULL);
tmpSubWidget = new ParameterAboutGui();
tmpWidget->MenuAdd("About", "", tmpSubWidget);
tmpWidget->menuAdd("About", "", tmpSubWidget);
}
} else if (_msg.GetMessage() == ednMsgGuiReloadShader) {
ewol::GetContext().GetResourcesManager().ReLoadResources();
ewol::GetContext().ForceRedrawAll();
} else if (_msg.GetMessage() == ednMsgGuiExit) {
// TODO ...
} else if (_msg.getMessage() == appl::MsgNameGuiChangeColor) {
etk::theme::setName("COLOR", _msg.getData());
ewol::getContext().getResourcesManager().reLoadResources();
ewol::getContext().forceRedrawAll();
} else if (_msg.getMessage() == ednMsgGuiReloadShader) {
ewol::getContext().getResourcesManager().reLoadResources();
ewol::getContext().forceRedrawAll();
} else if (_msg.getMessage() == ednMsgGuiExit) {
// TODO : ...
}
// Note : Fore all next message we need to acces to the buffer manager ==> just check one time ...
if (m_bufferManager == NULL) {
APPL_ERROR("can not call unexistant buffer manager ... ");
return;
}
if ( _msg.getMessage() == appl::MsgSelectNewFile
|| _msg.getMessage() == appl::Buffer::eventIsModify
|| _msg.getMessage() == appl::Buffer::eventIsSave
|| _msg.getMessage() == appl::Buffer::eventChangeName) {
// select a new Buffer ==> change title:
appl::Buffer* tmpp = m_bufferManager->getBufferSelected();
if (tmpp == NULL) {
setTitle("Edn");
if (m_widgetLabelFileName != NULL) {
m_widgetLabelFileName->setLabel("");
}
} else {
if (_msg.getMessage() == appl::MsgSelectNewFile) {
tmpp->registerOnEvent(this, appl::Buffer::eventIsModify);
tmpp->registerOnEvent(this, appl::Buffer::eventIsSave);
tmpp->registerOnEvent(this, appl::Buffer::eventChangeName);
}
setTitle(std::string("Edn : ") + (tmpp->isModify()==true?" *":"") + tmpp->getFileName());
if (m_widgetLabelFileName != NULL) {
m_widgetLabelFileName->setLabel(tmpp->getFileName() + (tmpp->isModify()==true?" *":""));
}
}
} else if (_msg.getMessage() == ednMsgGuiNew) {
(void)m_bufferManager->createNewBuffer();
} else if (_msg.getMessage() == ednEventPopUpFileSelected) {
APPL_DEBUG("Request opening the file : " << _msg.getData());
m_bufferManager->open(_msg.getData());
} else if (_msg.getMessage() == ednMsgGuiSave) {
APPL_DEBUG("Request saving the file : " << _msg.getData());
if (to_lower(_msg.getData()) == "current") {
appl::WorkerSaveFile* tmpWorker = new appl::WorkerSaveFile("", false);
return;
} else if (to_lower(_msg.getData()) == "all") {
appl::WorkerSaveAllFile* tmpWorker = new appl::WorkerSaveAllFile();
return;
} else {
APPL_ERROR("UNKNOW request : " << _msg);
}
} else if (_msg.getMessage() == ednMsgGuiSaveAs) {
appl::WorkerSaveFile* tmpWorker = new appl::WorkerSaveFile("", true);
} else if (_msg.getMessage() == ednMsgGuiClose) {
// Get a ref on the buffer selected (if null, no buffer was selected ...)
if (_msg.getData() == "current") {
appl::WorkerCloseFile* tmpWorker = new appl::WorkerCloseFile("");
} else {
appl::WorkerCloseAllFile* tmpWorker = new appl::WorkerCloseAllFile();
}
} else if (_msg.getMessage() == mainWindowsRequestSaveFile) { // return after a choice of close...
if (m_bufferManager->exist(_msg.getData()) == false) {
APPL_ERROR("Try to save an non-existant file :" << _msg.getData());
return;
}
appl::Buffer* tmpBuffer = m_bufferManager->get(_msg.getData());
if (tmpBuffer == NULL) {
APPL_ERROR("Error to get the buffer : " << _msg.getData());
return;
}
if (tmpBuffer->hasFileName() == false) {
APPL_ERROR("Will never arrive");
saveAsPopUp(tmpBuffer);
} else {
if (tmpBuffer->storeFile() == false) {
APPL_ERROR("Error when loading the file " << _msg.getData());
displayErrorMessage("Error when loading the file <br/><i>" + _msg.getData() + "</i>");
}
}
} else if (_msg.getMessage() == mainWindowsRequestSaveFileAs) { // return after a choice of close...
if (m_bufferManager->exist(_msg.getData()) == false) {
APPL_ERROR("Try to save an non-existant file :" << _msg.getData());
return;
}
appl::Buffer* tmpBuffer = m_bufferManager->get(_msg.getData());
if (tmpBuffer == NULL) {
APPL_ERROR("Error to get the buffer : " << _msg.getData());
return;
}
saveAsPopUp(tmpBuffer);
} else if (_msg.getMessage() == mainWindowsRequestcloseFileNoCheck) { // return after a choice of close...
if (m_bufferManager->exist(_msg.getData()) == false) {
APPL_ERROR("Try to save an non-existant file :" << _msg.getData());
return;
}
appl::Buffer* tmpBuffer = m_bufferManager->get(_msg.getData());
if (tmpBuffer == NULL) {
APPL_ERROR("Error to get the buffer : " << _msg.getData());
return;
}
// note: just remove ==> no check : normal case ...
tmpBuffer->removeObject();
}
return;
}
void MainWindows::OnObjectRemove(ewol::EObject * _removeObject)
{
ewol::Windows::OnObjectRemove(_removeObject);
void MainWindows::saveAsPopUp(appl::Buffer* _buffer) {
if (_buffer == NULL) {
APPL_ERROR("Call With NULL input...");
return;
}
appl::WorkerSaveFile* tmpObject = new appl::WorkerSaveFile(_buffer->getFileName());
}
void MainWindows::closeNotSavedFile(appl::Buffer* _buffer) {
if (_buffer == NULL) {
APPL_ERROR("Call With NULL input...");
return;
}
widget::StdPopUp* tmpPopUp = new widget::StdPopUp();
if (tmpPopUp == NULL) {
APPL_ERROR("Can not create a simple pop-up");
return;
}
tmpPopUp->setTitle("<bold>Close un-saved file:</bold>");
tmpPopUp->setComment("The file named : <i>\"" + _buffer->getFileName() + "\"</i> is curently modify. <br/>If you don't saves these modifications,<br/>they will be definitly lost...");
ewol::Widget* bt = NULL;
if (_buffer->hasFileName() == true) {
bt = tmpPopUp->addButton("Save", true);
if (bt != NULL) {
// TODO : The element is removed before beeing pressed
bt->registerOnEvent(this, widget::Button::eventPressed, mainWindowsRequestSaveFile, _buffer->getFileName());
bt->registerOnEvent(this, widget::Button::eventPressed, mainWindowsRequestcloseFileNoCheck, _buffer->getFileName());
}
}
bt = tmpPopUp->addButton("Save As", true);
if (bt != NULL) {
bt->registerOnEvent(this, widget::Button::eventPressed, mainWindowsRequestSaveFileAs, _buffer->getFileName());
//bt->registerOnEvent(this, widget::Button::eventPressed, mainWindowsRequestcloseFileNoCheck, _buffer->getFileName());
// TODO : Request the close when saved ...
}
bt = tmpPopUp->addButton("Close", true);
if (bt != NULL) {
bt->registerOnEvent(this, widget::Button::eventPressed, mainWindowsRequestcloseFileNoCheck, _buffer->getFileName());
}
tmpPopUp->addButton("Cancel", true);
tmpPopUp->setRemoveOnExternClick(true);
popUpWidgetPush(tmpPopUp);
}
void MainWindows::onObjectRemove(ewol::EObject* _removeObject) {
ewol::Windows::onObjectRemove(_removeObject);
if (m_widgetLabelFileName == _removeObject) {
m_widgetLabelFileName = NULL;
}

View File

@@ -9,16 +9,15 @@
#ifndef __MAIN_WINDOWS_H__
#define __MAIN_WINDOWS_H__
#include <appl/Debug.h>
#include <appl/debug.h>
#include <appl/globalMsg.h>
#include <CodeView.h>
#include <BufferView.h>
#include <BufferManager.h>
#include <appl/Gui/BufferView.h>
#include <appl/BufferManager.h>
#include <ewol/widget/Label.h>
#include <appl/BufferManager.h>
class MainWindows : public ewol::Windows
{
class MainWindows : public ewol::Windows {
private:
int32_t m_currentSavingAsIdBuffer;
widget::Label* m_widgetLabelFileName;
@@ -26,13 +25,23 @@ class MainWindows : public ewol::Windows
// Constructeur
MainWindows(void);
~MainWindows(void);
private:
appl::BufferManager* m_bufferManager; //!< handle on the buffer manager
/**
* @brief Display a pop-up to the select the name of the file.
* @param[in] _buffer Buffer that might be saved with a new name.
*/
void saveAsPopUp(appl::Buffer* _buffer);
/**
* @brief Display a pop-up to the user to confirm wat he want to do when he close a file not saved.
* @param[in] _buffer Buffer that might be close.
*/
void closeNotSavedFile(appl::Buffer* _buffer);
public: // Derived function
virtual const char * const GetObjectType(void) { return "MainWindows"; };
virtual void OnReceiveMessage(const ewol::EMessage& _msg);
virtual void OnObjectRemove(ewol::EObject * _removeObject);
virtual void onReceiveMessage(const ewol::EMessage& _msg);
virtual void onObjectRemove(ewol::EObject * _removeObject);
};
#define EDN_CAST_MAIN_WINDOWS(curentPointer) EWOL_CAST(TYPE_EOBJECT_EDN_MAIN_WINDOWS,MainWindows,curentPointer)
#endif

View File

@@ -7,15 +7,12 @@
*/
#include "appl/global.h"
#include "Search.h"
#include "SearchData.h"
#include "BufferManager.h"
#include "MainWindows.h"
#include "appl/Gui/Search.h"
#include "appl/BufferManager.h"
#include "appl/Gui/TextViewer.h"
#include "appl/Gui/MainWindows.h"
#include "appl/globalMsg.h"
#include <ewol/widget/Button.h>
#include <ewol/widget/Image.h>
#undef __class__
#define __class__ "Search"
@@ -32,248 +29,149 @@ const char* const l_eventForwardCb = "appl-forward-CheckBox";
const char* const l_eventHideBt = "appl-hide-button";
Search::Search(void) :
widget::Sizer(widget::Sizer::modeHori),
m_searchEntry(NULL),
m_replaceEntry(NULL)
{
m_forward = false;
// TODO : Change the mode of creating interface :
/*
<composer>
<sizer mode="hori" expand="true,false" fill="true" lock="true">
<button name="SEARCH:close">
<image src="THEME:GUI:Remove.svg" fill="true" size="70,70mm"/>
</button>
<entry name="SEARCH:search-entry" expand="true" fill="true"/>
<button name="SEARCH:search">
<image src="THEME:GUI:Search.svg" fill="true" size="70,70mm"/>
</button>
<entry name="SEARCH:replace-entry" expand="true" fill="true"/>
<button name="SEARCH:replace">
<image src="THEME:GUI:Replace.svg" fill="true" size="70,70mm"/>
</button>
<button name="SEARCH:case">
<image src="THEME:GUI:CaseSensitive.svg" fill="true" size="70,70mm" hover="Close search bar"/>
<image src="THEME:GUI:CaseSensitive.svg" fill="true" size="70,70mm" hover="Close search bar"/>
</button>
<button name="SEARCH:wrap">
<image src="THEME:GUI:WrapAround.svg" fill="true" size="70,70mm" hover="Close search bar"/>
<image src="THEME:GUI:WrapAround.svg" fill="true" size="70,70mm" hover="Close search bar"/>
</button>
<button name="SEARCH:up-down">
<image src="THEME:GUI:Up.svg" fill="true" size="70,70mm" hover="Close search bar"/>
<image src="THEME:GUI:Down.svg" fill="true" size="70,70mm" hover="Close search bar"/>
</button>
</size>
</composer>
*/
widget::Button * myButtonImage = NULL;
myButtonImage = new widget::Button();
if (NULL == myButtonImage) {
APPL_ERROR("Widget allocation error ==> it will missing in the display");
} else {
widget::Image* tmpImage = new widget::Image("THEME:GUI:Remove.svg");
tmpImage->SetImageSize(ewol::Dimension(vec2(8,8), ewol::Dimension::Millimeter));
myButtonImage->SetSubWidget(tmpImage);
myButtonImage->RegisterOnEvent(this, widget::Button::eventPressed, l_eventHideBt);
SubWidgetAdd(myButtonImage);
}
m_searchEntry = new widget::Entry();
if (NULL == m_searchEntry) {
APPL_ERROR("Widget allocation error ==> it will missing in the display");
} else {
m_searchEntry->RegisterOnEvent(this, widget::Entry::eventModify, l_eventSearchEntry);
m_searchEntry->RegisterOnEvent(this, widget::Entry::eventEnter, l_eventSearchEntryEnter);
m_searchEntry->SetExpand(bvec2(true,false));
m_searchEntry->SetFill(bvec2(true,false));
SubWidgetAdd(m_searchEntry);
}
myButtonImage = new widget::Button();
if (NULL == myButtonImage) {
APPL_ERROR("Widget allocation error ==> it will missing in the display");
} else {
widget::Image* tmpImage = new widget::Image("THEME:GUI:Search.svg");
tmpImage->SetImageSize(ewol::Dimension(vec2(8,8), ewol::Dimension::Millimeter));
myButtonImage->SetSubWidget(tmpImage);
myButtonImage->RegisterOnEvent(this, widget::Button::eventPressed, l_eventSearchBt);
SubWidgetAdd(myButtonImage);
}
m_replaceEntry = new widget::Entry();
if (NULL == m_replaceEntry) {
APPL_ERROR("Widget allocation error ==> it will missing in the display");
} else {
m_replaceEntry->RegisterOnEvent(this, widget::Entry::eventModify, l_eventReplaceEntry);
m_replaceEntry->RegisterOnEvent(this, widget::Entry::eventEnter, l_eventReplaceEntryEnter);
m_replaceEntry->SetExpand(bvec2(true,false));
m_replaceEntry->SetFill(bvec2(true,false));
SubWidgetAdd(m_replaceEntry);
}
myButtonImage = new widget::Button();
if (NULL == myButtonImage) {
APPL_ERROR("Widget allocation error ==> it will missing in the display");
} else {
widget::Image* tmpImage = new widget::Image("THEME:GUI:Replace.svg");
tmpImage->SetImageSize(ewol::Dimension(vec2(8,8), ewol::Dimension::Millimeter));
myButtonImage->SetSubWidget(tmpImage);
myButtonImage->RegisterOnEvent(this, widget::Button::eventPressed, l_eventReplaceBt);
SubWidgetAdd(myButtonImage);
}
myButtonImage = new widget::Button();
if (NULL == myButtonImage) {
APPL_ERROR("Widget allocation error ==> it will missing in the display");
} else {
myButtonImage->SetToggleMode(true);
widget::Image* tmpImage = new widget::Image("THEME:GUI:CaseSensitive.svg");
tmpImage->SetImageSize(ewol::Dimension(vec2(8,8), ewol::Dimension::Millimeter));
myButtonImage->SetSubWidget(tmpImage);
tmpImage = new widget::Image("THEME:GUI:CaseSensitive.svg"); // TODO : Set color on Image .... 0xFFFFFF5F
tmpImage->SetImageSize(ewol::Dimension(vec2(8,8), ewol::Dimension::Millimeter));
myButtonImage->SetSubWidgetToggle(tmpImage);
myButtonImage->SetValue(!SearchData::GetCase());
myButtonImage->RegisterOnEvent(this, widget::Button::eventPressed, l_eventCaseCb);
SubWidgetAdd(myButtonImage);
}
myButtonImage = new widget::Button();
if (NULL == myButtonImage) {
APPL_ERROR("Widget allocation error ==> it will missing in the display");
} else {
myButtonImage->SetToggleMode(true);
widget::Image* tmpImage = new widget::Image("THEME:GUI:WrapAround.svg");
tmpImage->SetImageSize(ewol::Dimension(vec2(8,8), ewol::Dimension::Millimeter));
myButtonImage->SetSubWidget(tmpImage);
tmpImage = new widget::Image("THEME:GUI:WrapAround.svg"); // TODO : Set color on Image .... 0xFFFFFF5F
tmpImage->SetImageSize(ewol::Dimension(vec2(8,8), ewol::Dimension::Millimeter));
myButtonImage->SetSubWidgetToggle(tmpImage);
myButtonImage->SetValue(!SearchData::GetWrap());
myButtonImage->RegisterOnEvent(this, widget::Button::eventPressed, l_eventWrapCb);
SubWidgetAdd(myButtonImage);
}
myButtonImage = new widget::Button();
if (NULL == myButtonImage) {
APPL_ERROR("Widget allocation error ==> it will missing in the display");
} else {
myButtonImage->SetToggleMode(true);
widget::Image* tmpImage = new widget::Image("THEME:GUI:Up.svg");
tmpImage->SetImageSize(ewol::Dimension(vec2(8,8), ewol::Dimension::Millimeter));
myButtonImage->SetSubWidget(tmpImage);
tmpImage = new widget::Image("THEME:GUI:Down.svg");
tmpImage->SetImageSize(ewol::Dimension(vec2(8,8), ewol::Dimension::Millimeter));
myButtonImage->SetSubWidgetToggle(tmpImage);
myButtonImage->SetValue(!m_forward);
myButtonImage->RegisterOnEvent(this, widget::Button::eventPressed, l_eventForwardCb);
SubWidgetAdd(myButtonImage);
}
RegisterMultiCast(ednMsgGuiSearch);
widget::Composer(widget::Composer::file, "DATA:GUI-Search.xml"),
m_viewerManager(NULL),
m_forward(true),
m_caseSensitive(false),
m_wrap(true),
m_searchEntry(NULL),
m_replaceEntry(NULL) {
addObjectType("appl::Search");
// load buffer manager:
m_viewerManager = appl::ViewerManager::keep();
// link event
registerOnEventNameWidget(this, "SEARCH:close", "pressed", l_eventHideBt);
registerOnEventNameWidget(this, "SEARCH:search-entry", "modify", l_eventSearchEntry);
registerOnEventNameWidget(this, "SEARCH:search-entry", "enter", l_eventSearchEntryEnter);
registerOnEventNameWidget(this, "SEARCH:search", "pressed", l_eventSearchBt);
registerOnEventNameWidget(this, "SEARCH:replace-entry", "modify", l_eventReplaceEntry);
registerOnEventNameWidget(this, "SEARCH:replace-entry", "enter", l_eventReplaceEntryEnter);
registerOnEventNameWidget(this, "SEARCH:replace", "pressed", l_eventReplaceBt);
registerOnEventNameWidget(this, "SEARCH:case", "value", l_eventCaseCb);
registerOnEventNameWidget(this, "SEARCH:wrap", "value", l_eventWrapCb);
registerOnEventNameWidget(this, "SEARCH:up-down", "value", l_eventForwardCb);
// set default properties
setConfigNamed("SEARCH:case", "value", std::to_string(m_caseSensitive));
setConfigNamed("SEARCH:wrap", "value", std::to_string(m_wrap));
setConfigNamed("SEARCH:up-down", "value", std::to_string(m_forward));
// get widget
m_searchEntry = dynamic_cast<widget::Entry*>(getWidgetNamed("SEARCH:search-entry"));
m_replaceEntry = dynamic_cast<widget::Entry*>(getWidgetNamed("SEARCH:replace-entry"));
// Display and hide event:
registerMultiCast(ednMsgGuiSearch);
// basicly hiden ...
Hide();
hide();
}
Search::~Search(void)
{
Search::~Search(void) {
appl::ViewerManager::release(m_viewerManager);
}
void Search::find(void) {
if (m_viewerManager == NULL) {
APPL_WARNING("No viewer manager selected!!!");
return;
}
appl::TextViewer* viewer = m_viewerManager->getViewerSelected();
if (viewer == NULL) {
APPL_INFO("No viewer selected!!!");
return;
}
viewer->unSelect();
appl::Buffer::Iterator resultStart;
appl::Buffer::Iterator resultStop;
if (m_forward == true) {
if (viewer->find(viewer->cursor(), m_searchData, resultStart, resultStop, m_caseSensitive) == false) {
if ( m_wrap == false
|| viewer->find(viewer->begin(), m_searchData, resultStart, resultStop, m_caseSensitive) == false) {
// TODO : Display an IHM pop-up
APPL_WARNING("No element find ...");
return;
}
}
viewer->select(resultStart, resultStop);
} else {
if (viewer->rfind(viewer->cursor(), m_searchData, resultStart, resultStop, m_caseSensitive) == false) {
if ( m_wrap == false
|| viewer->rfind(viewer->end(), m_searchData, resultStart, resultStop, m_caseSensitive) == false) {
// TODO : Display an IHM pop-up
APPL_WARNING("No element find ...");
return;
}
}
viewer->select(resultStop, resultStart);
}
}
void Search::replace(void) {
if (m_viewerManager == NULL) {
APPL_WARNING("No viewer manager selected!!!");
return;
}
appl::TextViewer* viewer = m_viewerManager->getViewerSelected();
if (viewer == NULL) {
APPL_INFO("No viewer selected!!!");
return;
}
if (viewer->hasTextSelected() == false) {
// nothing to replace ...
return;
}
viewer->replace(m_replaceData);
}
void Search::OnReceiveMessage(const ewol::EMessage& _msg)
{
widget::Sizer::OnReceiveMessage(_msg);
//APPL_INFO("Search receive message : \"" << eventId << "\" data=\"" << data << "\"");
if ( _msg.GetMessage() == l_eventSearchEntry) {
SearchData::SetSearch(_msg.GetData());
} else if ( _msg.GetMessage() == l_eventSearchEntryEnter) {
SearchData::SetSearch(_msg.GetData());
if (true==m_forward) {
SendMultiCast(ednMsgGuiFind, "Previous");
} else {
SendMultiCast(ednMsgGuiFind, "Next");
}
} else if ( _msg.GetMessage() == l_eventReplaceEntry) {
SearchData::SetReplace(_msg.GetData());
} else if ( _msg.GetMessage() == l_eventReplaceEntryEnter) {
SearchData::SetReplace(_msg.GetData());
SendMultiCast(ednMsgGuiReplace, "Normal");
if (true==m_forward) {
SendMultiCast(ednMsgGuiFind, "Previous");
} else {
SendMultiCast(ednMsgGuiFind, "Next");
}
} else if ( _msg.GetMessage() == l_eventSearchBt) {
if (true==m_forward) {
SendMultiCast(ednMsgGuiFind, "Previous");
} else {
SendMultiCast(ednMsgGuiFind, "Next");
}
} else if ( _msg.GetMessage() == l_eventReplaceBt) {
SendMultiCast(ednMsgGuiReplace, "Normal");
if (true==m_forward) {
SendMultiCast(ednMsgGuiFind, "Previous");
} else {
SendMultiCast(ednMsgGuiFind, "Next");
}
} else if ( _msg.GetMessage() == l_eventCaseCb) {
if (_msg.GetData() == "1") {
SearchData::SetCase(false);
} else {
SearchData::SetCase(true);
}
} else if ( _msg.GetMessage() == l_eventWrapCb) {
if (_msg.GetData() == "1") {
SearchData::SetWrap(false);
} else {
SearchData::SetWrap(true);
}
} else if ( _msg.GetMessage() == l_eventForwardCb) {
if (_msg.GetData() == "1") {
m_forward = false;
} else {
m_forward = true;
}
} else if ( _msg.GetMessage() == l_eventHideBt) {
Hide();
} else if ( _msg.GetMessage() == ednMsgGuiSearch) {
if (true == IsHide()) {
Show();
void Search::onReceiveMessage(const ewol::EMessage& _msg) {
widget::Composer::onReceiveMessage(_msg);
APPL_INFO("Search receive message : " << _msg);
if ( _msg.getMessage() == l_eventSearchEntry) {
m_searchData = to_u32string(_msg.getData());
} else if ( _msg.getMessage() == l_eventSearchEntryEnter
|| _msg.getMessage() == l_eventSearchBt) {
find();
} else if ( _msg.getMessage() == l_eventReplaceEntry) {
m_replaceData = to_u32string(_msg.getData());
} else if ( _msg.getMessage() == l_eventReplaceEntryEnter
|| _msg.getMessage() == l_eventReplaceBt) {
replace();
find();
} else if ( _msg.getMessage() == l_eventCaseCb) {
m_caseSensitive = stobool(_msg.getData());
} else if ( _msg.getMessage() == l_eventWrapCb) {
m_wrap = stobool(_msg.getData());
} else if ( _msg.getMessage() == l_eventForwardCb) {
m_forward = stobool(_msg.getData());
} else if ( _msg.getMessage() == l_eventHideBt) {
hide();
} else if ( _msg.getMessage() == ednMsgGuiSearch) {
if (true == isHide()) {
show();
if (m_searchEntry!= NULL) {
m_searchEntry->KeepFocus();
m_searchEntry->keepFocus();
}
} else {
if( (m_searchEntry!=NULL && true==m_searchEntry->GetFocus())
|| (m_replaceEntry!=NULL && true==m_replaceEntry->GetFocus()) ) {
Hide();
if( (m_searchEntry!=NULL && true == m_searchEntry->getFocus())
|| (m_replaceEntry!=NULL && true == m_replaceEntry->getFocus()) ) {
hide();
} else if (m_searchEntry!= NULL) {
m_searchEntry->KeepFocus();
m_searchEntry->keepFocus();
} else {
Hide();
hide();
}
}
}
}
void Search::OnObjectRemove(ewol::EObject * _removeObject)
{
widget::Sizer::OnObjectRemove(_removeObject);
void Search::onObjectRemove(ewol::EObject * _removeObject) {
widget::Composer::onObjectRemove(_removeObject);
if (_removeObject == m_searchEntry) {
m_searchEntry = NULL;
}
if (_removeObject == m_replaceEntry) {
m_replaceEntry = NULL;
}
if (_removeObject == m_viewerManager) {
m_viewerManager = NULL;
}
}

View File

@@ -9,24 +9,38 @@
#ifndef __SEARCH_H__
#define __SEARCH_H__
#include <appl/Debug.h>
#include <ewol/widget/Sizer.h>
#include <appl/debug.h>
#include <ewol/widget/Composer.h>
#include <ewol/widget/Entry.h>
#include <appl/Buffer.h>
#include <appl/Gui/ViewerManager.h>
class Search : public widget::Sizer
{
class Search : public widget::Composer {
private:
bool m_forward;
widget::Entry * m_searchEntry;
widget::Entry * m_replaceEntry;
appl::ViewerManager* m_viewerManager; //!< handle on the buffer manager
bool m_forward;
bool m_caseSensitive;
bool m_wrap;
widget::Entry* m_searchEntry;
widget::Entry* m_replaceEntry;
std::u32string m_searchData;
std::u32string m_replaceData;
public:
// Constructeur
Search(void);
~Search(void);
private:
/**
* @brief Find the next element that corespond at the search
*/
void find(void);
/**
* @brief Replace the current selected text.
*/
void replace(void);
public: // derived function
virtual const char * const GetObjectType(void) { return "ApplSearch"; };
virtual void OnReceiveMessage(const ewol::EMessage& _msg);
virtual void OnObjectRemove(ewol::EObject * _removeObject);
virtual void onReceiveMessage(const ewol::EMessage& _msg);
virtual void onObjectRemove(ewol::EObject * _removeObject);
};
#endif

View File

@@ -1,85 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/global.h>
#include <SearchData.h>
#undef __class__
#define __class__ "SearchData"
static etk::UString m_findRequest = "";
void SearchData::SetSearch(const etk::UString &myData)
{
m_findRequest = myData;
}
void SearchData::GetSearch(etk::UString &myData)
{
myData = m_findRequest;
}
bool SearchData::IsSearchEmpty(void)
{
if(m_findRequest.Size() > 0) {
return false;
}
return true;
}
static etk::UString m_replaceRequest = "";
void SearchData::SetReplace(const etk::UString &myData)
{
m_replaceRequest = myData;
}
void SearchData::GetReplace(etk::UString &myData)
{
myData = m_replaceRequest;
}
bool SearchData::IsReplaceEmpty(void)
{
if(m_replaceRequest.Size() > 0) {
return false;
}
return true;
}
static bool m_case = false;
void SearchData::SetCase(bool value)
{
m_case = value;
}
bool SearchData::GetCase(void)
{
return m_case;
}
static bool m_wrap = true;
void SearchData::SetWrap(bool value)
{
m_wrap = value;
}
bool SearchData::GetWrap(void)
{
return m_wrap;
}
static bool m_RegExp = false;
void SearchData::SetRegExp(bool value)
{
m_RegExp = value;
}
bool SearchData::GetRegExp(void)
{
return m_RegExp;
}

View File

@@ -1,32 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __SEARCH_DATA_H__
#define __SEARCH_DATA_H__
#include <etk/UString.h>
#include <appl/Debug.h>
namespace SearchData
{
void SetSearch(const etk::UString &myData);
void GetSearch(etk::UString &myData);
bool IsSearchEmpty(void);
void SetReplace(const etk::UString &myData);
void GetReplace(etk::UString &myData);
bool IsReplaceEmpty(void);
void SetCase(bool value);
bool GetCase(void);
void SetWrap(bool value);
bool GetWrap(void);
void SetRegExp(bool value);
bool GetRegExp(void);
}
#endif

View File

@@ -10,25 +10,23 @@
#include <appl/Gui/TagFileList.h>
#undef __class__
#define __class__ "TagFileList"
#define __class__ "TagFileList"
extern const char * const applEventCtagsListSelect = "appl-event-ctags-list-select";
extern const char * const applEventCtagsListUnSelect = "appl-event-ctags-list-un-select";
extern const char * const applEventCtagsListValidate = "appl-event-ctags-list-validate";
appl::TagFileList::TagFileList(void)
{
appl::TagFileList::TagFileList(void) {
addObjectType("appl::TagFileList");
m_selectedLine = -1;
AddEventId(applEventCtagsListSelect);
AddEventId(applEventCtagsListValidate);
SetMouseLimit(1);
addEventId(applEventCtagsListSelect);
addEventId(applEventCtagsListValidate);
setMouseLimit(1);
}
appl::TagFileList::~TagFileList(void)
{
for (int32_t iii=0; iii<m_list.Size(); iii++) {
appl::TagFileList::~TagFileList(void) {
for (int32_t iii=0; iii<m_list.size(); iii++) {
if (NULL != m_list[iii]) {
delete(m_list[iii]);
m_list[iii] = NULL;
@@ -36,82 +34,81 @@ appl::TagFileList::~TagFileList(void)
}
}
etk::Color<> appl::TagFileList::GetBasicBG(void) {
etk::Color<> appl::TagFileList::getBasicBG(void) {
return 0x00000010;
}
uint32_t appl::TagFileList::GetNuberOfColomn(void) {
uint32_t appl::TagFileList::getNuberOfColomn(void) {
return 2;
}
bool appl::TagFileList::GetTitle(int32_t colomn, etk::UString &myTitle, etk::Color<> &fg, etk::Color<> &bg) {
myTitle = "title";
bool appl::TagFileList::getTitle(int32_t _colomn, std::string& _myTitle, etk::Color<>& _fg, etk::Color<>& _bg) {
_myTitle = "title";
return true;
}
uint32_t appl::TagFileList::GetNuberOfRaw(void) {
return m_list.Size();
uint32_t appl::TagFileList::getNuberOfRaw(void) {
return m_list.size();
}
bool appl::TagFileList::GetElement(int32_t colomn, int32_t raw, etk::UString &myTextToWrite, etk::Color<> &fg, etk::Color<> &bg) {
if (raw >= 0 && raw < m_list.Size() && NULL != m_list[raw]) {
if (0==colomn) {
myTextToWrite = etk::UString(m_list[raw]->fileLine);
bool appl::TagFileList::getElement(int32_t _colomn, int32_t _raw, std::string& _myTextToWrite, etk::Color<>& _fg, etk::Color<>& _bg) {
if (_raw >= 0 && _raw < m_list.size() && NULL != m_list[_raw]) {
if (0 == _colomn) {
_myTextToWrite = std::to_string(m_list[_raw]->fileLine);
} else {
myTextToWrite = m_list[raw]->filename;
_myTextToWrite = m_list[_raw]->filename;
}
} else {
myTextToWrite = "ERROR";
_myTextToWrite = "ERROR";
}
fg = etk::color::black;
if (raw % 2) {
if (colomn%2==0) {
bg = 0xFFFFFF00;
_fg = etk::color::black;
if (_raw % 2) {
if (_colomn%2 == 0) {
_bg = 0xFFFFFF00;
} else {
bg = 0xFFFFFF10;
_bg = 0xFFFFFF10;
}
} else {
if (colomn%2==0) {
bg = 0xBFBFBFFF;
if (_colomn%2 == 0) {
_bg = 0xBFBFBFFF;
} else {
bg = 0xCFCFCFFF;
_bg = 0xCFCFCFFF;
}
}
if (m_selectedLine == raw) {
if (colomn%2==0) {
bg = 0x8F8FFFFF;
if (m_selectedLine == _raw) {
if (_colomn%2 == 0) {
_bg = 0x8F8FFFFF;
} else {
bg = 0x7F7FFFFF;
_bg = 0x7F7FFFFF;
}
}
return true;
};
bool appl::TagFileList::OnItemEvent(int32_t IdInput, ewol::keyEvent::status_te typeEvent, int32_t colomn, int32_t raw, float x, float y)
{
if (typeEvent == ewol::keyEvent::statusSingle) {
EWOL_INFO("Event on List : IdInput=" << IdInput << " colomn=" << colomn << " raw=" << raw );
if (1 == IdInput) {
bool appl::TagFileList::onItemEvent(int32_t _IdInput, enum ewol::keyEvent::status _typeEvent, int32_t _colomn, int32_t _raw, float _x, float _y) {
if (_typeEvent == ewol::keyEvent::statusSingle) {
EWOL_INFO("Event on List : IdInput=" << _IdInput << " colomn=" << _colomn << " raw=" << _raw );
if (_IdInput == 1) {
int32_t previousRaw = m_selectedLine;
if (raw > m_list.Size() ) {
if (_raw > m_list.size() ) {
m_selectedLine = -1;
} else {
m_selectedLine = raw;
m_selectedLine = _raw;
}
const char * event = applEventCtagsListValidate;
if (previousRaw != m_selectedLine) {
event = applEventCtagsListSelect;
}
if( m_selectedLine >=0
&& m_selectedLine < m_list.Size()
if( m_selectedLine >= 0
&& m_selectedLine < m_list.size()
&& NULL != m_list[m_selectedLine] ) {
GenerateEventId(event, etk::UString(m_list[raw]->fileLine)+":"+m_list[m_selectedLine]->filename);
generateEventId(event, std::to_string(m_list[_raw]->fileLine)+":"+m_list[m_selectedLine]->filename);
} else {
GenerateEventId(applEventCtagsListUnSelect);
generateEventId(applEventCtagsListUnSelect);
}
// need to regenerate the display of the list :
MarkToRedraw();
markToRedraw();
return true;
}
}
@@ -120,18 +117,16 @@ bool appl::TagFileList::OnItemEvent(int32_t IdInput, ewol::keyEvent::status_te t
/**
* @brief Add a Ctags item on the curent list
* @brief add a Ctags item on the curent list
* @param[in] file Compleate file name
* @param[in] jump line id
* @return ---
*/
void appl::TagFileList::Add(etk::UString& file, int32_t line)
{
appl::TagListElement *tmpFile = new appl::TagListElement(file, line);
void appl::TagFileList::add(std::string& _file, int32_t _line) {
appl::TagListElement *tmpFile = new appl::TagListElement(_file, _line);
if (NULL != tmpFile) {
m_list.PushBack(tmpFile);
m_list.push_back(tmpFile);
}
MarkToRedraw();
markToRedraw();
}

View File

@@ -9,7 +9,7 @@
#ifndef __APPL_CTAGS_LIST_H__
#define __APPL_CTAGS_LIST_H__
#include <appl/Debug.h>
#include <appl/debug.h>
#include <ewol/widget/List.h>
@@ -20,35 +20,38 @@ extern const char * const applEventCtagsListUnSelect;
namespace appl {
class TagListElement {
public:
etk::UString filename;
std::string filename;
int32_t fileLine;
TagListElement(etk::UString& file, int32_t line) : filename(file), fileLine(line) {};
~TagListElement(void) {};
TagListElement(std::string& _file, int32_t _line) :
filename(_file),
fileLine(_line) {
};
~TagListElement(void) {
};
};
class TagFileList : public widget::List
{
class TagFileList : public widget::List {
private:
int32_t m_selectedLine;
etk::Vector<appl::TagListElement*> m_list;
std::vector<appl::TagListElement*> m_list;
public:
TagFileList(void);
~TagFileList(void);
// display API :
virtual etk::Color<> GetBasicBG(void);
uint32_t GetNuberOfColomn(void);
bool GetTitle(int32_t colomn, etk::UString &myTitle, etk::Color<> &fg, etk::Color<> &bg);
uint32_t GetNuberOfRaw(void);
bool GetElement(int32_t colomn, int32_t raw, etk::UString &myTextToWrite, etk::Color<> &fg, etk::Color<> &bg);
bool OnItemEvent(int32_t IdInput, ewol::keyEvent::status_te typeEvent, int32_t colomn, int32_t raw, float x, float y);
// derived function
const char * const GetObjectType(void) { return "TagFileList"; };
virtual etk::Color<> getBasicBG(void);
uint32_t getNuberOfColomn(void);
bool getTitle(int32_t _colomn, std::string& _myTitle, etk::Color<>& _fg, etk::Color<>& _bg);
uint32_t getNuberOfRaw(void);
bool getElement(int32_t _colomn, int32_t _raw, std::string& _myTextToWrite, etk::Color<>& _fg, etk::Color<>& _bg);
bool onItemEvent(int32_t _IdInput, enum ewol::keyEvent::status _typeEvent, int32_t _colomn, int32_t _raw, float _x, float _y);
public:
/**
* @brief Add a Ctags item on the curent list
* @brief add a Ctags item on the curent list
* @param[in] file Compleate file name
* @param[in] jump line id
*/
void Add(etk::UString& file, int32_t line);
void add(std::string& _file, int32_t _line);
};
};

View File

@@ -12,7 +12,7 @@
#include <ewol/widget/Spacer.h>
#include <ewol/widget/Image.h>
#include <ewol/widget/WidgetManager.h>
#include <etk/Vector.h>
#include <vector>
#include <etk/tool.h>
#include <ewol/widget/Button.h>
#include <ewol/widget/Label.h>
@@ -23,17 +23,17 @@
#undef __class__
#define __class__ "TagFileSelection"
#define __class__ "TagFileSelection"
extern const char * const applEventctagsSelection = "appl-event-ctags-validate";
extern const char * const applEventctagsCancel = "appl-event-ctags-cancel";
extern const char * const applEventctagsSelection = "appl-event-ctags-validate";
extern const char * const applEventctagsCancel = "appl-event-ctags-cancel";
appl::TagFileSelection::TagFileSelection(void)
{
AddEventId(applEventctagsSelection);
AddEventId(applEventctagsCancel);
appl::TagFileSelection::TagFileSelection(void) {
addObjectType("appl::TagFileSelection");
addEventId(applEventctagsSelection);
addEventId(applEventctagsCancel);
widget::Label* myWidgetTitle = NULL;
widget::Button* myWidgetValidate = NULL;
@@ -43,135 +43,109 @@ appl::TagFileSelection::TagFileSelection(void)
widget::Sizer * mySizerHori = NULL;
widget::Spacer * mySpacer = NULL;
#if defined(__TARGET_OS__Android)
SetMinSize(ewol::Dimension(vec2(90,90),ewol::Dimension::Pourcent));
setMinSize(ewol::Dimension(vec2(90,90),ewol::Dimension::Pourcent));
#elif defined(__TARGET_OS__Windows)
SetMinSize(ewol::Dimension(vec2(80,80),ewol::Dimension::Pourcent));
setMinSize(ewol::Dimension(vec2(80,80),ewol::Dimension::Pourcent));
#else
SetMinSize(ewol::Dimension(vec2(80,80),ewol::Dimension::Pourcent));
setMinSize(ewol::Dimension(vec2(80,80),ewol::Dimension::Pourcent));
#endif
mySizerVert = new widget::Sizer(widget::Sizer::modeVert);
if (NULL == mySizerVert) {
EWOL_ERROR("Can not allocate widget ==> display might be in error");
EWOL_ERROR("Can not allocate widget == > display might be in error");
} else {
mySizerVert->LockExpand(bvec2(true,true));
mySizerVert->lockExpand(bvec2(true,true));
mySizerVert->setExpand(bvec2(true,true));
// set it in the pop-up-system :
SetSubWidget(mySizerVert);
mySizerHori = new widget::Sizer(widget::Sizer::modeHori);
if (NULL == mySizerHori) {
EWOL_ERROR("Can not allocate widget ==> display might be in error");
} else {
mySizerVert->SubWidgetAdd(mySizerHori);
mySpacer = new widget::Spacer();
if (NULL == mySpacer) {
EWOL_ERROR("Can not allocate widget ==> display might be in error");
} else {
mySpacer->SetExpand(bvec2(true,false));
mySizerHori->SubWidgetAdd(mySpacer);
}
myWidgetValidate = new widget::Button();
if (NULL == myWidgetValidate) {
EWOL_ERROR("Can not allocate widget ==> display might be in error");
} else {
myWidgetValidate->SetSubWidget(
new widget::Composer(widget::Composer::String,
"<composer>\n"
" <sizer mode=\"hori\">\n"
" <image src=\"THEME:GUI:icon/Load.svg\" fill=\"true\" size=\"70,70mm\"/>\n"
" <label>Jump</label>\n"
" </sizer>\n"
"</composer\n"));
myWidgetValidate->RegisterOnEvent(this, widget::Button::eventPressed, applEventctagsSelection);
mySizerHori->SubWidgetAdd(myWidgetValidate);
}
myWidgetCancel = new widget::Button();
if (NULL == myWidgetCancel) {
EWOL_ERROR("Can not allocate widget ==> display might be in error");
} else {
myWidgetCancel->SetSubWidget(
new widget::Composer(widget::Composer::String,
"<composer>\n"
" <sizer mode=\"hori\">\n"
" <image src=\"THEME:GUI:icon/Remove.svg\" fill=\"true\" size=\"70,70mm\"/>\n"
" <label>Cancel</label>\n"
" </sizer>\n"
"</composer\n"));
myWidgetCancel->RegisterOnEvent(this, widget::Button::eventPressed, applEventctagsCancel);
mySizerHori->SubWidgetAdd(myWidgetCancel);
}
}
setSubWidget(mySizerVert);
widget::Composer* compose = new widget::Composer(widget::Composer::String,
"<sizer mode=\"hori\" expand=\"true,false\" lock=\"false,true\">\n"
" <spacer expand=\"true,false\"/>\n"
" <button name=\"PLUGIN-CTAGS-jump\" expand=\"false\" fill=\"true\">"
" <sizer mode=\"hori\">\n"
" <image src=\"THEME:GUI:Load.svg\" fill=\"true\" size=\"10,10mm\"/>\n"
" <label>Jump</label>\n"
" </sizer>\n"
" </button>\n"
" <button name=\"PLUGIN-CTAGS-cancel\" expand=\"false\" fill=\"true\">"
" <sizer mode=\"hori\">\n"
" <image src=\"THEME:GUI:Remove.svg\" fill=\"true\" size=\"10,10mm\"/>\n"
" <label>Cancel</label>\n"
" </sizer>\n"
" </button>\n"
"</sizer>\n");
compose->setExpand(bvec2(true,false));
compose->setFill(bvec2(true,true));
mySizerVert->subWidgetAdd(compose);
compose->registerOnEventNameWidget(this, "PLUGIN-CTAGS-jump", "pressed", applEventctagsSelection);
compose->registerOnEventNameWidget(this, "PLUGIN-CTAGS-cancel", "pressed", applEventctagsCancel);
m_listTag = new appl::TagFileList();
if (NULL == m_listTag) {
EWOL_ERROR("Can not allocate widget ==> display might be in error");
EWOL_ERROR("Can not allocate widget == > display might be in error");
} else {
m_listTag->RegisterOnEvent(this, applEventCtagsListValidate);
m_listTag->RegisterOnEvent(this, applEventCtagsListSelect);
m_listTag->RegisterOnEvent(this, applEventCtagsListUnSelect);
m_listTag->SetExpand(bvec2(true,true));
m_listTag->SetFill(bvec2(true,true));
mySizerVert->SubWidgetAdd(m_listTag);
m_listTag->registerOnEvent(this, applEventCtagsListValidate);
m_listTag->registerOnEvent(this, applEventCtagsListSelect);
m_listTag->registerOnEvent(this, applEventCtagsListUnSelect);
m_listTag->setExpand(bvec2(true,true));
m_listTag->setFill(bvec2(true,true));
mySizerVert->subWidgetAdd(m_listTag);
}
myWidgetTitle = new widget::Label("Ctags Jump Selection ...");
if (NULL == myWidgetTitle) {
EWOL_ERROR("Can not allocate widget ==> display might be in error");
EWOL_ERROR("Can not allocate widget == > display might be in error");
} else {
mySizerVert->SubWidgetAdd(myWidgetTitle);
mySizerVert->subWidgetAdd(myWidgetTitle);
}
}
}
appl::TagFileSelection::~TagFileSelection(void)
{
appl::TagFileSelection::~TagFileSelection(void) {
}
void appl::TagFileSelection::OnReceiveMessage(const ewol::EMessage& _msg)
{
EWOL_INFO("ctags LIST ... : \"" << _msg.GetMessage() << "\" ==> data=\"" << _msg.GetData() << "\"" );
if (_msg.GetMessage() == applEventctagsSelection) {
void appl::TagFileSelection::onReceiveMessage(const ewol::EMessage& _msg) {
EWOL_INFO("ctags LIST ... : " << _msg );
if (_msg.getMessage() == applEventctagsSelection) {
if (m_eventNamed!="") {
GenerateEventId(applEventctagsSelection, m_eventNamed);
//==> Auto remove ...
AutoDestroy();
generateEventId(applEventctagsSelection, m_eventNamed);
// == > Auto remove ...
autoDestroy();
}
} else if (_msg.GetMessage() == applEventCtagsListSelect) {
m_eventNamed = _msg.GetData();
} else if (_msg.getMessage() == applEventCtagsListSelect) {
m_eventNamed = _msg.getData();
} else if (_msg.GetMessage() == applEventCtagsListUnSelect) {
} else if (_msg.getMessage() == applEventCtagsListUnSelect) {
m_eventNamed = "";
} else if (_msg.GetMessage() == applEventCtagsListValidate) {
GenerateEventId(applEventctagsSelection, _msg.GetData());
//==> Auto remove ...
AutoDestroy();
} else if (_msg.GetMessage() == applEventctagsCancel) {
GenerateEventId(applEventctagsCancel, "");
//==> Auto remove ...
AutoDestroy();
} else if (_msg.getMessage() == applEventCtagsListValidate) {
generateEventId(applEventctagsSelection, _msg.getData());
// == > Auto remove ...
autoDestroy();
} else if (_msg.getMessage() == applEventctagsCancel) {
generateEventId(applEventctagsCancel, "");
// == > Auto remove ...
autoDestroy();
}
return;
};
/**
* @brief Add a Ctags item on the curent list
* @brief add a Ctags item on the curent list
* @param[in] file Compleate file name
* @param[in] jump line id
*/
void appl::TagFileSelection::AddCtagsNewItem(etk::UString file, int32_t line)
{
void appl::TagFileSelection::addCtagsNewItem(std::string _file, int32_t _line) {
if (NULL != m_listTag) {
m_listTag->Add(file, line);
m_listTag->add(_file, _line);
}
}
void appl::TagFileSelection::OnObjectRemove(ewol::EObject * _removeObject)
{
void appl::TagFileSelection::onObjectRemove(ewol::EObject * _removeObject) {
// First step call parrent :
widget::PopUp::OnObjectRemove(_removeObject);
widget::PopUp::onObjectRemove(_removeObject);
// second step find if in all the elements ...
if(_removeObject == m_listTag) {
m_listTag = NULL;

View File

@@ -9,7 +9,7 @@
#ifndef __APPL_CTAGS_SELECTION_H__
#define __APPL_CTAGS_SELECTION_H__
#include <appl/Debug.h>
#include <appl/debug.h>
#include <ewol/widget/PopUp.h>
#include <appl/Gui/TagFileList.h>
@@ -17,24 +17,22 @@ extern const char * const applEventctagsSelection;
extern const char * const applEventctagsCancel;
namespace appl {
class TagFileSelection : public widget::PopUp
{
class TagFileSelection : public widget::PopUp {
private:
appl::TagFileList* m_listTag;
etk::UString m_eventNamed;
appl::TagFileList* m_listTag;
std::string m_eventNamed;
public:
TagFileSelection(void);
virtual ~TagFileSelection(void);
/**
* @brief Add a Ctags item on the curent list
* @brief add a Ctags item on the curent list
* @param[in] file Compleate file name
* @param[in] jump line id
*/
void AddCtagsNewItem(etk::UString file, int32_t line);
void addCtagsNewItem(std::string file, int32_t line);
public: // herited function
const char * const GetObjectType(void) { return "EwolFileChooser"; };
void OnReceiveMessage(const ewol::EMessage& _msg);
void OnObjectRemove(ewol::EObject * _removeObject);
void onReceiveMessage(const ewol::EMessage& _msg);
void onObjectRemove(ewol::EObject * _removeObject);
};
};

View File

@@ -0,0 +1,976 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/debug.h>
#include <appl/global.h>
#include <appl/Gui/TextViewer.h>
#include <appl/BufferManager.h>
#include <ewol/clipBoard.h>
#include <ewol/widget/WidgetManager.h>
#include <appl/Gui/ViewerManager.h>
#include <ewol/renderer/EObject.h>
#include <appl/TextPluginManager.h>
#undef __class__
#define __class__ "TextViewer"
#define tic() \
int64_t startTime = ewol::getTime();
#define toc(comment) \
int64_t endTime = ewol::getTime(); \
int64_t processTimeLocal = (endTime - startTime); \
APPL_DEBUG(comment << (float)((float)processTimeLocal / 1000.0) << "ms");
appl::TextViewer::TextViewer(const std::string& _fontName, int32_t _fontSize) :
m_buffer(NULL),
m_displayText(_fontName, _fontSize),
m_insertMode(false) {
addObjectType("appl::TextViewer");
setCanHaveFocus(true);
registerMultiCast(ednMsgBufferId);
registerMultiCast(ednMsgGuiFind);
registerMultiCast(ednMsgGuiReplace);
registerMultiCast(appl::MsgSelectGotoLine);
registerMultiCast(appl::MsgSelectNewFile);
registerMultiCast(appl::MsgSelectGotoLineSelect);
setLimitScrolling(0.2);
// load buffer manager:
m_bufferManager = appl::BufferManager::keep();
m_viewerManager = appl::ViewerManager::keep();
// load color properties
m_paintingProperties = appl::GlyphPainting::keep("THEME:COLOR:textViewer.json");
// get all id properties ...
m_colorBackground = m_paintingProperties->request("CODE_basicBackgroung");
m_colorSpace = m_paintingProperties->request("CODE_space");
m_colorTabulation = m_paintingProperties->request("CODE_tabulation");
m_colorCursor = m_paintingProperties->request("CODE_cursor");
m_colorLineNumber = m_paintingProperties->request("CODE_lineNumber");
m_colorSelection = m_paintingProperties->request("SelectedText");
m_colorNormal = m_paintingProperties->request("normal");
appl::textPluginManager::connect(*this);
// last created has focus ...
setCurrentSelect();
}
appl::TextViewer::~TextViewer(void) {
appl::textPluginManager::disconnect(*this);
appl::GlyphPainting::release(m_paintingProperties);
appl::BufferManager::release(m_bufferManager);
appl::ViewerManager::release(m_viewerManager);
}
bool appl::TextViewer::calculateMinSize(void) {
m_minSize.setValue(50,50);
return true;
}
void appl::TextViewer::onDraw(void) {
m_displayDrawing.draw();
m_displayText.draw();
WidgetScrooled::onDraw();
}
void appl::TextViewer::onRegenerateDisplay(void) {
if (false == needRedraw()) {
return;
}
//tic();
// For the scrooling windows
m_displayDrawing.clear();
m_displayText.clear();
// reset the background :
m_displayDrawing.setPos(vec3(0, 0, 0));
m_displayDrawing.setColor((*m_paintingProperties)[m_colorBackground].getForeground());
m_displayDrawing.rectangleWidth(m_size);
if (m_buffer == NULL) {
m_maxSize.setX(256);
m_maxSize.setY(256);
m_displayText.setTextAlignement(10, m_size.x()-20, ewol::Text::alignLeft);
m_displayText.setRelPos(vec3(10, 0, 0));
std::string tmpString("<br/>\n"
"<font color=\"red\">\n"
" <b>\n"
" edn - Editeur De N'ours\n"
" </b>\n"
"</font>\n"
"<br/>\n"
"<br/>\n"
"<font color=\"indigo\">\n"
" <i>\n"
" No Buffer Availlable to display\n"
" </i>\n"
"</font>\n");
m_displayText.setPos(vec3(0.0f, m_size.y(), 0.0f) );
m_displayText.forceLineReturn();
m_displayText.printDecorated(tmpString);
// call the herited class...
WidgetScrooled::onRegenerateDisplay();
return;
}
// normal displa of the buffer :
vec3 tmpCursorPosition(0, 0, -1);
float tmpCursorLenght = -1.0;
// real display ...
etk::Buffer& buf = m_buffer->getData();
m_displayText.setColor(etk::Color<>(0, 0, 0, 256));
float countNbLine = 1;
int32_t countColomn = 0;
// the siplay string :
std::u32string stringToDisplay;
int64_t bufferElementSize = 0;
bool isSelect = false;
appl::Buffer::Iterator selectPosStart = m_buffer->begin();
appl::Buffer::Iterator selectPosStop = m_buffer->begin();
if (m_buffer->hasTextSelected() == true) {
selectPosStart = m_buffer->selectStart();
selectPosStop = m_buffer->selectStop();
}
m_displayText.setPos(vec3(-m_originScrooled.x(), m_size.y()+m_originScrooled.y(), 0));
m_displayText.forceLineReturn();
appl::Buffer::Iterator startingIt = m_buffer->begin();
int64_t startLineId = 0;
if (m_size.y() < m_displayText.getPos().y()) {
for (startingIt = m_buffer->begin();
(bool)startingIt == true;
++startingIt) {
if (*startingIt == etk::UChar::Return) {
++startLineId;
m_displayText.forceLineReturn();
if (m_size.y() >= m_displayText.getPos().y()) {
++startingIt;
break;
}
}
}
}
// Display line number :
m_lastOffsetDisplay = 0;
vec3 tmpLetterSize = m_displayText.calculateSize((char32_t)'A');
{
int32_t nbLine = m_buffer->getNumberOfLines();
float nbLineCalc = nbLine;
int32_t nbChar = 0;
while (nbLineCalc >= 1.0f) {
++nbChar;
nbLineCalc /= 10.0f;
}
m_lastOffsetDisplay = tmpLetterSize.x() * (float)nbChar + 1.0f;
m_displayText.setFontItalic((*m_paintingProperties)[m_colorLineNumber].getItalic());
m_displayText.setFontBold((*m_paintingProperties)[m_colorLineNumber].getBold());
m_displayText.setColorBg((*m_paintingProperties)[m_colorLineNumber].getBackground());
m_displayText.setColor((*m_paintingProperties)[m_colorLineNumber].getForeground());
m_displayText.setClippingMode(false);
vec3 startWriteRealPosition = m_displayText.getPos();
m_displayText.setPos(vec3(0.0f, startWriteRealPosition.y(), 0.0f));
for (int32_t iii=startLineId;
iii<nbLine;
++iii) {
char tmpLineNumber[50];
sprintf(tmpLineNumber, "%*d", nbChar, iii+1);
m_displayText.print(tmpLineNumber);
m_displayText.forceLineReturn();
if (m_displayText.getPos().y() < -20.0f ) {
break;
}
}
m_displayText.setPos(vec3(-m_originScrooled.x()+m_lastOffsetDisplay, startWriteRealPosition.y(), 0.0f));
m_displayText.setClipping(vec2(m_lastOffsetDisplay, 0), m_size);
}
appl::DisplayHLData displayLocalSyntax;
m_buffer->hightlightGenerateLines(displayLocalSyntax, (int64_t)startingIt, m_size.y());
float maxSizeX = 0;
appl::HighlightInfo * HLColor = NULL;
bool DisplayCursorAndSelection = isSelectedLast();
appl::Buffer::Iterator it;
for (it = startingIt;
(bool)it == true;
++it) {
if (it == m_buffer->cursor()) {
// need to display the cursor :
tmpCursorPosition = m_displayText.getPos();
tmpCursorLenght = 0.0f;
}
//APPL_DEBUG("display element '" << currentValue << "'at pos : " << m_displayText.getPos() );
//APPL_DEBUG(" element size : " << iii << " : " << bufferElementSize);
if (*it == etk::UChar::Return) {
countNbLine += 1;
countColomn = 0;
maxSizeX = etk_max(m_displayText.getPos().x(), maxSizeX);
// Display the end line position only if we have the focus ...
if (DisplayCursorAndSelection == true) {
if (it >= selectPosStart && it < selectPosStop) {
ewol::Drawing& draw = m_displayText.getDrawing();
draw.setColor(etk::Color<>(0xFF0000FF));
draw.setPos(m_displayText.getPos() + tmpLetterSize/4.0f);
draw.rectangle(m_displayText.getPos() + tmpLetterSize*3.0f/4.0f);
}
}
if (tmpCursorLenght == 0.0f) {
tmpCursorLenght = tmpLetterSize.x();
}
m_displayText.forceLineReturn();
m_displayText.setPos(vec3(-m_originScrooled.x()+m_lastOffsetDisplay, m_displayText.getPos().y(), 0.0f));
if (m_displayText.getPos().y() < -20.0f ) {
break;
}
continue;
}
HLColor = m_buffer->getElementColorAtPosition(displayLocalSyntax, (int64_t)it);
bool haveBackground = false;
if ( HLColor != NULL
&& HLColor->patern != NULL) {
m_displayText.setColor(HLColor->patern->getColorGlyph().getForeground());
m_displayText.setColorBg(HLColor->patern->getColorGlyph().getBackground());
haveBackground = HLColor->patern->getColorGlyph().haveBackground();
m_displayText.setFontItalic(HLColor->patern->getColorGlyph().getItalic());
m_displayText.setFontBold(HLColor->patern->getColorGlyph().getBold());
} else {
m_displayText.setFontItalic((*m_paintingProperties)[m_colorNormal].getItalic());
m_displayText.setFontBold((*m_paintingProperties)[m_colorNormal].getBold());
m_displayText.setColorBg((*m_paintingProperties)[m_colorNormal].getBackground());
m_displayText.setColor((*m_paintingProperties)[m_colorNormal].getForeground());
}
if (haveBackground == false) {
if (*it == etk::UChar::Space) {
m_displayText.setColorBg((*m_paintingProperties)[m_colorSpace].getForeground());
} else if (*it == etk::UChar::Tabulation) {
m_displayText.setColorBg((*m_paintingProperties)[m_colorTabulation].getForeground());
}
}
m_buffer->expand(countColomn, *it, stringToDisplay);
// Display selection only if we have the focus ...
if (DisplayCursorAndSelection == true) {
if (it >= selectPosStart && it < selectPosStop) {
m_displayText.setColor((*m_paintingProperties)[m_colorSelection].getForeground());
m_displayText.setColorBg((*m_paintingProperties)[m_colorSelection].getBackground());
}
}
//APPL_DEBUG("display : '" << currentValue << "' == > '" << stringToDisplay << "'");
m_displayText.print(stringToDisplay);
if (tmpCursorLenght == 0.0f) {
tmpCursorLenght = m_displayText.getPos().x()-tmpCursorPosition.x();
}
countColomn += stringToDisplay.size();
}
if (it == m_buffer->cursor()) {
tmpCursorPosition = m_displayText.getPos();
tmpCursorLenght = 5;
}
maxSizeX = etk_max(m_displayText.getPos().x(), maxSizeX);
// Display cursor only if we have the focus ...
if ( tmpCursorPosition.z() != -1
&& getFocus() == true) {
// display the cursor:
//APPL_DEBUG("display cursor at position : " << tmpCursorPosition);
m_displayText.setPos(tmpCursorPosition);
if (m_buffer->hasTextSelected() == true) {
m_displayText.setColorBg((*m_paintingProperties)[m_colorCursor].getForeground());
m_displayText.printCursor(false);
} else {
if (m_insertMode == true) {
m_displayText.setColorBg((*m_paintingProperties)[m_colorSelection].getBackground());
} else {
m_displayText.setColorBg((*m_paintingProperties)[m_colorCursor].getForeground());
}
m_displayText.printCursor(m_insertMode, tmpCursorLenght);
}
}
// set maximum size (X&Y) :
{
vec3 tmpLetterSize = m_displayText.calculateSize((char32_t)'A');
int64_t nbLines = m_buffer->getNumberOfLines();
m_maxSize.setX(maxSizeX+m_originScrooled.x());
m_maxSize.setY((float)nbLines*tmpLetterSize.y());
}
//toc("Display time : ");
// call the herited class...
WidgetScrooled::onRegenerateDisplay();
}
bool appl::TextViewer::onEventEntry(const ewol::EventEntry& _event) {
if (m_buffer == NULL) {
return false;
}
// First call plugin
if (appl::textPluginManager::onEventEntry(*this, _event) == true) {
markToRedraw();
return true;
}
// just forward event == > manage directly in the buffer
if (_event.getType() == ewol::keyEvent::keyboardChar) {
//APPL_DEBUG("KB EVENT : \"" << UTF8_data << "\" size=" << strlen(UTF8_data) << "type=" << (int32_t)typeEvent);
if (_event.getStatus() != ewol::keyEvent::statusDown) {
return false;
}
char32_t localValue = _event.getChar();
if (localValue == etk::UChar::Return) {
if (true == _event.getSpecialKey().isSetShift()) {
localValue = etk::UChar::CarrierReturn;
}
} else if (localValue == etk::UChar::Suppress ) {
//APPL_INFO("keyEvent : <suppr> pos=" << m_cursorPos);
if (m_buffer->hasTextSelected()) {
remove();
} else {
appl::Buffer::Iterator pos = m_buffer->cursor();
appl::Buffer::Iterator posEnd = pos;
++posEnd;
replace("", pos, posEnd);
}
return true;
} else if (localValue == etk::UChar::Delete) {
//APPL_INFO("keyEvent : <del> pos=" << m_cursorPos);
if (m_buffer->hasTextSelected()) {
remove();
} else {
appl::Buffer::Iterator pos = m_buffer->cursor();
appl::Buffer::Iterator posEnd = pos;
--pos;
replace("", pos, posEnd);
}
return true;
}
m_buffer->setSelectMode(false);
// normal adding char ...
char output[5];
int32_t nbElement = etk::getUtf8(localValue, output);
if ( m_buffer->hasTextSelected() == false
&& _event.getSpecialKey().isSetInsert() == true) {
appl::Buffer::Iterator pos = m_buffer->cursor();
appl::Buffer::Iterator posEnd = pos;
++posEnd;
replace(output, pos, posEnd);
//TODO : choisce UTF ... replace(localValue, pos, posEnd);
} else {
std::string myString = output;
write(myString);
}
return true;
}
// move events ...
if (_event.getStatus() == ewol::keyEvent::statusDown) {
bool needUpdatePosition = true;
// selection when shift is set:
m_buffer->setSelectMode(_event.getSpecialKey().isSetShift());
// check selection event ...
switch(_event.getType()) {
case ewol::keyEvent::keyboardInsert:
m_insertMode = m_insertMode==true?false:true;
markToRedraw();
break;
case ewol::keyEvent::keyboardLeft:
//APPL_INFO("keyEvent : <LEFT>");
moveCursorLeft();
break;
case ewol::keyEvent::keyboardRight:
//APPL_INFO("keyEvent : <RIGHT>");
moveCursorRight();
break;
case ewol::keyEvent::keyboardUp:
//APPL_INFO("keyEvent : <UP>");
moveCursorUp(1);
break;
case ewol::keyEvent::keyboardDown:
//APPL_INFO("keyEvent : <DOWN>");
moveCursorDown(1);
break;
case ewol::keyEvent::keyboardPageUp:
//APPL_INFO("keyEvent : <PAGE-UP>");
moveCursorUp(15); // TODO : Set the real number of line ...
break;
case ewol::keyEvent::keyboardPageDown:
//APPL_INFO("keyEvent : <PAGE-DOWN>");
moveCursorDown(15); // TODO : Set the real number of line ...
break;
case ewol::keyEvent::keyboardStart:
//APPL_INFO("keyEvent : <Start of line>");
moveCursorLeft(moveEnd);
break;
case ewol::keyEvent::keyboardEnd:
//APPL_INFO("keyEvent : <End of line>");
moveCursorRight(moveEnd);
break;
default:
break;
}
return true;
}
return false;
}
bool appl::TextViewer::onEventInput(const ewol::EventInput& _event) {
if (_event.getId() != 0) {
keepFocus();
}
//tic();
if (m_buffer == NULL) {
return false;
}
// First call the scrolling widget :
if (WidgetScrooled::onEventInput(_event) == true) {
markToRedraw();
return true;
}
// Second call plugin
if (appl::textPluginManager::onEventInput(*this, _event) == true) {
markToRedraw();
return true;
}
vec2 relativePos = relativePosition(_event.getPos());
// offset for the lineNumber:
relativePos -= vec2(m_lastOffsetDisplay, 0);
// offset for the scrolling:
relativePos += vec2(m_originScrooled.x(), -m_originScrooled.y());
// invert for the buffer event ...
relativePos.setY(m_size.y()-relativePos.y());
if (relativePos.x()<0) {
relativePos.setX(0);
}
if ( _event.getId() == 12
&& _event.getStatus() == ewol::keyEvent::statusSingle) {
APPL_DEBUG("kjhkjhkjh");
// Rat5 save event
sendMultiCast(ednMsgGuiSave, "current");
return true;
}
// just forward event == > manage directly in the buffer
if (_event.getId() == 1) {
// mouse selection :
if (_event.getType() == ewol::keyEvent::typeMouse) {
if (_event.getStatus() == ewol::keyEvent::statusDown) {
//if (_event.getSpecialKey().isSetShift() == false) {
appl::Buffer::Iterator newPos = getMousePosition(relativePos);
moveCursor(newPos);
m_buffer->setSelectMode(true);
markToRedraw();
return true;
//}
} else if (_event.getStatus() == ewol::keyEvent::statusUp) {
appl::Buffer::Iterator newPos = getMousePosition(relativePos);
moveCursor(newPos);
m_buffer->setSelectMode(false);
// Copy selection :
std::string value;
m_buffer->copy(value);
if (value.size() != 0) {
ewol::clipBoard::set(ewol::clipBoard::clipboardSelection, value);
}
markToRedraw();
return true;
}
}
if (_event.getStatus() == ewol::keyEvent::statusSingle) {
if (_event.getType() == ewol::keyEvent::typeMouse) {
appl::Buffer::Iterator newPos = getMousePosition(relativePos);
moveCursor(newPos);
markToRedraw();
return true;
}
} else if (_event.getStatus() == ewol::keyEvent::statusDouble) {
mouseEventDouble();
// Copy selection :
std::string value;
m_buffer->copy(value);
if (value.size() != 0) {
ewol::clipBoard::set(ewol::clipBoard::clipboardSelection, value);
}
markToRedraw();
return true;
} else if (_event.getStatus() == ewol::keyEvent::statusTriple) {
mouseEventTriple();
// Copy selection :
std::string value;
m_buffer->copy(value);
if (value.size() != 0) {
ewol::clipBoard::set(ewol::clipBoard::clipboardSelection, value);
}
markToRedraw();
return true;
} else if (_event.getStatus() == ewol::keyEvent::statusMove) {
if (m_buffer->getSelectMode() == true) {
appl::Buffer::Iterator newPos = getMousePosition(relativePos);
moveCursor(newPos);
markToRedraw();
return true;
}
}
} else if (2 == _event.getId()) {
if (ewol::keyEvent::statusSingle == _event.getStatus()) {
appl::Buffer::Iterator newPos = getMousePosition(relativePos);
moveCursor(newPos);
ewol::clipBoard::request(ewol::clipBoard::clipboardSelection);
markToRedraw();
return true;
}
}
return false;
}
void appl::TextViewer::mouseEventDouble(void) {
//m_selectMode = false;
appl::Buffer::Iterator beginPos, endPos;
if (true == m_buffer->getPosAround(m_buffer->cursor(), beginPos, endPos)) {
moveCursor(endPos);
m_buffer->setSelectionPos(beginPos);
}
}
void appl::TextViewer::mouseEventTriple(void) {
//m_selectMode = false;
moveCursor(m_buffer->getEndLine(m_buffer->cursor()));
m_buffer->setSelectionPos(m_buffer->getStartLine(m_buffer->cursor()));
}
appl::Buffer::Iterator appl::TextViewer::getMousePosition(const vec2& _relativePos) {
char32_t currentValue;
vec3 positionCurentDisplay(0,0,0);
vec3 tmpLetterSize = m_displayText.calculateSize((char32_t)'A');
int32_t countColomn = 0;
std::u32string stringToDisplay;
m_displayText.clear();
m_displayText.forceLineReturn();
positionCurentDisplay = m_displayText.getPos();
for (appl::Buffer::Iterator it = m_buffer->begin();
(bool)it == true;
++it) {
currentValue = *it;
m_buffer->expand(countColomn, currentValue, stringToDisplay);
for (size_t kkk=0; kkk<stringToDisplay.size(); ++kkk) {
if (stringToDisplay[kkk] == etk::UChar::Return) {
m_displayText.forceLineReturn();
countColomn = 0;
} else {
//note : Without this condithion the time od selection change to 0.6 ms to 8ms ...
if (-_relativePos.y() >= positionCurentDisplay.y()) {
m_displayText.print(stringToDisplay[kkk]);
}
++countColomn;
}
}
if (-_relativePos.y() >= positionCurentDisplay.y()) {
if (-_relativePos.y() < positionCurentDisplay.y()+tmpLetterSize.y()) {
APPL_VERBOSE("line position : '" << (char)(*it) << "' = '" << stringToDisplay << "' n=" << countColomn << " " <<positionCurentDisplay.x() << " < " << _relativePos.x() << " < " << m_displayText.getPos().x() );
if ( _relativePos.x() >= positionCurentDisplay.x()
&& _relativePos.x() < m_displayText.getPos().x() ) {
APPL_VERBOSE("find ...");
return it;
}
} else {
// previous line ...
return --it;
}
}
positionCurentDisplay = m_displayText.getPos();
}
return m_buffer->end();
}
void appl::TextViewer::onEventClipboard(enum ewol::clipBoard::clipboardListe _clipboardID) {
if (m_buffer != NULL) {
std::string data = ewol::clipBoard::get(_clipboardID);
write(data);
}
markToRedraw();
}
void appl::TextViewer::onReceiveMessage(const ewol::EMessage& _msg) {
widget::WidgetScrooled::onReceiveMessage(_msg);
APPL_VERBOSE("receive msg: " << _msg);
// First call plugin
if (appl::textPluginManager::onReceiveMessage(*this, _msg) == true) {
markToRedraw();
return;
}
// event needed even if selection of buffer is not done ...
if (_msg.getMessage() == appl::Buffer::eventIsModify) {
markToRedraw();
return;
}
if (_msg.getMessage() == appl::Buffer::eventSelectChange) {
markToRedraw();
return;
}
// If not the last buffer selected, then no event parsing ...
if (isSelectedLast() == false) {
return;
}
if (_msg.getMessage() == appl::MsgSelectGotoLineSelect) {
if (m_buffer == NULL) {
return;
}
appl::Buffer::Iterator it = m_buffer->countForwardNLines(m_buffer->begin(), std::stoi(_msg.getData()));
select(it, m_buffer->getEndLine(it));
markToRedraw();
return;
}
if (_msg.getMessage() == appl::MsgSelectGotoLine) {
if (m_buffer == NULL) {
return;
}
appl::Buffer::Iterator it = m_buffer->countForwardNLines(m_buffer->begin(), std::stoi(_msg.getData()));
moveCursor(it);
markToRedraw();
return;
}
if (_msg.getMessage() == appl::MsgSelectNewFile) {
// reset scroll:
if (m_buffer != NULL) {
m_buffer->unRegisterOnEvent(this);
bool needAdd = true;
for (size_t iii=0; iii<m_drawingRemenber.size(); ++iii) {
if (m_drawingRemenber[iii].first == m_buffer) {
m_drawingRemenber[iii].second = m_originScrooled;
APPL_VERBOSE("store origin : " << m_originScrooled);
needAdd = false;
break;
}
}
if (needAdd == true) {
m_drawingRemenber.push_back(std::make_pair(m_buffer, m_originScrooled));
APPL_VERBOSE("Push origin : " << m_originScrooled);
}
}
m_originScrooled = vec2(0,0);
if (m_bufferManager != NULL) {
m_buffer = m_bufferManager->get(_msg.getData());
m_bufferManager->setBufferSelected(m_buffer);
if (m_buffer != NULL) {
m_buffer->registerOnEvent(this, appl::Buffer::eventIsModify);
m_buffer->registerOnEvent(this, appl::Buffer::eventSelectChange);
for (auto element : m_drawingRemenber) {
if (element.first == m_buffer) {
m_originScrooled = element.second;
APPL_VERBOSE("retrive origin : " << m_originScrooled);
// TODO : Check if this element is not out of the display text ...
break;
}
}
}
}
markToRedraw();
return;
}
}
void appl::TextViewer::onObjectRemove(ewol::EObject* _removeObject) {
widget::WidgetScrooled::onObjectRemove(_removeObject);
if (m_buffer == _removeObject) {
m_buffer = NULL;
markToRedraw();
}
}
void appl::TextViewer::onGetFocus(void) {
showKeyboard();
APPL_INFO("Focus - In");
setCurrentSelect();
markToRedraw();
}
void appl::TextViewer::onLostFocus(void) {
hideKeyboard();
APPL_INFO("Focus - out");
markToRedraw();
}
void appl::TextViewer::setFontSize(int32_t _size) {
m_displayText.setFontSize(_size);
setScrollingSize(_size*3.0*1.46); // 1.46 is a magic number ...
}
void appl::TextViewer::setFontName(const std::string& _fontName) {
m_displayText.setFontName(_fontName);
}
void appl::TextViewer::updateScrolling(void) {
if (m_buffer == NULL) {
return;
}
vec2 realCursorPosition(0,0);
uint32_t lineId = m_buffer->getCursorLinesId();
m_displayText.clear();
m_displayText.forceLineReturn();
float lineSize = -m_displayText.getPos().y();
for (size_t iii=0; iii<lineId; ++iii) {
m_displayText.forceLineReturn();
}
realCursorPosition.setY(-m_displayText.getPos().y());
realCursorPosition.setX(getScreenSize(m_buffer->getStartLine(m_buffer->cursor()), m_buffer->cursor()));
APPL_VERBOSE("position=" << realCursorPosition << " scrool=" << m_originScrooled << " size" << m_size);
if (realCursorPosition.x() < m_originScrooled.x()+lineSize*2.0f) {
m_originScrooled.setX(realCursorPosition.x()-lineSize*2.0f);
} else if (realCursorPosition.x() > m_originScrooled.x()+(m_size.x()-m_lastOffsetDisplay)-lineSize*2.0f-10) {
m_originScrooled.setX(realCursorPosition.x()-(m_size.x()-m_lastOffsetDisplay)+lineSize*2.0f+10);
}
if (realCursorPosition.y() < m_originScrooled.y()+lineSize*2.0f) {
m_originScrooled.setY(realCursorPosition.y()-lineSize*2.0f);
} else if (realCursorPosition.y() > m_originScrooled.y()+m_size.y()-lineSize*2.0f) {
m_originScrooled.setY(realCursorPosition.y()-m_size.y()+lineSize*2.0f);
}
m_originScrooled.setMax(vec2(0,0));
// TODO : Limit min position too ...
}
bool appl::TextViewer::moveCursor(const appl::Buffer::Iterator& _pos) {
if (m_buffer == NULL) {
return false;
}
markToRedraw();
if (appl::textPluginManager::onCursorMove(*this, _pos) == true) {
updateScrolling();
return true;
}
m_buffer->moveCursor((int64_t)_pos);
updateScrolling();
return true;
}
bool appl::TextViewer::write(const std::string& _data) {
if (m_buffer == NULL) {
return false;
}
if (m_buffer->hasTextSelected() == true) {
return replace(_data);
}
return write(_data, m_buffer->cursor());
}
bool appl::TextViewer::write(const std::string& _data, const appl::Buffer::Iterator& _pos) {
if (m_buffer == NULL) {
return false;
}
markToRedraw();
if (appl::textPluginManager::onWrite(*this, _pos, _data) == true) {
// no call of the move cursor, because pluging might call theses function to copy and cut data...
updateScrolling();
return true;
}
bool ret = m_buffer->write(_data, _pos);
appl::textPluginManager::onCursorMove(*this, m_buffer->cursor());
updateScrolling();
return ret;
}
bool appl::TextViewer::replace(const std::string& _data, const appl::Buffer::Iterator& _pos, const appl::Buffer::Iterator& _posEnd) {
if (m_buffer == NULL) {
return false;
}
markToRedraw();
if (appl::textPluginManager::onReplace(*this, _pos, _data, _posEnd) == true) {
// no call of the move cursor, because pluging might call theses function to copy and cut data...
updateScrolling();
return true;
}
bool ret = m_buffer->replace(_data, _pos, _posEnd);
appl::textPluginManager::onCursorMove(*this, m_buffer->cursor());
updateScrolling();
return ret;
}
bool appl::TextViewer::replace(const std::string& _data) {
if (m_buffer == NULL) {
return false;
}
if (m_buffer->hasTextSelected() == false) {
return write(_data);
}
return replace(_data, m_buffer->selectStart(), m_buffer->selectStop());
}
void appl::TextViewer::remove(void) {
if (m_buffer == NULL) {
return;
}
if (m_buffer->hasTextSelected() == false) {
// nothing to do ...
return;
}
markToRedraw();
if (appl::textPluginManager::onRemove(*this, m_buffer->selectStart(), m_buffer->selectStop()) == true) {
return;
}
m_buffer->removeSelection();
appl::textPluginManager::onCursorMove(*this, m_buffer->cursor());
}
void appl::TextViewer::moveCursorRight(appl::TextViewer::moveMode _mode) {
if (m_buffer == NULL) {
return;
}
markToRedraw();
appl::Buffer::Iterator it;
switch (_mode) {
default:
case moveLetter:
it = m_buffer->cursor();
++it;
moveCursor(it);
break;
case moveWord:
// TODO : ...
break;
case moveEnd:
it = m_buffer->getEndLine(m_buffer->cursor());
moveCursor(it);
break;
}
}
void appl::TextViewer::moveCursorLeft(appl::TextViewer::moveMode _mode) {
if (m_buffer == NULL) {
return;
}
markToRedraw();
appl::Buffer::Iterator it;
switch (_mode) {
default:
case moveLetter:
it = m_buffer->cursor();
--it;
moveCursor(it);
break;
case moveWord:
// TODO : ...
break;
case moveEnd:
it = m_buffer->getStartLine(m_buffer->cursor());
moveCursor(it);
break;
}
}
void appl::TextViewer::moveCursorUp(uint32_t _nbLine) {
if (m_buffer == NULL) {
return;
}
markToRedraw();
// find the position of the start of the line.
appl::Buffer::Iterator lineStartPos = m_buffer->getStartLine(m_buffer->cursor());
// check if we can go up ...
if (lineStartPos == m_buffer->begin()) {
return;
}
// Decide what column to move to, if there's a preferred column use that
if (m_buffer->getFavoriteUpDownPos() < 0) {
m_buffer->setFavoriteUpDownPos(getScreenSize(lineStartPos, m_buffer->cursor()));
}
// get the previous line
appl::Buffer::Iterator prevLineStartPos = m_buffer->countBackwardNLines(lineStartPos-1, _nbLine);
//APPL_INFO("Move line UP result : prevLineStartPos=" << prevLineStartPos);
// get the display char position
appl::Buffer::Iterator newPos = getPosSize(prevLineStartPos, m_buffer->getFavoriteUpDownPos());
//APPL_INFO("Move to colomn : column=" << column << " newPos=" << newPos);
float posStore = m_buffer->getFavoriteUpDownPos();
moveCursor(newPos);
m_buffer->setFavoriteUpDownPos(posStore);
}
void appl::TextViewer::moveCursorDown(uint32_t _nbLine) {
if (m_buffer == NULL) {
return;
}
markToRedraw();
// check if we are not at the end of Buffer
if (m_buffer->cursor() == m_buffer->end() ) {
return;
}
// find the position of the start of the line.
appl::Buffer::Iterator lineStartPos = m_buffer->getStartLine(m_buffer->cursor());
if (m_buffer->getFavoriteUpDownPos() < 0) {
m_buffer->setFavoriteUpDownPos(getScreenSize(lineStartPos, m_buffer->cursor()));
}
// get the next line :
appl::Buffer::Iterator nextLineStartPos = m_buffer->countForwardNLines(lineStartPos, _nbLine);
//APPL_INFO("Move line DOWN result : nextLineStartPos=" << nextLineStartPos);
// get the display char position
appl::Buffer::Iterator newPos = getPosSize(nextLineStartPos, m_buffer->getFavoriteUpDownPos());
//APPL_INFO("Move to colomn : column=" << column << " newPos=" << newPos);
float posStore = m_buffer->getFavoriteUpDownPos();
moveCursor(newPos);
m_buffer->setFavoriteUpDownPos(posStore);
}
// TODO : Rename ...
appl::Buffer::Iterator appl::TextViewer::getPosSize(const appl::Buffer::Iterator& _startLinePos, float _distance) {
char32_t currentValue;
int32_t countColomn = 0;
std::u32string stringToDisplay;
m_displayText.clear();
m_displayText.forceLineReturn();
for (appl::Buffer::Iterator it = _startLinePos;
(bool)it == true;
++it) {
currentValue = *it;
m_buffer->expand(countColomn, currentValue, stringToDisplay);
for (size_t kkk=0; kkk<stringToDisplay.size(); ++kkk) {
if (stringToDisplay[kkk] == etk::UChar::Return) {
return it;
} else {
m_displayText.print(stringToDisplay[kkk]);
}
}
if (m_displayText.getPos().x() >= _distance) {
return it;
}
countColomn += stringToDisplay.size();
}
return m_buffer->end();
}
// TODO : Rename ...
float appl::TextViewer::getScreenSize(const appl::Buffer::Iterator& _startLinePos, const appl::Buffer::Iterator& _stopPos) {
float ret = 0;
char32_t currentValue;
int32_t countColomn = 0;
std::u32string stringToDisplay;
m_displayText.clear();
for (appl::Buffer::Iterator it = _startLinePos;
(bool)it == true && it <= _stopPos;
++it) {
currentValue = *it;
//APPL_DEBUG("parse : " << currentValue);
m_buffer->expand(countColomn, currentValue, stringToDisplay);
for (size_t kkk=0; kkk<stringToDisplay.size(); ++kkk) {
if (stringToDisplay[kkk] == etk::UChar::Return) {
return m_displayText.getPos().x() + 2; // TODO : Add the +2 for the end of line ...
} else {
m_displayText.print(stringToDisplay[kkk]);
}
}
ret = m_displayText.getPos().x();
countColomn += stringToDisplay.size();
}
return ret;
}
void appl::TextViewer::setCurrentSelect(void) {
if (m_viewerManager != NULL) {
m_viewerManager->setViewerSelected(this, m_buffer);
}
}
bool appl::TextViewer::isSelectedLast(void) {
if (m_viewerManager != NULL) {
return m_viewerManager->isLastSelected(this);
}
return false;
}

View File

@@ -0,0 +1,404 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __APPL_TEXT_VIEWER_H__
#define __APPL_TEXT_VIEWER_H__
#include <appl/debug.h>
#include <appl/Buffer.h>
#include <appl/globalMsg.h>
#include <ewol/widget/WidgetScrolled.h>
#include <ewol/compositing/Text.h>
#include <ewol/compositing/Drawing.h>
#include <appl/BufferManager.h>
#include <appl/Gui/ViewerManager.h>
#include <utility>
namespace appl {
class TextViewer : public widget::WidgetScrooled {
private:
appl::GlyphPainting* m_paintingProperties; //!< element painting property
int32_t m_colorBackground;
int32_t m_colorSpace;
int32_t m_colorTabulation;
int32_t m_colorCursor;
int32_t m_colorLineNumber;
int32_t m_colorSelection;
int32_t m_colorNormal;
private:
appl::BufferManager* m_bufferManager; //!< handle on the buffer manager
appl::ViewerManager* m_viewerManager; //!< handle on the buffer manager
public:
TextViewer(const std::string& _fontName="", int32_t _fontSize=-1);
virtual ~TextViewer(void);
private:
appl::Buffer* m_buffer; //!< pointer on the current buffer to display (can be null if the buffer is remover or in state of changing buffer)
public:
/**
* @brief Get the buffer property (only for the class : template <typename TYPE> class TextViewerPluginData)
* @return pointer on buffer
*/
appl::Buffer* internalGetBuffer(void) {
return m_buffer;
}
private:
ewol::Text m_displayText; //!< Text display properties.
ewol::Drawing m_displayDrawing; //!< Other diaplay requested.
std::vector<std::pair<appl::Buffer*, vec2>> m_drawingRemenber;
public:
void setFontSize(int32_t _size);
void setFontName(const std::string& _fontName);
protected: // derived function
virtual void onDraw(void);
public: // Derived function
virtual bool calculateMinSize(void);
virtual void onRegenerateDisplay(void);
virtual void onReceiveMessage(const ewol::EMessage& _msg);
virtual void onObjectRemove(ewol::EObject* _removeObject);
virtual bool onEventInput(const ewol::EventInput& _event);
virtual bool onEventEntry(const ewol::EventEntry& _event);
virtual void onEventClipboard(enum ewol::clipBoard::clipboardListe _clipboardID);
virtual void onGetFocus(void);
virtual void onLostFocus(void);
private:
float m_lastOffsetDisplay; //!< Line number ofssed in the display
private:
bool m_insertMode; //!< the insert mode is enable
public:
/**
* @brief Update the scrolling position from the cursor position,
* it might be be all time in the display screen.
*/
void updateScrolling(void);
// TODO : Doc : write data on buffer
bool moveCursor(const appl::Buffer::Iterator& _pos);
bool write(const std::string& _data);
bool write(const std::string& _data, const appl::Buffer::Iterator& _pos);
bool replace(const std::string& _data, const appl::Buffer::Iterator& _pos, const appl::Buffer::Iterator& _posEnd);
bool replace(const std::string& _data);
bool replace(const std::u32string& _data) {
return replace(to_u8string(_data));
}
/**
* @brief Remove selected data ...
*/
void remove(void);
/**
* @brief Remove selected data ... (No plugin call)
*/
void removeDirect(void) {
if (m_buffer==NULL) {
return;
}
m_buffer->removeSelection();
updateScrolling();
}
/**
* @brief copy data in the _data ref value.
* @param[out] _data Output stream to copy.
* @return true of no error occured.
*/
bool copy(std::string& _data) {
if (m_buffer==NULL) {
return false;
}
return m_buffer->copy(_data);
}
/**
* @brief copy data in the _data ref value.
* @param[out] _data Output stream to copy.
* @param[in] _pos Position to add the data.
* @param[in] _posEnd End position to end replace the data.
*/
void copy(std::string& _data, const appl::Buffer::Iterator& _pos, const appl::Buffer::Iterator& _posEnd) {
if (m_buffer==NULL) {
return;
}
m_buffer->copy(_data, _pos, _posEnd);
}
/**
* @brief Write data at a specific position (No plugin call)
* @param[in] _data Data to insert in the buffer
* @param[in] _pos Position to add the data.
* @return true if the write is done corectly
*/
bool writeDirect(const std::string& _data, const appl::Buffer::Iterator& _pos) {
if (m_buffer==NULL) {
return false;
}
bool ret = m_buffer->write(_data, _pos);
updateScrolling();
return ret;
}
/**
* @brief Write data at a specific position (No plugin call)
* @param[in] _data Data to insert in the buffer
* @param[in] _pos Position to add the data.
* @param[in] _posEnd End position to end replace the data.
* @return true if the write is done corectly
*/
bool replaceDirect(const std::string& _data, const appl::Buffer::Iterator& _pos, const appl::Buffer::Iterator& _posEnd) {
if (m_buffer==NULL) {
return false;
}
bool ret = m_buffer->replace(_data, _pos, _posEnd);
updateScrolling();
return ret;
}
appl::Buffer::Iterator getMousePosition(const vec2& _relativePos);
void mouseEventDouble(void);
void mouseEventTriple(void);
private:
enum moveMode {
moveLetter,
moveWord,
moveEnd
};
/**
* Move the cursor right in the line (no stop of a new line)
* @param[in] _mode Moving mode char, word, ...
*/
void moveCursorRight(moveMode _mode = moveLetter);
/**
* Move the cursor left in the line (no stop of a new line)
* @param[in] _mode Moving mode char, word, ...
*/
void moveCursorLeft(moveMode _mode = moveLetter);
/**
* @brief Move the cursor at an other position upper.
* @param[in] _nbLine number of up line that might be moved
*/
void moveCursorUp(uint32_t _nbLine);
/**
* @brief Move the cursor at an other position under.
* @param[in] _nbLine number of down line that might be moved
*/
void moveCursorDown(uint32_t _nbLine);
appl::Buffer::Iterator getPosSize(const appl::Buffer::Iterator& _startLinePos, float _distance);
float getScreenSize(const appl::Buffer::Iterator& _startLinePos, const appl::Buffer::Iterator& _stopPos);
private:
/**
* @brief Set the current buffer selected
*/
void setCurrentSelect(void);
/**
* @brief Check if the current buffer is last selected
* @return true if selected last
*/
bool isSelectedLast(void);
public:
/**
* @brief Check if the buffer is availlable
* @return true if a display buffer is present, false otherwise.
*/
virtual bool hasBuffer(void) {
return m_buffer != NULL;
}
/**
* @brief Get the status of selection.
* @return true if we have a current selection, false otherwise.
*/
virtual bool hasTextSelected(void) {
if (m_buffer==NULL) {
return false;
}
return m_buffer->hasTextSelected();
}
/**
* @brief Remove Selection of the buffer.
*/
virtual void unSelect(void) {
if (m_buffer==NULL) {
return;
}
m_buffer->unSelect();
}
/**
* @brief Select a section of text.
* @param[in] _start Start position of the selection
* @param[in] _stop Stop position of the selection (the curor is set at this position)
*/
virtual void select(const appl::Buffer::Iterator& _start, const appl::Buffer::Iterator& _stop) {
if (m_buffer==NULL) {
return;
}
moveCursor(_stop);
m_buffer->setSelectionPos(_start);
}
/**
* @brief Find a string in the buffer.
* @param[in] _pos Position to start the search of the element.
* @param[in] _search String to search.
* @param[out] _resultStart Find element start position.
* @param[out] _resultStop Find element end position.
* @param[in] _caseSensitive (optional) Search making attention of the case [default true]
* @return true if pos if fined.
*/
virtual bool find(const appl::Buffer::Iterator& _pos,
const std::u32string& _search,
appl::Buffer::Iterator& _resultStart,
appl::Buffer::Iterator& _resultStop,
bool _caseSensitive = true) {
if (m_buffer==NULL) {
return false;
}
bool ret = m_buffer->search(_pos, _search, _resultStart, _caseSensitive);
if (ret == true) {
_resultStop = _resultStart + _search.size();
}
return ret;
}
/**
* @brief revers find a string in the buffer.
* @param[in] _pos Position to start the search of the element.
* @param[in] _search String to search.
* @param[out] _resultStart Find element start position.
* @param[out] _resultStop Find element end position.
* @param[in] _caseSensitive (optional) Search making attention of the case [default true]
* @return true if pos if fined.
*/
virtual bool rfind(const appl::Buffer::Iterator& _pos,
const std::u32string& _search,
appl::Buffer::Iterator& _resultStart,
appl::Buffer::Iterator& _resultStop,
bool _caseSensitive = true) {
if (m_buffer==NULL) {
return false;
}
bool ret = m_buffer->searchBack(_pos, _search, _resultStart, _caseSensitive);
if (ret == true) {
_resultStop = _resultStart + _search.size();
}
return ret;
}
/**
* @brief Get the position of selection around (select word).
* @param[in] _pos Position to start the selection.
* @param[out] _beginPos Position where the element start.
* @param[out] _endPos Position where the element stop.
* @return true if we find a selection around.
*/
bool getPosAround(const appl::Buffer::Iterator& _pos,
appl::Buffer::Iterator &_beginPos,
appl::Buffer::Iterator &_endPos) {
if (m_buffer==NULL) {
return false;
}
return m_buffer->getPosAround(_pos, _beginPos, _endPos);
}
/**
* @brief Get an iterator an an specific position
* @param[in] _pos Requested position of the iterator.
* @return The Iterator
*/
appl::Buffer::Iterator position(int64_t _pos) {
if (m_buffer==NULL) {
return appl::Buffer::Iterator();
}
return m_buffer->position(_pos);
}
/**
* @brief Get the cursor position.
* @return The iterator on the cursor position
*/
appl::Buffer::Iterator cursor(void) {
if (m_buffer==NULL) {
return appl::Buffer::Iterator();
}
return m_buffer->cursor();
}
/**
* @brief Get the begin position.
* @return The iterator on the begin position
*/
appl::Buffer::Iterator begin(void) {
if (m_buffer==NULL) {
return appl::Buffer::Iterator();
}
return m_buffer->begin();
}
/**
* @brief Get the end position.
* @return The iterator on the end position
*/
appl::Buffer::Iterator end(void) {
if (m_buffer==NULL) {
return appl::Buffer::Iterator();
}
return m_buffer->end();
}
/**
* @brief Get an Iterator on the start selection.
* @return The Iterator
*/
appl::Buffer::Iterator selectStart(void) {
if (m_buffer==NULL) {
return appl::Buffer::Iterator();
}
return m_buffer->selectStart();
}
/**
* @brief Get an Iterator on the stop selection.
* @return The Iterator
*/
appl::Buffer::Iterator selectStop(void) {
if (m_buffer==NULL) {
return appl::Buffer::Iterator();
}
return m_buffer->selectStop();
}
/**
* @brief get the start of a line with the position in the buffer.
* @param[in] _pos position in the buffer.
* @return The position in the buffer of the start of the line.
*/
appl::Buffer::Iterator getStartLine(const appl::Buffer::Iterator& _pos) {
if (m_buffer==NULL) {
return appl::Buffer::Iterator();
}
return m_buffer->getStartLine(_pos);
}
/**
* @brief get the end of a line with the position in the buffer.
* @param[in] _pos position in the buffer.
* @return The position in the buffer of the end of the line.
*/
appl::Buffer::Iterator getEndLine(const appl::Buffer::Iterator& _pos) {
if (m_buffer==NULL) {
return appl::Buffer::Iterator();
}
return m_buffer->getEndLine(_pos);
}
/**
* @brief Register of the arrival of a Multicast message
* @param[in] _messageId Event Id waiting for...
*/
void ext_registerMultiCast(const char* const _messageId) {
registerMultiCast(_messageId);
}
/**
* @brief add a specific shortcut with his description
* @param[in] _descriptiveString Description string of the shortcut
* @param[in] _generateEventId Event generic of the element
* @param[in] _data Associate data wit the event
*/
virtual void ext_shortCutAdd(const char * _descriptiveString,
const char * _generateEventId,
std::string _data="",
bool _broadcast=false) {
shortCutAdd(_descriptiveString, _generateEventId, _data, _broadcast);
}
};
};
#endif

View File

@@ -0,0 +1,77 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/debug.h>
#include <appl/global.h>
#include <appl/Gui/ViewerManager.h>
#include <appl/Gui/TextViewer.h>
#include <ewol/renderer/EObject.h>
#include <ewol/renderer/EObjectManager.h>
#undef __class__
#define __class__ "ViewerManager"
appl::ViewerManager::ViewerManager(void) :
ewol::Resource("???ViewerManager???"),
m_viewer(NULL) {
addObjectType("appl::ViewerManager");
// load buffer manager:
m_bufferManager = appl::BufferManager::keep();
}
appl::ViewerManager::~ViewerManager(void) {
appl::BufferManager::release(m_bufferManager);
}
void appl::ViewerManager::setViewerSelected(appl::TextViewer* _viewer, appl::Buffer* _buffer) {
if (m_viewer == _viewer) {
return;
}
m_viewer = _viewer;
if (m_bufferManager != NULL) {
m_bufferManager->setBufferSelected(_buffer);
}
}
void appl::ViewerManager::onReceiveMessage(const ewol::EMessage& _msg) {
APPL_DEBUG("receive message !!! " << _msg);
}
void appl::ViewerManager::onObjectRemove(ewol::EObject* _removeObject) {
ewol::Resource:: onObjectRemove(_removeObject);
if (_removeObject == m_viewer) {
m_viewer = NULL;
return;
}
}
appl::ViewerManager* appl::ViewerManager::keep(void) {
//EWOL_INFO("KEEP : appl::GlyphPainting : file : \"" << _filename << "\"");
appl::ViewerManager* object = static_cast<appl::ViewerManager*>(getManager().localKeep("???ViewerManager???"));
if (NULL != object) {
return object;
}
// this element create a new one every time ....
EWOL_INFO("CREATE : appl::ViewerManager: ???ViewerManager???");
object = new appl::ViewerManager();
if (NULL == object) {
EWOL_ERROR("allocation error of a resource : ???ViewerManager???");
return NULL;
}
getManager().localAdd(object);
return object;
}
void appl::ViewerManager::release(appl::ViewerManager*& _object) {
if (NULL == _object) {
return;
}
ewol::Resource* object2 = static_cast<ewol::Resource*>(_object);
getManager().release(object2);
_object = NULL;
}

View File

@@ -0,0 +1,68 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __VIEWER_MANAGER_H__
#define __VIEWER_MANAGER_H__
#include <appl/Buffer.h>
#include <appl/globalMsg.h>
#include <ewol/widget/Widget.h>
#include <ewol/resources/Resource.h>
#include <appl/BufferManager.h>
namespace appl {
class TextViewer;
class ViewerManager : public ewol::Resource {
protected:
ViewerManager(void);
~ViewerManager(void);
private:
appl::BufferManager* m_bufferManager; //!< handle on the buffer manager
appl::TextViewer* m_viewer;
public:
/**
* @brief Set the current buffer selected
* @param[in] _viewer Pointer on the viewer selected
*/
void setViewerSelected(appl::TextViewer* _viewer, appl::Buffer* _buffer);
/**
* @brief Get the current buffer selected
* @return Pointer on the buffer selected
*/
appl::TextViewer* getViewerSelected(void) {
return m_viewer;
};
/**
* @breif Check if the element is the last request selection
* @param[in] _viewer element selected.
* @return true if the element is selected
*/
bool isLastSelected(appl::TextViewer* _viewer) {
return m_viewer == _viewer;
};
public: // herited function
void onReceiveMessage(const ewol::EMessage& _msg);
void onObjectRemove(ewol::EObject* _removeObject);
public: // resource manager
/**
* @brief keep the resource pointer.
* @note Never free this pointer by your own...
* @param[in] _filename Name of the configuration file.
* @return pointer on the resource or NULL if an error occured.
*/
static appl::ViewerManager* keep(void);
/**
* @brief release the keeped resources
* @param[in,out] reference on the object pointer
*/
static void release(appl::ViewerManager*& _object);
};
};
#endif

View File

@@ -0,0 +1,94 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <ewol/renderer/eContext.h>
#include <appl/debug.h>
#include <appl/Gui/WorkerCloseAllFile.h>
#undef __class__
#define __class__ "WorkerCloseAllFile"
static const char* s_closeDone = "close-done";
appl::WorkerCloseAllFile::WorkerCloseAllFile(void) :
m_worker(NULL),
m_bufferManager(NULL) {
addObjectType("appl::WorkerCloseAllFile");
// load buffer manager:
m_bufferManager = appl::BufferManager::keep();
if (m_bufferManager == NULL) {
APPL_ERROR("can not call unexistant buffer manager ... ");
autoDestroy();
return;
}
// List all current open file :
for (int64_t iii=m_bufferManager->size()-1; iii>=0; --iii) {
appl::Buffer* tmpBuffer = m_bufferManager->get(iii);
if (tmpBuffer == NULL) {
continue;
}
if (tmpBuffer->isModify() == false) {
tmpBuffer->removeObject();
continue;
}
m_bufferNameList.push_back(tmpBuffer->getFileName());
}
// checkif an element has something to do in the queue
if (m_bufferNameList.size() == 0) {
autoDestroy();
return;
}
// create the worker :
m_worker = new appl::WorkerCloseFile(m_bufferNameList.front());
// remove first element :
m_bufferNameList.erase(m_bufferNameList.begin());
if (m_bufferNameList.size() == 0) {
autoDestroy();
return;
}
m_worker->registerOnEvent(this, appl::WorkerCloseFile::eventCloseDone, s_closeDone);
}
appl::WorkerCloseAllFile::~WorkerCloseAllFile(void) {
appl::BufferManager::release(m_bufferManager);
}
void appl::WorkerCloseAllFile::onReceiveMessage(const ewol::EMessage& _msg) {
if (m_bufferManager == NULL) {
// nothing to do in this case ==> can do nothing ...
return;
}
if (_msg.getMessage() == s_closeDone) {
if (m_bufferNameList.size() == 0) {
autoDestroy();
return;
}
// create the worker :
m_worker = new appl::WorkerCloseFile(m_bufferNameList.front());
// remove first element :
m_bufferNameList.erase(m_bufferNameList.begin());
if (m_bufferNameList.size() == 0) {
autoDestroy();
return;
}
m_worker->registerOnEvent(this, appl::WorkerCloseFile::eventCloseDone, s_closeDone);
}
}
void appl::WorkerCloseAllFile::onObjectRemove(ewol::EObject* _removeObject) {
if (_removeObject == m_worker) {
m_worker = NULL;
APPL_VERBOSE("AutoRemove After saving sub widget ...");
autoDestroy();
} else if (_removeObject == m_bufferManager) {
m_bufferManager = NULL;
autoDestroy();
}
}

View File

@@ -0,0 +1,31 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __WORKER_CLOSE_ALL_FILE_H__
#define __WORKER_CLOSE_ALL_FILE_H__
#include <appl/BufferManager.h>
#include <appl/Gui/WorkerCloseFile.h>
namespace appl {
class WorkerCloseAllFile : public ewol::EObject {
public:
WorkerCloseAllFile(void);
virtual ~WorkerCloseAllFile(void);
private:
std::vector<std::string> m_bufferNameList;
appl::WorkerCloseFile* m_worker; //! pop-up element that is open...
appl::BufferManager* m_bufferManager; //!< handle on the buffer manager
public: // derived function
virtual void onReceiveMessage(const ewol::EMessage& _msg);
virtual void onObjectRemove(ewol::EObject * _removeObject);
};
};
#endif

View File

@@ -0,0 +1,154 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <ewol/renderer/eContext.h>
#include <appl/debug.h>
#include <appl/Gui/WorkerCloseFile.h>
#include <ewol/widget/meta/StdPopUp.h>
#undef __class__
#define __class__ "WorkerCloseFile"
const char* appl::WorkerCloseFile::eventCloseDone = "close-file-done";
static const char* s_saveAsValidate = "save-as-validate";
static const char* s_saveValidate = "save-validate";
static const char* s_closeValidate = "close-validate";
static const char* s_saveAsDone = "save-as-done";
appl::WorkerCloseFile::WorkerCloseFile(const std::string& _bufferName) :
m_bufferName(_bufferName),
m_buffer(NULL),
m_worker(NULL),
m_bufferManager(NULL) {
addObjectType("appl::WorkerCloseFile");
addEventId(eventCloseDone);
// load buffer manager:
m_bufferManager = appl::BufferManager::keep();
if (m_bufferManager == NULL) {
APPL_ERROR("can not call unexistant buffer manager ... ");
autoDestroy();
return;
}
if (m_bufferName == "") {
// need to find the curent file ...
appl::Buffer* tmpp = m_bufferManager->getBufferSelected();
if (tmpp == NULL) {
APPL_ERROR("No selected buffer now ...");
autoDestroy();
return;
}
m_bufferName = tmpp->getFileName();
}
if (m_bufferManager->exist(m_bufferName) == false) {
APPL_ERROR("Try to close an non-existant file :" << m_bufferName);
autoDestroy();
return;
}
m_buffer = m_bufferManager->get(m_bufferName);
if (m_buffer == NULL) {
APPL_ERROR("Error to get the buffer : " << m_bufferName);
autoDestroy();
return;
}
if (m_buffer->isModify() == false) {
generateEventId(eventCloseDone);
m_buffer->removeObject();
return;
}
widget::StdPopUp* tmpPopUp = new widget::StdPopUp();
if (tmpPopUp == NULL) {
APPL_ERROR("Can not create a simple pop-up");
return;
}
tmpPopUp->setTitle("<bold>Close un-saved file:</bold>");
tmpPopUp->setComment("The file named : <i>\"" + m_buffer->getFileName() + "\"</i> is curently modify. <br/>If you don't saves these modifications,<br/>they will be definitly lost...");
ewol::Widget* bt = NULL;
if (m_buffer->hasFileName() == true) {
bt = tmpPopUp->addButton("Save", true);
if (bt != NULL) {
bt->registerOnEvent(this, widget::Button::eventPressed, s_saveValidate);
}
}
bt = tmpPopUp->addButton("Save As", true);
if (bt != NULL) {
bt->registerOnEvent(this, widget::Button::eventPressed, s_saveAsValidate);
}
bt = tmpPopUp->addButton("Close", true);
if (bt != NULL) {
bt->registerOnEvent(this, widget::Button::eventPressed, s_closeValidate);
}
tmpPopUp->addButton("Cancel", true);
tmpPopUp->setRemoveOnExternClick(true);
ewol::Windows* tmpWindows = ewol::getContext().getWindows();
if (tmpWindows == NULL) {
APPL_ERROR("Error to get the windows.");
autoDestroy();
return;
}
tmpWindows->popUpWidgetPush(tmpPopUp);
}
appl::WorkerCloseFile::~WorkerCloseFile(void) {
appl::BufferManager::release(m_bufferManager);
}
void appl::WorkerCloseFile::onReceiveMessage(const ewol::EMessage& _msg) {
if (m_bufferManager == NULL) {
// nothing to do in this case ==> can do nothing ...
return;
}
APPL_DEBUG("have message : " << _msg);
if (_msg.getMessage() == s_saveAsValidate) {
m_worker = new appl::WorkerSaveFile(m_bufferName);
if (m_worker != NULL) {
m_worker->registerOnEvent(this, appl::WorkerSaveFile::eventSaveDone, s_saveAsDone);
}
} else if (_msg.getMessage() == s_saveValidate) {
if (m_buffer == NULL) {
APPL_ERROR("Error to get the buffer : oldName=" << m_bufferName);
autoDestroy();
return;
}
if (m_buffer->storeFile() == false) {
ewol::Windows* tmpWindows = ewol::getContext().getWindows();
if (tmpWindows == NULL) {
return;
}
tmpWindows->displayWarningMessage("We can not save the file : <br/><i>" + m_buffer->getFileName() + "</i>");
} else {
generateEventId(eventCloseDone);
}
} else if ( _msg.getMessage() == s_closeValidate
|| _msg.getMessage() == s_saveAsDone) {
if (m_buffer == NULL) {
APPL_ERROR("Error to get the buffer : " << m_bufferName);
autoDestroy();
return;
}
generateEventId(eventCloseDone);
m_buffer->removeObject();
}
}
void appl::WorkerCloseFile::onObjectRemove(ewol::EObject* _removeObject) {
if (_removeObject == m_worker) {
m_worker = NULL;
APPL_VERBOSE("AutoRemove After closing sub widget ...");
autoDestroy();
} else if (_removeObject == m_bufferManager) {
m_bufferManager = NULL;
autoDestroy();
} else if (_removeObject == m_buffer) {
m_buffer = NULL;
autoDestroy();
}
}

View File

@@ -0,0 +1,35 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __WORKER_CLOSE_FILE_H__
#define __WORKER_CLOSE_FILE_H__
#include <ewol/widget/meta/FileChooser.h>
#include <appl/BufferManager.h>
#include <appl/Gui/WorkerSaveFile.h>
namespace appl {
class WorkerCloseFile : public ewol::EObject {
public:
static const char* eventCloseDone;
public:
// note : if == "" ==> current ...
WorkerCloseFile(const std::string& _bufferName);
virtual ~WorkerCloseFile(void);
private:
std::string m_bufferName;
appl::Buffer* m_buffer; //!< reference on the buffer (when rename, we have no more reference on the buffer
appl::WorkerSaveFile* m_worker; //! sub-worker element...
appl::BufferManager* m_bufferManager; //!< handle on the buffer manager
public: // derived function
virtual void onReceiveMessage(const ewol::EMessage& _msg);
virtual void onObjectRemove(ewol::EObject * _removeObject);
};
};
#endif

View File

@@ -0,0 +1,97 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <ewol/renderer/eContext.h>
#include <appl/debug.h>
#include <appl/Gui/WorkerSaveAllFile.h>
#undef __class__
#define __class__ "WorkerSaveAllFile"
static const char* s_saveAsDone = "save-as-done";
appl::WorkerSaveAllFile::WorkerSaveAllFile(void) :
m_worker(NULL),
m_bufferManager(NULL) {
addObjectType("appl::WorkerSaveAllFile");
// load buffer manager:
m_bufferManager = appl::BufferManager::keep();
if (m_bufferManager == NULL) {
APPL_ERROR("can not call unexistant buffer manager ... ");
autoDestroy();
return;
}
// List all current open file :
for (size_t iii=0; iii<m_bufferManager->size(); ++iii) {
appl::Buffer* tmpBuffer = m_bufferManager->get(iii);
if (tmpBuffer == NULL) {
continue;
}
if (tmpBuffer->isModify() == false) {
continue;
}
if (tmpBuffer->hasFileName() == false) {
m_bufferNameList.push_back(tmpBuffer->getFileName());
} else {
tmpBuffer->storeFile();
}
}
// checkif an element has something to do in the queue
if (m_bufferNameList.size() == 0) {
autoDestroy();
return;
}
// create the worker :
m_worker = new appl::WorkerSaveFile(m_bufferNameList.front());
// remove first element :
m_bufferNameList.erase(m_bufferNameList.begin());
if (m_bufferNameList.size() == 0) {
autoDestroy();
return;
}
m_worker->registerOnEvent(this, appl::WorkerSaveFile::eventSaveDone, s_saveAsDone);
}
appl::WorkerSaveAllFile::~WorkerSaveAllFile(void) {
appl::BufferManager::release(m_bufferManager);
}
void appl::WorkerSaveAllFile::onReceiveMessage(const ewol::EMessage& _msg) {
if (m_bufferManager == NULL) {
// nothing to do in this case ==> can do nothing ...
return;
}
if (_msg.getMessage() == s_saveAsDone) {
if (m_bufferNameList.size() == 0) {
autoDestroy();
return;
}
// create the worker :
m_worker = new appl::WorkerSaveFile(m_bufferNameList.front());
// remove first element :
m_bufferNameList.erase(m_bufferNameList.begin());
if (m_bufferNameList.size() == 0) {
autoDestroy();
return;
}
m_worker->registerOnEvent(this, appl::WorkerSaveFile::eventSaveDone, s_saveAsDone);
}
}
void appl::WorkerSaveAllFile::onObjectRemove(ewol::EObject* _removeObject) {
if (_removeObject == m_worker) {
m_worker = NULL;
APPL_VERBOSE("AutoRemove After saving sub widget ...");
autoDestroy();
} else if (_removeObject == m_bufferManager) {
m_bufferManager = NULL;
autoDestroy();
}
}

View File

@@ -0,0 +1,30 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __WORKER_SAVE_ALL_FILE_H__
#define __WORKER_SAVE_ALL_FILE_H__
#include <appl/BufferManager.h>
#include <appl/Gui/WorkerSaveFile.h>
namespace appl {
class WorkerSaveAllFile : public ewol::EObject {
public:
WorkerSaveAllFile(void);
virtual ~WorkerSaveAllFile(void);
private:
std::vector<std::string> m_bufferNameList;
appl::WorkerSaveFile* m_worker; //! pop-up element that is open...
appl::BufferManager* m_bufferManager; //!< handle on the buffer manager
public: // derived function
virtual void onReceiveMessage(const ewol::EMessage& _msg);
virtual void onObjectRemove(ewol::EObject * _removeObject);
};
};
#endif

View File

@@ -0,0 +1,130 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <ewol/renderer/eContext.h>
#include <appl/debug.h>
#include <appl/Gui/WorkerSaveFile.h>
#undef __class__
#define __class__ "WorkerSaveFile"
const char* appl::WorkerSaveFile::eventSaveDone = "save-file-done";
static const char* s_saveAsValidate = "save-as-validate";
appl::WorkerSaveFile::WorkerSaveFile(const std::string& _bufferName, bool _forceSaveAs) :
m_bufferName(_bufferName),
m_chooser(NULL),
m_bufferManager(NULL) {
addObjectType("appl::WorkerSaveFile");
addEventId(eventSaveDone);
// load buffer manager:
m_bufferManager = appl::BufferManager::keep();
if (m_bufferManager == NULL) {
APPL_ERROR("can not call unexistant buffer manager ... ");
autoDestroy();
return;
}
if (m_bufferName == "") {
// need to find the curent file ...
appl::Buffer* tmpp = m_bufferManager->getBufferSelected();
if (tmpp == NULL) {
APPL_ERROR("No selected buffer now ...");
autoDestroy();
return;
}
m_bufferName = tmpp->getFileName();
}
if (m_bufferManager->exist(m_bufferName) == false) {
APPL_ERROR("Try to save an non-existant file :" << m_bufferName);
autoDestroy();
return;
}
appl::Buffer* tmpBuffer = m_bufferManager->get(m_bufferName);
if (tmpBuffer == NULL) {
APPL_ERROR("Error to get the buffer : " << m_bufferName);
autoDestroy();
return;
}
if (_forceSaveAs == false) {
if (tmpBuffer->hasFileName() == true) {
tmpBuffer->storeFile();
generateEventId(eventSaveDone);
autoDestroy();
return;
}
}
m_chooser = new widget::FileChooser();
if (NULL == m_chooser) {
APPL_ERROR("Can not allocate widget == > display might be in error");
autoDestroy();
return;
}
m_chooser->setTitle("Save files As...");
m_chooser->setValidateLabel("Save");
etk::FSNode tmpName(m_bufferName);
m_chooser->setFolder(tmpName.getNameFolder());
m_chooser->setFileName(tmpName.getNameFile());
ewol::Windows* tmpWindows = ewol::getContext().getWindows();
if (tmpWindows == NULL) {
APPL_ERROR("Error to get the windows.");
autoDestroy();
return;
}
tmpWindows->popUpWidgetPush(m_chooser);
m_chooser->registerOnEvent(this, widget::FileChooser::eventValidate, s_saveAsValidate);
}
appl::WorkerSaveFile::~WorkerSaveFile(void) {
appl::BufferManager::release(m_bufferManager);
}
void appl::WorkerSaveFile::onReceiveMessage(const ewol::EMessage& _msg) {
if (m_bufferManager == NULL) {
// nothing to do in this case ==> can do nothing ...
return;
}
if (_msg.getMessage() == s_saveAsValidate) {
if (_msg.getData() == "") {
APPL_ERROR(" might be an error of the File chooser system...");
return;
}
if (m_bufferManager->exist(m_bufferName) == false) {
APPL_ERROR("Try to save an non-existant file :" << m_bufferName);
return;
}
appl::Buffer* tmpBuffer = m_bufferManager->get(m_bufferName);
if (tmpBuffer == NULL) {
APPL_ERROR("Error to get the buffer : " << m_bufferName);
return;
}
tmpBuffer->setFileName(_msg.getData());
if (tmpBuffer->storeFile() == false) {
ewol::Windows* tmpWindows = ewol::getContext().getWindows();
if (tmpWindows == NULL) {
return;
}
tmpWindows->displayWarningMessage("We can not save the file : <br/><i>" + tmpBuffer->getFileName() + "</i>");
} else {
generateEventId(eventSaveDone);
}
}
}
void appl::WorkerSaveFile::onObjectRemove(ewol::EObject* _removeObject) {
if (_removeObject == m_chooser) {
m_chooser = NULL;
APPL_VERBOSE("AutoRemove After closing sub widget ...");
autoDestroy();
} else if (_removeObject == m_bufferManager) {
m_bufferManager = NULL;
autoDestroy();
}
}

View File

@@ -0,0 +1,32 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __WORKER_SAVE_FILE_H__
#define __WORKER_SAVE_FILE_H__
#include <ewol/widget/meta/FileChooser.h>
#include <appl/BufferManager.h>
namespace appl {
class WorkerSaveFile : public ewol::EObject {
public:
static const char* eventSaveDone;
public:
WorkerSaveFile(const std::string& _bufferName, bool _forceSaveAs=true);
virtual ~WorkerSaveFile(void);
private:
std::string m_bufferName;
widget::FileChooser* m_chooser; //! pop-up element that is open...
appl::BufferManager* m_bufferManager; //!< handle on the buffer manager
public: // derived function
virtual void onReceiveMessage(const ewol::EMessage& _msg);
virtual void onObjectRemove(ewol::EObject * _removeObject);
};
};
#endif

279
sources/appl/Highlight.cpp Normal file
View File

@@ -0,0 +1,279 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/debug.h>
#include <appl/global.h>
#include <appl/Highlight.h>
#include <exml/exml.h>
#include <ewol/resources/ResourceManager.h>
#undef __class__
#define __class__ "Highlight"
void appl::Highlight::parseRules(exml::Element* _child,
std::vector<HighlightPattern*>& _mListPatern,
int32_t _level) {
// Create the patern ...
HighlightPattern *myPattern = new HighlightPattern(m_paintingProperties);
// parse under Element
myPattern->parseRules(_child, _level);
// add element in the list
_mListPatern.push_back(myPattern);
}
appl::Highlight::Highlight(const std::string& _xmlFilename, const std::string& _colorFile) :
ewol::Resource(_xmlFilename),
m_typeName("") {
// keep color propertiy file :
m_paintingProperties = appl::GlyphPainting::keep(_colorFile);
exml::Document doc;
if (doc.load(_xmlFilename) == false) {
APPL_ERROR(" can not load file XML : " << _xmlFilename);
return;
}
exml::Element* root = doc.getNamed("EdnLang");
if (NULL == root ) {
APPL_ERROR("(l ?) main node not find: \"EdnLang\" ...");
return;
}
m_typeName = root->getAttribute("lang");
int32_t level1 = 0;
int32_t level2 = 0;
// parse all the elements :
for(int32_t iii = 0; iii < root->size(); ++iii) {
exml::Element* child = root->getElement(iii);
if (child == NULL) {
// trash here all that is not element ...
continue;
}
if (child->getValue() == "ext") {
std::string myData = child->getText();
if (myData.size()!=0) {
//APPL_INFO(PFX"(l %d) node fined : %s=\"%s\"", child->Row(), child->Value() , myData);
m_listExtentions.push_back(myData);
}
} else if (child->getValue() == "pass1") {
// get sub Nodes ...
for(int32_t jjj=0; jjj< child->size(); jjj++) {
exml::Element* passChild = child->getElement(jjj);
if (passChild == NULL) {
continue;
}
if (passChild->getValue() != "rule") {
APPL_ERROR("(l "<< passChild->getPos() << ") node not suported : \""<< passChild->getValue() << "\" must be [rule]" );
continue;
}
parseRules(passChild, m_listHighlightPass1, level1++);
}
} else if (child->getValue() == "pass2") {
// get sub Nodes ...
for(int32_t jjj=0; jjj< child->size(); jjj++) {
exml::Element* passChild = child->getElement(jjj);
if (passChild == NULL) {
continue;
}
if (passChild->getValue() != "rule") {
APPL_ERROR("(l "<< passChild->getPos() << ") node not suported : \""<< passChild->getValue() << "\" must be [rule]" );
continue;
}
parseRules(passChild, m_listHighlightPass2, level2++);
}
} else {
APPL_ERROR("(l "<< child->getPos() << ") node not suported : \""<< child->getValue() << "\" must be [ext,pass1,pass2]" );
}
}
}
appl::Highlight::~Highlight(void) {
int32_t i;
// clean all Element
for (int32_t iii = 0; iii < m_listHighlightPass1.size(); ++iii) {
if (m_listHighlightPass1[iii] != NULL) {
delete(m_listHighlightPass1[iii]);
m_listHighlightPass1[iii] = NULL;
}
}
// clear the compleate list
m_listHighlightPass1.clear();
// clear the compleate list
m_listExtentions.clear();
}
bool appl::Highlight::hasExtention(const std::string& _ext) {
for (int32_t iii=0; iii<m_listExtentions.size(); iii++) {
APPL_VERBOSE(" check : " << m_listExtentions[iii] << "=?=" << _ext);
if ( m_listExtentions[iii] == "*." + _ext
|| m_listExtentions[iii] == _ext) {
return true;
}
}
return false;
}
bool appl::Highlight::fileNameCompatible(const std::string& _fileName) {
std::string extention;
etk::FSNode file(_fileName);
if (true == file.fileHasExtention() ) {
extention = "*.";
extention += file.fileGetExtention();
} else {
extention = file.getNameFile();
}
APPL_DEBUG(" try to find : in \"" << file << "\" extention:\"" << extention << "\" ");
for (int32_t iii=0; iii<m_listExtentions.size(); iii++) {
if (extention == m_listExtentions[iii] ) {
return true;
}
}
return false;
}
void appl::Highlight::display(void) {
APPL_INFO("List of ALL Highlight : ");
for (int32_t iii=0; iii< m_listExtentions.size(); iii++) {
APPL_INFO(" Extention : " << iii << " : " << m_listExtentions[iii] );
}
// display all elements
for (int32_t iii=0; iii< m_listHighlightPass1.size(); iii++) {
APPL_INFO(" " << iii << " Pass 1 : " << m_listHighlightPass1[iii]->getName() );
//m_listHighlightPass1[iii]->display();
}
// display all elements
for (int32_t iii=0; iii< m_listHighlightPass2.size(); iii++) {
APPL_INFO(" " << iii << " Pass 2 : " << m_listHighlightPass2[iii]->getName() );
//m_listHighlightPass2[iii]->display();
}
}
/* TODO : Celui qui appelle suprime des element pour rien ... Enfin c'est pas très grave...
* Il suffirait juste de suprimer celui d'avant si il n'est pas terminer...
*/
void appl::Highlight::parse(int64_t start,
int64_t stop,
std::vector<appl::HighlightInfo> &metaData,
int64_t addingPos,
etk::Buffer &buffer) {
if (0 > addingPos) {
addingPos = 0;
}
//APPL_DEBUG("Parse element 0 => " << m_listHighlightPass1.size() << " == > position search: (" << start << "," << stop << ")" );
int64_t elementStart = start;
int64_t elementStop = stop;
appl::HighlightInfo resultat;
while (elementStart<elementStop) {
//APPL_DEBUG("Parse element in the buffer id=" << elementStart);
//try to fond the HL in ALL of we have
for (int64_t jjj=0; jjj<m_listHighlightPass1.size(); jjj++){
enum resultFind ret = HLP_FIND_OK;
//APPL_DEBUG("Parse HL id=" << jjj << " position search: (" << start << "," << buffer.size() << ")" );
// Stop the search to the end (to get the end of the pattern)
ret = m_listHighlightPass1[jjj]->find(elementStart, buffer.size(), resultat, buffer);
if (HLP_FIND_ERROR != ret) {
//APPL_INFO("Find Pattern in the Buffer : (" << resultat.beginStart << "," << resultat.endStop << ")" );
// remove element in the current List where the current Element have a end inside the next...
int64_t kkk=addingPos;
while(kkk < metaData.size() ) {
if (metaData[kkk].beginStart <= resultat.endStop) {
// remove element
//APPL_INFO("Erase element=" << kkk);
metaData.erase(metaData.begin()+kkk, metaData.begin()+kkk+1);
// Increase the end of search
if (kkk < metaData.size()) {
// just befor the end of the next element
elementStop = metaData[kkk].beginStart-1;
} else {
// end of the buffer
elementStop = buffer.size();
}
} else {
// Not find == > exit the cycle :
break;
}
}
// add curent element in the list ...
metaData.insert(metaData.begin()+addingPos, resultat);
//APPL_DEBUG("INSERT at "<< addingPos << " S=" << resultat.beginStart << " E=" << resultat.endStop );
// update the current research starting element: (set position at the end of the current element
elementStart = resultat.endStop-1;
// increment the position of insertion:
addingPos++;
// We find a pattern == > Stop search for the current element
break;
}
}
// Go to the next element (and search again ...).
elementStart++;
}
}
/**
* @brief second pass of the hightlight
*
*/
void appl::Highlight::parse2(int64_t start,
int64_t stop,
std::vector<appl::HighlightInfo> &metaData,
etk::Buffer &buffer) {
//APPL_DEBUG("Parse element 0 => " << m_listHighlightPass2.size() << " == > position search: (" << start << "," << stop << ")" );
int64_t elementStart = start;
int64_t elementStop = stop;
appl::HighlightInfo resultat;
while (elementStart<elementStop) {
//APPL_DEBUG("Parse element in the buffer id=" << elementStart);
//try to fond the HL in ALL of we have
for (int64_t jjj=0; jjj<m_listHighlightPass2.size(); jjj++){
enum resultFind ret = HLP_FIND_OK;
//APPL_DEBUG("Parse HL id=" << jjj << " position search: (" << start << "," << buffer.size() << ")" );
// Stop the search to the end (to get the end of the pattern)
ret = m_listHighlightPass2[jjj]->find(elementStart, elementStop, resultat, buffer);
if (HLP_FIND_ERROR != ret) {
//APPL_INFO("Find Pattern in the Buffer : (" << resultat.beginStart << "," << resultat.endStop << ")" );
// add curent element in the list ...
metaData.push_back(resultat);
elementStart = resultat.endStop-1;
// Exit current cycle
break;
}
}
// Go to the next element (and search again ...).
elementStart++;
}
}
appl::Highlight* appl::Highlight::keep(const std::string& _filename) {
//EWOL_INFO("KEEP : appl::Highlight : file : \"" << _filename << "\"");
appl::Highlight* object = static_cast<appl::Highlight*>(getManager().localKeep(_filename));
if (NULL != object) {
return object;
}
EWOL_INFO("CREATE : appl::Highlight : file : \"" << _filename << "\"");
// this element create a new one every time ....
object = new appl::Highlight(_filename, "THEME:COLOR:textViewer.json");
if (NULL == object) {
EWOL_ERROR("allocation error of a resource : ??Highlight??");
return NULL;
}
getManager().localAdd(object);
return object;
}
void appl::Highlight::release(appl::Highlight*& _object) {
if (NULL == _object) {
return;
}
ewol::Resource* object2 = static_cast<ewol::Resource*>(_object);
getManager().release(object2);
_object = NULL;
}

95
sources/appl/Highlight.h Normal file
View File

@@ -0,0 +1,95 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __HIGHLIGHT_H__
#define __HIGHLIGHT_H__
namespace appl {
class Highlight;
class HighlightPattern;
class HighlightInfo {
public:
int32_t beginStart;
int32_t beginStop;
int32_t endStart;
int32_t endStop;
bool notEnded;
appl::HighlightPattern* patern; // pointer on class :
};
};
#include <etk/os/FSNode.h>
#include <appl/HighlightPattern.h>
#include <appl/GlyphPainting.h>
#include <etk/Buffer.h>
#include <exml/exml.h>
namespace appl {
class Highlight : public ewol::Resource {
private:
appl::GlyphPainting* m_paintingProperties;
protected:
// Constructeur
Highlight(const std::string& _xmlFilename, const std::string& _colorFile);
~Highlight(void);
private:
std::string m_typeName; //!< descriptive string type like "C/C++"
public:
const std::string& getTypeName(void) {
return m_typeName;
}
public:
bool hasExtention(const std::string& _ext);
bool fileNameCompatible(const std::string& _fileName);
void display(void);
void parse(int64_t _start,
int64_t _stop,
std::vector<appl::HighlightInfo> &_metaData,
int64_t _addingPos,
etk::Buffer &_buffer);
void parse2(int64_t _start,
int64_t _stop,
std::vector<appl::HighlightInfo> &_metaData,
etk::Buffer &_buffer);
private:
void parseRules(exml::Element* _child,
std::vector<HighlightPattern*> &_mListPatern,
int32_t _level);
std::string m_styleName; //!< curent style name (like "c++" or "c" or "script Bash")
std::vector<std::string> m_listExtentions; //!< List of possible extention for this high-light, like : ".c", ".cpp", ".h"
std::vector<HighlightPattern*> m_listHighlightPass1; //!< List of ALL hightlight modules (pass 1 == > when we load and wride data on the buffer)
std::vector<HighlightPattern*> m_listHighlightPass2; //!< List of ALL hightlight modules (pass 2 == > When we display the buffer( only the display area (100 lines)) )
public:
/**
* @brief keep the resource pointer.
* @note Never free this pointer by your own...
* @param[in] _filename Name of the configuration file.
* @return pointer on the resource or NULL if an error occured.
*/
static appl::Highlight* keep(const std::string& _filename);
/**
* @brief release the keeped resources
* @param[in,out] reference on the object pointer
*/
static void release(appl::Highlight*& _object);
public: // herited function :
virtual void updateContext(void) {
// no upfate to do ...
};
};
};
#endif

View File

@@ -1,267 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/Debug.h>
#include <appl/global.h>
#include <Highlight.h>
#include <exml/exml.h>
#undef __class__
#define __class__ "Highlight"
void Highlight::ParseRules(exml::Element* child, etk::Vector<HighlightPattern*> &mListPatern, int32_t level)
{
// Create the patern ...
HighlightPattern *myPattern = new HighlightPattern();
// parse under Element
myPattern->ParseRules(child, level);
// add element in the list
mListPatern.PushBack(myPattern);
}
Highlight::Highlight(const etk::UString& _xmlFilename)
{
exml::Document doc;
if (doc.Load(_xmlFilename)==false) {
APPL_ERROR(" can not load file XML : " << _xmlFilename);
return;
}
exml::Element* root = (exml::Element*)doc.GetNamed("EdnLang");
if (NULL == root ) {
APPL_ERROR("(l ?) main node not find: \"EdnLang\" ...");
return;
}
int32_t level1 = 0;
int32_t level2 = 0;
// parse all the elements :
for(int32_t iii=0; iii< root->Size(); iii++) {
exml::Element* child = root->GetElement(iii);
if (child==NULL) {
// trash here all that is not element ...
continue;
}
if (child->GetValue() == "ext") {
etk::UString myData = child->GetText();
if (myData.Size()!=0) {
//APPL_INFO(PFX"(l %d) node fined : %s=\"%s\"", child->Row(), child->Value() , myData);
m_listExtentions.PushBack(myData);
}
} else if (child->GetValue()=="pass1") {
// Get sub Nodes ...
for(int32_t jjj=0; jjj< child->Size(); jjj++) {
exml::Element* passChild = child->GetElement(jjj);
if (passChild==NULL) {
continue;
}
if (passChild->GetValue() != "rule") {
APPL_ERROR("(l "<< passChild->GetPos() << ") node not suported : \""<< passChild->GetValue() << "\" must be [rule]" );
continue;
}
ParseRules(passChild, m_listHighlightPass1, level1++);
}
} else if (child->GetValue() == "pass2") {
// Get sub Nodes ...
for(int32_t jjj=0; jjj< child->Size(); jjj++) {
exml::Element* passChild = child->GetElement(jjj);
if (passChild==NULL) {
continue;
}
if (passChild->GetValue() != "rule") {
APPL_ERROR("(l "<< passChild->GetPos() << ") node not suported : \""<< passChild->GetValue() << "\" must be [rule]" );
continue;
}
ParseRules(passChild, m_listHighlightPass2, level2++);
}
} else {
APPL_ERROR("(l "<< child->GetPos() << ") node not suported : \""<< child->GetValue() << "\" must be [ext,pass1,pass2]" );
}
}
}
Highlight::~Highlight(void)
{
int32_t i;
// clean all Element
for (i=0; i< m_listHighlightPass1.Size(); i++) {
if (NULL != m_listHighlightPass1[i]) {
delete(m_listHighlightPass1[i]);
m_listHighlightPass1[i] = NULL;
}
}
// clear the compleate list
m_listHighlightPass1.Clear();
// clear the compleate list
m_listExtentions.Clear();
}
void Highlight::ReloadColor(void)
{
int32_t i;
for (i=0; i< m_listHighlightPass1.Size(); i++) {
if (NULL != m_listHighlightPass1[i]) {
m_listHighlightPass1[i]->ReloadColor();
}
}
for (i=0; i< m_listHighlightPass2.Size(); i++) {
if (NULL != m_listHighlightPass2[i]) {
m_listHighlightPass2[i]->ReloadColor();
}
}
}
bool Highlight::HasExtention(const etk::UString& _ext)
{
for (int32_t iii=0; iii<m_listExtentions.Size(); iii++) {
if (_ext == m_listExtentions[iii] ) {
return true;
}
}
return false;
}
bool Highlight::FileNameCompatible(etk::FSNode &_fileName)
{
etk::UString extention;
if (true == _fileName.FileHasExtention() ) {
extention = "*.";
extention += _fileName.FileGetExtention();
} else {
extention = _fileName.GetNameFile();
}
APPL_DEBUG(" try to find : in \"" << _fileName << "\" extention:\"" << extention << "\" ");
for (int32_t iii=0; iii<m_listExtentions.Size(); iii++) {
if (extention == m_listExtentions[iii] ) {
return true;
}
}
return false;
}
void Highlight::Display(void)
{
APPL_INFO("List of ALL Highlight : ");
for (int32_t iii=0; iii< m_listExtentions.Size(); iii++) {
APPL_INFO(" Extention : " << iii << " : " << m_listExtentions[iii] );
}
// Display all elements
for (int32_t iii=0; iii< m_listHighlightPass1.Size(); iii++) {
APPL_INFO(" " << iii << " Pass 1 : " << m_listHighlightPass1[iii]->GetName() );
//m_listHighlightPass1[i]->Display();
}
// Display all elements
for (int32_t iii=0; iii< m_listHighlightPass2.Size(); iii++) {
APPL_INFO(" " << iii << " Pass 2 : " << m_listHighlightPass2[iii]->GetName() );
//m_listHighlightPass2[i]->Display();
}
}
// 13h 46min 22s | (l= 214) Highlight::Parse | [II] Find Pattern in the Buffer : (2457,2479)
// TODO : Celui qui appelle suprime des element pour rien ... Enfin c'est pas tr<74>grave... Il suffirait juste de suprimer celuis d'avant si il n'est pas terminer...
void Highlight::Parse(int32_t start,
int32_t stop,
etk::Vector<colorInformation_ts> &metaData,
int32_t addingPos,
etk::Buffer &buffer)
{
if (0 > addingPos) {
addingPos = 0;
}
//APPL_DEBUG("Parse element 0 => " << m_listHighlightPass1.Size() << " ==> position search: (" << start << "," << stop << ")" );
int32_t elementStart = start;
int32_t elementStop = stop;
colorInformation_ts resultat;
while (elementStart<elementStop) {
//APPL_DEBUG("Parse element in the buffer id=" << elementStart);
//try to fond the HL in ALL of we have
for (int32_t jjj=0; jjj<m_listHighlightPass1.Size(); jjj++){
resultFind_te ret = HLP_FIND_OK;
//APPL_DEBUG("Parse HL id=" << jjj << " position search: (" << start << "," << buffer.Size() << ")" );
// Stop the search to the end (to get the end of the pattern)
ret = m_listHighlightPass1[jjj]->Find(elementStart, buffer.Size(), resultat, buffer);
if (HLP_FIND_ERROR != ret) {
//APPL_INFO("Find Pattern in the Buffer : (" << resultat.beginStart << "," << resultat.endStop << ")" );
// Remove element in the current List where the current Element have a end inside the next...
int32_t kkk=addingPos;
while(kkk < metaData.Size() ) {
if (metaData[kkk].beginStart <= resultat.endStop) {
// Remove element
//APPL_INFO("Erase element=" << kkk);
metaData.EraseLen(kkk, kkk+1);
// Increase the end of search
if (kkk < metaData.Size()) {
// just befor the end of the next element
elementStop = metaData[kkk].beginStart-1;
} else {
// end of the buffer
elementStop = buffer.Size();
}
} else {
// Not find ==> exit the cycle :
break;
}
}
// Add curent element in the list ...
metaData.Insert(addingPos, resultat);
//APPL_DEBUG("INSERT at "<< addingPos << " S=" << resultat.beginStart << " E=" << resultat.endStop );
// Update the current research starting element: (Set position at the end of the current element
elementStart = resultat.endStop-1;
// increment the position of insertion:
addingPos++;
// We find a pattern ==> Stop search for the current element
break;
}
}
// Go to the next element (and search again ...).
elementStart++;
}
}
/**
* @brief second pass of the hightlight
*
*/
void Highlight::Parse2(int32_t start,
int32_t stop,
etk::Vector<colorInformation_ts> &metaData,
etk::Buffer &buffer)
{
//APPL_DEBUG("Parse element 0 => " << m_listHighlightPass2.size() << " ==> position search: (" << start << "," << stop << ")" );
int32_t elementStart = start;
int32_t elementStop = stop;
colorInformation_ts resultat;
while (elementStart<elementStop) {
//APPL_DEBUG("Parse element in the buffer id=" << elementStart);
//try to fond the HL in ALL of we have
int32_t jjj;
for (jjj=0; jjj<m_listHighlightPass2.Size(); jjj++){
resultFind_te ret = HLP_FIND_OK;
//APPL_DEBUG("Parse HL id=" << jjj << " position search: (" << start << "," << buffer.Size() << ")" );
// Stop the search to the end (to get the end of the pattern)
ret = m_listHighlightPass2[jjj]->Find(elementStart, elementStop, resultat, buffer);
if (HLP_FIND_ERROR != ret) {
//APPL_INFO("Find Pattern in the Buffer : (" << resultat.beginStart << "," << resultat.endStop << ")" );
// Add curent element in the list ...
metaData.PushBack(resultat);
elementStart = resultat.endStop-1;
// Exit current cycle
break;
}
}
// Go to the next element (and search again ...).
elementStart++;
}
}

View File

@@ -1,66 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __HIGHLIGHT_H__
#define __HIGHLIGHT_H__
class Highlight;
class HighlightPattern;
extern "C" {
typedef struct
{
int32_t beginStart;
int32_t beginStop;
int32_t endStart;
int32_t endStop;
bool notEnded;
HighlightPattern * patern; // pointer on class :
} colorInformation_ts;
}
#include <etk/os/FSNode.h>
#include <HighlightPattern.h>
#include <Colorize.h>
#include <etk/Buffer.h>
#include <exml/exml.h>
class Highlight {
public:
// Constructeur
Highlight(const etk::UString& _xmlFilename);
~Highlight(void);
bool HasExtention(const etk::UString& _ext);
bool FileNameCompatible(etk::FSNode &_fileName);
void Display(void);
void ReloadColor(void);
void Parse(int32_t start,
int32_t stop,
etk::Vector<colorInformation_ts> &metaData,
int32_t addingPos,
etk::Buffer &buffer);
void Parse2(int32_t start,
int32_t stop,
etk::Vector<colorInformation_ts> &metaData,
etk::Buffer &buffer);
private:
void ParseRules(exml::Element* child, etk::Vector<HighlightPattern*> &mListPatern, int32_t level);
etk::UString m_styleName; //!< curent style name (like "c++" or "c" or "script Bash")
etk::Vector<etk::UString> m_listExtentions; //!< List of possible extention for this high-light, like : ".c", ".cpp", ".h"
etk::Vector<HighlightPattern*> m_listHighlightPass1; //!< List of ALL hightlight modules (pass 1 ==> when we load and wride data on the buffer)
etk::Vector<HighlightPattern*> m_listHighlightPass2; //!< List of ALL hightlight modules (pass 2 ==> When we display the buffer( only the display area (100 lines)) )
};
#endif

View File

@@ -1,156 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/Debug.h>
#include <appl/global.h>
#include <HighlightManager.h>
#include <ewol/renderer/EObject.h>
#include <ewol/renderer/EObjectManager.h>
#undef __class__
#define __class__ "HighlightManager"
class localClassHighlightManager: public ewol::EObject
{
private:
etk::Vector<Highlight*> listHighlight; //!< List of ALL hightlight modules
public:
// Constructeur
localClassHighlightManager(void) {
//ewol::widgetMessageMultiCast::Add(GetWidgetId(), ednMsgBufferColor);
};
~localClassHighlightManager(void) {
int32_t i;
// clean all Element
for (i=0; i< listHighlight.Size(); i++) {
if (NULL != listHighlight[i]) {
delete(listHighlight[i]);
listHighlight[i] = NULL;
}
}
// clear the compleate list
listHighlight.Clear();
};
// herited function
const char * const GetObjectType(void)
{
return "ApplHighlightManager";
}
// herited function
virtual void OnReceiveMessage(const ewol::EMessage& _msg)
{
/*
switch (id)
{
case APPL_MSG__COLOR_HAS_CHANGE:
APPL_INFO("UPDATE the color pointer on the HL");
for (int32_t i=0; i<listHighlight.Size(); i++) {
if (NULL != listHighlight[i]) {
listHighlight[i]->ReloadColor();
}
}
break;
}
*/
}
Highlight* Get(etk::FSNode &fileName)
{
int32_t i;
for (i=0; i<listHighlight.Size(); i++) {
if (true == listHighlight[i]->FileNameCompatible(fileName) ) {
return listHighlight[i];
}
}
return NULL;
}
bool Exist(etk::FSNode &fileName)
{
if (NULL != Get(fileName) ) {
return true;
}
return false;
}
void loadLanguages(void)
{
etk::FSNode myFile("DATA:languages/");
// get the subfolder list :
etk::Vector<etk::FSNode *> list = myFile.FolderGetSubList(false, true, false,false);
for ( int32_t iii=0 ; iii<list.Size() ; iii++ ) {
if (NULL!=list[iii]) {
if (list[iii]->GetNodeType()==etk::FSN_FOLDER) {
etk::UString filename = list[iii]->GetName() + "/highlight.xml";
APPL_DEBUG("Load xml name : " << filename);
Highlight *myHightline = new Highlight(filename);
listHighlight.PushBack(myHightline);
}
}
}
//myHightline->Display();
}
};
static localClassHighlightManager * localManager = NULL;
void HighlightManager::Init(void)
{
if (NULL != localManager) {
APPL_ERROR("HighlightManager ==> already exist, just unlink the previous ...");
localManager = NULL;
}
localManager = new localClassHighlightManager();
if (NULL == localManager) {
APPL_CRITICAL("Allocation of HighlightManager not done ...");
}
}
void HighlightManager::UnInit(void)
{
if (NULL == localManager) {
APPL_ERROR("HighlightManager ==> request UnInit, but does not exist ...");
return;
}
delete(localManager);
localManager = NULL;
}
void HighlightManager::loadLanguages(void)
{
if (NULL == localManager) {
return;
}
localManager->loadLanguages();
}
Highlight* HighlightManager::Get(etk::FSNode &fileName)
{
if (NULL == localManager) {
return NULL;
}
return localManager->Get(fileName);
}
bool HighlightManager::Exist(etk::FSNode &fileName)
{
if (NULL == localManager) {
return false;
}
return localManager->Exist(fileName);
}

View File

@@ -1,28 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __HIGHLIGHT_MANAGER_H__
#define __HIGHLIGHT_MANAGER_H__
#include <etk/UString.h>
#include <appl/globalMsg.h>
#include <Highlight.h>
#include <ewol/widget/Widget.h>
namespace HighlightManager{
void Init(void);
void UnInit(void);
void loadLanguages(void);
Highlight* Get(etk::FSNode &fileName);
bool Exist(etk::FSNode &fileName);
};
#endif

View File

@@ -1,233 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/Debug.h>
#include <appl/global.h>
#include <HighlightPattern.h>
#include <ColorizeManager.h>
#undef __class__
#define __class__ "HighlightPattern"
HighlightPattern::HighlightPattern(void)
{
m_haveStopPatern = false;
m_multiline = false;
m_color = ColorizeManager::Get("normal");
m_regExpStart = new etk::RegExp<etk::Buffer>();
m_regExpStop = new etk::RegExp<etk::Buffer>();
m_escapeChar = 0;
}
HighlightPattern::~HighlightPattern(void)
{
delete(m_regExpStart);
delete(m_regExpStop);
}
void HighlightPattern::SetPaternStart(etk::UString &regExp)
{
m_regExpStart->SetRegExp(regExp);
}
void HighlightPattern::SetPaternStop(etk::UString &regExp)
{
if (regExp.Size() != 0) {
m_regExpStop->SetRegExp(regExp);
m_haveStopPatern = true;
} else {
m_haveStopPatern = false;
}
}
void HighlightPattern::SetEscapeChar(etk::UString &EscapeChar)
{
if (EscapeChar.Size()>0) {
m_escapeChar = EscapeChar[0];
} else {
m_escapeChar = 0;
}
}
void HighlightPattern::SetColor(etk::UString &colorName)
{
m_colorName = colorName;
m_color = ColorizeManager::Get(m_colorName);
}
bool HighlightPattern::IsEnable(void)
{
return true;
}
void HighlightPattern::ReloadColor(void)
{
m_color = ColorizeManager::Get(m_colorName);
}
/**
* @brief
*
* @param[in,out]
*
* @eturn
*
*/
void HighlightPattern::Display(void)
{
/*
APPL_INFO("patern : \"" << m_paternName << "\" level=" << m_level );
APPL_INFO(" ==> colorName \"" << m_colorName << "\"");
APPL_INFO(" ==> regExpStart \"" << m_regExpStart->GetRegExp() << "\"");
APPL_INFO(" ==> regExpStop \"" << m_regExpStop->GetRegExp() << "\"");
if (true == m_haveStopPatern) {
APPL_INFO(" ==> stop pattern: YES");
} else {
APPL_INFO(" ==> stop pattern: NO");
}
if (true == m_multiline) {
APPL_INFO(" ==> multiline pattern: YES");
} else {
APPL_INFO(" ==> multiline pattern: NO");
}
*/
// Display all elements
for (int32_t i=0; i< m_subPatern.Size(); i++) {
APPL_INFO(" " << i << " SubPattern : " << m_subPatern[i]->GetName() );
m_subPatern[i]->Display();
}
}
void HighlightPattern::ParseRules(exml::Element *child, int32_t level)
{
//--------------------------------------------------------------------------------------------
/*
<rule name="my preprocesseur">
<color>preprocesseur</color>
<start>#</start>
<end>$</end>
<multiline>yes</multiline>
</rule>
*/
//--------------------------------------------------------------------------------------------
// process attribute
etk::UString highLightName = child->GetAttribute("name");
etk::UString myEdnDataTmp = "???";
if (highLightName.Size()!=0) {
myEdnDataTmp = highLightName;
}
SetName(myEdnDataTmp);
SetLevel(level);
exml::Element* xChild = (exml::Element*)child->GetNamed("color");
if (NULL != xChild) {
etk::UString myData = xChild->GetText();
if (myData.Size()!=0) {
//APPL_INFO(PFX"(l %d) node fined : %s=\"%s\"", xChild->Row(), xChild->Value() , myData);
etk::UString myEdnData = myData;
SetColor(myEdnData);
}
}
xChild = (exml::Element*)child->GetNamed("start");
if (NULL != xChild) {
etk::UString myData = xChild->GetText();
if (myData.Size()!=0) {
//APPL_INFO(PFX"(l %d) node fined : %s=\"%s\"", xChild->Row(), xChild->Value() , myData);
etk::UString myEdnData = myData;
SetPaternStart(myEdnData);
}
}
xChild = (exml::Element*)child->GetNamed("end");
if (NULL != xChild) {
etk::UString myData = xChild->GetText();
if (myData.Size()!=0) {
//APPL_INFO(PFX"(l %d) node fined : %s=\"%s\"", xChild->Row(), xChild->Value() , myData);
etk::UString myEdnData = myData;
SetPaternStop(myEdnData);
}
}
xChild = (exml::Element*)child->GetNamed("EscapeChar");
if (NULL != xChild) {
etk::UString myData = xChild->GetText();
if (myData.Size()!=0) {
//APPL_INFO(PFX"(l %d) node fined : %s=\"%s\"", xChild->Row(), xChild->Value() , myData);
etk::UString myEdnData = myData;
SetEscapeChar(myEdnData);
}
}
xChild = (exml::Element*)child->GetNamed("rule");
if (NULL != xChild) {
/*
// Create the patern ...
HighlightPattern *myPattern = new HighlightPattern();
// parse under Element
myPattern->ParseRules(ruleChild, level+1);
// add element in the list
m_subPatern.PushBack(myPattern);
//ParseRules(passChild, m_listHighlightPass1, level1++);
*/
}
}
/**
* @brief Find Element only in the specify start characters and find the end with the range done
*
* @param[in] start First character to search data (if recognise it start here)
* @param[in] stop End of the possibility whe search can continue
* @param[out] resultat Position where find data
* @param[in] buffer : Where to search data
*
* @return HLP_FIND_OK We find a compleate pattern
* @return HLP_FIND_OK_NO_END Xe find a partial pattern (missing end)
* @return HLP_FIND_ERROR Not find the pattern
*/
resultFind_te HighlightPattern::Find(int32_t start, int32_t stop, colorInformation_ts &resultat, etk::Buffer &buffer)
{
//APPL_DEBUG(" try to find the element");
resultat.beginStart = -1;
resultat.beginStop = -1;
resultat.endStart = -1;
resultat.endStop = -1;
resultat.notEnded = false;
resultat.patern = this;
// when we have only one element :
if (false == m_haveStopPatern) {
if (true == m_regExpStart->ProcessOneElement(buffer, start, stop)) {
resultat.beginStart = m_regExpStart->Start();
resultat.beginStop = m_regExpStart->Stop();
resultat.endStart = m_regExpStart->Start();
resultat.endStop = m_regExpStart->Stop();
return HLP_FIND_OK;
}
//APPL_DEBUG("NOT find hightlightpatern ...");
} else {
// try while we find the first element
if (true == m_regExpStart->ProcessOneElement(buffer, start, stop, m_escapeChar)) {
resultat.beginStart = m_regExpStart->Start();
resultat.beginStop = m_regExpStart->Stop();
if (true == m_regExpStop->Process(buffer, resultat.beginStop, stop, m_escapeChar)) {
resultat.endStart = m_regExpStop->Start();
resultat.endStop = m_regExpStop->Stop();
return HLP_FIND_OK;
} else {
resultat.endStart = stop+1;
resultat.endStop = stop+1;
resultat.notEnded = true;
return HLP_FIND_OK_NO_END;
}
}
//APPL_DEBUG("NOT find start hightlightpatern ...");
}
return HLP_FIND_ERROR;
}

View File

@@ -1,73 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <Highlight.h>
#ifndef __HIGHLIGHT_PATTERN_H__
#define __HIGHLIGHT_PATTERN_H__
class HighlightPattern;
#include <etk/RegExp.h>
#include <Colorize.h>
#include <etk/Vector.h>
#include <exml/exml.h>
#include <etk/Buffer.h>
typedef enum {
HLP_FIND_ERROR,
HLP_FIND_OK,
HLP_FIND_OK_NO_END,
}resultFind_te;
class HighlightPattern;
class HighlightPattern {
public:
// Constructeur
HighlightPattern(void);
~HighlightPattern(void);
void SetName(etk::UString &name) { m_paternName = name;};
etk::UString GetName(void) { return m_paternName;};
void SetPaternStart(etk::UString &regExp);
void SetPaternStop(etk::UString &regExp);
void SetColor(etk::UString &colorName);
void SetEscapeChar(etk::UString &EscapeChar);
void SetMultiline(bool enable) { m_multiline = enable; };
void SetLevel(int32_t newLevel) { m_level = newLevel; };
int32_t GetLevel(void) { return m_level; };
bool IsEnable(void);
void Display(void);
resultFind_te Find(int32_t start, int32_t stop, colorInformation_ts &resultat, etk::Buffer &buffer);
Colorize * GetColor(void) { return m_color; };
void ParseRules(exml::Element *child, int32_t level);
void ReloadColor(void);
private:
int32_t m_level; //!< Level of the pattern ==> this is to overwrite next pattern when we create an higher ....
etk::UString m_paternName; //!< Current style name (like "c++" or "c" or "script Bash")
etk::UString m_colorName; //!< Current color name
Colorize * m_color; //!< Link to the color manager
etk::RegExp<etk::Buffer> * m_regExpStart; //!< Start of Regular expression
etk::RegExp<etk::Buffer> * m_regExpStop; //!< Stop of Regular Expression
bool m_haveStopPatern; //!< Stop patern presence
bool m_multiline; //!< The patern is multiline
etk::UniChar m_escapeChar; //!< Escape char to prevent exeit of patern ....
etk::Vector<HighlightPattern *> m_subPatern; //!< Under patern of this one
// etk::Vector<HighlightPattern *> m_subColor; //!< Under Color in the start RegExp ...
};
#endif

View File

@@ -0,0 +1,118 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/debug.h>
#include <appl/global.h>
#include <appl/HighlightManager.h>
#include <ewol/renderer/EObject.h>
#include <ewol/renderer/EObjectManager.h>
#undef __class__
#define __class__ "highlightManager"
static std::vector<appl::Highlight*>& s_list(void) {
static std::vector<appl::Highlight*> list;
return list;
}
void appl::highlightManager::init(void) {
std::vector<appl::Highlight*>& hlList = s_list();
if (hlList.size() != 0) {
APPL_ERROR("HighlightManager == > already exist, just unlink the previous ...");
hlList.clear();
}
etk::FSNode myFile("DATA:languages/");
// get the subfolder list :
std::vector<etk::FSNode *> list = myFile.folderGetSubList(false, true, false,false);
for (int32_t iii = 0; iii < list.size(); ++iii) {
if (list[iii] == NULL) {
continue;
}
if (list[iii]->getNodeType() != etk::FSN_FOLDER) {
continue;
}
std::string filename = list[iii]->getName() + "/highlight.xml";
APPL_DEBUG("Load xml name : " << filename);
appl::Highlight *myHightLine = appl::Highlight::keep(filename);
if (myHightLine != NULL) {
hlList.push_back(myHightLine);
} else {
APPL_ERROR("Can not allocate HighLight");
}
}
// display :
/*
for (int32_t iii = 0; iii < hlList.size(); ++iii) {
if (hlList[iii] == NULL) {
continue;
}
hlList[iii]->display();
}
*/
}
void appl::highlightManager::unInit(void) {
std::vector<Highlight*>& hlList = s_list();
if (hlList.size() == 0) {
APPL_DEBUG("HighlightManager ==> no highlight");
hlList.clear();
return;
}
for (int32_t iii = 0; iii < hlList.size(); ++iii) {
if (hlList[iii] == NULL) {
continue;
}
appl::Highlight::release(hlList[iii]);
hlList[iii] = NULL;
}
hlList.clear();
}
std::string appl::highlightManager::getTypeExtention(const std::string& _extention) {
if (_extention.size() == 0) {
return "";
}
APPL_VERBOSE("Try to find type for extention : '" << _extention << "' in " << s_list().size() << " types");
std::vector<Highlight*>& hlList = s_list();
for (int32_t iii = 0; iii < hlList.size(); ++iii) {
if (hlList[iii] == NULL) {
continue;
}
APPL_VERBOSE(" check : " << hlList[iii]->getTypeName());
if (hlList[iii]->hasExtention(_extention) == true) {
APPL_VERBOSE("Find type for extention : " << _extention
<< " type : " << hlList[iii]->getTypeName());
return hlList[iii]->getTypeName();
}
}
return "";
}
std::string appl::highlightManager::getFileWithTypeType(const std::string& _type) {
if (_type.size() == 0) {
return "";
}
std::vector<Highlight*>& hlList = s_list();
for (int32_t iii = 0; iii < hlList.size(); ++iii) {
if (hlList[iii] == NULL) {
continue;
}
if (hlList[iii]->getTypeName() == _type) {
return hlList[iii]->getName();
}
}
return "";
}
std::vector<std::string> appl::highlightManager::getTypeList(void) {
std::vector<std::string> ret;
return ret;
}

View File

@@ -0,0 +1,50 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __HIGHLIGHT_MANAGER_H__
#define __HIGHLIGHT_MANAGER_H__
#include <etk/UString.h>
#include <appl/globalMsg.h>
#include <appl/Highlight.h>
#include <ewol/widget/Widget.h>
namespace appl {
namespace highlightManager {
/**
* @brief Init the Highlight manager
*/
void init(void);
/**
* @brief Un-Init the Highlight manager
*/
void unInit(void);
/**
* @brief Un-Init the Highlight manager
* @param[in] extention of the file
* @return type of highlight
*/
std::string getTypeExtention(const std::string& _extention);
/**
* @brief Get filename with type.
* @param[in] _type Type name of the highlight.
* @return filename of the highlight.
*/
std::string getFileWithTypeType(const std::string& _type);
/**
* @brief Get the list of extention type
* @return the requested list.
*/
std::vector<std::string> getTypeList(void);
};
};
#endif

View File

@@ -0,0 +1,185 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/debug.h>
#include <appl/global.h>
#include <appl/HighlightPattern.h>
#undef __class__
#define __class__ "HighlightPattern"
appl::HighlightPattern::HighlightPattern(appl::GlyphPainting*& _glyphPainting) :
m_glyphPainting(_glyphPainting),
m_paternName(""),
m_regExpStart(NULL),
m_regExpStop(NULL),
m_colorName(""),
m_escapeChar(etk::UChar::Null),
m_multiline(false),
m_level(0) {
m_regExpStart = new etk::RegExp<etk::Buffer>();
}
appl::HighlightPattern::~HighlightPattern(void) {
if (m_regExpStart != NULL) {
delete(m_regExpStart);
m_regExpStart = NULL;
}
if (m_regExpStop != NULL) {
delete(m_regExpStop);
m_regExpStop = NULL;
}
}
void appl::HighlightPattern::setPaternStart(std::string& _regExp) {
if (m_regExpStart == NULL) {
return;
}
m_regExpStart->setRegExp(_regExp);
}
void appl::HighlightPattern::setPaternStop(std::string& _regExp) {
if (m_regExpStop != NULL) {
delete(m_regExpStop);
m_regExpStop = NULL;
}
if (_regExp.size() != 0) {
m_regExpStop = new etk::RegExp<etk::Buffer>();
if (m_regExpStop != NULL) {
m_regExpStop->setRegExp(_regExp);
} else {
APPL_ERROR("Allocation error");
}
}
}
void appl::HighlightPattern::setEscapeChar(const char32_t& _EscapeChar) {
m_escapeChar = _EscapeChar;
}
void appl::HighlightPattern::setColorGlyph(std::string& _colorName) {
m_colorName = _colorName;
m_colorId = m_glyphPainting->request(m_colorName);
APPL_VERBOSE("Resuest color name '" << m_colorName << "' => id=" << m_colorId);
}
void appl::HighlightPattern::display(void) {
APPL_INFO("patern : \"" << m_paternName << "\" level=" << m_level );
APPL_INFO(" == > colorName \"" << m_colorName << "\"");
APPL_INFO(" == > regExpStart \"" << m_regExpStart->getRegExp() << "\"");
if (m_regExpStop != NULL) {
APPL_INFO(" == > regExpStop \"" << m_regExpStop->getRegExp() << "\"");
}
if (m_multiline == true) {
APPL_INFO(" == > multiline pattern: YES");
} else {
APPL_INFO(" == > multiline pattern: NO");
}
}
void appl::HighlightPattern::parseRules(exml::Element* _child, int32_t _level) {
//--------------------------------------------------------------------------------------------
/*
<rule name="my preprocesseur">
<color>preprocesseur</color>
<start>#</start>
<end>$</end>
<multiline>yes</multiline>
</rule>
*/
//--------------------------------------------------------------------------------------------
// process attribute
std::string highLightName = _child->getAttribute("name");
std::string myEdnDataTmp = "???";
if (highLightName.size()!=0) {
myEdnDataTmp = highLightName;
}
setName(myEdnDataTmp);
setLevel(_level);
exml::Element* xChild = _child->getNamed("color");
if (NULL != xChild) {
std::string myData = xChild->getText();
if (myData.size() != 0) {
//APPL_INFO(PFX"(l %d) node fined : %s=\"%s\"", xChild->Row(), xChild->Value() , myData);
std::string myEdnData = myData;
setColorGlyph(myEdnData);
}
}
xChild = _child->getNamed("start");
if (NULL != xChild) {
std::string myData = xChild->getText();
if (myData.size() != 0) {
//APPL_INFO(PFX"(l %d) node fined : %s=\"%s\"", xChild->Row(), xChild->Value() , myData);
std::string myEdnData = myData;
setPaternStart(myEdnData);
}
}
xChild = _child->getNamed("end");
if (NULL != xChild) {
std::string myData = xChild->getText();
if (myData.size() != 0) {
//APPL_INFO(PFX"(l %d) node fined : %s=\"%s\"", xChild->Row(), xChild->Value() , myData);
std::string myEdnData = myData;
setPaternStop(myEdnData);
}
}
xChild = _child->getNamed("EscapeChar");
if (NULL != xChild) {
std::string myData = xChild->getText();
if (myData.size() != 0) {
//APPL_INFO(PFX"(l %d) node fined : %s=\"%s\"", xChild->Row(), xChild->Value() , myData);
setEscapeChar(myData[0]);
}
}
}
enum resultFind appl::HighlightPattern::find(int32_t _start,
int32_t _stop,
appl::HighlightInfo& _resultat,
etk::Buffer& _buffer) {
//APPL_DEBUG(" try to find the element");
_resultat.beginStart = -1;
_resultat.beginStop = -1;
_resultat.endStart = -1;
_resultat.endStop = -1;
_resultat.notEnded = false;
_resultat.patern = this;
// when we have only one element:
if (m_regExpStop == NULL) {
if (true == m_regExpStart->processOneElement(_buffer, _start, _stop)) {
_resultat.beginStart = m_regExpStart->start();
_resultat.beginStop = m_regExpStart->stop();
_resultat.endStart = m_regExpStart->start();
_resultat.endStop = m_regExpStart->stop();
return HLP_FIND_OK;
}
//APPL_DEBUG("NOT find hightlightpatern ...");
return HLP_FIND_ERROR;
}
// try while we find the first element
if (m_regExpStart->processOneElement(_buffer, _start, _stop, m_escapeChar) == false) {
return HLP_FIND_ERROR;
}
_resultat.beginStart = m_regExpStart->start();
_resultat.beginStop = m_regExpStart->stop();
if (m_regExpStop->process(_buffer, _resultat.beginStop, _stop, m_escapeChar) == true) {
_resultat.endStart = m_regExpStop->start();
_resultat.endStop = m_regExpStop->stop();
return HLP_FIND_OK;
} else {
_resultat.endStart = _stop+1;
_resultat.endStop = _stop+1;
_resultat.notEnded = true;
return HLP_FIND_OK_NO_END;
}
//APPL_DEBUG("NOT find start hightlightpatern ...");
return HLP_FIND_ERROR;
}

View File

@@ -0,0 +1,106 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/Highlight.h>
#ifndef __HIGHLIGHT_PATTERN_H__
#define __HIGHLIGHT_PATTERN_H__
class HighlightPattern;
#include <etk/RegExp.h>
#include <appl/GlyphPainting.h>
#include <vector>
#include <exml/exml.h>
#include <etk/Buffer.h>
enum resultFind {
HLP_FIND_ERROR,
HLP_FIND_OK,
HLP_FIND_OK_NO_END,
};
namespace appl {
class HighlightPattern {
private:
appl::GlyphPainting*& m_glyphPainting;
public:
// Constructeur
HighlightPattern(appl::GlyphPainting*& _glyphPainting);
~HighlightPattern(void);
private:
std::string m_paternName; //!< Current style name (like "c++" or "c" or "script Bash")
public:
void setName(std::string& _name) {
m_paternName = _name;
};
std::string getName(void) {
return m_paternName;
};
private:
etk::RegExp<etk::Buffer>* m_regExpStart; //!< Start of Regular expression
public:
void setPaternStart(std::string& _regExp);
private:
etk::RegExp<etk::Buffer>* m_regExpStop; //!< Stop of Regular Expression
public:
void setPaternStop(std::string& _regExp);
private:
std::string m_colorName; //!< Current color name
int32_t m_colorId; //!< Id of the the glyph painting
public:
void setColorGlyph(std::string& _colorName);
const appl::GlyphDecoration& getColorGlyph(void) {
return (*m_glyphPainting)[m_colorId];
};
private:
char32_t m_escapeChar; //!< Escape char to prevent exeit of patern ....
public:
void setEscapeChar(const char32_t& _EscapeChar);
private:
bool m_multiline; //!< The patern is multiline
public:
void setMultiline(bool _enable) {
m_multiline = _enable;
};
private:
int32_t m_level; //!< Level of the pattern == > this is to overwrite next pattern when we create an higher ....
public:
void setLevel(int32_t _newLevel) {
m_level = _newLevel;
};
int32_t getLevel(void) {
return m_level;
};
private:
public:
void display(void);
/**
* @brief find Element only in the specify start characters and find the end with the range done
* @param[in] _start First character to search data (if recognise it start here)
* @param[in] _stop End of the possibility whe search can continue
* @param[out] _resultat Position where find data
* @param[in] _buffer : Where to search data
* @return HLP_FIND_OK We find a compleate pattern
* @return HLP_FIND_OK_NO_END Xe find a partial pattern (missing end)
* @return HLP_FIND_ERROR Not find the pattern
*/
enum resultFind find(int32_t _start,
int32_t _stop,
appl::HighlightInfo& _resultat,
etk::Buffer& _buffer);
void parseRules(exml::Element* _child, int32_t _level);
};
};
#endif

View File

@@ -0,0 +1,48 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/TextPlugin.h>
#include <appl/debug.h>
#undef __class__
#define __class__ "TextViewerPlugin"
appl::TextViewerPlugin::TextViewerPlugin(void) :
m_isEnable(true),
m_activateOnEventEntry(false),
m_activateOnEventInput(false),
m_activateOnWrite(false),
m_activateOnReplace(false),
m_activateOnRemove(false),
m_activateOnReceiveMessage(false),
m_activateOnCursorMove(false) {
}
appl::TextViewerPlugin::~TextViewerPlugin(void) {
if (m_isEnable == false) {
return;
}
m_isEnable = false;
onPluginDisable();
}
void appl::TextViewerPlugin::setEnableStatus(bool _status) {
if (_status == m_isEnable) {
return;
}
m_isEnable = _status;
if (m_isEnable == true) {
onPluginEnable();
} else {
onPluginDisable();
}
}

217
sources/appl/TextPlugin.h Normal file
View File

@@ -0,0 +1,217 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __APPL_TEXT_PLUGIN_H__
#define __APPL_TEXT_PLUGIN_H__
#include <etk/types.h>
#include <ewol/renderer/EObject.h>
#include <appl/Gui/TextViewer.h>
#include <ewol/compositing/Text.h>
namespace appl {
class TextViewerPlugin : public ewol::EObject {
friend class appl::TextViewer;
public:
TextViewerPlugin(void);
virtual ~TextViewerPlugin(void);
private:
bool m_isEnable; //!< The plugin is enable or not (for all viewer).
public:
/**
* @brief Set activity status of the plugin
* @param[in] _status new activity status
*/
void setEnableStatus(bool _status);
/**
* @brief Get the activity status.
* @return true if the plugin is active, false otherwise.
*/
bool isEnable(void) {
return m_isEnable;
};
public:
/**
* @brief On plugin global enable.
*/
virtual void onPluginEnable(void) {
// nothing to do here ...
};
/**
* @brief On plugin global disable.
*/
virtual void onPluginDisable(void) {
// nothing to do here ...
};
/**
* @brief On plugin enable on a specific text viewer.
* @param[in] _widget Reference on the widget caller.
*/
virtual void onPluginEnable(appl::TextViewer& _textDrawer) {
// nothing to do here ...
};
/**
* @brief On plugin disable on a specific text viewer.
* @param[in] _widget Reference on the widget caller.
*/
virtual void onPluginDisable(appl::TextViewer& _textDrawer) {
// nothing to do here ...
};
protected:
bool m_activateOnEventEntry; //!< onEventEntry is availlable for this plugin.
public:
/**
* @brief Get the availlability of a callback
* @return true if availlable
*/
bool isAvaillableOnEventEntry(void) {
return m_activateOnEventEntry;
}
/**
* @brief On entry event call.
* @param[in] _widget Reference on the widget caller.
* @param[in] _event Generic event.
* @return true if the event might not propagate anymore.
*/
virtual bool onEventEntry(appl::TextViewer& _textDrawer,
const ewol::EventEntry& _event) {
return false;
};
protected:
bool m_activateOnEventInput; //!< onEventInput is availlable for this plugin.
public:
/**
* @brief Get the availlability of a callback
* @return true if availlable
*/
bool isAvaillableOnEventInput(void) {
return m_activateOnEventInput;
}
/**
* @brief On Input event call.
* @param[in] _widget Reference on the widget caller.
* @param[in] _event Generic event.
* @return true if the event might not propagate anymore
*/
virtual bool onEventInput(appl::TextViewer& _textDrawer,
const ewol::EventInput& _event) {
return false;
};
protected:
bool m_activateOnWrite; //!< onWrite is availlable for this plugin.
public:
/**
* @brief Get the availlability of a callback
* @return true if availlable
*/
bool isAvaillableOnWrite(void) {
return m_activateOnWrite;
}
/**
* @brief Called when data is written in the buffer.
* @param[in] _widget Reference on the widget caller.
* @param[in] _pos Position in the buffer where data might be witten.
* @param[in] _data Input stream written.
* @return true if the event might not propagate anymore
*/
virtual bool onWrite(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const std::string& _data) {
return false;
};
protected:
bool m_activateOnReplace; //!< onReplace is availlable for this plugin.
public:
/**
* @brief Get the availlability of a callback
* @return true if availlable
*/
bool isAvaillableOnReplace(void) {
return m_activateOnReplace;
}
/**
* @brief Called when data is written in the buffer, and some are removed.
* @param[in] _widget Reference on the widget caller.
* @param[in] _pos Position in the buffer where data might be witten.
* @param[in] _data Input stream written.
* @param[in] _posEnd end replace position.
* @return true if the event might not propagate anymore
*/
virtual bool onReplace(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const std::string& _data,
const appl::Buffer::Iterator& _posEnd) {
return false;
};
protected:
bool m_activateOnRemove; //!< onRemove is availlable for this plugin.
public:
/**
* @brief Get the availlability of a callback
* @return true if availlable
*/
bool isAvaillableOnRemove(void) {
return m_activateOnRemove;
}
/**
* @brief Called when data is removed.
* @param[in] _widget Reference on the widget caller.
* @param[in] _pos Position in the buffer where data might be witten.
* @param[in] _posEnd end replace position.
* @return true if the event might not propagate anymore
*/
virtual bool onRemove(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const appl::Buffer::Iterator& _posEnd) {
return false;
};
protected:
bool m_activateOnReceiveMessage; //!< onReceiveMessage is availlable for this plugin.
public:
/**
* @brief Get the availlability of a callback
* @return true if availlable
*/
bool isAvaillableOnReceiveMessage(void) {
return m_activateOnReceiveMessage;
}
/**
* @brief Called when a message arrive.
* @param[in] _widget Reference on the widget caller.
* @param[in] _msg Generic message.
* @return true if the event might not propagate anymore
*/
virtual bool onReceiveMessage(appl::TextViewer& _textDrawer,
const ewol::EMessage& _msg) {
return false;
}
protected:
bool m_activateOnCursorMove; //!< onCursorMove is availlable for this plugin.
public:
/**
* @brief Get the availlability of a callback
* @return true if availlable
*/
bool isAvaillableOnCursorMove(void) {
return m_activateOnCursorMove;
}
/**
* @brief Called when Cursor move of position.
* @param[in] _widget Reference on the widget caller.
* @param[in] _pos New cursor position.
* @return true if the event might not propagate anymore
*/
virtual bool onCursorMove(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos) {
return false;
}
};
};
#endif

View File

@@ -0,0 +1,63 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/TextPluginAutoIndent.h>
#include <ewol/clipBoard.h>
#include <appl/Gui/TextViewer.h>
#undef __class__
#define __class__ "TextPluginAutoIndent"
appl::TextPluginAutoIndent::TextPluginAutoIndent(void) {
m_activateOnEventEntry = true;
}
bool appl::TextPluginAutoIndent::onEventEntry(appl::TextViewer& _textDrawer,
const ewol::EventEntry& _event) {
if (isEnable() == false) {
return false;
}
//APPL_DEBUG("KB EVENT : " << _event);
// just forward event == > manage directly in the buffer
if (_event.getType() != ewol::keyEvent::keyboardChar) {
return false;
}
if (_event.getStatus() != ewol::keyEvent::statusDown) {
return false;
}
if (_event.getChar() != etk::UChar::Return) {
return false;
}
if (_event.getSpecialKey().isSetShift() == true) {
return false;
}
appl::Buffer::Iterator startLine = _textDrawer.cursor();
if (_textDrawer.hasTextSelected() == true) {
startLine = _textDrawer.selectStart();
}
startLine = _textDrawer.getStartLine(startLine);
std::string data = "\n";
for (appl::Buffer::Iterator it = startLine;
(bool)it == true;
++it) {
if (*it == etk::UChar::Space) {
data += etk::UChar::Space;
} else if(*it == etk::UChar::Tabulation) {
data += etk::UChar::Tabulation;
} else {
break;
}
}
_textDrawer.write(data);
return true;
}

View File

@@ -0,0 +1,32 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __APPL_TEXT_PLUGIN_AUTO_INDENT_H__
#define __APPL_TEXT_PLUGIN_AUTO_INDENT_H__
#include <etk/types.h>
#include <ewol/renderer/EObject.h>
#include <appl/Gui/TextViewer.h>
#include <ewol/compositing/Text.h>
#include <appl/TextPlugin.h>
namespace appl {
class TextPluginAutoIndent : public appl::TextViewerPlugin {
public:
TextPluginAutoIndent(void);
~TextPluginAutoIndent(void) {
// nothing to do ...
};
public:
virtual bool onEventEntry(appl::TextViewer& _textDrawer,
const ewol::EventEntry& _event);
};
};
#endif

View File

@@ -0,0 +1,61 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/TextPluginCopy.h>
#include <ewol/clipBoard.h>
#include <appl/Gui/TextViewer.h>
#undef __class__
#define __class__ "TextPluginCopy"
appl::TextPluginCopy::TextPluginCopy(void) {
m_activateOnReceiveMessage = true;
}
void appl::TextPluginCopy::onPluginEnable(appl::TextViewer& _textDrawer) {
// add event :
_textDrawer.ext_registerMultiCast(ednMsgGuiCopy);
_textDrawer.ext_registerMultiCast(ednMsgGuiPaste);
_textDrawer.ext_registerMultiCast(ednMsgGuiCut);
_textDrawer.ext_shortCutAdd("ctrl+x", ednMsgGuiCut, "STD");
_textDrawer.ext_shortCutAdd("ctrl+c", ednMsgGuiCopy, "STD");
_textDrawer.ext_shortCutAdd("ctrl+v", ednMsgGuiPaste, "STD");
}
void appl::TextPluginCopy::onPluginDisable(appl::TextViewer& _textDrawer) {
// TODO : unknow function ...
}
bool appl::TextPluginCopy::onReceiveMessage(appl::TextViewer& _textDrawer,
const ewol::EMessage& _msg) {
if (isEnable() == false) {
return false;
}
if ( _msg.getMessage() == ednMsgGuiCopy
|| _msg.getMessage() == ednMsgGuiCut) {
if (_textDrawer.hasBuffer() == true) {
std::string value;
_textDrawer.copy(value);
if (value.size() != 0) {
ewol::clipBoard::set(ewol::clipBoard::clipboardStd, value);
}
}
if (_msg.getMessage() == ednMsgGuiCut) {
_textDrawer.remove();
}
return true;
} else if (_msg.getMessage() == ednMsgGuiPaste) {
if (_textDrawer.hasBuffer() == true) {
ewol::clipBoard::request(ewol::clipBoard::clipboardStd);
}
return true;
}
return false;
}

View File

@@ -0,0 +1,33 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __APPL_TEXT_PLUGIN_COPY_H__
#define __APPL_TEXT_PLUGIN_COPY_H__
#include <etk/types.h>
#include <ewol/renderer/EObject.h>
#include <appl/Gui/TextViewer.h>
#include <ewol/compositing/Text.h>
#include <appl/TextPlugin.h>
namespace appl {
class TextPluginCopy : public appl::TextViewerPlugin {
public:
TextPluginCopy(void);
~TextPluginCopy(void) {
// nothing to do ...
};
public:
virtual void onPluginEnable(appl::TextViewer& _textDrawer);
virtual void onPluginDisable(appl::TextViewer& _textDrawer);
virtual bool onReceiveMessage(appl::TextViewer& _textDrawer, const ewol::EMessage& _msg);
};
};
#endif

View File

@@ -0,0 +1,212 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/TextPluginCtags.h>
#include <ewol/clipBoard.h>
#include <appl/Gui/TextViewer.h>
#include <ewol/widget/meta/FileChooser.h>
#include <ewol/renderer/eContext.h>
#include <appl/Gui/TagFileSelection.h>
#undef __class__
#define __class__ "TextPluginCtags"
appl::TextPluginCtags::TextPluginCtags(void) :
m_tagFilename(""),
m_tagFolderBase(""),
m_ctagFile(NULL) {
m_activateOnReceiveMessage = true;
// load buffer manager:
m_bufferManager = appl::BufferManager::keep();
}
appl::TextPluginCtags::~TextPluginCtags(void) {
appl::BufferManager::release(m_bufferManager);
}
const char* eventJumpDestination = "event-plugin-ctags-jump-destination";
const char* eventJumpBack = "event-plugin-ctags-jump-back";
const char* eventOpenCtagsFile = "event-plugin-ctags-open";
const char* eventOpenCtagsOpenFileReturn = "event-plugin-ctags-open-file-return";
const char* eventOpenCtagsSelectReturn = "event-plugin-ctags-select-file-return";
void appl::TextPluginCtags::onPluginEnable(appl::TextViewer& _textDrawer) {
// Add local event of this object (no dependency with the viewer ...
/*
registerMultiCast(ednMsgGuiCtags);
registerMultiCast(ednMsgBufferId);
registerMultiCast(ednMsgCtagsLoadFile);
*/
// add event :
_textDrawer.ext_registerMultiCast(eventJumpDestination);
_textDrawer.ext_registerMultiCast(eventJumpBack);
_textDrawer.ext_registerMultiCast(eventOpenCtagsFile);
_textDrawer.ext_shortCutAdd("ctrl+d", eventJumpDestination);
_textDrawer.ext_shortCutAdd("ctrl+shift+d", eventJumpBack);
_textDrawer.ext_shortCutAdd("ctrl+alt+d", eventOpenCtagsFile);
}
void appl::TextPluginCtags::onPluginDisable(appl::TextViewer& _textDrawer) {
// TODO : unknow function ...
}
void appl::TextPluginCtags::jumpTo(const std::string& _name) {
if (m_ctagFile == NULL) {
APPL_WARNING("No ctags file open");
return;
}
tagEntry entry;
APPL_INFO("try to find the tag : " << _name);
if (tagsFind (m_ctagFile, &entry, _name.c_str(), 0) != TagSuccess) {
APPL_INFO("no tag find ...");
return;
}
tagEntry entrySave = entry;
int32_t numberOfTags = 0;
// For all tags : Save in an internal Structure :
std::string tmpFile(m_tagFolderBase + "/" + entry.file);
etk::FSNode myfile(tmpFile);
int32_t lineID = entry.address.lineNumber;
printTag(&entry);
if (tagsFindNext (m_ctagFile, &entry) == TagSuccess) {
APPL_INFO("Multiple file destination ...");
appl::TagFileSelection* tmpWidget = new appl::TagFileSelection();
if (NULL == tmpWidget) {
APPL_ERROR("Can not allocate widget == > display might be in error");
} else {
tmpWidget->addCtagsNewItem(myfile.getName(), lineID);
do {
tmpFile = m_tagFolderBase + "/" + entry.file;
myfile = tmpFile;
lineID = entry.address.lineNumber;
printTag(&entry);
tmpWidget->addCtagsNewItem(myfile.getName(), lineID);
} while (tagsFindNext (m_ctagFile, &entry) == TagSuccess);
ewol::getContext().getWindows()->popUpWidgetPush(tmpWidget);
tmpWidget->registerOnEvent(this, applEventctagsSelection, eventOpenCtagsSelectReturn);
}
} else {
jumpFile(myfile.getName(), lineID - 1);
}
}
void appl::TextPluginCtags::jumpFile(const std::string& _filename, int64_t _lineId) {
// save the current file in the history
// TODO : registerHistory();
if (m_bufferManager != NULL) {
m_bufferManager->open(_filename);
}
sendMultiCast(appl::MsgSelectChange, _filename);
sendMultiCast(appl::MsgSelectGotoLineSelect, std::to_string(_lineId));
}
void appl::TextPluginCtags::loadTagFile(void) {
tagFileInfo info;
// close previous tag file
if (NULL != m_ctagFile) {
tagsClose(m_ctagFile);
m_ctagFile = NULL;
}
if (m_tagFilename == "") {
return;
}
// load (open) the tag file :
APPL_INFO("try to open tag file : " << m_tagFilename);
m_ctagFile = tagsOpen(m_tagFilename.c_str(), &info);
if (NULL != m_ctagFile) {
APPL_INFO("open exuberant Ctags file is OK ...");
} else {
APPL_INFO("Error to open ctags file ...");
}
}
void appl::TextPluginCtags::printTag(const tagEntry *_entry) {
#if 1
APPL_INFO("find Tag file : name=\"" << _entry->name << "\" in file=\"" << _entry->file
<< "\" at line="<< (int32_t)_entry->address.lineNumber);
#else
APPL_INFO("find Tag file : name=\"" << _entry->name << "\" in file=\"" << _entry->file
<< "\" pattern=\"" << _entry->address.pattern
<< "\" at line="<< (int32_t)_entry->address.lineNumber);
APPL_INFO("Extention field : ");
if (_entry->kind != NULL && _entry->kind [0] != '\0') {
APPL_INFO(" kind : " << _entry->kind);
}
if (_entry->fileScope) {
APPL_INFO(" file : ");
}
for (int32_t iii = 0 ; iii < _entry->fields.count ; ++iii) {
APPL_INFO(" " << _entry->fields.list[iii].key << ":" << _entry->fields.list[iii].value );
}
#endif
}
void appl::TextPluginCtags::onReceiveMessage(const ewol::EMessage& _msg) {
if (_msg.getMessage() == eventOpenCtagsOpenFileReturn) {
// open the new one :
etk::FSNode tmpFilename = _msg.getData();
m_tagFilename = tmpFilename.getNameFile();
m_tagFolderBase = tmpFilename.getNameFolder();
APPL_DEBUG("Receive load Ctags file : " << m_tagFolderBase << "/" << m_tagFilename << " ");
loadTagFile();
} else if (_msg.getMessage() == eventOpenCtagsSelectReturn) {
// parse the input data
char tmp[4096];
int32_t lineID;
// TODO : Review this ...
sscanf(_msg.getData().c_str(), "%d:%s", &lineID, tmp);
jumpFile(tmp, lineID - 1);
}
}
bool appl::TextPluginCtags::onReceiveMessage(appl::TextViewer& _textDrawer,
const ewol::EMessage& _msg) {
if (isEnable() == false) {
return false;
}
if (_msg.getMessage() == eventOpenCtagsFile) {
APPL_INFO("Request opening ctag file");
widget::FileChooser* tmpWidget = new widget::FileChooser();
if (NULL == tmpWidget) {
APPL_ERROR("Can not allocate widget == > display might be in error");
} else {
tmpWidget->setTitle("Open Exuberant Ctags file");
tmpWidget->setValidateLabel("Open");
ewol::getContext().getWindows()->popUpWidgetPush(tmpWidget);
tmpWidget->registerOnEvent(this, widget::FileChooser::eventValidate, eventOpenCtagsOpenFileReturn);
}
return true;
} else if (_msg.getMessage() == eventJumpDestination) {
if (_textDrawer.hasBuffer() == false) {
return false;
}
std::string textToSearch;
if (_textDrawer.hasTextSelected() == true) {
_textDrawer.copy(textToSearch, _textDrawer.selectStart(), _textDrawer.selectStop() );
} else {
appl::Buffer::Iterator _beginPos;
appl::Buffer::Iterator _endPos;
if (_textDrawer.getPosAround(_textDrawer.cursor(), _beginPos, _endPos) == false) {
APPL_WARNING("Can not get data around...");
return true;
}
_textDrawer.copy(textToSearch, _beginPos, _endPos);
}
jumpTo(textToSearch);
return true;
} else if (_msg.getMessage() == eventJumpBack) {
if (_textDrawer.hasBuffer() == false) {
return false;
}
return true;
}
return false;
}

View File

@@ -0,0 +1,48 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __APPL_TEXT_PLUGIN_CTAGS_H__
#define __APPL_TEXT_PLUGIN_CTAGS_H__
#include <etk/types.h>
#include <ewol/renderer/EObject.h>
#include <appl/Gui/TextViewer.h>
#include <ewol/compositing/Text.h>
#include <appl/TextPlugin.h>
#include <appl/ctags/readtags.h>
namespace appl {
class TextPluginCtags : public appl::TextViewerPlugin {
private:
// Global plugin data (not specific on buffer :
/*
std::vector<std::pair<std::string, int64_t>> m_historyList;
*/
std::string m_tagFolderBase;
std::string m_tagFilename;
tagFile* m_ctagFile;
void loadTagFile(void);
void printTag(const tagEntry *_entry);
void jumpTo(const std::string& _name);
void jumpFile(const std::string& _filename, int64_t _lineId);
appl::BufferManager* m_bufferManager; //!< handle on the buffer manager
public:
TextPluginCtags(void);
~TextPluginCtags(void);
public:
virtual void onPluginEnable(appl::TextViewer& _textDrawer);
virtual void onPluginDisable(appl::TextViewer& _textDrawer);
virtual bool onReceiveMessage(appl::TextViewer& _textDrawer,
const ewol::EMessage& _msg);
// internal message :
virtual void onReceiveMessage(const ewol::EMessage& _msg);
};
};
#endif

View File

View File

@@ -0,0 +1,125 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __APPL_TEXT_PLUGIN_DATA_H__
#define __APPL_TEXT_PLUGIN_DATA_H__
#include <etk/types.h>
#include <ewol/renderer/EObject.h>
#include <appl/Gui/TextViewer.h>
#include <ewol/compositing/Text.h>
#include <appl/TextPlugin.h>
namespace appl {
template <typename TYPE> class TextViewerPluginData : public appl::TextViewerPlugin {
public:
TextViewerPluginData(void) {
// nothing to do ...
}
virtual ~TextViewerPluginData(void) {
for (size_t iii = 0; iii < m_specificData.size() ; ++iii) {
if (m_specificData[iii].second != NULL) {
remove(*m_specificData[iii].second);
delete(m_specificData[iii].second);
m_specificData[iii].second = NULL;
}
}
m_specificData.clear();
}
private:
std::vector<std::pair<appl::Buffer* ,TYPE* >> m_specificData;
protected:
TYPE* getDataRef(appl::TextViewer& _textDrawer) {
for (size_t iii = 0; iii < m_specificData.size() ; ++iii) {
if (m_specificData[iii].first == _textDrawer.internalGetBuffer()) {
return m_specificData[iii].second;
}
}
TYPE* data = new TYPE();
if (data == NULL) {
return NULL;
}
m_specificData.push_back(std::make_pair(_textDrawer.internalGetBuffer(), data));
// create a new one ...
return data;
}
protected: // Wrap all element with their internal data: (do not use theses function)
bool onReceiveMessage(appl::TextViewer& _textDrawer,
const ewol::EMessage& _msg) {
TYPE* data = getDataRef(_textDrawer);
if (data == NULL) {
return false;
}
return onReceiveMessage(_textDrawer, _msg, *data);
}
bool onWrite(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const std::string& _data) {
TYPE* data = getDataRef(_textDrawer);
if (data == NULL) {
return false;
}
return onWrite(_textDrawer, _pos, _data, *data);
}
bool onReplace(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const std::string& _data,
const appl::Buffer::Iterator& _posEnd) {
TYPE* data = getDataRef(_textDrawer);
if (data == NULL) {
return false;
}
return onReplace(_textDrawer, _pos, _data, _posEnd, *data);
}
bool onRemove(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const appl::Buffer::Iterator& _posEnd) {
TYPE* data = getDataRef(_textDrawer);
if (data == NULL) {
return false;
}
return onRemove(_textDrawer, _pos, _posEnd, *data);
}
public:
virtual bool onReceiveMessage(appl::TextViewer& _textDrawer,
const ewol::EMessage& _msg,
TYPE& _data) {
return false;
}
virtual bool onWrite(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const std::string& _strData,
TYPE& _data) {
return false;
}
virtual bool onReplace(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const std::string& _strData,
const appl::Buffer::Iterator& _posEnd,
TYPE& _data) {
return false;
}
virtual bool onRemove(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const appl::Buffer::Iterator& _posEnd,
TYPE& _data) {
return false;
}
virtual void remove(TYPE& _data) {
return;
};
public:
virtual void onObjectRemove(ewol::EObject* _removeObject) {
// TODO : plop
};
};
};
#endif

View File

@@ -0,0 +1,184 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/TextPluginHistory.h>
#include <ewol/clipBoard.h>
#include <appl/Gui/TextViewer.h>
#include <appl/TextPluginManager.h>
#undef __class__
#define __class__ "TextPluginHistory"
appl::TextPluginHistory::TextPluginHistory(void) {
m_activateOnReceiveMessage = true;
m_activateOnWrite = true;
m_activateOnReplace = true;
m_activateOnRemove = true;
}
void appl::TextPluginHistory::onPluginEnable(appl::TextViewer& _textDrawer) {
// add event :
_textDrawer.ext_registerMultiCast(ednMsgGuiRedo);
_textDrawer.ext_registerMultiCast(ednMsgGuiUndo);
_textDrawer.ext_shortCutAdd("ctrl+z", ednMsgGuiUndo);
_textDrawer.ext_shortCutAdd("ctrl+shift+z", ednMsgGuiRedo);
}
void appl::TextPluginHistory::onPluginDisable(appl::TextViewer& _textDrawer) {
// TODO : unknow function ...
}
bool appl::TextPluginHistory::onReceiveMessage(appl::TextViewer& _textDrawer,
const ewol::EMessage& _msg,
appl::PluginHistoryData& _data) {
if (isEnable() == false) {
return false;
}
if (_msg.getMessage() == ednMsgGuiRedo) {
if (_data.m_redo.size() == 0) {
return true;
}
if (_data.m_redo[_data.m_redo.size()-1] == NULL) {
_data.m_redo.pop_back();
return true;
}
appl::History *tmpElement = _data.m_redo[_data.m_redo.size()-1];
_data.m_redo.pop_back();
_data.m_undo.push_back(tmpElement);
_textDrawer.replaceDirect(tmpElement->m_addedText,
_textDrawer.position(tmpElement->m_posAdded),
_textDrawer.position(tmpElement->m_endPosRemoved) );
return true;
} else if (_msg.getMessage() == ednMsgGuiUndo) {
if (_data.m_undo.size() == 0) {
return true;
}
if (_data.m_undo[_data.m_undo.size()-1] == NULL) {
_data.m_undo.pop_back();
return true;
}
appl::History *tmpElement = _data.m_undo[_data.m_undo.size()-1];
_data.m_undo.pop_back();
_data.m_redo.push_back(tmpElement);
_textDrawer.replaceDirect(tmpElement->m_removedText,
_textDrawer.position(tmpElement->m_posAdded),
_textDrawer.position(tmpElement->m_endPosAdded) );
return true;
}
return false;
}
void appl::TextPluginHistory::clearRedo(appl::PluginHistoryData& _data) {
if (_data.m_redo.size() == 0) {
return;
}
for (size_t iii=0; iii<_data.m_redo.size(); ++iii) {
if (_data.m_redo[iii] == NULL) {
continue;
}
delete(_data.m_redo[iii]);
_data.m_redo[iii] = NULL;
}
_data.m_redo.clear();
}
void appl::TextPluginHistory::clearUndo(appl::PluginHistoryData& _data) {
if (_data.m_undo.size() == 0) {
return;
}
for (size_t iii=0; iii<_data.m_undo.size(); ++iii) {
if (_data.m_undo[iii] == NULL) {
continue;
}
delete(_data.m_undo[iii]);
_data.m_undo[iii] = NULL;
}
_data.m_undo.clear();
}
bool appl::TextPluginHistory::onWrite(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const std::string& _strData,
appl::PluginHistoryData& _data) {
if (isEnable() == false) {
return false;
}
appl::History *tmpElement = new appl::History();
if (tmpElement != NULL) {
tmpElement->m_addedText = _strData;
tmpElement->m_posAdded = (int64_t)_pos;
tmpElement->m_endPosRemoved = (int64_t)_pos;
}
_textDrawer.writeDirect(_strData, _pos);
if (tmpElement != NULL) {
tmpElement->m_endPosAdded = (int64_t)_textDrawer.cursor();
clearRedo(_data);
_data.m_undo.push_back(tmpElement);
}
appl::textPluginManager::onCursorMove(_textDrawer, _textDrawer.cursor());
return true;
}
bool appl::TextPluginHistory::onReplace(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const std::string& _strData,
const appl::Buffer::Iterator& _posEnd,
appl::PluginHistoryData& _data) {
if (isEnable() == false) {
return false;
}
appl::History *tmpElement = new appl::History();
if (tmpElement != NULL) {
tmpElement->m_posAdded = (int64_t)_pos;
tmpElement->m_addedText = _strData;
tmpElement->m_endPosRemoved = (int64_t)_posEnd;
_textDrawer.copy(tmpElement->m_removedText, _pos, _posEnd);
}
_textDrawer.replaceDirect(_strData, _pos, _posEnd);
if (tmpElement != NULL) {
tmpElement->m_endPosAdded = (int64_t)_textDrawer.cursor();
clearRedo(_data);
_data.m_undo.push_back(tmpElement);
}
appl::textPluginManager::onCursorMove(_textDrawer, _textDrawer.cursor());
return true;
}
bool appl::TextPluginHistory::onRemove(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const appl::Buffer::Iterator& _posEnd,
appl::PluginHistoryData& _data) {
if (isEnable() == false) {
return false;
}
appl::History *tmpElement = new appl::History();
if (tmpElement != NULL) {
tmpElement->m_addedText = "";
tmpElement->m_posAdded = (int64_t)_pos;
tmpElement->m_endPosAdded = tmpElement->m_posAdded;
tmpElement->m_endPosRemoved = (int64_t)_posEnd;
_textDrawer.copy(tmpElement->m_removedText, _pos, _posEnd);
clearRedo(_data);
_data.m_undo.push_back(tmpElement);
}
_textDrawer.removeDirect();
appl::textPluginManager::onCursorMove(_textDrawer, _textDrawer.cursor());
return true;
}
void appl::TextPluginHistory::onObjectRemove(ewol::EObject* _removeObject) {
// TODO : Dependence with buffer removing ...
}

View File

@@ -0,0 +1,75 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __APPL_TEXT_PLUGIN_HISTORY_H__
#define __APPL_TEXT_PLUGIN_HISTORY_H__
#include <etk/types.h>
#include <ewol/renderer/EObject.h>
#include <appl/Gui/TextViewer.h>
#include <ewol/compositing/Text.h>
#include <appl/TextPluginData.h>
namespace appl {
class History {
public:
History(void) :
m_posAdded(0),
m_endPosAdded(0),
m_endPosRemoved(0) {
};
std::string m_addedText;
std::string m_removedText;
int64_t m_posAdded;
int64_t m_endPosAdded;
int64_t m_endPosRemoved;
};
class PluginHistoryData {
public:
std::vector<History*> m_undo; //!< History storing data
std::vector<History*> m_redo; //!< History storing data
};
class TextPluginHistory : public appl::TextViewerPluginData<appl::PluginHistoryData> {
public:
TextPluginHistory(void);
virtual ~TextPluginHistory(void) { };
private:
public:
virtual void onPluginEnable(appl::TextViewer& _textDrawer);
virtual void onPluginDisable(appl::TextViewer& _textDrawer);
virtual bool onReceiveMessage(appl::TextViewer& _textDrawer,
const ewol::EMessage& _msg,
appl::PluginHistoryData& _data);
virtual bool onWrite(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const std::string& _strData,
appl::PluginHistoryData& _data);
virtual bool onReplace(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const std::string& _strData,
const appl::Buffer::Iterator& _posEnd,
appl::PluginHistoryData& _data);
virtual bool onRemove(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const appl::Buffer::Iterator& _posEnd,
appl::PluginHistoryData& _data);
virtual void remove(appl::PluginHistoryData& _data) {
clearRedo(_data);
clearUndo(_data);
}
private:
void clearRedo(appl::PluginHistoryData& _data);
void clearUndo(appl::PluginHistoryData& _data);
public:
virtual void onObjectRemove(ewol::EObject* _removeObject);
};
};
#endif

View File

@@ -0,0 +1,236 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/TextPluginManager.h>
#include <appl/debug.h>
#include <appl/TextPluginCopy.h>
#include <appl/TextPluginMultiLineTab.h>
#include <appl/TextPluginAutoIndent.h>
#include <appl/TextPluginHistory.h>
#include <appl/TextPluginRmLine.h>
#include <appl/TextPluginSelectAll.h>
#include <appl/TextPluginCtags.h>
#undef __class__
#define __class__ "textPluginManager"
static std::vector<appl::TextViewerPlugin *>& getList(void) {
static std::vector<appl::TextViewerPlugin *> s_list;
return s_list;
}
static std::vector<appl::TextViewerPlugin *>& getListOnEventEntry(void) {
static std::vector<appl::TextViewerPlugin *> s_list;
return s_list;
}
static std::vector<appl::TextViewerPlugin *>& getListOnEventInput(void) {
static std::vector<appl::TextViewerPlugin *> s_list;
return s_list;
}
static std::vector<appl::TextViewerPlugin *>& getListOnWrite(void) {
static std::vector<appl::TextViewerPlugin *> s_list;
return s_list;
}
static std::vector<appl::TextViewerPlugin *>& getListOnReplace(void) {
static std::vector<appl::TextViewerPlugin *> s_list;
return s_list;
}
static std::vector<appl::TextViewerPlugin *>& getListOnRemove(void) {
static std::vector<appl::TextViewerPlugin *> s_list;
return s_list;
}
static std::vector<appl::TextViewerPlugin *>& getListOnReceiveMessage(void) {
static std::vector<appl::TextViewerPlugin *> s_list;
return s_list;
}
static std::vector<appl::TextViewerPlugin *>& getListOnCursorMove(void) {
static std::vector<appl::TextViewerPlugin *> s_list;
return s_list;
}
void appl::textPluginManager::init(void) {
}
void appl::textPluginManager::unInit(void) {
// remove all sub plugin class:
getListOnEventEntry().clear();
getListOnEventInput().clear();
getListOnWrite().clear();
getListOnReplace().clear();
getListOnRemove().clear();
getListOnReceiveMessage().clear();
getListOnCursorMove().clear();
// remove all plugin:
for (int32_t iii=0; iii<getList().size(); ++iii) {
if (getList()[iii] == NULL) {
continue;
}
delete(getList()[iii]);
getList()[iii] = NULL;
}
getList().clear();
}
void appl::textPluginManager::addDefaultPlugin(void) {
appl::textPluginManager::addPlugin(new appl::TextPluginCopy());
appl::textPluginManager::addPlugin(new appl::TextPluginMultiLineTab());
appl::textPluginManager::addPlugin(new appl::TextPluginAutoIndent());
appl::textPluginManager::addPlugin(new appl::TextPluginHistory());
appl::textPluginManager::addPlugin(new appl::TextPluginRmLine());
appl::textPluginManager::addPlugin(new appl::TextPluginSelectAll());
appl::textPluginManager::addPlugin(new appl::TextPluginCtags());
}
void appl::textPluginManager::addPlugin(appl::TextViewerPlugin* _plugin) {
if (_plugin == NULL) {
return;
}
getList().push_back(_plugin);
if (_plugin->isAvaillableOnEventEntry() == true) {
getListOnEventEntry().push_back(_plugin);
}
if (_plugin->isAvaillableOnEventInput() == true) {
getListOnEventInput().push_back(_plugin);
}
if (_plugin->isAvaillableOnWrite() == true) {
getListOnWrite().push_back(_plugin);
}
if (_plugin->isAvaillableOnReplace() == true) {
getListOnReplace().push_back(_plugin);
}
if (_plugin->isAvaillableOnRemove() == true) {
getListOnRemove().push_back(_plugin);
}
if (_plugin->isAvaillableOnReceiveMessage() == true) {
getListOnReceiveMessage().push_back(_plugin);
}
if (_plugin->isAvaillableOnCursorMove() == true) {
getListOnCursorMove().push_back(_plugin);
}
}
void appl::textPluginManager::connect(appl::TextViewer& _widget) {
for (int32_t iii=0; iii<getList().size(); ++iii) {
if (getList()[iii] == NULL) {
continue;
}
getList()[iii]->onPluginEnable(_widget);
}
}
void appl::textPluginManager::disconnect(appl::TextViewer& _widget) {
for (int32_t iii=0; iii<getList().size(); ++iii) {
if (getList()[iii] == NULL) {
continue;
}
getList()[iii]->onPluginDisable(_widget);
}
}
bool appl::textPluginManager::onEventEntry(appl::TextViewer& _textDrawer,
const ewol::EventEntry& _event) {
std::vector<appl::TextViewerPlugin *>& list = getListOnEventEntry();
for (int32_t iii=0; iii<list.size(); ++iii) {
if (list[iii] == NULL) {
continue;
}
if (list[iii]->onEventEntry(_textDrawer, _event) == true ) {
return true;
}
}
return false;
}
bool appl::textPluginManager::onEventInput(appl::TextViewer& _textDrawer,
const ewol::EventInput& _event) {
std::vector<appl::TextViewerPlugin *>& list = getListOnEventInput();
for (int32_t iii=0; iii<list.size(); ++iii) {
if (list[iii] == NULL) {
continue;
}
if (list[iii]->onEventInput(_textDrawer, _event) == true ) {
return true;
}
}
return false;
}
bool appl::textPluginManager::onWrite(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const std::string& _data) {
std::vector<appl::TextViewerPlugin *>& list = getListOnWrite();
for (int32_t iii=0; iii<list.size(); ++iii) {
if (list[iii] == NULL) {
continue;
}
if (list[iii]->onWrite(_textDrawer, _pos, _data) == true ) {
return true;
}
}
return false;
}
bool appl::textPluginManager::onReplace(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const std::string& _data,
const appl::Buffer::Iterator& _posEnd) {
std::vector<appl::TextViewerPlugin *>& list = getListOnReplace();
for (int32_t iii=0; iii<list.size(); ++iii) {
if (list[iii] == NULL) {
continue;
}
if (list[iii]->onReplace(_textDrawer, _pos, _data, _posEnd) == true ) {
return true;
}
}
return false;
}
bool appl::textPluginManager::onRemove(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const appl::Buffer::Iterator& _posEnd) {
std::vector<appl::TextViewerPlugin *>& list = getListOnRemove();
for (int32_t iii=0; iii<list.size(); ++iii) {
if (list[iii] == NULL) {
continue;
}
if (list[iii]->onRemove(_textDrawer, _pos, _posEnd) == true ) {
return true;
}
}
return false;
}
bool appl::textPluginManager::onReceiveMessage(appl::TextViewer& _textDrawer,
const ewol::EMessage& _msg) {
std::vector<appl::TextViewerPlugin *>& list = getListOnReceiveMessage();
for (int32_t iii=0; iii<list.size(); ++iii) {
if (list[iii] == NULL) {
continue;
}
if (list[iii]->onReceiveMessage(_textDrawer, _msg) == true ) {
return true;
}
}
return false;
}
bool appl::textPluginManager::onCursorMove(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos) {
std::vector<appl::TextViewerPlugin *>& list = getListOnCursorMove();
for (int32_t iii=0; iii<list.size(); ++iii) {
if (list[iii] == NULL) {
continue;
}
if (list[iii]->onCursorMove(_textDrawer, _pos) == true ) {
return true;
}
}
return false;
}

View File

@@ -0,0 +1,115 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __APPL_TEXT_PLUGIN_MANAGER_H__
#define __APPL_TEXT_PLUGIN_MANAGER_H__
#include <etk/types.h>
#include <ewol/renderer/EObject.h>
#include <appl/Gui/TextViewer.h>
#include <ewol/compositing/Text.h>
#include <appl/TextPlugin.h>
namespace appl {
namespace textPluginManager {
/**
* @brief Init the plugin manager for writer.
*/
void init(void);
/**
* @brief UnInit the plugin manager for writer.
*/
void unInit(void);
/**
* @brief Add default plugin list
*/
void addDefaultPlugin(void);
/**
* @brief Add a plugin.
* @param[in] _plugin Plugin pointer to add.
*/
void addPlugin(appl::TextViewerPlugin* _plugin);
/**
* @brief connect a new widget to the plugin.
* @param[in] _widget Reference on the widget caller.
*/
void connect(appl::TextViewer& _widget);
/**
* @brief dis-connect a new widget to the plugin.
* @param[in] _widget Reference on the widget caller.
*/
void disconnect(appl::TextViewer& _widget);
/**
* @brief On entry event call.
* @param[in] _widget Reference on the widget caller.
* @param[in] _event Generic event.
* @return true if the event might not propagate anymore.
*/
bool onEventEntry(appl::TextViewer& _widget,
const ewol::EventEntry& _event);
/**
* @brief On Input event call.
* @param[in] _widget Reference on the widget caller.
* @param[in] _event Generic event.
* @return true if the event might not propagate anymore
*/
bool onEventInput(appl::TextViewer& _textDrawer,
const ewol::EventInput& _event);
/**
* @brief Called when data is written in the buffer.
* @param[in] _widget Reference on the widget caller.
* @param[in] _pos Position in the buffer where data might be witten.
* @param[in] _data Input stream written.
* @return true if the event might not propagate anymore
*/
bool onWrite(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const std::string& _data);
/**
* @brief Called when data is written in the buffer, and some are removed.
* @param[in] _widget Reference on the widget caller.
* @param[in] _pos Position in the buffer where data might be witten.
* @param[in] _data Input stream written.
* @param[in] _posEnd end replace position.
* @return true if the event might not propagate anymore
*/
bool onReplace(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const std::string& _data,
const appl::Buffer::Iterator& _posEnd);
/**
* @brief Called when data is removed.
* @param[in] _widget Reference on the widget caller.
* @param[in] _pos Position in the buffer where data might be witten.
* @param[in] _posEnd end replace position.
* @return true if the event might not propagate anymore
*/
bool onRemove(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const appl::Buffer::Iterator& _posEnd);
/**
* @brief Called when a message arrive.
* @param[in] _widget Reference on the widget caller.
* @param[in] _msg Generic message.
* @return true if the event might not propagate anymore
*/
bool onReceiveMessage(appl::TextViewer& _textDrawer,
const ewol::EMessage& _msg);
/**
* @brief Called when Cursor move of position.
* @param[in] _widget Reference on the widget caller.
* @param[in] _pos New cursor position.
* @return true if the event might not propagate anymore
*/
bool onCursorMove(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos);
};
};
#endif

View File

@@ -0,0 +1,96 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/TextPluginMultiLineTab.h>
#include <ewol/clipBoard.h>
#include <appl/Gui/TextViewer.h>
#undef __class__
#define __class__ "TextPluginMultiLineTab"
appl::TextPluginMultiLineTab::TextPluginMultiLineTab(void) {
m_activateOnEventEntry = true;
}
bool appl::TextPluginMultiLineTab::onEventEntry(appl::TextViewer& _textDrawer,
const ewol::EventEntry& _event) {
if (isEnable() == false) {
return false;
}
if (_event.getType() != ewol::keyEvent::keyboardChar) {
return false;
}
//APPL_DEBUG("KB EVENT : \"" << UTF8_data << "\" size=" << strlen(UTF8_data) << "type=" << (int32_t)typeEvent);
if (_event.getStatus() != ewol::keyEvent::statusDown) {
return false;
}
char32_t localValue = _event.getChar();
if (localValue != etk::UChar::Tabulation) {
return false;
}
if (_textDrawer.hasTextSelected() == false) {
return false;
}
appl::Buffer::Iterator itStart = _textDrawer.selectStart();
appl::Buffer::Iterator itStop = _textDrawer.selectStop();
// get the compleate section of the buffer :
itStart = _textDrawer.getStartLine(itStart);
itStop = _textDrawer.getEndLine(itStop);
// copy the curent data in a classicle string:
std::string data;
_textDrawer.copy(data, itStart, itStop);
// TODO : Change this ...
bool m_useTabs = true;
int32_t m_tabDist = 4;
if (true == _event.getSpecialKey().isSetShift() ) {
// un-indent
data.insert(0, 1, etk::UChar::Return);
for (int32_t iii=1; iii<data.size(); ++iii) {
if (data[iii-1] != etk::UChar::Return) {
continue;
}
if(data[iii] == etk::UChar::Tabulation) {
data.erase(iii, 1);
} else if(data[iii] == etk::UChar::Space) {
for (int32_t jjj=0; jjj<m_tabDist && jjj+iii<data.size() ; jjj++) {
if(data[iii] == etk::UChar::Space) {
data.erase(iii, 1);
} else if(data[iii] == etk::UChar::Tabulation) {
data.erase(iii, 1);
break;
} else {
break;
}
}
}
}
data.erase(0, 1);
} else {
// indent
data.insert(0, 1, etk::UChar::Return);
for (int32_t iii=1; iii<data.size(); iii++) {
if (data[iii-1] != etk::UChar::Return) {
continue;
}
if (true == _event.getSpecialKey().isSetCtrl() ) {
data.insert(iii, 1, etk::UChar::Space);
} else if (true == m_useTabs) {
data.insert(iii, 1, etk::UChar::Tabulation);
} else {
data.insert(iii, m_tabDist, etk::UChar::Space);
}
}
data.erase(0, 1);
}
// Real replace of DATA :
_textDrawer.replace(data, itStart, itStop);
_textDrawer.select(itStart, itStart+data.size());
return true;
}

View File

@@ -0,0 +1,33 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __APPL_TEXT_PLUGIN_MULTI_LINE_TAB_H__
#define __APPL_TEXT_PLUGIN_MULTI_LINE_TAB_H__
#include <etk/types.h>
#include <ewol/renderer/EObject.h>
#include <appl/Gui/TextViewer.h>
#include <ewol/compositing/Text.h>
#include <appl/TextPlugin.h>
namespace appl {
class TextPluginMultiLineTab : public appl::TextViewerPlugin {
public:
TextPluginMultiLineTab(void);
~TextPluginMultiLineTab(void) {
// nothing to do ...
};
public:
virtual bool onEventEntry(appl::TextViewer& _textDrawer,
const ewol::EventEntry& _event);
};
};
#endif

View File

@@ -0,0 +1,53 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/TextPluginRmLine.h>
#include <ewol/clipBoard.h>
#include <appl/Gui/TextViewer.h>
#undef __class__
#define __class__ "TextPluginRmLine"
appl::TextPluginRmLine::TextPluginRmLine(void) {
m_activateOnReceiveMessage = true;
}
void appl::TextPluginRmLine::onPluginEnable(appl::TextViewer& _textDrawer) {
// add event :
_textDrawer.ext_registerMultiCast(ednMsgGuiRm);
_textDrawer.ext_shortCutAdd("ctrl+w", ednMsgGuiRm);
}
void appl::TextPluginRmLine::onPluginDisable(appl::TextViewer& _textDrawer) {
// TODO : unknow function ...
}
bool appl::TextPluginRmLine::onReceiveMessage(appl::TextViewer& _textDrawer,
const ewol::EMessage& _msg) {
if (isEnable() == false) {
return false;
}
if (_msg.getMessage() == ednMsgGuiRm) {
if (_textDrawer.hasBuffer() == false) {
return false;
}
if (_textDrawer.hasTextSelected() == true) {
appl::Buffer::Iterator start = _textDrawer.getStartLine(_textDrawer.selectStart());
appl::Buffer::Iterator end = _textDrawer.getEndLine(_textDrawer.selectStop())+1;
_textDrawer.replace("", start, end);
} else {
appl::Buffer::Iterator start = _textDrawer.getStartLine(_textDrawer.cursor());
appl::Buffer::Iterator end = _textDrawer.getEndLine(_textDrawer.cursor())+1;
_textDrawer.replace("", start, end);
}
return true;
}
return false;
}

View File

@@ -0,0 +1,33 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __APPL_TEXT_RM_LINE_H__
#define __APPL_TEXT_RM_LINE_H__
#include <etk/types.h>
#include <ewol/renderer/EObject.h>
#include <appl/Gui/TextViewer.h>
#include <ewol/compositing/Text.h>
#include <appl/TextPlugin.h>
namespace appl {
class TextPluginRmLine : public appl::TextViewerPlugin {
public:
TextPluginRmLine(void);
~TextPluginRmLine(void) {
// nothing to do ...
};
public:
virtual void onPluginEnable(appl::TextViewer& _textDrawer);
virtual void onPluginDisable(appl::TextViewer& _textDrawer);
virtual bool onReceiveMessage(appl::TextViewer& _textDrawer, const ewol::EMessage& _msg);
};
};
#endif

View File

@@ -0,0 +1,47 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/TextPluginSelectAll.h>
#include <ewol/clipBoard.h>
#include <appl/Gui/TextViewer.h>
#undef __class__
#define __class__ "TextPluginSelectAll"
appl::TextPluginSelectAll::TextPluginSelectAll(void) {
m_activateOnReceiveMessage = true;
}
static const char* eventSelectAll = "plugin-select-all";
void appl::TextPluginSelectAll::onPluginEnable(appl::TextViewer& _textDrawer) {
// add event :
_textDrawer.ext_registerMultiCast(eventSelectAll);
_textDrawer.ext_shortCutAdd("ctrl+a", eventSelectAll);
}
void appl::TextPluginSelectAll::onPluginDisable(appl::TextViewer& _textDrawer) {
// TODO : unknow function ...
}
bool appl::TextPluginSelectAll::onReceiveMessage(appl::TextViewer& _textDrawer,
const ewol::EMessage& _msg) {
if (isEnable() == false) {
return false;
}
if (_msg.getMessage() == eventSelectAll) {
if (_textDrawer.hasBuffer() == false) {
return false;
}
_textDrawer.select(_textDrawer.begin(), _textDrawer.end());
return true;
}
return false;
}

View File

@@ -0,0 +1,33 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __APPL_TEXT_PLUGIN_SELECT_ALL_H__
#define __APPL_TEXT_PLUGIN_SELECT_ALL_H__
#include <etk/types.h>
#include <ewol/renderer/EObject.h>
#include <appl/Gui/TextViewer.h>
#include <ewol/compositing/Text.h>
#include <appl/TextPlugin.h>
namespace appl {
class TextPluginSelectAll : public appl::TextViewerPlugin {
public:
TextPluginSelectAll(void);
~TextPluginSelectAll(void) {
// nothing to do ...
};
public:
virtual void onPluginEnable(appl::TextViewer& _textDrawer);
virtual void onPluginDisable(appl::TextViewer& _textDrawer);
virtual bool onReceiveMessage(appl::TextViewer& _textDrawer, const ewol::EMessage& _msg);
};
};
#endif

View File

@@ -1,284 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/Debug.h>
#include <appl/global.h>
#include <CTagsManager.h>
#include <BufferManager.h>
#include <ewol/renderer/EObject.h>
#include <ewol/renderer/eContext.h>
#include <ewol/widget/meta/FileChooser.h>
#include <appl/Gui/TagFileSelection.h>
// TODO : The line ID is no more stored in the file system (FSNode) ...
#undef __class__
#define __class__ "CTagsManager"
class CTagsManager: public ewol::EObject
{
public:
// Constructeur
CTagsManager(void);
~CTagsManager(void);
const char * const GetObjectType(void)
{
return "CTagsManager";
};
void OnReceiveMessage(const ewol::EMessage& _msg);
int32_t m_currentSelectedID;
void LoadTagFile(void);
int32_t MultipleJump(void);
void JumpTo(void);
void PrintTag(const tagEntry *entry);
etk::UString GetFolder(etk::UString &inputString);
etk::UString m_tagFolderBase;
etk::UString m_tagFilename;
tagFile * m_ctagFile;
// history system
int32_t m_historyPos;
etk::Vector<etk::FSNode*> m_historyList;
void RegisterHistory(void);
};
static CTagsManager* s_elementPointer = NULL;
void cTagsManager::Init(void)
{
if (NULL != s_elementPointer) {
s_elementPointer = NULL;
EWOL_WARNING("Ctags manager already instanciate ... ==> restart IT (can have memory leek ...)");
}
s_elementPointer = new CTagsManager();
if (NULL == s_elementPointer) {
EWOL_ERROR("Ctags manager error to instanciate ...");
}
}
void cTagsManager::UnInit(void)
{
if (NULL != s_elementPointer) {
delete(s_elementPointer);
s_elementPointer = NULL;
} else {
EWOL_ERROR("Ctags manager not instanciate ... ==> can not remove it ...");
}
}
/**
* @brief
*
* @param[in,out] ---
*
* @return ---
*
*/
CTagsManager::CTagsManager(void)
{
m_tagFilename = "";
m_tagFolderBase = "";
m_ctagFile = NULL;
m_historyPos = 0;
RegisterMultiCast(ednMsgGuiCtags);
RegisterMultiCast(ednMsgBufferId);
RegisterMultiCast(ednMsgCtagsLoadFile);
EWOL_INFO("Ctags manager (INIT)");
}
/**
* @brief
*
* @param[in,out] ---
*
* @return ---
*
*/
CTagsManager::~CTagsManager(void)
{
EWOL_INFO("Ctags manager (Un-INIT)");
if(0 != m_historyList.Size()) {
for (int32_t iii=0; iii< m_historyList.Size(); iii++) {
delete(m_historyList[iii]);
}
m_historyList.Clear();
}
}
const char * ednEventPopUpCtagsLoadFile = "edn-event-load-ctags";
void CTagsManager::OnReceiveMessage(const ewol::EMessage& _msg)
{
//EWOL_INFO("ctags manager event ... : \"" << eventId << "\" ==> data=\"" << data << "\"" );
if (_msg.GetMessage() == ednMsgBufferId) {
//m_currentSelectedID = dataID;
} else if( _msg.GetMessage() == ednEventPopUpCtagsLoadFile
|| _msg.GetMessage() == ednMsgCtagsLoadFile) {
// open the new one :
etk::FSNode tmpFilename = _msg.GetData();
m_tagFilename = tmpFilename.GetNameFile();
m_tagFolderBase = tmpFilename.GetNameFolder();
APPL_DEBUG("Receive load Ctags file : " << m_tagFolderBase << "/" << m_tagFilename << " ");
LoadTagFile();
} else if (_msg.GetMessage() == ednMsgGuiCtags) {
if (_msg.GetData() == "Load") {
APPL_INFO("Request opening ctag file");
widget::FileChooser* tmpWidget = new widget::FileChooser();
if (NULL == tmpWidget) {
APPL_ERROR("Can not allocate widget ==> display might be in error");
} else {
tmpWidget->SetTitle("Open Exuberant Ctags File");
tmpWidget->SetValidateLabel("Open");
ewol::GetContext().GetWindows()->PopUpWidgetPush(tmpWidget);
tmpWidget->RegisterOnEvent(this, ewolEventFileChooserValidate, ednEventPopUpCtagsLoadFile);
}
} else if (_msg.GetData() == "ReLoad") {
APPL_INFO("Request re-load ctag file");
LoadTagFile();
} else if (_msg.GetData() == "Jump") {
JumpTo();
} else if (_msg.GetData() == "Back") {
if (m_historyList.Size() > 0) {
int32_t id = m_historyList.Size()-1;
SendMultiCast(ednMsgOpenFile, m_historyList[id]->GetName() );
SendMultiCast(ednMsgGuiGotoLine, 0);// TODO : m_historyList[id]->GetLineNumber());
// Remove element ....
delete(m_historyList[id]);
m_historyList[id]=NULL;
m_historyList.PopBack();
}
} else {
}
} else if (_msg.GetMessage() == applEventctagsSelection) {
// save the current file in the history
RegisterHistory();
// parse the input data
char tmp[4096];
int32_t lineID;
sscanf(_msg.GetData().c_str(), "%d:%s", &lineID, tmp);
// generate envents
SendMultiCast(ednMsgOpenFile, tmp);
SendMultiCast(ednMsgGuiGotoLine, lineID - 1);
}
}
void CTagsManager::LoadTagFile(void)
{
tagFileInfo info;
// close previous tag file
if (NULL != m_ctagFile) {
tagsClose(m_ctagFile);
m_ctagFile = NULL;
}
if (m_tagFilename == "") {
return;
}
// load (open) the tag file :
APPL_INFO("try to open tag file : " << m_tagFilename);
m_ctagFile = tagsOpen(m_tagFilename.c_str(), &info);
if (NULL != m_ctagFile) {
APPL_INFO("open exuberant Ctags file is OK ...");
} else {
APPL_INFO("Error to open ctags file ...");
}
}
void CTagsManager::RegisterHistory(void)
{
APPL_INFO("save curent filename and position : ");
int32_t currentSelected = BufferManager::GetSelected();
BufferText* tmpBuf = BufferManager::Get(currentSelected);
if (NULL != tmpBuf) {
etk::FSNode * bufferFilename = new etk::FSNode();
*bufferFilename = tmpBuf->GetFileName();
// TODO : bufferFilename->SetLineNumber(tmpBuf->GetCurrentLine());
m_historyList.PushBack(bufferFilename);
}
}
void CTagsManager::JumpTo(void)
{
if (NULL != m_ctagFile) {
// get the middle button of the clipboard ==> represent the current selection ...
etk::UString data = ewol::clipBoard::Get(ewol::clipBoard::clipboardSelection);
APPL_DEBUG("clipboard data : \"" << data << "\"");
if (data.Size() == 0) {
APPL_INFO("No current selection");
}
tagEntry entry;
APPL_INFO("try to find the tag : " << data);
if (tagsFind (m_ctagFile, &entry, data.c_str(), 0) == TagSuccess) {
tagEntry entrySave = entry;
int32_t numberOfTags = 0;
// For all tags : Save in an internal Structure :
etk::UString tmpFile(m_tagFolderBase + "/" + entry.file);
etk::FSNode myfile(tmpFile);
int32_t lineID = entry.address.lineNumber;
PrintTag(&entry);
if (tagsFindNext (m_ctagFile, &entry) == TagSuccess) {
APPL_INFO("Multiple file destination ...");
appl::TagFileSelection* tmpWidget = new appl::TagFileSelection();
if (NULL == tmpWidget) {
APPL_ERROR("Can not allocate widget ==> display might be in error");
} else {
tmpWidget->AddCtagsNewItem(myfile.GetName(), lineID);
do {
tmpFile = m_tagFolderBase + "/" + entry.file;
myfile = tmpFile;
lineID = entry.address.lineNumber;
PrintTag(&entry);
tmpWidget->AddCtagsNewItem(myfile.GetName(), lineID);
} while (tagsFindNext (m_ctagFile, &entry) == TagSuccess);
ewol::GetContext().GetWindows()->PopUpWidgetPush(tmpWidget);
tmpWidget->RegisterOnEvent(this, applEventctagsSelection);
}
} else {
RegisterHistory();
APPL_INFO(" OPEN the TAG file Destination : " << tmpFile );
SendMultiCast(ednMsgOpenFile, myfile.GetName());
SendMultiCast(ednMsgGuiGotoLine, lineID - 1);
}
} else {
APPL_INFO("no tag find ...");
}
}
}
void CTagsManager::PrintTag(const tagEntry *entry)
{
#if 1
APPL_INFO("find Tag file : name=\"" << entry->name << "\" in file=\"" << entry->file
<< "\" at line="<< (int32_t)entry->address.lineNumber);
#else
int i;
APPL_INFO("find Tag file : name=\"" << entry->name << "\" in file=\"" << entry->file
<< "\" pattern=\"" << entry->address.pattern
<< "\" at line="<< (int32_t)entry->address.lineNumber);
APPL_INFO("Extention field : ");
if (entry->kind != NULL && entry->kind [0] != '\0') {
APPL_INFO(" kind : " << entry->kind);
}
if (entry->fileScope) {
APPL_INFO(" file : ");
}
for (i = 0 ; i < entry->fields.count ; ++i) {
APPL_INFO(" " << entry->fields.list[i].key << ":" << entry->fields.list[i].value );
}
#endif
}

View File

@@ -1,26 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __C_TAGS_MANAGER_H__
#define __C_TAGS_MANAGER_H__
#include <ewol/widget/Widget.h>
#include "appl/globalMsg.h"
#include "readtags.h"
#define MAX_REG_EXP_SEARCH (1024)
namespace cTagsManager
{
void Init(void);
void UnInit(void);
};
#endif

Some files were not shown because too many files have changed in this diff Show More