mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-21 23:09:40 +00:00
localize date/time
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10129 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
200435f2d9
commit
dd1d850e93
@ -1,3 +1,8 @@
|
||||
2005-07-05 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
|
||||
|
||||
* text3.C (doDispatch): rewrite LFUN_DATE_INSERT using the brandnew
|
||||
formatted_time methods in support/lyxtime.
|
||||
|
||||
2005-07-04 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
|
||||
|
||||
* toc.[Ch]: new method getGuiName, which is used by the frontends
|
||||
|
@ -1,3 +1,8 @@
|
||||
2005-07-05 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
|
||||
|
||||
* ControlChanges.C (getChangeDate): use localized date (from
|
||||
support/lyxtime).
|
||||
|
||||
2005-07-04 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
|
||||
|
||||
* ControlToc.[Ch]: new method getGuiName, which is used by the frontends
|
||||
|
@ -19,14 +19,12 @@
|
||||
#include "changes.h"
|
||||
#include "funcrequest.h"
|
||||
#include "lyxfind.h"
|
||||
#include "support/lstrings.h"
|
||||
#include "support/lyxtime.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace lyx {
|
||||
|
||||
using support::rtrim;
|
||||
|
||||
namespace frontend {
|
||||
|
||||
|
||||
@ -47,9 +45,7 @@ string const ControlChanges::getChangeDate()
|
||||
if (c.type == Change::UNCHANGED || !c.changetime)
|
||||
return string();
|
||||
|
||||
// ctime adds newline; trim it off!
|
||||
string const date = rtrim(ctime(&c.changetime), "\n");
|
||||
return date;
|
||||
return formatted_time(c.changetime);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,3 +1,8 @@
|
||||
2005-07-05 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
|
||||
|
||||
* lyxtime.[Ch]: two new functions formatted_time, which return
|
||||
the strftime-formatted localized date/time.
|
||||
|
||||
2005-06-24 Georg Baum <Georg.Baum@post.rwth-aachen.de>
|
||||
|
||||
* FileName.C (mangledFilename): replace spaces with _
|
||||
|
@ -11,6 +11,9 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "support/lyxtime.h"
|
||||
#include "lyxrc.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace lyx {
|
||||
|
||||
@ -19,4 +22,19 @@ time_type current_time()
|
||||
return time(0);
|
||||
}
|
||||
|
||||
|
||||
string const formatted_time(time_type t, string const & fmt)
|
||||
{
|
||||
struct tm * loc_tm = localtime(&t);
|
||||
char date[50];
|
||||
strftime(date, sizeof(date), fmt.c_str(), loc_tm);
|
||||
return string(date);
|
||||
}
|
||||
|
||||
|
||||
string const formatted_time(time_type t)
|
||||
{
|
||||
return formatted_time(t, lyxrc.date_insert_format);
|
||||
}
|
||||
|
||||
} // namespace lyx
|
||||
|
@ -5,6 +5,7 @@
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author John Levon
|
||||
* \author Jürgen Spitzmüller
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
@ -13,6 +14,8 @@
|
||||
#define LYXTIME_H
|
||||
|
||||
#include <time.h>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace lyx {
|
||||
|
||||
@ -20,6 +23,18 @@ typedef time_t time_type;
|
||||
|
||||
time_type current_time();
|
||||
|
||||
/** Returns a locale-dependent formatting of the date
|
||||
* and time encoded in \c time. The \p fmt string
|
||||
* holds the formatting arguments of \c strftime.
|
||||
*/
|
||||
std::string const formatted_time(time_type t, std::string const & fmt);
|
||||
|
||||
/** Returns a locale-dependent formatting of the date
|
||||
* and time encoded in \c time. For the formatting,
|
||||
* \c lyxrc.date_insert_format is being used.
|
||||
*/
|
||||
std::string const formatted_time(time_type t);
|
||||
|
||||
}; // namespace lyx
|
||||
|
||||
#endif // LYXTIME_H
|
||||
|
26
src/text3.C
26
src/text3.C
@ -57,6 +57,7 @@
|
||||
#include "support/lstrings.h"
|
||||
#include "support/lyxlib.h"
|
||||
#include "support/convert.h"
|
||||
#include "support/lyxtime.h"
|
||||
|
||||
#include "mathed/math_hullinset.h"
|
||||
#include "mathed/math_macrotemplate.h"
|
||||
@ -954,27 +955,14 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
|
||||
break;
|
||||
}
|
||||
|
||||
case LFUN_DATE_INSERT: {
|
||||
lyx::cap::replaceSelection(cur);
|
||||
time_t now_time_t = time(NULL);
|
||||
struct tm * now_tm = localtime(&now_time_t);
|
||||
setlocale(LC_TIME, "");
|
||||
string arg;
|
||||
if (!cmd.argument.empty())
|
||||
arg = cmd.argument;
|
||||
case LFUN_DATE_INSERT:
|
||||
if (cmd.argument.empty())
|
||||
bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT,
|
||||
lyx::formatted_time(lyx::current_time())));
|
||||
else
|
||||
arg = lyxrc.date_insert_format;
|
||||
char datetmp[32];
|
||||
int const datetmp_len =
|
||||
::strftime(datetmp, 32, arg.c_str(), now_tm);
|
||||
|
||||
for (int i = 0; i < datetmp_len; i++)
|
||||
insertChar(cur, datetmp[i]);
|
||||
|
||||
cur.resetAnchor();
|
||||
moveCursor(cur, false);
|
||||
bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT,
|
||||
lyx::formatted_time(lyx::current_time(), cmd.argument)));
|
||||
break;
|
||||
}
|
||||
|
||||
case LFUN_MOUSE_TRIPLE:
|
||||
if (cmd.button() == mouse_button::button1) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user