예제 #1
0
  /**
   * Sadly, we have to restore all pydev editors that have a different icon to make it correct.
   *
   * <p>See https://bugs.eclipse.org/bugs/show_bug.cgi?id=308740
   */
  private void restoreAllPydevEditorsWithDifferentIcon() {
    if (!PyTitlePreferencesPage.useCustomInitIcon()) {
      return;
    }
    Job job =
        new Job("Invalidate images") {

          @Override
          protected IStatus run(IProgressMonitor monitor) {
            try {
              while (PydevPlugin.isAlive()
                  && !doRestoreAllPydevEditorsWithDifferentIcons()) { // stop trying if the plugin
                // is stopped
                synchronized (this) {
                  try {
                    Thread.sleep(200);
                  } catch (InterruptedException e) {
                    // ignore.
                  }
                }
              }
              ;
            } finally {
              jobPool.removeJob(this);
            }
            return Status.OK_STATUS;
          }
        };
    job.setPriority(Job.SHORT);
    jobPool.addJob(job);
  }
예제 #2
0
  public void propertyChange(PropertyChangeEvent event) {
    // When the
    String property = event.getProperty();
    if (PyTitlePreferencesPage.isTitlePreferencesProperty(property)) {

      Job job =
          new Job("Invalidate title") {

            @Override
            protected IStatus run(IProgressMonitor monitor) {
              try {
                List<IEditorReference> currentEditorReferences;
                do {
                  currentEditorReferences = getCurrentEditorReferences();
                  synchronized (this) {
                    try {
                      Thread.sleep(200);
                    } catch (InterruptedException e) {
                      // ignore.
                    }
                  }
                } while (PydevPlugin.isAlive()
                    && currentEditorReferences == null); // stop trying if the plugin is stopped;

                if (currentEditorReferences != null) {
                  final List<IEditorReference> refs = currentEditorReferences;
                  RunInUiThread.sync(
                      new Runnable() {

                        public void run() {
                          for (final IEditorReference iEditorReference : refs) {
                            final IEditorPart editor = iEditorReference.getEditor(true);
                            if (editor instanceof PyEdit) {
                              try {
                                invalidateTitle((PyEdit) editor, iEditorReference.getEditorInput());
                              } catch (PartInitException e) {
                                // ignore
                              }
                            }
                          }
                        }
                      });
                }

              } finally {
                jobPool.removeJob(this);
              }
              return Status.OK_STATUS;
            }
          };
      job.setPriority(Job.SHORT);
      jobPool.addJob(job);
    }
  }
예제 #3
0
  /**
   * Updates the title text and image of the given pyEdit (based on the passed input).
   *
   * <p>That will be done depending on the other open editors (if the user has chosen unique names).
   */
  private void invalidateTitleInput(final PyEdit pyEdit, final IEditorInput input) {
    if (input == null) {
      return;
    }

    final IPath pathFromInput = getPathFromInput(input);
    if (pathFromInput == null || pathFromInput.segmentCount() == 0) {
      return; // not much we can do!
    }

    final String lastSegment = pathFromInput.lastSegment();
    if (lastSegment == null) {
      return;
    }

    final String initHandling = PyTitlePreferencesPage.getInitHandling();
    final String djangoModulesHandling = PyTitlePreferencesPage.getDjangoModulesHandling();

    // initially set this as the title (and change it later to a computed name).
    String computedEditorTitle =
        getPartNameInLevel(1, pathFromInput, initHandling, djangoModulesHandling, input).o1;

    pyEdit.setEditorTitle(computedEditorTitle);
    updateImage(pyEdit, null, pathFromInput);

    if (!PyTitlePreferencesPage.getEditorNamesUnique()) {
      return; // the user accepts having the same name for 2 files, no more work to do.
    }

    Job job =
        new Job("Invalidate title") {

          @Override
          protected IStatus run(IProgressMonitor monitor) {
            try {
              while (PydevPlugin.isAlive()
                  && !initializeTitle(
                      pyEdit,
                      input,
                      pathFromInput,
                      lastSegment,
                      initHandling,
                      djangoModulesHandling)) { // stop trying if the plugin is stopped
                synchronized (this) {
                  try {
                    Thread.sleep(200);
                  } catch (InterruptedException e) {
                    // ignore.
                  }
                }
              }
              ;
            } finally {
              jobPool.removeJob(this);
            }
            return Status.OK_STATUS;
          }
        };
    job.setPriority(Job.SHORT);
    jobPool.addJob(job);
  }