<commit_before>// Copyright (C) 2009 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;

import com.google.gerrit.client.changes.ChangeScreen;
import com.google.gerrit.client.reviewdb.Change;
import com.google.gwt.event.dom.client.BlurEvent;
import com.google.gwt.event.dom.client.BlurHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.FocusEvent;
import com.google.gwt.event.dom.client.FocusHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyPressEvent;
import com.google.gwt.event.dom.client.KeyPressHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwtexpui.globalkey.client.GlobalKey;
import com.google.gwtexpui.globalkey.client.KeyCommand;
import com.google.gwtexpui.globalkey.client.NpTextBox;

class SearchPanel extends Composite {
  private final NpTextBox searchBox;
  private HandlerRegistration focusKey;

  SearchPanel() {
    final FlowPanel body = new FlowPanel();
    initWidget(body);
    setStyleName("gerrit-SearchPanel");

    searchBox = new NpTextBox();
    searchBox.setVisibleLength(42);
    searchBox.setText(Gerrit.C.searchHint());
    searchBox.addStyleName("gerrit-InputFieldTypeHint");
    searchBox.addFocusHandler(new FocusHandler() {
      @Override
      public void onFocus(FocusEvent event) {
        if (Gerrit.C.searchHint().equals(searchBox.getText())) {
          searchBox.setText("");
          searchBox.removeStyleName("gerrit-InputFieldTypeHint");
        }
      }
    });
    searchBox.addBlurHandler(new BlurHandler() {
      @Override
      public void onBlur(BlurEvent event) {
        if ("".equals(searchBox.getText())) {
          searchBox.setText(Gerrit.C.searchHint());
          searchBox.addStyleName("gerrit-InputFieldTypeHint");
        }
      }
    });
    searchBox.addKeyPressHandler(new KeyPressHandler() {
      @Override
      public void onKeyPress(final KeyPressEvent event) {
        if (event.getCharCode() == KeyCodes.KEY_ENTER) {
          doSearch();
        }
      }
    });

    final Button searchButton = new Button(Gerrit.C.searchButton());
    searchButton.addClickHandler(new ClickHandler() {
      @Override
      public void onClick(ClickEvent event) {
        doSearch();
      }
    });

    body.add(searchBox);
    body.add(searchButton);
  }

  @Override
  public void onLoad() {
    super.onLoad();
    if (focusKey == null) {
      focusKey =
          GlobalKey
              .addApplication(new KeyCommand(0, '/', Gerrit.C.keySearch()) {
                @Override
                public void onKeyPress(final KeyPressEvent event) {
                  event.preventDefault();
                  searchBox.setFocus(true);
                  searchBox.selectAll();
                }
              });
    }
  }

  @Override
  public void onUnload() {
    if (focusKey != null) {
      focusKey.removeHandler();
      focusKey = null;
    }
  }

  private void doSearch() {
    final String query = searchBox.getText().trim();
    if (query.length() == 0 || Gerrit.C.searchHint().equals(query)) {
      return;
    }

    searchBox.setFocus(false);

    if (query.matches("^[1-9][0-9]*$")) {
      final Change.Id ck = Change.Id.parse(query);
      Gerrit.display(Link.toChange(ck), new ChangeScreen(ck));
    } else {
      Gerrit.display(new NotFoundScreen());
    }
  }
}<commit_msg>Cleanup the name of the search focus key registration<commit_after>// Copyright (C) 2009 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;

import com.google.gerrit.client.changes.ChangeScreen;
import com.google.gerrit.client.reviewdb.Change;
import com.google.gwt.event.dom.client.BlurEvent;
import com.google.gwt.event.dom.client.BlurHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.FocusEvent;
import com.google.gwt.event.dom.client.FocusHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyPressEvent;
import com.google.gwt.event.dom.client.KeyPressHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwtexpui.globalkey.client.GlobalKey;
import com.google.gwtexpui.globalkey.client.KeyCommand;
import com.google.gwtexpui.globalkey.client.NpTextBox;

class SearchPanel extends Composite {
  private final NpTextBox searchBox;
  private HandlerRegistration regFocus;

  SearchPanel() {
    final FlowPanel body = new FlowPanel();
    initWidget(body);
    setStyleName("gerrit-SearchPanel");

    searchBox = new NpTextBox();
    searchBox.setVisibleLength(42);
    searchBox.setText(Gerrit.C.searchHint());
    searchBox.addStyleName("gerrit-InputFieldTypeHint");
    searchBox.addFocusHandler(new FocusHandler() {
      @Override
      public void onFocus(FocusEvent event) {
        if (Gerrit.C.searchHint().equals(searchBox.getText())) {
          searchBox.setText("");
          searchBox.removeStyleName("gerrit-InputFieldTypeHint");
        }
      }
    });
    searchBox.addBlurHandler(new BlurHandler() {
      @Override
      public void onBlur(BlurEvent event) {
        if ("".equals(searchBox.getText())) {
          searchBox.setText(Gerrit.C.searchHint());
          searchBox.addStyleName("gerrit-InputFieldTypeHint");
        }
      }
    });
    searchBox.addKeyPressHandler(new KeyPressHandler() {
      @Override
      public void onKeyPress(final KeyPressEvent event) {
        if (event.getCharCode() == KeyCodes.KEY_ENTER) {
          doSearch();
        }
      }
    });

    final Button searchButton = new Button(Gerrit.C.searchButton());
    searchButton.addClickHandler(new ClickHandler() {
      @Override
      public void onClick(ClickEvent event) {
        doSearch();
      }
    });

    body.add(searchBox);
    body.add(searchButton);
  }

  @Override
  public void onLoad() {
    super.onLoad();
    if (regFocus == null) {
      regFocus =
          GlobalKey
              .addApplication(new KeyCommand(0, '/', Gerrit.C.keySearch()) {
                @Override
                public void onKeyPress(final KeyPressEvent event) {
                  event.preventDefault();
                  searchBox.setFocus(true);
                  searchBox.selectAll();
                }
              });
    }
  }

  @Override
  public void onUnload() {
    if (regFocus != null) {
      regFocus.removeHandler();
      regFocus = null;
    }
  }

  private void doSearch() {
    final String query = searchBox.getText().trim();
    if (query.length() == 0 || Gerrit.C.searchHint().equals(query)) {
      return;
    }

    searchBox.setFocus(false);

    if (query.matches("^[1-9][0-9]*$")) {
      final Change.Id ck = Change.Id.parse(query);
      Gerrit.display(Link.toChange(ck), new ChangeScreen(ck));
    } else {
      Gerrit.display(new NotFoundScreen());
    }
  }
}
{'fraction_non_alphanumeric': 0.12093690248565965, 'fraction_numerical': 0.0038240917782026767, 'mean_word_length': 3.002391200382592, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6812520', 'n_tokens_mistral': 2546, 'n_tokens_neox': 2472, 'n_words': 520}