def save_stylesheet(self): try: file_name = "%s.qss" % self.line_name.text() if not self._is_valid_scheme_name(file_name): QMessageBox.information( self, translations.TR_PREFERENCES_THEME, translations.TR_SCHEME_INVALID_NAME) file_name = ('{0}.qss'.format( file_manager.create_path( resources.NINJA_THEME_DOWNLOAD, file_name))) content = self.edit_qss.toPlainText() answer = True if file_manager.file_exists(file_name): answer = QMessageBox.question( self, translations.TR_PREFERENCES_THEME, translations.TR_WANT_OVERWRITE_FILE + ": {0}?".format( file_name), QMessageBox.Yes, QMessageBox.No) if answer in (QMessageBox.Yes, True): self.apply_stylesheet() file_manager.store_file_content( file_name, content, newFile=True) self.close() except file_manager.NinjaFileExistsException as ex: QMessageBox.information( self, self.tr("File Already Exists"), (self.tr("Invalid File Name: the file '%s' already exists.") % ex.filename))
def _replace_results(self): """Replace the search with the proper text in all the files.""" result = QMessageBox.question( self, translations.TR_REPLACE_FILES_CONTENTS, translations.TR_ARE_YOU_SURE_WANT_TO_REPLACE, buttons=QMessageBox.Yes | QMessageBox.No) if result == QMessageBox.Yes: for index in range(self._result_widget.topLevelItemCount()): parent = self._result_widget.topLevelItem(index) root_dir_name = parent.dir_name_root file_name = parent.text(0) file_path = file_manager.create_path(root_dir_name, file_name) try: content = file_manager.read_file_content(file_path) pattern = self._find_widget.pattern_line_edit.text() flags = 0 if not self._find_widget.case_checkbox.isChecked(): flags |= re.IGNORECASE if self._find_widget.type_checkbox.isChecked(): pattern = r'\b%s\b' % pattern new_content = re.sub(pattern, self._find_widget.replace_line.text(), content, flags=flags) file_manager.store_file_content(file_path, new_content, False) except: print(('File: {} content, could not be replaced'.format( file_path)))
def _replace_results(self): result = QMessageBox.question(self, self.tr("Replace Files Contents"), self.tr("Are you sure you want to replace the content in " "this files?\n(The change is not reversible)"), buttons=QMessageBox.Yes | QMessageBox.No) if result == QMessageBox.Yes: for index in range(self._result_widget.topLevelItemCount()): parent = self._result_widget.topLevelItem(index) root_dir_name = parent.dir_name_root file_name = parent.text(0) file_path = file_manager.create_path(root_dir_name, file_name) try: content = file_manager.read_file_content(file_path) pattern = self._find_widget.pattern_line_edit.text() flags = 0 if not self._find_widget.case_checkbox.isChecked(): flags |= re.IGNORECASE if self._find_widget.type_checkbox.isChecked(): pattern = r'\b%s\b' % pattern new_content = re.sub(pattern, self._find_widget.replace_line.text(), content, flags=flags) file_manager.store_file_content(file_path, new_content, False) except: print('File: %s content, could not be replaced' % file_path)
def _replace_results(self): result = QMessageBox.question( self, self.tr("Replace Files Contents"), self.tr("Are you sure you want to replace the content in " "this files?\n(The change is not reversible)"), buttons=QMessageBox.Yes | QMessageBox.No) if result == QMessageBox.Yes: for index in range(self._result_widget.topLevelItemCount()): parent = self._result_widget.topLevelItem(index) root_dir_name = parent.dir_name_root file_name = parent.text(0) file_path = file_manager.create_path(root_dir_name, file_name) try: content = file_manager.read_file_content(file_path) pattern = self._find_widget.pattern_line_edit.text() flags = 0 if not self._find_widget.case_checkbox.isChecked(): flags |= re.IGNORECASE if self._find_widget.type_checkbox.isChecked(): pattern = r'\b%s\b' % pattern new_content = re.sub(pattern, self._find_widget.replace_line.text(), content, flags=flags) file_manager.store_file_content(file_path, new_content, False) except: print('File: %s content, could not be replaced' % file_path)
def _replace_results(self): """Replace the search with the proper text in all the files.""" result = QMessageBox.question(self, translations.TR_REPLACE_FILES_CONTENTS, translations.TR_ARE_YOU_SURE_WANT_TO_REPLACE, buttons=QMessageBox.Yes | QMessageBox.No) if result == QMessageBox.Yes: for index in range(self._result_widget.topLevelItemCount()): parent = self._result_widget.topLevelItem(index) root_dir_name = parent.dir_name_root file_name = parent.text(0) file_path = file_manager.create_path(root_dir_name, file_name) try: content = file_manager.read_file_content(file_path) pattern = self._find_widget.pattern_line_edit.text() flags = 0 if not self._find_widget.case_checkbox.isChecked(): flags |= re.IGNORECASE if self._find_widget.type_checkbox.isChecked(): pattern = r'\b%s\b' % pattern new_content = re.sub(pattern, self._find_widget.replace_line.text(), content, flags=flags) file_manager.store_file_content(file_path, new_content, False) except: print(('File: {} content, could not be replaced'.format( file_path)))
def save_stylesheet(self): try: file_name = "%s.qss" % self.line_name.text() if not self._is_valid_scheme_name(file_name): QMessageBox.information(self, translations.TR_PREFERENCES_THEME, translations.TR_SCHEME_INVALID_NAME) file_name = ('{0}.qss'.format( file_manager.create_path(resources.NINJA_THEME_DOWNLOAD, file_name))) content = self.edit_qss.toPlainText() answer = True if file_manager.file_exists(file_name): answer = QMessageBox.question( self, translations.TR_PREFERENCES_THEME, translations.TR_WANT_OVERWRITE_FILE + ": {0}?".format(file_name), QMessageBox.Yes, QMessageBox.No) if answer in (QMessageBox.Yes, True): self.apply_stylesheet() file_manager.store_file_content(file_name, content, newFile=True) self.close() except file_manager.NinjaFileExistsException as ex: QMessageBox.information( self, self.tr("File Already Exists"), (self.tr("Invalid File Name: 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 _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 _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 _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 _copy_file(self): #get the selected QTreeWidgetItem 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 = QInputDialog.getText(self, self.tr("Copy File"), self.tr("File Name:"), text=item.text(0))[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(pathForFile) path = file_manager.store_file_content(path, content, newFile=True) self.add_existing_file(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): 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 _copy_file(self): #get the selected QTreeWidgetItem 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 = QInputDialog.getText(self, self.tr("Copy File"), self.tr("File Name:"), text=item.text(0))[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(pathForFile) path = file_manager.store_file_content(path, content, newFile=True) self.add_existing_file(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 _add_new_file(self): path = self.model().filePath(self.currentIndex()) 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(path, fileName) fileName = file_manager.store_file_content( fileName, '', newFile=True) 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 _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 _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 _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