/*
 * Copyright 2000-2016 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.internal;

import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.DumbModeTask;
import com.intellij.openapi.project.DumbServiceImpl;
import com.intellij.openapi.project.Project;
import com.intellij.util.TimeoutUtil;
import org.jetbrains.annotations.NotNull;

/**
 * @author peter
 */
public class ToggleDumbModeAction extends DumbAwareAction {
  private volatile boolean myDumb = false;

  public void actionPerformed(final AnActionEvent e) {
    if (myDumb) {
      myDumb = false;
    }
    else {
      myDumb = true;
      final Project project = e.getProject();
      if (project == null) return;

      DumbServiceImpl.getInstance(project).queueTask(new DumbModeTask() {
        @Override
        public void performInDumbMode(@NotNull ProgressIndicator indicator) {
          while (myDumb) {
            indicator.checkCanceled();
            TimeoutUtil.sleep(100);
          }
        }
      });
    }
  }

  @Override
  public void update(final AnActionEvent e) {
    final Presentation presentation = e.getPresentation();
    final Project project = e.getProject();
    presentation.setEnabled(project != null && myDumb == DumbServiceImpl.getInstance(project).isDumb());
    if (myDumb) {
      presentation.setText("Exit Dumb Mode");
    }
    else {
      presentation.setText("Enter Dumb Mode");
    }
  }
}

@@ -686,63 +686,8 @@
 nt;%0A
-import com.intellij.openapi.actionSystem.Presentation;%0A
 impo
@@ -1179,22 +1179,16 @@
 rformed(
-final 
 AnAction
@@ -1706,22 +1706,16 @@
  update(
-final 
 AnAction
@@ -1733,112 +1733,81 @@
     
-final Presentation presentation = e.getPresentation();%0A    final Project project = e.getProject();%0A    p
+Project project = e.getProject();%0A    if (project == null) %7B%0A      e.getP
 rese
@@ -1809,24 +1809,26 @@
 Presentation
+()
 .setEnabled(
@@ -1831,36 +1831,54 @@
 led(
-project != null && myD
+false);%0A      return;%0A    %7D%0A    boolean d
 umb =
-=
  Dum
@@ -1923,36 +1923,109 @@
 mb()
-);%0A    if (myDumb) %7B%0A      p
+;%0A    boolean enabled = !dumb %7C%7C myDumb;%0A    if (enabled && myDumb != dumb) myDumb = dumb;%0A    e.getP
 rese
@@ -2035,60 +2035,42 @@
 tion
+()
 .set
-Text(%22Exit Dumb Mode%22);%0A    %7D%0A    else %7B%0A      p
+Enabled(enabled);%0A    e.getP
 rese
@@ -2076,16 +2076,18 @@
 entation
+()
 .setText
@@ -2087,16 +2087,42 @@
 setText(
+dumb ? %22Exit Dumb Mode%22 : 
 %22Enter D
@@ -2133,20 +2133,14 @@
 Mode%22);%0A
-    %7D%0A
   %7D%0A%7D%0A

enable un-toggled dumb toggle toggling