Resolves tdf#140298 - Improve UX for SQL dialog

* dialog made resizable
* user input remembered across session
* number of results shown (inkluding plural form)

Change-Id: I5b08064ed68a02a2c20fa658dbc6ed5cde656417
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172803
Tested-by: Jenkins
Reviewed-by: Heiko Tietze <heiko.tietze@documentfoundation.org>
This commit is contained in:
Heiko Tietze 2024-09-03 15:14:32 +02:00 committed by Heiko Tietze
parent 3631c6ffcb
commit 0266763e05
6 changed files with 42 additions and 5 deletions

View file

@ -24,6 +24,7 @@
#include <unotools/resmgr.hxx>
#define DBA_RES( id ) ::dbaccess::ResourceManager::loadString( id )
#define DBA_RES_PLURAL( id, number ) ::dbaccess::ResourceManager::loadString( id, number )
#define DBA_RES_PARAM( id, ascii, replace ) ::dbaccess::ResourceManager::loadString( id, ascii, replace )
namespace dbaccess
@ -41,6 +42,7 @@ namespace dbaccess
/** loads the string with the specified resource id
*/
static OUString loadString(TranslateId pResId);
static OUString loadString(TranslateNId aContextSingularPlural, int nCardinality);
/** loads a string from the resource file, substituting two placeholders with given strings

View file

@ -22,6 +22,7 @@
#include <unotools/resmgr.hxx>
#define NC_(Context, String) TranslateId(Context, u8##String)
#define NNC_(Context, StringSingular, StringPlural) TranslateNId(Context, reinterpret_cast<char const *>(u8##StringSingular), reinterpret_cast<char const *>(u8##StringPlural))
#define RID_STR_CONNECTION_INVALID NC_("RID_STR_CONNECTION_INVALID", "No connection could be established.")
#define RID_STR_TABLE_IS_FILTERED NC_("RID_STR_TABLE_IS_FILTERED", "The table $name$ already exists. It is not visible because it has been filtered out.")
@ -398,6 +399,8 @@
#define STR_SPREADSHEETPATH NC_("STR_SPREADSHEETPATH", "~Location and file name" )
#define STR_COMMAND_EXECUTED_SUCCESSFULLY NC_("STR_COMMAND_EXECUTED_SUCCESSFULLY", "Command successfully executed." )
#define STR_COMMAND_NROWS NNC_("STR_COMMAND_NROWS", "%1 row in set", "%1 rows in set" )
#define STR_DIRECTSQL_CONNECTIONLOST NC_("STR_DIRECTSQL_CONNECTIONLOST", "The connection to the database has been lost. This dialog will be closed.")
#define STR_TAB_INDEX_SORTORDER NC_("STR_TAB_INDEX_SORTORDER", "Sort order" )

View file

@ -28,6 +28,11 @@ namespace dbaccess
return Translate::get(pResId, Translate::Create("dba"));
}
OUString ResourceManager::loadString(TranslateNId aContextSingularPlural, int nCardinality)
{
return Translate::nget(aContextSingularPlural, nCardinality, Translate::Create("dba"));
}
OUString ResourceManager::loadString(TranslateId pResId, std::u16string_view _rPlaceholderAscii1, std::u16string_view _rReplace1,
std::u16string_view _rPlaceholderAscii2, std::u16string_view _rReplace2)
{

View file

@ -25,6 +25,7 @@
#include <comphelper/types.hxx>
#include <osl/mutex.hxx>
#include <rtl/ustrbuf.hxx>
#include <rtl/ustring.hxx>
#include <comphelper/diagnose_ex.hxx>
#include <vcl/svapp.hxx>
#include <vcl/weld.hxx>
@ -36,8 +37,21 @@
#include <com/sun/star/sdbc/XResultSetMetaData.hpp>
#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
// tdf#140298 - remember user settings within the currect session
// memp is filled in dtor and restored after initialization
namespace
{
struct memParam {
std::vector<OUString> SQLHistory;
bool DirectSQL;
bool ShowOutput;
};
memParam memp;
}
namespace dbaui
{
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::lang;
@ -73,6 +87,13 @@ namespace dbaui
m_xClose->connect_clicked(LINK(this, DirectSQLDialog, OnCloseClick));
m_xSQLHistory->connect_changed(LINK(this, DirectSQLDialog, OnListEntrySelected));
for (size_t i = 0; i < memp.SQLHistory.size(); i++)
{
implAddToStatementHistory(memp.SQLHistory[i], true);
m_xDirectSQL->set_active(memp.DirectSQL);
m_xShowOutput->set_active(memp.ShowOutput);
}
// add a dispose listener to the connection
Reference< XComponent > xConnComp(m_xConnection, UNO_QUERY);
OSL_ENSURE(xConnComp.is(), "DirectSQLDialog::DirectSQLDialog: invalid connection!");
@ -85,6 +106,9 @@ namespace dbaui
DirectSQLDialog::~DirectSQLDialog()
{
memp.DirectSQL = m_xDirectSQL->get_active();
memp.ShowOutput = m_xShowOutput->get_active();
::osl::MutexGuard aGuard(m_aMutex);
if (m_pClosingEvent)
Application::RemoveUserEvent(m_pClosingEvent);
@ -147,7 +171,7 @@ namespace dbaui
}
}
void DirectSQLDialog::implAddToStatementHistory(const OUString& _rStatement)
void DirectSQLDialog::implAddToStatementHistory(const OUString& _rStatement, const bool bFromMemory)
{
#ifdef DBG_UTIL
{
@ -159,6 +183,8 @@ namespace dbaui
// add the statement to the history
m_aStatementHistory.push_back(_rStatement);
if (!bFromMemory)
memp.SQLHistory.push_back(_rStatement);
// normalize the statement, and remember the normalized form, too
OUString sNormalized = _rStatement.replaceAll("\n", " ");
@ -311,7 +337,7 @@ namespace dbaui
const Reference<XResultSetMetaData> xResultSetMetaData = Reference<XResultSetMetaDataSupplier>(xRS,UNO_QUERY_THROW)->getMetaData();
const sal_Int32 nColumnsCount = xResultSetMetaData->getColumnCount();
sal_Int32 nRowCount = 0;
// get a handle for the rows
css::uno::Reference< css::sdbc::XRow > xRow( xRS, css::uno::UNO_QUERY );
// work through each of the rows
@ -348,6 +374,7 @@ namespace dbaui
out.append(xRow->getString(i) + ",");
}
}
nRowCount++;
}
// trap for when we fall off the end of the row
catch (const SQLException&)
@ -356,6 +383,7 @@ namespace dbaui
// report the output
addOutputText(out);
}
addOutputText(DBA_RES_PLURAL(STR_COMMAND_NROWS, nRowCount).replaceAll("%1", OUString::number(nRowCount)));
}
void DirectSQLDialog::addStatusText(std::u16string_view _rMessage)

View file

@ -86,7 +86,7 @@ namespace dbaui
DECL_LINK( OnStatementModified, LinkParamNone*, void );
/// adds a statement to the statement history
void implAddToStatementHistory(const OUString& _rStatement);
void implAddToStatementHistory(const OUString& _rStatement, const bool bFromMemory = false);
/// ensures that our history has at most m_nHistoryLimit entries
void implEnsureHistoryLimit();

View file

@ -1,12 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<!-- Generated with glade 3.40.0 -->
<interface domain="dba">
<requires lib="gtk+" version="3.20"/>
<object class="GtkDialog" id="DirectSQLDialog">
<property name="can-focus">False</property>
<property name="border-width">6</property>
<property name="title" translatable="yes" context="directsqldialog|DirectSQLDialog">Execute SQL Statement</property>
<property name="resizable">False</property>
<property name="modal">True</property>
<property name="type-hint">dialog</property>
<child internal-child="vbox">