Home Download Buy Blog Forum Support

Value of global setting show on Menu checkbox? [SOLVED]

Value of global setting show on Menu checkbox? [SOLVED]

Postby robertcollier4 on Wed Feb 27, 2013 8:22 am

I have added the following to Main.sublime-menu but it is not working. The entry shows up in the Menu and the checkbox in the menu item toggles when I click on it - however it is not changing the behavior. Does anyone have any tips or know what I am doing wrong or is this a bug?

In Main.sublime-menu:
Code: Select all
{ "command": "toggle_setting", "args": {"setting": "remember_open_files"}, "caption": "Remember Opened Files", "checkbox": true },


---------------------------------------------------------------
EDIT: [SOLVED]
Last edited by robertcollier4 on Wed Mar 06, 2013 9:35 am, edited 13 times in total.
robertcollier4
 
Posts: 154
Joined: Sun Feb 24, 2013 5:37 pm

Re: [ST3] toggle_setting for remember_open_files not working

Postby robertcollier4 on Wed Feb 27, 2013 10:06 am

This doesn't work either:
Code: Select all
{ "keys": ["f8"], "command": "toggle_setting", "args": {"setting": "remember_open_files"} },
robertcollier4
 
Posts: 154
Joined: Sun Feb 24, 2013 5:37 pm

Re: [ST3] toggle_setting for remember_open_files not working

Postby quarnster on Wed Feb 27, 2013 10:37 am

Toggle_setting only toggles the view's setting, not the global settings. You'll have to create a new command, something like this:

Code: Select all
import sublime, sublime_plugin

class ToggleGlobalSettingCommand(sublime_plugin.WindowCommand):
    def run(self, setting):
        s = sublime.load_settings("Preferences.sublime-settings")
        s.set(setting, not s.get(setting, False))
        s.save_settings("Preferences.sublime-settings")
quarnster
 
Posts: 389
Joined: Tue Nov 29, 2011 11:34 am

How to have value of global setting show on Menu checkbox?

Postby robertcollier4 on Wed Feb 27, 2013 12:06 pm

Fantastic! Thanks quarnster. Works perfectly with last line changed from "s.save_settings" to "sublime.save_settings".

However - is there any way to also have the menu show a checkbox regarding the state of a global setting or from the return value of a plugin?. I tried returning true or false from the ToggleGlobalSettingCommand - but it doesn't affect the state of the checkbox. Otherwise I have no way to know if I am turning the setting on or off, and I would have to create two buttons on the Menu - one for "Remember Opened Files - Off" and "Remember Opened Files - On".

This is my entry in Main.sublime-menu:
Code: Select all
{ "command": "toggle_global_setting", "args": {"setting": "remember_open_files"}, "caption": "Remember Opened Files", "mnemonic": "R", "checkbox": true },
robertcollier4
 
Posts: 154
Joined: Sun Feb 24, 2013 5:37 pm

Re: How to have value of global setting show on Menu checkbox?

Postby jps on Thu Feb 28, 2013 5:15 am

Plugin commands can define an is_checked method, which will be queried by the menu
jps
Site Admin
 
Posts: 3069
Joined: Wed Mar 19, 2008 12:33 pm

Re: How to have value of global setting show on Menu checkbox?

Postby robertcollier4 on Wed Mar 06, 2013 9:26 am

jps wrote:Plugin commands can define an is_checked method, which will be queried by the menu

Fantastic, thanks for letting me know. Here is a working menu entry that toggles "remember_open_files".

Code: Select all
import sublime, sublime_plugin

class GlobalSettingToggleCommand(sublime_plugin.ApplicationCommand):
   def run(self, setting):
      s = sublime.load_settings("Preferences.sublime-settings")
      s.set(setting, not s.get(setting, False))
      sublime.save_settings("Preferences.sublime-settings")

   def is_checked(self, setting):
      return sublime.load_settings("Preferences.sublime-settings").get(setting, False)

In Main.sublime-menu
Code: Select all
{ "command": "global_setting_toggle", "args": {"setting": "remember_open_files"}, "caption": "Remember Opened Files", "checkbox": true },
robertcollier4
 
Posts: 154
Joined: Sun Feb 24, 2013 5:37 pm


Return to Technical Support

Who is online

Users browsing this forum: No registered users and 13 guests