Пример #1
0
 /**
  * Save the most-recently-used history in the given memento.
  *
  * @param memento the memento to save the mru history in
  */
 public IStatus saveState(IMemento memento) {
   Iterator iterator = fifoList.iterator();
   while (iterator.hasNext()) {
     EditorHistoryItem item = (EditorHistoryItem) iterator.next();
     if (item.canSave()) {
       IMemento itemMemento = memento.createChild(IWorkbenchConstants.TAG_FILE);
       item.saveState(itemMemento);
     }
   }
   return Status.OK_STATUS;
 }
Пример #2
0
 /**
  * Restore the most-recently-used history from the given memento.
  *
  * @param memento the memento to restore the mru history from
  */
 public IStatus restoreState(IMemento memento) {
   IMemento[] mementos = memento.getChildren(IWorkbenchConstants.TAG_FILE);
   for (int i = 0; i < mementos.length; i++) {
     EditorHistoryItem item = new EditorHistoryItem(mementos[i]);
     if (!"".equals(item.getName())
         || !"".equals(item.getToolTipText())) { // $NON-NLS-1$ //$NON-NLS-2$
       add(item, fifoList.size());
     }
   }
   return Status.OK_STATUS;
 }
Пример #3
0
 /** Removes all traces of an editor input from the history. */
 public void remove(IEditorInput input) {
   if (input == null) {
     return;
   }
   Iterator iter = fifoList.iterator();
   while (iter.hasNext()) {
     EditorHistoryItem item = (EditorHistoryItem) iter.next();
     if (item.matches(input)) {
       iter.remove();
     }
   }
 }
Пример #4
0
 /** Refresh the editor list. Any stale items are removed. Only restored items are considered. */
 public void refresh() {
   Iterator iter = fifoList.iterator();
   while (iter.hasNext()) {
     EditorHistoryItem item = (EditorHistoryItem) iter.next();
     if (item.isRestored()) {
       IEditorInput input = item.getInput();
       if (input != null && !input.exists()) {
         iter.remove();
       }
     }
   }
 }
Пример #5
0
  /** Adds an item to the history. */
  private void add(EditorHistoryItem newItem, int index) {
    // Remove the item if it already exists so that it will be put
    // at the top of the list.
    if (newItem.isRestored()) {
      remove(newItem.getInput());
    }

    // Remove the oldest one
    if (fifoList.size() == MAX_SIZE) {
      fifoList.remove(MAX_SIZE - 1);
    }

    // Add the new item.
    fifoList.add(index < MAX_SIZE ? index : MAX_SIZE - 1, newItem);
  }