// Copyright (C) 2013 The Android Open Source Project
//
// 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.google.gerrit.client.diff;

import com.google.gerrit.client.account.DiffPreferences;
import com.google.gwt.event.logical.shared.CloseEvent;
import com.google.gwt.event.logical.shared.CloseHandler;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.PopupPanel.PositionCallback;

class PreferencesAction {
  private final SideBySide2 view;
  private final DiffPreferences prefs;
  private PopupPanel popup;
  private PreferencesBox current;

  PreferencesAction(SideBySide2 view, DiffPreferences prefs) {
    this.view = view;
    this.prefs = prefs;
  }

  void update() {
    if (current != null) {
      current.set(prefs);
    }
  }

  void show() {
    if (popup != null) {
      // Already open? Close the dialog.
      hide();
      return;
    }

    current = new PreferencesBox(view);
    current.set(prefs);

    popup = new PopupPanel(true, false);
    popup.setStyleName(current.style.dialog());
    popup.add(current);
    popup.addCloseHandler(new CloseHandler<PopupPanel>() {
      @Override
      public void onClose(CloseEvent<PopupPanel> event) {
        view.getCmB().focus();
        popup = null;
        current = null;
      }
    });
    popup.setPopupPositionAndShow(new PositionCallback() {
      @Override
      public void setPosition(int offsetWidth, int offsetHeight) {
        popup.setPopupPosition(390, 120);
      }
    });
    current.setFocus(true);
  }

  void hide() {
    if (popup != null) {
      popup.hide();
      popup = null;
      current = null;
    }
  }
}

@@ -1984,9 +1984,9 @@
 on(3
-9
+0
 0, 1

Move diff preferences popup 90px left