This commit is contained in:
Devon22 2025-03-20 23:25:59 +08:00
parent 68db67dac3
commit 49ccecdcc6
7 changed files with 51 additions and 23 deletions

29
main.ts
View file

@ -91,18 +91,23 @@ export default class GridExplorerPlugin extends Plugin {
let leaf = null;
const leaves = workspace.getLeavesOfType('grid-view');
// 根據設定選擇開啟位置
switch (this.settings.defaultOpenLocation) {
case 'left':
leaf = workspace.getLeftLeaf(false);
break;
case 'right':
leaf = workspace.getRightLeaf(false);
break;
case 'tab':
default:
leaf = workspace.getLeaf('tab');
break;
// 如果設定為重用現有的leaf且存在已開啟的 grid-view則使用第一個
if (this.settings.reuseExistingLeaf && leaves.length > 0) {
leaf = leaves[0];
} else {
// 根據設定選擇開啟位置
switch (this.settings.defaultOpenLocation) {
case 'left':
leaf = workspace.getLeftLeaf(false);
break;
case 'right':
leaf = workspace.getRightLeaf(false);
break;
case 'tab':
default:
leaf = workspace.getLeaf('tab');
break;
}
}
// 確保 leaf 不為 null

View file

@ -1,7 +1,7 @@
{
"id": "gridexplorer",
"name": "GridExplorer",
"version": "1.8.8",
"version": "1.8.9",
"minAppVersion": "1.1.0",
"description": "Browse note files in a grid view.",
"author": "Devon22",

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "gridexplorer",
"version": "1.8.8",
"version": "1.8.9",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "gridexplorer",
"version": "1.8.8",
"version": "1.8.9",
"license": "MIT",
"devDependencies": {
"@types/node": "^16.11.6",

View file

@ -1,6 +1,6 @@
{
"name": "gridexplorer",
"version": "1.8.8",
"version": "1.8.9",
"description": "Browse note files in a grid view.",
"main": "main.js",
"scripts": {

View file

@ -18,6 +18,7 @@ export interface GallerySettings {
showVideoThumbnails: boolean;
defaultOpenLocation: string; // 預設開啟位置
showParentFolderItem: boolean; // 是否显示"返回上级文件夹"选项
reuseExistingLeaf: boolean; // 是否重用現有的網格視圖
}
// 預設設定
@ -37,6 +38,7 @@ export const DEFAULT_SETTINGS: GallerySettings = {
showVideoThumbnails: false, // 預設不顯示影片縮圖
defaultOpenLocation: 'tab', // 預設開啟位置:新分頁
showParentFolderItem: false, // 預設顯示"返回上级文件夹"選項
reuseExistingLeaf: false, // 是否重用現有的網格視圖
};
// 設定頁面類別
@ -117,6 +119,19 @@ export class GridExplorerSettingTab extends PluginSettingTab {
containerEl.createEl('h3', { text: t('grid_view_settings') });
// 重用現有的網格視圖
new Setting(containerEl)
.setName(t('reuse_existing_leaf'))
.setDesc(t('reuse_existing_leaf_desc'))
.addToggle(toggle => {
toggle
.setValue(this.plugin.settings.reuseExistingLeaf)
.onChange(async (value) => {
this.plugin.settings.reuseExistingLeaf = value;
await this.plugin.saveSettings();
});
});
// 預設開啟位置設定
new Setting(containerEl)
.setName(t('default_open_location'))

View file

@ -104,6 +104,9 @@ export const TRANSLATIONS: Translations = {
'default_open_location_desc': '設定網格視圖預設開啟的位置',
'open_in_left_sidebar': '開在左側邊欄',
'open_in_right_sidebar': '開在右側邊欄',
'open_in_new_tab': '在新分頁開啟',
'reuse_existing_leaf': '重複使用已開啟的視圖',
'reuse_existing_leaf_desc': '開啟網格視圖時,優先使用已開啟的視圖而非建立新視圖',
// 選擇資料夾對話框
'select_folders': '選擇資料夾',
@ -112,7 +115,6 @@ export const TRANSLATIONS: Translations = {
'view_current_note_in_grid_view': '在網格視圖中查看當前筆記',
'open_settings': '開啟設定',
'delete_note': '刪除檔案',
'open_in_new_tab': '在新分頁開啟',
'searching': '搜尋中...',
'no_files': '沒有找到任何檔案',
'filter_folders': '篩選資料夾...',
@ -202,6 +204,9 @@ export const TRANSLATIONS: Translations = {
'default_open_location_desc': 'Set the default location to open the grid view',
'open_in_left_sidebar': 'Open in left sidebar',
'open_in_right_sidebar': 'Open in right sidebar',
'open_in_new_tab': 'Open in new tab',
'reuse_existing_leaf': 'Reuse existing view',
'reuse_existing_leaf_desc': 'When opening Grid View, prioritize using an existing view instead of creating a new one',
// Select Folder Dialog
'select_folders': 'Select folder',
@ -210,7 +215,6 @@ export const TRANSLATIONS: Translations = {
'view_current_note_in_grid_view': 'View current note in grid view',
'open_settings': 'Open settings',
'delete_note': 'Delete file',
'open_in_new_tab': 'Open in new tab',
'searching': 'Searching...',
'no_files': 'No files found',
'filter_folders': 'Filter folders...',
@ -298,8 +302,11 @@ export const TRANSLATIONS: Translations = {
// 默认打开位置设置
'default_open_location': '默认打开位置',
'default_open_location_desc': '设置网格视图默认打开的位置',
'open_in_left_sidebar': '打开在左侧边栏',
'open_in_right_sidebar': '打开在右侧边栏',
'open_in_left_sidebar': '在左侧边栏打开',
'open_in_right_sidebar': '在右侧边栏打开',
'open_in_new_tab': '在新标签页打开',
'reuse_existing_leaf': '重复使用已打开的视图',
'reuse_existing_leaf_desc': '打开网格视图时,优先使用已打开的视图而非创建新视图',
// 选择文件夹对话框
'select_folders': '选择文件夹',
@ -308,7 +315,6 @@ export const TRANSLATIONS: Translations = {
'view_current_note_in_grid_view': '在网格视图中查看当前笔记',
'open_settings': '打开设置',
'delete_note': '删除文件',
'open_in_new_tab': '在新标签页打开',
'searching': '搜索中...',
'no_files': '没有找到任何文件',
'filter_folders': '筛选文件夹...',
@ -398,6 +404,9 @@ export const TRANSLATIONS: Translations = {
'default_open_location_desc': 'グリッドビューを開くデフォルトの場所を設定',
'open_in_left_sidebar': '左サイドバーで開く',
'open_in_right_sidebar': '右サイドバーで開く',
'open_in_new_tab': '新しいタブで開く',
'reuse_existing_leaf': '既存のビューを再利用',
'reuse_existing_leaf_desc': 'グリッドビューを開くとき、新しいビューを作成せずに既存のビューを優先的に使用',
// フォルダ選択ダイアログ
'select_folders': 'フォルダを選択',
@ -406,7 +415,6 @@ export const TRANSLATIONS: Translations = {
'view_current_note_in_grid_view': '現在のノートをグリッドビューで表示',
'open_settings': '設定を開く',
'delete_note': 'ファイルを削除',
'open_in_new_tab': '新しいタブで開く',
'searching': '検索中...',
'no_files': 'ファイルが見つかりません',
'filter_folders': 'フォルダをフィルタリング...',

View file

@ -1,3 +1,3 @@
{
"1.8.8": "1.1.0"
"1.8.9": "1.1.0"
}