def _restoreStep (self, step):
        #print "going to step: %s line %d col %d" % (step.doc.get_uri(), step.lineNo, step.colNo)
        self._btnBack.set_sensitive( self._history.canGoBack() )
        self._btnForward.set_sensitive( self._history.canGoForward() )

        newIter = step.doc.get_iter_at_line(step.lineNo)
        targetCol = min(step.colNo, newIter.get_chars_in_line() -1)
        newIter.forward_chars(targetCol)

        step.doc.place_cursor(newIter)

        self._window.set_active_tab(gedit.tab_get_from_document(step.doc))
        view = gedit.tab_get_from_document(step.doc).get_view()
        view.scroll_to_cursor()
Example #2
0
    def __openDocumentAtLine(self, filename, line, column):
        documents = self.window.get_documents()
        found = None
        for d in documents:
            if d.get_uri_for_display() == filename:
                found = d
                break

        # open an existing tab or create a new one
        if found is not None:
            tab = gedit.tab_get_from_document(found)
            self.window.set_active_tab(tab)
            doc = tab.get_document()
            doc.begin_user_action()
            it = doc.get_iter_at_line_offset(line - 1, column - 1)
            doc.place_cursor(it)
            (start, end) = doc.get_bounds()
            self.window.get_active_view().scroll_to_iter(end, 0.0)
            self.window.get_active_view().scroll_to_iter(it, 0.0)
            self.window.get_active_view().grab_focus()
            doc.end_user_action()
        else:
            uri = "file://" + filename
            tab = self.window.create_tab_from_uri(uri, self.encoding, line,
                                                  False, False)
            self.window.set_active_tab(tab)
Example #3
0
    def __openDocumentAtLine(self, filename, line, column):
        documents = self.window.get_documents()
        found = None
        for d in documents:
            if d.get_uri_for_display() == filename:
                found = d
                break

        # open an existing tab or create a new one
        if found is not None:
            tab = gedit.tab_get_from_document(found)
            self.window.set_active_tab(tab)
            doc = tab.get_document()
            doc.begin_user_action()
            it = doc.get_iter_at_line_offset(line-1,column-1)
            doc.place_cursor(it)
            (start, end) = doc.get_bounds()
            self.window.get_active_view().scroll_to_iter(end,0.0)
            self.window.get_active_view().scroll_to_iter(it,0.0)
            self.window.get_active_view().grab_focus()
            doc.end_user_action()
        else:
            uri = "file://"+ filename
            tab = self.window.create_tab_from_uri(uri,self.encoding,line,False,False)
            self.window.set_active_tab(tab)
Example #4
0
 def on_navigation_request(self, page, frame, request):
     file_uri = None
     uri = request.get_uri()
     gp =  self.mt.search(uri)
     if gp:
         file_uri = 'file:///%s' % gp.group('file')
         line_number = gp.group('line')
         if file_uri:
             # Test if document is not already open
             for doc in self.window.get_documents():
                 if doc.get_uri() == file_uri:
                     tab = gedit.tab_get_from_document(doc)
                     view = tab.get_view()
                     self.window.set_active_tab(tab)
                     doc.goto_line(int(line_number))
                     view.scroll_to_cursor()
                     self.todo_window.hide()
                     return 1
             # Document isn't open, create a new tab from uri
             self.window.create_tab_from_uri(file_uri,
                         gedit.encoding_get_current(),
                         int(line_number), False, True)
     else:
         print "(%s) not found" % file_uri
     self.todo_window.hide()
     return 1
Example #5
0
 def on_navigation_request(self, page, frame, request):
     file_uri = None
     uri = request.get_uri()
     gp =  self.mt.search(uri)
     if gp:
         file_uri = 'file:///%s' % gp.group('file')
         line_number = gp.group('line')
         if file_uri:
             # Test if document is not already open
             for doc in self.window.get_documents():
                 if doc.get_uri() == file_uri:
                     tab = gedit.tab_get_from_document(doc)
                     view = tab.get_view()
                     self.window.set_active_tab(tab)
                     doc.goto_line(int(line_number))
                     view.scroll_to_cursor()
                     self.todo_window.hide()
                     return 1
             # Document isn't open, create a new tab from uri
             self.window.create_tab_from_uri(file_uri,
                         gedit.encoding_get_current(),
                         int(line_number), False, True)
     else:
         print "(%s) not found" % file_uri
     self.todo_window.hide()
     return 1
Example #6
0
 def view_result(self, widget):
     # Get the selection object
     tree_selection = self.results_list.get_selection()
     
     # Get the model and iterator for the row selected
     (model, iterator) = tree_selection.get_selected()
     
     if (iterator):
         # Get the absolute path of the file
         absolute_path = model.get_value(iterator, 3)
         
         # Get the line number
         line_number = int(model.get_value(iterator, 2)) - 1
         
         # Get all open tabs
         documents = self.geditwindow.get_documents()
         
         # Loop through the tabs until we find which one matches the file
         # If we don't find it, we'll create it in a new tab afterwards.
         for each in documents:
         
             if (each.get_uri() != None and each.get_uri().replace("file://", "") == absolute_path):
                 # This sets the active tab to "each"
                 self.geditwindow.set_active_tab(gedit.tab_get_from_document(each))
                 each.goto_line(line_number)
                 
                 x = each.get_iter_at_line_offset(line_number, 0)
                 self.geditwindow.get_active_view().scroll_to_iter(x, 0.0, True)
                 
                 return
                 
         # If we got this far, then we didn't find the file open in a tab.
         # Thus, we'll want to go ahead and open it...
         self.geditwindow.create_tab_from_uri("file://" + absolute_path, self.encoding, int(model.get_value(iterator, 2)), False, True)
Example #7
0
def apply_settings_to_document(doc):
    lang = doc.get_language()
    if lang != None:
        view = gedit.tab_get_from_document(doc).get_view()
        lang_data = settings.get_lang_data(lang.get_id())
        view.set_tab_width(lang_data[0])
        view.set_insert_spaces_instead_of_tabs(bool(lang_data[1]))
    def __openDocumentAtLine(self, filename, line, column=1, register_history=True):
        """ open a the file specified by filename at the given line and column
        number. Line and column numbering starts at 1. """

        if line == 0 or column == 0:
            raise ValueError, "line and column numbers start at 1"

        documents = self._window.get_documents()
        found = None
        for d in documents:
            if d.get_uri() == filename:
                found = d
                break

        # open an existing tab or create a new one
        if found is not None:
            tab = gedit.tab_get_from_document(found)
            self._window.set_active_tab(tab)
            doc = tab.get_document()
            doc.begin_user_action()
            #it = doc.get_iter_at_line_offset(line-1,column-1)
            #doc.place_cursor(it)
            #(start, end) = doc.get_bounds()
            #self._window.get_active_view().scroll_to_iter(end,0.0)
            #self._window.get_active_view().scroll_to_iter(it,0.0)
            self._window.get_active_view().grab_focus()
            doc.end_user_action()
        else:
            tab = self._window.create_tab_from_uri(filename,self.encoding,line,False,False)
            self._window.set_active_tab(tab)
            found = self._window.get_active_document()
Example #9
0
	def on_row_activated(self, tw, path, col, window):
		it=self.model.get_iter(path)
		doc=self.model.get(it, 0)[0]
		if doc != None:
			tab = gedit.tab_get_from_document(doc)
			window.set_active_tab(tab)
		
		self.hide()
Example #10
0
 def switch_to_file(self, widget):
     tree_selection = self.treeview.get_selection()
     (model, iterator) = tree_selection.get_selected()
     if (model.get_value(iterator, 0) == "1"):
         documents = self.geditwindow.get_documents()
         for each in documents:
             if each.get_uri_for_display().rpartition('/'+self.DEFAULT_LANG+'/')[2] == model.get_value(iterator, 1):
                 self.geditwindow.set_active_tab(gedit.tab_get_from_document(each))
 def _open_file(self, uri):
     already_open = False
     for doc in self._window.get_documents():
         if doc.get_uri() == uri:
             self._window.set_active_tab(gedit.tab_get_from_document(doc))
             already_open = True
             break
     if not already_open:
         self._window.create_tab_from_uri(uri, None, 0, False, True)
Example #12
0
def save_document(window, gdoc, func):
    tab = gedit.tab_get_from_document(gdoc)
    if tab.get_state() != gedit.TAB_STATE_NORMAL:
        return
    def handler(*args):
        if tab.get_state() == gedit.TAB_STATE_NORMAL:
            tab.disconnect(gdoc.get_data("openplm_sig"))
            func()
    sig = tab.connect_after("notify::state", handler)
    gdoc.set_data("openplm_sig", sig)
    gedit.commands.save_document(window, gdoc)
Example #13
0
    def open_file(self, src):
        # First let's make sure the file exists.  If it doesn't exist,
        # prompt them for how to handle the missing file.
        if (not os.path.exists(src.replace("file://", "").replace("%20",
                                                                  " "))):
            result = self.ask_about_missing_file(src)

            return

        current_documents = self.window.get_documents()

        # Make sure the document isn't already open
        for each in current_documents:
            if (each.get_uri() == src):
                # If it's already open, then focus on that tab and return
                self.window.set_active_tab(gedit.tab_get_from_document(each))

                return

        # If it isn't already open, then let's see if we're on an unchanged, untitled
        # document.  If so, we'll close it and replace it...
        active_document = self.window.get_active_document()

        # Make sure there IS an active document!
        if (active_document):
            if (active_document.is_untouched()
                    and active_document.is_untitled()):
                self.window.close_tab(
                    gedit.tab_get_from_document(active_document))
                #active_document.load(src, self.encoding, 1, True)

                self.window.create_tab_from_uri(src, self.encoding, 0, True,
                                                True)

                return

        # If it isn't open, open it...
        self.window.create_tab_from_uri(src, self.encoding, 0, True, True)
Example #14
0
 def on_document_load(self, doc, *args):
     language = doc.get_language()
     if language:
         lang = language.get_id()
         if lang == 'ruby':
             uri = doc.get_uri_for_display()
             if self.get_in_rails(uri):
                 lang = gedit.get_language_manager().get_language('rubyonrails')
                 doc.set_language(lang)
                 # Uggly workarroud to call update_ui
                 view = gedit.tab_get_from_document(doc).get_view()
                 editable = view.get_editable()
                 view.set_editable(not editable)
                 view.set_editable(editable)
Example #15
0
 def on_document_load(self, doc, *args):
     language = doc.get_language()
     if language:
         lang = language.get_id()
         if lang == 'ruby':
             uri = doc.get_uri_for_display()
             if self.get_in_rails(uri):
                 lang = gedit.get_language_manager().get_language('rubyonrails')
                 doc.set_language(lang)
                 # Uggly workarroud to call update_ui
                 view = gedit.tab_get_from_document(doc).get_view()
                 editable = view.get_editable()
                 view.set_editable(not editable)
                 view.set_editable(editable)
Example #16
0
    def onDocumentOpenedCb(self, doScroll):
        currDoc = self._window.get_active_document()

        if doScroll:
            # workaround to scroll to cursor position when opening file into window of "Unnamed Document":
            currView = gedit.tab_get_from_document(currDoc).get_view()
            currView.scroll_to_cursor()

        # highlight matches in opened document:
        flags = 0
        if self.query.caseSensitive:
            flags |= 4
        if self.query.wholeWord:
            flags |= 2

        currDoc.set_search_text(self.query.text, flags)
        return False
Example #17
0
    def onDocumentOpenedCb(self, doScroll):
        currDoc = self._window.get_active_document()

        if doScroll:
            # workaround to scroll to cursor position when opening file into window of "Unnamed Document":
            currView = gedit.tab_get_from_document(currDoc).get_view()
            currView.scroll_to_cursor()

        # highlight matches in opened document:
        flags = 0
        if self.query.caseSensitive:
            flags |= 4
        if self.query.wholeWord:
            flags |= 2

        currDoc.set_search_text(self.query.text, flags)
        return False
Example #18
0
    def __openDocumentAtLine(self,
                             filename,
                             line,
                             column=1,
                             register_history=True):
        """ open a the file specified by filename at the given line and column
        number. Line and column numbering starts at 1. """

        if line == 0 or column == 0:
            raise ValueError, "line and column numbers start at 1"

        documents = self.geditwindow.get_documents()
        found = None
        for d in documents:
            if d.get_uri() == filename:
                found = d
                break

        # open an existing tab or create a new one
        if found is not None:
            tab = gedit.tab_get_from_document(found)
            self.geditwindow.set_active_tab(tab)
            doc = tab.get_document()
            doc.begin_user_action()
            it = doc.get_iter_at_line_offset(line - 1, column - 1)
            doc.place_cursor(it)
            (start, end) = doc.get_bounds()
            self.geditwindow.get_active_view().scroll_to_iter(end, 0.0)
            self.geditwindow.get_active_view().scroll_to_iter(it, 0.0)
            self.geditwindow.get_active_view().grab_focus()
            doc.end_user_action()
        else:
            tab = self.geditwindow.create_tab_from_uri(filename, self.encoding,
                                                       line, False, False)
            self.geditwindow.set_active_tab(tab)
            found = self.geditwindow.get_active_document()

        # place mark
        #it = found.get_iter_at_line(line-1)
        #mark = found.create_marker(None,"jumped_to",it)

        if register_history:
            self.document_history.append((filename, line, column))
            self.back.set_sensitive(True)
            self.forward.set_sensitive(False)
            self.history_pos += 1
    def __init__(self, plugin, window):
        #print "back-forward: plugin created for", window
        self._window = window
        self._plugin = plugin
        self.handlers = [] # list of (object, handlerId) tuples, for deactivate() method

        self._history = History()

        self._insert_toolbar_buttons()

        # register button-press handlers for all existing tabs
        for doc in self._window.get_documents():
            tab = gedit.tab_get_from_document(doc)
            self.onTabAdded(tab)

        handler = self._window.connect_object("tab-added", BFWindowHelper.onTabAdded, self)
        self.handlers.append( (self._window, handler) )
    def __tab_added(self, window, tab):
        """ Once a tab is created find the first *other* tab with an emtpy and 
            untouched file and kill it"""

        # find the empty tab
        from pprint import pprint
        for document in self.geditwindow.get_documents():
            if document.is_untitled() and document.is_untouched():
                empty_tab = gedit.tab_get_from_document(document)
                if not (empty_tab is tab):
                    # kill it
                    self.geditwindow.close_tab(empty_tab)

                    # once we've closed the annoying empty document, there's no use
                    # in handling the event anymore
                    self.geditwindow.disconnect(self._signal)
                    self._signal = None
                    break
    def __tab_added(self, window, tab):
        """ Once a tab is created find the first *other* tab with an emtpy and 
            untouched file and kill it"""

        # find the empty tab
        from pprint import pprint
        for document in self.geditwindow.get_documents():
            if document.is_untitled() and document.is_untouched():
                empty_tab = gedit.tab_get_from_document(document)
                if not (empty_tab is tab):
                    # kill it
                    self.geditwindow.close_tab(empty_tab)

                    # once we've closed the annoying empty document, there's no use
                    # in handling the event anymore
                    self.geditwindow.disconnect(self._signal)
                    self._signal = None
                    break
Example #22
0
	def _init_tab_decorators(self):
		"""
		Look for already open tabs and create decorators for them
		"""
		self._tab_decorators = {}
		self._active_tab_decorator = None
		active_view = self._window.get_active_view()
		views = self._window.get_views()

		for view in views:
			tab = gedit.tab_get_from_document(view.get_buffer())
			decorator = self._create_tab_decorator(tab, init=True)
			if view is active_view:
				self._active_tab_decorator = decorator
		
		self._log.debug("_init_tab_decorators: initialized %s decorators" % len(views))
		
		if len(views) > 0 and not self._active_tab_decorator:
			self._log.warning("_init_tab_decorators: no active decorator found")
Example #23
0
    def on_findResultTreeview_cursor_changed_action(self, object):
        model, it = object.get_selection().get_selected()
        if not it:
            return

        try:
            m = re.search('.+(<.+>)+([0-9]+)(<.+>)+.*', model.get_value(it, 1))
            line_num = int(m.group(2))
        except:
            return

        result_start = model.get_value(it, 4)
        result_len = model.get_value(it, 5)

        parent_it = model.iter_parent(it)
        if parent_it:
            uri = urllib.quote(model.get_value(parent_it,
                                               6).encode('utf-8')).replace(
                                                   '%3A//', '://')
            tab = model.get_value(parent_it, 3)
        else:
            return

        # Tab wasn't passed, try to find one
        if not tab:
            docs = self._window.get_documents()
            for doc in docs:
                if doc.get_uri() == uri:
                    tab = gedit.tab_get_from_document(doc)

        # Still nothing? Open the file then
        if not tab:
            tab = self._window.create_tab_from_uri(uri, None, line_num, False,
                                                   False)
            self.do_events()

        if tab:
            self._window.set_active_tab(tab)
            doc = tab.get_document()
            doc.select_range(doc.get_iter_at_offset(result_start),
                             doc.get_iter_at_offset(result_start + result_len))
            view = tab.get_view()
            view.scroll_to_cursor()
Example #24
0
 def open_file(self, widget, a, b):
     tree_selection = self.treeview.get_selection()
     (model, iterator) = tree_selection.get_selected()
     absolute_path = model.get_value(iterator, 1)
     if (model.get_value(iterator, 0) == "1"):
         documents = self.geditwindow.get_documents()
         for each in documents:
             if each.get_short_name_for_display() == model.get_value(iterator, 1):
                 self.geditwindow.set_active_tab(gedit.tab_get_from_document(each))
     elif (model.get_value(iterator, 0) == "-1"):
         None
     else:
         self.geditwindow.create_tab_from_uri("file://"+self.thepath+absolute_path, None, 1, False, True)
         self.treestore.set_value(iterator, 0, "1")
         self.treestore.set_value(iterator, 2, gtk.Window().render_icon(gtk.STOCK_EDIT, gtk.ICON_SIZE_MENU))
         self.open_files.append(iterator)
         buffer = self.geditwindow.get_active_view().get_buffer()
         language = gedit.language_manager_get_language_from_mime_type(self.language_manager, "application/docbook+xml")
         buffer.set_language(language)
Example #25
0
    def go_to_path(self, widget, path, column=None):
        it = self.browsermodel.get_iter(path)
        tok = self.browsermodel.get_value(it,0)

        # get the document
        if tok.pythonfile is None: doc = tok.doc
        else: doc = tok.pythonfile.doc

        # scroll to the correct position
        tab = gedit.tab_get_from_document(doc)
        self.geditwindow.set_active_tab(tab)
        doc.begin_user_action()
        it = doc.get_iter_at_line_offset(tok.start,0)
        doc.place_cursor(it)
        (start, end) = doc.get_bounds()
        self.geditwindow.get_active_view().scroll_to_iter(end,0.0)
        self.geditwindow.get_active_view().scroll_to_iter(it,0.0)
        self.geditwindow.get_active_view().grab_focus()
        doc.end_user_action()
Example #26
0
    def go_to_path(self, widget, path, column=None):
        it = self.browsermodel.get_iter(path)
        tok = self.browsermodel.get_value(it, 0)

        # get the document
        if tok.pythonfile is None: doc = tok.doc
        else: doc = tok.pythonfile.doc

        # scroll to the correct position
        tab = gedit.tab_get_from_document(doc)
        self.geditwindow.set_active_tab(tab)
        doc.begin_user_action()
        it = doc.get_iter_at_line_offset(tok.start, 0)
        doc.place_cursor(it)
        (start, end) = doc.get_bounds()
        self.geditwindow.get_active_view().scroll_to_iter(end, 0.0)
        self.geditwindow.get_active_view().scroll_to_iter(it, 0.0)
        self.geditwindow.get_active_view().grab_focus()
        doc.end_user_action()
Example #27
0
    def view_result(self, widget):
        # Get the selection object
        tree_selection = self.results_list.get_selection()

        # Get the model and iterator for the row selected
        (model, iterator) = tree_selection.get_selected()

        if (iterator):
            # Get the absolute path of the file
            absolute_path = model.get_value(iterator, 3)

            # Get the line number
            line_number = int(model.get_value(iterator, 2)) - 1

            # Get all open tabs
            documents = self.geditwindow.get_documents()

            # Loop through the tabs until we find which one matches the file
            # If we don't find it, we'll create it in a new tab afterwards.
            for each in documents:

                if (each.get_uri().replace("file://", "") == absolute_path):
                    # This sets the active tab to "each"
                    self.geditwindow.set_active_tab(
                        gedit.tab_get_from_document(each))
                    each.goto_line(line_number)

                    # Get the bounds of the document
                    (start, end) = each.get_bounds()

                    self.geditwindow.get_active_view().scroll_to_iter(end, 0.0)

                    x = each.get_iter_at_line_offset(line_number, 0)
                    self.geditwindow.get_active_view().scroll_to_iter(x, 0.0)

                    return

            # If we got this far, then we didn't find the file open in a tab.
            # Thus, we'll want to go ahead and open it...
            self.geditwindow.create_tab_from_uri(
                "file://" + absolute_path, self.encoding,
                int(model.get_value(iterator, 2)), False, True)
Example #28
0
	def on_findResultTreeview_cursor_changed_action(self, object):
		model, it = object.get_selection().get_selected()
		if not it:
			return
		
		try:
			line = int(model.get_value(it, 1)[5:-2])
		except:
			return
		
		tab = model.get_value(it, 3)
		result_start = model.get_value(it, 4)
		result_len = model.get_value(it, 5)
		#uri = model.get_value(it, 6)
		
		parent_it = model.iter_parent(it)
		if parent_it:
			uri = "file://" + urllib.pathname2url(model.get_value(parent_it, 6).encode('utf-8'))
		else:
			uri = ""
			
		if uri == "":
			return
		
		# Tab wasn't passed, try to find one		
		if not tab:
			for doc in self._window.get_documents():
				if doc.get_uri() == uri:
					tab = gedit.tab_get_from_document(doc)					
			
		# Still nothing? Open the file then
		if not tab:
			tab = self._window.create_tab_from_uri(uri, None, line, False, False)
			
		if tab:
			self._window.set_active_tab(tab)
			doc = tab.get_document()
			view = tab.get_view()
			if result_len > 0:
				doc.select_range(doc.get_iter_at_offset(result_start), doc.get_iter_at_offset(result_start + result_len))
			
			view.scroll_to_cursor()
Example #29
0
    def on_row_activated (self, widget, path, col):
        selectedIter = self.treeStore.get_iter(path)
        parentIter = self.treeStore.iter_parent(selectedIter)
        lineno = 0
        if parentIter == None:
            file = self.treeStore.get_value(selectedIter, 1)
        else:
            file = self.treeStore.get_value(parentIter, 1)
            lineno = self.treeStore.get_value(selectedIter, 2)

        if not(file):
            return

        uri="file://%s" % urllib.quote(file)
        gedit.commands.load_uri(window=self._window, uri=uri, line_pos=lineno)
        if lineno > 0: # this is necessary for Gedit 2.17.4 and older (see gbo #401219)
            currDoc = self._window.get_active_document()
            currDoc.goto_line(lineno - 1) # -1 required to work around gbo #503665
            currView = gedit.tab_get_from_document(currDoc).get_view()
            currView.scroll_to_cursor()
Example #30
0
    def on_row_activated (self, widget, path, col):
        selectedIter = self.treeStore.get_iter(path)
        parentIter = self.treeStore.iter_parent(selectedIter)
        lineno = 0
        if parentIter == None:
            file = self.treeStore.get_value(selectedIter, 1)
        else:
            file = self.treeStore.get_value(parentIter, 1)
            lineno = self.treeStore.get_value(selectedIter, 2)

        if not(file):
            return

        uri="file://%s" % urllib.quote(file)
        gedit.commands.load_uri(window=self._window, uri=uri, line_pos=lineno)
        if lineno > 0: # this is necessary for Gedit 2.17.4 and older (see gbo #401219)
            currDoc = self._window.get_active_document()
            currDoc.goto_line(lineno - 1) # -1 required to work around gbo #503665
            currView = gedit.tab_get_from_document(currDoc).get_view()
            currView.scroll_to_cursor()
Example #31
0
	def activate(self, window):
		"""Activate plugin."""
		self.window = window
		self.tip = AutoCompleteWindowHelper(window)

		l_ids = []
		for signal in ('tab-added', 'tab-removed'):
			method = getattr(self, 'on_window_' + signal.replace('-', '_'))
			l_ids.append(window.connect(signal, method))
		window.set_data(self.id_name, l_ids)

		for view in window.get_views():
			self.connect_view(view)

		for doc in window.get_documents():
			# configure tabs already displayed
			self.configure_tab(window, gedit.tab_get_from_document(doc))
			# connect doc and scan
			self.connect_document(doc)
			self.scan(doc)
Example #32
0
 def old_get_tab_from_uri(self, window, uri):
     docs = window.get_documents()
     for doc in docs:
         if doc.get_uri() == uri:
             return gedit.tab_get_from_document(doc)
     return None
	def advanced_find_all_in_doc(self, parent_it, doc, search_pattern, options, replace_flg = False, selection_only = False):
		if search_pattern == "":
			return
		
		regex = self.create_regex(search_pattern, options)

		self.result_highlight_off(doc)
		start, end = doc.get_bounds()
		text = unicode(doc.get_text(start, end), 'utf-8')
		
		start_pos = 0
		end_pos = end.get_offset()
		if selection_only == True:
			sel_start, sel_end = doc.get_selection_bounds()
			if sel_start:
				start_pos = sel_start.get_offset()
			if sel_end:
				end_pos = sel_end.get_offset()

		tree_it = None
		match = regex.search(text, start_pos, end_pos)
		if match:
			if not tree_it:
				doc_uri = doc.get_uri()
				if doc_uri == None:
					uri = ''
				else:
					uri = urllib.unquote(doc.get_uri()).decode('utf-8')
				tree_it = self._results_view.append_find_result_filename(parent_it, doc.get_short_name_for_display(), uri)
			tab = gedit.tab_get_from_document(doc)

			if replace_flg == False:
				while(match):
					line_num = doc.get_iter_at_offset(match.start()).get_line()
					line_start_pos = doc.get_iter_at_line(line_num).get_offset()
					line_end_pos = doc.get_iter_at_line(doc.get_iter_at_offset(match.end()).get_line()+1).get_offset()
					if line_end_pos == line_start_pos:
						line_end_pos = end_pos
					line_text = text[line_start_pos:line_end_pos]
					self._results_view.append_find_result(tree_it, str(line_num+1), line_text, tab, match.start(), match.end()-match.start(), "", line_start_pos)
					start_pos = match.end() + 1
					match = regex.search(text, start_pos, end_pos)
			else:
				results = []
				replace_offset = 0
				doc.begin_user_action()
				while(match):
					if options['REGEX_SEARCH'] == False:
						replace_text = unicode(self.find_ui.replaceTextEntry.get_active_text(), 'utf-8')
					else:
						replace_text = match.expand(unicode(self.find_ui.replaceTextEntry.get_active_text(), 'utf-8'))
					replace_start_pos = match.start() + replace_offset
					replace_end_pos = match.end() + replace_offset
					replace_start = doc.get_iter_at_offset(replace_start_pos)
					replace_end = doc.get_iter_at_offset(replace_end_pos)
					doc.delete(replace_start, replace_end)
					doc.insert(replace_start, replace_text)
					replace_text_len = len(replace_text)
					results.append([replace_start_pos, replace_text_len])
					replace_offset += replace_text_len - (match.end() - match.start())
					start_pos = match.end() + 1
					match = regex.search(text, start_pos, end_pos)
				doc.end_user_action()
				
				start, end = doc.get_bounds()
				text = unicode(doc.get_text(start, end), 'utf-8')

				for result in results:
					line_num = doc.get_iter_at_offset(result[0]).get_line()
					line_start_pos = doc.get_iter_at_line(line_num).get_offset()
					line_end_pos = result[0]+result[1]
					line_text = text[line_start_pos:line_end_pos]
					self._results_view.append_find_result(tree_it, str(line_num+1), line_text, tab, result[0], result[1], "", line_start_pos, True)
			
		self.result_highlight_on(tree_it)
def find_file_from_error(mrplugin, error_iter, can_msgbox = True):
    
    # error_iter = iter do objeto 'storeOutput'
    #
    
    arq = mrplugin.storeOutput.get_value( error_iter, 0 )
    linha = mrplugin.storeOutput.get_value( error_iter, 1 ) - 1

    arq_full = os.path.abspath( os.path.join( mrplugin.get_src().get_dir(), arq ) )
    arq_full_uri = gio.File( arq_full ).get_uri()

    # procura o documento aberto no gedit que possa ter o mesmo
    # uri que o arquivo indicado no erro relatado.
    #
    for d in mrplugin.window.get_documents():
        doc_arq_uri = d.get_uri()
        
        if arq_full_uri == doc_arq_uri:
        
            # define um novo 'active_document' 
            #
            tab = gedit.tab_get_from_document( d )
            mrplugin.window.set_active_tab( tab )
            
            mrplugin.get_src().remove_error()
            mrplugin.get_src().mark_error( linha )
            
            return

    # já que não achou um URI completo, procura um documento aberto
    # no gedit que possa ter pelo menos o mesmo basename (ex.: a.c).
    #
    arq_basename = os.path.basename( gio.File( arq_full ).get_path() )
    
    for d in mrplugin.window.get_documents():
        doc_arq_basename = os.path.basename( gio.File( d.get_uri() ).get_path() )
        
        if arq_basename == doc_arq_basename:
        
            # define um novo 'active_document' 
            #
            tab = gedit.tab_get_from_document( d )
            mrplugin.window.set_active_tab( tab )
            
            mrplugin.get_src().remove_error()
            mrplugin.get_src().mark_error( linha )
            
            return
            
    # chegou aqui? entao nao achou o arquivo aberto no gedit.
    # tenta abrir entao..
        
    if not os.path.exists( arq_full ):
        if can_msgbox:
            msgbox( "Ir para linha do erro", \
                "O arquivo indicado nessa linha do erro não foi encontrado." + \
                "\n\n" + \
                "<small><b>Arquivo buscado:</b> " + arq_full + " </small>", \
                "warning" \
            )
            
        return
    
    #arq_uri = "file://" + arq_full
    arq_uri = gio.File( arq_full ).get_uri()
    
    new_tab = mrplugin.window.create_tab_from_uri(
        uri = arq_uri,
        encoding = gedit.encoding_get_current(),
        line_pos = linha,
        create = False,
        jump_to = True
    )
    
    # pra variar, mais outro esquema do gedit que eh assincrono,
    # isto eh, a criacao de tabs (acima) vai emitir signals e etc.
    #
    # pra continuar o codigo supondo que tudo isso ja foi processado,
    # devemos rodar varias iteracoes do looping do gtk.
    #
    # sem fazer isso, os comandos em seguida (get_src().mark_error
    # etc.) nao funcionarao adequadamente.
    #
    while gtk.events_pending():
        gtk.main_iteration( block=False )
    
    # com a nova tab ativada, o 'active_document' muda.
    # assim, fazemos get_src() pra ativar o erro nele.
    #
    mrplugin.get_src().remove_error()
    mrplugin.get_src().mark_error( linha )
	def old_get_tab_from_uri(self, window, uri):
		docs = window.get_documents()
		for doc in docs:
			if doc.get_uri() == uri:
				return gedit.tab_get_from_document(doc)
		return None
Example #36
0
	def advanced_find_all_in_doc(self, parent_it, doc, search_pattern, options, replace_flg = False, selection_only = False):
		if search_pattern == "":
			return
		
		regex = self.create_regex(search_pattern, options)

		self.result_highlight_off(doc)
		start, end = doc.get_bounds()
		text = unicode(doc.get_text(start, end), 'utf-8')
		
		if selection_only == False:
			lines = text.splitlines(True)
			line_number_offset = 1
		else:
			selection_start, selection_end = doc.get_selection_bounds()
			selection_text = unicode(doc.get_text(selection_start, selection_end), 'utf-8')
			lines= selection_text.splitlines(True)
			line_start_offset = selection_start.get_offset()
			#print line_start_offset
			line_number_offset = selection_start.get_line() + 1
			#print line_number_offset

		tree_it = None
		new_text = list(text)
		text_changed = False
		replace_cnt = 0

		for i in range(len(lines)):
			results = regex.findall(lines[i])
			if selection_only == False:
				line_start = doc.get_iter_at_line(i)
			else:
				if i > 0:
					line_start_offset += len(lines[i-1])
				#print line_start_offset
				line_start = doc.get_iter_at_offset(line_start_offset)
				
			if results:
				if not tree_it:
					doc_uri = doc.get_uri()
					if doc_uri == None:
						uri = ''
					else:
						uri = urllib.unquote(doc.get_uri()[7:]).decode('utf-8')
					tree_it = self._results_view.append_find_result_filename(parent_it, doc.get_short_name_for_display(), uri)
				tab = gedit.tab_get_from_document(doc)

				match_pos = 0
				for cnt in range(0, len(results)):
					match = regex.search(lines[i][match_pos:])
					result_offset_start = line_start.get_offset() + match.start() + match_pos
					result_len = len(match.group(0))
					if options['REGEX_SEARCH'] == False:
						replace_text = unicode(self.find_dialog.replaceTextEntry.get_active_text(), 'utf-8')
					else:
						replace_text = match.expand(unicode(self.find_dialog.replaceTextEntry.get_active_text(), 'utf-8'))
					replace_text_len = len(replace_text)
					replace_offset = result_len - replace_text_len
					
					if replace_flg == True:
						self._results_view.append_find_result(tree_it, str(line_number_offset + i), lines[i].strip(), tab, result_offset_start - (replace_offset * replace_cnt), replace_text_len)
						replace_start_idx = result_offset_start - (replace_offset * replace_cnt)
						new_text[replace_start_idx:replace_start_idx + result_len] = replace_text
						replace_cnt += 1
						text_changed = True
					else:
						self._results_view.append_find_result(tree_it, str(line_number_offset + i), lines[i].strip(), tab, result_offset_start, result_len)
					match_pos += match.end()
				
		if text_changed == True:
			doc.set_text("".join(new_text))
			
		self.result_highlight_on(tree_it)
Example #37
0
    def advanced_find_all_in_doc(self,
                                 parent_it,
                                 doc,
                                 search_pattern,
                                 find_options,
                                 replace_flg=False,
                                 selection_only=False):
        if search_pattern == "":
            return

        regex = self.create_regex(search_pattern, find_options)

        self.result_highlight_off(doc)
        start, end = doc.get_bounds()
        text = unicode(doc.get_text(start, end), 'utf-8')

        start_pos = 0
        end_pos = end.get_offset()

        if selection_only == True:
            try:
                sel_start, sel_end = doc.get_selection_bounds()
            except:
                return

            if sel_start and sel_end:
                start_pos = sel_start.get_offset()
                end_pos = sel_end.get_offset()
            else:
                return

        tree_it = None
        match = regex.search(text, start_pos, end_pos)
        if match:
            if not tree_it:
                doc_uri = doc.get_uri()
                if doc_uri == None:
                    uri = ''
                else:
                    uri = urllib.unquote(doc.get_uri()).decode('utf-8')
                tab = gedit.tab_get_from_document(doc)
                tree_it = self._results_view.append_find_result_filename(
                    parent_it, doc.get_short_name_for_display(), tab, uri)

            if replace_flg == False:
                while (match):
                    line_num = doc.get_iter_at_offset(match.start()).get_line()
                    line_start_pos = doc.get_iter_at_line(
                        line_num).get_offset()
                    '''
					line_end_pos = doc.get_iter_at_line(doc.get_iter_at_offset(match.end()).get_line()+1).get_offset()
					if line_end_pos == line_start_pos:
						line_end_pos = end_pos
					#'''
                    match_end_line_cnt = doc.get_iter_at_offset(
                        match.end()).get_line() + 1
                    if match_end_line_cnt == doc.get_line_count():
                        line_end_pos = end_pos
                    else:
                        line_end_pos = doc.get_iter_at_line(
                            match_end_line_cnt).get_offset()
                    line_text = text[line_start_pos:line_end_pos]
                    self._results_view.append_find_result(
                        tree_it, str(line_num + 1), line_text, match.start(),
                        match.end() - match.start(), "", line_start_pos)
                    if match.start() == match.end():
                        start_pos = match.end() + 1
                    else:
                        start_pos = match.end()
                    if start_pos > end_pos:
                        #print 'EOF'
                        break
                    match = regex.search(text, start_pos, end_pos)
            else:
                results = []
                replace_offset = 0
                doc.begin_user_action()
                while (match):
                    if find_options['REGEX_SEARCH'] == False:
                        replace_text = unicode(
                            self.find_ui.replaceTextEntry.get_active_text(),
                            'utf-8')
                    else:
                        replace_text = match.expand(
                            unicode(
                                self.find_ui.replaceTextEntry.get_active_text(
                                ), 'utf-8'))
                    if match.start() == match.end():
                        break
                    replace_start_pos = match.start() + replace_offset
                    replace_end_pos = match.end() + replace_offset
                    replace_start = doc.get_iter_at_offset(replace_start_pos)
                    replace_end = doc.get_iter_at_offset(replace_end_pos)
                    doc.delete(replace_start, replace_end)
                    doc.insert(replace_start, replace_text)
                    replace_text_len = len(replace_text)
                    results.append([replace_start_pos, replace_text_len])
                    replace_offset += replace_text_len - (match.end() -
                                                          match.start())
                    start_pos = match.end()
                    if start_pos > end_pos:
                        #print 'EOF'
                        break
                    match = regex.search(text, start_pos, end_pos)
                doc.end_user_action()

                start, end = doc.get_bounds()
                text = unicode(doc.get_text(start, end), 'utf-8')

                for result in results:
                    line_num = doc.get_iter_at_offset(result[0]).get_line()
                    line_start_pos = doc.get_iter_at_line(
                        line_num).get_offset()
                    #line_end_pos = result[0]+result[1]
                    '''
					line_end_pos = doc.get_iter_at_line(doc.get_iter_at_offset(result[0]+result[1]).get_line()+1).get_offset()
					if line_end_pos == line_start_pos:
						line_end_pos = end_pos
					#'''
                    match_end_line_cnt = doc.get_iter_at_offset(
                        result[0] + result[1]).get_line() + 1
                    if match_end_line_cnt == doc.get_line_count():
                        line_end_pos = end_pos
                    else:
                        line_end_pos = doc.get_iter_at_line(
                            match_end_line_cnt).get_offset()
                    line_text = text[line_start_pos:line_end_pos]
                    self._results_view.append_find_result(
                        tree_it, str(line_num + 1), line_text, result[0],
                        result[1], "", line_start_pos, True)

        self.result_highlight_on(tree_it)
Example #38
0
 def switch_to_buffer_by_index(self, index):
     tab = gedit.tab_get_from_document(self._matching_docs[index])
     self._window.set_active_tab(tab)
Example #39
0
 def close(self, gdoc):
     self._window.close_tab(gedit.tab_get_from_document(gdoc))
     return False