Sublime Forum

Several Plugin Dev questions: Prevent menu from closing, detect window open / close, and more

#1

I have a few questions which will greatly increase productivity in mine… and for the edit_settings_plus system I’ll release as a stand-alone system people can include in their projects, or as a library in mine ( although if placed into your own project then you don’t need to manually or dynamically grab the package folder name [ dynamically using helpers I provide ] )

  • Primary Thread Questions
    • Is there a solution to prevent a context or main menu from being closed when certain entries have been clicked - for instance: When enabling / disabling a checkmark on a list item after it has been selected for viewing / hiding a category in my plugin…
    • Are there event listener callbacks to detect a window being opened / closed? Mostly not needed at the moment as I found another way - but I’m surprised there isn’t a callback for this… I did create a solution to handle it but there should be a way around it.
    • I have a few more questions but I’ll edit the thread or make a new one later… if needed…

And secondary: If you could have any helper expanded vars for all of the commands ( edit_settings [ or my edit_settings_plus ], open url, etc… ) what would they be? This is for my edit_settings_plus release… Right now I use the active window extract_vars in addition to many many more…

Here’s a list of all of the available vars ( although architecture seems to be bugged ) and if syntax isn’t set or something is off it seems to use the file extension so I need to add a way to get the associated languages and more information to ensure the proper data is always reported for the short-keywords ( syntax should be the syntax either used for the file extension or the syntax selected - if none then it should use the default – and language needs to be unique from syntax … so it can return Markdown when syntax returns md, for instance )

The following is the larger of the 2 example commands to open a scratch file in edit_settings_plus to show all of the variables available for use for the base_file, user_file, default for contents, file_list == Dict containing dicts of the previous vars…

//
// Acecool - Code Mapping System - Extracted Vars Example
//
// Note: Because of our use of several sources - some values may be identical and some vars may be shortened - treat these as aliases...
//
{
	//
	// Computer / Software Information - The following variables and results pertain to your computer and Sublime Text...
	//

	// This is a built in helper to return Case-Correct Windows / Linux / OSX / etc.. and is future-proof
	${platform}				Windows

	// This returns the CPU architecture - ie 32 bit / 64 bit as "x32" or "x64"
	${architecture}			x64
	${arch}					x64

	//Sublime Text Version - Not necessary from what I've seen unless there is a changelog file with this number to access...
	${version_sublime}		3143


	//
	// File Information - The following variables and results pertain to the file which was active / in-focus at the time edit_settings_plus was called...
	//

	// Full path to the file with file extension
	${file}					C:\AcecoolServers\srcds_acecooldev_framework\garrysmod\gamemodes\acecooldev_framework\ideas.md

	// Filename without path - with and without the extension
	${file_name}			ideas.md
	${file_base_name}		ideas

	// File Path without file-name...
	${file_path}			C:\AcecoolServers\srcds_acecooldev_framework\garrysmod\gamemodes\acecooldev_framework

	// File Extension for the file which was active at the time edit_settings_plus was called... and aliases.. ie: py, sublime-settings, cpp, ahk, etc..
	${file_extension}		md
	${extension}			md
	${ext}					md


	//
	// Syntax Information - The following variables and results pertain to the Syntax / Language Definition being used by the file which was active / in-focus at the time edit_settings_plus was called...
	//

	// Syntax / Language Name for the file which was active at the time edit_settings_plus was called... and aliases..
	${syntax}				Markdown
	${language}				Markdown
	${lang}					Markdown

	// Full Path to the Syntax User Configuration File ie: Packages/User/Python.sublime-settings
	${user_syntax}			C:\Users\Acecool\AppData\Roaming\Sublime Text 3\Packages\User\md.sublime-settings

	// Syntax / Language Definition Data - File Extenson.. ie: tmLanguage or sublime-syntax
	${syntax_ext}			sublime-syntax

	// Syntax / Language Definition File Name with Extension
	${syntax_file}			md.sublime-syntax

	// Full Path to the Syntax / Language Definition File with filename and Extension.
	${syntax_path}			User/CodeMap/custom_languages/md.sublime-syntax


	//
	// Sublime Text Folder Structure - The following variables and results pertain with the folder-structure used by Sublime Text, and the active package...
	//

	// Full path to the Packages folder
	${packages}				C:\Users\Acecool\AppData\Roaming\Sublime Text 3\Packages

	// Full Path to the Default Packages Directory ie: Packages/Default/ - Windows Example: %AppData%/Sublime Text 3/Packages/Default/
	${default}				C:\Users\Acecool\AppData\Roaming\Sublime Text 3\Packages\Default

	// Full Path to the User Packages Directory ie: Packages/User/ - Windows Example: %AppData%/Sublime Text 3/Packages/User/
	${user}					C:\Users\Acecool\AppData\Roaming\Sublime Text 3\Packages\User

	// Full Path to the Sublime Text Cache Directory ie: Cache/ - Windows Example: %AppData%/Sublime Text 3/Packages/User/
	${cache}				C:\Users\Acecool\AppData\Local\Sublime Text 3\Cache

	// Full Path to the Installed Packages Directory ie: ../Installed Packages/ - Windows Example: %AppData%/Sublime Text 3/Installed Packages/
	${packages_installed}	C:\Users\Acecool\AppData\Roaming\Sublime Text 3\Installed Packages

	// Full Path to the Package Directory ie: Packages/PackageName/ - Windows Example: %AppData%/Sublime Text 3/Packages/AcecoolCodeMappingSystem/
	${package}				C:\Users\Acecool\AppData\Roaming\Sublime Text 3\Packages\AcecoolCodeMappingSystem

	// Full Path to the User Package Directory ie: Packages/User/PackageName/ - Windows Example: %AppData%/Sublime Text 3/Packages/User/AcecoolCodeMappingSystem/
	${user_package}			C:\Users\Acecool\AppData\Roaming\Sublime Text 3\Packages\User\AcecoolCodeMappingSystem


	//
	// Sublime Text Window Session / Project Information - The following data pertains to the Sublime Text window session, project folders, etc.. as seen in menu > project > *
	//

	// Project Based - These contain data regarding the Sublime Text Window Session - The Project with folder data in the sidebar, etc.. nothing to do with Sublime Text Packages...
	${folder}				C:\AcecoolGit\acecooldev_sublimetext3\AppData\Sublime Text 3\Packages\AcecoolCodeMappingSystem
	${project}				C:\AcecoolGit\AcecoolCodeMappingSystem.sublime-project
	${project_path}			C:\AcecoolGit
	${project_name}			AcecoolCodeMappingSystem.sublime-project
	${project_base_name}	AcecoolCodeMappingSystem
	${project_extension}	sublime-project


	//
	// Miscellaneous Variables - The following have no other categorization...
	//

	// Base Repo URL - Useful when adding multiple menu items to the Repo such as: View Wiki, View All Issues, Submit New Issue, etc.. Note: ARG repo REQUIRED to be of use!
	${repo}					https://bitbucket.org/Acecool/acecooldev_sublimetext3


	//
	// Contributors - The following simply lists where each variable came from...
	//

	// Acecool Library - edit_settings_plus or AcecoolLib_Sublime or AcecoolLib_Python
	user, default, cache, packages_installed
	package, user_package
	syntax / language / lang, user_syntax, syntax_ext, syntax_file, syntax_path
	extension / ext
	architecture / arch
	repo
	version_sublime

	// Sublime Text - Active Window Variables using: sublime.active_window( ).extract_variables( )
	platform
	packages
	project, project_path, project_name, project_base_name, project_extension
	file, folder, file_path, file_name, file_base_name, file_extension
}

Short version:

//
"//
// Acecool - Code Mapping System - Extracted Vars Example
//
{
	//
	// Acecool Library / Extract Vars
	//
	${version_sublime}		3143
	${architecture}			x64
	${arch}					x64
	${cache}				C:\Users\Acecool\AppData\Local\Sublime Text 3\Cache
	${packages_installed}	C:\Users\Acecool\AppData\Roaming\Sublime Text 3\Installed Packages
	${packages}				C:\Users\Acecool\AppData\Roaming\Sublime Text 3\Packages
	${user}					C:\Users\Acecool\AppData\Roaming\Sublime Text 3\Packages\User
	${default}				C:\Users\Acecool\AppData\Roaming\Sublime Text 3\Packages\Default
	${package}				C:\Users\Acecool\AppData\Roaming\Sublime Text 3\Packages\AcecoolCodeMappingSystem
	${user_package}			C:\Users\Acecool\AppData\Roaming\Sublime Text 3\Packages\User\AcecoolCodeMappingSystem
	${syntax}				Python
	${language}				Python
	${lang}					Python
	${user_syntax}			C:\Users\Acecool\AppData\Roaming\Sublime Text 3\Packages\User\Python.sublime-settings
	${syntax_ext}			tmLanguage
	${syntax_file}			Python.tmLanguage
	${syntax_path}			Python/Python.tmLanguage
	${extension}			py
	${ext}					py
	${repo}					https://bitbucket.org/Acecool/acecooldev_sublimetext3


	//
	// sublime.active_window( ).extract_variables( )
	//
	${platform}				Windows
	${packages}				C:\Users\Acecool\AppData\Roaming\Sublime Text 3\Packages
	${file}					C:\AcecoolGit\acecooldev_sublimetext3\AppData\Sublime Text 3\Packages\AcecoolCodeMappingSystem\AcecoolCodeMappingSystemPlugin.py
	${file_path}			C:\AcecoolGit\acecooldev_sublimetext3\AppData\Sublime Text 3\Packages\AcecoolCodeMappingSystem
	${file_name}			AcecoolCodeMappingSystemPlugin.py
	${file_base_name}		AcecoolCodeMappingSystemPlugin
	${file_extension}		py
	${folder}				C:\AcecoolGit\acecooldev_sublimetext3\AppData\Sublime Text 3\Packages\AcecoolCodeMappingSystem
	${project}				C:\AcecoolGit\AcecoolCodeMappingSystem.sublime-project
	${project_path}			C:\AcecoolGit
	${project_name}			AcecoolCodeMappingSystem.sublime-project
	${project_base_name}	AcecoolCodeMappingSystem
	${project_extension}	sublime-project
}"

What would you add?

What would you remove?

ie Would you prefer the sublime.extract_variables( ) file_extension, or ext / extension… long or short? Do you like the helpers such as user_syntax instead of using ${user}/${syntax}.sublime-settings… etc… What is missing? What is too much?

Examples of edit_settings_plus used in Python as commands are:

##
## Command - Open Sublime Preferences
##
class acms_menu_settings_open_sublime_prefs( sublime_plugin.WindowCommand ):
	##
	def description( self ):
		return 'Sublime Text Preferences'

	##
	def is_enabled( self ):		return self.window.active_view( ) is not None

	##
	def run( self ):
		self.window.run_command(
			'edit_settings_plus',
			{
				## Set developer to True to ensure the left / base group doesn't set the default files as read only... debugging arg to print out information as the command loads or runs other tasks...
				# 'developer':	True,

				'base_file':	[ '${default}/Preferences.sublime-settings',						'${default}/Preferences (${platform}).sublime-settings',			None ], # '${syntax_path}'
				'user_file':	[ '${user}/Preferences.sublime-settings',							'${user}/Preferences (${platform}).sublime-settings',				'${user}/${syntax}.sublime-settings' ],#'os.path.join( sublime.packages_path( ), 'User', _syntax + '.sublime-settings' ),
				'default':		[ '//\n// Sublime Text - Configuration - User\n//\n{\n\t$0\n}\n',	'//\n// Sublime Text - Configuration - User\n//\n{\n\t$0\n}\n',		'//\n// Acecool - Code Mapping System - ${syntax} Syntax Configuration - User\n//\n{\n\t$0\n}\n' ]
			}
		)


##
## Command - Open All Plugin Preferences
##
class acms_menu_settings_open_plugin_prefs( sublime_plugin.WindowCommand ):
	##
	def description( self ):
		return 'Plugin Preferences'

	##
	def is_enabled( self ):		return self.window.active_view( ) is not None

	##
	def run( self ):
		self.window.run_command(
			'edit_settings_plus',
			{
				'developer':	True,
				##'debugging':	True,
				## RunTime > Map > Plugin > Panel > Definitions > Default...
				'file_list':
				[
					## 'caption':			'Plugin Map Settings - Default',
					{ 'base_file': '${package}/ACMS_Definitions.sublime-settings',	'user_file': '${user}/ACMS_Definitions.sublime-settings',	'default': '//\n// Acecool - Code Mapping System - Plugin Definitions - User\n//\n{\n\t$0\n}\n' },

					## 'caption':			'Plugin Map Settings - Default',
					{ 'base_file': '${package}/ACMS_Panels.sublime-settings',		'user_file': '${user}/ACMS_Panels.sublime-settings',		'default': '//\n// Acecool - Code Mapping System - Mapping Panel( s ) Configuration - User\n//\n{\n\t$0\n}\n' },

					## 'caption':			'Plugin Map Settings - Default',
					{ 'base_file': '${package}/ACMS_Plugin.sublime-settings',		'user_file': '${user}/ACMS_Plugin.sublime-settings',		'default': '//\n// Acecool - Code Mapping System - Plugin Configuration - User\n//\n{\n\t$0\n}\n' },

					## 'caption':			'Plugin Map Settings - Default',
					{ 'base_file': '${package}/ACMS_Mapping.sublime-settings',		'user_file': '${user}/ACMS_Mapping.sublime-settings',		'default': '//\n// Acecool - Code Mapping System - Mapping Configuration - User\n//\n{\n\t$0\n}\n' },

					## 'caption':			'Plugin Map Settings - Default',
					{ 'base_file': '${package}/ACMS_RunTime.sublime-settings',		'user_file': '${user}/ACMS_RunTime.sublime-settings',		'default': '//\n// Acecool - Code Mapping System - Plugin RunTime Configuration - User - EDIT AT YOUR OWN RISK!\n//\n{\n\t$0\n}\n' },

					## 'caption':			'${syntax} Syntax Settings'
					{ 'base_file': None,											'user_file': '${user}/${syntax}.sublime-settings',			'default': '//\n// Acecool - Code Mapping System - ${syntax} Syntax Configuration - User\n//\n{\n\t$0\n}\n' },
				],
			},
		)

I have a few basic tasks to do with edit_settings_plus.py before I release it to the public for use throughout… I did a quick update to remove settings.py influence ( and problems ), and got rid of a lot of redundant code used to resolve those problems by doing things differently… and I also got rid of the requirement stating you need a base file AND user file at the same time - now you can use edit_settings_plus with a single file base or user and instead of 2 groups opening, only 1 will appear and the file linking system will be disabled…

But overall the usefulness of this is amazing - I have a command set up to open all standard Sublime Text preferences, key / mouse maps in a window so 6 to 8 files ( Preferences User/Default, Preferences PLATFORM User/Default, Keymap User / Default, MouseMap User / Default - depending what exists or not )

Increase efficiency of tab linking, prevent non existent base group files from opening… add res:// support and a few small other things.

0 Likes