Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
silentdeath76 committed Sep 22, 2024
2 parents 9823c38 + a899215 commit 14b87d5
Show file tree
Hide file tree
Showing 19 changed files with 495 additions and 107 deletions.
10 changes: 5 additions & 5 deletions src/.theme/font.fx.css
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
@font-face {
font-family: 'Open Sans';
src: url('/.theme/font/OpenSans-Regular.ttf');
src: url('./font/OpenSans-Regular.ttf');
}

@font-face {
font-family: 'Open Sans Italic';
src: url('/.theme/font/OpenSans-Italic.ttf');
src: url('./font/OpenSans-Italic.ttf');
}

@font-face {
font-family: 'Open Sans Lighter';
src: url('/.theme/font/OpenSans-Light.ttf');
font-family: 'Open Sans Light';
src: url('./font/OpenSans-Light.ttf');
}

@font-face {
font-family: 'Open Sans Bold';
src: url('/.theme/font/OpenSans-Bold.ttf');
src: url('./font/OpenSans-Bold.ttf');
}
2 changes: 2 additions & 0 deletions src/.theme/style.fx.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

* {
-fx-font-family: 'Open Sans';
-fx-font-smoothing-type: lcd;
}

.root {
Expand All @@ -37,6 +38,7 @@
}

.about .title {
-fx-font-family: 'Open Sans Light';
-fx-font-size: 26px;
}

Expand Down
34 changes: 23 additions & 11 deletions src/app/FSTreeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,31 @@ public function __construct (UXTreeItem $rootTreeItem) {
public function setDirectory ($path) {
$this->selectedDirectory = $path;

fs::scan($path, ['extensions' => ['zip'], 'callback' => function (File $file) {
$filePath = str::sub($file->getAbsoluteFile(), strlen($this->selectedDirectory) + 1);
$this->zipFiles[$file->getAbsoluteFile()] = new ZipFile($file);
$items = explode(File::DIRECTORY_SEPARATOR, $filePath);
app()->form("MainForm")->showPreloader();

$th = new Thread(function () {
$r = fs::scan($this->selectedDirectory, ['extensions' => ['zip'], 'callback' => function (File $file) {
$filePath = str::sub($file->getAbsoluteFile(), strlen($this->selectedDirectory) + 1);
$this->zipFiles[$file->getAbsoluteFile()] = new ZipFile($file);
$items = explode(File::DIRECTORY_SEPARATOR, $filePath);

if ($file->isFile()) {
uiLater(function () use ($items, $filePath) {
$this->treeHelper->makeTree($this->rootItem, $items, function ($node, bool $isDir) use ($filePath) {
$this->applyIcon($node, ($isDir) ? FSTreeProvider::EMPTY_PATH_ELEMENT : $filePath);
});
});
}
}]);

if ($file->isFile()) {
$this->treeHelper->makeTree($this->rootItem, $items, function ($node, bool $isDir) use ($filePath) {
$this->applyIcon($node, ($isDir) ? FSTreeProvider::EMPTY_PATH_ELEMENT : $filePath);
});
}
}]);
uiLater(function () {
$this->treeHelper->sort($this->rootItem);
app()->form("MainForm")->hidePreloader();
});
});
$th->setDaemon(true);
$th->start();

$this->treeHelper->sort($this->rootItem);
}


Expand Down
63 changes: 63 additions & 0 deletions src/app/events/FSTreeEvents.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
namespace app\events;

use std;
use std;
use app;

class FSTreeEvents
{
public function onFileSystem (StandartFileSystem $provider, $path = null)
{
$this->getForm()->fileInfoPanel->updateFilePath($path);

$this->getForm()->fileInfoPanel->updateFileIcon($provider, $path);
$this->getForm()->updateFileinfo($provider, $path);
}

public function onZipFileSystem (ZipFileSystem $provider, $zipPath, $path)
{
$this->getForm()->fileInfoPanel->updateFilePath($zipPath);

$zipPath = $this->normalizeZipPath($provider, $zipPath);

$this->getForm()->fileInfoPanel->updateFileIcon($provider, $zipPath);

if ($provider->isFile($zipPath)) {
$provider->getZipInstance()->read($zipPath, function (array $stat, Stream $output) use ($zipPath) {
$this->getForm()->showMeta($stat);

$ext = $this->getForm()->getHighlightType(fs::ext($zipPath));

if ($this->getForm()->findOperation($zipPath, $output, $ext) === false) {
$this->getForm()->showCodeInBrowser($output->readFully(), $ext);
}
});

$this->getForm()->updateFileinfo($provider, $zipPath);
} else if ($provider->isDirectory($zipPath)) {
$this->getForm()->fileInfoPanel->updateFileSize("unknown");
}
}

private function normalizeZipPath ($provider, $zipPath)
{
if (!$provider->getZipInstance()->has($zipPath)) {
$zipPath = str_replace('\\', '/', $zipPath);

if (!$provider->getZipInstance()->has($zipPath)) {
$zipPath = str_replace('/', '\\', $zipPath);
}
}

return $zipPath;
}

/**
* @return MainForm
*/
private function getForm ()
{
return app()->form("MainForm");
}
}
12 changes: 6 additions & 6 deletions src/app/events/MainMenuEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class MainMenuEvents
{
public function selectedFolder () {
$dc = new UXDirectoryChooser();

if (($path = $dc->showDialog(app()->form("MainForm"))) == null) return;

app()->form("MainForm")->projectDir = $path;

try {
app()->form("MainForm")->ini->set('ProjectDirectory', $path);
$result = app()->form("MainForm")->ini->get('directoryList');
Expand All @@ -37,9 +37,9 @@ public function selectedFolder () {
} catch (Exception $ex) {
app()->form("MainForm")->errorAlert($ex);
}

app()->form("MainForm")->tree->root->children->clear();

try {
app()->form("MainForm")->fsTree->setDirectory($path);
} catch (Exception $ex) {
Expand Down Expand Up @@ -80,7 +80,7 @@ public function changeTheme ($ev, $menu, $themeList) {

public function about () {
if (!($this->overlayContainer instanceof OverlayContainer)) {
$this->overlayContainer = new OverlayContainer();
$this->overlayContainer = new BlurredOverlayContainer();
$this->overlayContainer->addContent(new AboutContainer());
app()->form("MainForm")->add($this->overlayContainer->getNode());
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/forms/MainForm.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<tabs>
<Tab text="Исходный код">
<content>
<AnchorPane focusTraversable="false" id="" maxHeight="-1" maxWidth="-1" minHeight="-1" minWidth="-1" prefHeight="426" prefWidth="647" styleClass="">
<AnchorPane focusTraversable="false" id="" maxHeight="-1" maxWidth="-1" minHeight="-1" minWidth="-1" prefHeight="416" prefWidth="647" styleClass="">
<children>
<WebView AnchorPane.bottomAnchor="0" AnchorPane.leftAnchor="0" AnchorPane.rightAnchor="-1" AnchorPane.topAnchor="0" focusTraversable="true" id="browser" layoutX="0" layoutY="0" prefHeight="408" prefWidth="640"/>
<Data contextMenuEnabled="" cursor="DEFAULT" enabled="1" id="data-browser" visible=""/>
Expand Down Expand Up @@ -38,7 +38,7 @@
</AnchorPane>
</content>
</ScrollPane>
<ScrollPane AnchorPane.bottomAnchor="0" AnchorPane.leftAnchor="0" AnchorPane.topAnchor="32" fitToHeight="true" fitToWidth="true" focusTraversable="false" hbarPolicy="NEVER" hvalue="0" id="leftCotainer" layoutX="0" layoutY="32" prefHeight="456" prefWidth="256" styleClass="scroll-pane " vbarPolicy="NEVER" vvalue="0">
<ScrollPane AnchorPane.bottomAnchor="0" AnchorPane.leftAnchor="0" AnchorPane.topAnchor="32" fitToHeight="true" fitToWidth="true" focusTraversable="false" hbarPolicy="NEVER" hvalue="0" id="leftContainer" layoutX="0" layoutY="32" prefHeight="456" prefWidth="256" styleClass="scroll-pane " vbarPolicy="NEVER" vvalue="0">
<content>
<AnchorPane focusTraversable="false" id="" maxHeight="-1" maxWidth="-1" minHeight="-1" minWidth="-1" prefHeight="456" prefWidth="256" styleClass="">
<children>
Expand All @@ -48,7 +48,7 @@
</AnchorPane>
</content>
</ScrollPane>
<Data cursor="DEFAULT" enabled="1" id="data-leftCotainer" visible="1"/>
<Data cursor="DEFAULT" enabled="1" id="data-leftContainer" visible="1"/>
<Data cursor="DEFAULT" enabled="1" id="data-rightContainer" visible="1"/>
</children>
</AnchorPane>
114 changes: 39 additions & 75 deletions src/app/forms/MainForm.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace app\forms;

use Error;
use php\gui\UXTitledPaneWrapper;
use Exception;
use php\compress\ZipFile;
Expand Down Expand Up @@ -36,6 +37,9 @@ class MainForm extends AbstractForm
* @var Fileinfo
*/
public $fileInfoPanel;


use OpertaionTrait;


/**
Expand All @@ -60,87 +64,23 @@ function doConstruct(UXEvent $e = null)

$this->projectDir = $this->ini->get('ProjectDirectory');

$this->leftCotainer->content->add(new SelectDirectoryCombobox()->getNode());
$this->leftContainer->content->add(new SelectDirectoryCombobox()->getNode());

try {
$this->fsTree->onFileSystem(function (StandartFileSystem $provider, $path = null) {
$this->fileInfoPanel->updateFilePath($path);

$this->fileInfoPanel->updateFileIcon($provider, $path);
$this->updateFileinfo($provider, $path);
});

$this->fsTree->onZipFileSystem(function (ZipFileSystem $provider, $zipPath, $path) {
$this->fileInfoPanel->updateFilePath($zipPath);

if (!$provider->getZipInstance()->has($zipPath)) {
$zipPath = str_replace('\\', '/', $zipPath);

if (!$provider->getZipInstance()->has($zipPath)) {
$zipPath = str_replace('/', '\\', $zipPath);
}
}

$this->fileInfoPanel->updateFileIcon($provider, $zipPath);

if ($provider->isFile($zipPath)) {
$provider->getZipInstance()->read($zipPath, function (array $stat, Stream $output) use ($zipPath) {
$this->showMeta($stat);

$ext = $this->getHighlightType(fs::ext($zipPath));

if (fs::ext($zipPath) === 'fxml') {
$output = (string) $output;
$this->_showForm($output, $this->image);
$this->tabPane->selectedIndex = 1;
} else if ($ext == 'image') {
$this->image->image = new UXImage($output);
$output = "Binary";
$this->tabPane->selectedIndex = 1;
} else {
switch (fs::ext($zipPath)) {
case 'zip':
case 'exe':
case 'jar':
case 'ttf':
$output = "Binary";
}

$this->tabPane->selectedIndex = 0;
}

$this->showCodeInBrowser($output, $ext);
});

$this->updateFileinfo($provider, $zipPath);
} else if ($provider->isDirectory($zipPath)) {
$this->fileInfoPanel->updateFileSize("unknown");
}
});

$treeEvents = new FSTreeEvents();
$this->fsTree->onFileSystem([$treeEvents, 'onFileSystem']);
$this->fsTree->onZipFileSystem([$treeEvents, 'onZipFileSystem']);
} catch (Exception $ex) {
$this->errorAlert($ex);
}

// splitter
$this->split = new UXSplitPane([$this->leftCotainer, $this->rightContainer]);
$this->split->position = [0, 0];
$this->split->topAnchor = 25;
$this->split->bottomAnchor = true;
$this->split->rightAnchor = true;
$this->split->leftAnchor = true;

$this->makeSplitter();
$this->add($this->split);
UXSplitPane::setResizeWithParent($this->leftContainer, false);


UXSplitPane::setResizeWithParent($this->leftCotainer, false);
// end spliter

// задержка у браузера перед отрисовкой страницы слишком долгая, по этому таймер в 0.5 скунду чтобы не мелькало
timer::after(500, function () { $this->browser->show(); });

$this->showCodeInBrowser('', 'html');

// фикс мигания экрана если окно развернуто на весь екран и выбрана не светлая тема
// фикс мигания экрана если окно развернуто на весь экран и выбрана не светлая тема
waitAsync(100, function () {
if ($this->ini->get("maximized") == 1) {
$this->maximized = true;
Expand Down Expand Up @@ -224,7 +164,7 @@ function doTreeClickRight(UXMouseEvent $e = null)
$contextRoot = new DirectoryContextMenu();

if ($this->fsTree->getFileByNode($this->tree->focusedItem) === false) {
// чтобы контексттоное меню не появлялось на директориях в архиве
// чтобы контекстное меню не появлялось на директориях в архиве
if ($this->tree->focusedItem->children->count() == 0) {
$context->showByNode($e);
}
Expand Down Expand Up @@ -257,6 +197,19 @@ function doClose(UXWindowEvent $e = null)
$this->ini->set("splitter", $this->split->dividerPositions);
}

/**
* @event show
*/
function doShow(UXWindowEvent $e = null)
{
// задержка у браузера перед отрисовкой страницы слишком долгая, по этому таймер в 0.5 скунду чтобы не мелькало
waitAsync(500, function () {
$this->browser->show();
});

$this->showCodeInBrowser('', 'html');
}



public function getHighlightType ($zipPath) {
Expand Down Expand Up @@ -288,20 +241,31 @@ public function updateFileinfo ($provider, $path) {
}


private function showCodeInBrowser ($output, $ext = 'config') {
public function showCodeInBrowser ($output, $ext = 'config') {
$output = str_replace(['<', '>'], ['&lt;', '&gt;'], $output);
$this->browser->engine->loadContent(
str_replace(['${lang}', '${code}'], [$ext, $output], Stream::of('res://.data/web/highlight.html'))
);
}


private function showMeta ($meta) {
public function showMeta ($meta) {
$meta = $meta["size"];
$types = [Localization::get('ui.sidepanel.fileSizeFromat.b'), Localization::get('ui.sidepanel.fileSizeFromat.kb'), Localization::get('ui.sidepanel.fileSizeFromat.mb'), Localization::get('ui.sidepanel.fileSizeFromat.gb')];

$index = floor(str::length($meta) / 3);

$this->fileInfoPanel->updateFileSize(round($meta / pow(1024, $index), 2) . ' ' . $types[$index]);
}

private function makeSplitter ()
{
$this->split = new UXSplitPane([$this->leftContainer, $this->rightContainer]);
$this->split->position = [0, 0];
$this->split->topAnchor = 25;
$this->split->bottomAnchor = true;
$this->split->rightAnchor = true;
$this->split->leftAnchor = true;
}

}
Loading

0 comments on commit 14b87d5

Please sign in to comment.