def build_document_request(self, button_object=None): if self.document.filename == None: if DialogLocator.get_dialog('build_save').run(self.document): DialogLocator.get_dialog('save_document').run(self.document) else: return False if self.document.filename != None: self.document.build_and_forward_sync()
def build_document_request(self, button_object=None): if self.document.filename == None: if DialogLocator.get_dialog('build_save').run(self.document): DialogLocator.get_dialog('save_document').run(self.document) else: return False if self.document.filename != None: active_document = ServiceLocator.get_workspace( ).get_active_document() if active_document != None: self.document.build_system.build_and_forward_sync( active_document)
def on_save_all_clicked(self, action=None, parameter=None): active_document = self.workspace.get_active_document() return_to_active_document = False documents = self.workspace.get_unsaved_documents() if documents != None: for document in documents: if document.get_filename() == None: self.workspace.set_active_document(document) return_to_active_document = True DialogLocator.get_dialog('save_document').run(document) else: document.save_to_disk() if return_to_active_document == True: self.workspace.set_active_document(document)
def shortcut_open(self, accel_group=None, window=None, key=None, mask=None): filename = DialogLocator.get_dialog('open_document').run() self.workspace.open_document_by_filename(filename)
def on_doclist_close_clicked(self, button_object, document): if document.get_modified(): dialog = DialogLocator.get_dialog('close_confirmation') not_save_to_close = dialog.run([document])['not_save_to_close_documents'] if document not in not_save_to_close: self.workspace.remove_document(document) else: self.workspace.remove_document(document)
def save_date_loop(self): if self.document.filename == None: return True if self.document.save_date <= os.path.getmtime(self.document.filename) - 0.001: if DialogLocator.get_dialog('document_changed_on_disk').run(self.document): self.document.populate_from_filename() else: self.document.source_buffer.set_modified(False) self.document.update_save_date() return True
def on_replace_all_button_click(self, button_object=None): original = self.search_bar.entry.get_text() replacement = self.search_bar.replace_entry.get_text() number_of_occurrences = self.search_context.get_occurrences_count() if number_of_occurrences > 0: dialog = DialogLocator.get_dialog('replace_confirmation') if dialog.run(original, replacement, number_of_occurrences): self.search_context.replace_all(replacement, -1)
def on_close_document_clicked(self, action=None, parameter=None): document = self.workspace.get_active_document() if document.get_modified(): dialog = DialogLocator.get_dialog('close_confirmation') not_save_to_close = dialog.run([document])['not_save_to_close_documents'] if document not in not_save_to_close: self.workspace.remove_document(document) else: self.workspace.remove_document(document)
def save_date_loop(self): if self.document.filename == None: return True if self.document.deleted_on_disk_dialog_shown_after_last_save: return True if self.document.get_deleted_on_disk(): DialogLocator.get_dialog('document_deleted_on_disk').run( self.document) self.document.deleted_on_disk_dialog_shown_after_last_save = True self.document.source_buffer.set_modified(True) return True if self.document.get_changed_on_disk(): if DialogLocator.get_dialog('document_changed_on_disk').run( self.document): self.document.populate_from_filename() self.document.source_buffer.set_modified(False) else: self.document.source_buffer.set_modified(True) self.document.update_save_date() return True
def on_close_all_clicked(self, action=None, parameter=None): active_document = self.workspace.get_active_document() documents = self.workspace.get_all_documents() unsaved_documents = self.workspace.get_unsaved_documents() dialog = DialogLocator.get_dialog('close_confirmation') not_save_to_close_documents = dialog.run(unsaved_documents)['not_save_to_close_documents'] for document in documents: if document not in not_save_to_close_documents: self.workspace.remove_document(document)
def on_restore_session_clicked(self, action=None, parameter=None): parameter = parameter.unpack()[0] if parameter == '': filename = DialogLocator.get_dialog('open_session').run() if filename == None: return else: filename = parameter active_document = self.workspace.get_active_document() documents = self.workspace.get_all_documents() unsaved_documents = self.workspace.get_unsaved_documents() dialog = DialogLocator.get_dialog('close_confirmation') not_save_to_close_documents = dialog.run(unsaved_documents)['not_save_to_close_documents'] if len(not_save_to_close_documents) == 0: if documents != None: for document in documents: self.workspace.remove_document(document) self.workspace.load_documents_from_session_file(filename)
def start_spellchecking_dialog(self, action, parameter=None): DialogLocator.get_dialog('spellchecking').run()
def show_about_dialog(self, action, parameter=''): DialogLocator.get_dialog('about').run()
def show_preferences_dialog(self, action=None, parameter=''): DialogLocator.get_dialog('preferences').run()
def show_shortcuts_window(self, action, parameter=''): DialogLocator.get_dialog('keyboard_shortcuts').run()
def start_search_online_for_bibtex_entries_dialog(self, action, parameter=None): document = self.workspace.get_active_document() DialogLocator.get_dialog('bibtex_wizard').run('search_online', document)
def start_show_previous_bibtex_entries_dialog(self, action, parameter=None): document = self.workspace.get_active_document() DialogLocator.get_dialog('bibtex_wizard').run('previous_entries', document)
def on_save_session_clicked(self, action=None, parameter=None): DialogLocator.get_dialog('save_session').run()
def start_add_remove_packages_dialog(self, action, parameter=None): document = self.workspace.get_active_document() DialogLocator.get_dialog('add_remove_packages').run(document)
def start_include_latex_file_dialog(self, action, parameter=None): document = self.workspace.get_active_document() DialogLocator.get_dialog('include_latex_file').run(document)
def on_open_document_dialog_action_activated(self, action=None, parameter=None): filename = DialogLocator.get_dialog('open_document').run() self.workspace.open_document_by_filename(filename)
def change_notification(self, change_code, notifying_object, parameter): if change_code == 'build_state_change' and parameter == 'ready_for_building': document = self.document mode = document.get_build_mode() filename = self.document.get_filename()[:] if mode in ['sync', 'build_and_sync']: insert = document.source_buffer.get_iter_at_mark( document.source_buffer.get_insert()) synctex_arguments = dict() synctex_arguments['line'] = insert.get_line() + 1 synctex_arguments['line_offset'] = insert.get_line_offset() + 1 if mode in ['build', 'build_and_sync']: interpreter = self.settings.get_value('preferences', 'latex_interpreter') build_option_system_commands = self.settings.get_value( 'preferences', 'build_option_system_commands') additional_arguments = '' lualatex_prefix = ' -' if interpreter == 'lualatex' else ' ' latexmk_prefix = ' -latexoption=' if interpreter == 'latexmk' else ' ' if build_option_system_commands == 'disable': additional_arguments += lualatex_prefix + '-no-shell-escape' elif build_option_system_commands == 'restricted': additional_arguments += lualatex_prefix + '-shell-restricted' elif build_option_system_commands == 'enable': additional_arguments += lualatex_prefix + '-shell-escape' buffer = document.get_buffer() if buffer != None: text = buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter(), True) else: text = '' do_cleanup = self.settings.get_value('preferences', 'cleanup_build_files') if mode == 'build': query = build_system.QueryBuild(text, filename, interpreter, additional_arguments, do_cleanup) elif mode == 'sync': if document.build_pathname != None: query = build_system.QuerySync(filename, document.build_pathname, synctex_arguments) else: query = build_system.QueryBuildAndSync(text, filename, interpreter, additional_arguments, do_cleanup, synctex_arguments) self.build_system.add_query(query) if change_code == 'build_state_change' and parameter == 'building_to_stop': self.build_system.stop_building() if change_code == 'building_started': self.document.change_build_state('building_in_progress') if change_code == 'reset_timer': self.document.build_widget.view.reset_timer() self.document.build_widget.view.label.set_text('0:00') if change_code == 'building_stopped': self.document.show_build_state('') self.document.change_build_state('idle') if change_code == 'building_finished': result_blob = parameter if result_blob['build'] != None: try: self.document.preview.set_pdf_filename( result_blob['build']['pdf_filename']) except KeyError: pass if result_blob['sync'] != None: self.document.preview.set_synctex_rectangles( result_blob['sync']) self.document.show_build_state('') if result_blob['build'] != None: build_blob = result_blob['build'] build_log_items = list() if build_blob['error'] == 'interpreter_missing': self.document.show_build_state('') self.document.change_build_state('idle') if DialogLocator.get_dialog('interpreter_missing').run( build_blob['error_arg']): DialogLocator.get_dialog('preferences').run() return if build_blob['error'] == 'interpreter_not_working': self.document.show_build_state('') self.document.change_build_state('idle') if DialogLocator.get_dialog('building_failed').run( build_blob['error_arg']): DialogLocator.get_dialog('preferences').run() return try: build_log_blob = build_blob['log_messages'] except KeyError: pass else: for item in build_log_blob: build_log_items.append(item) self.document.build_log_items = build_log_items self.document.build_time = time.time( ) - self.document.last_build_start_time error_count = 0 for item in self.document.build_log_items: if item[0] == 'Error': error_count += 1 if error_count > 0: error_color = helpers.theme_color_to_css( self.document.view.get_style_context(), 'error_color') message = '<span color="' + error_color + '">Failed</span> (' + str( error_count) + ' error' + ('s' if error_count > 1 else '') + ')!' self.document.show_build_state(message) else: self.document.show_build_state('Success!') self.document.set_build_pathname(build_blob['build_pathname']) self.document.has_been_built = True self.document.change_build_state('idle')
def on_open_document_button_click(self, button_object=None): filename = DialogLocator.get_dialog('open_document').run() self.workspace.open_document_by_filename(filename)
def start_create_new_bibtex_entry_dialog(self, action, parameter=None): document = self.workspace.get_active_document() DialogLocator.get_dialog('bibtex_wizard').run('new_entry', document)
def start_wizard(self, action, parameter=None): document = self.workspace.get_active_document() DialogLocator.get_dialog('document_wizard').run(document)
def on_save_as_clicked(self, action=None, parameter=None): document = self.workspace.get_active_document() DialogLocator.get_dialog('save_document').run(document)
def change_notification(self, change_code, notifying_object, parameter): if change_code == 'building_started': self.document.change_build_state('building_in_progress') if change_code == 'reset_timer': self.document.build_widget.view.reset_timer() self.document.build_widget.view.label.set_text('0:00') if change_code == 'building_stopped': self.document.show_build_state('') self.document.change_build_state('idle') if change_code == 'building_finished': result_blob = parameter if result_blob['build'] != None or result_blob[ 'forward_sync'] != None: if result_blob['build'] != None: try: self.document.preview.set_pdf_filename( result_blob['build']['pdf_filename']) except KeyError: pass if result_blob['forward_sync'] != None: self.document.preview.set_synctex_rectangles( result_blob['forward_sync']) self.document.show_build_state('') if result_blob['build'] != None: build_blob = result_blob['build'] if build_blob['error'] == 'interpreter_missing': self.document.show_build_state('') self.document.change_build_state('idle') if DialogLocator.get_dialog('interpreter_missing').run( build_blob['error_arg']): DialogLocator.get_dialog('preferences').run() return if build_blob['error'] == 'interpreter_not_working': self.document.show_build_state('') self.document.change_build_state('idle') if DialogLocator.get_dialog('building_failed').run( build_blob['error_arg']): DialogLocator.get_dialog('preferences').run() return self.document.set_build_log_items( build_blob['log_messages']) self.document.build_time = time.time( ) - self.document.last_build_start_time error_count = self.document.get_error_count() if error_count > 0: error_color_rgba = ServiceLocator.get_error_color() error_color = '#' + format( int(error_color_rgba.red * 255), '02x') + format( int(error_color_rgba.green * 255), '02x') + format( int(error_color_rgba.blue * 255), '02x') str_errors = ngettext( '<span color="{color}">Failed</span> ({amount} error)!', '<span color="{color}">Failed</span> ({amount} errors)!', error_count) message = str_errors.format(color=error_color, amount=str(error_count)) self.document.show_build_state(message) else: self.document.show_build_state(_('Success!')) self.document.set_has_synctex_file( build_blob['has_synctex_file']) self.document.has_been_built = True elif result_blob['backward_sync'] != None: self.document.set_synctex_position( result_blob['backward_sync']) self.document.change_build_state('idle') if result_blob['build'] != None: self.document.invalidate_build_log()
def change_notification(self, change_code, notifying_object, parameter): if change_code == 'build_state_change' and parameter == 'ready_for_building': document = self.document mode = document.get_build_mode() filename = self.document.get_filename()[:] if mode in ['forward_sync', 'build_and_forward_sync']: insert = document.source_buffer.get_iter_at_mark(document.source_buffer.get_insert()) synctex_arguments = dict() synctex_arguments['line'] = insert.get_line() + 1 synctex_arguments['line_offset'] = insert.get_line_offset() + 1 if mode in ['build', 'build_and_forward_sync']: interpreter = self.settings.get_value('preferences', 'latex_interpreter') use_latexmk = self.settings.get_value('preferences', 'use_latexmk') build_option_system_commands = self.settings.get_value('preferences', 'build_option_system_commands') additional_arguments = '' lualatex_prefix = ' -' if interpreter == 'lualatex' else ' ' if build_option_system_commands == 'disable': additional_arguments += lualatex_prefix + '-no-shell-escape' elif build_option_system_commands == 'restricted': additional_arguments += lualatex_prefix + '-shell-restricted' elif build_option_system_commands == 'enable': additional_arguments += lualatex_prefix + '-shell-escape' buffer = document.get_buffer() if buffer != None: text = buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter(), True) else: text = '' do_cleanup = self.settings.get_value('preferences', 'cleanup_build_files') if mode == 'build': query = build_system.QueryBuild(text, filename, interpreter, use_latexmk, additional_arguments, do_cleanup) elif mode == 'forward_sync': if document.build_pathname != None: query = build_system.QueryForwardSync(filename, document.build_pathname, synctex_arguments) elif mode == 'backward_sync': if document.backward_sync_data != None: query = build_system.QueryBackwardSync(filename, document.build_pathname, document.backward_sync_data) else: query = build_system.QueryBuildAndForwardSync(text, filename, interpreter, use_latexmk, additional_arguments, do_cleanup, synctex_arguments) self.build_system.add_query(query) if change_code == 'build_state_change' and parameter == 'building_to_stop': self.build_system.stop_building() if change_code == 'building_started': self.document.change_build_state('building_in_progress') if change_code == 'reset_timer': self.document.build_widget.view.reset_timer() self.document.build_widget.view.label.set_text('0:00') if change_code == 'building_stopped': self.document.show_build_state('') self.document.change_build_state('idle') if change_code == 'building_finished': result_blob = parameter if result_blob['build'] != None or result_blob['forward_sync'] != None: if result_blob['build'] != None: try: self.document.preview.set_pdf_filename(result_blob['build']['pdf_filename']) except KeyError: pass if result_blob['forward_sync'] != None: self.document.preview.set_synctex_rectangles(result_blob['forward_sync']) self.document.show_build_state('') if result_blob['build'] != None: build_blob = result_blob['build'] build_log_items = list() if build_blob['error'] == 'interpreter_missing': self.document.show_build_state('') self.document.change_build_state('idle') if DialogLocator.get_dialog('interpreter_missing').run(build_blob['error_arg']): DialogLocator.get_dialog('preferences').run() return if build_blob['error'] == 'interpreter_not_working': self.document.show_build_state('') self.document.change_build_state('idle') if DialogLocator.get_dialog('building_failed').run(build_blob['error_arg']): DialogLocator.get_dialog('preferences').run() return try: build_log_blob = build_blob['log_messages'] except KeyError: pass else: for item in build_log_blob: build_log_items.append(item) self.document.build_log_items = build_log_items self.document.build_time = time.time() - self.document.last_build_start_time error_count = 0 for item in self.document.build_log_items: if item[0] == 'Error': error_count += 1 if error_count > 0: error_color_rgba = ServiceLocator.get_error_color() error_color = '#' + format(int(error_color_rgba.red * 255), '02x') + format(int(error_color_rgba.green * 255), '02x') + format(int(error_color_rgba.blue * 255), '02x') str_errors = ngettext('<span color="{color}">Failed</span> ({amount} error)!', '<span color="{color}">Failed</span> ({amount} errors)!', error_count) message = str_errors.format(color=error_color, amount=str(error_count)) self.document.show_build_state(message) else: self.document.show_build_state(_('Success!')) self.document.set_build_pathname(build_blob['build_pathname']) self.document.has_been_built = True elif result_blob['backward_sync'] != None: self.document.set_synctex_position(result_blob['backward_sync']) self.document.change_build_state('idle')