Added actions for saving all files, closing and closing all files

Tue, 16 Jul 2013 02:06:30 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Tue, 16 Jul 2013 02:06:30 +0300
changeset 389
ccb763dbe98e
parent 388
7ff483614aa1
child 390
57be36dfa55e

Added actions for saving all files, closing and closing all files

src/actions.h file | annotate | diff | comparison | revisions
src/file.cpp file | annotate | diff | comparison | revisions
src/gui_actions.cpp file | annotate | diff | comparison | revisions
src/ui/ldforge.ui file | annotate | diff | comparison | revisions
--- a/src/actions.h	Tue Jul 16 01:33:11 2013 +0300
+++ b/src/actions.h	Tue Jul 16 02:06:30 2013 +0300
@@ -2,6 +2,9 @@
 act (Open)
 act (Save)
 act (SaveAs)
+act (SaveAll)
+act (Close)
+act (CloseAll)
 act (InsertFrom)
 act (ExportTo)
 act (Settings)
--- a/src/file.cpp	Tue Jul 16 01:33:11 2013 +0300
+++ b/src/file.cpp	Tue Jul 16 02:06:30 2013 +0300
@@ -102,6 +102,8 @@
 
 // =============================================================================
 LDOpenFile::~LDOpenFile() {
+	ulong i;
+	
 	// Clear everything from the model
 	for (LDObject* obj : m_objs)
 		delete obj;
@@ -109,6 +111,29 @@
 	// Clear the cache as well
 	for (LDObject* obj : m_cache)
 		delete obj;
+	
+	// Remove this file from the list of files
+	for (i = 0; i < g_loadedFiles.size(); ++i) {
+		if (g_loadedFiles[i] == this) {
+			g_loadedFiles.erase (i);
+			break;
+		}
+	}
+	
+	// If we just closed the current file, we need to set the current
+	// file as something else.
+	if (this == LDOpenFile::current()) {
+		if (i > 0)
+			i--;
+		
+		// If we closed the last file, create a blank one.
+		if (g_loadedFiles.size() < i + 1)
+			newFile();
+		else
+			LDOpenFile::setCurrent (g_loadedFiles[i]);
+	}
+	
+	g_win->updateFileList();
 }
 
 // =============================================================================
@@ -565,6 +590,7 @@
 	setSavePos (history().pos());
 	setName (savepath);
 	
+	g_win->updateFileListItem (this);
 	g_win->updateTitle();
 	return true;
 }
--- a/src/gui_actions.cpp	Tue Jul 16 01:33:11 2013 +0300
+++ b/src/gui_actions.cpp	Tue Jul 16 02:06:30 2013 +0300
@@ -111,6 +111,38 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
+DEFINE_ACTION (SaveAll, CTRL (L)) {
+	for (LDOpenFile* file : g_loadedFiles) {
+		if (file->implicit())
+			continue;
+		
+		g_win->save (file, false);
+	}
+}
+
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
+DEFINE_ACTION (Close, CTRL (W)) {
+	if (!LDOpenFile::current()->safeToClose())
+		return;
+	
+	delete LDOpenFile::current();
+}
+
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
+DEFINE_ACTION (CloseAll, 0) {
+	if (!safeToCloseAll())
+		return;
+	
+	closeAll();
+}
+
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
 DEFINE_ACTION (Settings, 0) {
 	ConfigDialog::staticDialog();
 }
--- a/src/ui/ldforge.ui	Tue Jul 16 01:33:11 2013 +0300
+++ b/src/ui/ldforge.ui	Tue Jul 16 02:06:30 2013 +0300
@@ -88,6 +88,10 @@
     <addaction name="menuOpenRecent"/>
     <addaction name="actionSave"/>
     <addaction name="actionSaveAs"/>
+    <addaction name="actionSaveAll"/>
+    <addaction name="separator"/>
+    <addaction name="actionClose"/>
+    <addaction name="actionCloseAll"/>
     <addaction name="separator"/>
     <addaction name="actionInsertFrom"/>
     <addaction name="actionExportTo"/>
@@ -1221,6 +1225,21 @@
     <string>Set Rotation Point</string>
    </property>
   </action>
+  <action name="actionSaveAll">
+   <property name="text">
+    <string>Save All</string>
+   </property>
+  </action>
+  <action name="actionClose">
+   <property name="text">
+    <string>Close</string>
+   </property>
+  </action>
+  <action name="actionCloseAll">
+   <property name="text">
+    <string>Close All</string>
+   </property>
+  </action>
  </widget>
  <resources>
   <include location="../../ldforge.qrc"/>

mercurial