Sat, 25 May 2013 02:05:35 +0300
Added Export To File action, moved it + insert from to File menu
icons/file-export.png | file | annotate | diff | comparison | revisions | |
icons/file-import.png | file | annotate | diff | comparison | revisions | |
ldforge.qrc | file | annotate | diff | comparison | revisions | |
src/gui.cpp | file | annotate | diff | comparison | revisions | |
src/gui_actions.cpp | file | annotate | diff | comparison | revisions | |
src/misc.cpp | file | annotate | diff | comparison | revisions | |
src/string.h | file | annotate | diff | comparison | revisions |
--- a/ldforge.qrc Sat May 25 01:44:11 2013 +0300 +++ b/ldforge.qrc Sat May 25 02:05:35 2013 +0300 @@ -41,6 +41,8 @@ <file>./icons/empty.png</file> <file>./icons/error.png</file> <file>./icons/exit.png</file> + <file>./icons/file-export.png</file> + <file>./icons/file-import.png</file> <file>./icons/file-new.png</file> <file>./icons/file-open.png</file> <file>./icons/file.png</file>
--- a/src/gui.cpp Sat May 25 01:44:11 2013 +0300 +++ b/src/gui.cpp Sat May 25 02:05:35 2013 +0300 @@ -167,6 +167,9 @@ addMenuAction ("save"); // Save addMenuAction ("saveAs"); // Save As menu->addSeparator (); // ------- + addMenuAction ("insertFrom"); // Insert from File + addMenuAction ("exportTo"); // Export to File + menu->addSeparator (); // ------- addMenuAction ("settings"); // Settings addMenuAction ("setLDrawPath"); // Set LDraw Path menu->addSeparator (); // ------- @@ -188,7 +191,6 @@ // Insert menu initMenu ("&Insert"); - addMenuAction ("insertFrom"); // Insert from File addMenuAction ("insertRaw"); // Insert Raw menu->addSeparator (); // ------- addMenuAction ("newSubfile"); // New Subfile
--- a/src/gui_actions.cpp Sat May 25 01:44:11 2013 +0300 +++ b/src/gui_actions.cpp Sat May 25 02:05:35 2013 +0300 @@ -297,7 +297,7 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -MAKE_ACTION (insertFrom, "Insert from File", "insert-from", "Insert LDraw data from a file.", (0)) { +MAKE_ACTION (insertFrom, "Insert from File", "file-import", "Insert LDraw data from a file.", (0)) { str fname = QFileDialog::getOpenFileName (); ulong idx = g_win->getInsertionPoint (); @@ -335,6 +335,30 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= +MAKE_ACTION (exportTo, "Export To File", "file-export", "Export current selection to file", (0)) { + if (g_win->sel ().size () == 0) + return; + + str fname = QFileDialog::getSaveFileName (); + if (fname.len () == 0) + return; + + QFile file (fname); + if (!file.open (QIODevice::WriteOnly | QIODevice::Text)) { + critical (fmt ("Unable to open %s for writing (%s)", fname.chars (), strerror (errno))); + return; + } + + for (LDObject* obj : g_win->sel ()) { + str contents = obj->getContents (); + file.write (contents, contents.len ()); + file.write ("\r\n", 2); + } +} + +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= MAKE_ACTION (insertRaw, "Insert Raw", "insert-raw", "Type in LDraw code to insert.", (0)) { ulong idx = g_win->getInsertionPoint ();
--- a/src/misc.cpp Sat May 25 01:44:11 2013 +0300 +++ b/src/misc.cpp Sat May 25 02:05:35 2013 +0300 @@ -155,7 +155,6 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= bool isNumber (const str& tok) { - char* ptr = &tok[0]; bool gotDot = false; for (const char& c : tok) {
--- a/src/string.h Sat May 25 01:44:11 2013 +0300 +++ b/src/string.h Sat May 25 02:05:35 2013 +0300 @@ -45,14 +45,14 @@ void append (const char data) { m_string.push_back (data); } void append (const String data) { m_string.append (data.chars ()); } it begin () { return m_string.begin (); } + c_it begin () const { return m_string.cbegin (); } const char* c () const { return chars (); } size_t capacity () const { return m_string.capacity (); } const char* chars () const { return m_string.c_str (); } int compare (const char* other) const { return m_string.compare (other); } int compare (String other) const { return m_string.compare (other); } it end () { return m_string.end (); } - c_it cbegin () const { return m_string.cbegin (); } - c_it cend () const { return m_string.end (); } + c_it end () const { return m_string.end (); } void clear () { m_string.clear (); } ushort count (const char needle) const; bool empty () const { return m_string.empty (); }