Ejemplo n.º 1
0
class FilesHandler(QWidget):

    def __init__(self, parent=None):
        super(FilesHandler, self).__init__(
            None, Qt.FramelessWindowHint | Qt.Popup)
        self.setAttribute(Qt.WA_TranslucentBackground)
        self._main_container = parent
        # Create the QML user interface.
        self.setFixedHeight(300)
        self.setFixedWidth(400)
        self.view = QQuickWidget()
        self.view.rootContext().setContextProperty(
            "theme", resources.QML_COLORS)
        self.view.setResizeMode(QQuickWidget.SizeRootObjectToView)
        self.view.setSource(ui_tools.get_qml_resource("FilesHandler.qml"))
        self._root = self.view.rootObject()
        vbox = QVBoxLayout(self)
        vbox.setContentsMargins(0, 0, 0, 0)
        vbox.setSpacing(0)
        vbox.addWidget(self.view)

        self._model = {}
        self._temp_files = {}
        self._max_index = 0

        self._root.open.connect(self._open)
        self._root.close.connect(self._close)
        self._root.fuzzySearch.connect(self._fuzzy_search)
        self._root.hide.connect(self.hide)

    def _open(self, path, temp, project):
        if project:
            path = os.path.join(os.path.split(project)[0], path)
            self._main_container.open_file(path)
        elif temp:
            nfile = self._temp_files[temp]
            ninjaide = IDE.get_service("ide")
            neditable = ninjaide.get_or_create_editable(nfile=nfile)
            self._main_container.combo_area.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 _close(self, path, temp):
        # FIXME: when we have splitters?
        if temp:
            nfile = self._temp_files.get(temp, None)
        else:
            ninjaide = IDE.get_service("ide")
            nfile = ninjaide.get_or_create_nfile(path)
        if nfile is not None:
            nfile.close()

    def _fuzzy_search(self, search):
        search = '.+'.join(re.escape(search).split('\\ '))
        pattern = re.compile(search, re.IGNORECASE)

        model = []
        for project_path in locator.files_paths:
            files_in_project = locator.files_paths[project_path]
            base_project = os.path.basename(project_path)
            for file_path in files_in_project:
                file_path = os.path.join(
                    base_project, os.path.relpath(file_path, project_path))
                if pattern.search(file_path):
                    model.append([os.path.basename(file_path), file_path,
                                  project_path])
        self._root.set_fuzzy_model(model)

    def _add_model(self):
        ninjaide = IDE.get_service("ide")
        files = ninjaide.opened_files
        # Update model
        current_editor = self._main_container.get_current_editor()
        current_path = None
        if current_editor is not None:
            current_path = current_editor.file_path
        model = []
        for nfile in files:
            if nfile.file_path is not None and \
                    nfile.file_path not in self._model:
                self._model[nfile.file_path] = 0
            neditable = ninjaide.get_or_create_editable(nfile=nfile)
            checkers = neditable.sorted_checkers
            checks = []
            for item in checkers:
                checker, color, _ = item
                if checker.dirty:
                    checks.append({
                        "checker_text": checker.dirty_text,
                        "checker_color": color
                    })
            modified = neditable.editor.is_modified
            temp_file = str(uuid.uuid4()) if nfile.file_path is None else ""
            filepath = nfile.file_path if nfile.file_path is not None else ""
            model.append([
                nfile.file_name, filepath,
                checks, modified, temp_file])
            if temp_file:
                self._temp_files[temp_file] = nfile
        if current_path is not None:
            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.get(x[1], False),
                       reverse=True)
        self._root.set_model(model)

    def showEvent(self, event):
        self._add_model()
        editor_widget = self._main_container.get_current_editor()
        simple = False
        if editor_widget.height() < 400 or editor_widget.width() < 350:
            width = editor_widget.width()
            height = self._main_container.height() / 3
            simple = True
        else:
            width = max(editor_widget.width() / 3, 550)
            height = max(editor_widget.height() / 2, 400)

        self.setFixedWidth(width)
        self.setFixedHeight(height)

        self._root.setMode(simple)
        super(FilesHandler, self).showEvent(event)
        point = editor_widget.mapToGlobal(self.view.pos())
        self.move(point)
        # Trick
        QTimer.singleShot(100, self.__set_focus)

    def __set_focus(self):
        self.view.setFocus()
        self._root.activateInput()

    def hideEvent(self, event):
        super(FilesHandler, self).hideEvent(event)
        self._temp_files = {}
        self._root.clear_model()
        # Recovery focus
        editor_widget = self._main_container.get_current_editor()
        if editor_widget is not None:
            editor_widget.setFocus()

    def next_item(self):
        if not self.isVisible():
            self.show()

    def previous_item(self):
        if not self.isVisible():
            self.show()
        self._root.previous_item()

    def keyPressEvent(self, event):
        if event.key() == Qt.Key_Escape:
            self.hide()
        elif (event.modifiers() == Qt.ControlModifier and
                event.key() == Qt.Key_Tab):
            self._root.next_item()
        elif (event.modifiers() == Qt.ControlModifier and
                event.key() == Qt.Key_PageDown) or event.key() == Qt.Key_Down:
            self._root.next_item()
        elif (event.modifiers() == Qt.ControlModifier and
                event.key() == Qt.Key_PageUp) or event.key() == Qt.Key_Up:
            self._root.previous_item()
        elif event.key() in (Qt.Key_Return, Qt.Key_Enter):
            self._root.open_item()
        super(FilesHandler, self).keyPressEvent(event)
Ejemplo n.º 2
0
class FilesHandler(QWidget):

    def __init__(self, parent=None):
        super(FilesHandler, self).__init__(
            None, Qt.FramelessWindowHint | Qt.Popup)
        self.setAttribute(Qt.WA_TranslucentBackground)
        self._main_container = parent
        # Create the QML user interface.
        self.setFixedHeight(300)
        self.setFixedWidth(400)
        self.view = QQuickWidget()
        self.view.rootContext().setContextProperty(
            "theme", resources.QML_COLORS)
        self.view.setResizeMode(QQuickWidget.SizeRootObjectToView)
        self.view.setSource(ui_tools.get_qml_resource("FilesHandler.qml"))
        # self.view.setClearColor(Qt.transparent)
        self._root = self.view.rootObject()
        vbox = QVBoxLayout(self)
        vbox.setContentsMargins(0, 0, 0, 0)
        vbox.setSpacing(0)
        vbox.addWidget(self.view)

        self._model = {}
        self._temp_files = {}
        self._max_index = 0

        self._root.open.connect(self._open)
        self._root.close.connect(self._close)
        self._root.fuzzySearch.connect(self._fuzzy_search)
        self._root.hide.connect(self.hide)

    def _open(self, path, temp, project):
        if project:
            path = os.path.join(os.path.split(project)[0], path)
            self._main_container.open_file(path)
        elif temp:
            nfile = self._temp_files[temp]
            ninjaide = IDE.get_service("ide")
            neditable = ninjaide.get_or_create_editable(nfile=nfile)
            self._main_container.combo_area.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 _close(self, path, temp):
        # FIXME: when we have splitters?
        if temp:
            nfile = self._temp_files.get(temp, None)
        else:
            ninjaide = IDE.get_service("ide")
            nfile = ninjaide.get_or_create_nfile(path)
        if nfile is not None:
            nfile.close()

    def _fuzzy_search(self, search):
        search = '.+'.join(re.escape(search).split('\\ '))
        pattern = re.compile(search, re.IGNORECASE)

        model = []
        for project_path in locator.files_paths:
            files_in_project = locator.files_paths[project_path]
            base_project = os.path.basename(project_path)
            for file_path in files_in_project:
                file_path = os.path.join(
                    base_project, os.path.relpath(file_path, project_path))
                if pattern.search(file_path):
                    model.append([os.path.basename(file_path), file_path,
                                  project_path])
        self._root.set_fuzzy_model(model)

    def _add_model(self):
        ninjaide = IDE.get_service("ide")
        files = ninjaide.opened_files
        # Update model
        current_editor = self._main_container.get_current_editor()
        current_path = None
        if current_editor is not None:
            current_path = current_editor.file_path
        model = []
        for nfile in files:
            if nfile.file_path is not None and \
                    nfile.file_path not in self._model:
                self._model[nfile.file_path] = 0
            neditable = ninjaide.get_or_create_editable(nfile=nfile)
            checkers = neditable.sorted_checkers
            checks = []
            for item in checkers:
                checker, color, _ = item
                if checker.dirty:
                    checks.append({
                        "checker_text": checker.dirty_text,
                        "checker_color": color
                    })
            modified = neditable.editor.is_modified
            temp_file = str(uuid.uuid4()) if nfile.file_path is None else ""
            filepath = nfile.file_path if nfile.file_path is not None else ""
            model.append([
                nfile.file_name, filepath,
                checks, modified, temp_file])
            if temp_file:
                self._temp_files[temp_file] = nfile
        if current_path is not None:
            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.get(x[1], False),
                       reverse=True)
        self._root.set_model(model)

    def showEvent(self, event):
        self._add_model()
        editor_widget = self._main_container.get_current_editor()
        simple = False
        if editor_widget.height() < 400 or editor_widget.width() < 350:
            width = editor_widget.width()
            height = self._main_container.height() / 3
            simple = True
        else:
            width = max(editor_widget.width() / 3, 550)
            height = max(editor_widget.height() / 2, 400)

        self.setFixedWidth(width)
        self.setFixedHeight(height)

        self._root.setMode(simple)
        super(FilesHandler, self).showEvent(event)
        # self._root.show_animation()
        point = editor_widget.mapToGlobal(self.view.pos())
        self.move(point)
        # Trick
        QTimer.singleShot(100, self.__set_focus)

    def __set_focus(self):
        self.view.setFocus()
        self._root.activateInput()

    def hideEvent(self, event):
        super(FilesHandler, self).hideEvent(event)
        self._temp_files = {}
        self._root.clear_model()
        # Recovery focus
        editor_widget = self._main_container.get_current_editor()
        if editor_widget is not None:
            editor_widget.setFocus()

    def next_item(self):
        if not self.isVisible():
            self.show()
        # self._root.next_item()

    def previous_item(self):
        if not self.isVisible():
            self.show()
        self._root.previous_item()

    def keyPressEvent(self, event):
        if event.key() == Qt.Key_Escape:
            self.hide()
        elif (event.modifiers() == Qt.ControlModifier and
                event.key() == Qt.Key_Tab):
            self._root.next_item()
        elif (event.modifiers() == Qt.ControlModifier and
                event.key() == Qt.Key_PageDown) or event.key() == Qt.Key_Down:
            self._root.next_item()
        elif (event.modifiers() == Qt.ControlModifier and
                event.key() == Qt.Key_PageUp) or event.key() == Qt.Key_Up:
            self._root.previous_item()
        elif event.key() in (Qt.Key_Return, Qt.Key_Enter):
            self._root.open_item()
        super(FilesHandler, self).keyPressEvent(event)
Ejemplo n.º 3
0
class AddFileFolderWidget(QDialog):
    """LocatorWidget class with the Logic for the QML UI"""
    def __init__(self, parent=None):
        super(AddFileFolderWidget,
              self).__init__(parent, Qt.Dialog | Qt.FramelessWindowHint)
        self._main_container = parent
        self.setModal(True)
        self.setAttribute(Qt.WA_TranslucentBackground)
        self.setStyleSheet("background:transparent;")
        self.setFixedHeight(70)
        self.setFixedWidth(650)
        # Create the QML user interface.
        self.view = QQuickWidget()
        self.view.setResizeMode(QQuickWidget.SizeRootObjectToView)
        self.view.setSource(ui_tools.get_qml_resource("AddFileFolder.qml"))
        self._root = self.view.rootObject()
        vbox = QVBoxLayout(self)
        vbox.setContentsMargins(0, 0, 0, 0)
        vbox.setSpacing(0)
        vbox.addWidget(self.view)

        self._base_path = ""

        self._create_file_operation = True

        self._root.create.connect(self._create)

    def create_file(self, base_path, project_path):
        self._create_file_operation = True
        self._base_path = project_path
        base_path = os.path.relpath(base_path, project_path)
        self._root.setDialogType(self._create_file_operation)
        self._root.setBasePath(base_path + os.path.sep)
        self.show()

    def create_folder(self, base_path, project_path):
        self._create_file_operation = False
        self._base_path = project_path
        base_path = os.path.relpath(base_path, project_path)
        self._root.setDialogType(self._create_file_operation)
        self._root.setBasePath(base_path + os.path.sep)
        self.show()

    def showEvent(self, event):
        """Method takes an event to show the Notification"""
        super(AddFileFolderWidget, self).showEvent(event)
        ninjaide = IDE.get_service("ide")
        point = self._main_container.mapToGlobal(self.view.pos())
        x = point.x() + (ninjaide.width() / 2) - (self.width() / 2)
        self.move(x, point.y())
        self.view.setFocus()
        self._root.activateInput()

    def _create(self, path):
        """Open the item received."""
        if self._create_file_operation:
            path = os.path.join(self._base_path, path)
            folder = os.path.split(path)[0]
            if not os.path.exists(folder):
                file_manager.create_folder(folder)
            ninjaide = IDE.getInstance()
            current_nfile = ninjaide.get_or_create_nfile(path)
            current_nfile.create()
            main_container = IDE.get_service('main_container')
            if main_container:
                main_container.open_file(path)
        else:
            path = os.path.join(self._base_path, path)
            if not os.path.exists(path):
                file_manager.create_folder(path)
        self.hide()

    def hideEvent(self, event):
        super(AddFileFolderWidget, self).hideEvent(event)
        self._root.cleanText()
Ejemplo n.º 4
0
class FilesHandler(QFrame):
#Qt.WindowStaysOnTopHint | 
    def __init__(self, parent=None):#SplashScreen
        super(FilesHandler, self).__init__(None, Qt.SplashScreen)#, Qt.Popup | Qt.FramelessWindowHint
        # self.setAttribute(Qt.WA_TranslucentBackground)
        # self.setStyleSheet("background:transparent;")
        #self.setStyleSheet("background-color: rgb(25, 255, 60);")
        self.setWindowState(Qt.WindowActive)# | Qt.SplashScreen
        self.setAttribute(Qt.WA_AlwaysStackOnTop, False)
        # Create the QML user interface.
        self._main_container = parent.container#IDE.get_service('main_container')
        self.comboParent = parent
        # self.rawObj = raww(self)

        self.view = QQuickWidget()
        self.view.setResizeMode(QQuickWidget.SizeRootObjectToView)
        self.view.engine().quit.connect(self.hide)
        # self.view.rootContext().setContextProperty("rawObj", self.rawObj)
        self.view.setSource(ui_tools.get_qml_resource("FilesHandler.qml"))
        self._root = self.view.rootObject()
        vbox = QVBoxLayout(self)
        vbox.setContentsMargins(0, 0, 0, 0)
        vbox.setSpacing(0)
        vbox.addWidget(self.view)

        self._model = {}
        self._temp_files = {}
        self._max_index = 0


        # QApplication.instance().focusChanged["QWidget*", "QWidget*"].connect(\
        #     lambda w1, w2: print("\n\n:focusChanged:", w1, w1.geometry() if w1\
        #     else "_No es un widget",  w2, w2.geometry() if w2 else "_No es un widget"))

        QApplication.instance().focusChanged["QWidget*", "QWidget*"].connect(\
            lambda w1, w2, this=self: this.hide() if w1 == this.view else None)

        self._root.open.connect(self._open)
        self._root.close.connect(self._close)
        self._root.hide.connect(self.hide)
        self._root.fuzzySearch.connect(self._fuzzy_search)
        #QTimer.singleShot(15000, lambda: print("QTimer::", self.show()))

        # self._root.setVisible(True)

    def _open(self, path, temp, project):
        if project:
            path = os.path.join(os.path.split(project)[0], path)
            self._main_container.open_file(path)
        elif temp:
            nfile = self._temp_files[temp]
            ninjaide = IDE.getInstance()
            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 _close(self, path, temp):
        if temp:
            nfile = self._temp_files.get(temp, None)
        else:
            ninjaide = IDE.getInstance()
            nfile = ninjaide.get_or_create_nfile(path)
        if nfile is not None:
            nfile.close()

    def _fuzzy_search(self, search):
        search = '.+'.join(re.escape(search).split('\\ '))
        pattern = re.compile(search, re.IGNORECASE)

        model = []
        for project_path in locator.files_paths:
            files_in_project = locator.files_paths[project_path]
            base_project = os.path.basename(project_path)
            for file_path in files_in_project:
                file_path = os.path.join(
                    base_project, os.path.relpath(file_path, project_path))
                if pattern.search(file_path):
                    model.append([os.path.basename(file_path), file_path,
                                  project_path])
        self._root.set_fuzzy_model(model)

    def _add_model(self):
        print("_add_model:_add_model")
        ninjaide = IDE.getInstance()
        files = ninjaide.opened_files
        # print("_add_model::", files, "\n", self._model.keys())
        # Update model
        # old = set(self._model.keys())
        # now = set([nfile.file_path for nfile in files])
        # new = old - now
        # for item in new:
        #     del self._model[item]

        past = set(self._model.keys())
        now = set([nfile.file_path for nfile in files])
        old = past - now
        # print("\n_model:past:", past)
        # print("\n_model:now:", now)
        # print("\n_model:old:", old)
        for item in old:
            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 = []
        # print("len(files)", len(files), [nfile.file_path for nfile in files], "\n\n")
        for nfile in files:
            if (nfile.file_path not in self._model and
                    nfile.file_path is not None):
                self._model[nfile.file_path] = 0
            neditable = ninjaide.get_or_create_editable(nfile=nfile)
            checkers = neditable.sorted_checkers
            checks = []
            for items in checkers:
                checker, color, _ = items
                if checker.dirty:
                    # Colors needs to be reversed for QML
                    color = "#%s" % color[::-1]
                    checks.append(
                        {"checker_text": checker.dirty_text,
                         "checker_color": color})
            modified = neditable.editor.is_modified
            temp_file = str(uuid.uuid4()) if nfile.file_path is None else ""
            filepath = nfile.file_path if nfile.file_path is not None else ""
            model.append([nfile.file_name, filepath, checks, modified,
                          temp_file])
            if temp_file:
                self._temp_files[temp_file] = nfile
        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.get(x[1], False),
                       reverse=True)
        self._root.set_model(model)

    def showEvent(self, event):
        print("\nshowEvent:::showEvent")
        self._add_model()
        widget = self._main_container.get_current_editor()
        if widget is None:
            widget = self._main_container
        if self._main_container.splitter.count() < 2:
            width = max(widget.width() / 2, 500)
            height = max(widget.height() / 2, 400)
        else:
            width = widget.width()
            height = widget.height()
        self.view.setFixedWidth(width)
        self.view.setFixedHeight(height)

        super(FilesHandler, self).showEvent(event)
        self._root.show_animation()
        point = widget.mapToGlobal(self.view.pos())
        self.move(point.x(), point.y())
        self.view.setFocus()
        self._root.activateInput()
        # QTimer.singleShot(5000, lambda item=self._root.childItems()[0].childItems()[0]:\
        #     print("QTimer::", item, item.hasActiveFocus(), item.scopedFocusItem(),\
        #         item.hasFocus(), item.isFocusScope() ))

    def hideEvent(self, event):
        print("\nhideEvent:::")
        super(FilesHandler, self).hideEvent(event)
        self._temp_files = {}
        self._root.clear_model()

    def next_item(self):
        print("next_item()", self)
        if not self.isVisible():
            self.show()
        self._root.next_item()

    def previous_item(self):
        print("previous_item()", self)
        if not self.isVisible():
            self.show()
        self._root.previous_item()

    def keyPressEvent(self, event):
        print("keyPressEvent()", event.key(), event.key() == Qt.Key_Escape)
        if event.key() == Qt.Key_Escape:
            self.hide()
        elif (event.modifiers() == Qt.ControlModifier and
                event.key() == Qt.Key_PageDown) or event.key() == Qt.Key_Down:
            self._root.next_item()
        elif (event.modifiers() == Qt.ControlModifier and
                event.key() == Qt.Key_PageUp) or event.key() == Qt.Key_Up:
            self._root.previous_item()
        elif event.key() in (Qt.Key_Return, Qt.Key_Enter):
            self._root.open_item()
        # elif event.key() == Qt.Key_Asterisk):
        #     print("keyPressEvent()", self,self.isVisible())
        super(FilesHandler, self).keyPressEvent(event)

    def mousePressEvent(self, event):
        if QApplication.instance().widgetAt( self.mapToGlobal(event.pos()) ) == self.comboParent:
            event.ignore()
            self.comboParent.hidePopup()
            return
        super(FilesHandler, self).mousePressEvent(event)


    def hideEvent(self, event):
        print("hideEvent()", event)
        super(FilesHandler, self).hideEvent(event)
Ejemplo n.º 5
0
class FilesHandler(QWidget):
    def __init__(self, parent=None):
        super(FilesHandler, self).__init__(None,
                                           Qt.FramelessWindowHint | Qt.Popup)
        self._main_container = parent
        self.setStyleSheet("background:transparent;")
        # Create the QML user interface.
        self.view = QQuickWidget()
        self.view.setResizeMode(QQuickWidget.SizeRootObjectToView)
        self.view.setSource(ui_tools.get_qml_resource("FilesHandler.qml"))
        self._root = self.view.rootObject()
        vbox = QVBoxLayout(self)
        vbox.setContentsMargins(0, 0, 0, 0)
        vbox.setSpacing(0)
        vbox.addWidget(self.view)

        self._model = {}
        self._temp_files = {}
        self._max_index = 0

        self._root.open['QString', 'QString', 'QString'].connect(self._open)
        self._root.hide.connect(self.hide)
        # self.connect(self._root, SIGNAL("open(QString, QString, QString)"),
        #             self._open)
        # self.connect(self._root, SIGNAL("close(QString, QString)"), self._close)
        # self.connect(self._root, SIGNAL("hide()"), self.hide)
        # self.connect(self._root, SIGNAL("fuzzySearch(QString)"),
        #             self._fuzzy_search)

    def _open(self, path, temp, project):
        if project:
            path = os.path.join(os.path.split(project)[0], path)
            self._main_container.open_file(path)
        elif 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 _close(self, path, temp):
        if temp:
            nfile = self._temp_files.get(temp, None)
        else:
            ninjaide = IDE.get_service("ide")
            nfile = ninjaide.get_or_create_nfile(path)
        if nfile is not None:
            nfile.close()

    def _fuzzy_search(self, search):
        search = '.+'.join(re.escape(search).split('\\ '))
        pattern = re.compile(search, re.IGNORECASE)

        model = []
        for project_path in locator.files_paths:
            files_in_project = locator.files_paths[project_path]
            base_project = os.path.basename(project_path)
            for file_path in files_in_project:
                file_path = os.path.join(
                    base_project, os.path.relpath(file_path, project_path))
                if pattern.search(file_path):
                    model.append(
                        [os.path.basename(file_path), file_path, project_path])
        self._root.set_fuzzy_model(model)

    def _add_model(self):
        ninjaide = IDE.get_service("ide")
        files = ninjaide.opened_files
        # Update model
        old = set(self._model.keys())
        new = set([nfile.file_path for nfile in files])
        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:
            if (nfile.file_path not in self._model
                    and nfile.file_path is not None):
                self._model[nfile.file_path] = 0
            neditable = ninjaide.get_or_create_editable(nfile=nfile)
            checkers = neditable.sorted_checkers
            checks = []
            for items in checkers:
                checker, color, _ = items
                if checker.dirty:
                    # Colors needs to be reversed for QML
                    color = "#%s" % color[::-1][:-1]
                    checks.append({
                        "checker_text": checker.dirty_text,
                        "checker_color": color
                    })
            modified = neditable.editor.is_modified
            temp_file = str(uuid.uuid4()) if nfile.file_path is None else ""
            filepath = nfile.file_path if nfile.file_path is not None else ""
            model.append(
                [nfile.file_name, filepath, checks, modified, temp_file])
            if temp_file:
                self._temp_files[temp_file] = nfile
        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.get(x[1], False),
                       reverse=True)
        self._root.set_model(model)

    def showEvent(self, event):
        self._add_model()
        widget = self._main_container.get_current_editor()
        if widget is None:
            widget = self._main_container
        if self._main_container.splitter.count() < 2:
            width = max(widget.width() / 2, 500)
            height = max(widget.height() / 2, 400)
        else:
            width = widget.width()
            height = widget.height()
        self.view.setFixedWidth(width)
        self.view.setFixedHeight(height)

        super(FilesHandler, self).showEvent(event)
        self._root.show_animation()
        point = widget.mapToGlobal(self.view.pos())
        self.move(point.x(), point.y())
        self.view.setFocus()
        self._root.activateInput()

    def hideEvent(self, event):
        super(FilesHandler, self).hideEvent(event)
        self._temp_files = {}
        self._root.clear_model()

    def next_item(self):
        if not self.isVisible():
            self.show()
        self._root.next_item()

    def previous_item(self):
        if not self.isVisible():
            self.show()
        self._root.previous_item()

    def keyPressEvent(self, event):
        if event.key() == Qt.Key_Escape:
            self.hide()
        elif (event.modifiers() == Qt.ControlModifier and event.key()
              == Qt.Key_PageDown) or event.key() == Qt.Key_Down:
            self._root.next_item()
        elif (event.modifiers() == Qt.ControlModifier
              and event.key() == Qt.Key_PageUp) or event.key() == Qt.Key_Up:
            self._root.previous_item()
        elif event.key() in (Qt.Key_Return, Qt.Key_Enter):
            self._root.open_item()
        super(FilesHandler, self).keyPressEvent(event)
class FilesHandler(QFrame):
    #Qt.WindowStaysOnTopHint |
    _changedForJava = pyqtSignal()

    def __init__(self, combofiles, Force_Free=False):  #SplashScreen
        super(FilesHandler, self).__init__(
            None, Qt.SplashScreen)  #, Qt.Popup | Qt.FramelessWindowHint
        # self.setAttribute(Qt.WA_TranslucentBackground)
        # self.setStyleSheet("background:transparent;")
        # self.setStyleSheet("background-color: rgb(25, 255, 60);")
        self.setWindowState(Qt.WindowActive)  # | Qt.SplashScreen
        # self.setAttribute(Qt.WA_AlwaysStackOnTop, False)
        # Create the QML user interface.
        self._main_container = combofiles.container  #IDE.get_service('main_container')
        self.comboParent = combofiles
        self.Force_Free = combofiles.undocked or Force_Free
        # self.rawObj = raww(self)

        self.view = QQuickWidget()
        self.view.setResizeMode(QQuickWidget.SizeRootObjectToView)
        self.view.engine().quit.connect(self.hide)
        # self.view.rootContext().setContextProperty("rawObj", self.rawObj)
        self.view.setSource(ui_tools.get_qml_resource("FilesHandler.qml"))
        self._root = self.view.rootObject()
        cntx = self.view.rootContext()
        cntx.setProperty("tools", Tools())
        self._contextMenu_Incert = self._root.property("_window_")

        vbox = QVBoxLayout(self)
        vbox.setContentsMargins(0, 0, 0, 0)
        vbox.setSpacing(0)
        vbox.addWidget(self.view)

        # {"name": model[i][0],
        # "path": model[i][1],
        # "checkers": model[i][2],
        # "modified": model[i][3],
        # "tempFile": model[i][4],
        # "project": "",
        # "itemVisible": true});

        self._ntup = ("name", "path", "checkers", "modified", "tempFile",
                      "project", "itemVisible")
        # self._Ndtup = namedtuple("_Ndtup", self._ntup)

        self._filePathPosition = {}
        self._filesModel = []
        self._temp_files = {}
        self._max_index = 0
        print("\n\nFilesHandler", self, self._contextMenu_Incert)

        # QApplication.instance().focusChanged["QWidget*", "QWidget*"].connect(\
        #     lambda w1, w2: print("\n\n:focusChanged:", w1, w1.geometry() if w1\
        #     else "_No es un widget",  w2, w2.geometry() if w2 else "_No es un widget"))

        QApplication.instance().focusChanged["QWidget*", "QWidget*"].connect(\
            lambda old, now, this=self:  print("\n\n:focusChanged:", this.hide(), old, now) if old == this.view else None)

        self._root.open.connect(self._open)
        self._root.close.connect(self._close)
        self._root.hide.connect(self.hide)
        self._root.fuzzySearch.connect(self._fuzzy_search)
        #QTimer.singleShot(15000, lambda: print("QTimer::", self.show()))

        # self._root.setVisible(True)

    def _open(self, path, temp, project):
        print("\n\n_open", path, "|", temp, "|", project, "|", self)
        if project:
            path = os.path.join(os.path.split(project)[0], path)
            self._main_container.open_file(path)
        elif temp:
            nfile = self._temp_files[temp]
            ninjaide = IDE.getInstance()
            neditable = ninjaide.get_or_create_editable(nfile=nfile)
            print("nfile", nfile, neditable, self._temp_files, temp)
            self._main_container.current_comboEditor.set_current(neditable)
        else:
            # self._main_container.open_file(path)
            # self._main_container.open_file_from_nEditable(self.comboParent.get_editable_fromPath(path),\
            # self.comboParent.ParentalComboEditor)
            self.comboParent.ParentalComboEditor.set_current(\
                self.comboParent.get_editable_fromPath(path) )

            index = self._filePathPosition[path]
            self._max_index = max(self._max_index, index) + 1
            self._filePathPosition[path] = self._max_index
        self.hide()

    def _close(self, path, temp):
        if temp:
            nfile = self._temp_files.get(temp, None)
        else:
            ninjaide = IDE.getInstance()
            nfile = ninjaide.get_or_create_nfile(path)
        if nfile is not None:
            nfile.close()

    def _fuzzy_search(self, search):
        search = '.+'.join(re.escape(search).split('\\ '))
        pattern = re.compile(search, re.IGNORECASE)

        model = []
        for project_path in locator.files_paths:
            files_in_project = locator.files_paths[project_path]
            base_project = os.path.basename(project_path)
            for file_path in files_in_project:
                file_path = os.path.join(
                    base_project, os.path.relpath(file_path, project_path))
                if pattern.search(file_path):
                    model.append(
                        [os.path.basename(file_path), file_path, project_path])
        self._root.set_fuzzy_model(model)

    def getNewIndex(self):
        self._max_index += 1
        return self._max_index - 1

    def currentEditable(self):
        return self.comboParent.get_editable()

    def removeFile(self, nedit):
        self.removeFilePath(nedit.file_path)

    def removeFilePath(self, path):
        # del self._filesModel[self._filePathPosition[path]]
        del self._filePathPosition[path]
        self._changedForJava.emit()

    @pyqtProperty(QJsonValue, notify=_changedForJava)
    def fileModel(self):
        return self._filesModel

    def add_Data(self, dat):
        self._filesModel.append(dict(zip(self._tup, dat)))
        # sort by Path
        model = sorted(self._filesModel,\
            key=lambda x: self._filePathPosition.get(x[1], False), reverse=True)

        self._filesModel = model
        self._changedForJava.emit()

    def addFile(self, neditable):
        nfile = neditable.nfile
        current_editor = ninjaide.getCurrentEditor()

        current_path = current_editor.file_path if current_editor else ""
        model = []
        if nfile.file_path not in self._filePathPosition and nfile.file_path is not None:
            self._filePathPosition[
                nfile.file_path] = 0  # default position for NEW FILE

        checkers = neditable.sorted_checkers
        checks = []
        for items in checkers:
            checker, color, _ = items
            if checker.dirty:
                # Colors needs to be reversed for QML
                color = "#%s" % color[::-1]
                checks.append({
                    "checker_text": checker.dirty_text,
                    "checker_color": color
                })

        modified = neditable.editor.is_modified
        temp_file = str(uuid.uuid4()) if nfile.file_path is None else ""
        filepath = nfile.file_path if nfile.file_path is not None else ""

        if temp_file:
            self._temp_files[temp_file] = nfile

        self.add_Data( (nfile.file_name, filepath, checks, modified, temp_file,\
            "", current_path and current_path != nfile.file_path) )

    def _add_model(self):
        # print("_add_model:_add_model")
        ninjaide = IDE.getInstance()
        #files = ninjaide.opened_files# list<neditable>
        # if True:#self.Force_Free:
        #     files = self.comboParent.opened_files
        # else:
        #     files = ninjaide.opened_files

        files = self.comboParent.opened_files
        print("_add_model::", len(files))
        past = set(self._filePathPosition.keys())
        now = set([neditable.file_path for neditable in files])
        old = past - now
        # print("\n_model:past:", past)
        # print("\n_model:now:", now)
        # print("\n_model:old:", old)

        # Update model
        for item in old:
            # print("\n to Delete", item)
            del self._filePathPosition[item]

        current_editor = ninjaide.getCurrentEditor()
        # if current_editor.neditable != self.currentEditable():
        #     QMessageBox.critical(None, "current_editor", "el QSCiEditor que la aplicación dice que es el actual\n"\
        #         "NO coincide con el Editor de éste FilesHandler()")

        current_path = current_editor.file_path if current_editor else ""
        model = []
        # print("len(files)", len(files), [nfile.file_path for nfile in files], "\n\n")
        for neditable in files:
            nfile = neditable.nfile

            if nfile.file_path not in self._filePathPosition and nfile.file_path is not None:
                self._filePathPosition[nfile.file_path] = self.getNewIndex()

            # print("\n_add_model->", not self.Force_Free, type(nfile))
            # if not self.Force_Free:
            #     neditable = ninjaide.get_or_create_editable_EXTERNAL(nfile=nfile)

            # print("\n_add_model->->", neditable, self._filePathPosition, neditable.editor)

            checkers = neditable.sorted_checkers
            checks = []
            for items in checkers:
                checker, color, _ = items
                if checker.dirty:
                    # Colors needs to be reversed for QML
                    color = "#%s" % color[::-1][:-1]
                    checks.append({
                        "checker_text": checker.dirty_text,
                        "checker_color": color
                    })

            modified = neditable.editor.is_modified
            temp_file = str(uuid.uuid4()) if nfile.file_path is None else ""
            filepath = nfile.file_path if nfile.file_path is not None else ""
            model.append([
                nfile.file_name, filepath, checks, modified, temp_file, "",
                current_path and current_path != nfile.file_path
            ])
            if temp_file:
                self._temp_files[temp_file] = nfile

        # if current_path:
        #     index = self._filePathPosition[current_path]
        #     self._max_index = max(self._max_index, index) + 1
        #     self._filePathPosition[current_path] = self._max_index

        # print("\n\nmodel:1:", self._filePathPosition, "\n///", model)
        # sort by Path
        model = sorted(model,
                       key=lambda x: self._filePathPosition.get(x[1], False),
                       reverse=True)
        # print("\n\nmodel:2:", model)
        self._root.set_model(model)

    def showEvent(self, event):
        print("\nshowEvent:::showEvent", self.isVisible(),
              self.view.isVisible())
        self._add_model()
        widget = self.comboParent.ParentalComboEditor.currentEditor()
        if widget is None:
            widget = self._main_container

        if self._main_container.splitter.count() < 2:
            width = max(widget.width() / 2, 500)
            height = max(widget.height() / 2, 400)
        else:
            width = widget.width()
            height = widget.height()
        self.view.setFixedWidth(width)
        self.view.setFixedHeight(height)

        point = widget.mapToGlobal(self.view.pos())
        self.move(point.x(), point.y())
        super(FilesHandler, self).showEvent(event)
        self._root.show_animation()
        self.view.setFocus()
        self._root.activateInput()

    def hideEvent(self, event):
        print("\nhideEvent:::", self.isVisible(), self.view.isVisible())
        super(FilesHandler, self).hideEvent(event)
        self._temp_files = {}
        self._root.clear_model()

    def next_item(self):
        print("next_item()", self)
        if not self.isVisible():
            self.show()
        self._root.next_item()

    def previous_item(self):
        print("previous_item()", self)
        if not self.isVisible():
            self.show()
        self._root.previous_item()

    def keyPressEvent(self, event):
        print("keyPressEvent()", event.key(), event.key() == Qt.Key_Escape)
        if event.key() == Qt.Key_Escape:
            self.hide()
        elif (event.modifiers() == Qt.ControlModifier and event.key()
              == Qt.Key_PageDown) or event.key() == Qt.Key_Down:
            self._root.next_item()
        elif (event.modifiers() == Qt.ControlModifier
              and event.key() == Qt.Key_PageUp) or event.key() == Qt.Key_Up:
            self._root.previous_item()
        elif event.key() in (Qt.Key_Return, Qt.Key_Enter):
            self._root.open_item()
        # elif event.key() == Qt.Key_Asterisk):
        #     print("keyPressEvent()", self,self.isVisible())
        super(FilesHandler, self).keyPressEvent(event)

    def mousePressEvent(self, event):
        print("\n\nFILESHANDLER.mousePressEvent",
              QApplication.instance().widgetAt(self.mapToGlobal(event.pos())))
        if QApplication.instance().widgetAt(self.mapToGlobal(
                event.pos())) == self.comboParent:
            print("TRUE!!!")
            # event.ignore()
            # self.comboParent.hidePopup()
            return
        super(FilesHandler, self).mousePressEvent(event)