This commit is contained in:
LZX committed 2026-09-11 13:03:34 +08:00
1 parent 2379b4476f
commit 8531403c33
21 files changed
+2498 -354

No files matched your search

+4
View File
@@ -0,0 +1,4 @@
{
"java.configuration.updateBuildConfiguration": "interactive",
"cmake.ignoreCMakeListsMissing": true
}
+6 -2
View File
@@ -12,8 +12,12 @@ val newBuildDir: Directory =
rootProject.layout.buildDirectory.value(newBuildDir)
subprojects {
val newSubprojectBuildDir: Directory = newBuildDir.dir(project.name)
project.layout.buildDirectory.value(newSubprojectBuildDir)
val projectRoot = project.projectDir.toPath().root
val buildRoot = newBuildDir.asFile.toPath().root
if (projectRoot != null && projectRoot == buildRoot) {
val newSubprojectBuildDir: Directory = newBuildDir.dir(project.name)
project.layout.buildDirectory.value(newSubprojectBuildDir)
}
}
subprojects {
project.evaluationDependsOn(":app")
@@ -0,0 +1,663 @@
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<style type="text/css">
/*! normalize.css v7.0.0 | MIT License | github.com/necolas/normalize.css */
html {
line-height: 1.15;
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%
}
body {
margin: 0
}
article, aside, footer, header, nav, section {
display: block
}
h1 {
font-size: 2em;
margin: .67em 0
}
figcaption, figure, main {
display: block
}
figure {
margin: 1em 40px
}
hr {
box-sizing: content-box;
height: 0;
overflow: visible
}
pre {
font-family: monospace, monospace;
font-size: 1em
}
a {
background-color: transparent;
-webkit-text-decoration-skip: objects
}
abbr[title] {
border-bottom: none;
text-decoration: underline;
text-decoration: underline dotted
}
b, strong {
font-weight: inherit
}
b, strong {
font-weight: bolder
}
code, kbd, samp {
font-family: monospace, monospace;
font-size: 1em
}
dfn {
font-style: italic
}
mark {
background-color: #ff0;
color: #000
}
small {
font-size: 80%
}
sub, sup {
font-size: 75%;
line-height: 0;
position: relative;
vertical-align: baseline
}
sub {
bottom: -.25em
}
sup {
top: -.5em
}
audio, video {
display: inline-block
}
audio:not([controls]) {
display: none;
height: 0
}
img {
border-style: none
}
svg:not(:root) {
overflow: hidden
}
button, input, optgroup, select, textarea {
font-family: sans-serif;
font-size: 100%;
line-height: 1.15;
margin: 0
}
button, input {
overflow: visible
}
button, select {
text-transform: none
}
[type=reset], [type=submit], button, html [type=button] {
-webkit-appearance: button
}
[type=button]::-moz-focus-inner, [type=reset]::-moz-focus-inner, [type=submit]::-moz-focus-inner, button::-moz-focus-inner {
border-style: none;
padding: 0
}
[type=button]:-moz-focusring, [type=reset]:-moz-focusring, [type=submit]:-moz-focusring, button:-moz-focusring {
outline: 1px dotted ButtonText
}
fieldset {
padding: .35em .75em .625em
}
legend {
box-sizing: border-box;
color: inherit;
display: table;
max-width: 100%;
padding: 0;
white-space: normal
}
progress {
display: inline-block;
vertical-align: baseline
}
textarea {
overflow: auto
}
[type=checkbox], [type=radio] {
box-sizing: border-box;
padding: 0
}
[type=number]::-webkit-inner-spin-button, [type=number]::-webkit-outer-spin-button {
height: auto
}
[type=search] {
-webkit-appearance: textfield;
outline-offset: -2px
}
[type=search]::-webkit-search-cancel-button, [type=search]::-webkit-search-decoration {
-webkit-appearance: none
}
::-webkit-file-upload-button {
-webkit-appearance: button;
font: inherit
}
details, menu {
display: block
}
summary {
display: list-item
}
canvas {
display: inline-block
}
template {
display: none
}
[hidden] {
display: none
}
/* configuration cache styles */
.report-wrapper {
margin: 0;
padding: 0 24px;
}
.gradle-logo {
width: 32px;
height: 24px;
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAYCAYAAACbU/80AAAAAXNSR0IArs4c6QAAAERlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAIKADAAQAAAABAAAAGAAAAAA915G0AAAD5klEQVRIDbVWC0xTZxT+emmhVUEeA1/ROh/tFAFFGK7oJisIKsNVoOwBbJPowEWHzikRxeiMRpwwjDWRBHQLIzOmiRhe22BT40TitiyaMBQFfMEeLMIEaSmk+/+rvd7be4no6Elu7n++c/5zzv845/wyOyG4iGyDgzCdNOPLM9W41n4bnmNUiHo5DNsz0hGsmcV6lbkyAOOWXJjrz4qWp1C4o3z/LqzWL4VcJB1FIHmZHn/f78a6pDcxbeIEfNvQiPwTZbDZBpC24zOEaGfDpTsgtZby6u+QlrubFWUY3nh6AH39/ahr/Bn1jZfxW3ML2js60dtvgbtcQVblj8CZM7A0PBSrol6Ft+c4KZ8iTB1nwN0//8IEP9/hA2i924Gir0/iq8oa/NvbJzLiDKiUSqTE6pGVbEBY4BxnsYAPSnwXTa3tLCZ5BF3dPdAkGNHzoFcwcaRMnC4CeZkZiAgKFE252nITC1Pew9Dj5GNEGgS4Rbb5eZ1Te7UXG6FLX4cV6zeh5kIDaDpSunL9Boyf5nLOpwT4Sx+BxWrFK8QAnTAapPRQwofcj86uLoG59cbVEOzA0NAQNh38Atn5RSjY8rFAmc/I3dyQvOx1PsSNVy7Roa3ajHDePbBYLSLn1MaGd5KFAXy07xAOl59C6elK+I73hIHcbGd6wXs8qkyH8FZcjLOI5X/9/TrOnLsAldJDUu4As1NToFFPe3IEpm/M2HigwCFnU6t4Zw6Ck1JhGRhgcXq5juXloKyqFnlHirmz5CaNcEAv59kSE9wVikcB3O78A/MSU0Fznk/H9+yAetJEnPr+B8RFLsLcGS8ia28+qQuX+WrPNNZOV+Nc6VH4+3iz89g0pEaLzRUiQ3LGDWsM8Qidq2WL0PGKKlgf74ZIeQTAfFJ6a44WIsDXh9OW/dPdY58aawC9KK6kpOgolO7JxViVSuBGXnvxksudZ5F0O5yzGYxMJnBOGaau4fnPU2RNAtCFBKFoa7akczaAptY2iWmjB33+yQa4kZwfjpi2ex3Dyf43vuAljWQ/4Btmei1WPj+q45hF4U+1J4fEizCEvNf0EWHoIW244sfzoN1RipaT2kDfdjfv3MNpojdISjmfIheE8Fnp8WR9vJ2Zr+O+bYUmO+kJ9KnIUtf9bnvY2x9wcqrrvnCJvfL8Tw4V9v9LU7PdKzJaoNdy645AR4ph1JMncZHRKrVvYyYY5kmP8iO1v2T3dk6HDtYmrgJtOnwKnaPFrg8z+BBX7QSgEyOPJfX9Qd9DFs40GgTOHbrBs2ch4bXFuEG2mmFkeD9hpUMk+NMXEe0TNtsg/Ly94DVurEAuxfwHC1WiVbe0U7MAAAAASUVORK5CYII=");
background-size: contain;
}
.header {
display: flex;
flex-wrap: wrap;
position: fixed;
top: 0;
left: 0;
width: 100%;
padding: 24px 24px 0 24px;
background-color: white;
z-index: 1;
}
.learn-more {
margin-left: auto;
align-self: center;
font-size: 0.875rem;
font-weight: normal;
}
.title {
display: flex;
align-items: center;
padding: 18px 0 24px 0;
flex: 1 0 100%;
}
.content {
font-size: 0.875rem;
padding: 240px 0 48px;
overflow-x: auto;
white-space: nowrap;
}
.content ol:first-of-type {
margin: 0;
}
.tree-btn {
cursor: pointer;
display: inline-block;
width: 16px;
height: 16px;
background-size: contain;
background-repeat: no-repeat;
vertical-align: middle;
margin-top: -0.2em;
}
.tree-btn.collapsed {
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 192 512"><path d="M166.9 264.5l-117.8 116c-4.7 4.7-12.3 4.7-17 0l-7.1-7.1c-4.7-4.7-4.7-12.3 0-17L127.3 256 25.1 155.6c-4.7-4.7-4.7-12.3 0-17l7.1-7.1c4.7-4.7 12.3-4.7 17 0l117.8 116c4.6 4.7 4.6 12.3-.1 17z" fill="%23999999" stroke="%23999999"/></svg>');
}
.tree-btn.expanded {
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 512"><path d="M119.5 326.9L3.5 209.1c-4.7-4.7-4.7-12.3 0-17l7.1-7.1c4.7-4.7 12.3-4.7 17 0L128 287.3l100.4-102.2c4.7-4.7 12.3-4.7 17 0l7.1 7.1c4.7 4.7 4.7 12.3 0 17L136.5 327c-4.7 4.6-12.3 4.6-17-.1z" fill="%23999999" stroke="%23999999"/></svg>');
}
ul .tree-btn {
margin-right: 3px;
}
.leaf-icon {
display: inline-block;
width: 16px;
height: 16px;
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 512"><path d="M32 256 H224" stroke="%23999999" stroke-width="48" stroke-linecap="round"/></svg>');
background-size: contain;
background-repeat: no-repeat;
vertical-align: middle;
margin-top: -0.2em;
}
.invisible-text {
user-select: all; /* Allow the text to be selectable */
color: transparent; /* Hide the text */
text-indent: -9999px; /* Move the text out of view */
position: relative;
white-space: pre; /* Preserve meaningful whitespace in the invisible text for copying */
}
.text-for-copy {
display: inline-block;
}
.enum-icon {
display: inline-block;
width: 16px;
height: 16px;
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024"><circle cx="512" cy="512" r="200" /></svg>');
background-size: contain;
background-repeat: no-repeat;
vertical-align: middle;
margin-inline-start: 0.5ex;
margin-inline-end: 0.5ex;
margin-top: -0.2em;
}
.error-icon {
display: inline-block;
width: 16px;
height: 16px;
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><path d="M193.94 256L296.5 153.44l21.15-21.15c3.12-3.12 3.12-8.19 0-11.31l-22.63-22.63c-3.12-3.12-8.19-3.12-11.31 0L160 222.06 36.29 98.34c-3.12-3.12-8.19-3.12-11.31 0L2.34 120.97c-3.12 3.12-3.12 8.19 0 11.31L126.06 256 2.34 379.71c-3.12 3.12-3.12 8.19 0 11.31l22.63 22.63c3.12 3.12 8.19 3.12 11.31 0L160 289.94 262.56 392.5l21.15 21.15c3.12 3.12 8.19 3.12 11.31 0l22.63-22.63c3.12-3.12 3.12-8.19 0-11.31L193.94 256z" fill="%23FC461E" stroke="%23FC461E"/></svg>');
background-size: contain;
background-repeat: no-repeat;
vertical-align: middle;
margin-inline-start: 0.5ex;
margin-inline-end: 0.5ex;
margin-top: -0.2em;
}
.advice-icon {
display: inline-block;
width: 16px;
height: 16px;
background-image: url('data:image/svg+xml;utf8,<svg width="800px" height="800px" viewBox="-4.93 0 122.88 122.88" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="enable-background:new 0 0 113.01 122.88" xml:space="preserve"><g><path d="M44.13,102.06c-1.14,0.03-2.14-0.81-2.3-1.96c-0.17-1.2,0.64-2.31,1.82-2.54c-1.3-7.37-4.85-11.43-8.6-15.72 c-2.92-3.34-5.95-6.81-8.34-11.92c-2.35-5.03-3.64-10.23-3.6-15.63c0.05-5.4,1.42-10.96,4.4-16.71c0.02-0.04,0.04-0.07,0.06-0.11 l0,0c3.91-6.62,9.38-11.04,15.47-13.52c5.11-2.09,10.66-2.8,16.1-2.3c5.42,0.5,10.73,2.2,15.37,4.94 c5.9,3.49,10.75,8.67,13.42,15.21c1.44,3.54,2.42,7.49,2.54,11.82c0.12,4.31-0.62,8.96-2.61,13.88 c-2.66,6.59-6.18,10.68-9.47,14.51c-3.03,3.53-5.85,6.81-7.42,11.84c0.89,0.21,1.59,0.94,1.73,1.9c0.17,1.24-0.7,2.39-1.94,2.56 l-0.77,0.11c-0.14,1.09-0.23,2.26-0.27,3.51l0.25-0.04c1.24-0.17,2.39,0.7,2.56,1.94c0.17,1.24-0.7,2.39-1.94,2.56l-0.78,0.11 c0.01,0.15,0.02,0.3,0.03,0.45l0,0c0.07,0.88,0.08,1.73,0.03,2.54l0.13-0.02c1.25-0.15,2.38,0.74,2.54,1.98 c0.15,1.25-0.74,2.38-1.98,2.54l-1.68,0.21c-1.2,3.11-3.34,5.48-5.87,6.94c-1.74,1.01-3.67,1.59-5.61,1.71 c-1.97,0.12-3.96-0.25-5.78-1.13c-2.08-1.02-3.94-2.71-5.29-5.14c-0.65-0.33-1.13-0.97-1.23-1.75c-0.04-0.31-0.01-0.61,0.07-0.89 c-0.39-1.16-0.68-2.43-0.87-3.83l-0.07,0.01c-1.24,0.17-2.39-0.7-2.56-1.94c-0.17-1.24,0.7-2.39,1.94-2.56l0.54-0.08 C44.19,104.32,44.18,103.16,44.13,102.06L44.13,102.06z M2.18,58.86C1.01,58.89,0.04,57.98,0,56.81c-0.04-1.17,0.88-2.14,2.05-2.18 l8.7-0.3c1.17-0.04,2.14,0.88,2.18,2.05c0.04,1.17-0.88,2.14-2.05,2.18L2.18,58.86L2.18,58.86z M110.68,50.25 c1.16-0.12,2.2,0.73,2.32,1.89c0.12,1.16-0.73,2.2-1.89,2.32l-8.66,0.91c-1.16,0.12-2.2-0.73-2.32-1.89 c-0.12-1.16,0.73-2.2,1.89-2.32L110.68,50.25L110.68,50.25z M94.91,14.78c0.65-0.97,1.96-1.23,2.93-0.58 c0.97,0.65,1.23,1.96,0.58,2.93l-4.84,7.24c-0.65,0.97-1.96,1.23-2.93,0.58c-0.97-0.65-1.23-1.96-0.58-2.93L94.91,14.78 L94.91,14.78z M57.63,2.06c0.03-1.17,1-2.09,2.16-2.06c1.17,0.03,2.09,1,2.06,2.16l-0.22,8.7c-0.03,1.17-1,2.09-2.16,2.06 c-1.17-0.03-2.09-1-2.06-2.16L57.63,2.06L57.63,2.06z M13.88,15.53c-0.86-0.8-0.9-2.14-0.11-2.99c0.8-0.86,2.14-0.9,2.99-0.11 l6.37,5.94c0.86,0.8,0.9,2.14,0.11,2.99c-0.8,0.86-2.14,0.9-2.99,0.11L13.88,15.53L13.88,15.53z M47.88,96.95l18.49-2.63 c1.59-6.7,5.05-10.73,8.8-15.08c3.08-3.58,6.36-7.4,8.76-13.34c1.76-4.35,2.41-8.43,2.31-12.19c-0.1-3.75-0.96-7.21-2.24-10.34 c-2.3-5.63-6.51-10.11-11.65-13.15c-4.11-2.43-8.8-3.94-13.59-4.37c-4.77-0.44-9.64,0.19-14.13,2.02 c-5.26,2.15-9.99,5.97-13.39,11.72c-2.64,5.12-3.86,10.02-3.9,14.73c-0.04,4.74,1.11,9.33,3.2,13.8c2.13,4.56,4.97,7.8,7.69,10.92 C42.47,83.9,46.48,88.49,47.88,96.95L47.88,96.95z M65.62,99.02l-17.27,2.45c0.05,1.1,0.07,2.25,0.05,3.47l17.05-2.42 C65.47,101.29,65.52,100.12,65.62,99.02L65.62,99.02z M48.49,109.52c0.12,0.92,0.3,1.76,0.53,2.54l16.55-2.04 c0.11-0.86,0.13-1.77,0.05-2.74l0,0l0-0.02l-0.01-0.17L48.49,109.52L48.49,109.52z M51.37,116.36c0.64,0.67,1.35,1.19,2.1,1.55 c1.15,0.56,2.42,0.79,3.67,0.72c1.29-0.08,2.57-0.47,3.74-1.15c1.1-0.64,2.09-1.53,2.88-2.65L51.37,116.36L51.37,116.36z"/></g></svg>');
background-size: contain;
background-repeat: no-repeat;
vertical-align: middle;
margin-inline-start: 0.5ex;
margin-inline-end: 0.5ex;
margin-top: -0.2em;
}
.warning-icon {
display: inline-block;
width: 13px;
height: 13px;
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><path d="M270.2 160h35.5c3.4 0 6.1 2.8 6 6.2l-7.5 196c-.1 3.2-2.8 5.8-6 5.8h-20.5c-3.2 0-5.9-2.5-6-5.8l-7.5-196c-.1-3.4 2.6-6.2 6-6.2zM288 388c-15.5 0-28 12.5-28 28s12.5 28 28 28 28-12.5 28-28-12.5-28-28-28zm281.5 52L329.6 24c-18.4-32-64.7-32-83.2 0L6.5 440c-18.4 31.9 4.6 72 41.6 72H528c36.8 0 60-40 41.5-72zM528 480H48c-12.3 0-20-13.3-13.9-24l240-416c6.1-10.6 21.6-10.7 27.7 0l240 416c6.2 10.6-1.5 24-13.8 24z" fill="%23DEAD22" stroke="%23DEAD22"/></svg>');
background-size: contain;
background-repeat: no-repeat;
vertical-align: middle;
margin-inline-start: 0.3ex;
margin-inline-end: 1.1ex;
margin-top: -0.1em;
}
.documentation-button {
cursor: pointer;
display: inline-block;
width: 13px;
height: 13px;
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M256 340c-15.464 0-28 12.536-28 28s12.536 28 28 28 28-12.536 28-28-12.536-28-28-28zm7.67-24h-16c-6.627 0-12-5.373-12-12v-.381c0-70.343 77.44-63.619 77.44-107.408 0-20.016-17.761-40.211-57.44-40.211-29.144 0-44.265 9.649-59.211 28.692-3.908 4.98-11.054 5.995-16.248 2.376l-13.134-9.15c-5.625-3.919-6.86-11.771-2.645-17.177C185.658 133.514 210.842 116 255.67 116c52.32 0 97.44 29.751 97.44 80.211 0 67.414-77.44 63.849-77.44 107.408V304c0 6.627-5.373 12-12 12zM256 40c118.621 0 216 96.075 216 216 0 119.291-96.61 216-216 216-119.244 0-216-96.562-216-216 0-119.203 96.602-216 216-216m0-32C119.043 8 8 119.083 8 256c0 136.997 111.043 248 248 248s248-111.003 248-248C504 119.083 392.957 8 256 8z" fill="%23999999" stroke="%23999999"/></svg>');
background-size: contain;
background-repeat: no-repeat;
vertical-align: middle;
margin-inline-start: 0.5ex;
margin-inline-end: 0.5ex;
margin-top: -0.2em;
}
.documentation-button::selection {
color: transparent;
}
.documentation-button:hover {
color: transparent;
}
.copy-button {
cursor: pointer;
display: inline-block;
width: 12px;
height: 12px;
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path d="M433.941 193.941l-51.882-51.882A48 48 0 0 0 348.118 128H320V80c0-26.51-21.49-48-48-48h-66.752C198.643 13.377 180.858 0 160 0s-38.643 13.377-45.248 32H48C21.49 32 0 53.49 0 80v288c0 26.51 21.49 48 48 48h80v48c0 26.51 21.49 48 48 48h224c26.51 0 48-21.49 48-48V227.882a48 48 0 0 0-14.059-33.941zm-22.627 22.627a15.888 15.888 0 0 1 4.195 7.432H352v-63.509a15.88 15.88 0 0 1 7.431 4.195l51.883 51.882zM160 30c9.941 0 18 8.059 18 18s-8.059 18-18 18-18-8.059-18-18 8.059-18 18-18zM48 384c-8.822 0-16-7.178-16-16V80c0-8.822 7.178-16 16-16h66.752c6.605 18.623 24.389 32 45.248 32s38.643-13.377 45.248-32H272c8.822 0 16 7.178 16 16v48H176c-26.51 0-48 21.49-48 48v208H48zm352 96H176c-8.822 0-16-7.178-16-16V176c0-8.822 7.178-16 16-16h144v72c0 13.2 10.8 24 24 24h72v208c0 8.822-7.178 16-16 16z" fill="%23999999" stroke="%23999999"/></svg>');
background-size: contain;
background-repeat: no-repeat;
vertical-align: middle;
margin-inline-start: 0.5ex;
margin-top: -0.2em;
}
.groups{
display: flex;
border-bottom: 1px solid #EDEEEF;
flex: 1 0 100%;
}
.uncategorized {
display: flex;
border-top: 4px solid #EDEEEF;
flex: 1 0 100%;
}
.group-selector {
padding: 0 52px 24px 0;
font-size: 0.9rem;
font-weight: bold;
color: #999999;
cursor: pointer;
}
.group-selector__count {
margin: 0 8px;
border-radius: 8px;
background-color: #999;
color: #fff;
padding: 1px 8px 2px;
font-size: 0.75rem;
}
.group-selector--active {
color: #02303A;
cursor: auto;
}
.group-selector--active .group-selector__count {
background-color: #686868;
}
.group-selector--disabled {
cursor: not-allowed;
}
.accordion-header {
cursor: pointer;
}
.container {
padding-left: 0.5em;
padding-right: 0.5em;
}
.stacktrace {
border-radius: 4px;
overflow-x: auto;
padding: 0.5rem;
margin-bottom: 0;
min-width: 1000px;
}
/* Lato (bold, regular) */
@font-face {
font-display: swap;
font-family: Lato;
font-weight: 500;
font-style: normal;
src: url("https://assets.gradle.com/lato/fonts/lato-semibold/lato-semibold.woff2") format("woff2"),
url("https://assets.gradle.com/lato/fonts/lato-semibold/lato-semibold.woff") format("woff");
}
@font-face {
font-display: swap;
font-family: Lato;
font-weight: bold;
font-style: normal;
src: url("https://assets.gradle.com/lato/fonts/lato-bold/lato-bold.woff2") format("woff2"),
url("https://assets.gradle.com/lato/fonts/lato-bold/lato-bold.woff") format("woff");
}
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
html,
body {
margin: 0;
padding: 0;
}
html {
font-family: "Lato", "Helvetica Neue", Arial, sans-serif;
font-size: 16px;
font-weight: 400;
line-height: 1.5;
}
body {
color: #02303A;
background-color: #ffffff;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
-webkit-font-smoothing: antialiased;
}
/* typography */
h1, h2, h3, h4, h5, h6 {
color: #02303A;
text-rendering: optimizeLegibility;
margin: 0;
}
h1 {
font-size: 1rem;
}
h2 {
font-size: 0.9rem;
}
h3 {
font-size: 1.125rem;
}
h4, h5, h6 {
font-size: 0.875rem;
}
h1 code {
font-weight: bold;
}
ul, ol, dl {
list-style-position: outside;
line-height: 1.6;
padding: 0;
margin: 0 0 0 20px;
list-style-type: none;
}
li {
line-height: 2;
}
a {
color: #1DA2BD;
text-decoration: none;
transition: all 0.3s ease, visibility 0s;
}
a:hover {
color: #35c1e4;
}
/* code */
code, pre {
font-family: Inconsolata, Monaco, "Courier New", monospace;
font-style: normal;
font-variant-ligatures: normal;
font-variant-caps: normal;
font-variant-numeric: normal;
font-variant-east-asian: normal;
font-weight: normal;
font-stretch: normal;
color: #686868;
}
*:not(pre) > code {
letter-spacing: 0;
padding: 0.1em 0.5ex;
text-rendering: optimizeSpeed;
word-spacing: -0.15em;
word-wrap: break-word;
}
pre {
font-size: 0.75rem;
line-height: 1.8;
margin-top: 0;
margin-bottom: 1.5em;
padding: 1rem;
}
pre code {
background-color: transparent;
color: inherit;
line-height: 1.8;
font-size: 100%;
padding: 0;
}
a code {
color: #1BA8CB;
}
pre.code, pre.programlisting, pre.screen, pre.tt {
background-color: #f7f7f8;
border-radius: 4px;
font-size: 1em;
line-height: 1.45;
margin-bottom: 1.25em;
overflow-x: auto;
padding: 1rem;
}
li em, p em {
padding: 0 1px;
}
code em, tt em {
text-decoration: none;
}
code + .copy-button {
margin-inline-start: 0.2ex;
}
.java-exception {
font-size: 0.75rem;
padding-left: 24px;
}
.java-exception ul {
margin: 0;
line-height: inherit;
}
.java-exception code {
white-space: pre;
}
.java-exception-part-toggle {
user-select: none;
cursor: pointer;
border-radius: 2px;
padding: 0.1em 0.2em;
background: azure;
color: #686868;
}
</style>
<!-- Inconsolata is used as a default monospace font in the report. -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Inconsolata:400,700" />
<title>Gradle Configuration Cache</title>
</head>
<body>
<div id="playground"></div>
<div class="report" id="report">
Loading...
</div>
<script type="text/javascript">
function configurationCacheProblems() { return (
// begin-report-data
{"diagnostics":[{"locations":[{}],"problem":[{"text":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated."}],"severity":"WARNING","problemDetails":[{"text":"This is scheduled to be removed in Gradle 10.0."}],"contextualLabel":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated.","documentationLink":"https://docs.gradle.org/8.14/userguide/upgrading_version_8.html#groovy_space_assignment_syntax","problemId":[{"name":"deprecation","displayName":"Deprecation"},{"name":"properties-should-be-assigned-using-the-propname-value-syntax-setting-a-property-via-the-gradle-generated-propname-value-or-propname-value-syntax-in-groovy-dsl","displayName":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated."}],"solutions":[[{"text":"Use assignment ('group = <value>') instead."}]]},{"locations":[{}],"problem":[{"text":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated."}],"severity":"WARNING","problemDetails":[{"text":"This is scheduled to be removed in Gradle 10.0."}],"contextualLabel":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated.","documentationLink":"https://docs.gradle.org/8.14/userguide/upgrading_version_8.html#groovy_space_assignment_syntax","problemId":[{"name":"deprecation","displayName":"Deprecation"},{"name":"properties-should-be-assigned-using-the-propname-value-syntax-setting-a-property-via-the-gradle-generated-propname-value-or-propname-value-syntax-in-groovy-dsl","displayName":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated."}],"solutions":[[{"text":"Use assignment ('version = <value>') instead."}]]},{"locations":[{}],"problem":[{"text":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated."}],"severity":"WARNING","problemDetails":[{"text":"This is scheduled to be removed in Gradle 10.0."}],"contextualLabel":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated.","documentationLink":"https://docs.gradle.org/8.14/userguide/upgrading_version_8.html#groovy_space_assignment_syntax","problemId":[{"name":"deprecation","displayName":"Deprecation"},{"name":"properties-should-be-assigned-using-the-propname-value-syntax-setting-a-property-via-the-gradle-generated-propname-value-or-propname-value-syntax-in-groovy-dsl","displayName":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated."}],"solutions":[[{"text":"Use assignment ('compileSdk = <value>') instead."}]]},{"locations":[{}],"problem":[{"text":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated."}],"severity":"WARNING","problemDetails":[{"text":"This is scheduled to be removed in Gradle 10.0."}],"contextualLabel":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated.","documentationLink":"https://docs.gradle.org/8.14/userguide/upgrading_version_8.html#groovy_space_assignment_syntax","problemId":[{"name":"deprecation","displayName":"Deprecation"},{"name":"properties-should-be-assigned-using-the-propname-value-syntax-setting-a-property-via-the-gradle-generated-propname-value-or-propname-value-syntax-in-groovy-dsl","displayName":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated."}],"solutions":[[{"text":"Use assignment ('minSdk = <value>') instead."}]]},{"locations":[{}],"problem":[{"text":"Properties should be assigned using the 'propName = value' syntax. Setting a property via the Gradle-generated 'propName value' or 'propName(value)' syntax in Groovy DSL has been deprecated."}],"severity":"WARNING","problemDetails":[{"text":Line truncated
// end-report-data
);}
</script>
<script type="text/javascript">
!function(n,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["configuration-cache-report"]=t():n["configuration-cache-report"]=t()}(this,(()=>(({70:function(){void 0===ArrayBuffer.isView&&(ArrayBuffer.isView=function(n){return null!=n&&null!=n.__proto__&&n.__proto__.__proto__===Int8Array.prototype.__proto__}),void 0===Math.imul&&(Math.imul=function(n,t){return(4294901760&n)*(65535&t)+(65535&n)*(0|t)|0}),this["configuration-cache-report"]=function(n){"use strict";var t,r,i,e,u,o,f,s,c,a,h,l,_,v,d,g,w,b,p,m,k,q,y,B,C,x,j,P,I,S,z,T,E,L,N,A,M,F,D,O,R,H,$,G,U,V,Q,Z,Y,W,K,X,J,nn,tn,rn,en,un,on,fn,sn,cn,an,hn,ln,_n,vn,dn,gn,wn,bn,pn,mn,kn,qn,yn,Bn,Cn,xn,jn,Pn,In,Sn,zn,Tn,En,Ln,Nn,An,Mn=Math.imul,Fn=ArrayBuffer.isView;function Dn(n,t){if(!(t>=0))throw _u(ce("Requested element count "+t+" is less than zero."));return function(n,t){if(!(t>=0))throw _u(ce("Requested element count "+t+" is less than zero."));if(0===t)return Ct();if(t>=n.length)return function(n){switch(n.length){case 0:return Ct();case 1:return qr(n[0]);default:return function(n){return Hr(function(n){return new It(n,!1)}(n))}(n)}}(n);if(1===t)return qr(n[0]);var r=0,i=Rr(),e=0,u=n.length;n:for(;e<u;){var o=n[e];if(e=e+1|0,i.d(o),(r=r+1|0)===t)break n}return i}(n,rt(n.length-t|0,0))}function On(n,t,r,i,e,u,o){return t=t===A?", ":t,r=r===A?"":r,i=i===A?"":i,e=e===A?-1:e,u=u===A?"...":u,o=o===A?null:o,function(n,t,r,i,e,u,o,f){r=r===A?", ":r,i=i===A?"":i,e=e===A?"":e,u=u===A?-1:u,o=o===A?"...":o,f=f===A?null:f,t.e(i);var s=0,c=0,a=n.length;n:for(;c<a;){var h=n[c];if(c=c+1|0,(s=s+1|0)>1&&t.e(r),!(u<0||s<=u))break n;Jt(t,h,f)}return u>=0&&s>u&&t.e(o),t.e(e),t}(n,Bi(),t,r,i,e,u,o).toString()}function Rn(n){return n.length-1|0}function Hn(n,t){if(null==t){var r=0,i=n.length-1|0;if(r<=i)do{var e=r;if(r=r+1|0,null==n[e])return e}while(r<=i)}else{var u=0,o=n.length-1|0;if(u<=o)do{var f=u;if(u=u+1|0,le(t,n[f]))return f}while(u<=o)}return-1}function $n(n,t,r,i,e,u,o){return t=t===A?", ":t,r=r===A?"":r,i=i===A?"":i,e=e===A?-1:e,u=u===A?"...":u,o=o===A?null:o,Gn(n,Bi(),t,r,i,e,u,o).toString()}function Gn(n,t,r,i,e,u,o,f){r=r===A?", ":r,i=i===A?"":i,e=e===A?"":e,u=u===A?-1:u,o=o===A?"...":o,f=f===A?null:f,t.e(i);var s=0,c=n.f();n:for(;c.g();){var a=c.h();if((s=s+1|0)>1&&t.e(r),!(u<0||s<=u))break n;Jt(t,a,f)}return u>=0&&s>u&&t.e(o),t.e(e),t}function Un(n){if(n.i())throw xu("List is empty.");return n.j(0)}function Vn(n){return new tt(n)}function Qn(n){if(Ke(n,Di)){var t;switch(n.k()){case 0:t=Ct();break;case 1:t=qr(Ke(n,Fi)?n.j(0):n.f().h());break;default:t=Zn(n)}return t}return xt(Xn(n))}function Zn(n){return Hr(n)}function Yn(n){if(Ke(n,Di)&&n.k()<=1)return Qn(n);var t=Xn(n);return function(n){var t=(n.k()/2|0)-1|0;if(t<0)return br();var r=jt(n),i=0;if(i<=t)do{var e=i;i=i+1|0;var u=n.j(e);n.f4(e,n.j(r)),n.f4(r,u),r=r-1|0}while(e!==t)}(t),t}function Wn(n,t){if(!(t>=0))throw _u(ce("Requested element count "+t+" is less than zero."));return function(n,t){if(!(t>=0))throw _u(ce("Requested element count "+t+" is less than zero."));if(0===t)return Ct();if(Ke(n,Di)){if(t>=n.k())return Qn(n);if(1===t)return qr(function(n){if(Ke(n,Fi))return Un(n);var t=n.f();if(!t.g())throw xu("Collection is empty.");return t.h()}(n))}var r=0,i=Rr(),e=n.f();n:for(;e.g();){var u=e.h();if(i.d(u),(r=r+1|0)===t)break n}return xt(i)}(n,rt(n.k()-t|0,0))}function Kn(n,t){if(!(t>=0))throw _u(ce("Requested element count "+t+" is less than zero."));if(0===t)return Ct();var r=n.k();if(t>=r)return Qn(n);if(1===t)return qr(Jn(n));var i=Rr();if(Ke(n,bi)){var e=r-t|0;if(e<r)do{var u=e;e=e+1|0,i.d(n.j(u))}while(e<r)}else for(var o=n.l(r-t|0);o.g();){var f=o.h();i.d(f)}return i}function Xn(n){return Ke(n,Di)?Zn(n):nt(n,Or())}function Jn(n){if(n.i())throw xu("List is empty.");return n.j(jt(n))}function nt(n,t){for(var r=n.f();r.g();){var i=r.h();t.d(i)}return t}function tt(n){this.n_1=n}function rt(n,t){return n<t?t:n}function it(n,t){return n>t?t:n}function et(n,t){return Kt().q(n,t,-1)}function ut(n,t){return new Ft(n,t)}function ot(n){var t=n.f();if(!t.g())return Ct();var r=t.h();if(!t.g())return qr(r);var i=Or();for(i.d(r);t.g();)i.d(t.h());return i}function ft(n){this.r_1=n}function st(n,t){this.s_1=n,this.t_1=t}function ct(){}function at(n){this.x_1=n,this.w_1=0}function ht(n,t){this.a1_1=n,at.call(this,n),_t().b1(t,this.a1_1.k()),this.w_1=t}function lt(){t=this}function _t(){return null==t&&new lt,t}function vt(){_t(),ct.call(this)}function dt(n){this.h1_1=n}function gt(n,t){return t===n?"(this Map)":Vi(t)}function wt(n,t){var r;n:{for(var i=n.o().f();i.g();){var e=i.h();if(le(e.j1(),t)){r=e;break n}}r=null}return r}function bt(){r=this}function pt(){return null==r&&new bt,r}function mt(n){this.q1_1=n,ct.call(this)}function kt(){pt(),this.n1_1=null,this.o1_1=null}function qt(){i=this}function yt(){return null==i&&new qt,i}function Bt(n){return n.length>0?ou(n):Ct()}function Ct()Line truncated
//# sourceMappingURL=configuration-cache-report.js.map
</script>
</body>
</html>
+4
View File
@@ -1,3 +1,7 @@
org.gradle.jvmargs=-Xmx8G -XX:MaxMetaspaceSize=4G -XX:ReservedCodeCacheSize=512m -XX:+HeapDumpOnOutOfMemoryError
android.useAndroidX=true
android.enableJetifier=true
# This builtInKotlin flag was added automatically by Flutter migrator
android.builtInKotlin=false
# This newDsl flag was added automatically by Flutter migrator
android.newDsl=false
+1 -1
View File
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-all.zip
+2 -2
View File
@@ -19,8 +19,8 @@ pluginManagement {
plugins {
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
id("com.android.application") version "8.9.1" apply false
id("org.jetbrains.kotlin.android") version "2.1.0" apply false
id("com.android.application") version "8.11.1" apply false
id("org.jetbrains.kotlin.android") version "2.2.20" apply false
}
include(":app")
+21 -9
View File
@@ -1,6 +1,8 @@
import 'package:code_editor/l10n/app_localizations.dart';
import 'package:code_editor/providers/editor_provider.dart';
import 'package:code_editor/views/main_view.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
void main() {
runApp(const MyApp());
@@ -11,16 +13,26 @@ class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
title: 'Flutter Demo',
theme: ThemeData(
useMaterial3: true,
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
return ChangeNotifierProvider(
create: (_) => EditorProvider()..init(),
child: MaterialApp(
debugShowCheckedModeBanner: false,
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
title: 'Flutter Demo',
theme: ThemeData(
useMaterial3: true,
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
fontFamilyFallback: const [
'PingFang SC', // iOS / macOS
'Noto Sans SC', // Android
'Microsoft YaHei', // Windows
'WenQuanYi Micro Hei', // Linux
'sans-serif', // Web & generic fallback
],
),
home: const MainView(),
),
home: const MainView(),
);
}
}
+50 -17
View File
@@ -1,17 +1,50 @@
class FileItem {
final String path;
final String name;
final bool isDirectory;
final List<FileItem> children;
final int depth;
bool isOpen;
FileItem({
required this.path,
required this.name,
this.isDirectory = false,
this.children = const [],
this.depth = 0,
this.isOpen = false
});
}
import 'package:path/path.dart' as p;
class FileItem {
final String fullPath;
final String name;
final String? relativePath;
final bool isDirectory;
List<FileItem> children;
final int depth;
bool isOpen;
FileItem({
required String path,
String? name,
this.relativePath,
this.isDirectory = false,
List<FileItem>? children,
this.depth = 0,
this.isOpen = false,
}) : fullPath = p.normalize(path),
name = name ?? p.basename(path),
children = children ?? [];
/// 完整物理绝对路径别名(完全兼容旧代码)
String get path => fullPath;
/// 文件扩展名(含前导点,如 '.dart'、'.json';文件夹或无扩展名返回 '')
String get extension => isDirectory ? '' : p.extension(fullPath).toLowerCase();
/// 不带扩展名的文件名(如 'main')
String get nameWithoutExtension =>
isDirectory ? name : p.basenameWithoutExtension(fullPath);
/// 优先展示相对路径;若无相对路径则展示纯文件名
String get displayPath => relativePath ?? name;
/// 获取相对于指定 rootPath 的相对路径(优先使用已有相对路径,跨盘或无项目安全回退)
String getRelativePath([String? fromRoot]) {
if (relativePath != null && (fromRoot == null || fromRoot.isEmpty)) {
return relativePath!;
}
final root = fromRoot;
if (root == null || root.trim().isEmpty) return name;
try {
return p.relative(fullPath, from: root);
} catch (_) {
return fullPath;
}
}
}␍
+265
View File
@@ -0,0 +1,265 @@
import 'package:code_editor/models/file_directory_history.dart';
import 'package:code_editor/models/file_item.dart';
import 'package:code_editor/services/file_directory_history_service.dart';
import 'package:code_editor/services/file_service.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/foundation.dart';
import 'package:path/path.dart' as p;
class EditorProvider extends ChangeNotifier {
FileDirectoryHistory _history = const FileDirectoryHistory(
rootPath: null,
lastOpenedFilePath: "未命名",
);
List<FileItem> _items = [];
bool _isLoading = false;
FileItem? _cutItem;
FileItem? _copiedItem;
FileDirectoryHistory get history => _history;
String? get rootPath => _history.rootPath;
String? get currentFilePath => _history.lastOpenedFilePath;
List<String> get openDirectoryPaths => _history.openDirectoryPaths;
List<FileItem> get items => _items;
bool get isLoading => _isLoading;
FileItem? get cutItem => _cutItem;
FileItem? get copiedItem => _copiedItem;
bool get canPaste => _cutItem != null || _copiedItem != null;
bool isFileSelected(String path) {
if (currentFilePath == null) return false;
return currentFilePath == path || currentFilePath!.trim() == path.trim();
}
bool isItemCut(String path) {
if (_cutItem == null) return false;
return _cutItem!.path == path || _cutItem!.path.trim() == path.trim();
}
Future<void> init() async {
await _loadProjectFromHistory();
}
Future<void> _loadProjectFromHistory() async {
_isLoading = true;
notifyListeners();
try {
final lastHistory = await FileDirectoryHistoryService.instance.getLastHistory();
if (lastHistory == null) {
_isLoading = false;
notifyListeners();
return;
}
final path = lastHistory.rootPath;
final cleanPath = (path != null && path.trim().isNotEmpty) ? p.normalize(path.trim()) : null;
final validOpenPaths = cleanPath == null
? <String>[]
: lastHistory.openDirectoryPaths
.map((e) => p.normalize(e.trim()))
.where((e) => e != cleanPath && p.isWithin(cleanPath, e))
.toList();
List<FileItem> items = cleanPath != null
? await FileService.instance.buildTree(
cleanPath,
openDirectoryPaths: validOpenPaths,
)
: [];
_items = items;
_history = FileDirectoryHistory(
rootPath: cleanPath,
lastOpenedFilePath: lastHistory.lastOpenedFilePath,
openDirectoryPaths: validOpenPaths,
);
} catch (e) {
debugPrint('加载项目历史失败: $e');
} finally {
_isLoading = false;
notifyListeners();
}
}
Future<void> openDirectory() async {
try {
final String? selectedPath = await FilePicker.platform.getDirectoryPath();
if (selectedPath == null || selectedPath.trim().isEmpty) {
return;
}
final cleanPath = p.normalize(selectedPath.trim());
final currentRoot = _history.rootPath != null ? p.normalize(_history.rootPath!) : null;
final isSameRoot = currentRoot != null && cleanPath == currentRoot;
await FileDirectoryHistoryService.instance.recordHistory(
rootPath: cleanPath,
lastOpenedFilePath: isSameRoot ? _history.lastOpenedFilePath : null,
openDirectoryPaths: isSameRoot ? _history.openDirectoryPaths : const [],
);
_cutItem = null;
_copiedItem = null;
await _loadProjectFromHistory();
} catch (e) {
debugPrint('打开文件夹失败: $e');
}
}
Future<void> switchProject(FileDirectoryHistory selectedHistory) async {
final selectedRoot = selectedHistory.rootPath;
if (selectedRoot == null || selectedRoot.trim().isEmpty) return;
await FileDirectoryHistoryService.instance.recordHistory(
rootPath: selectedRoot,
lastOpenedFilePath: selectedHistory.lastOpenedFilePath,
openDirectoryPaths: selectedHistory.openDirectoryPaths,
);
_cutItem = null;
_copiedItem = null;
await _loadProjectFromHistory();
}
Future<void> selectFile(FileItem item) async {
if (item.isDirectory) return;
final cleanPath = _history.rootPath;
if (cleanPath != null) {
await FileDirectoryHistoryService.instance.recordHistory(
rootPath: cleanPath,
lastOpenedFilePath: item.path,
openDirectoryPaths: _history.openDirectoryPaths,
);
_history = FileDirectoryHistory(
rootPath: cleanPath,
lastOpenedFilePath: item.path,
openDirectoryPaths: _history.openDirectoryPaths,
);
notifyListeners();
}
}
Future<void> toggleDirectory(FileItem item, bool expanded) async {
final cleanPath = _history.rootPath;
if (cleanPath == null) return;
final updatedOpenPaths = List<String>.from(_history.openDirectoryPaths);
if (expanded) {
if (!updatedOpenPaths.contains(item.path)) {
updatedOpenPaths.add(item.path);
}
if (item.children.isEmpty) {
final children = await FileService.instance.buildTree(
item.path,
depth: item.depth + 1,
openDirectoryPaths: updatedOpenPaths,
);
item.children.clear();
item.children.addAll(children);
}
} else {
updatedOpenPaths.remove(item.path);
}
await FileDirectoryHistoryService.instance.recordHistory(
rootPath: cleanPath,
lastOpenedFilePath: _history.lastOpenedFilePath,
openDirectoryPaths: updatedOpenPaths,
);
_history = FileDirectoryHistory(
rootPath: cleanPath,
lastOpenedFilePath: _history.lastOpenedFilePath,
openDirectoryPaths: updatedOpenPaths,
);
notifyListeners();
}
Future<void> refreshTree() async {
final currentRoot = _history.rootPath;
if (currentRoot == null || currentRoot.trim().isEmpty) return;
try {
final items = await FileService.instance.buildTree(
currentRoot,
openDirectoryPaths: _history.openDirectoryPaths,
);
String? currentFile = _history.lastOpenedFilePath;
if (currentFile != null) {
final exists = await FileService.instance.entityExists(currentFile);
if (!exists) {
currentFile = null;
await FileDirectoryHistoryService.instance.recordHistory(
rootPath: currentRoot,
lastOpenedFilePath: null,
openDirectoryPaths: _history.openDirectoryPaths,
);
}
}
_items = items;
if (currentFile != _history.lastOpenedFilePath) {
_history = FileDirectoryHistory(
rootPath: currentRoot,
lastOpenedFilePath: currentFile,
openDirectoryPaths: _history.openDirectoryPaths,
);
}
notifyListeners();
} catch (e) {
debugPrint('刷新目录树失败: $e');
}
}
void cut(FileItem item) {
_cutItem = item;
_copiedItem = null;
notifyListeners();
}
void copy(FileItem item) {
_copiedItem = item;
_cutItem = null;
notifyListeners();
}
Future<void> paste(FileItem targetDir) async {
if (!targetDir.isDirectory) return;
if (_cutItem != null) {
final source = _cutItem!;
await FileService.instance.moveEntity(source.path, targetDir.path);
_cutItem = null;
await refreshTree();
} else if (_copiedItem != null) {
final source = _copiedItem!;
await FileService.instance.copyEntity(source.path, targetDir.path);
await refreshTree();
}
}
Future<void> createFile(String parentDir, String name) async {
final targetPath = p.join(parentDir, name.trim());
await FileService.instance.createFile(targetPath);
await refreshTree();
}
Future<void> createDirectory(String parentDir, String name) async {
final targetPath = p.join(parentDir, name.trim());
await FileService.instance.createDirectory(targetPath);
await refreshTree();
}
Future<void> rename(FileItem item, String newName) async {
await FileService.instance.renameEntity(item.path, newName.trim());
await refreshTree();
}
Future<void> delete(FileItem item) async {
await FileService.instance.deleteEntity(item.path);
await refreshTree();
}
}
+243 -33
View File
@@ -10,72 +10,150 @@ class FileService {
//构建文件目录树
Future<List<FileItem>> buildTree(
String dirPath, {
String? rootPath,
int depth = 0,
List<String> openDirectoryPaths = const [],
int maxDepth = 10,
}) async {
if (depth > maxDepth) {
return [];
}
final effectiveRoot = rootPath ?? dirPath;
final rootDir = Directory(dirPath);
if(!await rootDir.exists()) {
try {
if (!await rootDir.exists()) {
return [];
}
} catch (_) {
return [];
}
List<FileItem> items = [];
try {
final List<FileSystemEntity> entities = await rootDir.list().toList();
for(var entity in entities) {
final fileName = p.basename(entity.path);
if(fileName.startsWith('.')) continue;
final List<FileSystemEntity> entities = await rootDir
.list(followLinks: false)
.handleError((e) {
// 忽略无权限或已损坏的项目
})
.toList();
if(entity is Directory) {
final isDirOpen = openDirectoryPaths.contains(entity.path);
final children = await buildTree(
entity.path,
depth: depth + 1,
openDirectoryPaths: openDirectoryPaths,
);
items.add(FileItem(
name: fileName,
path: entity.path,
isDirectory: true,
children: children,
depth: depth,
isOpen: isDirOpen,
));
}else if(entity is File) {
items.add(FileItem(
name: fileName,
path: entity.path,
isDirectory: false,
depth: depth,
));
final normalizedOpenPaths = openDirectoryPaths.map((e) => p.normalize(e)).toSet();
for (var entity in entities) {
try {
final fileName = p.basename(entity.path);
if (fileName.startsWith('.')) continue;
final entityPath = p.normalize(entity.path);
String? relativePath;
try {
relativePath = p.relative(entityPath, from: effectiveRoot);
} catch (_) {}
if (entity is Directory) {
final isDirOpen = normalizedOpenPaths.contains(entityPath);
List<FileItem> children = [];
// 只有当该子目录确实被用户展开时,才递归加载其子项,避免无限制深度扫描
if (isDirOpen) {
children = await buildTree(
entityPath,
rootPath: effectiveRoot,
depth: depth + 1,
openDirectoryPaths: openDirectoryPaths,
maxDepth: maxDepth,
);
}
items.add(FileItem(
name: fileName,
path: entityPath,
relativePath: relativePath,
isDirectory: true,
children: children,
depth: depth,
isOpen: isDirOpen,
));
} else if (entity is File) {
items.add(FileItem(
name: fileName,
path: entityPath,
relativePath: relativePath,
isDirectory: false,
depth: depth,
));
}
} catch (_) {
// 单个文件/目录异常跳过,防止整体崩溃
continue;
}
}
items.sort((a, b) {
if(a.isDirectory && !b.isDirectory) return -1;
if(!a.isDirectory && b.isDirectory) return 1;
if (a.isDirectory && !b.isDirectory) return -1;
if (!a.isDirectory && b.isDirectory) return 1;
return a.name.toLowerCase().compareTo(b.name.toLowerCase());
});
}catch(e) {
print('扫描目录出错: $e');
} catch (_) {
// 扫描顶层目录出错,安全返回已扫描项
}
return items;
}
// 常见的二进制文件扩展名(不适合在代码文本编辑器中打开)
static const Set<String> _binaryExtensions = {
'.exe', '.dll', '.bin', '.so', '.dylib', '.class', '.pyc',
'.zip', '.tar', '.gz', '.7z', '.rar', '.iso', '.apk', '.aab',
'.png', '.jpg', '.jpeg', '.gif', '.webp', '.ico', '.bmp',
'.mp3', '.mp4', '.wav', '.avi', '.mov', '.flv', '.mkv',
'.pdf', '.doc', '.docx', '.xls', '.xlsx', '.ppt', '.pptx',
'.db', '.sqlite', '.sqlite3',
};
// 最大允许读取为文本的大小(默认 2MB)
static const int maxTextFileSize = 2 * 1024 * 1024;
//阅读文件内容
Future<String> readFileContent(String path) async {
final file = File(path);
if(!await file.exists()) {
if (!await file.exists()) {
throw FileSystemException('文件不存在或已被移除', path);
}
final ext = p.extension(path).toLowerCase();
if (_binaryExtensions.contains(ext)) {
throw const FileSystemException('此文件是二进制可执行文件或多媒体文件,不支持作为文本编辑');
}
final length = await file.length();
if (length > maxTextFileSize) {
final sizeMb = (length / (1024 * 1024)).toStringAsFixed(1);
throw FileSystemException('文件过大 (${sizeMb}MB),超过了编辑器限制 (2MB),暂不支持直接打开');
}
try {
// 先采样前 4KB 检测是否包含二进制 0x00 字节,防止无后缀的二进制文件被当作文本读入导致卡死
final raf = await file.open(mode: FileMode.read);
try {
final buffer = List<int>.filled(4096, 0);
final bytesRead = await raf.readInto(buffer, 0, 4096);
for (int i = 0; i < bytesRead; i++) {
if (buffer[i] == 0) {
throw const FileSystemException('检测到该文件为二进制格式,不支持作为文本展示与编辑');
}
}
} finally {
await raf.close();
}
return await file.readAsString(
encoding: const Utf8Codec(allowMalformed: true),
);
}catch (e) {
} catch (e) {
if (e is FileSystemException) rethrow;
throw FileSystemException('读取文件失败: $e', path);
}
}
@@ -85,4 +163,136 @@ class FileService {
final file = File(path);
await file.writeAsString(content, encoding: utf8, flush: true);
}
// 新建文件
Future<void> createFile(String targetPath) async {
final file = File(targetPath);
if (await file.exists()) {
throw FileSystemException('文件已存在', targetPath);
}
await file.create(recursive: true);
}
// 新建文件夹
Future<void> createDirectory(String targetPath) async {
final dir = Directory(targetPath);
if (await dir.exists()) {
throw FileSystemException('文件夹已存在', targetPath);
}
await dir.create(recursive: true);
}
// 重命名
Future<void> renameEntity(String oldPath, String newName) async {
final entityType = await FileSystemEntity.type(oldPath);
if (entityType == FileSystemEntityType.notFound) {
throw FileSystemException('项目不存在', oldPath);
}
final parentDir = p.dirname(oldPath);
final newPath = p.join(parentDir, newName);
if (entityType == FileSystemEntityType.directory) {
await Directory(oldPath).rename(newPath);
} else {
await File(oldPath).rename(newPath);
}
}
// 删除
Future<void> deleteEntity(String targetPath) async {
final entityType = await FileSystemEntity.type(targetPath);
if (entityType == FileSystemEntityType.directory) {
await Directory(targetPath).delete(recursive: true);
} else if (entityType == FileSystemEntityType.file) {
await File(targetPath).delete();
}
}
// 递归拷贝文件夹或文件
Future<void> copyEntity(String sourcePath, String destinationDir) async {
final entityType = await FileSystemEntity.type(sourcePath);
final baseName = p.basename(sourcePath);
String targetPath = p.join(destinationDir, baseName);
// 如果同名,自动生成副本名称(如 file(1).dart)
targetPath = await _getUniqueTargetPath(targetPath, entityType == FileSystemEntityType.directory);
if (entityType == FileSystemEntityType.directory) {
await _copyDirectory(Directory(sourcePath), Directory(targetPath));
} else if (entityType == FileSystemEntityType.file) {
await File(sourcePath).copy(targetPath);
}
}
// 移动(用于剪切后粘贴)
Future<void> moveEntity(String sourcePath, String destinationDir) async {
final entityType = await FileSystemEntity.type(sourcePath);
final baseName = p.basename(sourcePath);
String targetPath = p.join(destinationDir, baseName);
if (p.equals(p.dirname(sourcePath), destinationDir)) {
// 在同一目录下粘贴剪切的项目,无需操作
return;
}
targetPath = await _getUniqueTargetPath(targetPath, entityType == FileSystemEntityType.directory);
if (entityType == FileSystemEntityType.directory) {
try {
await Directory(sourcePath).rename(targetPath);
} catch (_) {
// 跨盘符或无法直接 rename 时退化为 copy + delete
await _copyDirectory(Directory(sourcePath), Directory(targetPath));
await Directory(sourcePath).delete(recursive: true);
}
} else if (entityType == FileSystemEntityType.file) {
try {
await File(sourcePath).rename(targetPath);
} catch (_) {
await File(sourcePath).copy(targetPath);
await File(sourcePath).delete();
}
}
}
Future<void> _copyDirectory(Directory source, Directory destination) async {
await destination.create(recursive: true);
await for (final entity in source.list(recursive: false, followLinks: false)) {
final newPath = p.join(destination.path, p.basename(entity.path));
if (entity is Directory) {
await _copyDirectory(entity, Directory(newPath));
} else if (entity is File) {
await entity.copy(newPath);
}
}
}
Future<String> _getUniqueTargetPath(String originalPath, bool isDirectory) async {
if (!await FileSystemEntity.isDirectory(originalPath) &&
!await FileSystemEntity.isFile(originalPath)) {
return originalPath;
}
final parent = p.dirname(originalPath);
final ext = isDirectory ? '' : p.extension(originalPath);
final nameWithoutExt = isDirectory
? p.basename(originalPath)
: p.basenameWithoutExtension(originalPath);
int counter = 1;
while (true) {
final candidateName = '$nameWithoutExt($counter)$ext';
final candidatePath = p.join(parent, candidateName);
if (!await FileSystemEntity.isDirectory(candidatePath) &&
!await FileSystemEntity.isFile(candidatePath)) {
return candidatePath;
}
counter++;
}
}
Future<bool> entityExists(String path) async {
final type = await FileSystemEntity.type(path);
return type != FileSystemEntityType.notFound;
}
}
+21 -139
View File
@@ -1,155 +1,37 @@
import 'package:code_editor/l10n/app_localizations.dart';
import 'package:code_editor/models/file_directory_history.dart';
import 'package:code_editor/models/file_item.dart';
import 'package:code_editor/services/file_directory_history_service.dart';
import 'package:code_editor/services/file_service.dart';
import 'package:code_editor/providers/editor_provider.dart';
import 'package:code_editor/widgets/code_editor_app_bar.dart';
import 'package:code_editor/widgets/code_editor_drawer.dart';
import 'package:code_editor/widgets/code_editor_widget.dart';
import 'package:code_editor/widgets/file_tree_widget.dart';
import 'package:flutter/material.dart';
import 'package:path/path.dart' as p;
import 'package:provider/provider.dart';
class MainView extends StatefulWidget {
class MainView extends StatelessWidget {
const MainView({super.key});
@override
State<MainView> createState() => _MainViewState();
}
class _MainViewState extends State<MainView> {
List<FileItem> _items = [];
FileDirectoryHistory _history = const FileDirectoryHistory(rootPath: null, lastOpenedFilePath: "未命名");
bool _isLoading = false;
@override
void initState() {
super.initState();
_loadFileItems();
}
Future<void> _loadFileItems() async {
setState(() {
_isLoading = true;
});
try {
FileDirectoryHistory? lastHistory = await FileDirectoryHistoryService.instance.getLastHistory();
if(lastHistory == null) {
if(mounted) {
setState(() {
_isLoading = false;
});
}
}else {
final path = lastHistory.rootPath;
List<FileItem> items = (path != null && path.trim().isNotEmpty)
? await FileService.instance.buildTree(
path,
openDirectoryPaths: lastHistory.openDirectoryPaths,
)
: [];
if(mounted) {
setState(() {
_items = items;
_history = lastHistory;
_isLoading = false;
});
}
}
} catch (e) {
if(mounted) {
setState(() {
_isLoading = false;
});
}
}
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final l10n = AppLocalizations.of(context)!;
if(_isLoading) {
final isLoading = context.select<EditorProvider, bool>((p) => p.isLoading);
if (isLoading) {
return const Center(child: CircularProgressIndicator());
}
final fileName = _history.lastOpenedFilePath;
final rootPath = _history.rootPath;
final currentFile = context.select<EditorProvider, String?>((p) => p.currentFilePath);
final rootPath = context.select<EditorProvider, String?>((p) => p.rootPath);
return Scaffold(
//顶部导航栏
appBar: AppBar(
backgroundColor: theme.colorScheme.primaryContainer,
foregroundColor: theme.colorScheme.onPrimaryContainer,
title: Text(fileName != null ? p.basename(fileName) : ''),
actions: [
IconButton(
icon: const Icon(Icons.undo),
tooltip: l10n.undo,
onPressed: () {},
),
IconButton(
icon: const Icon(Icons.redo),
tooltip: l10n.redo,
onPressed: () {},
),
IconButton(
icon: const Icon(Icons.save_outlined),
tooltip: l10n.save,
onPressed: () {},
),
IconButton(
icon: const Icon(Icons.play_arrow),
tooltip: l10n.run,
onPressed: () {},
),
IconButton(
icon: const Icon(Icons.settings),
tooltip: l10n.settings,
onPressed: () {},
),
],
appBar: CodeEditorAppBar(
filePath: currentFile,
onUndo: () {},
onRedo: () {},
onSave: () {},
onRun: () {},
onSettings: () {},
),
//侧边栏
drawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: [
Container(
padding: const EdgeInsets.all(16.0),
decoration: BoxDecoration(
color: theme.colorScheme.primaryContainer,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(children: [
Text(l10n.fileDirectory, style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold
)),
const Spacer(),
IconButton(
icon: const Icon(Icons.folder_open),
tooltip: l10n.openFileDirectory,
onPressed: () {},
),
IconButton(
icon: const Icon(Icons.history),
tooltip: l10n.viewFileDirectoryHistory,
onPressed: () {},
),
]),
Text(rootPath ?? '')
],
),
),
FileTreeWidget(rootFileItem: _items.isEmpty ? null : _items[0])
],
),
drawer: const CodeEditorDrawer(),
body: CodeEditorWidget(
filePath: currentFile,
rootPath: rootPath,
),
body: CodeEditorWidget(filePath: _history.lastOpenedFilePath, rootPath: _history.rootPath)
);
}
}
+70
View File
@@ -0,0 +1,70 @@
import 'package:code_editor/l10n/app_localizations.dart';
import 'package:flutter/material.dart';
import 'package:path/path.dart' as p;
class CodeEditorAppBar extends StatelessWidget implements PreferredSizeWidget {
final String? filePath;
final VoidCallback? onUndo;
final VoidCallback? onRedo;
final VoidCallback? onSave;
final VoidCallback? onRun;
final VoidCallback? onSettings;
const CodeEditorAppBar({
super.key,
required this.filePath,
this.onUndo,
this.onRedo,
this.onSave,
this.onRun,
this.onSettings,
});
@override
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final l10n = AppLocalizations.of(context)!;
final path = filePath;
return AppBar(
backgroundColor: theme.colorScheme.primaryContainer,
foregroundColor: theme.colorScheme.onPrimaryContainer,
title: Text(path != null && path.isNotEmpty ? p.basename(path) : ''),
actions: [
IconButton(
visualDensity: VisualDensity.compact,
icon: const Icon(Icons.undo),
tooltip: l10n.undo,
onPressed: onUndo ?? () {},
),
IconButton(
visualDensity: VisualDensity.compact,
icon: const Icon(Icons.redo),
tooltip: l10n.redo,
onPressed: onRedo ?? () {},
),
IconButton(
visualDensity: VisualDensity.compact,
icon: const Icon(Icons.save_outlined),
tooltip: l10n.save,
onPressed: onSave ?? () {},
),
IconButton(
visualDensity: VisualDensity.compact,
icon: const Icon(Icons.play_arrow),
tooltip: l10n.run,
onPressed: onRun ?? () {},
),
IconButton(
visualDensity: VisualDensity.compact,
icon: const Icon(Icons.settings),
tooltip: l10n.settings,
onPressed: onSettings ?? () {},
),
],
);
}
}
+82
View File
@@ -0,0 +1,82 @@
import 'package:code_editor/l10n/app_localizations.dart';
import 'package:code_editor/providers/editor_provider.dart';
import 'package:code_editor/widgets/file_directory_history_widget.dart';
import 'package:code_editor/widgets/file_tree_widget.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class CodeEditorDrawer extends StatelessWidget {
const CodeEditorDrawer({super.key});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final l10n = AppLocalizations.of(context)!;
final rootPath = context.select<EditorProvider, String?>((p) => p.rootPath);
return Drawer(
child: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
padding: const EdgeInsets.all(16.0),
decoration: BoxDecoration(
color: theme.colorScheme.primaryContainer,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text(
l10n.fileDirectory,
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
const Spacer(),
IconButton(
icon: const Icon(Icons.refresh),
tooltip: '刷新目录',
onPressed: () => context.read<EditorProvider>().refreshTree(),
),
IconButton(
icon: const Icon(Icons.folder_open),
tooltip: l10n.openFileDirectory,
onPressed: () => context.read<EditorProvider>().openDirectory(),
),
IconButton(
icon: const Icon(Icons.history),
tooltip: l10n.viewFileDirectoryHistory,
onPressed: () {
FileDirectoryHistoryWidget.show(
context,
onSelectHistory: (selectedHistory) {
context.read<EditorProvider>().switchProject(selectedHistory);
},
);
},
),
],
),
Text(
rootPath ?? '',
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onPrimaryContainer.withValues(alpha: 0.8),
),
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
],
),
),
const Expanded(
child: FileTreeWidget(),
),
],
),
),
);
}
}
+67 -21
View File
@@ -49,37 +49,79 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
@override
Widget build(BuildContext context) {
if(_isLoading) {
final hasNoProject = widget.rootPath == null || widget.rootPath!.trim().isEmpty;
final hasNoFile = widget.filePath == null || widget.filePath!.trim().isEmpty;
if (hasNoProject && hasNoFile) {
return Center(
child: Text(
"当前未打开文件目录",
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
);
}
if (_isLoading) {
return const Center(child: CircularProgressIndicator());
}
return CodeTheme(
data: CodeThemeData(styles: atomOneDarkTheme),
child: CodeField(
controller: _controller,
gutterStyle: const GutterStyle(
showLineNumbers: true,
showFoldingHandles: true,
if (_errorMessage != null) {
return Center(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Text(
_errorMessage!,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.error,
),
),
),
);
}
if (hasNoFile) {
return Center(
child: Text(
"当前未打开文件",
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
);
}
// atomOneDark 默认背景色为 0xFF282C34
const editorBgColor = Color(0xFF282C34);
return Container(
color: editorBgColor,
width: double.infinity,
height: double.infinity,
child: CodeTheme(
data: CodeThemeData(styles: atomOneDarkTheme),
child: SingleChildScrollView(
child: CodeField(
controller: _controller,
gutterStyle: const GutterStyle(
showLineNumbers: true,
showFoldingHandles: true,
),
),
),
),
);
}
Future<void> _loadFileContent() async {
String? fullFilePath;
final filePath = widget.filePath;
final rootPath = widget.rootPath;
final filePath = widget.filePath;
final hasNoProject = rootPath == null || rootPath.trim().isEmpty;
final hasNoFile = filePath == null || filePath.trim().isEmpty;
if (filePath != null && filePath.isNotEmpty) {
if (rootPath != null && rootPath.isNotEmpty && !p.isAbsolute(filePath)) {
fullFilePath = p.join(rootPath, filePath);
} else {
fullFilePath = filePath;
}
}
if(fullFilePath == null) {
if (hasNoFile) {
_controller.text = '';
if(mounted) {
if (mounted) {
setState(() {
_isLoading = false;
_errorMessage = null;
@@ -88,6 +130,10 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
return;
}
final String fullFilePath = (hasNoProject || p.isAbsolute(filePath))
? filePath
: p.join(rootPath, filePath);
final int requestVersion = ++_currentLoadVersion;
setState(() {
@@ -106,7 +152,7 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
}catch(e) {
if(!mounted || requestVersion != _currentLoadVersion) return;
setState(() {
_errorMessage = '读取文件失败: $e';
_errorMessage = '$e';
});
}finally {
if(mounted && requestVersion == _currentLoadVersion) {
@@ -0,0 +1,229 @@
import 'package:code_editor/models/file_directory_history.dart';
import 'package:code_editor/services/file_directory_history_service.dart';
import 'package:flutter/material.dart';
import 'package:path/path.dart' as p;
class FileDirectoryHistoryWidget extends StatefulWidget {
final ValueChanged<FileDirectoryHistory>? onSelectHistory;
const FileDirectoryHistoryWidget({
super.key,
this.onSelectHistory,
});
/// 打开历史弹窗(不关闭后方的 Drawer)
static Future<void> show(
BuildContext context, {
ValueChanged<FileDirectoryHistory>? onSelectHistory,
}) {
return showDialog<void>(
context: context,
barrierDismissible: true,
builder: (BuildContext dialogContext) {
return FileDirectoryHistoryWidget(
onSelectHistory: onSelectHistory,
);
},
);
}
@override
State<FileDirectoryHistoryWidget> createState() =>
_FileDirectoryHistoryWidgetState();
}
class _FileDirectoryHistoryWidgetState
extends State<FileDirectoryHistoryWidget> {
List<FileDirectoryHistory> _historyList = [];
bool _isLoading = true;
@override
void initState() {
super.initState();
_loadHistory();
}
Future<void> _loadHistory() async {
final list = await FileDirectoryHistoryService.instance.getFullHistory();
if (mounted) {
setState(() {
_historyList = list;
_isLoading = false;
});
}
}
Future<void> _deleteHistory(FileDirectoryHistory item) async {
final root = item.rootPath;
if (root != null && root.isNotEmpty) {
await FileDirectoryHistoryService.instance.removeHistory(root);
await _loadHistory();
}
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Dialog(
clipBehavior: Clip.antiAlias,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.0),
side: BorderSide(
color: theme.colorScheme.outlineVariant,
width: 1.0,
),
),
insetPadding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 32.0),
child: ConstrainedBox(
constraints: const BoxConstraints(
maxWidth: 480,
maxHeight: 520,
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// 1. Title 区域:加粗、与 AppBar 相同背景颜色、右上角 X 关闭
Container(
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 12.0),
color: theme.colorScheme.primaryContainer,
child: Row(
children: [
Expanded(
child: Text(
'历史文件目录',
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
color: theme.colorScheme.onPrimaryContainer,
),
),
),
IconButton(
icon: Icon(
Icons.close,
color: theme.colorScheme.onPrimaryContainer,
),
tooltip: '关闭',
visualDensity: VisualDensity.compact,
onPressed: () => Navigator.of(context).pop(),
),
],
),
),
// 2. 列表区域
Flexible(
child: _isLoading
? const Center(
child: Padding(
padding: EdgeInsets.all(32.0),
child: CircularProgressIndicator(),
),
)
: _historyList.isEmpty
? Center(
child: Padding(
padding: const EdgeInsets.all(32.0),
child: Text(
'暂无历史记录',
style: TextStyle(
color: theme.colorScheme.onSurfaceVariant,
fontSize: 14,
),
),
),
)
: ListView.separated(
shrinkWrap: true,
padding: const EdgeInsets.symmetric(vertical: 8.0),
itemCount: _historyList.length,
separatorBuilder: (context, index) => const Divider(
height: 1,
indent: 16,
endIndent: 16,
),
itemBuilder: (context, index) {
final item = _historyList[index];
final lastFile = item.lastOpenedFilePath;
final fileName = (lastFile != null &&
lastFile.trim().isNotEmpty)
? p.basename(lastFile)
: '未打开文件';
final rootDir = item.rootPath ?? '未知目录';
return InkWell(
onTap: () {
Navigator.of(context).pop();
widget.onSelectHistory?.call(item);
},
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16.0,
vertical: 12.0,
),
child: Row(
children: [
// 左边:历史图标
Icon(
Icons.history,
size: 24,
color: theme.colorScheme.primary,
),
const SizedBox(width: 12),
// 中间:撑开,占据最大空间,两行字
Expanded(
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
// 上面:大的上一次打开的文件名称
Text(
fileName,
style: theme.textTheme.titleSmall?.copyWith(
fontWeight: FontWeight.w600,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 4),
// 下面:一行小字表示根目录
Text(
rootDir,
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
),
),
const SizedBox(width: 8),
// 右边:删除历史记录的图标,点击后删除
IconButton(
icon: Icon(
Icons.delete_outline,
size: 20,
color: theme.colorScheme.error,
),
tooltip: '删除此记录',
visualDensity: VisualDensity.compact,
onPressed: () => _deleteHistory(item),
),
],
),
),
);
},
),
),
],
),
),
);
}
}
+541 -92
View File
@@ -1,147 +1,596 @@
import 'package:code_editor/models/file_item.dart';
import 'package:code_editor/providers/editor_provider.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
class FileItemWidget extends StatefulWidget {
final FileItem fileItem;
const FileItemWidget({
super.key,
required this.fileItem
super.key,
required this.fileItem,
});
@override
State<FileItemWidget> createState() => _FileItemWidget();
State<FileItemWidget> createState() => _FileItemWidgetState();
}
class _FileItemWidget extends State<FileItemWidget> {
class _FileItemWidgetState extends State<FileItemWidget> {
@override
Widget build(BuildContext context) {
return _buildFileItem(context, widget.fileItem);
}
Widget _buildFileItem(BuildContext context, FileItem item) {
final theme = Theme.of(context);
final provider = context.watch<EditorProvider>();
final indent = EdgeInsets.only(left: item.depth * 16.0 + 8.0, right: 8.0);
if(item.isDirectory) {
if(item.isOpen) {
return GestureDetector(
onLongPressStart: (details) {
_showContextMenu(context, item, details.globalPosition);
},
child: ExpansionTile(
initiallyExpanded: item.isOpen,
onExpansionChanged: (bool expanded) {
// 判断该文件是否处于被剪切状态
final isCut = provider.isItemCut(item.path);
// 判断该文件是否为当前正在编辑/修改的文件
final isSelected = !item.isDirectory && provider.isFileSelected(item.path);
// 文字样式:剪切时变灰,选中时高亮,其余正常
final itemTextStyle = theme.textTheme.bodyMedium?.copyWith(
fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
color: isCut
? theme.colorScheme.onSurface.withValues(alpha: 0.38)
: isSelected
? theme.colorScheme.primary
: null,
);
final iconColor = isCut
? theme.colorScheme.onSurface.withValues(alpha: 0.38)
: isSelected
? theme.colorScheme.primary
: null;
if (item.isDirectory) {
return GestureDetector(
onLongPressStart: (details) {
_showContextMenu(item, details.globalPosition);
},
child: ExpansionTile(
key: PageStorageKey(item.path),
initiallyExpanded: item.isOpen,
tilePadding: indent,
leading: Icon(
item.isOpen ? Icons.folder_open_outlined : Icons.folder_outlined,
color: isCut ? iconColor : null,
size: 20,
),
title: Text(
item.name,
style: itemTextStyle,
),
dense: true,
onExpansionChanged: (bool expanded) {
setState(() {
item.isOpen = expanded;
},
tilePadding: indent,
leading: const Icon(Icons.folder_outlined, color: Colors.amber, size: 20),
title: Text(
item.name,
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500),
),
dense: true,
children: item.children.map((child) => _buildFileItem(context, child)).toList()
)
);
}else {
return GestureDetector(
onLongPressStart: (details) {
_showContextMenu(context, item, details.globalPosition);
});
context.read<EditorProvider>().toggleDirectory(item, expanded);
},
children: item.children
.map((child) => FileItemWidget(fileItem: child))
.toList(),
),
);
} else {
return GestureDetector(
onLongPressStart: (details) {
_showContextMenu(item, details.globalPosition);
},
child: Container(
margin: const EdgeInsets.symmetric(vertical: 1.0),
decoration: BoxDecoration(
color: isSelected
? theme.colorScheme.primaryContainer.withValues(alpha: 0.5)
: Colors.transparent,
borderRadius: BorderRadius.circular(8.0),
),
child: ListTile(
contentPadding: indent,
leading: Icon(Icons.file_copy),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
selected: isSelected,
selectedTileColor: Colors.transparent,
leading: Icon(
_getFileIcon(item),
size: 20,
color: iconColor,
),
title: Text(
item.name,
style: const TextStyle(fontSize: 13),
style: itemTextStyle,
),
dense: true,
onTap: () {
_openFile(item);
Navigator.of(context).maybePop(); // 关闭 Drawer
context.read<EditorProvider>().selectFile(item);
},
)
);
}
}else {
return GestureDetector(
onLongPressStart: (details) {
_showContextMenu(context, item, details.globalPosition);
},
child: ListTile(
contentPadding: indent,
leading: Icon(Icons.file_copy),
title: Text(
item.name,
style: const TextStyle(fontSize: 13),
),
dense: true,
onTap: () {
_openFile(item);
},
)
),
);
}
}
//打开文件
void _openFile(FileItem item) {
IconData _getFileIcon(FileItem item) {
final lowerName = item.name.toLowerCase();
if (lowerName == '.gitignore' || lowerName == '.gitattributes' || lowerName == '.gitmodules') {
return Icons.commit_outlined;
}
switch (item.extension) {
case '.dart':
return Icons.flutter_dash;
case '.html':
case '.htm':
return Icons.html;
case '.css':
case '.scss':
case '.sass':
case '.less':
return Icons.css;
case '.js':
case '.mjs':
case '.cjs':
return Icons.javascript;
case '.ts':
case '.tsx':
case '.jsx':
case '.vue':
case '.svelte':
return Icons.code;
case '.json':
return Icons.data_object;
case '.yaml':
case '.yml':
case '.toml':
case '.ini':
case '.env':
case '.conf':
case '.config':
case '.properties':
return Icons.settings_suggest_outlined;
case '.xml':
return Icons.code;
case '.md':
case '.markdown':
return Icons.article_outlined;
case '.pdf':
return Icons.picture_as_pdf_outlined;
case '.py':
case '.pyw':
case '.java':
case '.kt':
case '.kts':
case '.c':
case '.cpp':
case '.cc':
case '.h':
case '.hpp':
case '.cs':
case '.go':
case '.rs':
case '.swift':
case '.rb':
case '.php':
return Icons.code;
case '.sh':
case '.bash':
case '.zsh':
case '.bat':
case '.cmd':
case '.ps1':
return Icons.terminal;
case '.sql':
case '.db':
case '.sqlite':
return Icons.storage_outlined;
case '.png':
case '.jpg':
case '.jpeg':
case '.gif':
case '.webp':
case '.svg':
case '.ico':
case '.bmp':
return Icons.image_outlined;
case '.mp3':
case '.wav':
case '.ogg':
case '.flac':
case '.aac':
return Icons.audio_file_outlined;
case '.mp4':
case '.avi':
case '.mov':
case '.mkv':
case '.flv':
case '.webm':
return Icons.video_file_outlined;
case '.zip':
case '.rar':
case '.7z':
case '.tar':
case '.gz':
return Icons.folder_zip_outlined;
case '.lock':
return Icons.lock_outline;
case '.txt':
default:
return Icons.description_outlined;
}
}
void _showContextMenu(BuildContext context, FileItem item, Offset tapPosition) async {
void _showContextMenu(FileItem item, Offset tapPosition) async {
final overlay = Overlay.of(context).context.findRenderObject() as RenderBox;
final position = RelativeRect.fromRect(
Rect.fromLTWH(tapPosition.dx, tapPosition.dy, 0, 0),
Offset.zero & overlay.size,
);
// 弹出 Material 原生菜单
final theme = Theme.of(context);
final onSurfaceColor = theme.colorScheme.onSurface;
final canPaste = context.read<EditorProvider>().canPaste;
final menuItems = <PopupMenuEntry<String>>[];
if (item.isDirectory) {
menuItems.addAll([
_buildMenuItem('new_file', Icons.note_add_outlined, '新建文件', onSurfaceColor),
_buildMenuItem('new_folder', Icons.create_new_folder_outlined, '新建文件夹', onSurfaceColor),
const PopupMenuDivider(),
_buildMenuItem('cut', Icons.content_cut, '剪切', onSurfaceColor),
_buildMenuItem('copy', Icons.copy, '复制', onSurfaceColor),
PopupMenuItem<String>(
value: 'paste',
enabled: canPaste,
child: Row(
children: [
Icon(
Icons.paste,
size: 18,
color: canPaste
? onSurfaceColor
: onSurfaceColor.withValues(alpha: 0.38),
),
const SizedBox(width: 8),
Text(
'粘贴',
style: TextStyle(
color: canPaste
? onSurfaceColor
: onSurfaceColor.withValues(alpha: 0.38),
),
),
],
),
),
const PopupMenuDivider(),
_buildMenuItem('copy_path', Icons.link, '复制路径', onSurfaceColor),
_buildMenuItem('copy_relative_path', Icons.short_text, '复制相对路径', onSurfaceColor),
const PopupMenuDivider(),
_buildMenuItem('rename', Icons.edit_outlined, '重命名', onSurfaceColor),
_buildMenuItem(
'delete',
Icons.delete_outline,
'删除',
theme.colorScheme.error,
isDestructive: true,
),
]);
} else {
menuItems.addAll([
_buildMenuItem('cut', Icons.content_cut, '剪切', onSurfaceColor),
_buildMenuItem('copy', Icons.copy, '复制', onSurfaceColor),
const PopupMenuDivider(),
_buildMenuItem('copy_path', Icons.link, '复制路径', onSurfaceColor),
_buildMenuItem('copy_relative_path', Icons.short_text, '复制相对路径', onSurfaceColor),
const PopupMenuDivider(),
_buildMenuItem('rename', Icons.edit_outlined, '重命名', onSurfaceColor),
_buildMenuItem(
'delete',
Icons.delete_outline,
'删除',
theme.colorScheme.error,
isDestructive: true,
),
]);
}
final selectedAction = await showMenu<String>(
context: context,
position: position,
color: const Color(0xFF252526),
elevation: 8,
items: const [
PopupMenuItem(
value: 'new_file',
child: Row(
children: [
Icon(Icons.note_add_outlined, size: 18, color: Colors.blueAccent),
SizedBox(width: 8),
Text('新建文件'),
],
),
color: theme.colorScheme.surface,
surfaceTintColor: theme.colorScheme.surfaceTint,
elevation: 6,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0),
side: BorderSide(
color: theme.colorScheme.outlineVariant,
width: 1.0,
),
PopupMenuItem(
value: 'rename',
child: Row(
children: [
Icon(Icons.edit_outlined, size: 18, color: Colors.orangeAccent),
SizedBox(width: 8),
Text('重命名'),
],
),
),
PopupMenuDivider(), // 分割线
PopupMenuItem(
value: 'delete',
child: Row(
children: [
Icon(Icons.delete_outline, size: 18, color: Colors.redAccent),
SizedBox(width: 8),
Text('删除', style: TextStyle(color: Colors.redAccent)),
],
),
),
],
),
items: menuItems,
);
// 用户点击了某一项后的处理逻辑
if(selectedAction != null) {
_handleMenuAction(context, selectedAction);
if (selectedAction != null && mounted) {
_handleMenuAction(item, selectedAction);
}
}
void _handleMenuAction(BuildContext context, String action) {
PopupMenuItem<String> _buildMenuItem(
String value,
IconData icon,
String title,
Color iconColor, {
bool isDestructive = false,
}) {
final theme = Theme.of(context);
return PopupMenuItem<String>(
value: value,
child: Row(
children: [
Icon(icon, size: 18, color: iconColor),
const SizedBox(width: 8),
Text(
title,
style: isDestructive
? TextStyle(color: theme.colorScheme.error)
: TextStyle(color: theme.colorScheme.onSurface),
),
],
),
);
}
void _handleMenuAction(FileItem item, String action) async {
final provider = context.read<EditorProvider>();
switch (action) {
case 'new_file':
await _showCreateInputDialog(
title: '新建文件',
hintText: '文件名 (例如: main.dart)',
onConfirm: (name) async {
await provider.createFile(item.path, name);
},
);
break;
case 'new_folder':
await _showCreateInputDialog(
title: '新建文件夹',
hintText: '文件夹名',
onConfirm: (name) async {
await provider.createDirectory(item.path, name);
},
);
break;
case 'cut':
provider.cut(item);
if (mounted) _showToast(context, '已剪切: ${item.name}');
break;
case 'copy':
provider.copy(item);
if (mounted) _showToast(context, '已复制: ${item.name}');
break;
case 'paste':
try {
await provider.paste(item);
if (mounted) _showToast(context, '操作成功');
} catch (e) {
if (mounted) _showToast(context, '操作失败: $e', isError: true);
}
break;
case 'copy_path':
await Clipboard.setData(ClipboardData(text: item.fullPath));
if (mounted) {
_showToast(context, '已复制完整路径到剪贴板');
}
break;
case 'copy_relative_path':
await Clipboard.setData(ClipboardData(text: item.getRelativePath(provider.rootPath)));
if (mounted) {
_showToast(context, '已复制相对路径到剪贴板');
}
break;
case 'rename':
await _showCreateInputDialog(
title: '重命名',
hintText: '新名称',
initialValue: item.name,
onConfirm: (newName) async {
if (newName.trim() == item.name) return;
await provider.rename(item, newName.trim());
},
);
break;
case 'delete':
final confirmed = await _showConfirmDialog(
title: '确认删除',
content: '确定要删除 "${item.name}" 吗?此操作不可恢复。',
);
if (confirmed == true && mounted) {
await provider.delete(item);
}
break;
}
}
void _showToast(BuildContext context, String message, {bool isError = false}) {
final overlay = Overlay.of(context, rootOverlay: true);
final theme = Theme.of(context);
late OverlayEntry entry;
entry = OverlayEntry(
builder: (ctx) => Positioned(
bottom: 48,
left: 0,
right: 0,
child: Center(
child: Material(
color: Colors.transparent,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
decoration: BoxDecoration(
color: isError
? theme.colorScheme.errorContainer
: theme.colorScheme.inverseSurface,
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: isError
? theme.colorScheme.error
: theme.colorScheme.outlineVariant,
width: 1,
),
boxShadow: const [
BoxShadow(
color: Colors.black26,
blurRadius: 10,
offset: Offset(0, 4),
),
],
),
child: Text(
message,
style: theme.textTheme.bodyMedium?.copyWith(
color: isError
? theme.colorScheme.onErrorContainer
: theme.colorScheme.onInverseSurface,
fontWeight: FontWeight.w500,
),
),
),
),
),
),
);
overlay.insert(entry);
Future.delayed(const Duration(seconds: 2), () {
if (entry.mounted) {
entry.remove();
}
});
}
Future<void> _showCreateInputDialog({
required String title,
required String hintText,
String? initialValue,
required Future<void> Function(String value) onConfirm,
}) async {
final controller = TextEditingController(text: initialValue);
final formKey = GlobalKey<FormState>();
final theme = Theme.of(context);
await showDialog<void>(
context: context,
builder: (dialogContext) {
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.0),
side: BorderSide(
color: theme.colorScheme.outlineVariant,
width: 1.0,
),
),
title: Text(title),
content: Form(
key: formKey,
child: TextFormField(
controller: controller,
autofocus: true,
decoration: InputDecoration(
hintText: hintText,
border: const OutlineInputBorder(),
),
validator: (val) {
if (val == null || val.trim().isEmpty) {
return '名称不能为空';
}
if (val.contains(RegExp(r'[\\/:*?"<>|]'))) {
return '名称不能包含非法字符 (\\/:*?"<>|)';
}
return null;
},
),
),
actions: [
TextButton(
onPressed: () => Navigator.of(dialogContext).pop(),
child: const Text('取消'),
),
FilledButton(
onPressed: () async {
if (formKey.currentState?.validate() ?? false) {
final inputVal = controller.text;
Navigator.of(dialogContext).pop();
try {
await onConfirm(inputVal);
} catch (e) {
if (mounted) {
_showToast(context, '操作失败: $e', isError: true);
}
}
}
},
child: const Text('确定'),
),
],
);
},
);
}
Future<bool?> _showConfirmDialog({
required String title,
required String content,
}) {
final theme = Theme.of(context);
return showDialog<bool>(
context: context,
builder: (dialogContext) {
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.0),
side: BorderSide(
color: theme.colorScheme.outlineVariant,
width: 1.0,
),
),
title: Text(title),
content: Text(content),
actions: [
TextButton(
onPressed: () => Navigator.of(dialogContext).pop(false),
child: const Text('取消'),
),
FilledButton(
style: FilledButton.styleFrom(
backgroundColor: theme.colorScheme.error,
foregroundColor: theme.colorScheme.onError,
),
onPressed: () => Navigator.of(dialogContext).pop(true),
child: const Text('删除'),
),
],
);
},
);
}
}
+22 -20
View File
@@ -1,43 +1,46 @@
import 'package:code_editor/models/file_item.dart';
import 'package:code_editor/providers/editor_provider.dart';
import 'package:code_editor/widgets/file_item_widget.dart';
import 'package:flutter/material.dart';
import '../models/file_item.dart';
import 'package:provider/provider.dart';
class FileTreeWidget extends StatelessWidget {
final FileItem? rootFileItem;
const FileTreeWidget({
super.key,
required this.rootFileItem
});
const FileTreeWidget({super.key});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final rootPath = context.select<EditorProvider, String?>((p) => p.rootPath);
final items = context.select<EditorProvider, List<FileItem>>((p) => p.items);
final root = rootFileItem;
if(root == null) {
// 1. 如果用户还没有打开/选择任何根目录
if (rootPath == null || rootPath.trim().isEmpty) {
return Padding(
padding: const EdgeInsets.all(24.0),
child: Center(
child: Text(
"请点击上方按钮打开文件目录",
style: TextStyle(
fontWeight: FontWeight.bold
textAlign: TextAlign.center,
style: theme.textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.bold,
color: theme.colorScheme.onSurfaceVariant,
),
),
),
);
}
final children = root.children;
if(children.isEmpty) {
// 2. 如果已经选择了根目录,但该目录下没有任何文件或子目录
if (items.isEmpty) {
return Padding(
padding: const EdgeInsets.all(24.0),
child: Center(
child: Text(
"目录为空",
style: TextStyle(
fontWeight: FontWeight.bold
textAlign: TextAlign.center,
style: theme.textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.bold,
color: theme.colorScheme.onSurfaceVariant,
),
),
),
@@ -45,13 +48,12 @@ class FileTreeWidget extends StatelessWidget {
}
return ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
padding: EdgeInsets.zero,
itemCount: children.length,
key: const PageStorageKey('code_editor_file_tree_list'),
padding: const EdgeInsets.symmetric(horizontal: 4.0),
itemCount: items.length,
itemBuilder: (context, index) {
return FileItemWidget(
fileItem: children[index],
fileItem: items[index],
);
},
);
@@ -5,10 +5,12 @@
import FlutterMacOS
import Foundation
import file_picker
import shared_preferences_foundation
import url_launcher_macos
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FilePickerPlugin.register(with: registry.registrar(forPlugin: "FilePickerPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
}
+48
View File
@@ -57,6 +57,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.19.1"
cross_file:
dependency: transitive
description:
name: cross_file
sha256: f141ea4f277af142a0356955707f6556f37b03947d39d55585981a06ca437bd6
url: "https://pub.dev"
source: hosted
version: "0.3.5+5"
crypto:
dependency: transitive
description:
@@ -105,6 +113,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "7.0.1"
file_picker:
dependency: "direct main"
description:
name: file_picker
sha256: ab13ae8ef5580a411c458d6207b6774a6c237d77ac37011b13994879f68a8810
url: "https://pub.dev"
source: hosted
version: "8.3.7"
flutter:
dependency: "direct main"
description: flutter
@@ -139,6 +155,14 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_plugin_android_lifecycle:
dependency: transitive
description:
name: flutter_plugin_android_lifecycle
sha256: "3854fe5e3bff0b113c658f260b90c95dea17c92db0f2addeac2e343dd9969785"
url: "https://pub.dev"
source: hosted
version: "2.0.35"
flutter_test:
dependency: "direct dev"
description: flutter
@@ -261,6 +285,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.5"
nested:
dependency: transitive
description:
name: nested
sha256: "03bac4c528c64c95c722ec99280375a6f2fc708eec17c7b3f07253b626cd2a20"
url: "https://pub.dev"
source: hosted
version: "1.0.0"
path:
dependency: "direct main"
description:
@@ -309,6 +341,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.8"
provider:
dependency: "direct main"
description:
name: provider
sha256: "4e82183fa20e5ca25703ead7e05de9e4cceed1fbd1eadc1ac3cb6f565a09f272"
url: "https://pub.dev"
source: hosted
version: "6.1.5+1"
scrollable_positioned_list:
dependency: transitive
description:
@@ -530,6 +570,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.1.1"
win32:
dependency: transitive
description:
name: win32
sha256: d7cb55e04cd34096cd3a79b3330245f54cb96a370a1c27adb3c84b917de8b08e
url: "https://pub.dev"
source: hosted
version: "5.15.0"
xdg_directories:
dependency: transitive
description:
+2
View File
@@ -22,6 +22,8 @@ dependencies:
highlight: ^0.7.0
shared_preferences: ^2.3.0
path: ^1.9.0
file_picker: ^8.1.7
provider: ^6.1.2
dev_dependencies:
flutter_test:
+155 -18
View File
@@ -1,30 +1,167 @@
// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility in the flutter_test package. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:code_editor/models/file_item.dart';
import 'package:code_editor/providers/editor_provider.dart';
import 'package:code_editor/widgets/code_editor_widget.dart';
import 'package:code_editor/widgets/file_item_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:path/path.dart' as p;
import 'package:provider/provider.dart';
import 'package:code_editor/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
testWidgets('App loads smoke test', (WidgetTester tester) async {
await tester.pumpWidget(const MyApp());
await tester.pump(const Duration(milliseconds: 100));
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
expect(find.byType(MyApp), findsOneWidget);
});
// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pump();
testWidgets('CodeEditorWidget shows empty directory message when rootPath is null or empty', (WidgetTester tester) async {
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: CodeEditorWidget(rootPath: null, filePath: null),
),
),
);
await tester.pumpAndSettle();
// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
expect(find.text("当前未打开文件目录"), findsOneWidget);
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: CodeEditorWidget(rootPath: '', filePath: null),
),
),
);
await tester.pumpAndSettle();
expect(find.text("当前未打开文件目录"), findsOneWidget);
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: CodeEditorWidget(rootPath: '/workspace', filePath: null),
),
),
);
await tester.pumpAndSettle();
expect(find.text("当前未打开文件"), findsOneWidget);
});
testWidgets('FileItemWidget renders specific icons and untinted folder icon', (WidgetTester tester) async {
final dartItem = FileItem(name: 'main.dart', path: '/test/main.dart', isDirectory: false);
final jsonItem = FileItem(name: 'config.json', path: '/test/config.json', isDirectory: false);
final txtItem = FileItem(name: 'notes.unknown', path: '/test/notes.unknown', isDirectory: false);
final dirItem = FileItem(name: 'src', path: '/test/src', isDirectory: true);
await tester.pumpWidget(
ChangeNotifierProvider(
create: (_) => EditorProvider(),
child: MaterialApp(
home: Scaffold(
body: Column(
children: [
FileItemWidget(fileItem: dartItem),
FileItemWidget(fileItem: jsonItem),
FileItemWidget(fileItem: txtItem),
FileItemWidget(fileItem: dirItem),
],
),
),
),
),
);
await tester.pumpAndSettle();
expect(find.byIcon(Icons.flutter_dash), findsOneWidget);
expect(find.byIcon(Icons.data_object), findsOneWidget);
expect(find.byIcon(Icons.description_outlined), findsOneWidget);
expect(find.byIcon(Icons.folder_outlined), findsOneWidget);
});
testWidgets('FileItemWidget enables paste when copiedItem is present', (WidgetTester tester) async {
final dirItem = FileItem(name: 'src', path: '/test/src', isDirectory: true);
final copiedFile = FileItem(name: 'main.dart', path: '/test/main.dart', isDirectory: false);
final provider = EditorProvider();
provider.copy(copiedFile);
await tester.pumpWidget(
ChangeNotifierProvider.value(
value: provider,
child: MaterialApp(
home: Scaffold(
body: FileItemWidget(
fileItem: dirItem,
),
),
),
),
);
await tester.pumpAndSettle();
// Long press to open context menu
await tester.longPress(find.text('src'));
await tester.pumpAndSettle();
// '粘贴' should be visible and enabled
expect(find.text('粘贴'), findsOneWidget);
final popupItem = tester.widget<PopupMenuItem<String>>(find.byWidgetPredicate(
(w) => w is PopupMenuItem<String> && w.value == 'paste',
));
expect(popupItem.enabled, isTrue);
});
test('EditorProvider manages cut, copy, and paste states correctly', () {
final provider = EditorProvider();
final file1 = FileItem(name: 'a.dart', path: '/test/a.dart', isDirectory: false);
final file2 = FileItem(name: 'b.dart', path: '/test/b.dart', isDirectory: false);
expect(provider.canPaste, isFalse);
provider.cut(file1);
expect(provider.cutItem, equals(file1));
expect(provider.copiedItem, isNull);
expect(provider.canPaste, isTrue);
expect(provider.isItemCut(file1.path), isTrue);
expect(provider.isItemCut(file2.path), isFalse);
provider.copy(file2);
expect(provider.copiedItem, equals(file2));
expect(provider.cutItem, isNull);
expect(provider.canPaste, isTrue);
expect(provider.isItemCut(file1.path), isFalse);
});
test('FileItem provides name, extension, relativePath, and fullPath', () {
final expectedRel = p.join('lib', 'main.dart');
final wsPath = p.join('workspace', 'lib', 'main.dart');
final item = FileItem(
path: wsPath,
relativePath: expectedRel,
isDirectory: false,
);
expect(item.name, equals('main.dart'));
expect(item.extension, equals('.dart'));
expect(item.nameWithoutExtension, equals('main'));
expect(item.relativePath, equals(expectedRel));
expect(item.displayPath, equals(expectedRel));
expect(item.getRelativePath('workspace'), equals(expectedRel));
final dirItem = FileItem(
path: p.join('workspace', 'lib'),
isDirectory: true,
);
expect(dirItem.name, equals('lib'));
expect(dirItem.extension, equals(''));
expect(dirItem.nameWithoutExtension, equals('lib'));
});
}