int PythonScriptViewWidget::addPluginEditor(const QString &fileName) {
    PythonCodeEditor *codeEditor = new PythonCodeEditor();
    codeEditor->setGraph(pythonScriptView->getGraph());
    codeEditor->setFileName(fileName);
    codeEditor->installEventFilter(pythonScriptView);
    codeEditor->setFocus(Qt::ActiveWindowFocusReason);
    connect(codeEditor, SIGNAL(textChanged()), this, SLOT(pluginScriptTextChanged()));
    int idx = pluginsTabWidget->addTab(codeEditor, "");
    pluginsTabWidget->setCurrentIndex(idx);
    return idx;
}
void PythonEditorsTabWidget::indicateErrors(const QMap<QString, QVector<int> > &errorLines) {
  for (int i = 0 ; i < count() ; ++i) {
    QString moduleFile = getEditor(i)->getFileName();

    if (errorLines.find(moduleFile) != errorLines.end()) {
      const QVector<int> &linesErrorNumbers = errorLines[moduleFile];
      PythonCodeEditor *codeEditor = getEditor(i);

      for (int i = 0 ; i < linesErrorNumbers.size() ; ++i) {
        codeEditor->indicateScriptCurrentError(linesErrorNumbers[i]-1);
      }
    }
  }
}
int PythonEditorsTabWidget::addEditor(const QString &fileName) {
  PythonCodeEditor *codeEditor = new PythonCodeEditor();

  QFileInfo fileInfo(fileName);
  codeEditor->loadCodeFromFile(fileName);
  codeEditor->analyseScriptCode(true);
  codeEditor->setFocus(Qt::ActiveWindowFocusReason);
  codeEditor->installEventFilter(this);
  connect(codeEditor, SIGNAL(textChanged()), this, SLOT(scriptTextChanged()));
  int idx = addTab(codeEditor, fileInfo.fileName());
  setTabToolTip(idx, fileInfo.absoluteFilePath());
  setCurrentIndex(idx);

  if (_fontZoom < 0) {
    for (int i = _fontZoom ; i < 0 ; ++i) {
      codeEditor->zoomOut();
    }
  }

  if (_fontZoom > 0) {
    for (int i = _fontZoom ; i > 0 ; --i) {
      codeEditor->zoomIn();
    }
  }

  return idx;
}
bool PythonEditorsTabWidget::reloadCodeInEditorIfNeeded(int index) {
  PythonCodeEditor *codeEditor = getEditor(index);
  QString fileName = codeEditor->getFileName();

  if (fileName != "") {
    QFileInfo fileInfo(fileName);

    if (fileInfo.exists() && fileInfo.lastModified() != codeEditor->getLastSavedTime()) {
      if (codeEditor->loadCodeFromFile(fileName)) {
        setTabText(index, fileInfo.fileName());
      }

      return true;
    }
  }

  return false;
}
void PythonScriptViewWidget::scrollToEditorLine(const QUrl & link) {
    QStringList strList = link.toString().split(":");
    QString file = strList.at(0);
    int line = strList.at(1).toInt()-1;

    if (file == "<unnamed script>") {
        tabWidget->setCurrentIndex(0);
        scrollToLine(getCurrentMainScriptEditor(), line);
        return;
    }

    for (int i = 0 ; i < mainScriptsTabWidget->count() ; ++i) {
        PythonCodeEditor *codeEditor = getMainScriptEditor(i);

        if (file == codeEditor->getFileName()) {
            tabWidget->setCurrentIndex(0);
            mainScriptsTabWidget->setCurrentIndex(i);
            scrollToLine(codeEditor, line);
            return;
        }
    }

    for (int i = 0 ; i < modulesTabWidget->count() ; ++i) {
        PythonCodeEditor *codeEditor = getModuleEditor(i);

        if (file == codeEditor->getFileName()) {
            tabWidget->setCurrentIndex(1);
            modulesTabWidget->setCurrentIndex(i);
            scrollToLine(codeEditor, line);
            return;
        }
    }

    for (int i = 0 ; i < pluginsTabWidget->count() ; ++i) {
        PythonCodeEditor *codeEditor = getPluginEditor(i);

        if (file == codeEditor->getFileName()) {
            tabWidget->setCurrentIndex(3);
            pluginsTabWidget->setCurrentIndex(i);
            scrollToLine(codeEditor, line);
            return;
        }
    }
}