Linux file open dialog

C++ simple open file dialog in linux

I was wondering if anyone could help me out on implementing a simple file open dialog in C++ in Ubuntu. I am using OpenGL for my GUI, but I would like the user to be able to select a file when the program loads. I have tried gtkmm and wxWidgets but they seem to be too complicated for what I want to do.

gtkmm and wxWidgets both come with premade file chooser dialogs. Does it get much simpler than that? In what way are those too complicated for you?

what I mean is that both openGl and gtk need their own main loops to be running at the same time, and I don’t know how to integrate both of them. thanks for the response

Why «at the same time»? You say you need to select a file when the program loads so theoretically you could even have a separate gtkmm program for the file chooser that then passes the file name as a command line parameter to your OpenGL app.

oh I mean that the user should be able to load a file when it starts but also at any time during the use of the program. but that does make sense.

4 Answers 4

If you just need to select a file, then launch a separate program to do that. Like @Dummy00001 said in the comment, you can start zenity —file-selection as a child process and read its stdout.

char filename[1024]; FILE *f = popen("zenity --file-selection", "r"); fgets(filename, 1024, f); 

Or you can also write your own program to do the task. That way you can customize the UI as you wish.

Читайте также:  Универсальный драйвер принтера canon linux

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

A tiny, neat C library that portably invokes native file open and save dialogs.

License

mlabbe/nativefiledialog

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

A tiny, neat C library that portably invokes native file open, folder select and save dialogs. Write dialog code once and have it pop up native dialogs on all supported platforms. Avoid linking large dependencies like wxWidgets and qt.

  • Lean C API, static library — no ObjC, no C++, no STL.
  • Zlib licensed.
  • Consistent UTF-8 support on all platforms.
  • Simple universal file filter syntax.
  • Paid support available.
  • Multiple file selection support.
  • 64-bit and 32-bit friendly.
  • GCC, Clang, Xcode, Mingw and Visual Studio supported.
  • No third party dependencies for building or linking.
  • Support for Vista’s modern IFileDialog on Windows.
  • Support for non-deprecated Cocoa APIs on OS X.
  • GTK3 dialog on Linux.
  • Optional Zenity support on Linux to avoid linking GTK.
  • Tested, works alongside http://www.libsdl.org on all platforms, for the game developers out there.
#include #include #include int main( void ) < nfdchar_t *outPath = NULL; nfdresult_t result = NFD_OpenDialog( NULL, NULL, &outPath ); if ( result == NFD_OKAY ) < puts("Success!"); puts(outPath); free(outPath); > else if ( result == NFD_CANCEL ) < puts("User pressed cancel."); > else < printf("Error: %s\n", NFD_GetError() ); > return 0; >

See self-documenting API NFD.h for more options.

Windows rendering a dialog GTK3 on Linux rendering a dialog Cocoa on MacOS rendering a dialog

  • Major version increments denote API or ABI departure.
  • Minor version increments denote build or trivial departures.
  • Micro version increments just recompile and drop-in.

NFD uses Premake5 generated Makefiles and IDE project files. The generated project files are checked in under build/ so you don’t have to download and use Premake in most cases.

If you need to run Premake5 directly, further build documentation is available.

Previously, NFD used SCons to build. As of 1.1.6, SCons support has been removed entirely.

nfd.a will be built for release builds, and nfd_d.a will be built for debug builds.

The makefile offers up to four options, with release_x64 as the default.

make config=release_x86 make config=release_x64 make config=debug_x86 make config=debug_x64 
  1. Add src/include to your include search path.
  2. Add nfd.lib or nfd_d.lib to the list of list of static libraries to link against (for release or debug, respectively).
  3. Add build// to the library search path.

apt-get libgtk-3-dev installs the gtk dependency for library compilation.

On Linux, you have the option of compiling and linking against GTK. If you use it, the recommended way to compile is to include the arguments of pkg-config —cflags —libs gtk+-3.0 .

Alternatively, you can use the Zenity backend by running the Makefile in build/gmake_linux_zenity . Zenity runs the dialog in its own address space, but requires the user to have Zenity correctly installed and configured on their system.

On Mac OS, add AppKit to the list of frameworks.

On Windows, ensure you are linking against comctl32.lib .

See NFD.h for API calls. See tests/*.c for example code.

After compiling, build/bin contains compiled test programs. The appropriate subdirectory under build/lib contains the built library.

There is a form of file filtering in every file dialog API, but no consistent means of supporting it. NFD provides support for filtering files by groups of extensions, providing its own descriptions (where applicable) for the extensions.

A wildcard filter is always added to every dialog.

txt The default filter is for text files. There is a wildcard option in a dropdown.

png,jpg;psd The default filter is for png and jpg files. A second filter is available for psd files. There is a wildcard option in a dropdown.

I accept quality code patches, or will resolve these and other matters through support. See contributing for details.

  • No support for Windows XP’s legacy dialogs such as GetOpenFileName .
  • No support for file filter names — ex: «Image Files» (*.png, *.jpg). Nameless filters are supported, however.
  • GTK Zenity implementation’s process exec error handling does not gracefully handle numerous error cases, choosing to abort rather than cleanup and return.
  • GTK 3 spams one warning per dialog created.

Copyright © 2014-2019 Frogtoss Games, Inc. File LICENSE covers all files in this repo.

Native File Dialog by Michael Labbe mike@frogtoss.com

Directed support for this work is available from the original author under a paid agreement.

About

A tiny, neat C library that portably invokes native file open and save dialogs.

Источник

Оцените статью
Adblock
detector