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
ddf06bd2
Commit
ddf06bd2
authored
Jan 19, 2017
by
Alex Beregszaszi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rewrite file handling logic using the new files API
parent
d55a6dc4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
124 additions
and
168 deletions
+124
-168
app.js
src/app.js
+80
-53
editor.js
src/app/editor.js
+44
-115
No files found.
src/app.js
View file @
ddf06bd2
This diff is collapsed.
Click to expand it.
src/app/editor.js
View file @
ddf06bd2
/* global FileReader */
'use strict'
'use strict'
var
EventManager
=
require
(
'../lib/eventManager'
)
var
EventManager
=
require
(
'../lib/eventManager'
)
var
examples
=
require
(
'./example-contracts'
)
var
ace
=
require
(
'brace'
)
var
ace
=
require
(
'brace'
)
var
Range
=
ace
.
acequire
(
'ace/range'
).
Range
var
Range
=
ace
.
acequire
(
'ace/range'
).
Range
require
(
'../mode-solidity.js'
)
require
(
'../mode-solidity.js'
)
function
Editor
(
doNotLoadStorage
,
storage
)
{
function
Editor
()
{
var
SOL_CACHE_FILE
=
null
var
editor
=
ace
.
edit
(
'input'
)
var
editor
=
ace
.
edit
(
'input'
)
document
.
getElementById
(
'input'
).
editor
=
editor
// required to access the editor during tests
document
.
getElementById
(
'input'
).
editor
=
editor
// required to access the editor during tests
var
event
=
new
EventManager
()
var
event
=
new
EventManager
()
this
.
event
=
event
this
.
event
=
event
var
sessions
=
{}
var
sessions
=
{}
var
sourceAnnotations
=
[]
var
sourceAnnotations
=
[]
var
readOnlySessions
=
{}
var
currentSession
this
.
addMarker
=
function
(
lineColumnPos
,
cssClass
)
{
var
emptySession
=
createSession
(
''
)
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
)
{
function
createSession
(
content
)
{
editor
.
session
.
removeMarker
(
markerId
)
var
s
=
new
ace
.
EditSession
(
content
,
'ace/mode/javascript'
)
}
s
.
setUndoManager
(
new
ace
.
UndoManager
())
s
.
setTabSize
(
4
)
this
.
newFile
=
function
()
{
s
.
setUseSoftTabs
(
true
)
var
untitledCount
=
''
return
s
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
)
])
}
}
this
.
resetSession
=
function
()
{
function
switchSession
(
path
)
{
editor
.
setSession
(
sessions
[
this
.
getCacheFile
()])
currentSession
=
path
editor
.
setSession
(
sessions
[
currentSession
])
editor
.
setReadOnly
(
readOnlySessions
[
currentSession
])
editor
.
focus
()
editor
.
focus
()
}
}
this
.
removeSession
=
function
(
fileKey
)
{
this
.
open
=
function
(
path
,
content
)
{
delete
sessions
[
fileKey
]
if
(
!
sessions
[
path
])
{
var
session
=
createSession
(
content
)
sessions
[
path
]
=
session
readOnlySessions
[
path
]
=
false
}
switchSession
(
path
)
}
}
this
.
renameSession
=
function
(
oldFileKey
,
newFileKey
)
{
this
.
openReadOnly
=
function
(
path
,
content
)
{
if
(
oldFileKey
!==
newFileKey
)
{
if
(
!
sessions
[
path
])
{
sessions
[
newFileKey
]
=
sessions
[
oldFileKey
]
var
session
=
createSession
(
content
)
this
.
removeSession
(
oldFileKey
)
sessions
[
path
]
=
session
readOnlySessions
[
path
]
=
true
}
}
switchSession
(
path
)
}
}
this
.
hasFile
=
function
(
name
)
{
this
.
get
=
function
(
path
)
{
return
this
.
getFiles
().
indexOf
(
name
)
!==
-
1
if
(
currentSession
===
path
)
{
return
editor
.
getValue
()
}
}
this
.
getFile
=
function
(
name
)
{
return
storage
.
get
(
name
)
}
}
function
getFiles
()
{
this
.
current
=
function
(
path
)
{
var
files
=
[]
if
(
editor
.
getSession
()
===
emptySession
)
{
storage
.
keys
().
forEach
(
function
(
f
)
{
return
// 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
currentSession
return
files
}
}
this
.
getFiles
=
getFiles
this
.
packageFiles
=
function
()
{
this
.
discard
=
function
(
path
)
{
var
files
=
{}
if
(
currentSession
!==
path
)
{
var
filesArr
=
this
.
getFiles
()
delete
sessions
[
path
]
for
(
var
f
in
filesArr
)
{
files
[
filesArr
[
f
]]
=
{
content
:
storage
.
get
(
filesArr
[
f
])
}
}
}
return
files
}
}
this
.
resize
=
function
()
{
this
.
resize
=
function
()
{
...
@@ -133,8 +84,13 @@ function Editor (doNotLoadStorage, storage) {
...
@@ -133,8 +84,13 @@ function Editor (doNotLoadStorage, storage) {
}
}
}
}
this
.
getValue
=
function
()
{
this
.
addMarker
=
function
(
lineColumnPos
,
cssClass
)
{
return
editor
.
getValue
()
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
()
{
this
.
clearAnnotations
=
function
()
{
...
@@ -156,15 +112,6 @@ function Editor (doNotLoadStorage, storage) {
...
@@ -156,15 +112,6 @@ function Editor (doNotLoadStorage, storage) {
editor
.
gotoLine
(
line
+
1
,
col
-
1
,
true
)
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
// Do setup on initialisation here
editor
.
on
(
'changeSession'
,
function
()
{
editor
.
on
(
'changeSession'
,
function
()
{
event
.
trigger
(
'sessionSwitched'
,
[])
event
.
trigger
(
'sessionSwitched'
,
[])
...
@@ -178,24 +125,6 @@ function Editor (doNotLoadStorage, storage) {
...
@@ -178,24 +125,6 @@ function Editor (doNotLoadStorage, storage) {
editor
.
commands
.
bindKeys
({
'ctrl-t'
:
null
})
editor
.
commands
.
bindKeys
({
'ctrl-t'
:
null
})
editor
.
commands
.
bindKeys
({
'ctrl-f'
:
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
)
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