/*
 * Copyright 2000-2009 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.intellij.ide.favoritesTreeView.actions;

import com.intellij.ide.IdeBundle;
import com.intellij.ide.favoritesTreeView.FavoritesManager;
import com.intellij.ide.favoritesTreeView.FavoritesTreeViewPanel;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;

/**
 * User: anna
 * Date: Feb 23, 2005
 */
public class DeleteAllFavoritesListsButThisAction extends AnAction implements DumbAware {
  public DeleteAllFavoritesListsButThisAction() {
    super(IdeBundle.message("action.delete.all.favorites.lists.but.this",""));
  }

  public void actionPerformed(AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    Project project = PlatformDataKeys.PROJECT.getData(dataContext);
    if (project == null) {
      return;
    }
    FavoritesManager favoritesManager = FavoritesManager.getInstance(project);
    String listName = FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY.getData(dataContext);
    String[] lists = favoritesManager.getAvailableFavoritesLists();
    for (String list : lists) {
      if (!list.equals(listName)) {
        favoritesManager.removeFavoritesList(list);
      }
    }
  }

  public void update(AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    Project project = PlatformDataKeys.PROJECT.getData(dataContext);
    if (project == null){
      e.getPresentation().setEnabled(false);
      return;
    }
    String listName = FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY.getData(dataContext);
    e.getPresentation().setEnabled(listName != null);
    if (listName != null) {
      e.getPresentation().setText(IdeBundle.message("action.delete.all.favorites.lists.but.this",listName));
      e.getPresentation().setDescription(IdeBundle.message("action.delete.all.favorites.lists.but.this",listName));
    }
  }
}

@@ -854,185 +854,9 @@
 tem.
-AnAction;%0Aimport com.intellij.openapi.actionSystem.AnActionEvent;%0Aimport com.intellij.openapi.actionSystem.DataContext;%0Aimport com.intellij.openapi.actionSystem.PlatformDataKeys
+*
 ;%0Aim
@@ -1909,32 +1909,38 @@
 aContext();%0A    
+final 
 Project project 
@@ -1980,32 +1980,91 @@
 a(dataContext);%0A
+    final Presentation presentation = e.getPresentation();%0A
     if (project 
@@ -2071,38 +2071,33 @@
 == null)%7B%0A      
-e.getP
+p
 resentation().se
@@ -2083,34 +2083,32 @@
     presentation
-()
 .setEnabled(fals
@@ -2131,24 +2131,30 @@
 ;%0A    %7D%0A    
+final 
 String listN
@@ -2233,30 +2233,25 @@
 ntext);%0A    
-e.getP
+p
 resentation(
@@ -2245,26 +2245,24 @@
 presentation
-()
 .setEnabled(
@@ -2260,16 +2260,32 @@
 tEnabled
+(false);%0A    if 
 (listNam
@@ -2298,35 +2298,238 @@
 ull)
-;%0A    if (listName != null)
+ %7B%0A      final String%5B%5D favoritesLists = FavoritesManager.getInstance(project).getAvailableFavoritesLists();%0A      if (listName.equals(project.getName())) %7B%0A        presentation.setEnabled(favoritesLists.length %3E 1);%0A      %7D  else
  %7B%0A 
@@ -2529,30 +2529,93 @@
 lse %7B%0A      
+ 
-e.getP
+ presentation.setEnabled(favoritesLists.length %3E 2);%0A      %7D%0A      p
 resentation(
@@ -2609,26 +2609,24 @@
 presentation
-()
 .setText(Ide
@@ -2677,32 +2677,33 @@
 lists.but.this%22,
+ 
 listName));%0A    
@@ -2704,22 +2704,17 @@
 ;%0A      
-e.getP
+p
 resentat
@@ -2716,18 +2716,16 @@
 entation
-()
 .setDesc
@@ -2795,16 +2795,17 @@
 t.this%22,
+ 
 listName

disable delete all but this favorite lists if only default exists (IDEA-62224)