Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
illa4257 committed Jul 12, 2021
1 parent 868ad28 commit 925a5c8
Show file tree
Hide file tree
Showing 18 changed files with 149 additions and 61 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# dn-TextEditor (NoPackage)
# dn-TextEditor (No bundle)
Text editor written in jphp in DevelNext. This project was created to test the canvas, add and modify for your projects.

[**Project at hub.develnext.org**](https://hub.develnext.org/project/jVezjlJACbVB)
4 changes: 2 additions & 2 deletions dnProject/.dn/backup.conf
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#Mon Jul 12 00:02:07 EEST 2021
#Mon Jul 12 23:43:57 EEST 2021
autoOpenTrigger=
autoCloseTrigger=1
autoIntervalTriggerTime=240000
masterDefault=dev
autoAmountMaxInSession=8
autoIntervalTrigger=1
autoAmountMax=12
autoIntervalTrigger=1
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#Mon Jul 12 00:02:07 EEST 2021
#Mon Jul 12 23:43:57 EEST 2021
env=dev
2 changes: 1 addition & 1 deletion dnProject/.dn/bundles/ide.bundle.std.UIDesktopBundle.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#Mon Jul 12 00:02:07 EEST 2021
#Mon Jul 12 23:43:57 EEST 2021
env=all
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Mon Jul 12 00:12:29 EEST 2021
#Mon Jul 12 23:43:57 EEST 2021
snapType=HIDDEN
blockedNodes=
zoom=100
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sun Jul 11 02:37:16 EEST 2021
#Mon Jul 12 23:43:57 EEST 2021
snapType=HIDDEN
blockedNodes=
snapSizeY=8
zoom=100
snapSizeY=8
snapSizeX=8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Mon Jul 12 00:12:26 EEST 2021
#Mon Jul 12 00:33:36 EEST 2021
snapType=HIDDEN
blockedNodes=
snapSizeY=8
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#Mon Jul 12 00:02:07 EEST 2021
#Mon Jul 12 23:43:57 EEST 2021
useImports=
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#Mon Jul 12 00:02:07 EEST 2021
#Mon Jul 12 23:43:57 EEST 2021
compileByteCode=
importType=package
2 changes: 1 addition & 1 deletion dnProject/.dn/library.conf
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#Mon Jul 12 00:02:07 EEST 2021
#Mon Jul 12 23:43:57 EEST 2021
2 changes: 1 addition & 1 deletion dnProject/.dn/project.ws
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#Mon Jul 12 00:02:07 EEST 2021
#Mon Jul 12 23:43:57 EEST 2021
projectArchive.uid=jVezjlJACbVB
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project author="i0972" authorOS="Windows 10" createdAt="1625773010180" ideName="DevelNext" ideVersion="16.7.0" ideVersionHash="2017103112" name="TextEditor v0.9.2" packageName="app" template="ide\project\templates\DefaultGuiProjectTemplate" updatedAt="1626037327173">
<project author="i0972" authorOS="Windows 10" createdAt="1625773010180" ideName="DevelNext" ideVersion="16.7.0" ideVersionHash="2017103112" name="TextEditor v1.0" packageName="app" template="ide\project\templates\DefaultGuiProjectTemplate" updatedAt="1626122637714">
<tree>
<expanded>
<path src=""/>
Expand All @@ -11,8 +11,7 @@
</expanded>
</tree>
<openedFiles>
<file selected="1" src="TextEditor v0.9.2.dnproject"/>
<file src="src/app/forms/Editor.php"/>
<file selected="1" src="TextEditor v1.0.dnproject"/>
</openedFiles>
<files/>
<behaviours>
Expand Down
2 changes: 1 addition & 1 deletion dnProject/src/.system/application.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MAIN CONFIGURATION

app.name = TextEditor v0.9.2
app.name = TextEditor v0.9.2.1
app.uuid = b5b21ab7-d7c9-42fd-a4be-a94678121c11
app.version = 1

Expand Down
4 changes: 2 additions & 2 deletions dnProject/src/app/forms/Editor.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#Mon Jul 12 00:12:29 EEST 2021
#Mon Jul 12 23:34:24 EEST 2021
form.style=DECORATED
form.title=Editor
form.title=new
2 changes: 2 additions & 0 deletions dnProject/src/app/forms/Editor.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
</items>
</ComboBox>
<Data cursor="DEFAULT" enabled="1" id="data-combobox" visible="1"/>
<org.develnext.jphp.ext.javafx.support.control.NumberSpinner alignment="CENTER_LEFT" arrowsStyle="RIGHT_VERTICAL" editable="false" focusTraversable="false" id="fontSize" initial="20" layoutX="96" layoutY="0" max="30" min="5" prefHeight="24" prefWidth="56" step="1" styleClass="spinner "/>
<Data cursor="DEFAULT" enabled="1" id="data-fontSize" visible="1"/>
</children>
</AnchorPane>
144 changes: 103 additions & 41 deletions dnProject/src/app/forms/Editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class Editor extends AbstractForm
* @var File
*/
public $file;

public $focused = false;
public $saved = true;

/**
* @var UXGraphicsContext
Expand Down Expand Up @@ -56,6 +56,30 @@ private function getIndexLine($x=-1){
if($x==-1) $x = $this->selection["x"];
return max(arr::count(explode("\n",str::sub($this->text,0,$x)))-1,0);
}

private function getBGLW(){ return $this->gc->font->calculateTextWidth((string)max(arr::count(explode("\n",$this->text))-1,0))+$this->settings["bgLineOffset"]*2; }

private function editedFile(){
$this->title="*".($this->file ? $this->file->getName() : "new");
$this->saved=false;
}

/**
* @return bool
*/
public function save(){
if($this->file==null){
$fc = new FileChooserScript;
$fc->saveDialog=true;
$fc->initialFileName="new.txt";
if($file=$fc->execute()) $this->file = $file;
}
if($this->file and file_put_contents(fs::abs($this->file),$this->text)!==false){
$this->title=$this->file->getName();
return $this->saved=true;
}
return false;
}

/**
* @event canvas.step
Expand All @@ -68,9 +92,14 @@ function doCanvasStep(UXEvent $e = null){
$this->gc = $this->canvas->gc();
$this->combobox->value = $this->gc->font->family;
foreach (UXFont::getFamilies() as $f) $this->combobox->items->add($f);
$this->fontSize->value=$this->gc->font->size;
$this->update=true;
$this->canvas->observer("width")->addListener(function (){$this->update=true;});
$this->canvas->observer("height")->addListener(function (){$this->update=true;});
$this->fontSize->observer("value")->addListener(function($old,$new){
$this->gc->font=$this->gc->font->withSize($new);
$this->update=true;
});
}
$cur = "TEXT";
$w = $this->canvas->width;
Expand All @@ -81,7 +110,7 @@ function doCanvasStep(UXEvent $e = null){
$tlo = $this->settings["lineOffset"];
$bglo = $this->settings["bgLineOffset"];
$wo = 32;
$bglw = $gc->font->calculateTextWidth((string)max(arr::count(explode("\n",$this->text))-1,0))+$bglo*2;
$bglw=$this->getBGLW();
$gc->fillColor = $cols["bg"];
$gc->fillRect($bglw-1,0,$w-$bglw+1,$h);
$l = -1;
Expand All @@ -100,36 +129,39 @@ function doCanvasStep(UXEvent $e = null){
$l+=str::length($line)+1;
$ly=$y*($gc->font->size+$to)+$to-$this->scrollY;
$ty=$ly+$gc->font->size;

$render=($ty+$gc->font->size*2>0 and $ly<$h);
if($this->selection["s"]){
$x=$bglw+$tlo-$this->scrollX;
$ws=$gc->font->calculateTextWidth($line);
if($l>=$this->selection["sx"] and $this->selection["sx"]>=$ol){
$b=true;
$x+=$gc->font->calculateTextWidth(str::sub($line,0,$this->selection["sx"]-$ol));
$ws-=$gc->font->calculateTextWidth(str::sub($line,0,$this->selection["sx"]-$ol));
if($render){
$x+=$gc->font->calculateTextWidth(str::sub($line,0,$this->selection["sx"]-$ol));
$ws-=$gc->font->calculateTextWidth(str::sub($line,0,$this->selection["sx"]-$ol));
}
}
$r=$b;
if($l>=$this->selection["sx"]+$this->selection["l"]){
$b=false;
$ws-=$gc->font->calculateTextWidth(str::sub($line,$this->selection["sx"]+$this->selection["l"]-$ol));
if($render) $ws-=$gc->font->calculateTextWidth(str::sub($line,$this->selection["sx"]+$this->selection["l"]-$ol));
}
if($r){
if($r and $render){
$gc->fillColor = $cols["sc"];
$gc->fillRect($x,$ly,$ws,$gc->font->size+$to);
}
}
if($ol<=$this->selection["x"] and $l>=$this->selection["x"]){
if($ol<=$this->selection["x"] and $l>=$this->selection["x"] and $render){
$gc->fillColor = $cols["ec"];
$gc->fillRect($bglw+$tlo-$this->scrollX+$gc->font->calculateTextWidth(str::sub($line,0,$this->selection["x"]-$ol)),$ly,2,$gc->font->size+$to);
}
$gc->fillColor=$cols["tc"];
$gc->fillText($line,$bglw+$tlo-$this->scrollX,$ty);

$gc->fillColor = $cols["bgl"];
$gc->fillRect(0,$ly,$bglw,$gc->font->size+$to);
$gc->fillColor=$cols["tcl"];
$gc->fillText($y,$bglw-($gc->font->calculateTextWidth($y)+$bglo),$ty);
if($render){
$gc->fillColor=$cols["tc"];
$gc->fillText($line,$bglw+$tlo-$this->scrollX,$ty);
$gc->fillColor = $cols["bgl"];
$gc->fillRect(0,$ly,$bglw,$gc->font->size+$to);
$gc->fillColor=$cols["tcl"];
$gc->fillText($y,$bglw-($gc->font->calculateTextWidth($y)+$bglo),$ty);
}
}
$gc->fillColor=$cols["bgs"];
$gc->fillRect($w-16,0,16,$h-16);
Expand All @@ -146,6 +178,7 @@ function doCanvasStep(UXEvent $e = null){
if($this->xmode) $cur="DEFAULT";
$gc->fillColor=($this->cy>$h-16 and $hsx+$hs>$this->cx and $this->cx>$hsx) ? $cols["bgsbh"] : $cols["bgsb"];
$gc->fillRect($hsx,$h-16,$hs,$hs);
if($this->cx<$bglw) $cur="DEFAULT";
$this->canvas->cursor=$cur;
}

Expand Down Expand Up @@ -289,15 +322,15 @@ function doCanvasKeyDown(UXKeyEvent $e = null){
$this->selection["x"]-=$this->selection["l"];
if($this->selection["x"]<0) $this->selection["x"]=0; }
}else $this->selection["x"]-=$this->selection["x"]>0 ? 1 : 0;
$this->update=true; $this->scroll();
$this->editedFile(); $this->update=true; $this->scroll();
}elseif($e->codeName=="Delete"){ $this->skip = true;
$this->text=$this->selection["s"] ? str::sub($this->text,0,$this->selection["sx"]).str::sub($this->text,$this->selection["sx"]+$this->selection["l"]) : str::sub($this->text,0,$this->selection["x"]).str::sub($this->text,$this->selection["x"]+1);
if($this->selection["s"]){ $this->selection["s"]=false;
if($this->selection["x"]!=$this->selection["sx"]){
$this->selection["x"]-=$this->selection["l"];
if($this->selection["x"]<0) $this->selection["x"]=0; }
}
$this->update=true;
$this->editedFile(); $this->update=true;
}elseif($e->codeName=="Home"){
$this->update=true;
$this->selection["x"]=str::lastPos(str::sub($this->text,0,$x=$this->selection["x"]),"\n")+1;
Expand Down Expand Up @@ -372,7 +405,7 @@ function doCanvasKeyDown(UXKeyEvent $e = null){
if($this->selection["s"]){
UXClipboard::setText(str::sub($this->text,$this->selection["sx"],$this->selection["sx"]+$this->selection["l"]));
$this->text=str::sub($this->text,0,$this->selection["sx"]).str::sub($this->text,$this->selection["sx"]+$this->selection["l"]);
$this->update=true; $this->scroll();
$this->editedFile(); $this->update=true; $this->scroll();
}
break;
case "C":
Expand All @@ -384,22 +417,13 @@ function doCanvasKeyDown(UXKeyEvent $e = null){
if($this->selection["s"]){
if($this->selection["sx"]!=$this->selection["x"]) $this->selection["x"]-=$this->selection["l"];
$this->selection["s"]=false; }
$this->selection["x"]+=str::length($cb); $this->update=true; $this->scroll(); $this->selection["o"]=0; break;
$this->selection["x"]+=str::length($cb); $this->editedFile(); $this->update=true; $this->scroll(); $this->selection["o"]=0; break;
case "A":
$this->selection["s"]=true; $this->selection["sx"]=0;
$this->selection["x"]=$this->selection["l"]=str::length($this->text);
$this->update=true; $this->scroll(); $this->selection["o"]=0; break;
case "S":
if($this->file==null){
$fc = new FileChooserScript;
$fc->saveDialog=true;
$fc->initialFileName="new.txt";
if($file=$fc->execute()) $this->file = $file;
}
if($this->file!=null){
file_put_contents(fs::abs($this->file),$this->text);
alert("Файл ".fs::name($this->file)." cохранён!");
}
$this->save();
break;
}
$this->skip=true;
Expand All @@ -410,14 +434,14 @@ function doCanvasKeyDown(UXKeyEvent $e = null){
* @event canvas.keyPress
*/
function doCanvasKeyPress(UXKeyEvent $e = null){
if($this->skip){ $this->skip=false; return; }
$chr=str::lines($e->character)[0]=="" ? "\n" : $e->character;
if($this->skip){ $this->skip=false; return; } $chr=$e->character;
if(str::lines($chr)[0]=="") $chr=$this->getIndexLine()>=0 ? "\n".str::sub($this->getLine(),0,str::pos($this->getLine()."a",str_replace([" ","\t"],"",$this->getLine()."a")[0])) : "\n";
$this->text = $this->selection["s"] ? str::sub($this->text,0,$this->selection["sx"]).$chr.str::sub($this->text,$this->selection["sx"]+$this->selection["l"]) : str::sub($this->text,0,$this->selection["x"]).$chr.str::sub($this->text,$this->selection["x"]);
if($this->selection["s"]){ $this->selection["s"] = false;
if($this->selection["x"]!=$this->selection["sx"]) $this->selection["x"]-=$this->selection["l"];
$this->selection["x"]+=str::length($chr);
}else $this->selection["x"]+=str::length($chr);
if(str::length($chr)>0){ $this->update=true; $this->scroll(); $this->selection["o"]=0; }
if(str::length($chr)>0){ $this->editedFile(); $this->update=true; $this->scroll(); $this->selection["o"]=0; }
}

/**
Expand All @@ -433,30 +457,68 @@ function doCanvasMouseExit(UXMouseEvent $e = null){ $this->cx=$this->cy=-1; $thi
/**
* @event canvas.scroll
*/
function doCanvasScroll(UXScrollEvent $e = null){
if($this->xmode) $this->scrollX-=$e->deltaY; else $this->scrollY-=$e->deltaY;
$this->scrollX-=$e->deltaX; $this->update=true;
}
function doCanvasScroll(UXScrollEvent $e = null){ if($this->xmode) $this->scrollX-=$e->deltaY; else $this->scrollY-=$e->deltaY; $this->scrollX-=$e->deltaX; $this->update=true; }

private $dc = 0;
private $sp = [0,0];
private $dur = 0;
private function calcX($pos){
$li = min(floor(($pos[1]+$this->scrollY)/($this->gc->font->size+$this->settings["textOffset"])-0.25),arr::count(explode("\n",$this->text)));
$x=0;
for($i=0;$i<$li;$i++) $x+=str::length($this->getLine($i))+1;
$ww=$this->gc->font->calculateTextWidth($this->getLine($i));
$wl=str::length($this->getLine($i));
$bglw=$this->getBGLW();
$i=0;
while($i<$wl and $this->gc->font->calculateTextWidth(str::sub($this->getLine($li),0,$i+1))<$pos[0]+$this->scrollX-$bglw) $i++;
$x+=$i;
return min($x,str::length($this->text));
}

/**
* @event canvas.mouseDrag
*/
function doCanvasMouseDrag(UXMouseEvent $e = null)
{
function doCanvasMouseDrag(UXMouseEvent $e = null){
$w=$this->canvas->width;
$h=$this->canvas->height;
if($w-16<$this->sp[0] and $h-16>$this->sp[1]) $this->scrollY=(1/($h-16)*$e->y)*$this->maxScrollY;
if($h-16<$this->sp[1] and $w-16>$this->sp[0]) $this->scrollX=(1/($w-16)*$e->x)*$this->maxScrollX;
if($w-16<$this->sp[0] and $h-16>$this->sp[1])
$this->scrollY=(1/($h-16)*$e->y)*$this->maxScrollY;
elseif($h-16<$this->sp[1] and $w-16>$this->sp[0])
$this->scrollX=(1/($w-16)*$e->x)*$this->maxScrollX;
else{
$x=$this->selection["x"];
$this->selection["x"]=$this->calcX($this->sp=[$e->x,$e->y]);
if(!$this->selection["s"]){
$this->selection["sx"]=$this->selection["x"]-$d;
$this->selection["l"]=0;
$this->dur=0;
}
$this->dur+=$this->selection["x"]-$x;
if($this->dur<0){
$this->selection["sx"]=$this->selection["x"];
$this->selection["l"]=-$this->dur;
}else{
$this->selection["sx"]=$this->selection["x"]-$this->dur;
$this->selection["l"]=$this->dur;
}
$this->selection["s"]=$this->selection["l"]>0;
}
$this->update=true;
}

/**
* @event canvas.mouseDown
*/
function doCanvasMouseDown(UXMouseEvent $e = null){ if($this->dc==0) $this->sp=[$e->x,$e->y]; $this->dc++; }
function doCanvasMouseDown(UXMouseEvent $e = null){
if($this->dc==0){
if(!($w-16<$this->sp[0] and $h-16>$this->sp[1]) and !($h-16<$this->sp[1] and $w-16>$this->sp[0])){
$this->selection["x"]=$this->calcX($this->sp=[$e->x,$e->y]);
$this->selection["s"]=false;
}
$this->update=true;
}
$this->dc++;
}

/**
* @event canvas.mouseUp
Expand Down
2 changes: 1 addition & 1 deletion dnProject/src/app/forms/MainForm.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Sat Jul 10 18:44:43 EEST 2021
#Mon Jul 12 23:42:25 EEST 2021
form.style=DECORATED
modules=
form.title=TextEditor
Expand Down
Loading

0 comments on commit 925a5c8

Please sign in to comment.