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.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)
def _close_project( self ): print "Closing project ... " + self._project.filename for item in self._window.get_documents(): #GYLL if item.get_uri() == None and not (item in self._window.get_unsaved_documents()): #GYLL self._window.close_tab( gedit.gedit_tab_get_from_document( item ) ) #GYLL there_are_unsaved_files = False for item in self._window.get_documents(): if item.get_data("BelongsToProject") == self._project.filename: item.set_data( "BelongsToProject", None ) #GYLL if not (item in self._window.get_unsaved_documents()): self._window.close_tab( gedit.gedit_tab_get_from_document( item ) ) else: self._message.append( " - The following file is NOT SAVED; it has not been closed: '/" + item.get_uri().lstrip("file:/").replace("%20", " ") + "'" ) self._project.clear() self.update_ui()
def _open_project( self, filename ): "Process the project file and open all the child files" for item in self._window.get_documents(): #GYLL if item.get_uri() == None and not (item in self._window.get_unsaved_documents()): #GYLL self._window.close_tab( gedit.gedit_tab_get_from_document( item ) ) #GYLL self._project.filename = filename file_list = list() xml = minidom.parse( filename ) for subfile in xml.getElementsByTagName( 'file' ): file_list.append( subfile.childNodes[0].data.strip() ) self._open_files( file_list ) self._project.active = True #GYLL -- this line has been inserted into this function; it used to be placed throught the program after each call to _open_project print "Opening project ... " + filename
def on_open_file_as_project_action( self): doc = self._window.get_active_document() if (doc and doc.get_uri() != None): filename = "/" + doc.get_uri().strip().lstrip("file:/").replace("%20", " ") print "Opening file as project: " + filename if self._project.active: self._show_alert("Could not open project: " + filename + "\nReason: A project is already open") return if not self._has_gedit_project_extension( filename ): self._show_alert("Cannot open project.\nReason: Current file is not a '.gedit-project' file") return if os.path.exists( filename ): if doc in self._window.get_unsaved_documents(): self._show_alert( "Cannot open current file as project.\nReason: Project file is modified but NOT SAVED." ) return self._window.close_tab( gedit.gedit_tab_get_from_document( doc )) self._open_project( filename ) self._save_project( filename ) self._add_to_history( filename ) if self._message: self._show_alert( "Project opened: '" + os.path.basename( self._project.filename ) + "'", self.WITH_LOG ) else: self._show_alert( "Project not opened: '"+ os.path.basename( filename ) + "'\n\nProject file not found: \n" + filename )
def gedit_tab_get_from_document(self, doc): if not is_mate: return gedit.gedit_tab_get_from_document(doc) else: return gedit.pluma_tab_get_from_document(doc)