Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy code functionality added #128

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ const styles = theme => ({
button: {
margin: theme.spacing(1)
},
copybutton: {
height: "40px",
margin: theme.spacing(2)
},
exportButton: {
height: "40px",
margin: theme.spacing(2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ class BodyWidget extends React.Component<BodyWidgetProps, BodyWidgetState> {
// })
// });

}
//function to copy code
handlecopyCode=()=>{
const code=this.state.code;


}

handleGetCode = () => {
Expand Down Expand Up @@ -584,6 +590,10 @@ class BodyWidget extends React.Component<BodyWidgetProps, BodyWidgetState> {
</Grid>
<Grid container spacing={8}>
<Grid item xs>

<Paper square>
<SimpleTabs code={this.state.code} runtimeData = {this.state.runtime_data} className={classes.copybutton} divStyle={classes.divStyle} />
</Paper>
<Paper square>
<SimpleTabs code={this.state.code} runtimeData = {this.state.runtime_data} divStyle={classes.divStyle} exportStyle={classes.exportButton}/>
</Paper>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import React from "react";
import { useRef } from "react";
import PropTypes from "prop-types";
import AppBar from "@material-ui/core/AppBar";
import Tabs from "@material-ui/core/Tabs";
import Tab from "@material-ui/core/Tab";
import Typography from "@material-ui/core/Typography";
import Button from "@material-ui/core/Button";
import FileCopyIcon from "@material-ui/icons/FileCopy";
import { Button } from "@material-ui/core";
import Filesaver from "file-saver";
import GetAppIcon from "@material-ui/icons/GetApp";

interface TabContainerProps {
children?: React.ReactNode;
}

interface SimpleTabsProps {
divStyle?: string;
className?: string;
exportStyle?: string | undefined;
divStyle?: string | undefined;
code: string;
Expand Down Expand Up @@ -45,10 +51,24 @@ export default function SimpleTabs(props: SimpleTabsProps) {
Filesaver.saveAs(blob, "hello-world.py");
}

function copyCode() {
const node = document.createElement("textarea");
console.log("button clicked!");

node.innerText = props.code;
console.log(node.value);
document.body.appendChild(node);
node.select();
if (document.execCommand("copy")) {
window.alert("Code Copied");
}
document.body.removeChild(node);
}
return (
<div className="log_main">
<div>
<AppBar position="static" color="default">
<Tabs value={value} onChange={handleChange} variant="scrollable">
<Tabs value={value} onChange={handleChange}>
<Tab label="Logs" />
<Tab label="Code" />
Expand All @@ -60,6 +80,11 @@ export default function SimpleTabs(props: SimpleTabsProps) {
<TabContainer>{newText}</TabContainer>
<Button
variant="contained"
className={props.className}
onClick={copyCode}
>
<FileCopyIcon fontSize="small" />
Copy Code To Clipboard
className={props.exportStyle}
onClick={exportPython}
>
Expand Down