# toggleMenubar plugin v1.0.1
#
# example keybinding:
# <binding key="leftalt+m" command="toggleMenubar"/>
#
# Known issues:
# menu hidden by fullscreen mode can't be shown again
# saving any file makes toggleMenubar backup hwnd, hmenu and show
import sublime, sublimeplugin, os
from ctypes import *
firstRun = 1
needSave = 1
show = 1
hwnd = windll.User32.GetActiveWindow()
hmenu = windll.User32.GetMenu(hwnd)
CSIDL_APPDATA = 26
_SHGetFolderPath = windll.shell32.SHGetFolderPathA
_SHGetFolderPath.argtypes = [wintypes.HWND,
wintypes.c_int,
wintypes.HANDLE,
wintypes.DWORD, wintypes.LPCSTR]
appdataPath = wintypes.create_string_buffer(wintypes.MAX_PATH)
result = _SHGetFolderPath(0, CSIDL_APPDATA, 0, 0, appdataPath)
if result <> 0:
print "[Error] SHGetFolderPath returned: " + str(result)
def loadGlobals():
if os.path.isfile(appdataPath.value+"\\sublime text\\Packages\\User\\toggleMenubar.tmp"):
file = open(appdataPath.value+"\\sublime text\\Packages\\User\\toggleMenubar.tmp", 'r')
try:
globals()["hmenu"] = int(file.readline())
globals()["hwnd"] = int(file.readline())
globals()["show"] = int(file.readline())
except:
pass
file.close()
os.remove("toggleMenubar.tmp")
else:
globals()["hwnd"] = windll.User32.GetActiveWindow()
globals()["hmenu"] = windll.User32.GetMenu(globals()["hwnd"])
class toggleMenubarCommand(sublimeplugin.TextCommand):
def run(self, view, args):
if globals()["firstRun"]:
globals()["firstRun"] = 0
globals()["show"] = 1
globals()["hwnd"] = windll.User32.GetActiveWindow()
globals()["hmenu"] = windll.User32.GetMenu(globals()["hwnd"])
if globals()["hmenu"] == 0 or globals()["hwnd"] == 0:
loadGlobals()
newMenu = windll.User32.GetMenu(hwnd)
if newMenu != 0 and newMenu != globals()["hmenu"]:
globals()["hmenu"] = newMenu
if show:
windll.User32.SetMenu(globals()["hwnd"], 0)
globals()["show"] = 0
else:
windll.User32.SetMenu(globals()["hwnd"], globals()["hmenu"])
globals()["show"] = 1
globals()["needSave"] = 1
class toggleMenubarSecure(sublimeplugin.Plugin):
def onPreSave(self, view):
if globals()["needSave"] == 1:
globals()["needSave"] = 0
file = open(appdataPath.value+"\\sublime text\\Packages\\User\\toggleMenubar.tmp", 'w')
file.write(str(globals()["hmenu"]))
file.write("\n")
file.write(str(globals()["hwnd"]))
file.write("\n")
file.write(str(globals()["show"]))
file.close()