added wxAppTraits::GetStandardCmdLineOptions() allowing to add the description of the standard toolkit options to the usage message and implement it for wxGTK2 (patch 1703077)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45589 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -109,6 +109,7 @@ All (GUI):
|
|||||||
- Added wxWindow::NavigateIn() in addition to existing Navigate()
|
- Added wxWindow::NavigateIn() in addition to existing Navigate()
|
||||||
- Add support for <data> tags to wxrc
|
- Add support for <data> tags to wxrc
|
||||||
- Support wxAPPLY and wxCLOSE in CreateStdDialogButtonSizer() (Marcin Wojdyr)
|
- Support wxAPPLY and wxCLOSE in CreateStdDialogButtonSizer() (Marcin Wojdyr)
|
||||||
|
- Show standard options in wxCmdLineParser usage message (Francesco Montorsi)
|
||||||
|
|
||||||
wxGTK:
|
wxGTK:
|
||||||
|
|
||||||
|
@@ -138,7 +138,21 @@ public:
|
|||||||
|
|
||||||
// return the name of the Desktop Environment such as
|
// return the name of the Desktop Environment such as
|
||||||
// "KDE" or "GNOME". May return an empty string.
|
// "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:
|
protected:
|
||||||
#if wxUSE_STACKWALKER && defined( __WXDEBUG__ )
|
#if wxUSE_STACKWALKER && defined( __WXDEBUG__ )
|
||||||
@@ -214,6 +228,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual bool IsUsingUniversalWidgets() const { return false; }
|
virtual bool IsUsingUniversalWidgets() const { return false; }
|
||||||
|
virtual wxString GetDesktopEnvironment() const { return wxEmptyString; }
|
||||||
};
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -253,6 +268,8 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual wxString GetDesktopEnvironment() const { return wxEmptyString; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // wxUSE_GUI
|
#endif // wxUSE_GUI
|
||||||
|
@@ -49,6 +49,8 @@ public:
|
|||||||
#ifdef __WXGTK__
|
#ifdef __WXGTK__
|
||||||
virtual void SetLocale();
|
virtual void SetLocale();
|
||||||
virtual wxString GetDesktopEnvironment() const;
|
virtual wxString GetDesktopEnvironment() const;
|
||||||
|
virtual wxString GetStandardCmdLineOptions(wxArrayString& names,
|
||||||
|
wxArrayString& desc) const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__WXDEBUG__) && defined(__WXGTK20__)
|
#if defined(__WXDEBUG__) && defined(__WXGTK20__)
|
||||||
|
@@ -41,6 +41,7 @@
|
|||||||
#include "wx/datetime.h"
|
#include "wx/datetime.h"
|
||||||
#include "wx/msgout.h"
|
#include "wx/msgout.h"
|
||||||
#include "wx/filename.h"
|
#include "wx/filename.h"
|
||||||
|
#include "wx/apptrait.h"
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// private functions
|
// private functions
|
||||||
@@ -179,7 +180,7 @@ struct wxCmdLineParserData
|
|||||||
|
|
||||||
// cmd line data
|
// cmd line data
|
||||||
wxArrayString m_arguments; // == argv, argc == m_arguments.GetCount()
|
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
|
wxArrayParams m_paramDesc; // description of all possible params
|
||||||
wxArrayString m_parameters; // all params found
|
wxArrayString m_parameters; // all params found
|
||||||
|
|
||||||
@@ -1068,18 +1069,29 @@ wxString wxCmdLineParser::GetUsageString()
|
|||||||
|
|
||||||
usage << _T('\n');
|
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
|
// now construct the detailed help message
|
||||||
size_t len, lenMax = 0;
|
size_t len, lenMax = 0;
|
||||||
count = namesOptions.size();
|
for ( n = 0; n < namesOptions.size(); n++ )
|
||||||
for ( n = 0; n < count; n++ )
|
|
||||||
{
|
{
|
||||||
len = namesOptions[n].length();
|
len = namesOptions[n].length();
|
||||||
if ( len > lenMax )
|
if ( len > lenMax )
|
||||||
lenMax = len;
|
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();
|
len = namesOptions[n].length();
|
||||||
usage << namesOptions[n]
|
usage << namesOptions[n]
|
||||||
<< wxString(_T(' '), lenMax - len) << _T('\t')
|
<< wxString(_T(' '), lenMax - len) << _T('\t')
|
||||||
|
@@ -482,5 +482,96 @@ wxString wxGUIAppTraits::GetDesktopEnvironment() const
|
|||||||
return wxEmptyString;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user