src/gui_actions.cpp

changeset 310
c62edce5668c
parent 292
4779ca562d5e
child 315
cb0c23f35e2b
equal deleted inserted replaced
309:11ec6aa1f1fb 310:c62edce5668c
64 } 64 }
65 65
66 // ============================================================================= 66 // =============================================================================
67 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 67 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
68 // ============================================================================= 68 // =============================================================================
69 void doSave (bool saveAs) { 69 MAKE_ACTION( save, "&Save", "file-save", "Save the part model.", CTRL( S ))
70 str path = g_curfile->name (); 70 {
71 71 g_win->save( g_curfile, false );
72 if (path.length () == 0 || saveAs) { 72 }
73 path = QFileDialog::getSaveFileName (g_win, "Save As", 73
74 g_curfile->name (), "LDraw files (*.dat *.ldr)"); 74 // =============================================================================
75 75 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
76 if (path.length () == 0) { 76 // =============================================================================
77 // User didn't give a file name. This happens if the user cancelled 77 MAKE_ACTION( saveAs, "Save &As", "file-save-as", "Save the part model to a specific file.", CTRL_SHIFT( S ))
78 // saving in the save file dialog. Abort. 78 {
79 return; 79 g_win->save( g_curfile, true );
80 }
81 }
82
83 if (g_curfile->save (path)) {
84 g_curfile->setName (path);
85 g_win->updateTitle ();
86 } else {
87 setlocale (LC_ALL, "C");
88
89 // Tell the user the save failed, and give the option for saving as with it.
90 QMessageBox dlg (QMessageBox::Critical, "Save Failure",
91 fmt ("Failed to save to %1\nReason: %2", path, strerror (errno)),
92 QMessageBox::Close, g_win);
93
94 QPushButton* saveAsBtn = new QPushButton ("Save As");
95 saveAsBtn->setIcon (getIcon ("file-save-as"));
96 dlg.addButton (saveAsBtn, QMessageBox::ActionRole);
97 dlg.setDefaultButton (QMessageBox::Close);
98 dlg.exec ();
99
100 if (dlg.clickedButton () == saveAsBtn)
101 doSave (true); // yay recursion!
102 }
103 }
104
105 // =============================================================================
106 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
107 // =============================================================================
108 MAKE_ACTION (save, "&Save", "file-save", "Save the part model.", CTRL (S)) {
109 doSave (false);
110 }
111
112 // =============================================================================
113 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
114 // =============================================================================
115 MAKE_ACTION (saveAs, "Save &As", "file-save-as", "Save the part model to a specific file.", CTRL_SHIFT (S)) {
116 doSave (true);
117 } 80 }
118 81
119 // ============================================================================= 82 // =============================================================================
120 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 83 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
121 // ============================================================================= 84 // =============================================================================
168 131
169 MAKE_ACTION (newVertex, "New Vertex", "add-vertex", "Creates a new vertex.", 0) { 132 MAKE_ACTION (newVertex, "New Vertex", "add-vertex", "Creates a new vertex.", 0) {
170 AddObjectDialog::staticDialog (LDObject::Vertex, null); 133 AddObjectDialog::staticDialog (LDObject::Vertex, null);
171 } 134 }
172 135
173 MAKE_ACTION (newRadial, "New Radial", "add-radial", "Creates a new radial.", 0) { 136 MAKE_ACTION( makePrimitive, "Make a Primitive", "radial", "Generate a new circular primitive.", 0 )
174 AddObjectDialog::staticDialog (LDObject::Radial, null); 137 {
138 generatePrimitive();
175 } 139 }
176 140
177 MAKE_ACTION (editObject, "Edit Object", "edit-object", "Edits this object.", 0) { 141 MAKE_ACTION (editObject, "Edit Object", "edit-object", "Edits this object.", 0) {
178 if (g_win->sel ().size () != 1) 142 if (g_win->sel ().size () != 1)
179 return; 143 return;

mercurial