Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
frama-c
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pub
frama-c
Commits
e9b5fcfd
Commit
e9b5fcfd
authored
4 years ago
by
Loïc Correnson
Browse files
Options
Downloads
Patches
Plain Diff
[ivette] refactor AST toolbar
parent
5333aa72
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ivette/src/renderer/ASTview.tsx
+36
-54
36 additions, 54 deletions
ivette/src/renderer/ASTview.tsx
with
36 additions
and
54 deletions
ivette/src/renderer/ASTview.tsx
+
36
−
54
View file @
e9b5fcfd
...
@@ -7,17 +7,23 @@ import * as Server from 'frama-c/server';
...
@@ -7,17 +7,23 @@ import * as Server from 'frama-c/server';
import
*
as
States
from
'
frama-c/states
'
;
import
*
as
States
from
'
frama-c/states
'
;
import
*
as
Dome
from
'
dome
'
;
import
*
as
Dome
from
'
dome
'
;
import
{
Vfill
}
from
'
dome/layout/boxes
'
;
import
{
RichTextBuffer
}
from
'
dome/text/buffers
'
;
import
{
RichTextBuffer
}
from
'
dome/text/buffers
'
;
import
{
Text
}
from
'
dome/text/editors
'
;
import
{
Text
}
from
'
dome/text/editors
'
;
import
{
Select
,
Switch
,
IconButton
}
from
'
dome/controls/buttons
'
;
import
{
Select
,
IconButton
}
from
'
dome/controls/buttons
'
;
import
*
as
Toolbars
from
'
dome/frame/toolbars
'
;
import
{
Space
}
from
'
dome/frame/toolbars
'
;
import
{
Component
,
TitleBar
}
from
'
frama-c/LabViews
'
;
import
{
Component
,
TitleBar
}
from
'
frama-c/LabViews
'
;
import
'
codemirror/mode/clike/clike
'
;
import
'
codemirror/mode/clike/clike
'
;
import
'
codemirror/theme/ambiance.css
'
;
import
'
codemirror/theme/ambiance.css
'
;
import
'
codemirror/theme/solarized.css
'
;
import
'
codemirror/theme/solarized.css
'
;
const
THEMES
=
[
{
id
:
"
default
"
,
label
:
"
Default
"
},
{
id
:
"
ambiance
"
,
label
:
"
Ambiance
"
},
{
id
:
"
solarized light
"
,
label
:
"
Solarized Light
"
},
{
id
:
"
solarized dark
"
,
label
:
"
Solarized Dark
"
}
];
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
// --- Rich Text Printer
// --- Rich Text Printer
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
...
@@ -63,21 +69,18 @@ async function loadAST(buffer: any, theFunction?: string, theMarker?: string) {
...
@@ -63,21 +69,18 @@ async function loadAST(buffer: any, theFunction?: string, theMarker?: string) {
// --- AST Printer
// --- AST Printer
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
function
useGlobal
(
param
:
string
,
dft
:
any
)
{
return
Dome
.
useGlobalSetting
(
`ASTview.
${
param
}
`
,
dft
);
}
const
ASTview
=
()
=>
{
const
ASTview
=
()
=>
{
// Hooks
// Hooks
const
buffer
=
React
.
useMemo
(()
=>
new
RichTextBuffer
(),
[]);
const
buffer
=
React
.
useMemo
(()
=>
new
RichTextBuffer
(),
[]);
const
printed
=
React
.
useRef
();
const
printed
=
React
.
useRef
();
const
[
select
,
setSelect
]
=
States
.
useSelection
();
const
[
select
,
setSelect
]
=
States
.
useSelection
();
const
[
theme
,
setTheme
]
=
Dome
.
useGlobalSetting
(
'
AST.theme
'
,
'
default
'
);
const
[
fontSize
,
setFontSize
]
=
Dome
.
useGlobalSetting
(
'
AST.fontSize
'
,
12
);
const
[
lineWrapping
,
setLineWrapping
]
=
Dome
.
useSwitch
(
'
ASTview.lineWrapping
'
,
false
);
const
theFunction
=
select
&&
select
.
function
;
const
theFunction
=
select
&&
select
.
function
;
const
theMarker
=
select
&&
select
.
marker
;
const
theMarker
=
select
&&
select
.
marker
;
const
[
theme
,
setTheme
]
=
useGlobal
(
'
theme
'
,
'
default
'
);
const
[
lineWrapping
,
setLineWrapping
]
=
useGlobal
(
'
lineWrapping
'
,
false
);
const
[
fontSize
,
setFontSize
]
=
useGlobal
(
'
fontSize
'
,
12
);
// Hook: async loading
// Hook: async loading
React
.
useEffect
(()
=>
{
React
.
useEffect
(()
=>
{
...
@@ -93,56 +96,35 @@ const ASTview = () => {
...
@@ -93,56 +96,35 @@ const ASTview = () => {
},
[
buffer
,
theMarker
]);
},
[
buffer
,
theMarker
]);
// Callbacks
// Callbacks
const
zoomIn
=
()
=>
setFontSize
(
fontSize
+
2
);
const
zoomOut
=
()
=>
setFontSize
(
fontSize
-
2
);
const
onSelection
=
(
marker
:
any
)
=>
setSelect
({
marker
});
const
onSelection
=
(
marker
:
any
)
=>
setSelect
({
marker
});
const
titlebar
=
(
// Theme Popup
<
TitleBar
>
<
Select
const
checkTheme
=
(
th
:
{
id
:
string
})
=>
({
checked
:
th
.
id
===
theme
,
...
th
});
value
=
{
theme
}
const
selectTheme
=
(
id
?:
string
)
=>
id
&&
setTheme
(
id
);
onChange
=
{
(
name
:
string
)
=>
setTheme
(
name
)
}
const
themePopup
=
()
=>
Dome
.
popupMenu
(
THEMES
.
map
(
checkTheme
),
selectTheme
);
>
<
option
value
=
"default"
label
=
"Default"
/>
<
option
value
=
"ambiance"
label
=
"Ambiance"
/>
<
option
value
=
"solarized light"
label
=
"Solarized light"
/>
<
option
value
=
"solarized dark"
label
=
"Solarized dark"
/>
</
Select
>
<
Toolbars
.
Space
/>
<
IconButton
icon
=
"MINUS"
title
=
"Decrease the font size"
onClick
=
{
()
=>
setFontSize
(
fontSize
-
2
)
}
/>
<
IconButton
icon
=
"PLUS"
title
=
"increase the font size"
onClick
=
{
()
=>
setFontSize
(
fontSize
+
2
)
}
/>
<
Toolbars
.
Space
/>
<
Switch
label
=
"Line wrapping"
title
=
"Change line wrapping mode"
value
=
{
lineWrapping
}
onChange
=
{
()
=>
setLineWrapping
(
!
lineWrapping
)
}
/>
<
Toolbars
.
Space
/>
</
TitleBar
>
);
// Component
// Component
return
(
return
(
<>
<>
{
titlebar
}
<
TitleBar
>
<
Vfill
style
=
{
{
fontSize
}
}
>
<
IconButton
icon
=
"ZOOM.OUT"
onClick
=
{
zoomOut
}
/>
<
Text
<
IconButton
icon
=
"ZOOM.IN"
onClick
=
{
zoomIn
}
/>
buffer
=
{
buffer
}
<
IconButton
icon
=
"CODE"
onClick
=
{
themePopup
}
/>
mode
=
"text/x-csrc"
<
IconButton
icon
=
"WRAPTEXT"
selected
=
{
lineWrapping
}
onClick
=
{
setLineWrapping
}
/>
theme
=
{
theme
}
</
TitleBar
>
lineWrapping
=
{
lineWrapping
}
<
Text
selection
=
{
theMarker
}
buffer
=
{
buffer
}
onSelection
=
{
onSelection
}
mode
=
"text/x-csrc"
readOnly
theme
=
{
theme
}
/>
fontSize
=
{
fontSize
}
</
Vfill
>
lineWrapping
=
{
lineWrapping
}
selection
=
{
theMarker
}
onSelection
=
{
onSelection
}
readOnly
/>
</>
</>
);
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment