def go_to_definition(self): self.dirty = True self.results = [] locations = self.get_locations() if self._isVariable: preResults = [ [file_manager.get_basename(x.path), x.path, x.lineno, ''] for x in locations if (x.type == FILTERS['attribs']) and (x.name == self._search)] else: preResults = [ [file_manager.get_basename(x.path), x.path, x.lineno, ''] for x in locations if ((x.type == FILTERS['functions']) or (x.type == FILTERS['classes'])) and (x.name.startswith(self._search))] for data in preResults: file_object = QFile(data[1]) if not file_object.open(QFile.ReadOnly): return stream = QTextStream(file_object) line_index = 0 line = stream.readLine() while not self._cancel and not stream.atEnd(): if line_index == data[2]: data[3] = line self.results.append(data) break #take the next line! line = stream.readLine() line_index += 1
def go_to_definition(self): self.dirty = True self.results = [] locations = self.get_locations() if self._isVariable: preResults = [ [file_manager.get_basename(x.path), x.path, x.lineno, ''] for x in locations if (x.type == FILTERS['attribs']) and (x.name == self._search) ] else: preResults = [[ file_manager.get_basename(x.path), x.path, x.lineno, '' ] for x in locations if ((x.type == FILTERS['functions']) or (x.type == FILTERS['classes'])) and ( x.name.startswith(self._search))] for data in preResults: file_object = QFile(data[1]) if not file_object.open(QFile.ReadOnly): return stream = QTextStream(file_object) line_index = 0 line = stream.readLine() while not self._cancel and not stream.atEnd(): if line_index == data[2]: data[3] = line self.results.append(data) break #take the next line! line = stream.readLine() line_index += 1 self._search = None self._isVariable = None
def expand_tab_name(self, title): """Expand the tab title to differentiate files with the same name. The way it is currently implemented, it will only change the first conflicting title passed in, because it only searches until the new title isn't in the tab titles. """ if title == 'New Document': return elif title not in self.titles: self.titles.append(title) return indexes = [i for i in range(self.count()) if type(self.widget(i)) is editor.Editor and self.tabText(i) == title and self.widget(i).ID] # self.widget.ID returns the basename self.dontLoopInExpandTitle = True for i in indexes: newName = file_manager.create_path( file_manager.get_basename( file_manager.get_folder(self.widget(i).ID)), title) while newName in self.titles: # Keep prepending the folder name onto the title until it # does not conflict. path = self.widget(i).ID tempDir = path[:path.rfind(newName)] newName = file_manager.create_path( file_manager.get_basename( file_manager.get_folder(tempDir)), '..', title) self.titles.append(newName) self.setTabText(i, newName) self.dontLoopInExpandTitle = False
def expand_tab_name(self, title): """Expand the tab title to differentiate files with the same name. The way it is currently implemented, it will only change the first conflicting title passed in, because it only searches until the new title isn't in the tab titles. """ if title == 'New Document': return elif title not in self.titles: self.titles.append(title) return indexes = [ i for i in range(self.count()) if type(self.widget(i)) is editor.Editor and self.tabText(i) == title and self.widget(i).ID ] # self.widget.ID returns the basename self.dontLoopInExpandTitle = True for i in indexes: newName = file_manager.create_path( file_manager.get_basename( file_manager.get_folder(self.widget(i).ID)), title) while newName in self.titles: # Keep prepending the folder name onto the title until it # does not conflict. path = self.widget(i).ID tempDir = path[:path.rfind(newName)] newName = file_manager.create_path( file_manager.get_basename( file_manager.get_folder(tempDir)), '..', title) self.titles.append(newName) self.setTabText(i, newName) self.dontLoopInExpandTitle = False
def _add_file_to_project(self, path): """Add the file for 'path' in the project the user choose here.""" if self._active_project: pathProject = [self._active_project.project] addToProject = add_to_project.AddToProject(pathProject, self) addToProject.exec_() if not addToProject.pathSelected: return main_container = IDE.get_service('main_container') if not main_container: return editorWidget = main_container.get_current_editor() if not editorWidget.file_path: name = QInputDialog.getText(None, self.tr("Add File To Project"), self.tr("File Name:"))[0] if not name: QMessageBox.information( self, self.tr("Invalid Name"), self.tr("The file name is empty, please enter a name")) return else: name = file_manager.get_basename(editorWidget.file_path) new_path = file_manager.create_path(addToProject.pathSelected, name) ide_srv = IDE.get_service("ide") old_file, ide_srv.get_or_create_nfile(path) new_file = old_file.save(editorWidget.get_text(), path) #FIXME: Make this file replace the original in the open tab else: pass
def _rename_file(self): path = self.model().filePath(self.currentIndex()) name = file_manager.get_basename(path) new_name, ok = QInputDialog.getText( self, translations.TR_RENAME_FILE, translations.TR_ENTER_NEW_FILENAME, text=name) if ok and new_name.strip(): filename = file_manager.create_path( file_manager.get_folder(path), new_name) if path == filename: return ninjaide = IDE.get_service("ide") print(ninjaide.filesystem.get_files()) current_nfile = ninjaide.get_or_create_nfile(path) editable = ninjaide.get_editable(nfile=current_nfile) current_nfile.move(filename) if editable is not None: main_container = IDE.get_service("main_container") main_container.combo_area.bar.update_item_text( editable, new_name) tree = ninjaide.filesystem.get_files() # FIXME: this is bad tree[filename] = tree.pop(path) print(ninjaide.filesystem.get_files())
def __init__(self, path): super(NProject, self).__init__() project = json_manager.read_ninja_project(path) self.path = path self._name = project.get('name', '') if not self._name: self._name = file_manager.get_basename(path) self.project_type = project.get('project-type', '') self.description = project.get('description', '') if self.description == '': self.description = translations.TR_NO_DESCRIPTION self.url = project.get('url', '') self.license = project.get('license', '') self.main_file = project.get('mainFile', '') self.pre_exec_script = project.get('preExecScript', '') self.post_exec_script = project.get('postExecScript', '') self.indentation = project.get('indentation', settings.INDENT) self.use_tabs = project.get('use-tabs', settings.USE_TABS) self.extensions = project.get('supported-extensions', settings.SUPPORTED_EXTENSIONS) self.python_exec = project.get('pythonExec', settings.PYTHON_EXEC) self.python_path = project.get('PYTHONPATH', '') self.additional_builtins = project.get('additional_builtins', []) self.program_params = project.get('programParams', '') self.venv = project.get('venv', '') self.related_projects = project.get('relatedProjects', []) self.added_to_console = False # TODO: handle this self.is_current = True # Model is a QFileSystemModel to be set on runtime self.__model = None
def __init__(self, parent): super(ProjectData, self).__init__() self._parent = parent grid = QGridLayout(self) grid.addWidget(QLabel(translations.TR_PROJECT_NAME), 0, 0) self.name = QLineEdit() if not len(self._parent.project.name): self.name.setText(file_manager.get_basename( self._parent.project.path)) else: self.name.setText(self._parent.project.name) grid.addWidget(self.name, 0, 1) grid.addWidget(QLabel(translations.TR_PROJECT_LOCATION), 1, 0) self.txtPath = QLineEdit() self.txtPath.setReadOnly(True) self.txtPath.setText(self._parent.project.path) grid.addWidget(self.txtPath, 1, 1) grid.addWidget(QLabel(translations.TR_PROJECT_TYPE), 2, 0) self.txtType = QLineEdit() completer = QCompleter(sorted(settings.PROJECT_TYPES)) completer.setCompletionMode(QCompleter.UnfilteredPopupCompletion) self.txtType.setCompleter(completer) self.txtType.setPlaceholderText("python") self.txtType.setText(self._parent.project.project_type) grid.addWidget(self.txtType, 2, 1) grid.addWidget(QLabel(translations.TR_PROJECT_DESCRIPTION), 3, 0) self.description = QPlainTextEdit() self.description.setPlainText(self._parent.project.description) grid.addWidget(self.description, 3, 1) grid.addWidget(QLabel(translations.TR_PROJECT_URL), 4, 0) self.url = QLineEdit() self.url.setText(self._parent.project.url) self.url.setPlaceholderText('https://www.{}.com'.format(getuser())) grid.addWidget(self.url, 4, 1) grid.addWidget(QLabel(translations.TR_PROJECT_LICENSE), 5, 0) self.cboLicense = QComboBox() self.cboLicense.addItems(LICENCES) self.cboLicense.setCurrentIndex(12) index = self.cboLicense.findText(self._parent.project.license) self.cboLicense.setCurrentIndex(index) grid.addWidget(self.cboLicense, 5, 1) self.txtExtensions = QLineEdit() self.txtExtensions.setText(', '.join(self._parent.project.extensions)) grid.addWidget(QLabel(translations.TR_PROJECT_EXTENSIONS), 6, 0) grid.addWidget(self.txtExtensions, 6, 1) grid.addWidget(QLabel(translations.TR_PROJECT_INDENTATION), 7, 0) self.spinIndentation = QSpinBox() self.spinIndentation.setValue(self._parent.project.indentation) self.spinIndentation.setRange(2, 10) self.spinIndentation.setValue(4) self.spinIndentation.setSingleStep(2) grid.addWidget(self.spinIndentation, 7, 1) self.checkUseTabs = QComboBox() self.checkUseTabs.addItems([ translations.TR_PREFERENCES_EDITOR_CONFIG_SPACES.capitalize(), translations.TR_PREFERENCES_EDITOR_CONFIG_TABS.capitalize()]) self.checkUseTabs.setCurrentIndex(int(self._parent.project.use_tabs)) grid.addWidget(self.checkUseTabs, 7, 2)
def _copy_file(self): #get the selected QTreeWidgetItem path = self.model().filePath(self.currentIndex()) name = file_manager.get_basename(path) global projectsColumn pathProjects = [p.path for p in projectsColumn.projects] addToProject = add_to_project.AddToProject(pathProjects, self) addToProject.setWindowTitle(self.tr("Copy File to")) addToProject.exec_() if not addToProject.pathSelected: return name = QInputDialog.getText(self, self.tr("Copy File"), self.tr("File Name:"), text=name)[0] if not name: QMessageBox.information(self, self.tr("Invalid Name"), self.tr("The file name is empty, please enter a name")) return path = file_manager.create_path(addToProject.pathSelected, name) try: content = file_manager.read_file_content(path) path = file_manager.store_file_content(path, content, newFile=True) except file_manager.NinjaFileExistsException as ex: QMessageBox.information(self, self.tr("File Already Exists"), (self.tr("Invalid Path: the file '%s' already exists.") % ex.filename))
def _rename_file(self): item = self.currentItem() if item.parent() is None: pathForFile = item.path else: pathForFile = os.path.join(item.path, item.text(0)) result = QInputDialog.getText(self, self.tr("Rename File"), self.tr("Enter New File Name:"), text=item.text(0)) fileName = result[0] if result[1] and fileName.strip() != '': fileName = os.path.join(file_manager.get_folder(pathForFile), fileName) if pathForFile == fileName: return try: fileName = file_manager.rename_file(pathForFile, fileName) name = file_manager.get_basename(fileName) main_container = IDE.get_service('main_container') if main_container and main_container.is_open(pathForFile): main_container.change_open_tab_name(pathForFile, fileName) subitem = ProjectItem(item.parent(), name, file_manager.get_folder(fileName)) subitem.setToolTip(0, name) subitem.setIcon(0, self._get_file_icon(name)) index = item.parent().indexOfChild(item) subitem.parent().takeChild(index) except file_manager.NinjaFileExistsException as ex: QMessageBox.information( self, self.tr("File Already Exists"), (self.tr("Invalid Path: the file '%s' already exists.") % ex.filename))
def _rename_file(self): item = self.currentItem() if item.parent() is None: pathForFile = item.path else: pathForFile = os.path.join(item.path, item.text(0)) result = QInputDialog.getText(self, self.tr("Rename File"), self.tr("Enter New File Name:"), text=item.text(0)) fileName = result[0] if result[1] and fileName.strip() != '': fileName = os.path.join( file_manager.get_folder(pathForFile), fileName) if pathForFile == fileName: return try: fileName = file_manager.rename_file(pathForFile, fileName) name = file_manager.get_basename(fileName) main_container = IDE.get_service('main_container') if main_container and main_container.is_open(pathForFile): main_container.change_open_tab_name(pathForFile, fileName) subitem = ProjectItem(item.parent(), name, file_manager.get_folder(fileName)) subitem.setToolTip(0, name) subitem.setIcon(0, self._get_file_icon(name)) index = item.parent().indexOfChild(item) subitem.parent().takeChild(index) except file_manager.NinjaFileExistsException as ex: QMessageBox.information(self, self.tr("File Already Exists"), (self.tr("Invalid Path: the file '%s' already exists.") % ex.filename))
def _move_file(self): item = self.currentItem() if item.parent() is None: pathForFile = item.path else: pathForFile = os.path.join(item.path, item.text(0)) pathProjects = [p.path for p in self.get_open_projects()] addToProject = ui_tools.AddToProject(pathProjects, self) addToProject.setWindowTitle(self.tr("Copy File to")) addToProject.exec_() if not addToProject.pathSelected: return name = file_manager.get_basename(pathForFile) path = file_manager.create_path(addToProject.pathSelected, name) try: content = file_manager.read_file_content(pathForFile) path = file_manager.store_file_content(path, content, newFile=True) file_manager.delete_file(pathForFile) index = item.parent().indexOfChild(item) item.parent().takeChild(index) self.add_existing_file(path) # Update path of opened file main = IDE.get_service('main_container') if main and main.is_open(pathForFile): widget = main.get_widget_for_path(pathForFile) if widget: widget.ID = path except file_manager.NinjaFileExistsException as ex: QMessageBox.information(self, self.tr("File Already Exists"), (self.tr("Invalid Path: the file '%s' already exists.") % ex.filename))
def _add_new_file(self): item = self.currentItem() if item.parent() is None: pathForFile = item.path else: pathForFile = os.path.join(item.path, item.text(0)) result = QInputDialog.getText(self, self.tr("New File"), self.tr("Enter the File Name:")) fileName = result[0] if result[1] and fileName.strip() != '': try: fileName = os.path.join(pathForFile, fileName) fileName = file_manager.store_file_content( fileName, '', newFile=True) name = file_manager.get_basename(fileName) subitem = ProjectItem(item, name, pathForFile) subitem.setToolTip(0, name) subitem.setIcon(0, self._get_file_icon(name)) main_container = IDE.get_service('main_container') if main_container: main_container.open_file(fileName) except file_manager.NinjaFileExistsException as ex: QMessageBox.information(self, self.tr("File Already Exists"), (self.tr("Invalid Path: the file '%s' already exists.") % ex.filename))
def save_recent_projects(self, folder): settings = IDE.data_settings() recent_project_list = settings.value('recentProjects', {}) # if already exist on the list update the date time projectProperties = json_manager.read_ninja_project(folder) name = projectProperties.get('name', '') description = projectProperties.get('description', '') if name == '': name = file_manager.get_basename(folder) if description == '': description = translations.TR_NO_DESCRIPTION if folder in recent_project_list: properties = recent_project_list[folder] properties["lastopen"] = QDateTime.currentDateTime() properties["name"] = name properties["description"] = description recent_project_list[folder] = properties else: recent_project_list[folder] = { "name": name, "description": description, "isFavorite": False, "lastopen": QDateTime.currentDateTime() } # if the length of the project list it's high that 10 then delete # the most old # TODO: add the length of available projects to setting if len(recent_project_list) > 10: del recent_project_list[self.find_most_old_open( recent_project_list)] settings.setValue('recentProjects', recent_project_list)
def _copy_file(self): path = self.model().filePath(self.currentIndex()) name = file_manager.get_basename(path) global projectsColumn pathProjects = [p.project for p in projectsColumn.projects] add_to_project_dialog = add_to_project.AddToProject(pathProjects, self) add_to_project_dialog.setWindowTitle(translations.TR_COPY_FILE_TO) add_to_project_dialog.exec_() if not add_to_project_dialog.path_selected: return name = QInputDialog.getText(self, translations.TR_COPY_FILE, translations.TR_FILENAME, text=name)[0] if not name: QMessageBox.information( self, translations.TR_INVALID_FILENAME, translations.TR_INVALID_FILENAME_ENTER_A_FILENAME) return new_path = file_manager.create_path(add_to_project_dialog.pathSelected, name) ninjaide = IDE.get_service("ide") current_nfile = ninjaide.get_or_create_nfile(path) # FIXME: Catch willOverWrite and willCopyTo signals current_nfile.copy(new_path)
def get_item_for_path(self, path): items = self.findItems(file_manager.get_basename(path), Qt.MatchRecursive, 0) folder = file_manager.get_folder(path) for item in items: if file_manager.belongs_to_folder(folder, item.path): return item
def _add_new_file(self): item = self.currentItem() if item.parent() is None: pathForFile = item.path else: pathForFile = os.path.join(item.path, item.text(0)) result = QInputDialog.getText(self, self.tr("New File"), self.tr("Enter the File Name:")) fileName = result[0] if result[1] and fileName.strip() != '': try: fileName = os.path.join(pathForFile, fileName) fileName = file_manager.store_file_content(fileName, '', newFile=True) name = file_manager.get_basename(fileName) subitem = ProjectItem(item, name, pathForFile) subitem.setToolTip(0, name) subitem.setIcon(0, self._get_file_icon(name)) main_container = IDE.get_service('main_container') if main_container: main_container.open_file(fileName) except file_manager.NinjaFileExistsException as ex: QMessageBox.information( self, self.tr("File Already Exists"), (self.tr("Invalid Path: the file '%s' already exists.") % ex.filename))
def get_item_for_path(self, path): items = self.findItems(file_manager.get_basename(path), Qt.MatchRecursive, 0) folder = file_manager.get_folder(path) for item in items: if file_manager.belongs_to_folder(folder, item.path): return item
def __init__(self, path): super(NProject, self).__init__() project = json_manager.read_ninja_project(path) self.path = path self._name = project.get('name', '') if self._name == '': self._name = file_manager.get_basename(path) self.project_type = project.get('project-type', '') self.description = project.get('description', '') if self.description == '': self.description = translations.TR_NO_DESCRIPTION self.url = project.get('url', '') self.license = project.get('license', '') self.main_file = project.get('mainFile', '') self.pre_exec_script = project.get('preExecScript', '') self.post_exec_script = project.get('postExecScript', '') self.indentation = project.get('indentation', settings.INDENT) self.use_tabs = project.get('use-tabs', settings.USE_TABS) self.extensions = project.get('supported-extensions', settings.SUPPORTED_EXTENSIONS) self.python_exec = project.get('pythonExec', settings.PYTHON_EXEC) self.python_path = project.get('PYTHONPATH', '') self.additional_builtins = project.get('additional_builtins', []) self.program_params = project.get('programParams', '') self.venv = project.get('venv', '') self.related_projects = project.get('relatedProjects', []) self.added_to_console = False self.is_current = False #Model is a QFileSystemModel to be set on runtime self.__model = None
def _add_file_to_project(self, path): """Add the file for 'path' in the project the user choose here.""" if self._active_project: pathProject = [self._active_project.project] addToProject = add_to_project.AddToProject(pathProject, self) addToProject.exec_() if not addToProject.pathSelected: return main_container = IDE.get_service('main_container') if not main_container: return editorWidget = main_container.get_current_editor() if not editorWidget.file_path: name = QInputDialog.getText(None, translations.TR_ADD_FILE_TO_PROJECT, translations.TR_FILENAME + ": ")[0] if not name: QMessageBox.information( self, translations.TR_INVALID_FILENAME, translations.TR_INVALID_FILENAME_ENTER_A_FILENAME) return else: name = file_manager.get_basename(editorWidget.file_path) new_path = file_manager.create_path(addToProject.pathSelected, name) ide_srv = IDE.get_service("ide") old_file = ide_srv.get_or_create_nfile(path) new_file = old_file.save(editorWidget.get_text(), new_path) #FIXME: Make this file replace the original in the open tab else: pass
def _rename_file(self): path = self.model().filePath(self.currentIndex()) name = file_manager.get_basename(path) new_name, ok = QInputDialog.getText(self, translations.TR_RENAME_FILE, translations.TR_ENTER_NEW_FILENAME, text=name) if ok and new_name.strip(): filename = file_manager.create_path(file_manager.get_folder(path), new_name) if path == filename: return ninjaide = IDE.get_service("ide") print(ninjaide.filesystem.get_files()) current_nfile = ninjaide.get_or_create_nfile(path) editable = ninjaide.get_editable(nfile=current_nfile) current_nfile.move(filename) if editable is not None: main_container = IDE.get_service("main_container") main_container.combo_area.bar.update_item_text( editable, new_name) tree = ninjaide.filesystem.get_files() # FIXME: this is bad tree[filename] = tree.pop(path) print(ninjaide.filesystem.get_files())
def _add_file_to_project(self, path): """Add the file for 'path' in the project the user choose here.""" if self._active_project: pathProject = [self._active_project.project] addToProject = add_to_project.AddToProject(pathProject, self) addToProject.exec_() if not addToProject.pathSelected: return main_container = IDE.get_service('main_container') if not main_container: return editorWidget = main_container.get_current_editor() if not editorWidget.file_path: name = QInputDialog.getText(None, self.tr("Add File To Project"), self.tr("File Name:"))[0] if not name: QMessageBox.information(self, self.tr("Invalid Name"), self.tr("The file name is empty, please enter a name")) return else: name = file_manager.get_basename(editorWidget.file_path) new_path = file_manager.create_path(addToProject.pathSelected, name) ide_srv = IDE.get_service("ide") old_file, ide_srv.get_or_create_nfile(path) new_file = old_file.save(editorWidget.get_text(), path) #FIXME: Make this file replace the original in the open tab else: pass
def save_recent_projects(self, folder): settings = IDE.data_settings() recent_project_list = settings.value('recentProjects', {}) #if already exist on the list update the date time projectProperties = json_manager.read_ninja_project(folder) name = projectProperties.get('name', '') description = projectProperties.get('description', '') if name == '': name = file_manager.get_basename(folder) if description == '': description = translations.TR_NO_DESCRIPTION if folder in recent_project_list: properties = recent_project_list[folder] properties["lastopen"] = QDateTime.currentDateTime() properties["name"] = name properties["description"] = description recent_project_list[folder] = properties else: recent_project_list[folder] = { "name": name, "description": description, "isFavorite": False, "lastopen": QDateTime.currentDateTime()} #if the length of the project list it's high that 10 then delete #the most old #TODO: add the length of available projects to setting if len(recent_project_list) > 10: del recent_project_list[self.find_most_old_open( recent_project_list)] settings.setValue('recentProjects', recent_project_list)
def _move_file(self): item = self.currentItem() if item.parent() is None: pathForFile = item.path else: pathForFile = os.path.join(item.path, item.text(0)) pathProjects = [p.path for p in self.get_open_projects()] addToProject = ui_tools.AddToProject(pathProjects, self) addToProject.setWindowTitle(self.tr("Copy File to")) addToProject.exec_() if not addToProject.pathSelected: return name = file_manager.get_basename(pathForFile) path = file_manager.create_path(addToProject.pathSelected, name) try: content = file_manager.read_file_content(pathForFile) path = file_manager.store_file_content(path, content, newFile=True) file_manager.delete_file(pathForFile) index = item.parent().indexOfChild(item) item.parent().takeChild(index) self.add_existing_file(path) # Update path of opened file main = IDE.get_service('main_container') if main and main.is_open(pathForFile): widget = main.get_widget_for_path(pathForFile) if widget: widget.ID = path except file_manager.NinjaFileExistsException as ex: QMessageBox.information( self, self.tr("File Already Exists"), (self.tr("Invalid Path: the file '%s' already exists.") % ex.filename))
def _move_file(self): path = self.model().filePath(self.currentIndex()) global projectsColumn pathProjects = [p.path for p in projectsColumn.projects] addToProject = add_to_project.AddToProject(pathProjects, self) addToProject.setWindowTitle(self.tr("Copy File to")) addToProject.exec_() if not addToProject.pathSelected: return name = file_manager.get_basename(path) path = file_manager.create_path(addToProject.pathSelected, name) try: content = file_manager.read_file_content(path) path = file_manager.store_file_content(path, content, newFile=True) file_manager.delete_file(path) # Update path of opened file main = IDE.get_service('main_container') if main and main.is_open(path): widget = main.get_widget_for_path(path) if widget: widget.ID = path except file_manager.NinjaFileExistsException as ex: QMessageBox.information(self, self.tr("File Already Exists"), (self.tr("Invalid Path: the file '%s' already exists.") % ex.filename))
def _add_file_to_project(self, path): """Add the file for 'path' in the project the user choose here.""" if self._projects_area.count() > 0: pathProject = [self.current_project] addToProject = add_to_project.AddToProject(pathProject, self) addToProject.exec_() if not addToProject.pathSelected: return main_container = IDE.get_service('main_container') if not main_container: return editorWidget = main_container.get_current_editor() if not editorWidget.file_path: name = QInputDialog.getText( None, translations.TR_ADD_FILE_TO_PROJECT, translations.TR_FILENAME + ": ")[0] if not name: QMessageBox.information( self, translations.TR_INVALID_FILENAME, translations.TR_INVALID_FILENAME_ENTER_A_FILENAME) return else: name = file_manager.get_basename(editorWidget.file_path) new_path = file_manager.create_path(addToProject.pathSelected, name) ide_srv = IDE.get_service("ide") old_file = ide_srv.get_or_create_nfile(path) new_file = old_file.save(editorWidget.text(), new_path) # FIXME: Make this file replace the original in the open tab else: pass
def locate_file_code(self): file_name = file_manager.get_basename(self._file_path) try: self._grep_file_locate(self._file_path, file_name) self.dirty = True self.execute = self.locate_code except Exception as reason: logger.error('locate_file_code, error: %r' % reason)
def locate_file_code(self): self._locator_db = sqlite3.connect(db_path) file_name = file_manager.get_basename(self._file_path) try: self._grep_file_symbols(self._file_path, file_name) self.dirty = True except Exception as reason: logger.error('locate_file_code, error: %r' % reason)
def locate_file_code(self): self._locator_db = sqlite3.connect(db_path) file_name = file_manager.get_basename(self._file_path) try: self._grep_file_symbols(self._file_path, file_name) self.dirty = True except Exception as reason: logger.error('locate_file_code, error: %r' % reason)
def _advanced_filter_by_file(self, filterOptions): if filterOptions[1] == FILTERS['files']: index = 2 else: index = 3 self.tempLocations = [x for x in self.tempLocations if file_manager.get_basename(x.path).lower().find( filterOptions[index]) > -1]
def locate_file_code(self): file_name = file_manager.get_basename(self._file_path) try: self._grep_file_locate(self._file_path, file_name) self.dirty = True self.execute = self.locate_code except Exception as reason: logger.error('locate_file_code, error: %r' % reason)
def change_open_tab_id(self, idname, newId): """Search for the Tab with idname, and set the newId to that Tab.""" index = self.tabs.is_open(idname) if index != -1: widget = self.tabs.widget(index) tabName = file_manager.get_basename(newId) self.tabs.change_open_tab_name(index, tabName) widget.ID = newId
def _advanced_filter_by_file(self, filterOptions): if filterOptions[1] == FILTERS['files']: index = 2 else: index = 3 self.tempLocations = [ x for x in self.tempLocations if file_manager.get_basename( x.path).lower().find(filterOptions[index]) > -1 ]
def _delete_folder(self): # FIXME: We need nfilesystem support for this path = self.model().filePath(self.currentIndex()) name = file_manager.get_basename(path) val = QMessageBox.question( self, translations.TR_REMOVE_FOLDER, translations.TR_DELETE_FOLLOWING_FOLDER.format(name), QMessageBox.Yes, QMessageBox.No) if val == QMessageBox.Yes: file_manager.delete_folder(path)
def _add_file_to_project(self, path): """Add the file for 'path' in the project the user choose here.""" pathProject = [self.get_actual_project()] addToProject = ui_tools.AddToProject(pathProject, self.ide) addToProject.exec_() if not addToProject.pathSelected: return main_container = IDE.get_service('main_container') if not main_container: return editorWidget = main_container.get_actual_editor() if not editorWidget.ID: name = QInputDialog.getText(None, self.tr("Add File To Project"), self.tr("File Name:"))[0] if not name: QMessageBox.information( self, self.tr("Invalid Name"), self.tr("The file name is empty, please enter a name")) return else: name = file_manager.get_basename(editorWidget.ID) path = file_manager.create_path(addToProject.pathSelected, name) try: path = file_manager.store_file_content(path, editorWidget.get_text(), newFile=True) main_container._file_watcher.allow_kill = False if path != editorWidget.ID: main_container.remove_standalone_watcher(editorWidget.ID) editorWidget.ID = path main_container.add_standalone_watcher(path) main_container._file_watcher.allow_kill = True self.add_existing_file(path) self.emit(SIGNAL("changeWindowTitle(QString)"), path) name = file_manager.get_basename(path) main_container.actualTab.setTabText( main_container.actualTab.currentIndex(), name) editorWidget._file_saved() except file_manager.NinjaFileExistsException as ex: QMessageBox.information( self, self.tr("File Already Exists"), (self.tr("Invalid Path: the file '%s' already exists.") % ex.filename))
def _delete_folder(self): # FIXME: We need nfilesystem support for this path = self.model().filePath(self.currentIndex()) name = file_manager.get_basename(path) val = QMessageBox.question( self, translations.TR_REMOVE_FOLDER, translations.TR_DELETE_FOLLOWING_FOLDER.format(name), QMessageBox.Yes, QMessageBox.No) if val == QMessageBox.Yes: file_manager.delete_folder(path)
def open_image(self, fileName): try: if not self.is_open(fileName): viewer = image_viewer.ImageViewer(fileName) self.add_tab(viewer, file_manager.get_basename(fileName)) viewer.ID = fileName else: self.move_to_open(fileName) except Exception as reason: logger.error("open_image: %s", reason) QMessageBox.information(self, self.tr("Incorrect File"), self.tr("The image couldn't be open"))
def _add_file_to_project(self, path): """Add the file for 'path' in the project the user choose here.""" pathProject = [self.get_actual_project()] addToProject = ui_tools.AddToProject(pathProject, self.ide) addToProject.exec_() if not addToProject.pathSelected: return main_container = IDE.get_service('main_container') if not main_container: return editorWidget = main_container.get_actual_editor() if not editorWidget.ID: name = QInputDialog.getText(None, self.tr("Add File To Project"), self.tr("File Name:"))[0] if not name: QMessageBox.information(self, self.tr("Invalid Name"), self.tr("The file name is empty, please enter a name")) return else: name = file_manager.get_basename(editorWidget.ID) path = file_manager.create_path(addToProject.pathSelected, name) try: path = file_manager.store_file_content( path, editorWidget.get_text(), newFile=True) main_container._file_watcher.allow_kill = False if path != editorWidget.ID: main_container.remove_standalone_watcher( editorWidget.ID) editorWidget.ID = path main_container.add_standalone_watcher(path) main_container._file_watcher.allow_kill = True self.add_existing_file(path) self.emit(SIGNAL("changeWindowTitle(QString)"), path) name = file_manager.get_basename(path) main_container.actualTab.setTabText( main_container.actualTab.currentIndex(), name) editorWidget._file_saved() except file_manager.NinjaFileExistsException as ex: QMessageBox.information(self, self.tr("File Already Exists"), (self.tr("Invalid Path: the file '%s' already exists.") % ex.filename))
def get_this_file_symbols(self, path): global mapping_symbols symbols = mapping_symbols.get(path, ()) try: if not symbols: file_name = file_manager.get_basename(path) self._grep_file_symbols(path, file_name) symbols = mapping_symbols.get(path, ()) symbols = sorted(symbols[1:], key=lambda item: item.name) except Exception as reason: logger.error('get_this_file_symbols, error: %r' % reason) return symbols
def _delete_file(self, path=''): if not path: path = self.model().filePath(self.currentIndex()) name = file_manager.get_basename(path) val = QMessageBox.question( self, translations.TR_DELETE_FILE, translations.TR_DELETE_FOLLOWING_FILE.format(name), QMessageBox.Yes, QMessageBox.No) if val == QMessageBox.Yes: ninjaide = IDE.get_service("ide") current_nfile = ninjaide.get_or_create_nfile(path) current_nfile.delete()
def print_file(self): """Call the print of ui_tool Call print of ui_tool depending on the focus of the application""" # TODO: Add funtionality for proyect tab and methods tab editorWidget = self.get_current_editor() if editorWidget is not None: fileName = "newDocument.pdf" if editorWidget.file_path: fileName = file_manager.get_basename(editorWidget.file_path) fileName = fileName[: fileName.rfind(".")] + ".pdf" ui_tools.print_file(fileName, editorWidget.print_)
def _delete_file(self, path=''): if not path: path = self.model().filePath(self.currentIndex()) name = file_manager.get_basename(path) val = QMessageBox.question( self, translations.TR_DELETE_FILE, translations.TR_DELETE_FOLLOWING_FILE.format(name), QMessageBox.Yes, QMessageBox.No) if val == QMessageBox.Yes: ninjaide = IDE.get_service("ide") current_nfile = ninjaide.get_or_create_nfile(path) current_nfile.delete()
def open_image(self, fileName): try: if not self.is_open(fileName): viewer = image_viewer.ImageViewer(fileName) self.add_tab(viewer, file_manager.get_basename(fileName)) viewer.ID = fileName else: self.move_to_open(fileName) except Exception as reason: logger.error('open_image: %s', reason) QMessageBox.information(self, self.tr("Incorrect File"), self.tr("The image couldn\'t be open"))
def get_this_file_symbols(self, path): global mapping_symbols symbols = mapping_symbols.get(path, ()) try: if not symbols: file_name = file_manager.get_basename(path) self._grep_file_symbols(path, file_name) symbols = mapping_symbols.get(path, ()) symbols = sorted(symbols[1:], key=lambda item: item.name) except Exception as reason: logger.error('get_this_file_symbols, error: %r' % reason) return symbols
def print_file(self): """Call the print of ui_tool Call print of ui_tool depending on the focus of the application""" #TODO: Add funtionality for proyect tab and methods tab editorWidget = self.get_current_editor() if editorWidget is not None: fileName = "newDocument.pdf" if editorWidget.file_path: fileName = file_manager.get_basename(editorWidget.file_path) fileName = fileName[:fileName.rfind('.')] + '.pdf' ui_tools.print_file(fileName, editorWidget.print_)
def get_this_file_locations(self, path): global mapping_locations thisFileLocations = mapping_locations.get(path, ()) try: if not thisFileLocations: file_name = file_manager.get_basename(path) self._grep_file_locate(path, file_name) thisFileLocations = mapping_locations.get(path, ()) thisFileLocations = sorted(thisFileLocations[1:], key=lambda item: item.name) except Exception as reason: logger.error('get_this_file_locations, error: %r' % reason) return thisFileLocations
def _rename_file(self): path = self.model().filePath(self.currentIndex()) name = file_manager.get_basename(path) result = QInputDialog.getText(self, self.tr("Rename File"), self.tr("Enter New File Name:"), text=name) fileName = result[0] if result[1] and fileName.strip() != '': fileName = os.path.join( file_manager.get_folder(path), fileName) if path == fileName: return try: fileName = file_manager.rename_file(path, fileName) name = file_manager.get_basename(fileName) main_container = IDE.get_service('main_container') if main_container and main_container.is_open(path): main_container.change_open_tab_name(path, fileName) except file_manager.NinjaFileExistsException as ex: QMessageBox.information(self, self.tr("File Already Exists"), (self.tr("Invalid Path: the file '%s' already exists.") % ex.filename))
def get_this_file_locations(self, path): global mapping_locations thisFileLocations = mapping_locations.get(path, ()) try: if not thisFileLocations: file_name = file_manager.get_basename(path) self._grep_file_locate(path, file_name) thisFileLocations = mapping_locations.get(path, ()) thisFileLocations = sorted(thisFileLocations[1:], key=lambda item: item.name) except Exception as reason: logger.error('get_this_file_locations, error: %r' % reason) return thisFileLocations
def _add_file_to_project(self, path): """Add the file for 'path' in the project the user choose here.""" if self._active_project: pathProject = [self._active_project.project] addToProject = add_to_project.AddToProject(pathProject, self) addToProject.exec_() if not addToProject.pathSelected: return main_container = IDE.get_service('main_container') if not main_container: return editorWidget = main_container.get_current_editor() if not editorWidget.file_path: name = QInputDialog.getText(None, self.tr("Add File To Project"), self.tr("File Name:"))[0] if not name: QMessageBox.information(self, self.tr("Invalid Name"), self.tr("The file name is empty, please enter a name")) return else: name = file_manager.get_basename(editorWidget.file_path) path = file_manager.create_path(addToProject.pathSelected, name) try: #FIXME path = file_manager.store_file_content( path, editorWidget.get_text(), newFile=True) editorWidget.nfile = path self.emit(SIGNAL("changeWindowTitle(QString)"), path) name = file_manager.get_basename(path) main_container.actualTab.setTabText( main_container.actualTab.currentIndex(), name) editorWidget._file_saved() except file_manager.NinjaFileExistsException as ex: QMessageBox.information(self, self.tr("File Already Exists"), (self.tr("Invalid Path: the file '%s' already exists.") % ex.filename)) else: pass
def _load_project(self, folderStructure, folder): if not folder: return name = file_manager.get_basename(folder) item = QTreeWidgetItem(self._tree) item.setText(0, name) item.setToolTip(0, folder) item.setIcon(0, QIcon(":img/tree-folder")) if folderStructure[folder][1] is not None: folderStructure[folder][1].sort() self._load_folder(folderStructure, folder, item) item.setExpanded(True) self._root = item
def _load_project(self, folderStructure, folder): if not folder: return name = file_manager.get_basename(folder) item = QTreeWidgetItem(self._tree) item.setText(0, name) item.setToolTip(0, folder) item.setIcon(0, QIcon(resources.IMAGES['tree-folder'])) if folderStructure[folder][1] is not None: folderStructure[folder][1].sort() self._load_folder(folderStructure, folder, item) item.setExpanded(True) self._root = item
def _move_file(self): path = self.model().filePath(self.currentIndex()) global projectsColumn pathProjects = [p.project for p in projectsColumn.projects] addToProject = add_to_project.AddToProject(pathProjects, self) addToProject.setWindowTitle(translations.TR_COPY_FILE_TO) addToProject.exec_() if not addToProject.pathSelected: return name = file_manager.get_basename(path) new_path = file_manager.create_path(addToProject.pathSelected, name) ide_srv = IDE.get_service("ide") current_nfile = ide_srv.get_or_create_nfile(path) #FIXME: Catch willOverWrite and willMove signals current_nfile.move(new_path)
def _move_file(self): path = self.model().filePath(self.currentIndex()) global projectsColumn pathProjects = [p.project for p in projectsColumn.projects] addToProject = add_to_project.AddToProject(pathProjects, self) addToProject.setWindowTitle(translations.TR_COPY_FILE_TO) addToProject.exec_() if not addToProject.pathSelected: return name = file_manager.get_basename(path) new_path = file_manager.create_path(addToProject.pathSelected, name) ide_srv = IDE.get_service("ide") current_nfile = ide_srv.get_or_create_nfile(path) # FIXME: Catch willOverWrite and willMove signals current_nfile.move(new_path)
def _rename_file(self): path = self.model().filePath(self.currentIndex()) name = file_manager.get_basename(path) result = QInputDialog.getText(self, self.tr("Rename File"), self.tr("Enter New File Name:"), text=name) fileName = result[0] if result[1] and fileName.strip() != '': fileName = os.path.join( file_manager.get_folder(path), fileName) if path == fileName: return ide_srv = IDE.get_service("ide") current_nfile = ide_srv.get_or_create_nfile(path) #FIXME: Catch willOverWrite and willMove signals current_nfile.move(fileName)
def _rename_file(self): path = self.model().filePath(self.currentIndex()) name = file_manager.get_basename(path) result = QInputDialog.getText(self, translations.TR_RENAME_FILE, translations.TR_ENTER_NEW_FILENAME, text=name) fileName = result[0] if result[1] and fileName.strip() != '': fileName = os.path.join(file_manager.get_folder(path), fileName) if path == fileName: return ide_srv = IDE.get_service("ide") current_nfile = ide_srv.get_or_create_nfile(path) # FIXME: Catch willOverWrite and willMove signals current_nfile.move(fileName)
def _move_file(self): path = self.model().filePath(self.currentIndex()) global projectsColumn path_projects = [p.project for p in projectsColumn.projects] add_to_project_dialog = add_to_project.AddToProject(path_projects) add_to_project_dialog.setWindowTitle(translations.TR_MOVE_FILE) add_to_project_dialog.exec_() if not add_to_project_dialog.path_selected: return name = file_manager.get_basename(path) new_path = file_manager.create_path( add_to_project_dialog.path_selected, name) ninjaide = IDE.get_service("ide") current_nfile = ninjaide.get_or_create_nfile(path) current_nfile.close() # FIXME: Catch willOverWrite and willMove signals current_nfile.move(new_path)
def _add_new_folder(self): item = self.currentItem() if item.parent() is None: pathForFolder = item.path else: pathForFolder = os.path.join(item.path, item.text(0)) result = QInputDialog.getText(self, self.tr("New Folder"), self.tr("Enter the Folder Name:")) folderName = result[0] if result[1] and folderName.strip() != '': folderName = os.path.join(pathForFolder, folderName) file_manager.create_folder(folderName) name = file_manager.get_basename(folderName) subitem = ProjectItem(item, name, pathForFolder) subitem.setToolTip(0, name) subitem.setIcon(0, QIcon(":img/tree-folder"))
def add_existing_file(self, path): relative = file_manager.convert_to_relative(self._actualProject.path, path) paths = relative.split(os.sep)[:-1] itemParent = self._actualProject for p in paths: for i in range(itemParent.childCount()): item = itemParent.child(i) if item.text(0) == p: itemParent = item break itemParent.setSelected(True) name = file_manager.get_basename(path) subitem = ProjectItem(itemParent, name, file_manager.get_folder(path)) subitem.setToolTip(0, name) subitem.setIcon(0, self._get_file_icon(name)) itemParent.setExpanded(True)