comparison FrmMainWindow.cs @ 33:441cfc410987

Re #86: Complete GTK# UI * Make save buttons enable when a change has been made, whether the file was saved or not * Make the Save button default to "Save As" behaviour if the file hasn't been saved before * Make sure that loaded file path is kept and that it is wiped on file load
author IBBoard <dev@ibboard.co.uk>
date Sat, 26 Sep 2009 11:06:34 +0000
parents eab45344cd56
children d68992a831df
comparison
equal deleted inserted replaced
32:eab45344cd56 33:441cfc410987
389 OpenArmy(); 389 OpenArmy();
390 } 390 }
391 391
392 protected virtual void OnSaveArmyActivated(object sender, System.EventArgs e) 392 protected virtual void OnSaveArmyActivated(object sender, System.EventArgs e)
393 { 393 {
394 SaveCurrentArmy(); 394 SaveCurrentArmyOrSaveAs();
395 } 395 }
396 396
397 protected virtual void OnAddUnitActivated(object sender, System.EventArgs e) 397 protected virtual void OnAddUnitActivated(object sender, System.EventArgs e)
398 { 398 {
399 if (sender is ToolButton) 399 if (sender is ToolButton)
496 } 496 }
497 497
498 miCloseArmy.Sensitive = newArmy!=null; 498 miCloseArmy.Sensitive = newArmy!=null;
499 miSaveArmyAs.Sensitive = newArmy!=null; 499 miSaveArmyAs.Sensitive = newArmy!=null;
500 miExportArmy.Sensitive = newArmy!=null; 500 miExportArmy.Sensitive = newArmy!=null;
501 loadedArmyPath = null;
501 //New army has no changes, so we can't save it 502 //New army has no changes, so we can't save it
502 miSaveArmy.Sensitive = false; 503 miSaveArmy.Sensitive = false;
503 saveArmyButton.Sensitive = false; 504 saveArmyButton.Sensitive = false;
504 505
505 CommandStack.Reset(); 506 CommandStack.Reset();
675 if (undoLength > 0) 676 if (undoLength > 0)
676 { 677 {
677 //undoMenuButton.Tooltip = CommandStack.PeekUndoCommand().UndoDescription; 678 //undoMenuButton.Tooltip = CommandStack.PeekUndoCommand().UndoDescription;
678 } 679 }
679 680
680 saveArmyButton.Sensitive = commandStack.IsDirty() && WarFoundryCore.CurrentArmy!=null && CanSave(); 681 saveArmyButton.Sensitive = commandStack.IsDirty() && WarFoundryCore.CurrentArmy!=null;
681 miSaveArmy.Sensitive = commandStack.IsDirty() && WarFoundryCore.CurrentArmy!=null && CanSave(); 682 miSaveArmy.Sensitive = commandStack.IsDirty() && WarFoundryCore.CurrentArmy!=null;
682 }
683
684 private bool CanSave()
685 {
686 return loadedArmyPath!=null && WarFoundryCore.CurrentArmy!=null && WarFoundrySaver.GetSaver()!=null;
687 } 683 }
688 684
689 private bool SaveCurrentArmyOrSaveAs() 685 private bool SaveCurrentArmyOrSaveAs()
690 { 686 {
691 if (CanSave()) 687 if (loadedArmyPath != null)
692 { 688 {
693 return SaveCurrentArmy(); 689 return SaveCurrentArmy();
694 } 690 }
695 else 691 else
696 { 692 {
725 721
726 if (army != null) 722 if (army != null)
727 { 723 {
728 logger.Debug("Loaded army " + army.ID); 724 logger.Debug("Loaded army " + army.ID);
729 success = true; 725 success = true;
726 WarFoundryCore.CurrentArmy = army;
730 loadedArmyPath = filePath; 727 loadedArmyPath = filePath;
731 WarFoundryCore.CurrentArmy = army;
732 logger.Debug("Army loading complete"); 728 logger.Debug("Army loading complete");
733 } 729 }
734 else 730 else
735 { 731 {
736 logger.ErrorFormat("Failed to load {0} as an army file", filePath); 732 logger.ErrorFormat("Failed to load {0} as an army file", filePath);
751 747
752 private bool SaveCurrentArmy() 748 private bool SaveCurrentArmy()
753 { 749 {
754 bool success = false; 750 bool success = false;
755 751
756 if (CanSave()) 752 if (loadedArmyPath!=null)
757 { 753 {
758 success = SaveArmyToPath(WarFoundryCore.CurrentArmy, loadedArmyPath); 754 success = SaveArmyToPath(WarFoundryCore.CurrentArmy, loadedArmyPath);
759 } 755 }
760 756
761 return success; 757 return success;
915 CommandStack.Redo(); 911 CommandStack.Redo();
916 } 912 }
917 913
918 protected virtual void saveTBButtonActivated (object sender, System.EventArgs e) 914 protected virtual void saveTBButtonActivated (object sender, System.EventArgs e)
919 { 915 {
920 SaveCurrentArmy(); 916 SaveCurrentArmyOrSaveAs();
921 } 917 }
922 918
923 protected virtual void openTBButtonActivated (object sender, System.EventArgs e) 919 protected virtual void openTBButtonActivated (object sender, System.EventArgs e)
924 { 920 {
925 OpenArmy(); 921 OpenArmy();