Skip to content
Prev Previous commit
Next Next commit
Edit button added, LOC removed.
  • Loading branch information
kpinnipa committed Jul 31, 2020
commit c427d6f836717806e517cdf71882759c3d9d229f
28 changes: 12 additions & 16 deletions src/CodeSnippetDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,18 @@ export class CodeSnippetDisplay extends React.Component<
};

// Pick color for side of snippet box based on number of code lines
private codeLines = (codeSnippet: ICodeSnippet): string => {
let i;
let counter = 0;
for (i = 0; i < codeSnippet.code[0].length; i++) {
if (codeSnippet.code[0][i] === '\n') {
counter++;
}
}
counter += 1;
console.log(counter);
return 'LOC\t\t' + counter;
};
// private codeLines = (codeSnippet: ICodeSnippet): string => {
// let i;
// let counter = 0;
// for (i = 0; i < codeSnippet.code[0].length; i++) {
// if (codeSnippet.code[0][i] === '\n') {
// counter++;
// }
// }
// counter += 1;
// console.log(counter);
// return 'LOC\t\t' + counter;
// };

//Change bookmark field and color onclick
private bookmarkSnippetClick = (
Expand Down Expand Up @@ -380,10 +380,6 @@ export class CodeSnippetDisplay extends React.Component<
}}
>
{this.boldNameOnSearch(this.state.filterValue, displayName)}
<br />
<div className="lines-of-code" id={id}>
{this.codeLines(codeSnippet)}
</div>
</span>
<div className={ACTION_BUTTONS_WRAPPER_CLASS}>
{actionButtons.map((btn: IExpandableActionButton) => {
Expand Down
39 changes: 39 additions & 0 deletions src/PreviewSnippet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ export class Preview<T> extends Widget {
content.addWidget(header);
const body = renderer.createBody(options.body || '');
content.addWidget(body);
const editButton = renderer.createEditButton(this);
content.addWidget(editButton);

if (Preview.tracker.size > 0) {
const previous = Preview.tracker.currentWidget;
Expand Down Expand Up @@ -330,11 +332,16 @@ export namespace Preview {
* @returns A widget for the body.
*/
createBody(body: Body<any>): Widget;
createEditButton(): Widget;
}

export class Renderer {
/**
* Create the header of the dialog.
*
* @param title - The title of the snippet.
*
* @returns A widget for the header of the preview.
*/
createHeader(title: string): Widget {
const header = ReactWidget.create(<>{title}</>);
Expand All @@ -343,6 +350,7 @@ export namespace Preview {
// Styling.styleNode(header.node);
return header;
}

/**
* Create the body of the dialog.
*
Expand All @@ -363,6 +371,7 @@ export namespace Preview {
// order to trigger a render of the DOM nodes from the React element.
MessageLoop.sendMessage(body, Widget.Msg.UpdateRequest);
}

// const iconNode = new Widget({ node: document.createElement('div') });
// iconNode.title.icon = checkIcon;
// body.
Expand All @@ -384,6 +393,36 @@ export namespace Preview {
// iconWidget.addClass('jp-confirm-icon');
// return iconWidget
// }

/**
* Create the edit button in the dialog.
*
* @returns A widget for the edit button.
*/
createEditButton(prev: any): Widget {
const editButton: Widget = new Widget({
node: document.createElement('span')
});
editButton.addClass('jp-Preview-button');
editButton.node.onmouseover = (): void => {
editButton.addClass('jp-Preview-button-hover');
};
editButton.node.onmouseout = (): void => {
editButton.removeClass('jp-Preview-button-hover');
};
editButton.node.onclick = (): void => {
document
.getElementsByClassName('drag-hover')
[prev._id].classList.remove('drag-hover-clicked');
document
.getElementsByClassName('elyra-codeSnippet-item')
[prev._id].classList.remove('elyra-codeSnippet-item-clicked');
event.stopPropagation();
event.preventDefault();
prev.reject();
};
return editButton;
}
}
/**
* The default renderer instance.
Expand Down
27 changes: 27 additions & 0 deletions style/icon/Jupyter_pencileditbutton_inactive.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions style/icon/jupyter_pencileditbutton_hover.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 16 additions & 1 deletion style/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
top: 31px;
left: 5px;
width: 100%;
height: 710px;
height: 100%;
display: flex;
justify-content: center;
flex-direction: column;
Expand Down Expand Up @@ -267,6 +267,21 @@
display: block;
}

.jp-Preview-button {
width: 51px;
height: 51px;
background-image: url(./icon/Jupyter_pencileditbutton_inactive.svg);
float: right;
margin-top: -80px;
margin-right: 9px;
cursor: pointer;
}

.jp-Preview-button-hover {
background-image: url(./icon/jupyter_pencileditbutton_hover.svg);
cursor: pointer;
}

.triangle {
width: 0;
height: 0;
Expand Down