Exemplo n.º 1
0
    def __init__(self, parent):
        QWidget.__init__(self, parent)
        self._main_container = main_container.MainContainer()
        self._explorer_container = explorer_container.ExplorerContainer()
        self._result_widget = FindInFilesResult()
        self._open_find_button = QPushButton(self.tr("Find!"))
        self._stop_button = QPushButton(self.tr("Stop"))
        self._clear_button = QPushButton(self.tr("Clear!"))
        self._replace_button = QPushButton(self.tr("Replace"))
        self._find_widget = FindInFilesDialog(self._result_widget, self)
        self._error_label = QLabel(self.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(self.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)
Exemplo n.º 2
0
    def _advanced_filter(self, filterOptions):
        was_this_file = filterOptions[0] == FILTERS['this-file']
        if was_this_file:
            previous_filter = filterOptions[0]
            filterOptions[0] = FILTERS['files']
            main = main_container.MainContainer()
            editorWidget = main.get_actual_editor()
            if editorWidget:
                filterOptions.insert(1, editorWidget.ID)
            if previous_filter == FILTERS['lines']:
                filterOptions.insert(2, ':')
        elif filterOptions[0] in (FILTERS['classes'], FILTERS['files'],
                                  FILTERS['tabs']):
            currentItem = self.frame.listWidget.currentItem()
            if type(currentItem) is LocateItem:
                if currentItem._data.type in (FILTERS['files'],
                                              FILTERS['classes']):
                    self._filterData = currentItem._data
            if filterOptions[0] == FILTERS['classes']:
                filterOptions.insert(0, FILTERS['files'])
                filterOptions.insert(1, self._filterData.path)
            else:
                filterOptions[1] = self._filterData.path
        if was_this_file and len(filterOptions) > 4:
            currentItem = self.frame.listWidget.currentItem()
            if type(currentItem) is LocateItem:
                if currentItem._data.type == FILTERS['classes']:
                    self._filterData = currentItem._data
        global mapping_locations
        filePath = filterOptions[1]

        moveIndex = 0
        if len(filterOptions) > 4 and filterOptions[2] == FILTERS['classes']:
            moveIndex = 2
            if self._filterData.type == FILTERS['classes']:
                self._classFilter = self._filterData.name
            symbols = self._parent._thread.get_symbols_for_class(
                filePath, self._classFilter)
            self.tempLocations = [
                x for x in symbols if x.type == filterOptions[4]
            ]
        elif len(filterOptions) == 4 and filterOptions[2] == FILTERS['lines']:
            self.tempLocations = [
                x for x in self.tempLocations if x.path == filePath
            ]
            if filterOptions[3].isdigit():
                self._line_jump = int(filterOptions[3]) - 1
                return
        else:
            self.tempLocations = [
                x for x in mapping_locations.get(filePath, [])
                if x.type == filterOptions[2]
            ]
        moveIndex += 3
        if len(filterOptions) > moveIndex and filterOptions[moveIndex]:
            self.tempLocations = [
                x for x in self.tempLocations
                if x.comparison.lower().find(filterOptions[moveIndex]) > -1
            ]
Exemplo n.º 3
0
 def setUp(self):
     super(StatusBarTestCase, self).setUp()
     self.app = QApplication(sys.argv)
     self.parent = gui.FakeParent()
     self.patch(main_container.editor, 'Editor', gui.FakeEditor)
     self.main = main_container.MainContainer(None)
     self.main._parent = self.parent
     self.status = status_bar.StatusBar()
Exemplo n.º 4
0
 def handle_tab_changed(self, new_tab):
     """
     Re-run search if tab changed, we use the find of search widget because
     we want the widget to be updated.
     """
     if self._searchWidget.isVisible():
         editor = main_container.MainContainer().get_actual_editor()
         self._searchWidget.find_matches(editor)
Exemplo n.º 5
0
 def message_end(self, message):
     if message == '':
         self.hide()
         QStatusBar.clearMessage(self)
         self._widgetStatus.show()
         widget = main_container.MainContainer().get_actual_widget()
         if widget:
             widget.setFocus()
Exemplo n.º 6
0
 def _open_result(self, item, col):
     filename = unicode(item.toolTip(1))
     line = int(item.text(2)) - 1
     main_container.MainContainer().open_file(
             fileName=filename,
             cursorPosition=line,
             positionIsLineNumber=True)
     self._parent.hide()
Exemplo n.º 7
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():
         editor = main_container.MainContainer().get_actual_editor()
         self._searchWidget.contents_changed(editor)
Exemplo n.º 8
0
 def go_to_error(self, event):
     cursor = self.cursorForPosition(event.pos())
     text = cursor.block().text()
     if self.patLink.match(text):
         file_path, lineno = self._parse_traceback(unicode(text))
         main = main_container.MainContainer()
         main.open_file(file_path)
         main.editor_jump_to_line(lineno=int(lineno) - 1)
Exemplo n.º 9
0
 def find_previous(self):
     s = 0 if not self._searchWidget._checkSensitive.isChecked() \
         else QTextDocument.FindCaseSensitively
     w = 0 if not self._searchWidget._checkWholeWord.isChecked() \
         else QTextDocument.FindWholeWords
     flags = 1 + s + w
     editor = main_container.MainContainer().get_actual_editor()
     if editor:
         editor.find_match(self._searchWidget._line.text(), flags, True)
Exemplo n.º 10
0
 def show_replace(self):
     self.clearMessage()
     self.show()
     editor = main_container.MainContainer().get_actual_editor()
     if editor:
         if editor.textCursor().hasSelection():
             word = editor.textCursor().selectedText()
             self._searchWidget._line.setText(word)
     self._replaceWidget.setVisible(True)
Exemplo n.º 11
0
    def load_ui(self, centralWidget):
        #Set Application Font for ToolTips
        QToolTip.setFont(QFont(settings.FONT_FAMILY, 10))
        #Create Main Container to manage Tabs
        self.mainContainer = main_container.MainContainer(self)
        self.connect(self.mainContainer, SIGNAL("currentTabChanged(QString)"),
                     self.change_window_title)
        self.connect(self.mainContainer,
                     SIGNAL("locateFunction(QString, QString, bool)"),
                     self.actions.locate_function)
        self.connect(self.mainContainer, SIGNAL("navigateCode(bool, int)"),
                     self.actions.navigate_code_history)
        self.connect(self.mainContainer, SIGNAL("addBackItemNavigation()"),
                     self.actions.add_back_item_navigation)
        self.connect(self.mainContainer, SIGNAL("updateFileMetadata()"),
                     self.actions.update_explorer)
        self.connect(self.mainContainer, SIGNAL("updateLocator(QString)"),
                     self.actions.update_explorer)
        self.connect(self.mainContainer, SIGNAL("openPreferences()"),
                     self._show_preferences)
        self.connect(self.mainContainer, SIGNAL("dontOpenStartPage()"),
                     self._dont_show_start_page_again)
        self.connect(self.mainContainer, SIGNAL("currentTabChanged(QString)"),
                     self.status.handle_tab_changed)
        # Update symbols
        self.connect(self.mainContainer, SIGNAL("updateLocator(QString)"),
                     self.status.explore_file_code)
        #Create Explorer Panel
        self.explorer = explorer_container.ExplorerContainer(self)
        self.connect(self.central, SIGNAL("splitterCentralRotated()"),
                     self.explorer.rotate_tab_position)
        self.connect(self.explorer, SIGNAL("updateLocator()"),
                     self.status.explore_code)
        self.connect(self.explorer, SIGNAL("goToDefinition(int)"),
                     self.actions.editor_go_to_line)
        self.connect(self.explorer, SIGNAL("projectClosed(QString)"),
                     self.actions.close_files_from_project)
        #Create Misc Bottom Container
        self.misc = misc_container.MiscContainer(self)
        self.connect(self.mainContainer, SIGNAL("findOcurrences(QString)"),
                     self.misc.show_find_occurrences)

        centralWidget.insert_central_container(self.mainContainer)
        centralWidget.insert_lateral_container(self.explorer)
        centralWidget.insert_bottom_container(self.misc)
        self.connect(self.mainContainer,
                     SIGNAL("cursorPositionChange(int, int)"),
                     self.central.lateralPanel.update_line_col)
        # TODO: Change current symbol on move
        #self.connect(self.mainContainer,
        #SIGNAL("cursorPositionChange(int, int)"),
        #self.explorer.update_current_symbol)
        self.connect(self.mainContainer, SIGNAL("enabledFollowMode(bool)"),
                     self.central.enable_follow_mode_scrollbar)

        if settings.SHOW_START_PAGE:
            self.mainContainer.show_start_page()
Exemplo n.º 12
0
 def go_to_error(self, event):
     """Resolve the link and take the user to the error line."""
     cursor = self.cursorForPosition(event.pos())
     text = cursor.block().text()
     if self.patLink.match(text):
         file_path, lineno = self._parse_traceback(text)
         main = main_container.MainContainer()
         main.open_file(file_path)
         main.editor_jump_to_line(lineno=int(lineno) - 1)
Exemplo n.º 13
0
 def _open_item(self, data):
     """Open the item received."""
     main = main_container.MainContainer()
     if file_manager.get_file_extension(data.path) in ('jpg', 'png'):
         main.open_image(data.path)
     else:
         if self._line_jump != -1:
             main.open_file(data.path, self._line_jump, None, True)
         else:
             main.open_file(data.path, data.lineno, None, True)
Exemplo n.º 14
0
 def show(self):
     self.clearMessage()
     QStatusBar.show(self)
     editor = main_container.MainContainer().get_actual_editor()
     if editor and editor.textCursor().hasSelection():
         text = editor.textCursor().selectedText()
         self._searchWidget._line.setText(text)
     if self._widgetStatus.isVisible():
         self._searchWidget._line.setFocus()
         self._searchWidget._line.selectAll()
Exemplo n.º 15
0
 def find_previous(self):
     self._parent.find_previous()
     if self.totalMatches > 0 and self.index > 1:
         self.index -= 1
     elif self.totalMatches > 0:
         self.index = self.totalMatches
         editor = main_container.MainContainer().get_actual_editor()
         editor.moveCursor(QTextCursor.End)
         self._parent.find_previous()
     self._line.counter.update_count(self.index, self.totalMatches)
Exemplo n.º 16
0
 def replace_all(self):
     s = 0 if not self._searchWidget._checkSensitive.isChecked() \
         else QTextDocument.FindCaseSensitively
     w = 0 if not self._searchWidget._checkWholeWord.isChecked() \
         else QTextDocument.FindWholeWords
     flags = 0 + s + w
     editor = main_container.MainContainer().get_actual_editor()
     if editor:
         editor.replace_match(unicode(self._searchWidget._line.text()),
             unicode(self._replaceWidget._lineReplace.text()), flags, True)
Exemplo n.º 17
0
 def hide_status(self):
     self._searchWidget._checkSensitive.setCheckState(Qt.Unchecked)
     self._searchWidget._checkWholeWord.setCheckState(Qt.Unchecked)
     self.hide()
     self._searchWidget.setVisible(True)
     self._replaceWidget.setVisible(False)
     self._codeLocator.setVisible(False)
     self._fileSystemOpener.setVisible(False)
     widget = main_container.MainContainer().get_actual_widget()
     if widget:
         widget.setFocus()
Exemplo n.º 18
0
 def load_suggestion(self, item):
     lineno = int(item.data(Qt.UserRole))
     lines = self._migration.migration_data[lineno][0].split('\n')
     code = ''
     for line in lines:
         if line.startswith('+'):
             code += '%s\n' % line[1:]
     self.suggestion.setPlainText(code)
     editorWidget = main_container.MainContainer().get_actual_editor()
     if editorWidget:
         editorWidget.jump_to_line(lineno)
         editorWidget.setFocus()
Exemplo n.º 19
0
    def filter(self):
        self.items_in_page = 0
        #Clean the objects from the listWidget
        inCurrentFile = False
        filterOptions = self.advancePrefix.split(
            unicode(self.__prefix).lstrip())
        if filterOptions[0] == '':
            del filterOptions[0]

        if len(filterOptions) > 2:
            if FILTERS['files'] in (filterOptions[1], filterOptions[2]):
                self._advanced_filter_by_file(filterOptions)
            else:
                self._advanced_filter(filterOptions)
            return self._create_list_widget_items(self.tempLocations)
        # Clear frame after advance filter because advance filter
        # ask for the first element in the popup
        self.tempLocations = []
        self.frame.clear()

        #if the user type any of the prefix
        if self.filterPrefix.match(self.__prefix):
            filterOption = self.__prefix[:1]
            #if the prefix is "." it means only the metadata of current file
            if filterOption == FILTERS['this-file']:
                inCurrentFile = True
                main = main_container.MainContainer()
                editorWidget = main.get_actual_editor()
                if editorWidget:
                    self.tempLocations = \
                        self._parent._thread.get_this_file_locations(
                            editorWidget.ID)
                    self.__prefix = unicode(self.__prefix)[1:].lstrip()
                    self.tempLocations = [x for x in self.tempLocations \
                        if x.comparison.lower().find(self.__prefix) > -1]
            else:
                #Is not "." filter by the other options
                self.tempLocations = [
                    x for x in self._parent._thread.get_locations()
                    if x.type == filterOption
                ]
                #Obtain the user input without the filter prefix
                self.__prefix = unicode(self.__prefix)[1:].lstrip()
        else:
            self.tempLocations = self._parent._thread.get_locations()

        if self.__prefix and not inCurrentFile:
            #if prefix (user search now) is not empty, filter words that1
            #contain the user input
            self.tempLocations = [x for x in self.tempLocations \
                if x.comparison.lower().find(self.__prefix) > -1]

        return self._create_list_widget_items(self.tempLocations)
Exemplo n.º 20
0
 def handle_tab_changed(self, new_tab):
     """
     Re-run search if tab changed, we use the find of search widget because
     we want the widget to be updated.
     """
     editor = main_container.MainContainer().get_actual_editor()
     if self._searchWidget.isVisible():
         self._searchWidget.find_matches(editor)
     if editor:
         self.disconnect(editor, SIGNAL("textChanged()"),
                         self._notify_editor_changed)
         self.connect(editor, SIGNAL("textChanged()"),
                      self._notify_editor_changed)
Exemplo n.º 21
0
 def _delete_file(self):
     item = self.currentItem()
     val = QMessageBox.question(self, self.tr("Delete File"),
             self.tr("Do you want to delete the following file: ") \
             + os.path.join(item.path, unicode(item.text(0))),
             QMessageBox.Yes, QMessageBox.No)
     if val == QMessageBox.Yes:
         path = file_manager.create_path(item.path, unicode(item.text(0)))
         file_manager.delete_file(item.path, unicode(item.text(0)))
         self.removeItemWidget(item, 0)
         mainContainer = main_container.MainContainer()
         if mainContainer.is_open(path):
             mainContainer.close_deleted_file(path)
Exemplo n.º 22
0
 def _editor_title(self):
     editorWidget = main_container.MainContainer().get_actual_editor()
     if editorWidget:
         editorWidget.textCursor().beginEditBlock()
         if editorWidget.textCursor().hasSelection():
             text = editorWidget.textCursor().selectedText().title()
         else:
             text = editorWidget._text_under_cursor().title()
             editorWidget.moveCursor(QTextCursor.StartOfWord)
             editorWidget.moveCursor(QTextCursor.EndOfWord,
                                     QTextCursor.KeepAnchor)
         editorWidget.textCursor().insertText(text)
         editorWidget.textCursor().endEditBlock()
Exemplo n.º 23
0
 def replace(self):
     s = 0 if not self._searchWidget._checkSensitive.isChecked() \
         else QTextDocument.FindCaseSensitively
     w = 0 if not self._searchWidget._checkWholeWord.isChecked() \
         else QTextDocument.FindWholeWords
     flags = 0 + s + w
     editor = main_container.MainContainer().get_actual_editor()
     if editor:
         editor.replace_match(self._searchWidget._line.text(),
                              self._replaceWidget._lineReplace.text(),
                              flags)
     if not editor.textCursor().hasSelection():
         self.find()
Exemplo n.º 24
0
 def find_occurrences(self, word):
     self._find_widget.pattern_line_edit.setText(word)
     editorWidget = main_container.MainContainer().get_actual_editor()
     explorerContainer = explorer_container.ExplorerContainer()
     projects_obj = explorerContainer.get_opened_projects()
     projects = [p.path for p in projects_obj]
     project = explorerContainer.get_actual_project()
     for p in projects:
         if file_manager.belongs_to_folder(p, editorWidget.ID):
             project = p
             break
     self._find_widget.dir_combo.clear()
     self._find_widget.dir_combo.addItem(project)
     self._find_widget._find_in_files()
Exemplo n.º 25
0
 def _delete_file(self):
     item = self.currentItem()
     val = QMessageBox.question(self, self.tr("Delete File"),
                    self.tr("Do you want to delete the following file: ")
                    + os.path.join(item.path, item.text(0)),
                    QMessageBox.Yes, QMessageBox.No)
     if val == QMessageBox.Yes:
         path = file_manager.create_path(item.path, item.text(0))
         file_manager.delete_file(item.path, item.text(0))
         index = item.parent().indexOfChild(item)
         item.parent().takeChild(index)
         mainContainer = main_container.MainContainer()
         if mainContainer.is_open(path):
             mainContainer.close_deleted_file(path)
Exemplo n.º 26
0
 def keyPressEvent(self, event):
     editor = main_container.MainContainer().get_actual_editor()
     if editor is None:
         super(TextLine, self).keyPressEvent(event)
         return
     if editor and event.key() in \
     (Qt.Key_Enter, Qt.Key_Return):
         self._parent.find_next()
         return
     super(TextLine, self).keyPressEvent(event)
     if int(event.key()) in range(32, 162) or \
     event.key() == Qt.Key_Backspace:
         has_replace = self._parent._parent._replaceWidget.isVisible()
         if not has_replace:
             self._parent.find_matches(editor)
Exemplo n.º 27
0
 def __init__(self):
     QObject.__init__(self)
     self._main = main_container.MainContainer()
     self._action = actions.Actions()
     self._explorer = explorer_container.ExplorerContainer()
     #Connect signals
     self.connect(self._main, SIGNAL("editorKeyPressEvent(QEvent)"),
                  self._keyPressEvent)
     self.connect(self._main, SIGNAL("beforeFileSaved(QString)"),
                  self._beforeFileSaved)
     self.connect(self._main, SIGNAL("fileSaved(QString)"), self._fileSaved)
     self.connect(self._main, SIGNAL("currentTabChanged(QString)"),
                  self._currentTabChanged)
     self.connect(self._action, SIGNAL("fileExecuted(QString)"),
                  self._fileExecuted)
     self.connect(self._main, SIGNAL("fileOpened(QString)"),
                  self._fileOpened)
Exemplo n.º 28
0
 def open_project_folder(self, folderName='', notIDEStart=True):
     if not self._treeProjects and notIDEStart:
         QMessageBox.information(
             self, self.tr("Projects Disabled"),
             self.tr("Project support has been disabled from Preferences"))
         return
     if not folderName:
         if settings.WORKSPACE:
             directory = settings.WORKSPACE
         else:
             directory = os.path.expanduser("~")
             current_project = self.get_actual_project()
             mainContainer = main_container.MainContainer()
             editorWidget = mainContainer.get_actual_editor()
             if current_project is not None:
                 directory = current_project
             elif editorWidget is not None and editorWidget.ID:
                 directory = file_manager.get_folder(editorWidget.ID)
         folderName = unicode(
             QFileDialog.getExistingDirectory(
                 self, self.tr("Open Project Directory"), directory))
     try:
         if not folderName:
             return
         if not self._treeProjects.is_open(folderName):
             self._treeProjects.mute_signals = True
             self._treeProjects.loading_project(folderName)
             thread = ui_tools.ThreadProjectExplore()
             self._thread_execution[folderName] = thread
             self.connect(thread,
                          SIGNAL("folderDataAcquired(PyQt_PyObject)"),
                          self._callback_open_project)
             self.connect(thread, SIGNAL("finished()"),
                          self._unmute_tree_signals_clean_threads)
             thread.open_folder(folderName)
         else:
             self._treeProjects._set_current_project(folderName)
     except Exception, reason:
         logger.error('open_project_folder: %s', reason)
         if not notIDEStart:
             QMessageBox.information(
                 self, self.tr("Incorrect Project"),
                 self.tr("The project could not be loaded!"))
Exemplo n.º 29
0
    def apply_changes(self):
        lineno = int(self.current_list.currentItem().data(Qt.UserRole))
        lines = self._migration.migration_data[lineno][0].split('\n')
        remove = -1
        code = ''
        for line in lines:
            if line.startswith('-'):
                remove += 1
            elif line.startswith('+'):
                code += '%s\n' % line[1:]

        editorWidget = main_container.MainContainer().get_actual_editor()
        block_start = editorWidget.document().findBlockByLineNumber(lineno)
        block_end = editorWidget.document().findBlockByLineNumber(lineno +
                                                                  remove)
        cursor = editorWidget.textCursor()
        cursor.setPosition(block_start.position())
        cursor.setPosition(block_end.position(), QTextCursor.KeepAnchor)
        cursor.movePosition(QTextCursor.EndOfLine, QTextCursor.KeepAnchor)
        cursor.insertText(code[:-1])
Exemplo n.º 30
0
 def keyPressEvent(self, event):
     editor = main_container.MainContainer().get_actual_editor()
     if editor is None:
         super(TextLine, self).keyPressEvent(event)
         return
     if editor and event.key() in \
     (Qt.Key_Enter, Qt.Key_Return):
         self._parent.find_next()
         return
     elif event.modifiers() == Qt.ControlModifier and \
     event.key() == Qt.Key_Right:
         self._parent.find_next()
         return
     elif event.modifiers() == Qt.ControlModifier and \
     event.key() == Qt.Key_Left:
         self._parent.find_previous()
         return
     super(TextLine, self).keyPressEvent(event)
     if int(event.key()) in range(32, 162) or \
     event.key() == Qt.Key_Backspace:
         self._parent.find_matches(editor)