Skip to content

Commit

Permalink
refactoring, jump over more brackets with tab
Browse files Browse the repository at this point in the history
  • Loading branch information
cvfosammmm committed Mar 25, 2022
1 parent 0c7b554 commit f97e371
Show file tree
Hide file tree
Showing 14 changed files with 502 additions and 424 deletions.
6 changes: 0 additions & 6 deletions setzer/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,6 @@ def get_value(self, section, item):
self.set_value(section, item, value)
return value

def get_source_buffer_options(self):
buffer_options = dict()
buffer_options['tab_width'] = self.get_value('preferences', 'tab_width')
buffer_options['spaces_instead_of_tabs'] = self.get_value('preferences', 'spaces_instead_of_tabs')
return buffer_options

def set_value(self, section, item, value):
try: section_dict = self.data[section]
except KeyError:
Expand Down
4 changes: 3 additions & 1 deletion setzer/dialogs/bibtex_wizard/bibtex_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,9 @@ def insert_template(self, data=None):

text += '\n}\n\n'

self.document.content.insert_text(0, 0, text, False)
insert_iter = self.document.content.source_buffer.get_iter_at_line_offset(0, 0)
self.document.content.source_buffer.place_cursor(insert_iter)
self.document.content.insert_text_at_cursor_and_select_dot(text)
self.document.content.place_cursor(0)
self.document.content.scroll_cursor_onscreen()

Expand Down
47 changes: 46 additions & 1 deletion setzer/dialogs/document_wizard/document_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def run(self, document):

document_class = self.current_values['document_class']
template_start, template_end = eval('self.get_insert_text_' + document_class + '()')
self.document.content.insert_template(template_start, template_end)
self.insert_template(template_start, template_end)

self.view.dialog.hide()

Expand Down Expand Up @@ -363,4 +363,49 @@ def get_insert_packages(self):
text += '\\usepackage{' + package_name + '}\n'
return text

def insert_template(self, template_start, template_end):
buffer = self.document.content.source_buffer
buffer.begin_user_action()

bounds = buffer.get_bounds()
text = buffer.get_text(bounds[0], bounds[1], True)
line_count_before_insert = buffer.get_line_count()

# replace tabs with spaces, if set in preferences
if self.settings.get_value('preferences', 'spaces_instead_of_tabs'):
number_of_spaces = self.settings.get_value('preferences', 'tab_width')
template_start = template_start.replace('\t', ' ' * number_of_spaces)
template_end = template_end.replace('\t', ' ' * number_of_spaces)

bounds = buffer.get_bounds()
buffer.insert(bounds[0], template_start)
bounds = buffer.get_bounds()
buffer.insert(bounds[1], template_end)

bounds = buffer.get_bounds()
bounds[0].forward_chars(len(template_start))
buffer.place_cursor(bounds[0])

buffer.end_user_action()
buffer.begin_user_action()

if len(text.strip()) > 0:
note = _('''% NOTE: The content of your document has been commented out
% by the wizard. Just do a CTRL+Z (undo) to put it back in
% or remove the "%" before each line you want to keep.
% You can remove this note as well.
%
''')
note_len = len(note)
note_number_of_lines = note.count('\n')
offset = buffer.get_iter_at_mark(buffer.get_insert()).get_line()
buffer.insert(buffer.get_iter_at_line(offset), note)
for line_number in range(offset + note_number_of_lines, line_count_before_insert + offset + note_number_of_lines):
buffer.insert(buffer.get_iter_at_line(line_number), '% ')
insert_iter = buffer.get_iter_at_mark(buffer.get_insert())
insert_iter.backward_chars(note_len + 2)
buffer.place_cursor(insert_iter)

buffer.end_user_action()


2 changes: 1 addition & 1 deletion setzer/dialogs/include_latex_file/include_latex_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def get_display_filename(self):

def insert_template(self):
text = '\\input{' + self.get_display_filename() + '}'
self.document.content.insert_text_at_cursor(text)
self.document.content.insert_text_at_cursor_indent_and_select_dot(text)
self.document.content.scroll_cursor_onscreen()


Loading

0 comments on commit f97e371

Please sign in to comment.