Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ if(APPLE)
MACOSX_BUNDLE_SHORT_VERSION_STRING "${CSV_EXPLORER_VERSION}"
MACOSX_BUNDLE_BUNDLE_VERSION "${CSV_EXPLORER_VERSION}"
MACOSX_BUNDLE_ICON_FILE "csv-explorer.icns"
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist.in"
)
set_source_files_properties(${CSV_EXPLORER_BUNDLE_ICON} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
set_source_files_properties(${CSV_EXPLORER_WINDOW_ICON} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
Expand Down
43 changes: 43 additions & 0 deletions Info.plist.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?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>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string>${MACOSX_BUNDLE_ICON_FILE}</string>
<key>CFBundleIdentifier</key>
<string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${MACOSX_BUNDLE_BUNDLE_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string>
<key>CFBundleVersion</key>
<string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>csv</string>
</array>
<key>CFBundleTypeName</key>
<string>Comma-Separated Values File</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>public.comma-separated-values-text</string>
</array>
</dict>
</array>
</dict>
</plist>
12 changes: 12 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,21 @@ class CsvExplorerApp : public wxApp {
}

auto* frame = CreateMainFrame(initialFile);
SetTopWindow(frame);
frame->Show();
return true;
}

#ifdef __WXOSX__
void MacOpenFile(const wxString& fileName) override {
wxFrame* frame = wxDynamicCast(GetTopWindow(), wxFrame);
if (!frame) {
return;
}

OpenFileInMainFrame(frame, fileName);
}
#endif
};

wxIMPLEMENT_APP(CsvExplorerApp);
51 changes: 47 additions & 4 deletions src/main_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <wx/textfile.h>
#include <wx/filename.h>
#include <wx/clipbrd.h>
#include <wx/dnd.h>
#include <wx/ffile.h>
#include <wx/grid.h>

Expand Down Expand Up @@ -133,19 +134,42 @@ class MainFrame : public wxFrame {
public:
explicit MainFrame(const wxString& initialFile)
: wxFrame(nullptr, wxID_ANY, CSV_EXPLORER_NAME, wxDefaultPosition, wxSize(900, 600)) {
SetDropTarget(new CsvFileDropTarget(*this));
BuildMenuBar();
BuildAccelerators();
BuildGrid();
BuildStatusBar();
ApplyWindowIcon();
if (!initialFile.IsEmpty()) {
OpenFile(initialFile);
OpenDocumentFile(initialFile);
} else {
CreateNewFile();
}
}

bool OpenDocumentFile(const wxString& path) {
if (!ConfirmDirtyFileAction()) {
return false;
}

OpenFile(path);
return !m_currentFile.IsEmpty() && m_currentFile == path;
}

private:
class CsvFileDropTarget final : public wxFileDropTarget {
public:
explicit CsvFileDropTarget(MainFrame& frame)
: m_frame(frame) {}

bool OnDropFiles(wxCoord, wxCoord, const wxArrayString& filenames) override {
return m_frame.HandleDroppedFiles(filenames);
}

private:
MainFrame& m_frame;
};

void BuildMenuBar() {
auto* fileMenu = new wxMenu();
fileMenu->Append(wxID_NEW, "&New\tCtrl+N");
Expand All @@ -170,9 +194,9 @@ class MainFrame : public wxFrame {
editMenu->AppendSeparator();
auto* goToMenu = new wxMenu();
#ifdef __WXOSX__
goToMenu->Append(ID_GO_TO_FIRST, "Go to &First\tCmd+Up");
goToMenu->Append(ID_GO_TO_LAST, "Go to &Last\tCmd+Down");
goToMenu->Append(ID_GO_TO_ROW, "Go to &Row...\tCmd+G");
goToMenu->Append(ID_GO_TO_FIRST, "Go to &First\tCtrl+Up");
goToMenu->Append(ID_GO_TO_LAST, "Go to &Last\tCtrl+Down");
goToMenu->Append(ID_GO_TO_ROW, "Go to &Row...\tCtrl+G");
#else
goToMenu->Append(ID_GO_TO_FIRST, "Go to &First\tCtrl+Home");
goToMenu->Append(ID_GO_TO_LAST, "Go to &Last\tCtrl+End");
Expand Down Expand Up @@ -214,6 +238,8 @@ class MainFrame : public wxFrame {
m_grid->Bind(wxEVT_CHAR_HOOK, &MainFrame::OnGridCharHook, this);
m_grid->Bind(wxEVT_SIZE, &MainFrame::OnGridResized, this);
m_grid->GetGridWindow()->Bind(wxEVT_LEFT_DCLICK, &MainFrame::OnGridWindowLeftDClick, this);
m_grid->SetDropTarget(new CsvFileDropTarget(*this));
m_grid->GetGridWindow()->SetDropTarget(new CsvFileDropTarget(*this));

m_headerEditor = new wxTextCtrl(
m_grid->GetGridColLabelWindow(),
Expand Down Expand Up @@ -691,6 +717,14 @@ class MainFrame : public wxFrame {
ResizeToCsvContent();
}

bool HandleDroppedFiles(const wxArrayString& filenames) {
if (!IsEffectivelyEmptyDocument() || filenames.empty()) {
return false;
}

return OpenDocumentFile(filenames[0]);
}

void ResizeToCsvContent() {
if (!m_grid || m_rows.empty() || GetColumnCount() == 0) {
return;
Expand Down Expand Up @@ -1349,3 +1383,12 @@ wxEND_EVENT_TABLE()
wxFrame* CreateMainFrame(const wxString& initialFile) {
return new MainFrame(initialFile);
}

bool OpenFileInMainFrame(wxFrame* frame, const wxString& path) {
auto* mainFrame = dynamic_cast<MainFrame*>(frame);
if (!mainFrame) {
return false;
}

return mainFrame->OpenDocumentFile(path);
}
1 change: 1 addition & 0 deletions src/main_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ class wxFrame;
class wxString;

wxFrame* CreateMainFrame(const wxString& initialFile);
bool OpenFileInMainFrame(wxFrame* frame, const wxString& path);
Loading