Skip to content

Commit 207dc34

Browse files
authored
Merge pull request #78 from geriyoco/main
🔖 Publish v0.2.7
2 parents a0d806f + a5e0749 commit 207dc34

File tree

10 files changed

+59
-76
lines changed

10 files changed

+59
-76
lines changed

.github/workflows/vsce_publish.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ on:
44
push:
55
branches:
66
- production
7-
release:
8-
types:
9-
- created
107

118
jobs:
129
build:

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Change Log
22

3+
## [0.2.7] - 2022-06-26
4+
### Changed
5+
- Single clicking an image in Gallery view opens up the image in Preview Mode
6+
- Double clicking an image in Gallery view opens up the image (not in Preview Mode)
7+
### Fixed
8+
- Files within subfolders were not being sorted correctly
9+
310
## [0.2.6] - 2022-06-23
411
### Added
512
- Gallery supports collapsible subfolders

LICENSE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
MIT License
22

3-
Copyright (c) 2022 TEH, Chi-En
3+
Copyright (c) 2022 GeriYoco owners, including Alex CHANDRA (alex2chan) and TEH
4+
Chi-En (fanurs).
45

56
Permission is hereby granted, free of charge, to any person obtaining a copy
67
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Image Gallery
2-
[![.github/workflows/vsce_publish.yml](https://github.com/geriyoco/vscode-image-gallery/actions/workflows/vsce_publish.yml/badge.svg?branch=production&event=release)](https://github.com/geriyoco/vscode-image-gallery/actions/workflows/vsce_publish.yml)
2+
[![.github/workflows/vsce_publish.yml](https://github.com/geriyoco/vscode-image-gallery/actions/workflows/vsce_publish.yml/badge.svg?branch=production)](https://github.com/geriyoco/vscode-image-gallery/actions/workflows/vsce_publish.yml)
33

44
A light-weighted extension that brings you the best image browsing experience in VS Code.
55

@@ -21,6 +21,6 @@ A light-weighted extension that brings you the best image browsing experience in
2121
See [here](docs/photo_credits.md) for the photo credits.
2222

2323
## Like this work?
24-
- :star: Star this project on [GitHub](https://github.com/geriyoco/vscode-image-gallery) and [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=GeriYoco.vscode-image-gallery)
25-
- :arrow_right_hook: Share with your friends: [Twitter](https://www.twitter.com/home?status=Just%20discovered%20this%20on%20the%20%23VSMarketplace%3A%20https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3DGeriYoco.vscode-image-gallery), [Facebook](https://www.facebook.com/sharer/sharer.php?u=https://marketplace.visualstudio.com/items?itemName=GeriYoco.vscode-image-gallery)
26-
- :computer: Contribute to the project
24+
- Star this project on [GitHub](https://github.com/geriyoco/vscode-image-gallery) and [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=GeriYoco.vscode-image-gallery)
25+
- ↪️ Share with your friends: [Twitter](https://twitter.com/intent/tweet?text=Just%20discovered%20this%20on%20the%20%23VSMarketplace%3A%20https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3DGeriYoco.vscode-image-gallery), [Facebook](https://www.facebook.com/sharer/sharer.php?u=https://marketplace.visualstudio.com/items?itemName=GeriYoco.vscode-image-gallery)
26+
- 🖥️ Contribute to the project

media/gallery.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
lazyloadImages.forEach((image) => {
2121
imageObserver.observe(image);
2222
});
23-
24-
document.addEventListener('click', event => {
23+
24+
const clickHandler = (event, preview) => {
2525
let node = event && event.target;
2626
const folderHeader = ['folder','folder-title','folder-arrow'];
2727
if (folderHeader.some(el => node.classList.contains(el))) {
@@ -46,10 +46,11 @@
4646
vscode.postMessage({
4747
command: 'vscodeImageGallery.openViewer',
4848
src: node.src,
49+
preview: preview,
4950
});
50-
51-
}, true);
52-
51+
};
52+
document.addEventListener('click', event => clickHandler(event, preview=true), true);
53+
document.addEventListener('dblclick', event => clickHandler(event, preview=false), true);
5354

5455
window.addEventListener('message', event => {
5556
const message = event.data;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-image-gallery",
33
"displayName": "Image Gallery",
44
"description": "An extension that enhances image browsing experience.",
5-
"version": "0.2.6",
5+
"version": "0.2.7",
66
"publisher": "GeriYoco",
77
"repository": {
88
"type": "git",

src/extension.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import * as vscode from 'vscode';
2-
import * as main_panel from './main_panel';
3-
import * as viewer_panel from './viewer_panel';
4-
import * as viewer_editor from './viewer_editor';
2+
import * as gallery from './gallery';
3+
import * as viewer from './viewer';
54
import * as file_watcher from './file_watcher';
65

76

87
export function activate(context: vscode.ExtensionContext) {
98
console.log('Welcome! VS Code extension "GeriYoco: Image Gallery" is now active.');
109

11-
const viewerEditor = new viewer_editor.ViewerCustomEditor(context);
10+
const viewerEditor = new viewer.ViewerCustomEditor(context);
1211
context.subscriptions.push(
1312
vscode.window.registerCustomEditorProvider(
14-
viewer_editor.ViewerCustomEditor.viewType,
13+
viewer.ViewerCustomEditor.viewType,
1514
viewerEditor,
1615
{
1716
supportsMultipleEditorsPerDocument: true,
@@ -25,23 +24,23 @@ export function activate(context: vscode.ExtensionContext) {
2524
let dispGallery = vscode.commands.registerCommand(
2625
'vscodeImageGallery.openGallery',
2726
async (galleryFolder?: vscode.Uri) => {
28-
const mainPanel = await main_panel.createPanel(context, galleryFolder);
27+
const mainPanel = await gallery.createPanel(context, galleryFolder);
2928
const galleryFileWatcher = file_watcher.galleryFileWatcher(mainPanel, galleryFolder);
3029
context.subscriptions.push(galleryFileWatcher);
3130

3231
mainPanel.webview.onDidReceiveMessage(
33-
message => {
32+
async message => {
3433
switch (message.command) {
3534
case 'vscodeImageGallery.openViewer':
36-
const viewerPanel = viewer_panel.createPanel(context, message.src);
37-
const viewerFileWatcher = file_watcher.viewerFileWatcher(viewerPanel);
38-
39-
viewerPanel.onDidDispose(
40-
() => {
41-
viewerFileWatcher.dispose();
35+
const resource = vscode.Uri.file(vscode.Uri.parse(message.src).path);
36+
await vscode.commands.executeCommand(
37+
'vscode.open',
38+
resource,
39+
{
40+
preserveFocus: true,
41+
preview: message.preview,
42+
viewColumn: vscode.ViewColumn.Two,
4243
},
43-
undefined,
44-
context.subscriptions
4544
);
4645
return;
4746
}

src/main_panel.ts renamed to src/gallery.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export function sortPathsBySubFolders(pathsBySubFolders: { [key: string]: Array<
5151
Object.keys(pathsBySubFolders).sort(comparator).forEach(
5252
subfolder => {
5353
sortedResult[subfolder] = pathsBySubFolders[subfolder].sort(
54-
(path1: vscode.Uri, path2: vscode.Uri) => path1.path.localeCompare(path2.path)
54+
(path1: vscode.Uri, path2: vscode.Uri) => comparator(path1.path, path2.path)
5555
);
5656
}
5757
);

src/viewer_panel.ts renamed to src/viewer.ts

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
11
import * as vscode from 'vscode';
22
import * as utils from './utils';
33

4-
export function createPanel(
5-
context: vscode.ExtensionContext,
6-
imgSrc: string,
7-
) {
8-
const panel = vscode.window.createWebviewPanel(
9-
'gryc.viewer',
10-
`${utils.getFilename(imgSrc)}`,
11-
vscode.ViewColumn.Two,
12-
{
13-
enableScripts: true,
14-
retainContextWhenHidden: true,
15-
}
16-
);
4+
export class ViewerCustomEditor implements vscode.CustomReadonlyEditorProvider {
5+
public static readonly viewType = 'gryc.editor';
6+
7+
constructor(private readonly context: vscode.ExtensionContext) { }
178

18-
panel.webview.html = getWebviewContent(context, panel.webview, imgSrc);
9+
public async openCustomDocument(uri: vscode.Uri) {
10+
return { uri, dispose: () => { } };
11+
}
1912

20-
return panel;
13+
public async resolveCustomEditor(
14+
document: vscode.CustomDocument,
15+
webviewPanel: vscode.WebviewPanel,
16+
): Promise<void> {
17+
let documentPath = webviewPanel.webview.asWebviewUri(document.uri).toString();
18+
let documentDir = document.uri.path.split('/').slice(0, -1).join('/');
19+
webviewPanel.webview.options = {
20+
localResourceRoots: [
21+
vscode.Uri.joinPath(this.context.extensionUri, 'media'),
22+
vscode.Uri.file(utils.getCwd()),
23+
vscode.Uri.file(documentDir),
24+
],
25+
enableScripts: true,
26+
enableForms: false
27+
};
28+
webviewPanel.webview.html = getWebviewContent(this.context, webviewPanel.webview, documentPath);
29+
}
2130
}
2231

2332
export function getWebviewContent(

src/viewer_editor.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)