Пример #1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Ut.RunMain(() =>
            {
                SettingsUtil.LoadSettings(out Settings);
                Tr = Lingo.LoadTranslationOrDefault <Translation>("AccountsWeb", ref Settings.Language);

                Interface = new WebInterface();
                TrayForm  = new TrayForm();

                if (Settings.LastFileName != null)
                {
                    OpenFile(Settings.LastFileName);
                }

#if DEBUG
                var defaultTr = new Translation();
                using (var tempConfigForm = new ConfigForm(new GncFileWrapper()))
                    using (var g = new Lingo.TranslationFileGenerator(PathUtil.AppPathCombine("../../users/rs/GnuCash/AccountsWeb/Translation.g.cs")))
                    {
                        g.TranslateControl(TrayForm, defaultTr.TrayForm);
                        g.TranslateControl(TrayForm.TrayMenu, defaultTr.TrayMenu);
                        g.TranslateControl(tempConfigForm, defaultTr.Config);
                    }
#endif

                Application.Run();

                Settings.Save();
            },
                       excp =>
            {
                var message = "\n" + "An internal error has occurred in RunLogged: ";
                foreach (var ex in excp.SelectChain(ex => ex.InnerException))
                {
                    message += "\n" + ex.GetType() + ": " + ex.Message;
                    message += "\n" + ex.StackTrace;
                }
                DlgMessage.ShowError(message);
            });
        }
Пример #2
0
        /// <summary>
        /// Constructor. Constructs the main form for the application.
        /// </summary>
        public Mainform()
            : base(Program.Settings.MainFormSettings)
        {
            InitializeComponent();
            mnuMain.Renderer    = new NativeToolStripRenderer();
            mnuContext.Renderer = new NativeToolStripRenderer();

#if DEBUG
            // Auto-generate the translation classes for automated form translation
            using (var generator = new Lingo.TranslationFileGenerator(@"..\..\main\ExpSok\Translation.g.cs"))
            {
                using (var form = new AboutBox(false))
                    generator.TranslateControl(form, Program.Tr.AboutBox);

                using (var form = new HighscoresForm(false))
                    generator.TranslateControl(form, Program.Tr.Highscores);

                using (var form = new ChoosePlayerNameForm(false))
                    generator.TranslateControl(form, Program.Tr.ChoosePlayerName);

                generator.TranslateControl(this, Program.Tr.Mainform);
                generator.TranslateControl(mnuContext, Program.Tr.Context);
            }
#else
            Lingo.TranslateControl(this, Program.Tr.Mainform);
            Lingo.TranslateControl(mnuContext, Program.Tr.Context);
#endif

            _translationHelper = new LanguageHelperWinForms <Translation>("Expert Sokoban", "ExpSok", Program.TranslationEnabled,
                                                                          Program.Settings.TranslationFormSettings, Icon, () => Program.Tr.Language);
            _translationHelper.TranslationChanged += translationChanged;
            _translationHelper.MakeLanguageMenu(mnuOptionsChangeLanguage);

            // Restore saved settings
            mnuOptionsPlayingToolbar.Checked   = Program.Settings.DisplayPlayingToolbar;
            mnuOptionsFileToolbars.Checked     = Program.Settings.DisplayFileToolbars;
            mnuOptionsEditLevelToolbar.Checked = Program.Settings.DisplayEditLevelToolbar;
            ctStatusBar.Visible = mnuOptionsStatusBar.Checked = Program.Settings.DisplayStatusBar;
            grpMovePathOptions.SetValue(Program.Settings.MoveDrawMode);
            grpPushPathOptions.SetValue(Program.Settings.PushDrawMode);
            grpEditTool.SetValue(Program.Settings.LastUsedTool);
            mnuOptionsEndPos.Checked        = ctMainArea.ShowEndPos = Program.Settings.ShowEndPos;
            mnuOptionsAreaSokoban.Checked   = ctMainArea.ShowAreaSokoban = Program.Settings.ShowAreaSokoban;
            mnuOptionsAreaPiece.Checked     = ctMainArea.ShowAreaPiece = Program.Settings.ShowAreaPiece;
            mnuOptionsSound.Checked         = ctMainArea.SoundEnabled = Program.Settings.SoundEnabled;
            mnuOptionsAnimation.Checked     = ctMainArea.AnimationEnabled = Program.Settings.AnimationEnabled;
            mnuOptionsLetterControl.Checked = ctMainArea.LetteringEnabled = Program.Settings.LetteringEnabled;

            if (string.IsNullOrWhiteSpace(Program.Settings.PlayerName))
            {
                Program.Settings.PlayerName = ChoosePlayerNameForm.GetPlayerName(ChoosePlayerNameForm.FormType.FirstRun, "", _translationHelper);
            }

            // Restore the last used level file
            try
            {
                lstLevels.LoadLevelPack(Program.Settings.LevelFilename);
            }
            catch
            {
                lstLevels.NewList();
                lstLevels.AddLevelListItem(SokobanLevel.TestLevel);
                lstLevels.Modified = false;
            }

            showLevelList(Program.Settings.DisplayLevelList);
            lstLevels.PlayFirstUnsolved();
            updateControls();

            // ManagedForm sets the form's Font in the Load event. This potentially changes the width of the level list, which in turn causes its Resize event, which in turn updates Program.Settings.LevelListWidth.
            // To work around this, remember the width from the settings file and defer setting the level list's width until the Load event.
            int levelListWidth = Program.Settings.LevelListWidth < 50 ? 50 : Program.Settings.LevelListWidth;
            Load += (s, e) => pnlLevelList.Width = levelListWidth;
        }