예제 #1
0
 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)
     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))
예제 #2
0
 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))
예제 #3
0
 def _add_file_to_project(self, path):
     pathProject = [self.ide.explorer.get_actual_project()]
     addToProject = ui_tools.AddToProject(pathProject, self.ide)
     addToProject.exec_()
     if not addToProject.pathSelected:
         return
     editorWidget = self.ide.mainContainer.get_actual_editor()
     if not editorWidget.ID:
         name = unicode(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(
         unicode(addToProject.pathSelected), name)
     try:
         path = file_manager.store_file_content(
             path, editorWidget.get_text(), newFile=True)
         editorWidget.ID = path
         self.ide.explorer.add_existing_file(path)
         self.ide.change_window_title(path)
         name = file_manager.get_basename(path)
         self.ide.mainContainer.actualTab.setTabText(
             self.ide.mainContainer.actualTab.currentIndex(), name)
         editorWidget._file_saved()
     except file_manager.NinjaFileExistsException, ex:
         QMessageBox.information(self, self.tr("File Already Exists"),
             self.tr("Invalid Path: the file '%s' already exists." % \
                 ex.filename))
예제 #4
0
 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))