Skip to content

Commit

Permalink
fix: show/hide open link button based on the settings
Browse files Browse the repository at this point in the history
  • Loading branch information
oae committed Mar 7, 2023
1 parent b8b2836 commit d62ab51
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
- `ctrl` `s` key will favorite/unfavorite the item
- `alt` key will switch between favorites/all items
- `ctrl` `1`..`9` keys will copy the item with the corresponding index
- `ctrl` `click` or `ctrl` `enter` shortcuts will copy the links and open them in default browser if `Open Links in Browser` option enabled

## Cli

Expand Down
47 changes: 30 additions & 17 deletions src/components/linkPanoItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,36 @@ export class LinkPanoItem extends PanoItem {
this.connect('activated', this.setClipboardContent.bind(this));
this.setStyle();
this.linkItemSettings.connect('changed', this.setStyle.bind(this));

const openLinkIcon = new Icon({
icon_name: 'web-browser-symbolic',
style_class: 'pano-item-action-button-icon',
});

const openLinkButton = new Button({
style_class: 'pano-item-action-button pano-item-open-link-button',
child: openLinkIcon,
});

openLinkButton.connect('clicked', () => {
this.emit('activated');
openLinkInBrowser(this.dbItem.content);
return EVENT_PROPAGATE;
});

if (this.settings.get_boolean('open-links-in-browser')) {
this.header.actionContainer.insert_child_at_index(openLinkButton, 0);
}

this.settings.connect('changed::open-links-in-browser', () => {
if (this.header.actionContainer.get_child_at_index(0) === openLinkButton) {
this.header.actionContainer.remove_child(openLinkButton);
}

if (this.settings.get_boolean('open-links-in-browser')) {
this.header.actionContainer.insert_child_at_index(openLinkButton, 0);
}
});
}

private setStyle() {
Expand Down Expand Up @@ -129,23 +159,6 @@ export class LinkPanoItem extends PanoItem {
this.linkLabel.set_style(
`color: ${metadataLinkColor}; font-family: ${metadataLinkFontFamily}; font-size: ${metadataLinkFontSize}px;`,
);

const openLinkIcon = new Icon({
icon_name: 'web-browser-symbolic',
style_class: 'pano-item-action-button-icon',
});

const openLinkButton = new Button({
style_class: 'pano-item-action-button pano-item-open-link-button',
child: openLinkIcon,
});

openLinkButton.connect('clicked', () => {
openLinkInBrowser(this.dbItem.content);
return EVENT_PROPAGATE;
});

this.header.actionContainer.insert_child_at_index(openLinkButton, 0);
}

private setClipboardContent(): void {
Expand Down

0 comments on commit d62ab51

Please sign in to comment.