My first plugin and my first python script that does something useful.
It allows to toggle the menu bars visibility.
I couldn’t find a way to do it with sublime api so I implemented it using ctypes.
Changelog v1.1.0:
Added support for remembering toggle state of the menubar and set it at next startup
Modified togglemenubar.tmp save order
Modified save behavior to save toggle state every time a toggle happens
Fixed some local/global variable naming issues
Changelog v1.0.2:
Fixed not using package folder to save tmp file when --data commandline option is used
Changelog v1.0.1:
Fixed toggleMenubar.tmp is now saved in appdata and not everywhere
Fixed only save menu data once when file saving file
[code]
toggleMenubar plugin v1.1.0 by Shoozza
Forum Thread:
http://www.sublimetext.com/forum/viewtopic.php?f=5&t=1080
example keybinding:
Known issues:
fullscreen mode menu toggling can cause issues in normal and fullscreen mode
import sublime, sublimeplugin, os
from ctypes import *
firstRun = 1
needSave = 1
show = 1
hwnd = windll.User32.GetActiveWindow()
hmenu = windll.User32.GetMenu(hwnd)
def doToggleMenubar():
if globals()“firstRun”] == 1:
globals()“firstRun”] = 0
globals()“hwnd”] = windll.User32.GetActiveWindow()
globals()“hmenu”] = windll.User32.GetMenu(globals()“hwnd”])
if globals()"hmenu"] == 0 or globals()"hwnd"] == 0:
loadToggleMenubarState()
newMenu = windll.User32.GetMenu(globals()"hwnd"])
if newMenu != 0 and newMenu != globals()"hmenu"]:
globals()"hmenu"] = newMenu
if globals()"show"] == 0:
windll.User32.SetMenu(globals()"hwnd"], globals()"hmenu"])
globals()"show"] = 1
else:
windll.User32.SetMenu(globals()"hwnd"], 0)
globals()"show"] = 0
globals()"needSave"] = 1
def loadToggleMenubarState():
if os.path.isfile(sublime.packagesPath()+"\User\toggleMenubar.tmp"):
file = open(sublime.packagesPath()+"\User\toggleMenubar.tmp", ‘r’)
try:
globals()“show”] = int(file.readline())
globals()“hmenu”] = int(file.readline())
globals()“hwnd”] = int(file.readline())
except:
pass
file.close()
else:
globals()“hwnd”] = windll.User32.GetActiveWindow()
globals()“hmenu”] = windll.User32.GetMenu(globals()“hwnd”])
def saveToggleMenubarState():
if globals()“needSave”] == 1:
globals()“needSave”] = 0
file = open(sublime.packagesPath()+"\User\toggleMenubar.tmp", ‘w’)
file.write(str(globals()“show”]))
file.write("\n")
file.write(str(globals()“hmenu”]))
file.write("\n")
file.write(str(globals()“hwnd”]))
file.close()
def cleanUpToggleMenubarStateFile():
if os.path.isfile(sublime.packagesPath()+"\User\toggleMenubar.tmp"):
os.remove(sublime.packagesPath()+"\User\toggleMenubar.tmp")
class toggleMenubarCommand(sublimeplugin.TextCommand):
def run(self, view, args):
doToggleMenubar()
saveToggleMenubarState()
class toggleMenubarStartup(sublimeplugin.Plugin):
def onActivated(self, view):
if globals()“firstRun”] == 1:
if os.path.isfile(sublime.packagesPath()+"\User\toggleMenubar.tmp"):
file = open(sublime.packagesPath()+"\User\toggleMenubar.tmp", ‘r’)
try:
globals()“show”] = int(file.readline())
except:
pass
file.close()
if globals()“show”] == 0:
globals()“show”] = 1
doToggleMenubar()
else:
cleanUpToggleMenubarStateFile()[/code]
Noticed that the code has spaces instead of tabs on this page and attachments don’t work for txt and py.
You can get the latest version here:
(current version v1.1.0) pastebin.com/1gUUebzv
(old version v1.0.2) pastebin.com/tRQXGqSC
(old version v1.0.1) pastebin.com/jzcx6H7x
(old version v1.0.0) pastebin.com/vkGUVL0Y