Skip to content
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
10 changes: 8 additions & 2 deletions setzer.in
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,15 @@ class MainApplicationController(Adw.Application):

argparser = argparse.ArgumentParser(usage='%(prog)s [OPTION...] [FILE...]')
argparser.add_argument('-V', '--version', action='version', version='@setzer_version@')
argparser.add_argument('-c', '--config', help='JSON config file for keybinds')
argparser.add_argument('file', nargs='*', help=argparse.SUPPRESS)
argparser.parse_args()
args, unknown = argparser.parse_known_args()

if args.config:
ServiceLocator.set_keymap_config_path(args.config)

new_argv = [sys.argv[0]] + unknown + args.file

main_controller = MainApplicationController()
exit_status = main_controller.run(sys.argv)
exit_status = main_controller.run(new_argv)
sys.exit(exit_status)
7 changes: 7 additions & 0 deletions setzer/app/service_locator.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,18 @@ class ServiceLocator():
setzer_version = None
resources_path = None
app_icons_path = None
keymap_config_path = '/etc/setzer.config.json'
increments = dict()
regexes = dict()
source_language_manager = None
source_style_scheme_manager = None

def set_keymap_config_path(path):
ServiceLocator.keymap_config_path = path

def get_keymap_config_path():
return ServiceLocator.keymap_config_path

def set_main_window(main_window):
ServiceLocator.main_window = main_window

Expand Down
124 changes: 67 additions & 57 deletions setzer/dialogs/keyboard_shortcuts/keyboard_shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from gi.repository import Gtk

import os.path

from setzer.keyboard_shortcuts.keybind_parser import KeybindParser

class KeyboardShortcutsDialog(object):

Expand All @@ -30,93 +30,103 @@ def __init__(self, main_window):

data = list()

def add_item(section, title, action_name, category=None):
shortcut_array = KeybindParser.get_shortcut(action_name, category)
if shortcut_array:
shortcut = KeybindParser.to_gtk_display(shortcut_array)
section['items'].append({'title': title, 'shortcut': shortcut})

section = {'title': _('Documents'), 'items': list()}
section['items'].append({'title': _('Create new document'), 'shortcut': '<ctrl>N'})
section['items'].append({'title': _('Open a document'), 'shortcut': '<ctrl>O'})
section['items'].append({'title': _('Show recent documents'), 'shortcut': '<ctrl><shift>O'})
section['items'].append({'title': _('Show open documents'), 'shortcut': '<ctrl>T'})
section['items'].append({'title': _('Switch to the next open document'), 'shortcut': '<ctrl>Tab'})
section['items'].append({'title': _('Save the current document'), 'shortcut': '<ctrl>S'})
section['items'].append({'title': _('Save the document with a new filename'), 'shortcut': '<ctrl><shift>S'})
section['items'].append({'title': _('Close the current document'), 'shortcut': '<ctrl>W'})
add_item(section, _('Create new document'), 'new-latex-document', 'app')
add_item(section, _('Open a document'), 'open-document-dialog', 'app')
add_item(section, _('Show recent documents'), 'shortcut_show_document_chooser', 'app')
add_item(section, _('Show open documents'), 'shortcut_show_open_docs', 'app')
add_item(section, _('Switch to the next open document'), 'shortcut_switch_document', 'app')
add_item(section, _('Save the current document'), 'save', 'app')
add_item(section, _('Save the document with a new filename'), 'save-as', 'app')
add_item(section, _('Close the current document'), 'close-active-document', 'app')
data.append(section)

section = {'title': _('Tools'), 'items': list()}
section['items'].append({'title': _('Save and build .pdf-file from document'), 'shortcut': 'F5'})
section['items'].append({'title': _('Build .pdf-file from document'), 'shortcut': 'F6'})
section['items'].append({'title': _('Show current position in preview'), 'shortcut': 'F7'})
add_item(section, _('Save and build .pdf-file from document'), 'save-and-build', 'app')
add_item(section, _('Build .pdf-file from document'), 'build', 'app')
add_item(section, _('Show current position in preview'), 'forward-sync', 'app')
data.append(section)

section = {'title': 'Windows and Panels', 'items': list()}
section['items'].append({'title': _('Show help panel'), 'shortcut': 'F1'})
section['items'].append({'title': _('Show build log'), 'shortcut': 'F8'})
section['items'].append({'title': _('Show preview panel'), 'shortcut': 'F9'})
section['items'].append({'title': _('Show global menu'), 'shortcut': 'F10'})
section['items'].append({'title': _('Show context menu'), 'shortcut': 'F12'})
section['items'].append({'title': _('Show keyboard shortcuts'), 'shortcut': '<ctrl>question'})
section['items'].append({'title': _('Close Application'), 'shortcut': '<ctrl>Q'})
add_item(section, _('Show help panel'), 'shortcut_help', 'app')
add_item(section, _('Show document structure'), 'shortcut_document_structure_toggle', 'app')
add_item(section, _('Show symbols'), 'shortcut_symbols_toggle', 'app')
add_item(section, _('Show build log'), 'shortcut_build_log', 'app')
add_item(section, _('Show preview panel'), 'shortcut_preview', 'app')
add_item(section, _('Show global menu'), 'shortcut_show_hamburger', 'app')
add_item(section, _('Show context menu'), 'show-context-menu', 'document')
add_item(section, _('Show keyboard shortcuts'), 'show-shortcuts-dialog', 'app')
add_item(section, _('Close Application'), 'quit', 'app')
data.append(section)

section = {'title': _('Find and Replace'), 'items': list()}
section['items'].append({'title': _('Find'), 'shortcut': '<ctrl>F'})
section['items'].append({'title': _('Find the next match'), 'shortcut': '<ctrl>G'})
section['items'].append({'title': _('Find the previous match'), 'shortcut': '<ctrl><shift>G'})
section['items'].append({'title': _('Find and Replace'), 'shortcut': '<ctrl>H'})
add_item(section, _('Find'), 'start-search', 'app')
add_item(section, _('Find the next match'), 'search-next', 'document')
add_item(section, _('Find the previous match'), 'search-previous', 'document')
add_item(section, _('Find and Replace'), 'start-search-and-replace', 'app')
data.append(section)

section = {'title': _('Zoom'), 'items': list()}
section['items'].append({'title': _('Zoom in'), 'shortcut': '<ctrl>plus'})
section['items'].append({'title': _('Zoom out'), 'shortcut': '<ctrl>minus'})
section['items'].append({'title': _('Reset zoom'), 'shortcut': '<ctrl>0'})
add_item(section, _('Zoom in'), 'zoom-in', 'app')
add_item(section, _('Zoom out'), 'zoom-out', 'app')
add_item(section, _('Reset zoom'), 'reset-zoom', 'app')
data.append(section)

section = {'title': 'Copy and Paste', 'items': list()}
section['items'].append({'title': _('Copy selected text to clipboard'), 'shortcut': '<ctrl>C'})
section['items'].append({'title': _('Cut selected text to clipboard'), 'shortcut': '<ctrl>X'})
section['items'].append({'title': _('Paste text from clipboard'), 'shortcut': '<ctrl>V'})
add_item(section, _('Copy selected text to clipboard'), 'copy', 'document')
add_item(section, _('Cut selected text to clipboard'), 'cut', 'document')
add_item(section, _('Paste text from clipboard'), 'paste', 'document')
data.append(section)

section = {'title': _('Undo and Redo'), 'items': list()}
section['items'].append({'title': _('Undo previous text edit'), 'shortcut': '<ctrl>Z'})
section['items'].append({'title': _('Redo previous text edit'), 'shortcut': '<ctrl><shift>Z'})
add_item(section, _('Undo previous text edit'), 'undo', 'document')
add_item(section, _('Redo previous text edit'), 'redo', 'document')
data.append(section)

section = {'title': _('Selection'), 'items': list()}
section['items'].append({'title': _('Select all text'), 'shortcut': '<ctrl>A'})
add_item(section, _('Select all text'), 'select-all', 'document')
data.append(section)

section = {'title': _('Editing'), 'items': list()}
section['items'].append({'title': _('Toggle insert / overwrite'), 'shortcut': 'Insert'})
section['items'].append({'title': _('Move current line up'), 'shortcut': '<Alt>Up'})
section['items'].append({'title': _('Move current line down'), 'shortcut': '<Alt>Down'})
section['items'].append({'title': _('Move current word left'), 'shortcut': '<Alt>Left'})
section['items'].append({'title': _('Move current word right'), 'shortcut': '<Alt>Right'})
section['items'].append({'title': _('Increment number at cursor'), 'shortcut': '<ctrl><shift>A'})
section['items'].append({'title': _('Decrement number at cursor'), 'shortcut': '<ctrl><shift>X'})
add_item(section, _('Toggle insert / overwrite'), 'toggle-insert', 'document')
add_item(section, _('Move current line up'), 'move-line-up', 'document')
add_item(section, _('Move current line down'), 'move-line-down', 'document')
add_item(section, _('Move current word left'), 'move-word-left', 'document')
add_item(section, _('Move current word right'), 'move-word-right', 'document')
add_item(section, _('Select next placeholder'), 'select-next-placeholder', 'document')
add_item(section, _('Select previous placeholder'), 'select-previous-placeholder', 'document')
add_item(section, _('Increment number at cursor'), 'increment-number', 'document')
add_item(section, _('Decrement number at cursor'), 'decrement-number', 'document')
data.append(section)

section = {'title': _('LaTeX Shortcuts'), 'items': list()}
section['items'].append({'title': _('Comment / Uncomment current line(s)'), 'shortcut': '<ctrl>K'})
section['items'].append({'title': _('New Line') + ' (\\\\)', 'shortcut': '<ctrl>Return'})
section['items'].append({'title': _('Bold Text'), 'shortcut': '<ctrl>B'})
section['items'].append({'title': _('Italic Text'), 'shortcut': '<ctrl>I'})
section['items'].append({'title': _('Underlined Text'), 'shortcut': '<ctrl>U'})
section['items'].append({'title': _('Typewriter Text'), 'shortcut': '<ctrl><shift>T'})
section['items'].append({'title': _('Emphasized Text'), 'shortcut': '<ctrl><shift>E'})
section['items'].append({'title': _('Quotation Marks'), 'shortcut': '<ctrl>quotedbl'})
section['items'].append({'title': _('List Item'), 'shortcut': '<ctrl><shift>I'})
section['items'].append({'title': _('Environment'), 'shortcut': '<ctrl>E'})
add_item(section, _('Comment / Uncomment current line(s)'), 'toggle-comment', 'latex')
add_item(section, _('Quotation Marks'), 'shortcut_quotes', 'latex')
add_item(section, _('New Line') + ' (\\\\)', '\\\\\\\\\\n', 'latex-symbol')
add_item(section, _('Bold Text'), '\\\\textbf{@@}', 'latex-before-after')
add_item(section, _('Italic Text'), '\\\\textit{@@}', 'latex-before-after')
add_item(section, _('Underlined Text'), '\\\\underline{@@}', 'latex-before-after')
add_item(section, _('Typewriter Text'), '\\\\texttt{@@}', 'latex-before-after')
add_item(section, _('Emphasized Text'), '\\\\emph{@@}', 'latex-before-after')
add_item(section, _('List Item'), '\\\\item •', 'latex-symbol')
add_item(section, _('Environment'), '\\\\begin{•}\\n\\t@@\\n\\\\end{•}', 'latex-before-after')
data.append(section)

section = {'title': _('Math Shortcuts'), 'items': list()}
section['items'].append({'title': _('Inline Math Section'), 'shortcut': '<ctrl>M'})
section['items'].append({'title': _('Display Math Section'), 'shortcut': '<ctrl><shift>M'})
section['items'].append({'title': _('Equation'), 'shortcut': '<ctrl><shift>N'})
section['items'].append({'title': _('Subscript'), 'shortcut': '<ctrl><shift>D'})
section['items'].append({'title': _('Superscript'), 'shortcut': '<ctrl><shift>U'})
section['items'].append({'title': _('Fraction'), 'shortcut': '<alt><shift>F'})
section['items'].append({'title': '\\left', 'shortcut': '<ctrl><shift>L'})
section['items'].append({'title': '\\right', 'shortcut': '<ctrl><shift>R'})
add_item(section, _('Inline Math Section'), '$ @@ $', 'latex-before-after')
add_item(section, _('Display Math Section'), '\\\\[ @@ \\\\]', 'latex-before-after')
add_item(section, _('Equation'), '\\\\begin{equation}\\n\\t@@\\n\\\\end{equation}', 'latex-before-after')
add_item(section, _('Subscript'), '_{@@}', 'latex-before-after')
add_item(section, _('Superscript'), '^{@@}', 'latex-before-after')
add_item(section, _('Fraction'), '\\\\frac{•}{•}', 'latex-symbol')
add_item(section, '\\left', '\\\\left •', 'latex-symbol')
add_item(section, '\\right', '\\\\right •', 'latex-symbol')
data.append(section)

self.data = data
Expand Down
4 changes: 3 additions & 1 deletion setzer/document/build_widget/build_widget_viewgtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import gi
gi.require_version('Gtk', '4.0')
from gi.repository import Gtk, GObject
from setzer.keyboard_shortcuts.keybind_parser import KeybindParser


class BuildWidgetView(Gtk.Box):
Expand All @@ -34,7 +35,8 @@ def __init__(self):

self.build_button = Gtk.Button()
self.build_button.set_child(Gtk.Image.new_from_icon_name('builder-build-symbolic'))
self.build_button.set_tooltip_text(_('Save and build .pdf-file from document') + ' (F5)')
build_shortcut = KeybindParser.to_display(KeybindParser.get_shortcut('save-and-build', 'app'))
self.build_button.set_tooltip_text(_('Save and build .pdf-file from document') + ' (' + build_shortcut + ')')
self.build_button.set_action_name('win.save-and-build')

self.stop_button = Gtk.Button()
Expand Down
11 changes: 1 addition & 10 deletions setzer/document/document_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,8 @@ def on_secondary_buttonpress(self, controller, n_press, x, y):
def on_keypress(self, controller, keyval, keycode, state):
modifiers = Gtk.accelerator_get_default_mod_mask()

if keyval in [Gdk.keyval_from_name('Tab'), Gdk.keyval_from_name('ISO_Left_Tab')]:
if keyval in [Gdk.keyval_from_name('Tab')]:
if state & modifiers == 0:
self.document.select_next_placeholder()
if self.document.dot_selected():
return True

if not self.document.settings.get_value('preferences', 'tab_jump_brackets'): return False
chars_at_cursor = self.document.get_chars_at_cursor(2)
if chars_at_cursor in ['\\}', '\\)', '\\]']: forward_chars = 2
Expand All @@ -97,11 +93,6 @@ def on_keypress(self, controller, keyval, keycode, state):
self.document.source_buffer.place_cursor(insert_iter)
return True

if (state & modifiers, keyval) == (Gdk.ModifierType.SHIFT_MASK, Gdk.keyval_from_name('ISO_Left_Tab')):
self.document.select_previous_placeholder()
if self.document.dot_selected():
return True

return False

def on_scroll(self, controller, dx, dy):
Expand Down
7 changes: 5 additions & 2 deletions setzer/document/search/search_viewgtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from gi.repository import Gtk

from setzer.widgets.search_entry.search_entry import SearchEntry
from setzer.keyboard_shortcuts.keybind_parser import KeybindParser


class SearchBar(Gtk.Revealer):
Expand Down Expand Up @@ -51,10 +52,12 @@ def __init__(self):

self.prev_button = Gtk.Button.new_from_icon_name('go-up-symbolic')
self.prev_button.set_can_focus(False)
self.prev_button.set_tooltip_text(_('Previous result') + ' (Ctrl+Shift+G)')
prev_result_shortcut = KeybindParser.to_display(KeybindParser.get_shortcut('find-previous', 'app'))
self.prev_button.set_tooltip_text(_('Previous result') + ' (' + prev_result_shortcut + ')')
self.next_button = Gtk.Button.new_from_icon_name('go-down-symbolic')
self.next_button.set_can_focus(False)
self.next_button.set_tooltip_text(_('Next result') + ' (Ctrl+G)')
next_result_shortcut = KeybindParser.to_display(KeybindParser.get_shortcut('find-next', 'app'))
self.next_button.set_tooltip_text(_('Next result') + ' (' + next_result_shortcut + ')')
self.replace_button = Gtk.Button.new_with_label(_('Replace'))
self.replace_button.set_can_focus(False)
self.replace_button.set_tooltip_text(_('Replace selected result'))
Expand Down
Loading