summaryrefslogtreecommitdiff
path: root/dbaccess
diff options
context:
space:
mode:
authorHeiko Tietze <tietze.heiko@gmail.com>2024-09-03 15:14:32 +0200
committerHeiko Tietze <heiko.tietze@documentfoundation.org>2024-09-05 07:38:22 +0200
commit0266763e05d1ca9413321533dcea73c4643db476 (patch)
treee1824cf3e15f7866c421baef5a6c7b4007c72e84 /dbaccess
parent3631c6ffcb2f27090cfc1b1c9dd492451d3d485c (diff)
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>
Diffstat (limited to 'dbaccess')
-rw-r--r--dbaccess/inc/core_resource.hxx2
-rw-r--r--dbaccess/inc/strings.hrc3
-rw-r--r--dbaccess/source/core/resource/core_resource.cxx5
-rw-r--r--dbaccess/source/ui/dlg/directsql.cxx32
-rw-r--r--dbaccess/source/ui/inc/directsql.hxx2
-rw-r--r--dbaccess/uiconfig/ui/directsqldialog.ui3
6 files changed, 42 insertions, 5 deletions
diff --git a/dbaccess/inc/core_resource.hxx b/dbaccess/inc/core_resource.hxx
index e806c398d297..713e494ae0f9 100644
--- a/dbaccess/inc/core_resource.hxx
+++ b/dbaccess/inc/core_resource.hxx
@@ -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
diff --git a/dbaccess/inc/strings.hrc b/dbaccess/inc/strings.hrc
index 0691ff9f7a8b..5eeb38a0a79c 100644
--- a/dbaccess/inc/strings.hrc
+++ b/dbaccess/inc/strings.hrc
@@ -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" )
diff --git a/dbaccess/source/core/resource/core_resource.cxx b/dbaccess/source/core/resource/core_resource.cxx
index 8a0bba5b67de..2bc3f7a28a04 100644
--- a/dbaccess/source/core/resource/core_resource.cxx
+++ b/dbaccess/source/core/resource/core_resource.cxx
@@ -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)
{
diff --git a/dbaccess/source/ui/dlg/directsql.cxx b/dbaccess/source/ui/dlg/directsql.cxx
index ea6ad7257dda..0e53c7c1d377 100644
--- a/dbaccess/source/ui/dlg/directsql.cxx
+++ b/dbaccess/source/ui/dlg/directsql.cxx
@@ -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)
diff --git a/dbaccess/source/ui/inc/directsql.hxx b/dbaccess/source/ui/inc/directsql.hxx
index bfe8195fc5ff..4d141d8a2f02 100644
--- a/dbaccess/source/ui/inc/directsql.hxx
+++ b/dbaccess/source/ui/inc/directsql.hxx
@@ -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();
diff --git a/dbaccess/uiconfig/ui/directsqldialog.ui b/dbaccess/uiconfig/ui/directsqldialog.ui
index c1c06f40a383..b3f62053d367 100644
--- a/dbaccess/uiconfig/ui/directsqldialog.ui
+++ b/dbaccess/uiconfig/ui/directsqldialog.ui
@@ -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">