Exemplo n.º 1
0
  private void initActions() {

    if (app.isExam()) {
      addItem(
          MainMenu.getMenuBarHtml(
              GuiResources.INSTANCE.menu_icon_sign_out().getSafeUri().asString(),
              app.getMenu("Close"),
              true),
          true,
          new MenuCommand(app) {

            @Override
            public void doExecute() {
              // set Firefox dom.allow_scripts_to_close_windows in about:config to true to make this
              // work
              String[] optionNames = {app.getMenu("Cancel"), app.getMenu("Exit")};

              app.getGuiManager()
                  .getOptionPane()
                  .showOptionDialog(
                      app,
                      app.getMenu("ExitExamConfirm"),
                      app.getMenu("ExitExamConfirmTitle"),
                      GOptionPane.CUSTOM_OPTION,
                      GOptionPane.WARNING_MESSAGE,
                      null,
                      optionNames,
                      new AsyncOperation() {
                        @Override
                        public void callback(Object obj) {
                          String[] dialogResult = (String[]) obj;
                          if ("1".equals(dialogResult[0])) {
                            exitExam();
                          }
                        }
                      });
            }
          });
      return;
    }

    // this is enabled always
    addItem(
        MainMenu.getMenuBarHtml(
            GuiResources.INSTANCE.menu_icon_file_new().getSafeUri().asString(),
            app.getMenu("New"),
            true),
        true,
        new MenuCommand(app) {

          @Override
          public void doExecute() {
            ((DialogManagerW) app.getDialogManager()).getSaveDialog().showIfNeeded(newConstruction);
          }
        });

    // open menu is always visible in menu

    addItem(
        MainMenu.getMenuBarHtml(
            GuiResources.INSTANCE.menu_icon_file_open().getSafeUri().asString(),
            app.getPlain("Open"),
            true),
        true,
        new MenuCommand(app) {

          @Override
          public void doExecute() {
            app.openSearch(null);
            if (FileMenuW.this.onFileOpen != null) {
              FileMenuW.this.onFileOpen.run();
            }
          }
        });

    if (app.getLAF().undoRedoSupported()) {
      addItem(
          MainMenu.getMenuBarHtml(
              GuiResources.INSTANCE.menu_icon_file_save().getSafeUri().asString(),
              app.getMenu("Save"),
              true),
          true,
          new MenuCommand(app) {

            @Override
            public void doExecute() {
              app.getGuiManager().save();
            }
          });
    }

    // this is enabled always
    uploadToGGT =
        addItem(
            MainMenu.getMenuBarHtml(
                GuiResources.INSTANCE.menu_icon_file_share().getSafeUri().asString(),
                app.getMenu("Share"),
                true),
            true,
            new MenuCommand(app) {

              @Override
              public void doExecute() {
                if (!nativeShareSupported()) {
                  app.uploadToGeoGebraTube();
                } else {
                  app.getGgbApi()
                      .getBase64(
                          true,
                          new StringHandler() {

                            @Override
                            public void handle(String s) {
                              String title = app.getKernel().getConstruction().getTitle();
                              nativeShare(s, "".equals(title) ? "construction" : title);
                            }
                          });
                }
              }
            });
    App.debug("HAS EXPORT" + app.getLAF().exportSupported());
    if (app.getLAF().exportSupported()) {
      addItem(
          MainMenu.getMenuBarHtml(
              GuiResources.INSTANCE.menu_icons_file_export().getSafeUri().asString(),
              app.getMenu("Export"),
              true),
          true,
          new ExportMenuW(app));
    }

    app.getNetworkOperation().getView().add(this);

    if (!app.getNetworkOperation().isOnline()) {
      render(false);
    }
  }