Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
5c9ed0ec
Commit
5c9ed0ec
authored
Feb 15, 2017
by
Alex Beregszaszi
Committed by
GitHub
Feb 15, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #401 from ethereum/editor-rewrite
Rewrite the editor based on the files API
parents
d55a6dc4
2370cd3f
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
117 deletions
+46
-117
app.js
src/app.js
+0
-0
editor.js
src/app/editor.js
+46
-117
No files found.
src/app.js
View file @
5c9ed0ec
This diff is collapsed.
Click to expand it.
src/app/editor.js
View file @
5c9ed0ec
/* global FileReader */
'use strict'
var
EventManager
=
require
(
'../lib/eventManager'
)
var
examples
=
require
(
'./example-contracts'
)
var
ace
=
require
(
'brace'
)
var
Range
=
ace
.
acequire
(
'ace/range'
).
Range
require
(
'../mode-solidity.js'
)
function
Editor
(
doNotLoadStorage
,
storage
)
{
var
SOL_CACHE_FILE
=
null
function
Editor
()
{
var
editor
=
ace
.
edit
(
'input'
)
document
.
getElementById
(
'input'
).
editor
=
editor
// required to access the editor during tests
var
event
=
new
EventManager
()
this
.
event
=
event
var
sessions
=
{}
var
sourceAnnotations
=
[]
var
readOnlySessions
=
{}
var
currentSession
this
.
addMarker
=
function
(
lineColumnPos
,
cssClass
)
{
var
currentRange
=
new
Range
(
lineColumnPos
.
start
.
line
,
lineColumnPos
.
start
.
column
,
lineColumnPos
.
end
.
line
,
lineColumnPos
.
end
.
column
)
return
editor
.
session
.
addMarker
(
currentRange
,
cssClass
)
}
var
emptySession
=
createSession
(
''
)
this
.
removeMarker
=
function
(
markerId
)
{
editor
.
session
.
removeMarker
(
markerId
)
}
this
.
newFile
=
function
()
{
var
untitledCount
=
''
while
(
storage
.
exists
(
'Untitled'
+
untitledCount
))
{
untitledCount
=
(
untitledCount
-
0
)
+
1
}
this
.
setCacheFile
(
'Untitled'
+
untitledCount
)
this
.
setCacheFileContent
(
''
)
}
this
.
uploadFile
=
function
(
file
,
callback
)
{
var
fileReader
=
new
FileReader
()
var
name
=
file
.
name
var
self
=
this
fileReader
.
onload
=
function
(
e
)
{
self
.
setCacheFile
(
name
)
self
.
setCacheFileContent
(
e
.
target
.
result
)
callback
()
}
fileReader
.
readAsText
(
file
)
}
this
.
setCacheFileContent
=
function
(
content
)
{
storage
.
set
(
SOL_CACHE_FILE
,
content
)
}
this
.
setCacheFile
=
function
(
cacheFile
)
{
SOL_CACHE_FILE
=
cacheFile
}
this
.
getCacheFile
=
function
()
{
return
SOL_CACHE_FILE
}
this
.
cacheFileIsPresent
=
function
()
{
return
!!
SOL_CACHE_FILE
}
this
.
setNextFile
=
function
(
fileKey
)
{
var
index
=
this
.
getFiles
().
indexOf
(
fileKey
)
this
.
setCacheFile
(
this
.
getFiles
()[
Math
.
max
(
0
,
index
-
1
)
])
function
createSession
(
content
)
{
var
s
=
new
ace
.
EditSession
(
content
,
'ace/mode/javascript'
)
s
.
setUndoManager
(
new
ace
.
UndoManager
())
s
.
setTabSize
(
4
)
s
.
setUseSoftTabs
(
true
)
return
s
}
this
.
resetSession
=
function
()
{
editor
.
setSession
(
sessions
[
this
.
getCacheFile
()])
function
switchSession
(
path
)
{
currentSession
=
path
editor
.
setSession
(
sessions
[
currentSession
])
editor
.
setReadOnly
(
readOnlySessions
[
currentSession
])
editor
.
focus
()
}
this
.
removeSession
=
function
(
fileKey
)
{
delete
sessions
[
fileKey
]
}
this
.
renameSession
=
function
(
oldFileKey
,
newFileKey
)
{
if
(
oldFileKey
!==
newFileKey
)
{
sessions
[
newFileKey
]
=
sessions
[
oldFileKey
]
this
.
removeSession
(
oldFileKey
)
this
.
open
=
function
(
path
,
content
)
{
if
(
!
sessions
[
path
])
{
var
session
=
createSession
(
content
)
sessions
[
path
]
=
session
readOnlySessions
[
path
]
=
false
}
switchSession
(
path
)
}
this
.
hasFile
=
function
(
name
)
{
return
this
.
getFiles
().
indexOf
(
name
)
!==
-
1
this
.
openReadOnly
=
function
(
path
,
content
)
{
if
(
!
sessions
[
path
])
{
var
session
=
createSession
(
content
)
sessions
[
path
]
=
session
readOnlySessions
[
path
]
=
true
}
switchSession
(
path
)
}
this
.
getFile
=
function
(
name
)
{
return
storage
.
get
(
name
)
this
.
get
=
function
(
path
)
{
if
(
currentSession
===
path
)
{
return
editor
.
getValue
()
}
}
function
getFiles
()
{
var
files
=
[]
storage
.
keys
().
forEach
(
function
(
f
)
{
// NOTE: as a temporary measure do not show the config file in the editor
if
(
f
!==
'.browser-solidity.json'
)
{
files
.
push
(
f
)
if
(
!
sessions
[
f
])
sessions
[
f
]
=
newEditorSession
(
f
)
}
})
return
files
this
.
current
=
function
(
path
)
{
if
(
editor
.
getSession
()
===
emptySession
)
{
return
}
return
currentSession
}
this
.
getFiles
=
getFiles
this
.
packageFiles
=
function
()
{
var
files
=
{}
var
filesArr
=
this
.
getFiles
()
for
(
var
f
in
filesArr
)
{
files
[
filesArr
[
f
]]
=
{
content
:
storage
.
get
(
filesArr
[
f
])
}
this
.
discard
=
function
(
path
)
{
if
(
currentSession
!==
path
)
{
delete
sessions
[
path
]
}
return
files
}
this
.
resize
=
function
()
{
...
...
@@ -133,8 +84,13 @@ function Editor (doNotLoadStorage, storage) {
}
}
this
.
getValue
=
function
()
{
return
editor
.
getValue
()
this
.
addMarker
=
function
(
lineColumnPos
,
cssClass
)
{
var
currentRange
=
new
Range
(
lineColumnPos
.
start
.
line
,
lineColumnPos
.
start
.
column
,
lineColumnPos
.
end
.
line
,
lineColumnPos
.
end
.
column
)
return
editor
.
session
.
addMarker
(
currentRange
,
cssClass
)
}
this
.
removeMarker
=
function
(
markerId
)
{
editor
.
session
.
removeMarker
(
markerId
)
}
this
.
clearAnnotations
=
function
()
{
...
...
@@ -156,15 +112,6 @@ function Editor (doNotLoadStorage, storage) {
editor
.
gotoLine
(
line
+
1
,
col
-
1
,
true
)
}
function
newEditorSession
(
filekey
)
{
var
s
=
new
ace
.
EditSession
(
storage
.
get
(
filekey
),
'ace/mode/javascript'
)
s
.
setUndoManager
(
new
ace
.
UndoManager
())
s
.
setTabSize
(
4
)
s
.
setUseSoftTabs
(
true
)
sessions
[
filekey
]
=
s
return
s
}
// Do setup on initialisation here
editor
.
on
(
'changeSession'
,
function
()
{
event
.
trigger
(
'sessionSwitched'
,
[])
...
...
@@ -178,24 +125,6 @@ function Editor (doNotLoadStorage, storage) {
editor
.
commands
.
bindKeys
({
'ctrl-t'
:
null
})
editor
.
commands
.
bindKeys
({
'ctrl-f'
:
null
})
if
(
doNotLoadStorage
)
{
return
}
var
files
=
getFiles
()
if
(
files
.
length
===
0
)
{
files
.
push
(
examples
.
ballot
.
name
)
storage
.
set
(
examples
.
ballot
.
name
,
examples
.
ballot
.
content
)
}
this
.
setCacheFile
(
files
[
0
])
for
(
var
x
in
files
)
{
sessions
[
files
[
x
]]
=
newEditorSession
(
files
[
x
])
}
editor
.
setSession
(
sessions
[
this
.
getCacheFile
()])
editor
.
resize
(
true
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment