]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiClipboard.cpp
On Linux show in crash message box the backtrace
[lyx.git] / src / frontends / qt4 / GuiClipboard.cpp
index b722ea36ba5981c8440aedac886ae6139404ff46..d96dd26f0be90fdaa5fe793208fbd7fa8a0a3981 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "FileDialog.h"
 
+#include "support/FileName.h"
 #include "GuiClipboard.h"
 #include "qt_helpers.h"
 
@@ -149,31 +150,31 @@ FileName GuiClipboard::getPastedGraphicsFileName(Cursor const & cur,
                types.push_back(Clipboard::PngGraphicsType);
        if (hasGraphicsContents(Clipboard::JpegGraphicsType))
                types.push_back(Clipboard::JpegGraphicsType);
-       
-       LASSERT(!types.empty(), /**/);
-       
+
+       LASSERT(!types.empty(), return FileName());
+
        // select prefered type if AnyGraphicsType was passed
        if (type == Clipboard::AnyGraphicsType)
                type = types.front();
-       
+
        // which extension?
        map<Clipboard::GraphicsType, string> extensions;
        map<Clipboard::GraphicsType, docstring> typeNames;
-       
+
        extensions[Clipboard::EmfGraphicsType] = "emf";
        extensions[Clipboard::WmfGraphicsType] = "wmf";
        extensions[Clipboard::LinkBackGraphicsType] = "linkback";
        extensions[Clipboard::PdfGraphicsType] = "pdf";
        extensions[Clipboard::PngGraphicsType] = "png";
        extensions[Clipboard::JpegGraphicsType] = "jpeg";
-       
+
        typeNames[Clipboard::EmfGraphicsType] = _("Enhanced Metafile");
        typeNames[Clipboard::WmfGraphicsType] = _("Windows Metafile");
        typeNames[Clipboard::LinkBackGraphicsType] = _("LinkBack PDF");
        typeNames[Clipboard::PdfGraphicsType] = _("PDF");
        typeNames[Clipboard::PngGraphicsType] = _("PNG");
        typeNames[Clipboard::JpegGraphicsType] = _("JPEG");
-       
+
        // find unused filename with primary extension
        string document_path = cur.buffer()->fileName().onlyPath().absFileName();
        unsigned newfile_number = 0;
@@ -185,7 +186,7 @@ FileName GuiClipboard::getPastedGraphicsFileName(Cursor const & cur,
                        + convert<string>(newfile_number) + "."
                        + extensions[type]));
        } while (filename.isReadableFile());
-       
+
        while (true) {
                // create file type filter, putting the prefered on to the front
                QStringList filter;
@@ -198,23 +199,23 @@ FileName GuiClipboard::getPastedGraphicsFileName(Cursor const & cur,
                                filter.append(toqstr(s));
                }
                filter = fileFilters(filter.join(";;"));
-               
+
                // show save dialog for the graphic
                FileDialog dlg(qt_("Choose a filename to save the pasted graphic as"));
                FileDialog::Result result =
                dlg.save(toqstr(filename.onlyPath().absFileName()), filter,
                         toqstr(filename.onlyFileName()));
-               
+
                if (result.first == FileDialog::Later)
                        return FileName();
-               
+
                string newFilename = fromqstr(result.second);
                if (newFilename.empty()) {
                        cur.bv().message(_("Canceled."));
                        return FileName();
                }
                filename.set(newFilename);
-               
+
                // check the extension (the user could have changed it)
                if (!suffixIs(ascii_lowercase(filename.absFileName()),
                              "." + extensions[type])) {
@@ -227,7 +228,7 @@ FileName GuiClipboard::getPastedGraphicsFileName(Cursor const & cur,
                                        break;
                                }
                        }
-                       
+
                        // invalid extension found, or none at all. In the latter
                        // case set the default extensions.
                        if (i == types.size()
@@ -235,7 +236,7 @@ FileName GuiClipboard::getPastedGraphicsFileName(Cursor const & cur,
                                filename.changeExtension("." + extensions[type]);
                        }
                }
-               
+
                // check whether the file exists and warn the user
                if (!filename.exists())
                        break;
@@ -246,10 +247,10 @@ FileName GuiClipboard::getPastedGraphicsFileName(Cursor const & cur,
                if (ret == 0)
                        // overwrite, hence break the dialog loop
                        break;
-               
+
                // not overwrite, hence show the dialog again (i.e. loop)
        }
-       
+
        return filename;
 }
 
@@ -279,7 +280,7 @@ FileName GuiClipboard::getAsGraphics(Cursor const & cur, GraphicsType type) cons
                else if (type == JpegGraphicsType)
                        image.save(toqstr(filename.absFileName()), "JPEG");
                else
-                       LASSERT(false, /**/);
+                       LATTEST(false);
                
                return filename;
        }
@@ -291,7 +292,7 @@ FileName GuiClipboard::getAsGraphics(Cursor const & cur, GraphicsType type) cons
        case LinkBackGraphicsType: mime = pdfMimeType(); break;
        case EmfGraphicsType: mime = emfMimeType(); break;
        case WmfGraphicsType: mime = wmfMimeType(); break;
-       default: LASSERT(false, /**/);
+       default: LASSERT(false, return FileName());
        }
        
        // get data
@@ -322,7 +323,7 @@ FileName GuiClipboard::getAsGraphics(Cursor const & cur, GraphicsType type) cons
                ds << pdfLen; // big endian by default
 #else
                // only non-Mac this should never happen
-               LASSERT(false, /**/);
+               LATTEST(false);
 #endif // Q_WS_MACX
        }
 
@@ -412,6 +413,12 @@ docstring const GuiClipboard::getAsText(TextType type) const
 }
 
 
+void GuiClipboard::put(string const & text) const
+{
+       qApp->clipboard()->setText(toqstr(text));
+}
+
+
 void GuiClipboard::put(string const & lyx, docstring const & html, docstring const & text)
 {
        LYXERR(Debug::ACTION, "GuiClipboard::put(`" << lyx << "' `"
@@ -499,7 +506,7 @@ bool GuiClipboard::hasGraphicsContents(Clipboard::GraphicsType type) const
        case EmfGraphicsType: mime = emfMimeType(); break;
        case WmfGraphicsType: mime = wmfMimeType(); break;
        case PdfGraphicsType: mime = pdfMimeType(); break;
-       default: LASSERT(false, /**/);
+       default: LASSERT(false, return false);
        }
        
        return cache_.hasFormat(mime);