[Libreoffice-commits] core.git: libreofficekit/qa

Pranav Kant pranavk at collabora.co.uk
Mon Dec 4 09:04:37 UTC 2017


 libreofficekit/qa/gtktiledviewer/gtv-helpers.cxx                    |   19 ---
 libreofficekit/qa/gtktiledviewer/gtv-helpers.hxx                    |   23 +++
 libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.cxx |    6 -
 libreofficekit/qa/gtktiledviewer/gtv-main-toolbar.cxx               |   60 +++++++++-
 libreofficekit/qa/gtktiledviewer/gtv-main-toolbar.hxx               |    8 -
 libreofficekit/qa/gtktiledviewer/gtv-signal-handlers.cxx            |   34 +++++
 libreofficekit/qa/gtktiledviewer/gtv-signal-handlers.hxx            |    2 
 libreofficekit/qa/gtktiledviewer/gtv.ui                             |   49 +++++++-
 8 files changed, 170 insertions(+), 31 deletions(-)

New commits:
commit 0d5ccc4eb114117b11f7ec53a2c75f9efcb4c651
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Tue Nov 28 16:43:54 2017 +0530

    gtv: Remember recently executed UNO commands
    
    Saves the recently executed UNO commands in a temp file and make it
    accessible to user in a combo box. Useful when debugging.
    
    Change-Id: Ic66961a388cc59dee3f65cb8d4de3c29a8a75eaa
    Reviewed-on: https://gerrit.libreoffice.org/45540
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: pranavk <pranavk at collabora.co.uk>

diff --git a/libreofficekit/qa/gtktiledviewer/gtv-helpers.cxx b/libreofficekit/qa/gtktiledviewer/gtv-helpers.cxx
index 3c4457b38215..d2fcb979e3d3 100644
--- a/libreofficekit/qa/gtktiledviewer/gtv-helpers.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtv-helpers.cxx
@@ -146,23 +146,4 @@ const std::string GtvHelpers::getDirPath(const std::string& filePath)
     return dirPath;
 }
 
-const std::vector<int> GtvHelpers::splitIntoIntegers(const std::string& aPayload, const std::string& aDelim, const int nItems)
-{
-    std::vector<int> aRet;
-
-    if (!aPayload.empty())
-    {
-        gchar** ppCoordinates = g_strsplit(aPayload.c_str(), aDelim.c_str(), nItems);
-        gchar** ppCoordinate  = ppCoordinates;
-        while (*ppCoordinate)
-        {
-            aRet.push_back(atoi(*ppCoordinate));
-            ++ppCoordinate;
-        }
-        g_strfreev(ppCoordinates);
-    }
-
-    return aRet;
-}
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/libreofficekit/qa/gtktiledviewer/gtv-helpers.hxx b/libreofficekit/qa/gtktiledviewer/gtv-helpers.hxx
index 9e984846f0ab..9474f4c0271a 100644
--- a/libreofficekit/qa/gtktiledviewer/gtv-helpers.hxx
+++ b/libreofficekit/qa/gtktiledviewer/gtv-helpers.hxx
@@ -39,7 +39,28 @@ namespace GtvHelpers
 
     const std::string getDirPath(const std::string& filePath);
 
-    const std::vector<int> splitIntoIntegers(const std::string& aPayload, const std::string& aDelim, const int nItems);
+    template<typename T>
+    const std::vector<T> split(const std::string& aPayload, const std::string& aDelim, const int nItems)
+    {
+        std::vector<T> aRet;
+
+        if (!aPayload.empty())
+        {
+            gchar** ppCoordinates = g_strsplit(aPayload.c_str(), aDelim.c_str(), nItems);
+            gchar** ppCoordinate  = ppCoordinates;
+            while (*ppCoordinate)
+            {
+                std::stringstream strstream(*ppCoordinate);
+                T item;
+                strstream >> item;
+                aRet.push_back(item);
+                ++ppCoordinate;
+            }
+            g_strfreev(ppCoordinates);
+        }
+
+        return aRet;
+    }
 }
 
 #endif
diff --git a/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.cxx b/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.cxx
index 79839aeccad2..2c97bd4d7393 100644
--- a/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.cxx
@@ -314,7 +314,7 @@ void LOKDocViewSigHandlers::dialog(LOKDocView* pDocView, gchar* pPayload, gpoint
     if (aAction == "created")
     {
         const std::string aSize = aRoot.get<std::string>("size");
-        std::vector<int> aPoints = GtvHelpers::splitIntoIntegers(aSize, ", ", 2);
+        std::vector<int> aPoints = GtvHelpers::split<int>(aSize, ", ", 2);
         GtkWidget* pDialog = gtv_lok_dialog_new(pDocView, nDialogId, aPoints[0], aPoints[1]);
         g_info("created  dialog, for dialogid: %d with size: %s", nDialogId, aSize.c_str());
 
@@ -345,7 +345,7 @@ void LOKDocViewSigHandlers::dialog(LOKDocView* pDocView, gchar* pPayload, gpoint
             else if (aAction == "size_changed")
             {
                 const std::string aSize = aRoot.get<std::string>("size");
-                std::vector<int> aSizePoints = GtvHelpers::splitIntoIntegers(aSize, ", ", 2);
+                std::vector<int> aSizePoints = GtvHelpers::split<int>(aSize, ", ", 2);
                 if (aSizePoints.size() != 2)
                 {
                     g_error("Malformed size_changed callback");
@@ -366,7 +366,7 @@ void LOKDocViewSigHandlers::dialog(LOKDocView* pDocView, gchar* pPayload, gpoint
                 try
                 {
                     const std::string aRectangle = aRoot.get<std::string>("rectangle");
-                    std::vector<int> aRectPoints = GtvHelpers::splitIntoIntegers(aRectangle, ", ", 4);
+                    std::vector<int> aRectPoints = GtvHelpers::split<int>(aRectangle, ", ", 4);
                     if (aRectPoints.size() == 4)
                         aGdkRectangle = {aRectPoints[0], aRectPoints[1], aRectPoints[2], aRectPoints[3]};
                 }
diff --git a/libreofficekit/qa/gtktiledviewer/gtv-main-toolbar.cxx b/libreofficekit/qa/gtktiledviewer/gtv-main-toolbar.cxx
index d973d32551d6..a415a8448e6c 100644
--- a/libreofficekit/qa/gtktiledviewer/gtv-main-toolbar.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtv-main-toolbar.cxx
@@ -35,6 +35,8 @@ struct GtvMainToolbarPrivateImpl
     GtkWidget* m_pDeleteComment;
     GtkWidget* m_pPartSelector;
     GtkWidget* m_pPartModeSelector;
+    GtkWidget* m_pRecentUnoSelector;
+    std::map<std::string, std::string> m_pRecentUnoCommands;
 
     /// Sensitivity (enabled or disabled) for each tool item, ignoring edit state
     std::map<GtkToolItem*, bool> m_aToolItemSensitivities;
@@ -49,7 +51,8 @@ struct GtvMainToolbarPrivateImpl
         m_pJustifypara(nullptr),
         m_pDeleteComment(nullptr),
         m_pPartSelector(nullptr),
-        m_pPartModeSelector(nullptr)
+        m_pPartModeSelector(nullptr),
+        m_pRecentUnoSelector(nullptr)
         { }
 };
 
@@ -96,6 +99,7 @@ gtv_main_toolbar_init(GtvMainToolbar* toolbar)
     priv->m_pDeleteComment = GTK_WIDGET(gtk_builder_get_object(builder.get(), "btn_removeannotation"));
     priv->m_pPartSelector = GTK_WIDGET(gtk_builder_get_object(builder.get(), "combo_partselector"));
     priv->m_pPartModeSelector = GTK_WIDGET(gtk_builder_get_object(builder.get(), "combo_partsmodeselector"));
+    priv->m_pRecentUnoSelector = GTK_WIDGET(gtk_builder_get_object(builder.get(), "combo_recentunoselector"));
 
     toolbar->m_pAddressbar = GTK_WIDGET(gtk_builder_get_object(builder.get(), "addressbar_entry"));
     toolbar->m_pFormulabar = GTK_WIDGET(gtk_builder_get_object(builder.get(), "formulabar_entry"));
@@ -106,6 +110,7 @@ gtv_main_toolbar_init(GtvMainToolbar* toolbar)
     gtk_builder_add_callback_symbol(builder.get(), "doPaste", G_CALLBACK(doPaste));
     gtk_builder_add_callback_symbol(builder.get(), "createView", G_CALLBACK(createView));
     gtk_builder_add_callback_symbol(builder.get(), "getRulerState", G_CALLBACK(getRulerState));
+    gtk_builder_add_callback_symbol(builder.get(), "recentUnoChanged", G_CALLBACK(recentUnoChanged));
     gtk_builder_add_callback_symbol(builder.get(), "unoCommandDebugger", G_CALLBACK(unoCommandDebugger));
     gtk_builder_add_callback_symbol(builder.get(), "toggleEditing", G_CALLBACK(toggleEditing));
     gtk_builder_add_callback_symbol(builder.get(), "changePartMode", G_CALLBACK(changePartMode));
@@ -178,6 +183,29 @@ static void populatePartSelector(GtvMainToolbar* toolbar)
     gtv_application_window_set_part_broadcast(window, true);
 }
 
+static void populateRecentUnoSelector(GtvMainToolbar* toolbar)
+{
+    GtvMainToolbarPrivate& priv = getPrivate(toolbar);
+    GtkComboBoxText* pSelector = GTK_COMBO_BOX_TEXT(priv->m_pRecentUnoSelector);
+
+    unsigned counter = 0;
+    std::ifstream is("/tmp/gtv-recentunos.txt");
+    while (is.good() && counter < 10)
+    {
+        std::string unoCommandStr;
+        std::getline(is, unoCommandStr);
+        std::vector<std::string> aUnoCmd = GtvHelpers::split<std::string>(unoCommandStr, " | ", 2);
+        if (aUnoCmd.size() != 2)
+            continue;
+        auto it = priv->m_pRecentUnoCommands.emplace(aUnoCmd[0], aUnoCmd[1]);
+        if (it.second)
+        {
+            gtk_combo_box_text_append_text(pSelector, aUnoCmd[0].c_str());
+            ++counter;
+        }
+    }
+}
+
 void
 gtv_main_toolbar_doc_loaded(GtvMainToolbar* toolbar, LibreOfficeKitDocumentType eDocType, bool bEditMode)
 {
@@ -204,6 +232,36 @@ gtv_main_toolbar_doc_loaded(GtvMainToolbar* toolbar, LibreOfficeKitDocumentType
 
     // populate combo boxes
     populatePartSelector(toolbar);
+
+    // populate recent uno selector
+    populateRecentUnoSelector(toolbar);
+}
+
+void
+gtv_main_toolbar_add_recent_uno(GtvMainToolbar* toolbar, const std::string& rUnoCmdStr)
+{
+    GtvMainToolbarPrivate& priv = getPrivate(toolbar);
+    GtkComboBoxText* pSelector = GTK_COMBO_BOX_TEXT(priv->m_pRecentUnoSelector);
+
+    const std::vector<std::string> aUnoCmd = GtvHelpers::split<std::string>(rUnoCmdStr, " | ", 2);
+    priv->m_pRecentUnoCommands[aUnoCmd[0]] = aUnoCmd[1];
+    // keep placeholder string at the top
+    gtk_combo_box_text_insert_text(pSelector, 1, aUnoCmd[0].c_str());
+    // TODO: Remove other text entries with same key
+}
+
+const std::string
+gtv_main_toolbar_get_recent_uno_args(GtvMainToolbar* toolbar, const std::string& rUnoCmd)
+{
+    GtvMainToolbarPrivate& priv = getPrivate(toolbar);
+    auto it = std::find_if(priv->m_pRecentUnoCommands.begin(), priv->m_pRecentUnoCommands.end(),
+                           [&rUnoCmd](const std::pair<std::string, std::string>& pair) {
+                               return rUnoCmd == pair.first;
+                           });
+    std::string ret;
+    if (it != priv->m_pRecentUnoCommands.end())
+        ret = it->second;
+    return ret;
 }
 
 GtkContainer*
diff --git a/libreofficekit/qa/gtktiledviewer/gtv-main-toolbar.hxx b/libreofficekit/qa/gtktiledviewer/gtv-main-toolbar.hxx
index 197f8d15d855..2e43ed4c7dc7 100644
--- a/libreofficekit/qa/gtktiledviewer/gtv-main-toolbar.hxx
+++ b/libreofficekit/qa/gtktiledviewer/gtv-main-toolbar.hxx
@@ -12,9 +12,9 @@
 
 #include <gtk/gtk.h>
 
-#include <LibreOfficeKit/LibreOfficeKitEnums.h>
+#include <string>
 
-G_BEGIN_DECLS
+#include <LibreOfficeKit/LibreOfficeKitEnums.h>
 
 #define GTV_TYPE_MAIN_TOOLBAR            (gtv_main_toolbar_get_type())
 #define GTV_MAIN_TOOLBAR(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), GTV_TYPE_MAIN_TOOLBAR, GtvMainToolbar))
@@ -51,7 +51,9 @@ void gtv_main_toolbar_set_edit(GtvMainToolbar* toolbar, gboolean bEdit);
 
 void gtv_main_toolbar_doc_loaded(GtvMainToolbar* toolbar, LibreOfficeKitDocumentType eDocType, bool bEditMode);
 
-G_END_DECLS
+void gtv_main_toolbar_add_recent_uno(GtvMainToolbar* toolbar, const std::string& rUnoCmdStr);
+
+const std::string gtv_main_toolbar_get_recent_uno_args(GtvMainToolbar* toolbar, const std::string& rUnoCmd);
 
 #endif /* GTV_MAIN_TOOLBAR_H */
 
diff --git a/libreofficekit/qa/gtktiledviewer/gtv-signal-handlers.cxx b/libreofficekit/qa/gtktiledviewer/gtv-signal-handlers.cxx
index 9c075f571170..32ba8115a4aa 100644
--- a/libreofficekit/qa/gtktiledviewer/gtv-signal-handlers.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtv-signal-handlers.cxx
@@ -195,6 +195,37 @@ static void iterateUnoParams(GtkWidget* pWidget, gpointer userdata)
     pTree->put(boost::property_tree::ptree::path_type(g_strconcat(unoParam[1], "/", "value", nullptr), '/'), unoParam[2]);
 }
 
+void recentUnoChanged( GtkWidget* pSelector, gpointer /* pItem */ )
+{
+    GtvApplicationWindow* pWindow = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(pSelector));
+    gchar* pUnoCmd = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(pSelector));
+
+    GtvMainToolbar* pToolbar = gtv_application_window_get_main_toolbar(pWindow);
+    const std::string aUnoArgs = gtv_main_toolbar_get_recent_uno_args(pToolbar, pUnoCmd);
+    // this will also discard our default placeholder string, "Recent UNO"
+    if (aUnoArgs.empty())
+        return;
+
+    lok_doc_view_post_command(LOK_DOC_VIEW(pWindow->lokdocview), pUnoCmd, (aUnoArgs.empty() ? nullptr : aUnoArgs.c_str()), false);
+    g_free(pUnoCmd);
+}
+
+static void addToRecentUnoCommands(GtvApplicationWindow* pWindow, const std::string& rUnoCmd, std::string rArgs)
+{
+    GtvMainToolbar* pToolbar = gtv_application_window_get_main_toolbar(pWindow);
+    rArgs.erase(std::find_if(rArgs.begin(), rArgs.end(), [](char ch) { return ch == '\n'; }));
+    const std::string rUnoCmdStr = rUnoCmd + " | " + rArgs;
+
+
+    // add to file
+    std::ofstream outfile("/tmp/gtv-recentunos.txt", std::ios_base::app | std::ios_base::out);
+    if (outfile.good())
+        outfile << rUnoCmdStr << '\n';
+
+    // add to combo box
+    gtv_main_toolbar_add_recent_uno(pToolbar, rUnoCmdStr);
+}
+
 void unoCommandDebugger(GtkWidget* pButton, gpointer /* pItem */)
 {
     GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(pButton));
@@ -235,12 +266,13 @@ void unoCommandDebugger(GtkWidget* pButton, gpointer /* pItem */)
         gtk_container_foreach(GTK_CONTAINER(pUnoParamAreaBox), iterateUnoParams, &aTree);
 
         std::stringstream aStream;
-        boost::property_tree::write_json(aStream, aTree);
+        boost::property_tree::write_json(aStream, aTree, false);
         std::string aArguments = aStream.str();
 
         g_info("Generated UNO command: %s %s", sUnoCmd, aArguments.c_str());
 
         lok_doc_view_post_command(LOK_DOC_VIEW(window->lokdocview), sUnoCmd, (aArguments.empty() ? nullptr : aArguments.c_str()), false);
+        addToRecentUnoCommands(window, sUnoCmd, aArguments);
     }
         break;
     }
diff --git a/libreofficekit/qa/gtktiledviewer/gtv-signal-handlers.hxx b/libreofficekit/qa/gtktiledviewer/gtv-signal-handlers.hxx
index 80c5c6061f9a..bddf5c29e625 100644
--- a/libreofficekit/qa/gtktiledviewer/gtv-signal-handlers.hxx
+++ b/libreofficekit/qa/gtktiledviewer/gtv-signal-handlers.hxx
@@ -22,6 +22,8 @@ void createView(GtkWidget* pButton, gpointer /*pItem*/);
 
 void getRulerState(GtkWidget* pButton, gpointer /*pItem*/);
 
+void recentUnoChanged( GtkWidget* pSelector, gpointer /* pItem */ );
+
 void unoCommandDebugger(GtkWidget* pButton, gpointer /* pItem */);
 
 void toggleEditing(GtkWidget* pButton, gpointer /*pItem*/);
diff --git a/libreofficekit/qa/gtktiledviewer/gtv.ui b/libreofficekit/qa/gtktiledviewer/gtv.ui
index 966c97e46967..732d79638895 100644
--- a/libreofficekit/qa/gtktiledviewer/gtv.ui
+++ b/libreofficekit/qa/gtktiledviewer/gtv.ui
@@ -459,6 +459,38 @@
       </packing>
     </child>
     <child>
+      <object class="GtkSeparatorToolItem" id="separator5">
+        <property name="use_action_appearance">False</property>
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="homogeneous">False</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkToolItem" id="recentunoselectortoolitem">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <child>
+          <object class="GtkComboBoxText" id="combo_recentunoselector">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="active">0</property>
+            <items>
+              <item translatable="no">Select UNO</item>
+            </items>
+            <signal name="changed" handler="recentUnoChanged" swapped="no"/>
+          </object>
+        </child>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="homogeneous">True</property>
+      </packing>
+    </child>
+    <child>
       <object class="GtkToolButton" id="btn_unodebugger">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
@@ -473,6 +505,17 @@
       </packing>
     </child>
     <child>
+      <object class="GtkSeparatorToolItem" id="separator6">
+        <property name="use_action_appearance">False</property>
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="homogeneous">False</property>
+      </packing>
+    </child>
+    <child>
       <object class="GtkToolButton" id="btn_createview">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
@@ -562,7 +605,7 @@
       </packing>
     </child>
     <child>
-      <object class="GtkSeparatorToolItem" id="separator5">
+      <object class="GtkSeparatorToolItem" id="separator7">
         <property name="use_action_appearance">False</property>
         <property name="visible">True</property>
         <property name="can_focus">False</property>
@@ -601,7 +644,7 @@
       </packing>
     </child>
     <child>
-      <object class="GtkSeparatorToolItem" id="separator6">
+      <object class="GtkSeparatorToolItem" id="separator8">
         <property name="use_action_appearance">False</property>
         <property name="visible">True</property>
         <property name="can_focus">False</property>
@@ -668,7 +711,7 @@
       </packing>
     </child>
     <child>
-      <object class="GtkSeparatorToolItem" id="separator7">
+      <object class="GtkSeparatorToolItem" id="separator9">
         <property name="use_action_appearance">False</property>
         <property name="visible">True</property>
         <property name="can_focus">False</property>


More information about the Libreoffice-commits mailing list