package _VisualDVM.Visual.Menus.ProjectMenuBar;
import Common.Utils.Utils_;
import _VisualDVM.Current;
import _VisualDVM.Global;
import _VisualDVM.Visual.Menus.LanguagesSubmenu;
import _VisualDVM.Visual.Menus.SettingsSubmenu;
import _VisualDVM.Visual.Menus.StylesSubmenu;
import _VisualDVM.Visual.Menus.VisualiserMenu;
import _VisualDVM.GlobalData.GlobalDatabase;
import _VisualDVM.GlobalData.Settings.SettingName;
import _VisualDVM.ProjectData.Files.LanguageStyle;
import _VisualDVM.ProjectData.LanguageName;

import javax.swing.*;
public class ProjectSettingsMenu extends VisualiserMenu {
    JMenu mLanguage;
    JMenu mStyle;
    public ProjectSettingsMenu() {
        super("Настройки проекта", "/icons/Settings.png");
        add(mLanguage = new LanguagesSubmenu() {
            @Override
            public void action(LanguageName languageName) {
                if (Global.mainModule.getProject().UpdateLanguage(languageName)) {
                    Global.mainModule.getSapfor().ResetAllAnalyses();
                    ShowLanguage();
                }
            }
        });
        ShowLanguage();
        //--
        add(mStyle = new StylesSubmenu() {
            @Override
            public void action(LanguageStyle languageStyle) {
                if (Global.mainModule.getProject().UpdateStyle(languageStyle))
                    ShowStyle();
            }
        });
        ShowStyle();
        addSeparator();
        add(new SettingsSubmenu("Анализ", null,
                SettingName.Precompilation,
                SettingName.STATIC_SHADOW_ANALYSIS,
                SettingName.KEEP_DVM_DIRECTIVES,
                SettingName.IGNORE_IO_SAPFOR,
                SettingName.MPI_PROGRAM,
                SettingName.ANALYSIS_OPTIONS
        ));
        addSeparator();
        add(new SettingsSubmenu("Построение системы интервалов", null,
                SettingName.KEEP_LOOPS_CLOSE_NESTING,
                SettingName.KEEP_GCOV
        ));
        addSeparator();
        add(new SettingsSubmenu("Построение версий", null,
                SettingName.FREE_FORM,
                SettingName.KEEP_SPF_DIRECTIVES,
                SettingName.KEEP_SPF_DIRECTIVES_AMONG_TRANSFORMATIONS,
                SettingName.OUTPUT_UPPER,
                SettingName.MAX_SHADOW_WIDTH,
                SettingName.DVMConvertationOptions,
                SettingName.SaveModifications
        ));
        addSeparator();
        add((Global.mainModule.getDb()).settings.get(SettingName.TRANSLATE_MESSAGES).getMenuItem());
        add((Global.mainModule.getDb()).settings.get(SettingName.DEBUG_PRINT_ON).getMenuItem());
        add((Global.mainModule.getDb()).settings.get(SettingName.GCOVLimit).getMenuItem());
    }
    public void ShowLanguage() {
        mLanguage.setText("Язык: " + Global.mainModule.getProject().languageName.getDescription());
    }
    public void ShowStyle() {
        mStyle.setText("Стиль: " + Global.mainModule.getProject().style.getDescription());
    }
}
