@@ -2003,31 +2003,33 @@ define(function (require, exports, module) {
20032003 }
20042004
20052005 /**
2006- * we call this function when the user selects the 'Pin' option from the context menu
2007- * so we pin the file. the pinned file is displayed before the normal files in the working set and tab bar
2008- * we also prevent the pinned files from being closed during bulk close operations
2009- * @param {{file: File, paneId: string} } commandData - the file to pin and paneId,
2010- * if unavailable we use the current file and active pane
2006+ * Toggles the pin state of a file. Pinned files are displayed before normal files
2007+ * in the working set and tab bar, and are protected from bulk close operations.
2008+ * @param {{file: File, paneId: string, forcePin: boolean, forceUnpin: boolean} } commandData
2009+ * - file: the file to pin/unpin (defaults to currently viewed file)
2010+ * - paneId: the pane ID (defaults to active pane)
2011+ * - forcePin: if true, always pins
2012+ * - forceUnpin: if true, always unpins
2013+ * - if neither forcePin nor forceUnpin, toggles based on current state
20112014 */
20122015 function handleFilePin ( commandData = { } ) {
20132016 const file = commandData . file || MainViewManager . getCurrentlyViewedFile ( ) ;
20142017 const paneId = commandData . paneId || MainViewManager . ACTIVE_PANE ;
20152018
20162019 if ( file ) {
2017- MainViewManager . pinFile ( paneId , file ) ;
2018- }
2019- }
2020-
2021- /**
2022- * this unpins the file so it goes back to normal behavior in the working set and tab bar
2023- * @param {{file: File, paneId: string} } commandData - read the JSDoc for handleFilePin
2024- */
2025- function handleFileUnpin ( commandData = { } ) {
2026- const file = commandData . file || MainViewManager . getCurrentlyViewedFile ( ) ;
2027- const paneId = commandData . paneId || MainViewManager . ACTIVE_PANE ;
2028-
2029- if ( file ) {
2030- MainViewManager . unpinFile ( paneId , file ) ;
2020+ if ( commandData . forcePin ) {
2021+ MainViewManager . pinFile ( paneId , file ) ;
2022+ } else if ( commandData . forceUnpin ) {
2023+ MainViewManager . unpinFile ( paneId , file ) ;
2024+ } else {
2025+ // Toggle based on current state
2026+ const isPinned = MainViewManager . isPathPinned ( paneId , file . fullPath ) ;
2027+ if ( isPinned ) {
2028+ MainViewManager . unpinFile ( paneId , file ) ;
2029+ } else {
2030+ MainViewManager . pinFile ( paneId , file ) ;
2031+ }
2032+ }
20312033 }
20322034 }
20332035
@@ -2410,7 +2412,6 @@ define(function (require, exports, module) {
24102412 CommandManager . register ( Strings . CMD_FILE_RENAME , Commands . FILE_RENAME , handleFileRename ) ;
24112413 CommandManager . register ( Strings . CMD_FILE_DELETE , Commands . FILE_DELETE , handleFileDelete ) ;
24122414 CommandManager . register ( Strings . CMD_FILE_PIN , Commands . FILE_PIN , handleFilePin ) ;
2413- CommandManager . register ( Strings . CMD_FILE_UNPIN , Commands . FILE_UNPIN , handleFileUnpin ) ;
24142415
24152416 // Close Commands
24162417 CommandManager . register ( Strings . CMD_FILE_CLOSE , Commands . FILE_CLOSE , handleFileClose ) ;
0 commit comments