Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Custom Menus in Sublime Text

How to add a custom Menu item in SublimeText 2 .

Any Ideas ??
I see there is a Main.sublime-menu file but dont know how to edit it.

Thanks!

like image 517
Avi Avatar asked Apr 22 '13 12:04

Avi


People also ask

How do I use plugins in Sublime Text?

Once Package Control is installed, you can use this to install the below packages as follows: Go to SublimeText – Preferences – Package Control (MAC) or Preferences – Package Control (PC) Choose “Install Package” from the list of options. Find the name of the package you wish to install and select it.


1 Answers

The *.sublime-menu file is simply JSON. You can create a Main.sublime-menu in your user directory and it will be merged with other menu entries. It may be beneficial to look through the Main.sublime-menu files third party plugins have. These are generally much shorter, so may be easier to understand some of the things you need to define in each entry.

edit

You can use the following as a plugin to open notepad with an arbitrary file.

import sublime
import sublime_plugin
import subprocess
import threading
class OpenNotepadCommand(sublime_plugin.TextCommand):
    def run(self, edit, filename=None):
        th = NotepadThread(filename)
        th.start()

class NotepadThread(threading.Thread):
    def __init__(self, filename=None):
        self.filename = filename
        threading.Thread.__init__(self)

    def run(self):
        if self.filename is not None:
            subprocess.call("notepad.exe %s" % self.filename)
        else:
            subprocess.call("notepad.exe")

When you are creating a menu item use something like the following for the command and arguments.

{
    "command": "open_notepad",
    "args": { "filename": "<the absolute path here>"}
}
like image 84
skuroda Avatar answered Oct 03 '22 02:10

skuroda