]> git.lyx.org Git - features.git/commitdiff
Fix bug #2948: Drag and drop support for all importable file types.
authorVincent van Ravesteijn <vfr@lyx.org>
Sat, 12 Dec 2009 15:25:45 +0000 (15:25 +0000)
committerVincent van Ravesteijn <vfr@lyx.org>
Sat, 12 Dec 2009 15:25:45 +0000 (15:25 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32492 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiView.cpp

index d5aede6382430084ab33acac73b0125148eccdc2..1ec7a2f13e03f3ac63211bf3f736cf6b7b36a80d 100644 (file)
@@ -608,13 +608,42 @@ void GuiView::dropEvent(QDropEvent * event)
        for (int i = 0; i != files.size(); ++i) {
                string const file = os::internal_path(fromqstr(
                        files.at(i).toLocalFile()));
-               if (!file.empty()) {
-                       // Asynchronously post the event. DropEvent usually come
-                       // from the BufferView. But reloading a file might close
-                       // the BufferView from within its own event handler.
-                       guiApp->dispatchDelayed(FuncRequest(LFUN_FILE_OPEN, file));
-                       event->accept();
+               if (file.empty())
+                       continue;
+
+               string const ext = support::getExtension(file);
+               vector<const Format *> found_formats;
+
+               // Find all formats that have the correct extension.
+               vector<const Format *> const & import_formats 
+                       = theConverters().importableFormats();
+               vector<const Format *>::const_iterator it = import_formats.begin();
+               for (; it != import_formats.end(); ++it)
+                       if ((*it)->extension() == ext)
+                               found_formats.push_back(*it);
+
+               FuncRequest cmd;
+               if (found_formats.size() >= 1) {
+                       if (found_formats.size() > 1) {
+                               //FIXME: show a dialog to choose the correct importable format
+                               LYXERR(Debug::FILES,
+                                       "Multiple importable formats found, selecting first");
+                       }
+                       string const arg = found_formats[0]->name() + " " + file;
+                       cmd = FuncRequest(LFUN_BUFFER_IMPORT, arg);
+               } 
+               else {
+                       //FIXME: do we have to explicitly check whether it's a lyx file?
+                       LYXERR(Debug::FILES,
+                               "No formats found, trying to open it as a lyx file");
+                       cmd = FuncRequest(LFUN_FILE_OPEN, file);
                }
+
+               // Asynchronously post the event. DropEvent usually come
+               // from the BufferView. But reloading a file might close
+               // the BufferView from within its own event handler.
+               guiApp->dispatchDelayed(cmd);
+               event->accept();
        }
 }