コード例 #1
0
ファイル: App.xaml.cs プロジェクト: billchiles/sgfeditor
        protected override async void OnFileActivated(FileActivatedEventArgs args)
        {
            base.OnFileActivated(args);
            MainWindow mainwin;
            // We only handle one file for now ...
            var sf = args.Files[0] as StorageFile;

            // Check dirty save if running already
            if (args.PreviousExecutionState == ApplicationExecutionState.Running ||
                args.PreviousExecutionState == ApplicationExecutionState.Suspended)
            {
                mainwin = ((Frame)Window.Current.Content).Content as MainWindow;
                // If file is already open, just show it.  NOTE, if change this, check DoOpenButton
                var gindex = GameAux.ListFind(sf.Path, mainwin.Games, (sfname, g) => ((string)sfname) == ((Game)g).Filename);
                if (gindex != -1)
                {
                    await mainwin.GotoOpenGame(gindex);

                    return;
                }
                // Get new open file.
                await mainwin.CheckDirtySave();
            }
            else
            {
                // else create main UI as OnLaunched does
                var frame = new Frame();
                Window.Current.Content = frame;
                // Need to set this so that an unnamed auto save doesn't prompt to re-open when user specified file.
                MainWindow.FileActivatedNoUnnamedAutoSave = true;
                frame.Navigate(typeof(MainWindow));
                mainwin = frame.Content as MainWindow;
                Window.Current.Activate();
            }
            // Stash this in case we hit an error reading the file or making the game in the activated file.
            var game = mainwin.Game;

            try {
                mainwin.LastCreatedGame = null;
                await mainwin.GetFileGameCheckingAutoSave(sf);
            }
            catch (IOException err) {
                // Essentially handles unexpected EOF or malformed property values.
                FileActivatedErrorCleanup(mainwin, game);
                var ignoreTask = // Squelch warning that we're not awaiting Message, which we can't in catch blocks.
                                 GameAux.Message(err.Message + err.StackTrace);
            }
            catch (Exception err) {
                // No code paths should throw from incomplete, unrecoverable state, so should be fine to continue.
                // For example, game state should be intact (other than IsDirty) for continuing.
                FileActivatedErrorCleanup(mainwin, game);
                var ignoreTask = // Squelch warning that we're not awaiting Message, which we can't in catch blocks.
                                 GameAux.Message(err.Message + err.StackTrace);
            }
            mainwin.DrawGameTree();
        }
コード例 #2
0
        private void okButton_click(object sender, RoutedEventArgs e)
        {
            this.GameInfoConfirmed = true;
            // See what's changed and if we're dirty.
            var g     = this.Game;
            var props = g.MiscGameInfo;

            if (this.gameInfoPB.Text != g.PlayerBlack)
            {
                g.PlayerBlack = this.gameInfoPB.Text;
                g.Dirty       = true;
            }
            if (this.gameInfoPW.Text != g.PlayerWhite)
            {
                g.PlayerWhite = this.gameInfoPW.Text;
                g.Dirty       = true;
            }
            if (this.gameInfoKM.Text != g.Komi)
            {
                g.Komi  = this.gameInfoKM.Text;
                g.Dirty = true;
            }
            // Aborted support for editing handicap in game info dialog.  Needed too much refactoring and
            // new abstractions to re-init game depending on state, and even just supporting changing from
            // zero just one time required complications that didn't seem worth it.
            //if (g.State == GameState.NotStarted && g.Handicap == 0) {
            //    var handicap = int.Parse(this.gameInfoHA.Text);
            //    if (handicap != g.Handicap) {
            //        if (handicap < 0 || handicap > 9) {
            //            //await GameAux.Message("Handicap must be 0 to 9.");
            //        }
            //        else {
            //            g.InitHandicapNextColor(handicap, null);
            //            g.mainwin.AddInitialStones(... new arg for just handicap, need to handle AW ...)
            //        }
            //    }
            //}
            //
            var    stuff  = GameAux.CompareComments(this.gameInfoGC.Text, g.Comments);
            bool   same   = stuff.Item1;
            string newstr = stuff.Item2;

            if (!same)
            {
                g.Comments          = newstr;
                g.Dirty             = true;
                this.CommentChanged = true;
            }
            // black rank ... wish I had Lisp macros :-).
            if (props.ContainsKey("BR"))
            {
                if (this.gameInfoBR.Text != props["BR"][0])
                {
                    if (this.gameInfoBR.Text == "")
                    {
                        props.Remove("BR");
                    }
                    else
                    {
                        props["BR"] = new List <string>()
                        {
                            this.gameInfoBR.Text
                        }
                    };
                    g.Dirty = true;
                }
            }
            else if (this.gameInfoBR.Text != "")
            {
                props["BR"] = new List <string>()
                {
                    this.gameInfoBR.Text
                };
                g.Dirty = true;
            }
            // white rank ... wish I had Lisp macros :-).
            if (props.ContainsKey("WR"))
            {
                if (this.gameInfoWR.Text != props["WR"][0])
                {
                    if (this.gameInfoWR.Text == "")
                    {
                        props.Remove("WR");
                    }
                    else
                    {
                        props["WR"] = new List <string>()
                        {
                            this.gameInfoWR.Text
                        }
                    };
                    g.Dirty = true;
                }
            }
            else if (this.gameInfoWR.Text != "")
            {
                props["WR"] = new List <string>()
                {
                    this.gameInfoWR.Text
                };
                g.Dirty = true;
            }
            // black team ... wish I had Lisp macros :-).
            if (props.ContainsKey("BT"))
            {
                if (this.gameInfoBT.Text != props["BT"][0])
                {
                    if (this.gameInfoBT.Text == "")
                    {
                        props.Remove("BT");
                    }
                    else
                    {
                        props["BT"] = new List <string>()
                        {
                            this.gameInfoBT.Text
                        }
                    };
                    g.Dirty = true;
                }
            }
            else if (this.gameInfoBT.Text != "")
            {
                props["BT"] = new List <string>()
                {
                    this.gameInfoBT.Text
                };
                g.Dirty = true;
            }
            // white team ... wish I had Lisp macros :-).
            if (props.ContainsKey("WT"))
            {
                if (this.gameInfoWT.Text != props["WT"][0])
                {
                    if (this.gameInfoWT.Text == "")
                    {
                        props.Remove("WT");
                    }
                    else
                    {
                        props["WT"] = new List <string>()
                        {
                            this.gameInfoWT.Text
                        }
                    };
                    g.Dirty = true;
                }
            }
            else if (this.gameInfoWT.Text != "")
            {
                props["WT"] = new List <string>()
                {
                    this.gameInfoWT.Text
                };
                g.Dirty = true;
            }
            // rules ... wish I had Lisp macros :-).
            if (props.ContainsKey("RU"))
            {
                if (this.gameInfoRU.Text != props["RU"][0])
                {
                    if (this.gameInfoRU.Text == "")
                    {
                        props.Remove("RU");
                    }
                    else
                    {
                        props["RU"] = new List <string>()
                        {
                            this.gameInfoRU.Text
                        }
                    };
                    g.Dirty = true;
                }
            }
            else if (this.gameInfoRU.Text != "")
            {
                props["RU"] = new List <string>()
                {
                    this.gameInfoRU.Text
                };
                g.Dirty = true;
            }
            // date ... wish I had Lisp macros :-).
            if (props.ContainsKey("DT"))
            {
                if (this.gameInfoDT.Text != props["DT"][0])
                {
                    if (this.gameInfoDT.Text == "")
                    {
                        props.Remove("DT");
                    }
                    else
                    {
                        props["DT"] = new List <string>()
                        {
                            this.gameInfoDT.Text
                        }
                    };
                    g.Dirty = true;
                }
            }
            else if (this.gameInfoDT.Text != "")
            {
                props["DT"] = new List <string>()
                {
                    this.gameInfoDT.Text
                };
                g.Dirty = true;
            }
            // Really should confirm text is YYYY-MM-DD format, but most SGF editors probably ignore this.
            //
            // time ... wish I had Lisp macros :-).
            if (props.ContainsKey("TM"))
            {
                if (this.gameInfoTM.Text != props["TM"][0])
                {
                    if (this.gameInfoTM.Text == "")
                    {
                        props.Remove("TM");
                    }
                    else
                    {
                        props["TM"] = new List <string>()
                        {
                            this.gameInfoTM.Text
                        }
                    };
                    g.Dirty = true;
                }
            }
            else if (this.gameInfoTM.Text != "")
            {
                props["TM"] = new List <string>()
                {
                    this.gameInfoTM.Text
                };
                g.Dirty = true;
            }
            // event name ... wish I had Lisp macros :-).
            if (props.ContainsKey("EV"))
            {
                if (this.gameInfoEV.Text != props["EV"][0])
                {
                    if (this.gameInfoEV.Text == "")
                    {
                        props.Remove("EV");
                    }
                    else
                    {
                        props["EV"] = new List <string>()
                        {
                            this.gameInfoEV.Text
                        }
                    };
                    g.Dirty = true;
                }
            }
            else if (this.gameInfoEV.Text != "")
            {
                props["EV"] = new List <string>()
                {
                    this.gameInfoEV.Text
                };
                g.Dirty = true;
            }
            // place ... wish I had Lisp macros :-).
            if (props.ContainsKey("PC"))
            {
                if (this.gameInfoPC.Text != props["PC"][0])
                {
                    if (this.gameInfoPC.Text == "")
                    {
                        props.Remove("PC");
                    }
                    else
                    {
                        props["PC"] = new List <string>()
                        {
                            this.gameInfoPC.Text
                        }
                    };
                    g.Dirty = true;
                }
            }
            else if (this.gameInfoPC.Text != "")
            {
                props["PC"] = new List <string>()
                {
                    this.gameInfoPC.Text
                };
                g.Dirty = true;
            }
            // game name ... wish I had Lisp macros :-).
            if (props.ContainsKey("GN"))
            {
                if (this.gameInfoGN.Text != props["GN"][0])
                {
                    if (this.gameInfoGN.Text == "")
                    {
                        props.Remove("GN");
                    }
                    else
                    {
                        props["GN"] = new List <string>()
                        {
                            this.gameInfoGN.Text
                        }
                    };
                    g.Dirty = true;
                }
            }
            else if (this.gameInfoGN.Text != "")
            {
                props["GN"] = new List <string>()
                {
                    this.gameInfoGN.Text
                };
                g.Dirty = true;
            }
            // opening name ... wish I had Lisp macros :-).
            if (props.ContainsKey("ON"))
            {
                if (this.gameInfoON.Text != props["ON"][0])
                {
                    if (this.gameInfoON.Text == "")
                    {
                        props.Remove("ON");
                    }
                    else
                    {
                        props["ON"] = new List <string>()
                        {
                            this.gameInfoON.Text
                        }
                    };
                    g.Dirty = true;
                }
            }
            else if (this.gameInfoON.Text != "")
            {
                props["ON"] = new List <string>()
                {
                    this.gameInfoON.Text
                };
                g.Dirty = true;
            }
            // result ... wish I had Lisp macros :-).
            if (props.ContainsKey("RE"))
            {
                if (this.gameInfoRE.Text != props["RE"][0])
                {
                    if (this.gameInfoRE.Text == "")
                    {
                        props.Remove("RE");
                    }
                    else
                    {
                        props["RE"] = new List <string>()
                        {
                            this.gameInfoRE.Text
                        }
                    };
                    g.Dirty = true;
                }
            }
            else if (this.gameInfoRE.Text != "")
            {
                props["RE"] = new List <string>()
                {
                    this.gameInfoRE.Text
                };
                g.Dirty = true;
            }
            // Really should confirm text is b+2, b+2.5, b+result, etc. format, but what SGF editors look at this.
            //
            // annotator ... wish I had Lisp macros :-).
            if (props.ContainsKey("AN"))
            {
                if (this.gameInfoAN.Text != props["AN"][0])
                {
                    if (this.gameInfoAN.Text == "")
                    {
                        props.Remove("AN");
                    }
                    else
                    {
                        props["AN"] = new List <string>()
                        {
                            this.gameInfoAN.Text
                        }
                    };
                    g.Dirty = true;
                }
            }
            else if (this.gameInfoAN.Text != "")
            {
                props["AN"] = new List <string>()
                {
                    this.gameInfoAN.Text
                };
                g.Dirty = true;
            }

            // Invoke whoever is waiting for the dialog to be done.
            if (this.GameInfoDialogClose != null)
            {
                this.GameInfoDialogClose(this, EventArgs.Empty);
            }
        }