Пример #1
0
 def focus_st(self):
     st_utils.focus_st()
Пример #2
0
    def run(self, edit, **args):
        # Check prefs for PDF focus and sync
        keep_focus = args.get('keep_focus', get_setting('keep_focus', True))
        forward_sync = args.get('forward_sync',
                                get_setting('forward_sync', True))

        # If invoked from keybinding, we sync
        # Rationale: if the user invokes the jump command, s/he wants to see the result of the compilation.
        # If the PDF viewer window is already visible, s/he probably wants to sync, or s/he would have no
        # need to invoke the command. And if it is not visible, the natural way to just bring up the
        # window without syncing is by using the system's window management shortcuts.
        # As for focusing, we honor the toggles / prefs.
        from_keybinding = args.pop("from_keybinding", False)
        if from_keybinding:
            forward_sync = True
        print(from_keybinding, keep_focus, forward_sync)

        if not is_tex_file(self.view.file_name()):
            sublime.error_message("%s is not a TeX source file: cannot jump." %
                                  (os.path.basename(view.fileName()), ))
            return

        root = getTeXRoot.get_tex_root(self.view)
        file_name = get_jobname(root)

        output_directory = get_output_directory(self.view)
        if output_directory is None:
            root = getTeXRoot.get_tex_root(self.view)
            pdffile = os.path.join(os.path.dirname(root), file_name + u'.pdf')
        else:
            pdffile = os.path.join(output_directory, file_name + u'.pdf')

            if not os.path.exists(pdffile):
                pdffile = os.path.join(os.path.dirname(root),
                                       file_name + u'.pdf')

        if not os.path.exists(pdffile):
            print("Expected PDF file {0} not found".format(pdffile))
            return

        pdffile = os.path.realpath(pdffile)

        (line, col) = self.view.rowcol(self.view.sel()[0].end())
        print("Jump to: ", line, col)
        # column is actually ignored up to 0.94
        # HACK? It seems we get better results incrementing line
        line += 1

        # issue #625: we need to pass the path to the file to the viewer when
        # there are files in subfolders of the main folder.
        # Thanks rstein and arahlin for this code!
        srcfile = self.view.file_name()

        try:
            viewer = get_viewer()
        except NoViewerException:
            return

        if forward_sync:
            try:
                viewer.forward_sync(pdffile,
                                    srcfile,
                                    line,
                                    col,
                                    keep_focus=keep_focus)
            except (AttributeError, NotImplementedError):
                try:
                    viewer.view_file(pdffile, keep_focus=keep_focus)
                except (AttributeError, NotImplementedError):
                    traceback.print_exc()
                    sublime.error_message(
                        'Viewer ' + viewer_name +
                        ' does not appear to be a proper LaTeXTools viewer plugin.'
                        + ' Please contact the plugin author.')
                    return
        else:
            try:
                viewer.view_file(pdffile, keep_focus=keep_focus)
            except (AttributeError, NotImplementedError):
                traceback.print_exc()
                sublime.error_message(
                    'Viewer ' + viewer_name +
                    ' does not appear to be a proper LaTeXTools viewer plugin.'
                    + ' Please contact the plugin author.')
                return

        if keep_focus:
            try:
                if viewer.supports_keep_focus():
                    return
            except (AttributeError, NotImplementedError):
                pass

            focus_st()
Пример #3
0
	def run(self, edit, **args):
		# Check prefs for PDF focus and sync
		keep_focus = args.get('keep_focus', get_setting('keep_focus', True))
		forward_sync = args.get('forward_sync', get_setting('forward_sync', True))

		# If invoked from keybinding, we sync
		# Rationale: if the user invokes the jump command, s/he wants to see
		# the result of the compilation.
		# If the PDF viewer window is already visible, s/he probably wants to
		# sync, or s/he would have no need to invoke the command. And if it is
		# not visible, the natural way to just bring up the window without
		# syncing is by using the system's window management shortcuts.
		# As for focusing, we honor the toggles / prefs.
		from_keybinding = args.pop("from_keybinding", False)
		if from_keybinding:
			forward_sync = True
		print(from_keybinding, keep_focus, forward_sync)

		view = self.view

		if not is_tex_file(view.file_name()):
			sublime.error_message(
				"%s is not a TeX source file: cannot jump." %
				(os.path.basename(view.fileName()),))
			return

		root = getTeXRoot.get_tex_root(view)
		file_name = get_jobname(root)

		output_directory = get_output_directory(view)
		if output_directory is None:
			pdffile = os.path.join(
				os.path.dirname(root),
				file_name + u'.pdf'
			)
		else:
			pdffile = os.path.join(
				output_directory,
				file_name + u'.pdf'
			)

			if not os.path.exists(pdffile):
				pdffile = os.path.join(
					os.path.dirname(root),
					file_name + u'.pdf'
				)

		if not os.path.exists(pdffile):
			print("Expected PDF file {0} not found".format(pdffile))
			return

		pdffile = os.path.realpath(pdffile)

		(line, col) = self.view.rowcol(self.view.sel()[0].end())
		print("Jump to: ", line, col)
		# column is actually ignored up to 0.94
		# HACK? It seems we get better results incrementing line
		line += 1

		# issue #625: we need to pass the path to the file to the viewer when
		# there are files in subfolders of the main folder.
		# Thanks rstein and arahlin for this code!
		srcfile = self.view.file_name()

		try:
			viewer = get_viewer()
		except NoViewerException:
			return

		if forward_sync:
			try:
				viewer.forward_sync(pdffile, srcfile, line, col, keep_focus=keep_focus)
			except (AttributeError, NotImplementedError):
				try:
					viewer.view_file(pdffile, keep_focus=keep_focus)
				except (AttributeError, NotImplementedError):
					traceback.print_exc()
					sublime.error_message(
						'Your viewer does not appear to be a proper'
						'LaTeXTools viewer plugin. '
						'Please contact the plugin author.')
					return
		else:
			try:
				viewer.view_file(pdffile, keep_focus=keep_focus)
			except (AttributeError, NotImplementedError):
				traceback.print_exc()
				sublime.error_message(
					'Your viewer does not appear to be a proper'
					'LaTeXTools viewer plugin. '
					'Please contact the plugin author.')
				return

		if keep_focus:
			try:
				if viewer.supports_keep_focus():
					return
			except (AttributeError, NotImplementedError):
				pass

			focus_st()
Пример #4
0
 def focus_st(self):
     st_utils.focus_st()