Skip to content

Commit

Permalink
Fixed drag-and-drop of files onto the app icon on Mac OS X.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Zahniser committed May 21, 2015
1 parent 1e1d40d commit 622d32d
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 22 deletions.
39 changes: 39 additions & 0 deletions Info.plist
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array/>
<key>CFBundleTypeName</key>
<string>Text</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSItemContentTypes</key>
<array>
<string>public.plain-text</string>
</array>
<key>NSDocumentClass</key>
<string></string>
</dict>
</array>
<key>CFBundleIconFile</key>
<string>endless-sky-editor.icns</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleGetInfoString</key>
<string>Created by Qt/QMake</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleExecutable</key>
<string>endless-sky-editor</string>
<key>CFBundleIdentifier</key>
<string>endless-sky-editor</string>
<key>NOTE</key>
<string>This file was generated by Qt/QMake.</string>
</dict>
</plist>
37 changes: 21 additions & 16 deletions MainWindow.cpp
Expand Up @@ -39,14 +39,35 @@ MainWindow::MainWindow(Map &map, QWidget *parent)
CreateWidgets();
CreateMenus();
setAcceptDrops(true);

resize(1200, 900);
show();
}



MainWindow::~MainWindow()
{
}



void MainWindow::DoOpen(const QString &path)
{
if(path.isEmpty())
return;

map.Load(path);
galaxyView->Center();
systemView->Select(nullptr);
planetView->Reinitialize();
tabs->setCurrentWidget(galaxyView);
update();
galaxyView->update();
}



void MainWindow::Open()
{
// TODO: ask about saving changes.
Expand Down Expand Up @@ -243,19 +264,3 @@ void MainWindow::CreateMenus()
// Activate only the menu for the current tab.
TabChanged(0);
}



void MainWindow::DoOpen(const QString &path)
{
if(path.isEmpty())
return;

map.Load(path);
galaxyView->Center();
systemView->Select(nullptr);
planetView->Reinitialize();
tabs->setCurrentWidget(galaxyView);
update();
galaxyView->update();
}
3 changes: 2 additions & 1 deletion MainWindow.h
Expand Up @@ -37,6 +37,8 @@ class MainWindow : public QMainWindow
MainWindow(Map &map, QWidget *parent = 0);
~MainWindow();

void DoOpen(const QString &path);

public slots:
void Open();
void Save();
Expand All @@ -53,7 +55,6 @@ public slots:
private:
void CreateWidgets();
void CreateMenus();
void DoOpen(const QString &path);


private:
Expand Down
30 changes: 25 additions & 5 deletions main.cpp
Expand Up @@ -16,12 +16,33 @@ PARTICULAR PURPOSE. See the GNU General Public License for more details.

#include <QApplication>
#include <QFileInfo>
#include <QFileOpenEvent>
#include <QString>

#include <iostream>

using namespace std;

class EventFilter: public QObject {
public:
EventFilter(MainWindow &window) : QObject(), window(window) {};
~EventFilter() {};

bool eventFilter(QObject *obj, QEvent *event)
{
if(event->type() == QEvent::FileOpen)
{
window.DoOpen(dynamic_cast<QFileOpenEvent *>(event)->file());
return false;
}
return obj->event(event);
}

MainWindow &window;
};



void PrintHelp();
void PrintVersion();

Expand Down Expand Up @@ -59,16 +80,15 @@ int main(int argc, char *argv[])
path.clear();
}

QApplication a(argc, argv);
QApplication app(argc, argv);
Map mapData;
if(!path.isEmpty())
mapData.Load(path);

MainWindow w(mapData);
w.resize(1200, 900);
w.show();
MainWindow window(mapData);
app.installEventFilter(new EventFilter(window));

return a.exec();
return app.exec();
}


Expand Down

0 comments on commit 622d32d

Please sign in to comment.