Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python context menu #684

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ Main.sublime-menu

# mypy cache
.mypy_cache/
/Context.sublime-menu
/Context.sublime-menu-hidden
File renamed without changes.
39 changes: 39 additions & 0 deletions anaconda.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import os
import sys
import shutil
import logging
from string import Template

Expand All @@ -31,6 +32,8 @@
logger.addHandler(logging.StreamHandler(sys.stdout))
logger.setLevel(logging.DEBUG)

CURRENT_PATH = os.path.dirname( os.path.realpath( __file__ ) )


def plugin_loaded() -> None:
"""Called directly from sublime on plugin load
Expand All @@ -56,6 +59,42 @@ def plugin_loaded() -> None:
if not LOOP_RUNNING:
ioloop.loop()

install_context_menu()
disable_linter_context_menu()

def install_context_menu():
origin = os.path.join( CURRENT_PATH, 'Base Context.sublime-menu' )
destine = os.path.join( CURRENT_PATH, 'Context.sublime-menu' )

shutil.copy( origin, destine )

class HideMenuOnActivation(sublime_plugin.EventListener):

def on_activated_async(self, view):
disable_linter_context_menu()

def disable_linter_context_menu():
"""
Disable the linter Context Menu, if not on a linter view.

Allow to hide .sublime-menu folders
https://github.com/SublimeTextIssues/Core/issues/1859
"""
origin = os.path.join( CURRENT_PATH, 'Context.sublime-menu' )
destine = os.path.join( CURRENT_PATH, 'Context.sublime-menu-hidden' )

try:
if is_current_view_linted( sublime.active_window().active_view() ):
shutil.move( destine, origin )

else:
shutil.move( origin, destine )

except IOError:
pass

def is_current_view_linted(view):
return view.match_selector( view.sel()[0].begin(), 'source.python')

def plugin_unloaded() -> None:
"""Called directly from sublime on plugin unload
Expand Down