- Added wxWindow::NavigateIn() in addition to existing Navigate()
- Add support for <data> tags to wxrc
- Support wxAPPLY and wxCLOSE in CreateStdDialogButtonSizer() (Marcin Wojdyr)
+- Show standard options in wxCmdLineParser usage message (Francesco Montorsi)
wxGTK:
// return the name of the Desktop Environment such as
// "KDE" or "GNOME". May return an empty string.
- virtual wxString GetDesktopEnvironment() const { return wxEmptyString; }
+ virtual wxString GetDesktopEnvironment() const = 0;
+
+ // returns a short string to identify the block of the standard command
+ // line options parsed automatically by current port: if this string is
+ // empty, there are no such options, otherwise the function also fills
+ // passed arrays with the names and the descriptions of those options.
+ virtual wxString GetStandardCmdLineOptions(wxArrayString& names,
+ wxArrayString& desc) const
+ {
+ wxUnusedVar(names);
+ wxUnusedVar(desc);
+
+ return wxEmptyString;
+ }
+
protected:
#if wxUSE_STACKWALKER && defined( __WXDEBUG__ )
}
virtual bool IsUsingUniversalWidgets() const { return false; }
+ virtual wxString GetDesktopEnvironment() const { return wxEmptyString; }
};
// ----------------------------------------------------------------------------
return false;
#endif
}
+
+ virtual wxString GetDesktopEnvironment() const { return wxEmptyString; }
};
#endif // wxUSE_GUI
#ifdef __WXGTK__
virtual void SetLocale();
virtual wxString GetDesktopEnvironment() const;
+ virtual wxString GetStandardCmdLineOptions(wxArrayString& names,
+ wxArrayString& desc) const;
#endif
#if defined(__WXDEBUG__) && defined(__WXGTK20__)
#include "wx/datetime.h"
#include "wx/msgout.h"
#include "wx/filename.h"
+#include "wx/apptrait.h"
// ----------------------------------------------------------------------------
// private functions
// cmd line data
wxArrayString m_arguments; // == argv, argc == m_arguments.GetCount()
- wxArrayOptions m_options; // all possible options and switchrs
+ wxArrayOptions m_options; // all possible options and switches
wxArrayParams m_paramDesc; // description of all possible params
wxArrayString m_parameters; // all params found
usage << _T('\n');
+ // set to number of our own options, not counting the standard ones
+ count = namesOptions.size();
+
+ // get option names & descriptions for standard options, if any:
+ wxAppTraits *traits = wxTheApp ? wxTheApp->GetTraits() : NULL;
+ wxString stdDesc;
+ if ( traits )
+ stdDesc = traits->GetStandardCmdLineOptions(namesOptions, descOptions);
+
// now construct the detailed help message
size_t len, lenMax = 0;
- count = namesOptions.size();
- for ( n = 0; n < count; n++ )
+ for ( n = 0; n < namesOptions.size(); n++ )
{
len = namesOptions[n].length();
if ( len > lenMax )
lenMax = len;
}
- for ( n = 0; n < count; n++ )
+ for ( n = 0; n < namesOptions.size(); n++ )
{
+ if ( n == count )
+ usage << _T('\n') << stdDesc;
+
len = namesOptions[n].length();
usage << namesOptions[n]
<< wxString(_T(' '), lenMax - len) << _T('\t')
return wxEmptyString;
}
+#ifdef __WXGTK26__
+// see the hack below in wxCmdLineParser::GetUsageString().
+// TODO: replace this hack with a g_option_group_get_entries()
+// call as soon as such function exists
+struct _GOptionGroup
+{
+ gchar *name;
+ gchar *description;
+ gchar *help_description;
+
+ GDestroyNotify destroy_notify;
+ gpointer user_data;
+
+ GTranslateFunc translate_func;
+ GDestroyNotify translate_notify;
+ gpointer translate_data;
+
+ GOptionEntry *entries;
+ gint n_entries;
+
+ GOptionParseFunc pre_parse_func;
+ GOptionParseFunc post_parse_func;
+ GOptionErrorFunc error_func;
+};
+
+wxString wxGetNameFromGtkOptionEntry(const GOptionEntry *opt)
+{
+ wxString ret;
+
+ if (opt->short_name)
+ ret << _T("-") << opt->short_name;
+ if (opt->long_name)
+ {
+ if (!ret.empty())
+ ret << _T(", ");
+ ret << _T("--") << opt->long_name;
+
+ if (opt->arg_description)
+ ret << _T("=") << opt->arg_description;
+ }
+
+ return _T(" ") + ret;
+}
+
+#endif // __WXGTK26__
+
+wxString
+wxGUIAppTraits::GetStandardCmdLineOptions(wxArrayString& names,
+ wxArrayString& desc) const
+{
+ wxString usage;
+
+#ifdef __WXGTK26__
+ // check whether GTK version is greater than 2.6 but also lower than 2.12
+ // because, as we use the undocumented _GOptionGroup struct, we don't want
+ // to run this code with future versions which might change it (2.11 is the
+ // latest one at the time of this writing)
+ if (!gtk_check_version(2,6,0) &&
+ gtk_check_version(2,12,0))
+ {
+ usage << _("The following standard GTK+ options are also supported:\n");
+
+ // passing true here means that the function can open the default
+ // display while parsing (not really used here anyhow)
+ GOptionGroup *gtkOpts = gtk_get_option_group(true);
+
+ // WARNING: here we access the internals of GOptionGroup:
+ GOptionEntry *entries = ((_GOptionGroup*)gtkOpts)->entries;
+ unsigned int n_entries = ((_GOptionGroup*)gtkOpts)->n_entries;
+ wxArrayString namesOptions, descOptions;
+
+ for ( size_t n = 0; n < n_entries; n++ )
+ {
+ if ( entries[n].flags & G_OPTION_FLAG_HIDDEN )
+ continue; // skip
+
+ names.push_back(wxGetNameFromGtkOptionEntry(&entries[n]));
+
+ const gchar * const entryDesc = entries[n].description;
+ desc.push_back(entryDesc ? wxString(entryDesc) : _T(""));
+ }
+
+ g_option_group_free (gtkOpts);
+ }
+#else
+ wxUnusedVar(names);
+ wxUnusedVar(desc);
+#endif // __WXGTK26__
+
+ return usage;
+}