mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Fix search for pinned notebooks (#12719)
* fix search for pinned notebooks * fix filtering when verifying that a search folder is not a subdirectory from the current folder queries path * Show book node on pinned notebooks search results * fix parent node on pinned notebooks search results * fix search for pinned notebook and modify how pinned notebooks are stored in workspace * update format of pinned notebooks for users that used the september release version * removed unused functions * Address PR comments * fix parent node for legacy version of jupyter books * remove cast from book path
This commit is contained in:
@@ -6,7 +6,7 @@ import * as path from 'path';
|
||||
import * as vscode from 'vscode';
|
||||
import * as constants from './../common/constants';
|
||||
import { BookTreeItem } from './bookTreeItem';
|
||||
import { getPinnedNotebooks } from '../common/utils';
|
||||
import { getPinnedNotebooks, setPinnedBookPathsInConfig, IBookNotebook } from '../common/utils';
|
||||
|
||||
export interface IBookPinManager {
|
||||
pinNotebook(notebook: BookTreeItem): boolean;
|
||||
@@ -33,7 +33,7 @@ export class BookPinManager implements IBookPinManager {
|
||||
}
|
||||
|
||||
isNotebookPinned(notebookPath: string): boolean {
|
||||
if (getPinnedNotebooks().findIndex(x => x === notebookPath) > -1) {
|
||||
if (getPinnedNotebooks().findIndex(x => x.notebookPath === notebookPath) > -1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -47,41 +47,23 @@ export class BookPinManager implements IBookPinManager {
|
||||
return this.updatePinnedBooks(notebook, PinBookOperation.Unpin);
|
||||
}
|
||||
|
||||
getPinnedBookPathsInConfig(): string[] {
|
||||
let config: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration(constants.notebookConfigKey);
|
||||
let pinnedBookDirectories: string[] = config.get(constants.pinnedBooksConfigKey);
|
||||
|
||||
return pinnedBookDirectories;
|
||||
}
|
||||
|
||||
setPinnedBookPathsInConfig(bookPaths: string[]) {
|
||||
let config: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration(constants.notebookConfigKey);
|
||||
let storeInWorspace: boolean = this.hasWorkspaceFolders();
|
||||
|
||||
config.update(constants.pinnedBooksConfigKey, bookPaths, storeInWorspace ? false : vscode.ConfigurationTarget.Global);
|
||||
}
|
||||
|
||||
hasWorkspaceFolders(): boolean {
|
||||
let workspaceFolders = vscode.workspace.workspaceFolders;
|
||||
return workspaceFolders && workspaceFolders.length > 0;
|
||||
}
|
||||
|
||||
updatePinnedBooks(notebook: BookTreeItem, operation: PinBookOperation) {
|
||||
let modifiedPinnedBooks = false;
|
||||
let bookPathToChange: string = notebook.book.contentPath;
|
||||
|
||||
let pinnedBooks: string[] = this.getPinnedBookPathsInConfig();
|
||||
let existingBookIndex = pinnedBooks.map(pinnedBookPath => path.normalize(pinnedBookPath)).indexOf(bookPathToChange);
|
||||
let pinnedBooks: IBookNotebook[] = getPinnedNotebooks();
|
||||
let existingBookIndex = pinnedBooks.map(pinnedBookPath => path.normalize(pinnedBookPath?.notebookPath)).indexOf(bookPathToChange);
|
||||
|
||||
if (existingBookIndex !== -1 && operation === PinBookOperation.Unpin) {
|
||||
pinnedBooks.splice(existingBookIndex, 1);
|
||||
modifiedPinnedBooks = true;
|
||||
} else if (existingBookIndex === -1 && operation === PinBookOperation.Pin) {
|
||||
pinnedBooks.push(bookPathToChange);
|
||||
let addNotebook: IBookNotebook = { notebookPath: bookPathToChange, bookPath: notebook.book.root };
|
||||
pinnedBooks.push(addNotebook);
|
||||
modifiedPinnedBooks = true;
|
||||
}
|
||||
|
||||
this.setPinnedBookPathsInConfig(pinnedBooks);
|
||||
setPinnedBookPathsInConfig(pinnedBooks);
|
||||
this.setPinnedSectionContext();
|
||||
|
||||
return modifiedPinnedBooks;
|
||||
|
||||
Reference in New Issue
Block a user