mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Update pin/unpin icon after pinning notebook (#20273)
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, setPinnedBookPathsInConfig, IPinnedNotebook } from '../common/utils';
|
||||
import { getPinnedNotebooks, setPinnedBookPathsInConfig, IPinnedNotebook, getNotebookType } from '../common/utils';
|
||||
|
||||
export interface IBookPinManager {
|
||||
pinNotebook(notebook: BookTreeItem): Promise<boolean>;
|
||||
@@ -58,7 +58,7 @@ export class BookPinManager implements IBookPinManager {
|
||||
pinnedBooks.splice(existingBookIndex, 1);
|
||||
modifiedPinnedBooks = true;
|
||||
} else if (existingBookIndex === -1 && operation === PinBookOperation.Pin) {
|
||||
let addNotebook: IPinnedNotebook = { notebookPath: bookPathToChange, bookPath: notebook.book.root, title: notebook.book.title };
|
||||
let addNotebook: IPinnedNotebook = { notebookPath: bookPathToChange, bookPath: getNotebookType(notebook.book) ? notebook.book.root : undefined, title: notebook.book.title };
|
||||
pinnedBooks.push(addNotebook);
|
||||
modifiedPinnedBooks = true;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ import { Deferred } from '../common/promise';
|
||||
import { IBookTrustManager, BookTrustManager } from './bookTrustManager';
|
||||
import * as loc from '../common/localizedConstants';
|
||||
import * as glob from 'fast-glob';
|
||||
import { getPinnedNotebooks, confirmMessageDialog, getNotebookType, FileExtension, IPinnedNotebook, BookTreeItemType } from '../common/utils';
|
||||
import { getPinnedNotebooks, getNotebookType, confirmMessageDialog, FileExtension, IPinnedNotebook, BookTreeItemType } from '../common/utils';
|
||||
import { IBookPinManager, BookPinManager } from './bookPinManager';
|
||||
import { BookTocManager, IBookTocManager, quickPickResults } from './bookTocManager';
|
||||
import { CreateBookDialog } from '../dialog/createBookDialog';
|
||||
@@ -138,7 +138,8 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
|
||||
let pinStatusChanged = await this.bookPinManager.pinNotebook(bookTreeItem);
|
||||
sendNotebookActionEvent(NbTelemetryView.Book, NbTelemetryAction.PinNotebook);
|
||||
if (pinStatusChanged) {
|
||||
bookTreeItem.contextValue = 'pinnedNotebook';
|
||||
bookTreeItem.contextValue = BookTreeItemType.pinnedNotebook;
|
||||
this._onDidChangeTreeData.fire(bookTreeItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -148,7 +149,14 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
|
||||
if (bookPathToUpdate) {
|
||||
let pinStatusChanged = await this.bookPinManager.unpinNotebook(bookTreeItem);
|
||||
if (pinStatusChanged) {
|
||||
bookTreeItem.contextValue = getNotebookType(bookTreeItem.book);
|
||||
// reset to original context value
|
||||
bookTreeItem.contextValue = bookTreeItem.book.type === BookTreeItemType.Markdown ? BookTreeItemType.Markdown : getNotebookType(bookTreeItem.book);
|
||||
// if notebook is not in current book then it is a standalone notebook
|
||||
let itemOpenedInBookTreeView = this.currentBook?.getNotebook(bookTreeItem.book.contentPath) ?? this.books.find(book => book.bookPath === bookTreeItem.book.contentPath)?.getNotebook(bookTreeItem.book.contentPath);
|
||||
if (itemOpenedInBookTreeView) {
|
||||
itemOpenedInBookTreeView.contextValue = bookTreeItem.contextValue;
|
||||
this._onDidChangeTreeData.fire(itemOpenedInBookTreeView.parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -264,7 +272,7 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
|
||||
async addNotebookToPinnedView(bookItem: BookTreeItem): Promise<void> {
|
||||
let notebookPath: string = bookItem.book.contentPath;
|
||||
if (notebookPath) {
|
||||
let notebookDetails: IPinnedNotebook = bookItem.book.root ? { bookPath: bookItem.book.root, notebookPath: notebookPath, title: bookItem.book.title } : { notebookPath: notebookPath };
|
||||
let notebookDetails: IPinnedNotebook = getNotebookType(bookItem.book) === BookTreeItemType.savedBookNotebook ? { bookPath: bookItem.book.root, notebookPath: notebookPath, title: bookItem.book.title } : { notebookPath: notebookPath };
|
||||
await this.createAndAddBookModel(notebookPath, true, notebookDetails);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user