Ejemplo n.º 1
0
 def find(self, backward=False, forward=False, rehighlight=True):
     """Collect flags and execute search in the editor"""
     main_container = IDE.get_service("main_container")
     editor = main_container.get_current_editor()
     if editor is None:
         return
     cs, wo, highlight = self.search_flags
     index, matches = 0, 0
     found = editor.find_match(self.search_text, cs, wo, backward, forward)
     if found:
         if rehighlight:
             editor.clear_found_results()
             index, matches = editor.highlight_found_results(
                 self.search_text, cs, wo)
     else:
         editor.clear_found_results()
     if matches == 0 and found:
         index, matches = editor._get_find_index_results(
             self.search_text, cs, wo)
         matches = len(matches)
         if index == 1:
             ide = IDE.get_service("ide")
             ide.show_message(translations.TR_SEARCH_FROM_TOP)
     self._line_search.counter.update_count(
         index, matches, len(self.search_text) > 0)
Ejemplo n.º 2
0
    def install(self):
        ide = IDE.get_service('ide')
        ide.place_me_on("explorer_container", self, "lateral")
        #Searching the Preferences
        self.tree_projects = None
        self._treeSymbols = None
        if settings.SHOW_SYMBOLS_LIST:
            self.add_tab_symbols()
        self._inspector = None
        if settings.SHOW_WEB_INSPECTOR and settings.WEBINSPECTOR_SUPPORTED:
            self.add_tab_inspector()
        self._listErrors = None
        if settings.SHOW_ERRORS_LIST:
            self.add_tab_errors()
        self._listMigration = None
        if settings.SHOW_MIGRATION_LIST:
            self.add_tab_migration()

        if self.count() == 0:
            central_container = IDE.get_service("central_container")
            central_container.change_explorer_visibility(force_hide=True)
        ui_tools.install_shortcuts(self, actions.ACTIONS, ide)
        for each_tab in self.__tabs:
            if hasattr(each_tab, "install"):
                each_tab.install()
Ejemplo n.º 3
0
 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
Ejemplo n.º 4
0
 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())
Ejemplo n.º 5
0
 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
Ejemplo n.º 6
0
    def __init__(self, parent):
        super(FindInFilesWidget, self).__init__(parent)
        self._main_container = IDE.get_service('main_container')
        self._explorer_container = IDE.get_service('explorer')
        self._result_widget = FindInFilesResult()
        self._open_find_button = QPushButton(translations.TR_FIND + "!")
        self._stop_button = QPushButton(translations.TR_STOP + "!")
        self._clear_button = QPushButton(translations.TR_CLEAR + "!")
        self._replace_button = QPushButton(translations.TR_REPLACE)
        self._find_widget = FindInFilesDialog(self._result_widget, self)
        self._error_label = QLabel(translations.TR_NO_RESULTS)
        self._error_label.setVisible(False)
        #Replace Area
        self.replace_widget = QWidget()
        hbox_replace = QHBoxLayout(self.replace_widget)
        hbox_replace.setContentsMargins(0, 0, 0, 0)
        self.lbl_replace = QLabel(translations.TR_REPLACE_RESULTS_WITH)
        self.lbl_replace.setTextFormat(Qt.PlainText)
        self.replace_edit = QLineEdit()
        hbox_replace.addWidget(self.lbl_replace)
        hbox_replace.addWidget(self.replace_edit)
        self.replace_widget.setVisible(False)
        #Main Layout
        main_hbox = QHBoxLayout(self)
        #Result Layout
        tree_vbox = QVBoxLayout()
        tree_vbox.addWidget(self._result_widget)
        tree_vbox.addWidget(self._error_label)
        tree_vbox.addWidget(self.replace_widget)

        main_hbox.addLayout(tree_vbox)
        #Buttons Layout
        vbox = QVBoxLayout()
        vbox.addWidget(self._open_find_button)
        vbox.addWidget(self._stop_button)
        vbox.addWidget(self._clear_button)
        vbox.addSpacerItem(
            QSpacerItem(0, 50, QSizePolicy.Fixed, QSizePolicy.Expanding))
        vbox.addWidget(self._replace_button)
        main_hbox.addLayout(vbox)

        self._open_find_button.setFocus()
        #signals
        self.connect(self._open_find_button, SIGNAL("clicked()"), self.open)
        self.connect(self._stop_button, SIGNAL("clicked()"), self._find_stop)
        self.connect(self._clear_button, SIGNAL("clicked()"),
                     self._clear_results)
        self.connect(self._result_widget,
                     SIGNAL("itemActivated(QTreeWidgetItem *, int)"),
                     self._go_to)
        self.connect(self._result_widget,
                     SIGNAL("itemClicked(QTreeWidgetItem *, int)"),
                     self._go_to)
        self.connect(self._find_widget, SIGNAL("finished()"),
                     self._find_finished)
        self.connect(self._find_widget, SIGNAL("findStarted()"),
                     self._find_started)
        self.connect(self._replace_button, SIGNAL("clicked()"),
                     self._replace_results)
Ejemplo n.º 7
0
    def _replace(self):
        """Replace one occurrence of the word"""

        status_search = IDE.get_service("status_search")
        cs, wo, highlight = status_search.search_flags
        main_container = IDE.get_service("main_container")
        editor_widget = main_container.get_current_editor()
        editor_widget.replace_match(
            status_search.search_text, self._line_replace.text(), cs, wo)
Ejemplo n.º 8
0
    def _replace_all(self, selected=False):
        """Replace all the occurrences of the word"""

        status_search = IDE.get_service("status_search")
        cs, wo, highlight = status_search.search_flags
        main_container = IDE.get_service("main_container")
        editor_widget = main_container.get_current_editor()
        editor_widget.replace_all(
            status_search.search_text, self._line_replace.text(), cs, wo)
        editor_widget.extra_selections.remove("find")
Ejemplo n.º 9
0
 def replace_all(self, selected=False):
     """Replace all the occurrences of the word."""
     status_search = IDE.get_service("status_search")
     main_container = IDE.get_service("main_container")
     editor = None
     if main_container:
         editor = main_container.get_current_editor()
     if editor:
         editor.replace_match(status_search.search_text,
                              self._lineReplace.text(), True,
                              selected)
Ejemplo n.º 10
0
 def replace(self):
     """Replace one occurrence of the word."""
     status_search = IDE.get_service("status_search")
     main_container = IDE.get_service("main_container")
     editor = None
     if main_container:
         editor = main_container.get_current_editor()
     if editor:
         editor.replace_match(status_search.search_text,
                              self._lineReplace.text())
         status_search.find()
Ejemplo n.º 11
0
 def _open_project_folder(self, folderName):
     ninjaide = IDE.get_service("ide")
     project = NProject(folderName)
     qfsm = ninjaide.filesystem.open_project(project)
     if qfsm:
         self.add_project(project)
         self.emit(SIGNAL("updateLocator()"))
         self.save_recent_projects(folderName)
         main_container = IDE.get_service('main_container')
         if main_container:
             main_container.show_editor_area()
Ejemplo n.º 12
0
 def find_occurrences(self, word):
     self._find_widget.pattern_line_edit.setText(word)
     ide = IDE.get_service('ide')
     main_container = IDE.get_service('main_container')
     editorWidget = main_container.get_current_editor()
     nproject = ide.get_project_for_file(editorWidget.ID)
     if nproject is None:
         nproject = ide.get_current_project()
     self._find_widget.dir_combo.clear()
     self._find_widget.dir_combo.addItem(nproject.path)
     self._find_widget.case_checkbox.setChecked(True)
     self._find_widget._find_in_files()
Ejemplo n.º 13
0
 def _set_focus_to_editor(self):
     status_bar = IDE.get_service("status_bar")
     tools_doock = IDE.get_service("tools_dock")
     editor_widget = self.get_current_editor()
     if status_bar.isVisible() and tools_doock.isVisible():
         status_bar.hide_status_bar()
     elif tools_doock.isVisible():
         tools_doock._hide()
     elif status_bar.isVisible():
         status_bar.hide_status_bar()
     if editor_widget is not None:
         editor_widget.extra_selections.remove("find")
         editor_widget.scrollbar().remove_marker("find")
Ejemplo n.º 14
0
    def _add_new_file(self, path=''):
        if not path:
            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() != '':
            fileName = os.path.join(path, fileName)
            ide_srv = IDE.get_service('ide')
            current_nfile = ide_srv.get_or_create_nfile(fileName)
            current_nfile.create()
            main_container = IDE.get_service('main_container')
            if main_container:
                main_container.open_file(fileName)
Ejemplo n.º 15
0
    def _add_new_file(self, path=''):
        if not path:
            path = self.model().filePath(self.currentIndex())
        result = QInputDialog.getText(self, translations.TR_NEW_FILE,
                                      translations.TR_ENTER_NEW_FILENAME + ": ")
        fileName = result[0]

        if result[1] and fileName.strip() != '':
            fileName = os.path.join(path, fileName)
            ide_srv = IDE.get_service('ide')
            current_nfile = ide_srv.get_or_create_nfile(fileName)
            current_nfile.create()
            main_container = IDE.get_service('main_container')
            if main_container:
                main_container.open_file(fileName)
Ejemplo n.º 16
0
 def _open_file(self):
     """Open the file selected."""
     path = self.pathLine.text()
     main_container = IDE.get_service("main_container")
     if main_container:
         main_container.open_file(path)
         self.emit(SIGNAL("requestHide()"))
Ejemplo n.º 17
0
    def install(self):
        """Install StatusBar as a service."""
        self.hide()
        ide = IDE.get_service('ide')
        self._codeLocator = locator_widget.LocatorWidget(ide)

        ui_tools.install_shortcuts(self, actions.ACTIONS_STATUS, ide)
Ejemplo n.º 18
0
    def add_tab_projects(self):
        if not self.tree_projects:
            self.tree_projects = tree_projects_widget.TreeProjectsWidget()
            self.addTab(self.tree_projects, self.tr('Projects'))
            self.connect(self.tree_projects, SIGNAL("runProject()"),
                self._execute_project)

            ide = IDE.get_service('ide')
            self.connect(ide, SIGNAL("goingDown()"),
                self.tree_projects.shutdown)
            self.connect(self.tree_projects,
                SIGNAL("addProjectToConsole(QString)"),
                self._add_project_to_console)
            self.connect(self.tree_projects,
                SIGNAL("removeProjectFromConsole(QString)"),
                self._remove_project_from_console)

            def close_project_signal():
                self.emit(SIGNAL("updateLocator()"))

            def close_files_related_to_closed_project(project):
                if project:
                    self.emit(SIGNAL("projectClosed(QString)"), project)
            self.connect(self.tree_projects, SIGNAL("closeProject(QString)"),
                close_project_signal)
            self.connect(self.tree_projects, SIGNAL("refreshProject()"),
                close_project_signal)
            self.connect(self.tree_projects,
                SIGNAL("closeFilesFromProjectClosed(QString)"),
                close_files_related_to_closed_project)
Ejemplo n.º 19
0
 def _open_project_folder(self, folderName):
     ninjaide = IDE.get_service("ide")
     project = NProject(folderName)
     qfsm = ninjaide.filesystem.open_project(project)
     if qfsm:
         self.add_project(project)
         self.emit(SIGNAL("updateLocator()"))
Ejemplo n.º 20
0
 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))
Ejemplo n.º 21
0
 def replace_all(self, selected=False):
     """Replace all the occurrences of the word."""
     status_search = IDE.get_service("status_search")
     s = 0 if not status_search.sensitive_checked \
         else QTextDocument.FindCaseSensitively
     w = 0 if not status_search.wholeword_checked \
         else QTextDocument.FindWholeWords
     flags = 0 + s + w
     main_container = IDE.get_service("main_container")
     editor = None
     if main_container:
         editor = main_container.get_current_editor()
     if editor:
         editor.replace_match(status_search.search_text,
             self._lineReplace.text(), flags, True,
             selected)
Ejemplo n.º 22
0
    def open_file(self, filename='', cursorPosition=-1,
                  tabIndex=None, positionIsLineNumber=False, notStart=True):
        if not filename:
            if settings.WORKSPACE:
                directory = settings.WORKSPACE
            else:
                directory = os.path.expanduser("~")
                editorWidget = self.get_current_editor()
                ninjaide = IDE.get_service('ide')
                if ninjaide:
                    current_project = ninjaide.get_current_project()
                    if current_project is not None:
                        directory = current_project
                    elif editorWidget is not None and editorWidget.ID:
                        directory = file_manager.get_folder(editorWidget.ID)
            extensions = ';;'.join(
                ['(*%s)' % e for e in
                    settings.SUPPORTED_EXTENSIONS + ['.*', '']])
            fileNames = list(QFileDialog.getOpenFileNames(self,
                self.tr("Open File"), directory, extensions))
        else:
            fileNames = [filename]
        if not fileNames:
            return

        for filename in fileNames:
            if file_manager.get_file_extension(filename) in ('jpg', 'png'):
                self.open_image(filename)
            elif file_manager.get_file_extension(filename).endswith('ui'):
                self.w = uic.loadUi(filename)
                self.w.show()
            else:
                self.__open_file(filename, cursorPosition,
                    tabIndex, positionIsLineNumber)
Ejemplo n.º 23
0
 def _open_file(self, model_index):
     path = self.model().filePath(model_index)
     main_container = IDE.get_service('main_container')
     logger.debug("tried to get main container")
     if main_container:
         logger.debug("will call open file")
         main_container.open_file(path)
Ejemplo n.º 24
0
    def install(self):
        """Install StatusBar as a service."""
        self.hide()
        ide = IDE.get_service('ide')
        ide.setStatusBar(self)

        ui_tools.install_shortcuts(self, actions.ACTIONS_STATUS, ide)
Ejemplo n.º 25
0
    def update_explorer(self):
        """Update the symbols in the Symbol Explorer when a file is saved."""
        main_container = IDE.get_service('main_container')
        if not main_container:
            return
        editorWidget = main_container.get_current_editor()
        if editorWidget:
            ext = file_manager.get_file_extension(editorWidget.ID)
            #obtain a symbols handler for this file extension
            symbols_handler = settings.get_symbols_handler(ext)
            if symbols_handler:
                source = editorWidget.toPlainText()
                if editorWidget.encoding is not None:
                    source = source.encode(editorWidget.encoding)
                if ext == 'py':
                    args = (source, True)
                else:
                    args = (source,)
                symbols = symbols_handler.obtain_symbols(*args)
                self.update_symbols(symbols, editorWidget.ID)

            #TODO: Should we change the code below similar to the code above?
            exts = settings.SYNTAX.get('python')['extension']
            if ext in exts or editorWidget.newDocument:
                self.update_errors(editorWidget.errors, editorWidget.pep8)
Ejemplo n.º 26
0
 def _add_model(self):
     ninjaide = IDE.get_service("ide")
     files = ninjaide.filesystem.get_files()
     files_data = list(files.values())
     # Update model
     old = set(self._model.keys())
     new = set([nfile.file_path for nfile in files_data])
     result = old - new
     for item in result:
         del self._model[item]
     current_editor = self._main_container.get_current_editor()
     current_path = None
     if current_editor:
         current_path = current_editor.file_path
     model = []
     for nfile in files_data:
         if nfile.file_path not in self._model:
             self._model[nfile.file_path] = 0
         neditable = ninjaide.get_or_create_editable(nfile.file_path)
         checkers = neditable.sorted_checkers
         checks = []
         for items in checkers:
             checker, color, _ = items
             if checker.dirty:
                 checks.append({"checker_text": checker.dirty_text, "checker_color": color})
         modified = neditable.document.isModified()
         model.append([nfile.file_name, nfile.file_path, checks, modified])
     if current_path:
         index = self._model[current_path]
         self._max_index = max(self._max_index, index) + 1
         self._model[current_path] = self._max_index
     model = sorted(model, key=lambda x: self._model[x[1]], reverse=True)
     self._root.set_model(model)
Ejemplo n.º 27
0
 def _filter_lines(self, filterOptions, index):
     at_start = (index == 0)
     if at_start:
         main_container = IDE.get_service('main_container')
         editorWidget = None
         if main_container:
             editorWidget = main_container.get_current_editor()
         index = 2
         if editorWidget:
             exts = settings.SYNTAX.get('python')['extension']
             file_ext = file_manager.get_file_extension(
                 editorWidget.file_path)
             if file_ext in exts:
                 filterOptions.insert(0, locator.FILTERS['files'])
             else:
                 filterOptions.insert(0, locator.FILTERS['non-python'])
             filterOptions.insert(1, editorWidget.file_path)
         self.tempLocations = [
             x for x in self.locate_symbols.get_locations()
             if x.type == filterOptions[0] and
             x.path == filterOptions[1]]
     else:
         currentItem = self._root.currentItem()
         if currentItem is not None:
             currentItem = currentItem.toVariant()
             self.tempLocations = [
                 x for x in self.locate_symbols.get_locations()
                 if x.type == currentItem[0] and
                 x.path == currentItem[2]]
     if filterOptions[index + 1].isdigit():
         self._line_jump = int(filterOptions[index + 1]) - 1
     return index + 2
Ejemplo n.º 28
0
 def _filter_this_file(self, filterOptions, index):
     at_start = (index == 0)
     if at_start:
         main_container = IDE.get_service('main_container')
         editorWidget = None
         if main_container:
             editorWidget = main_container.get_current_editor()
         index += 2
         if editorWidget:
             exts = settings.SYNTAX.get('python')['extension']
             file_ext = file_manager.get_file_extension(
                 editorWidget.file_path)
             if file_ext in exts:
                 filterOptions.insert(0, locator.FILTERS['files'])
             else:
                 filterOptions.insert(0, locator.FILTERS['non-python'])
             filterOptions.insert(1, editorWidget.file_path)
             self.tempLocations = \
                 self.locate_symbols.get_this_file_symbols(
                     editorWidget.file_path)
             search = filterOptions[index + 1].lstrip().lower()
             self.tempLocations = [x for x in self.tempLocations
                                   if x.comparison.lower().find(search) > -1]
     else:
         del filterOptions[index + 1]
         del filterOptions[index]
     return index
Ejemplo n.º 29
0
 def save_project(self):
     """Save all the opened files that belongs to the actual project."""
     if self._active_project:
         path = self._active_project.project.path
         main_container = IDE.get_service('main_container')
         if path and main_container:
             main_container.save_project(path)
Ejemplo n.º 30
0
 def _delete_file(self, path=''):
     if not path:
         path = self.model().filePath(self.currentIndex())
     val = QMessageBox.question(self, translations.TR_DELETE_FILE,
                                translations.TR_DELETE_FOLLOWING_FILE + path,
                                QMessageBox.Yes, QMessageBox.No)
     if val == QMessageBox.Yes:
         path = file_manager.create_path(path)
         main_container = ide_srv = IDE.get_service('main_container')
         if main_container and main_container.is_open(path):
             main_container.close_deleted_file(path)
         #FIXME: Manage the deletion signal instead of main container
         #fiddling here
         ide_srv = IDE.get_service('ide')
         current_nfile = ide_srv.get_or_create_nfile(path)
         current_nfile.delete()
Ejemplo n.º 31
0
 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()
Ejemplo n.º 32
0
    def install(self):
        """Install triggered by the ide."""
        self.setup_ui()
        ninjaide = IDE.get_service('ide')
        ninjaide.place_me_on("tools_dock", self, "central")
        ui_tools.install_shortcuts(self, actions.ACTIONS, ninjaide)

        self.connect(ninjaide, SIGNAL("goingDown()"), self.save_configuration)

        qsettings = IDE.ninja_settings()
        value = qsettings.value("tools_dock/visible", True, type=bool)
        self.setVisible(value)
Ejemplo n.º 33
0
 def find_occurrences(self, word):
     """Trigger the find occurrences mode with pre-search data."""
     self._find_widget.pattern_line_edit.setText(word)
     ninjaide = IDE.get_service('ide')
     editorWidget = self._main_container.get_current_editor()
     nproject = ninjaide.get_project_for_file(editorWidget.file_path)
     if nproject is None:
         nproject = ninjaide.get_current_project()
     self._find_widget.dir_combo.clear()
     self._find_widget.dir_combo.addItem(nproject.path)
     self._find_widget.case_checkbox.setChecked(True)
     self._find_widget._find_in_files()
Ejemplo n.º 34
0
 def paintEvent(self, event):
     super().paintEvent(event)
     painter = QPainter(self)
     painter.setRenderHint(QPainter.Antialiasing, True)
     r = self.width() - 10
     marks = IDE.get_service("bookmarks").bookmarks(self._neditor.file_path)
     for top, block_number, block in self._neditor.visible_blocks:
         for mark in marks:
             if mark.lineno == block_number:
                 r = QRect(0, top + 3, 16, 16)
                 mark.linetext = block.text()
                 mark.paint_icon(painter, r)
Ejemplo n.º 35
0
 def add_model(self, interpreters):
     self._model.clear()
     model = []
     for interpreter in interpreters:
         model.append([
             interpreter.display_name, interpreter.path,
             interpreter.exec_path
         ])
     self._model = model
     locator = IDE.get_service("interpreter")
     self.btn_selector.setText(locator.current.display_name)
     self.btn_selector.setEnabled(True)
Ejemplo n.º 36
0
    def _close_file(self, neditable):
        index = self.bar.close_file(neditable)
        layoutItem = self.stacked.takeAt(index)
        self.fileClosed.emit(neditable.nfile)
        layoutItem.widget().deleteLater()

        if self.stacked.isEmpty():
            self.bar.hide()
            self.allFilesClosed.emit()
            tree_symbols = IDE.get_service("symbols_explorer")
            if tree_symbols is not None:
                tree_symbols.clear()
Ejemplo n.º 37
0
 def install(self):
     self._load_ui()
     ninjaide = IDE.get_service("ide")
     ninjaide.place_me_on("tools_dock", self, "central")
     ui_tools.install_shortcuts(self, actions.ACTIONS, ninjaide)
     ninjaide.goingDown.connect(self._save_settings)
     ninja_settings = IDE.ninja_settings()
     index = int(ninja_settings.value("tools_dock/widgetVisible", -1))
     if index == -1:
         self.hide()
     else:
         self._show(index)
Ejemplo n.º 38
0
 def _open(self, path, temp):
     if temp:
         nfile = self._temp_files[temp]
         ninjaide = IDE.get_service("ide")
         neditable = ninjaide.get_or_create_editable(nfile=nfile)
         self._main_container.current_widget.set_current(neditable)
     else:
         self._main_container.open_file(path)
         index = self._model[path]
         self._max_index = max(self._max_index, index) + 1
         self._model[path] = self._max_index
     self.hide()
    def _undock_widget(self):
        tab_widget = self.widget(self._widget_index)
        bar = tab_widget.tabBar()
        index = bar.tabAt(self._point)
        widget = tab_widget.widget(index)
        widget.setParent(None)
        widget.resize(500, 500)
        widget.show()

        if tab_widget.count() == 0:
            central = IDE.get_service('central_container')
            central.change_lateral_visibility()
Ejemplo n.º 40
0
    def _change_current_project(self, index):
        nproject = self._combo_project.itemData(index)

        ninjaide = IDE.get_service("ide")
        projects = ninjaide.get_projects()
        for project in projects.values():
            if project == nproject:
                nproject.is_current = True
            else:
                project.is_current = False
        self._projects_area.setCurrentIndex(index + 1)
        self.activeProjectChanged.emit()
Ejemplo n.º 41
0
 def open(self):
     """Open the selected file in the proper line."""
     if not self._find_widget.isVisible():
         ninjaide = IDE.get_service('ide')
         actual_projects_obj = ninjaide.filesystem.get_projects()
         actual_projects = [path for path in actual_projects_obj]
         actual = ninjaide.get_current_project()
         actual_path = None
         if actual:
             actual_path = actual.path
         self._find_widget.show(actual_project=actual_projects,
                                actual=actual_path)
Ejemplo n.º 42
0
    def close_tab(self, tab_index):
        program = self.__programs[tab_index]
        self.__programs.remove(program)
        self._tabs.removeTab(tab_index)
        # Close process and delete OutputWidget
        program.main_process.close()
        program.outputw.deleteLater()
        del program.outputw

        if self._tabs.count() == 0:
            # Hide widget
            tools = IDE.get_service("tools_dock")
            tools.hide_widget(self)
Ejemplo n.º 43
0
    def install(self):
        ide = IDE.get_service('ide')
        ide.place_me_on("explorer_container", self, "lateral")

        for obj in ExplorerContainer.__TABS:
            tabname, icon = ExplorerContainer.__TABS[obj]
            self.add_tab(tabname, obj, icon)
            self.connect(obj, SIGNAL("dockWidget(PyQt_PyObject)"),
                         self._dock_widget)
            self.connect(obj, SIGNAL("undockWidget()"), self._undock_widget)

        if self.count() == 0:
            self.hide()
Ejemplo n.º 44
0
    def install(self):
        ide = IDE.get_service('ide')
        ide.place_me_on("main_container", self, "central", top=True)

        self.combo_area = combo_editor.ComboEditor(original=True)
        self.connect(self.combo_area, SIGNAL("allFilesClosed()"),
                     self._files_closed)
        self.splitter.add_widget(self.combo_area)
        self.add_widget(self.splitter)

        self.current_widget = self.combo_area

        ui_tools.install_shortcuts(self, actions.ACTIONS, ide)
Ejemplo n.º 45
0
 def render_web_page(self, url):
     """Render a webpage from the url path."""
     index_of = self.stack.indexOf(self._web)
     self._item_changed(index_of)
     self.show()
     self._web.render_page(url)
     if settings.SHOW_WEB_INSPECTOR:
         web_inspector = IDE.get_service('web_inspector')
         if web_inspector:
             web_inspector.set_inspection_page(self._web.webFrame.page())
             self._web.webFrame.triggerPageAction(
                 QWebPage.InspectElement, True)
             web_inspector.refresh_inspector()
Ejemplo n.º 46
0
 def _open_node(self, model_index):
     if self.model().isDir(model_index):
         if self.isExpanded(model_index):
             self.collapse(model_index)
         else:
             self.expand(model_index)
         return
     path = self.model().filePath(model_index)
     main_container = IDE.get_service('main_container')
     logger.debug("tried to get main container")
     if main_container:
         logger.debug("will call open file")
         main_container.open_file(path)
Ejemplo n.º 47
0
    def install(self):
        ninjaide = IDE.get_service("ide")
        ninjaide.place_me_on("main_container", self, "central", top=True)

        self.combo_area = combo_editor.ComboEditor(original=True)
        self.combo_area.allFilesClosed.connect(self._files_closed)
        self.splitter.add_widget(self.combo_area)
        self.add_widget(self.splitter)
        # self.current_widget = self.combo_area
        # Code Locator
        self._code_locator = locator_widget.LocatorWidget(ninjaide)

        ui_tools.install_shortcuts(self, actions.ACTIONS, ninjaide)
Ejemplo n.º 48
0
 def load_suggestion(self, item):
     lineno = int(item.data(Qt.UserRole))
     lines = self._migration[lineno][0].split('\n')
     code = ''
     for line in lines:
         if line.startswith('+'):
             code += '%s\n' % line[1:]
     self.suggestion.setPlainText(code)
     main_container = IDE.get_service('main_container')
     if main_container:
         editorWidget = main_container.get_current_editor()
         if editorWidget:
             editorWidget.jump_to_line(lineno)
             editorWidget.setFocus()
Ejemplo n.º 49
0
    def show_search(self):
        """Show the status bar with search widget"""

        self.current_status = _STATUSBAR_STATE_SEARCH
        self._search_widget.setVisible(True)
        self._search_widget._line_search.setFocus()
        self.show()
        main_container = IDE.get_service("main_container")
        editor_widget = main_container.get_current_editor()
        if editor_widget is not None:
            if editor_widget.selected_text():
                text = editor_widget.selected_text()
                self._search_widget._line_search.setText(text)
                self._search_widget._line_search.selectAll()
Ejemplo n.º 50
0
 def load_suggestion(self, item):
     """Take an argument item and load the suggestion."""
     lineno, code = int(item.data(Qt.UserRole)), ""
     lines = self._migration[lineno][0].split('\n')
     for line in lines:
         if line.startswith('+'):
             code += '{line_to_add}\n'.format(line_to_add=line[1:])
     self.suggestion.setPlainText(code)
     main_container = IDE.get_service('main_container')
     if main_container:
         editorWidget = main_container.get_current_editor()
         if editorWidget:
             editorWidget.jump_to_line(lineno)
             editorWidget.setFocus()
 def find(self, forward=True):
     """Collect flags and execute search in the editor."""
     reg = False
     cs = self.sensitive_checked
     wo = self.wholeword_checked
     main_container = IDE.get_service("main_container")
     editor = None
     if main_container:
         editor = main_container.get_current_editor()
     if editor:
         index, matches = editor.find_match(
             self.search_text, reg, cs, wo, forward=forward)
         self._line.counter.update_count(index, matches,
                                         len(self.search_text) > 0)
Ejemplo n.º 52
0
    def __init__(self, editor):
        super(Pep8Checker, self).__init__()
        self._editor = editor
        self._path = ''
        self._encoding = ''
        self.checks = {}

        self.checker_icon = QStyle.SP_MessageBoxWarning

        ninjaide = IDE.get_service('ide')
        self.connect(ninjaide,
                     SIGNAL("ns_preferences_editor_checkStyle(PyQt_PyObject)"),
                     lambda: remove_pep8_checker())
        self.connect(self, SIGNAL("checkerCompleted()"), self.refresh_display)
Ejemplo n.º 53
0
    def __init__(self, parent=None):
        super(NewProjectManager, self).__init__(parent, Qt.Dialog)
        self.setWindowTitle(translations.TR_NEW_PROJECT)
        self.setMinimumHeight(500)
        vbox = QVBoxLayout(self)
        vbox.addWidget(QLabel(translations.TR_CHOOSE_TEMPLATE))
        vbox.addWidget(QLabel(translations.TR_TAB_PROJECTS))

        hbox = QHBoxLayout()
        self.list_projects = QListWidget()
        self.list_projects.setProperty("wizard", True)
        hbox.addWidget(self.list_projects)

        self.list_templates = QListWidget()
        self.list_templates.setProperty("wizard", True)
        hbox.addWidget(self.list_templates)

        self.text_info = QTextBrowser()
        self.text_info.setProperty("wizard", True)
        hbox.addWidget(self.text_info)

        vbox.addLayout(hbox)

        button_box = QDialogButtonBox(QDialogButtonBox.Cancel
                                      | QDialogButtonBox.Ok)
        choose_button = button_box.button(QDialogButtonBox.Ok)
        choose_button.setText(translations.TR_CHOOSE)
        # hbox2 = QHBoxLayout()
        # cancel = QPushButton(translations.TR_CANCEL)
        # choose = QPushButton(translations.TR_CHOOSE)
        # hbox2.addSpacerItem(QSpacerItem(1, 0, QSizePolicy.Expanding,
        #                    QSizePolicy.Fixed))
        # hbox2.addWidget(cancel)
        # hbox2.addWidget(choose)
        # vbox.addLayout(button_box)
        vbox.addWidget(button_box)

        self.template_registry = IDE.get_service("template_registry")
        categories = self.template_registry.list_project_categories()
        for category in categories:
            self.list_projects.addItem(category)

        button_box.accepted.connect(self.accept)
        button_box.rejected.connect(self.reject)
        # cancel.clicked.connect(self.close)
        # choose.clicked.connect(self._start_wizard)
        self.list_projects.itemSelectionChanged.connect(self._project_selected)
        self.list_templates.itemSelectionChanged.connect(
            self._template_selected)
        self.list_projects.setCurrentRow(0)
Ejemplo n.º 54
0
 def _load_symbols(self, neditable):
     symbols_handler = handlers.get_symbols_handler('py')
     source = neditable.editor.toPlainText()
     source = source.encode(neditable.editor.encoding)
     symbols, symbols_simplified = symbols_handler.obtain_symbols(
         source, simple=True)
     self._symbols_index = sorted(symbols_simplified.keys())
     symbols_simplified = sorted(
         list(symbols_simplified.items()), key=lambda x: x[0])
     self.bar.add_symbols(symbols_simplified)
     line = neditable.editor.textCursor().blockNumber()
     self._set_current_symbol(line, True)
     tree_symbols = IDE.get_service('symbols_explorer')
     tree_symbols.update_symbols_tree(symbols, neditable.file_path)
 def _preview_style(self):
     scheme = self._listScheme.currentItem().text()
     if scheme == self.current_scheme:
         return
     main_container = IDE.get_service('main_container')
     if not main_container:
         return
     editorWidget = main_container.get_current_editor()
     if editorWidget is not None:
         resources.CUSTOM_SCHEME = self._schemes.get(
             scheme, resources.COLOR_SCHEME)
         editorWidget.restyle(editorWidget.lang)
         self._modified_editors.append(editorWidget)
     self.current_scheme = scheme
Ejemplo n.º 56
0
    def hide_all(self):
        """ Hide/Show all the containers except the editor """

        toolbar = IDE.get_service('toolbar')
        if (self.lateral_panel.isVisible() or toolbar.isVisible()):
            if self.lateral_panel:
                self.lateral_panel.hide()
            if toolbar:
                toolbar.hide()
        else:
            if self.lateral_panel:
                self.lateral_panel.show()
            if toolbar:
                toolbar.show()
Ejemplo n.º 57
0
 def execute_file(self):
     """Execute the current file"""
     main_container = IDE.get_service("main_container")
     editor_widget = main_container.get_current_editor()
     if editor_widget is not None and (editor_widget.is_modified
                                       or editor_widget.file_path):
         main_container.save_file(editor_widget)
         # FIXME: Emit a signal for plugin!
         # self.fileExecuted.emit(editor_widget.file_path)
         file_path = editor_widget.file_path
         extension = file_manager.get_file_extension(file_path)
         # TODO: Remove the IF statment and use Handlers
         if extension == "py":
             self.start_process(filename=file_path)
Ejemplo n.º 58
0
 def find_previous(self):
     """Find the previous occurrence of the word to search."""
     self.find(forward=False)
     if self.totalMatches > 0 and self.index > 1:
         self.index -= 1
     elif self.totalMatches > 0:
         self.index = self.totalMatches
         main_container = IDE.get_service("main_container")
         editor = None
         if main_container:
             editor = main_container.get_current_editor()
         if editor:
             self.find(forward=False)
     self._line.counter.update_count(self.index, self.totalMatches)
Ejemplo n.º 59
0
    def _notify_editor_changed(self):
        """
        Lets search widget know that the editor contents changed and find
        needs to be re-run
        """
        if self._searchWidget.isVisible():
            main_container = IDE.get_service("main_container")
            if main_container:
                editor = main_container.get_current_editor()
            else:
                return

            if editor:
                self._searchWidget.contents_changed(editor)
Ejemplo n.º 60
0
 def hide_status(self):
     """Hide the Status Bar and its widgets."""
     self.hide()
     self._searchWidget._checkSensitive.setCheckState(Qt.Unchecked)
     self._searchWidget._checkWholeWord.setCheckState(Qt.Unchecked)
     self._searchWidget.setVisible(False)
     self._replaceWidget.setVisible(False)
     self._fileSystemOpener.setVisible(False)
     main_container = IDE.get_service("main_container")
     widget = None
     if main_container:
         widget = main_container.get_current_widget()
     if widget:
         widget.setFocus()