├── Context.sublime-menu ├── LockTab.py ├── LockTab.sublime-settings ├── Main.sublime-menu ├── README.md ├── images ├── Alert.png ├── Lock.png ├── Locked.png ├── Settings.png ├── Toggle.png └── Unlock.png ├── messages.json └── messages └── 1.2.0.txt /Context.sublime-menu: -------------------------------------------------------------------------------- 1 | [ 2 | { "caption": "-" }, 3 | { "caption": "Lock Tab", "command": "lock_tab" }, 4 | { "caption": "UnLock Tab", "command": "unlock_tab" }, 5 | { "caption": "Toggle Tab Lock", "command": "toggle_tab_lock" }, 6 | { "caption": "-" } 7 | ] 8 | -------------------------------------------------------------------------------- /LockTab.py: -------------------------------------------------------------------------------- 1 | import sublime, sublime_plugin 2 | 3 | sSettings = sublime.load_settings('LockTab.sublime-settings') 4 | 5 | # For ST3 6 | def plugin_loaded(): 7 | global window 8 | window = sublime.windows()[0] 9 | global sSettings 10 | sSettings = sublime.load_settings('LockTab.sublime-settings') 11 | 12 | # Loading lockList and Alert settings 13 | tempLockList = sSettings.get("locked") 14 | tempAlert = sSettings.get("alert") 15 | tempFocusOCT = sSettings.get("focus_on_closed_tab") 16 | # Check that every "locked" file is still in the window 17 | for tempFile in tempLockList: 18 | found = False 19 | 20 | for view in window.views(): 21 | if tempFile == view.file_name(): 22 | view.set_status("Locked", "LOCKED") 23 | found = True 24 | # and if found, set the locked property 25 | 26 | if not found: 27 | tempLockList.remove(tempFile) ; 28 | 29 | # saving settings 30 | sSettings.set("locked", tempLockList) 31 | sSettings.set("alert", tempAlert) 32 | sSettings.set("focus_on_closed_tab", tempFocusOCT) 33 | sublime.save_settings( "LockTab.sublime-settings") 34 | 35 | class ToggleTabLockCommand( sublime_plugin.TextCommand ): 36 | 37 | def run(self, edit): 38 | 39 | settings = sublime.load_settings("LockTab.sublime-settings") 40 | self.Lock_list = sSettings.get("locked") 41 | 42 | if not (self.view.file_name() in self.Lock_list): 43 | name = self.view.name() 44 | self.view.set_status("Locked", "LOCKED") 45 | 46 | self.Lock_list.append(self.view.file_name()) 47 | 48 | else: 49 | self.Lock_list.remove(self.view.file_name()) 50 | self.view.erase_status("Locked") 51 | 52 | sSettings.set("locked", self.Lock_list) 53 | sublime.save_settings( "LockTab.sublime-settings") 54 | 55 | def is_visible(self, paths=None): 56 | 57 | settings = sublime.load_settings("LockTab.sublime-settings") 58 | bShowToggle = sSettings.get("show_toggle") 59 | bHideAll = sSettings.get("hide_all") 60 | 61 | if (bHideAll): 62 | return False 63 | 64 | return bShowToggle 65 | 66 | class LockTabCommand( sublime_plugin.TextCommand ): 67 | 68 | def run(self, edit): 69 | ToggleTabLockCommand.run(self, edit) 70 | 71 | def is_visible(self, paths=None): 72 | # def is_enabled(self, paths=None): 73 | self.Lock_list = sSettings.get("locked") 74 | bShowToggle = sSettings.get("show_toggle") 75 | bHideAll = sSettings.get("hide_all") 76 | 77 | if (bHideAll): 78 | return False 79 | 80 | # Avoiding locking of not-saved file 81 | if not ( self.view.file_name() ) or bShowToggle: 82 | return False 83 | 84 | if (self.view.file_name() in self.Lock_list): 85 | return False 86 | 87 | return True 88 | 89 | class UnlockTabCommand( sublime_plugin.TextCommand ): 90 | 91 | def run(self, edit): 92 | ToggleTabLockCommand.run(self, edit) 93 | 94 | def is_visible(self, paths=None): 95 | # def is_enabled(self, paths=None): 96 | self.Lock_list = sSettings.get("locked") 97 | bShowToggle = sSettings.get("show_toggle") 98 | bHideAll = sSettings.get("hide_all") 99 | 100 | if (bHideAll): 101 | return False 102 | 103 | if bShowToggle: 104 | return False 105 | 106 | if (self.view.file_name() in self.Lock_list): 107 | return True 108 | 109 | return False 110 | 111 | class KeyBindingListener(sublime_plugin.EventListener): 112 | 113 | def on_pre_close(self, view ): 114 | 115 | nId = view.file_name() 116 | Lock_list = sSettings.get("locked") 117 | bAlert = sSettings.get("alert") 118 | 119 | if not (nId in Lock_list): 120 | return 121 | 122 | # Saving tab position 123 | self.TabPosition = window.get_view_index(view) 124 | print (str(self.TabPosition[0] ) + str(self.TabPosition[1]) ) 125 | 126 | # Saving focus position 127 | self.visibleRegion = view.visible_region() 128 | # saving actual active view 129 | self.ActiveView = window.active_view() 130 | 131 | self.bClose = False; 132 | # PopUp 133 | if (bAlert): 134 | if (sublime.ok_cancel_dialog("Locked Tab. Close it anyway?", "Yes!")): 135 | self.bClose = True; 136 | 137 | 138 | def on_load(self, view): 139 | # setting focus position 140 | # if (view.name() in Lock_list): 141 | view.show(self.visibleRegion.begin()) 142 | 143 | def on_close(self, view): 144 | 145 | nId = view.file_name() 146 | tempFocusOCT = sSettings.get("focus_on_closed_tab") 147 | Lock_list = sSettings.get("locked") 148 | 149 | # if tab locked 150 | if (nId in Lock_list): 151 | 152 | # if user confirm closure 153 | if (self.bClose): 154 | # removing filename 155 | Lock_list.remove(nId) 156 | # exiting 157 | sublime.save_settings( "LockTab.sublime-settings") 158 | return 159 | 160 | # if I have to keep the tab opened 161 | window.run_command("reopen_last_file") 162 | 163 | 164 | # setting the old tab position 165 | vNew = window.active_view() 166 | vNew.set_status("Locked", "LOCKED") 167 | window.set_view_index(vNew, self.TabPosition[0], self.TabPosition[1]) 168 | if not tempFocusOCT: 169 | window.focus_view(self.ActiveView) -------------------------------------------------------------------------------- /LockTab.sublime-settings: -------------------------------------------------------------------------------- 1 | { 2 | 3 | // pop up alert when try closing locked tab 4 | "alert": true, 5 | 6 | // set the focus always on the closed tab (if locked) 7 | "focus_on_closed_tab": true, 8 | 9 | // if TRUE: doesn't show the LockTab / UnLockTab menu items but only Toggle Tab Lock 10 | "show_toggle": false, 11 | 12 | // if TRUE you won't see anything in the right-click menu. 13 | // In this case you must use the keybinding or the ctrl+shift+p menu 14 | // If TRUE this overwrite the "show_toggle" option 15 | "hide_all": false, 16 | 17 | "locked": [ ] 18 | 19 | } 20 | 21 | -------------------------------------------------------------------------------- /Main.sublime-menu: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "caption": "Preferences", 4 | "id": "preferences", 5 | "mnemonic": "n", 6 | "children": 7 | [ 8 | { 9 | "caption": "Package Settings", 10 | "id": "package-settings", 11 | "mnemonic": "P", 12 | "children": 13 | [ 14 | { 15 | "caption": "LockTab", 16 | "children": 17 | [ { 18 | "caption": "Settings – Default", 19 | "command": "open_file", "args": 20 | { 21 | "file": "${packages}/LockTab/LockTab.sublime-settings" 22 | } 23 | }, 24 | { 25 | "caption": "Settings – User", 26 | "command": "open_file", "args": 27 | { 28 | "file": "${packages}/User/LockTab.sublime-settings" 29 | } 30 | } 31 | ] 32 | } 33 | ] 34 | } 35 | ] 36 | } 37 | ] 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | LockTab 2 | ======== 3 | 4 | This plugin allows you to lock (and unlock) a tab in Sublime. 5 | The plugin tries to remember the position of the tab and also the position of the 6 | focus in the view. 7 | 8 | This is my first work and it has not the claim to be complete or perfect. 9 | It is (and will remain) a very simple and essential, but I hope useful, plugin but it can 10 | be improved in a lot of aspects. 11 | 12 | Right now you can lock only saved-files (or, at least, with a physical path). (See ToDo #7) 13 | 14 | Usage 15 | ----- 16 | Just right click on the view (right now not on the tab name, see ToDo#3) and Lock/Unlock 17 | the tab. 18 | 19 | **Lock, Unlock, Toggle:** 20 | 21 | ![Lock](./images/Lock.png) 22 | 23 | 24 | 25 | ![Lock](./images/Toggle.png) 26 | 27 | **Alert:** 28 | 29 | ![Alert](./images/Alert.png) 30 | 31 | **Settings:** 32 | LockTab.sublime-settings is quite self-explained. 33 | 34 | ![Settings](./images/Settings.png) 35 | 36 | **Status Bar Propery:** 37 | 38 | ![Settings](./images/Locked.png) 39 | 40 | 41 | 42 | ToDo 43 | ---- 44 | 1. **First of all I'm looking for a method for avoiding the normal behavior of sublime.** 45 | Right now I just intercept the tab closing, and then I reopen the tab. This is, as far as I 46 | know, the only thing I can do. **Right now is not possibile avoiding the tab closure!** 47 | **Do you know how to do it?** 48 | 49 | 2. One of the most important things to do is to **add a particular icon (or also only a different 50 | colour) to the locked tab**. ~~I haven't tried it. It could be very easy or impossible. I don't know.~~ 51 | I tried it but the '''set_name''' function changes the name of the tab (my idea was e.g. to add a particular 52 | ascii simbol in the tab name just after the file name) but ALSO the file path! Once I changed the name the file 53 | suddenly appear as dirty, so sublime'll ask for a save. 54 | **Am I doing something wrong?!** 55 | 56 | 3. It could be very useful permit the Lock/UnLock of the tab directly from the tab name 57 | and not only on the tab "body". Right now sublime do not give the view ID of the right-clicked 58 | tab name but only of the view on which you have the focus. 59 | Do you know how to do it? 60 | 61 | 4. Managing more than one group of views. Again didn't try at all. 62 | 63 | 5. Improving the "set focus" after the reopen 64 | 65 | 6. Lock a tab -> Save the locked file with a new name. -> Close the tab 66 | Right now the plugin does not forbid the closure. Should I manage it? 67 | 68 | 7. Managing not-saved files(?) 69 | 70 | 8. ~~Add a default key-binding.~~ 71 | 72 | 73 | ChangeLog 74 | ========= 75 | 76 | LockTab - 1.2.0 77 | --------------- 78 | - Added Toogle Lock Tab command. 79 | You can now use (and see) the toggle command both with a shorcut and from the right-click menu. 80 | 81 | - Added *show_toggle* and *hide_all* preferences. 82 | *show_toggle* if true hides the "lock_tab" and "unlock_tab" command from the right-click menu but shows a "Toggle lock tab" command. 83 | *hide_all* if true hides every command from the right-click menu. Useful if you don't want to view anything in the menu (if you have a menu full of functions) and if you want to use just the shortcut. 84 | 85 | - Now the "LOCKED" property in the status bar will be shown also when reopening sublime 86 | 87 | LockTab - 1.1.0 88 | --------------- 89 | - Changed IsEnabled in IsVisibile. You won't see the Lock/UnLock menu item every time you right-click on your file. You'll see only the available action. You won't see anything if the file hasn't a path. 90 | 91 | - Added the Preferences -> LockTab menu. You can now open the preferences file directly from sublime. 92 | 93 | Thanks To 94 | ========= 95 | - [antonioriva](https://github.com/antonioriva) 96 | - [belmat](https://github.com/belmat) 97 | - [gian8816](https://github.com/gian8816) -------------------------------------------------------------------------------- /images/Alert.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DavidGerva/LockTab-Sublime-Plugin/448c2569e4ef80709a4130f286cd74d028bb7a6f/images/Alert.png -------------------------------------------------------------------------------- /images/Lock.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DavidGerva/LockTab-Sublime-Plugin/448c2569e4ef80709a4130f286cd74d028bb7a6f/images/Lock.png -------------------------------------------------------------------------------- /images/Locked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DavidGerva/LockTab-Sublime-Plugin/448c2569e4ef80709a4130f286cd74d028bb7a6f/images/Locked.png -------------------------------------------------------------------------------- /images/Settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DavidGerva/LockTab-Sublime-Plugin/448c2569e4ef80709a4130f286cd74d028bb7a6f/images/Settings.png -------------------------------------------------------------------------------- /images/Toggle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DavidGerva/LockTab-Sublime-Plugin/448c2569e4ef80709a4130f286cd74d028bb7a6f/images/Toggle.png -------------------------------------------------------------------------------- /images/Unlock.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DavidGerva/LockTab-Sublime-Plugin/448c2569e4ef80709a4130f286cd74d028bb7a6f/images/Unlock.png -------------------------------------------------------------------------------- /messages.json: -------------------------------------------------------------------------------- 1 | { 2 | "install": "messages/1.2.0.txt", 3 | "1.2.0": "messages/1.2.0.txt" 4 | } -------------------------------------------------------------------------------- /messages/1.2.0.txt: -------------------------------------------------------------------------------- 1 | LockTab - 1.2.0 2 | --------------- 3 | 4 | Hello! Here what's new in LockTab 1.2.0. 5 | 6 | - Added Toogle Lock Tab command. 7 | You can now use (and see) the toggle command both with a shorcut and from the right-click menu. 8 | 9 | - Added *show_toggle* and *hide_all* preferences. 10 | *show_toggle* if true hides the "lock_tab" and "unlock_tab" command from the right-click menu but shows a "Toggle lock tab" command. 11 | *hide_all* if true hides every command from the right-click menu. Useful if you don't want to view anything in the menu (if you have a menu full of functions) and if you want to use just the shortcut. 12 | 13 | - Now the "LOCKED" property in the status bar will be shown also when reopening sublime. 14 | 15 | - Something you want to do or propose?! Contact me! 16 | 17 | I think I won't create a "default" key binding. If you want to have one just open the *Key Bindings - User* menu under *Preferences* and add a line like this: 18 | 19 | { "keys": ["ctrl+k"], "command": "toggle_tab_lock" } 20 | 21 | 22 | I will be back soon ;) 23 | 24 | David (davidgerva@gmail.com) --------------------------------------------------------------------------------