summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/commands.py25
-rw-r--r--src/core/completions.py13
-rw-r--r--src/core/core.py10
3 files changed, 45 insertions, 3 deletions
diff --git a/src/core/commands.py b/src/core/commands.py
index 712840d2..ca77501e 100644
--- a/src/core/commands.py
+++ b/src/core/commands.py
@@ -23,7 +23,7 @@ import fixes
import pep
import tabs
from common import safeJID
-from config import config, options as config_opts
+from config import config, DEFAULT_CONFIG, options as config_opts
import multiuserchat as muc
from plugin import PluginConfig
from roster import roster
@@ -648,11 +648,30 @@ def command_set(self, args):
info = config.set_and_save(option, value, section)
self.trigger_configuration_change(option, value)
else:
- self.command_help('set')
- return
+ return self.command_help('set')
self.call_for_resize()
self.information(*info)
+@command_args_parser.quoted(1, 2)
+def command_set_default(self, args):
+ """
+ /set_default [section] <option>
+ """
+ if len(args) == 1:
+ option = args[0]
+ section = 'Poezio'
+ elif len(args) == 2:
+ section = args[0]
+ option = args[1]
+ else:
+ return self.command_help('set_default')
+
+ default_config = DEFAULT_CONFIG.get(section, tuple())
+ if option not in default_config:
+ info = ("Option %s has no default value" % (option), "Error")
+ return self.information(*info)
+ self.command_set('%s %s %s' % (section, option, default_config[option]))
+
@command_args_parser.quoted(1)
def command_toggle(self, args):
"""
diff --git a/src/core/completions.py b/src/core/completions.py
index 7d95321b..a8d695d1 100644
--- a/src/core/completions.py
+++ b/src/core/completions.py
@@ -336,6 +336,19 @@ def completion_set(self, the_input):
return
return the_input.new_completion(end_list, n, quotify=True)
+
+def completion_set_default(self, the_input):
+ """ Completion for /set_default
+ """
+ args = common.shell_split(the_input.text)
+ n = the_input.get_argument_position(quoted=True)
+ if n >= len(args):
+ args.append('')
+ if n == 1 or (n == 2 and config.has_section(args[1])):
+ return self.completion_set(the_input)
+ return []
+
+
def completion_toggle(self, the_input):
"Completion for /toggle"
return the_input.new_completion(config.options('Poezio'), 1, quotify=False)
diff --git a/src/core/core.py b/src/core/core.py
index 4daeed6c..65d8622c 100644
--- a/src/core/core.py
+++ b/src/core/core.py
@@ -1773,6 +1773,14 @@ class Core(object):
"used as a special value to toggle a boolean option."),
shortdesc=_("Set the value of an option"),
completion=self.completion_set)
+ self.register_command('set_default', self.command_set_default,
+ usage=_("[section] <option>"),
+ desc=_("Set the default value of an option. For example,"
+ "`/set_default resource` will reset the default_resource"
+ "option. You can also reset options in specific"
+ "sections by doing `/set_default section option`."),
+ shortdesc=_("Set the default value of an option"),
+ completion=self.completion_set_default)
self.register_command('toggle', self.command_toggle,
usage=_('<option>'),
desc=_('Shortcut for /set <option> toggle'),
@@ -1967,6 +1975,7 @@ class Core(object):
command_destroy_room = commands.command_destroy_room
command_remove_bookmark = commands.command_remove_bookmark
command_set = commands.command_set
+ command_set_default = commands.command_set_default
command_toggle = commands.command_toggle
command_server_cycle = commands.command_server_cycle
command_last_activity = commands.command_last_activity
@@ -2007,6 +2016,7 @@ class Core(object):
completion_last_activity = completions.completion_last_activity
completion_server_cycle = completions.completion_server_cycle
completion_set = completions.completion_set
+ completion_set_default = completions.completion_set_default
completion_toggle = completions.completion_toggle
completion_bookmark_local = completions.completion_bookmark_local