public MainWindow() { MainWindow.Instance = this; // >:[ InitializeComponent(); this.menu_file_exit.Click += (sender, e) => { CommandDoer.Exit(this, this.ActiveModel); }; this.menu_file_new.Click += (sender, e) => { CommandDoer.New(this, this.ActiveModel); }; this.menu_file_open.Click += (sender, e) => { CommandDoer.Open(this, this.ActiveModel); }; this.menu_file_save.Click += (sender, e) => { CommandDoer.Save(this, this.ActiveModel); }; this.menu_file_saveas.Click += (sender, e) => { CommandDoer.SaveAs(this, this.ActiveModel); }; this.menu_edit_resize.Click += (sender, e) => { if (this.ActiveModel != null) { new ResizeDialog(this.ActiveModel).ShowDialog(); } }; this.menu_edit_maptype.Click += (sender, e) => { if (this.ActiveModel != null) { new MapTypeDialog(this.ActiveModel).ShowDialog(); } }; this.SizeChanged += (sender, e) => { this.artboardBitmap = null; this.RedrawTheWholeDamnThing(); }; this.layerToggle.Click += (sender, e) => { this.LayerToggle(); }; this.gridToggle.Click += (sender, e) => { this.GridToggle(); }; this.clickCatcher.MouseDown += (sender, e) => { this.HandleMouseClick(e.GetPosition(this.clickCatcher), true, e.ChangedButton == MouseButton.Left); }; this.clickCatcher.MouseUp += (sender, e) => { this.HandleMouseClick(e.GetPosition(this.clickCatcher), false, e.ChangedButton == MouseButton.Left); }; this.clickCatcher.MouseMove += (sender, e) => { this.HandleMouseMove(e.GetPosition(this.clickCatcher)); }; this.KeyDown += (sender, e) => { this.HandleKey(e.Key, true); }; this.KeyUp += (sender, e) => { this.HandleKey(e.Key, false); }; this.Loaded += (sender, e) => { this.Initialize(); }; this.LayerToggle(); this.UpdateTitle(); }
private void HandleKey(Key key, bool down) { bool shiftPressed = Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift); bool ctrlPressed = Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl); if (down && !shiftPressed && !ctrlPressed) { if (key == Key.G) { this.GridToggle(); } else if (key == Key.L) { this.LayerToggle(); } } if (ctrlPressed) { switch (key) { case Key.N: CommandDoer.New(this, this.ActiveModel); break; case Key.O: CommandDoer.Open(this, this.ActiveModel); break; case Key.S: if (shiftPressed) { CommandDoer.SaveAs(this, this.ActiveModel); } else { CommandDoer.Save(this, this.ActiveModel); } break; default: break; } } }
// returns false if the user hit cancel or the document was not saved. public static bool Save(MainWindow window, Model model) { if (model == null) { return(false); } if (model.Path == null) { return(CommandDoer.SaveAs(window, model)); } else { if (model.IsDirty) { string fileContents = model.Serialize(); System.IO.File.WriteAllText(model.Path, fileContents); model.IsDirty = false; window.UpdateTitle(); } } return(false); }