/[Sims3RigEditor]/trunk/gr2lib_cpp/gr2lib_rigeditor_frm.h
ViewVC logotype

Diff of /trunk/gr2lib_cpp/gr2lib_rigeditor_frm.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/gr2lib_cpp/gr2lib_rigeditor_frm.h	2010/08/15 00:51:50	88
+++ trunk/gr2lib_cpp/gr2lib_rigeditor_frm.h	2010/08/15 01:12:18	89
@@ -61,6 +61,9 @@
 public ref class gr2lib_rigeditor_frm : public System::Windows::Forms::Form
 {
 private:
+
+	bool IsRigLoaded;
+	bool RigContainsUnsavedChanges;
 	grannyfile* _grn_file;
 	void LogApplicationStartup()
 	{
@@ -185,6 +188,7 @@
 		this->propgrid->Size = System::Drawing::Size(558, 456);
 		this->propgrid->TabIndex = 4;
 		this->propgrid->ToolbarVisible = false;
+		this->propgrid->PropertyValueChanged += gcnew System::Windows::Forms::PropertyValueChangedEventHandler(this, &gr2lib_rigeditor_frm::propgrid_PropertyValueChanged);
 		// 
 		// mainmenu
 		// 
@@ -206,35 +210,35 @@
 		// mnuItemOpen
 		// 
 		this->mnuItemOpen->Name = L"mnuItemOpen";
-		this->mnuItemOpen->Size = System::Drawing::Size(114, 22);
+		this->mnuItemOpen->Size = System::Drawing::Size(152, 22);
 		this->mnuItemOpen->Text = L"&Open";
 		this->mnuItemOpen->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuItemOpen_Click);
 		// 
 		// mnuItemClose
 		// 
 		this->mnuItemClose->Name = L"mnuItemClose";
-		this->mnuItemClose->Size = System::Drawing::Size(114, 22);
+		this->mnuItemClose->Size = System::Drawing::Size(152, 22);
 		this->mnuItemClose->Text = L"&Close";
 		this->mnuItemClose->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuItemClose_Click);
 		// 
 		// mnuItemSave
 		// 
 		this->mnuItemSave->Name = L"mnuItemSave";
-		this->mnuItemSave->Size = System::Drawing::Size(114, 22);
+		this->mnuItemSave->Size = System::Drawing::Size(152, 22);
 		this->mnuItemSave->Text = L"&Save";
 		this->mnuItemSave->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuItemSave_Click);
 		// 
 		// mnuItemSaveAs
 		// 
 		this->mnuItemSaveAs->Name = L"mnuItemSaveAs";
-		this->mnuItemSaveAs->Size = System::Drawing::Size(114, 22);
+		this->mnuItemSaveAs->Size = System::Drawing::Size(152, 22);
 		this->mnuItemSaveAs->Text = L"Save &As";
 		this->mnuItemSaveAs->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuItemSaveAs_Click);
 		// 
 		// mnuItemExit
 		// 
 		this->mnuItemExit->Name = L"mnuItemExit";
-		this->mnuItemExit->Size = System::Drawing::Size(114, 22);
+		this->mnuItemExit->Size = System::Drawing::Size(152, 22);
 		this->mnuItemExit->Text = L"&Exit";
 		this->mnuItemExit->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuItemExit_Click);
 		// 
@@ -847,11 +851,20 @@
 
 private: System::Void mnuItemExit_Click(System::Object^  sender, System::EventArgs^  e) 
 		 {			
-			 ConvertToNative();
+			 if (this->IsRigLoaded && this->RigContainsUnsavedChanges)
+			 {				 
+				 System::Windows::Forms::DialogResult result = System::Windows::Forms::MessageBox::Show("Do you wish to save the currently opened Granny2 Rig?", "File Loader:", MessageBoxButtons::YesNo,MessageBoxIcon::Question);
+				 if (result != System::Windows::Forms::DialogResult::Yes) mnuItemSave->PerformClick();
+			 }
 			 this->Close();
 		 }
 private: System::Void mnuItemOpen_Click(System::Object^  sender, System::EventArgs^  e) 
 		 {
+			 if (this->IsRigLoaded && this->RigContainsUnsavedChanges)
+			 {				 
+				 System::Windows::Forms::DialogResult result = System::Windows::Forms::MessageBox::Show("Do you wish to save the currently opened Granny2 Rig?", "File Loader:", MessageBoxButtons::YesNo,MessageBoxIcon::Question);
+				 if (result == System::Windows::Forms::DialogResult::Yes) mnuItemSave->PerformClick();
+			 }
 			 System::Windows::Forms::DialogResult result = RigLoader->ShowDialog();
 			 if (result != System::Windows::Forms::DialogResult::OK) return;
 			 const char* fn = (char*)Marshal::StringToHGlobalAnsi(RigLoader->FileName).ToPointer();
@@ -871,6 +884,8 @@
 			 this->GR2LibPropertyWrapper = gcnew GR2LibWrapper();
 			 ConvertToManaged();
 			 propgrid->SelectedObject = this->GR2LibPropertyWrapper->GetPropertiesValidForThisInstance();
+			 this->IsRigLoaded = true;
+			  this->RigContainsUnsavedChanges = false;
 		 }
 private: System::Void gr2lib_rigeditor_frm_FormClosed(System::Object^  sender, System::Windows::Forms::FormClosedEventArgs^  e) 
 		 {
@@ -948,11 +963,17 @@
 		 {
 			 // convert Data to Native
 			 try 
-			 {				
+			 {	
+				 if (!this->IsRigLoaded)
+				 {
+					 System::Windows::Forms::MessageBox::Show("Please open a Granny2 Rig file before attempting to save it.", "File Writer:", MessageBoxButtons::OK,MessageBoxIcon::Asterisk);
+					 return;
+				 }
 				 ConvertToNative();
 				 const char* filename = _grn_file->_GrannyFilename;
 				 GrannyFileWriter::WriteFile(filename,_grn_file->GrannyFileInfo,_grn_file->_logger);		
 				 System::Windows::Forms::MessageBox::Show("Successfully Saved: \n" + gcnew String(_grn_file->GrannyFilename()),"File Writer:", MessageBoxButtons::OK,MessageBoxIcon::Information);
+				 this->RigContainsUnsavedChanges = false;
 			 }
 			 catch(Exception^ ex)
 			 {
@@ -964,12 +985,18 @@
 			 // convert Data to Native
 			 try
 			 {
+				 if (!this->IsRigLoaded)
+				 {
+					 System::Windows::Forms::MessageBox::Show("Please open a Granny2 Rig file before attempting to save it.", "File Writer:", MessageBoxButtons::OK,MessageBoxIcon::Asterisk);
+					 return;
+				 }
 				 ConvertToNative();
 				 System::Windows::Forms::DialogResult result = RigSaver->ShowDialog();
 				 if (result != System::Windows::Forms::DialogResult::OK) return;
 				 const char* filename = (char*)Marshal::StringToHGlobalAnsi(RigSaver->FileName).ToPointer();
 				 GrannyFileWriter::WriteFile(filename,_grn_file->GrannyFileInfo,_grn_file->_logger);		
 				 System::Windows::Forms::MessageBox::Show("Successfully Saved: \n" +  gcnew String(_grn_file->GrannyFilename()),"File Writer:", MessageBoxButtons::OK,MessageBoxIcon::Information);
+				 this->RigContainsUnsavedChanges = false;
 			 }
 			 catch(Exception^ ex)
 			 {
@@ -978,7 +1005,18 @@
 		 }
 private: System::Void mnuItemClose_Click(System::Object^  sender, System::EventArgs^  e) 
 		 {
+			 if (this->IsRigLoaded && this->RigContainsUnsavedChanges)
+			 {				 
+				 System::Windows::Forms::DialogResult result = System::Windows::Forms::MessageBox::Show("Do you wish to save the currently opened Granny2 Rig?", "File Loader:", MessageBoxButtons::YesNo,MessageBoxIcon::Question);
+				 if (result == System::Windows::Forms::DialogResult::Yes) mnuItemSave->PerformClick();
+			 }
 			 propgrid->SelectedObject = nullptr;
+			 this->IsRigLoaded = false;
+			  this->RigContainsUnsavedChanges = false;
+		 }
+private: System::Void propgrid_PropertyValueChanged(System::Object^  s, System::Windows::Forms::PropertyValueChangedEventArgs^  e) 
+		 {
+			 this->RigContainsUnsavedChanges =true;
 		 }
 };
 //		}

 

  ViewVC Help
Powered by ViewVC 1.1.22