Author Topic: new idea: context menu to open the image in doxygen style comment  (Read 1561 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5930
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator


https://www.doxygen.nl/manual/commands.html#cmdimage

We can have such comment:

Code
  /*! Here is a snapshot of my new application:
   *  \image html application.jpg
   *  \image latex application.eps "My application" width=10cm
   */

I think when a user right click on the "application.jpg", we can generate a url to let the browser open this jpg file in the browser?

Because we already have a context menu named "Open link in browser" which is used to open a link, such as: "http://xxx.yyy.zzz" in the comment.

Any ideas?

Sometimes, we need images in the doxygen, but we need to find a quick way to view the image.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline kipade

  • Multiple posting newcomer
  • *
  • Posts: 50
Re: new idea: context menu to open the image in doxygen style comment
« Reply #1 on: March 19, 2024, 04:37:52 am »
why not display it within a popup contex window, like message tips? And provide a entry to let the user have a change to show a big view via web browser.
And, how many people will use this feature?
« Last Edit: March 19, 2024, 04:40:12 am by kipade »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5930
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: new idea: context menu to open the image in doxygen style comment
« Reply #2 on: March 19, 2024, 04:46:58 am »
why not display it within a popup contex window, like message tips? And provide a entry to let the user have a change to show a big view via web browser.

Yes, context menu -> popup window could better.

Quote
And, how many people will use this feature?

I don't know, but I think this is a nice feature, especially if you have diagram or flowchart in images.


If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5930
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: new idea: context menu to open the image in doxygen style comment
« Reply #3 on: March 19, 2024, 01:45:50 pm »
This is the patch file for this simple feature.

When you right click on a image filename in the comment, such as "a.jpg".

Suppose you are editing a file named: "c:/abc/def.cpp", and you will open the file in the default image file browser.

Code
diff --git a/src/sdk/cbeditor.cpp b/src/sdk/cbeditor.cpp
index 71622d79..2a76d8a9 100644
--- a/src/sdk/cbeditor.cpp
+++ b/src/sdk/cbeditor.cpp
@@ -393,7 +393,7 @@ struct cbEditorInternalData
         }
     }
 
-    wxString GetUrl()
+    wxString GetUrl(wxString filename = wxEmptyString)
     {
         cbStyledTextCtrl* control = m_pOwner->GetControl();
         if (!control)
@@ -409,6 +409,9 @@ struct cbEditorInternalData
                               ")"
                               "(\\/?)([\\w\\-\\.\\?\\,\\'\\/\\\\\\+&%\\$#]*)?"
                               "([\\d\\w\\.\\/\\%\\+\\-\\=\\&\\?\\:\\\\\\"\\'\\,\\|\\~\\;]*)"));
+
+        wxRegEx reFile(R"raw([A-Za-z0-9]+\.(jpg|jpeg|png|gif|bmp|svg))raw");
+
         wxString url = control->GetSelectedText();
         // Is the URL selected?
         if (reUrl.Matches(url))
@@ -456,6 +459,31 @@ struct cbEditorInternalData
             else
                 url = wxEmptyString; // nope, too far from cursor, return invalid (empty)
         }
+        else if (reFile.Matches(url))
+        {
+            wxString match = reFile.GetMatch(url);
+            if ((url.Find(match) + startPos < control->GetCurrentPos()) &&
+                (url.Find(match) + startPos + (int)match.Length() > control->GetCurrentPos()))
+            {
+                // Translate short file path to absolute file path using the current source file path
+                // match is some string like "xyz.jpg" or "xyz.png"
+                if (match.IsEmpty())
+                {
+                    return wxT("file:///") + match;
+                }
+                else
+                {
+                    // suppose we are editing a file named : "c:/abc/def.cpp"
+                    // the file contains some piece of the comments which is "xyz.jpg"
+                    // we create an absolute file path of the image file named "c:/abc/xyz.jpg"
+                    wxFileName baseFilename(filename);
+                    wxFileName newFilename(baseFilename.GetPath(), match);
+                    return wxT("file:///") + newFilename.GetFullPath();
+                }
+            }
+            else
+                url = wxEmptyString; // nope, too far from cursor, return invalid (empty)
+        }
         else
             url = wxEmptyString; // nope, return invalid (empty)
 
@@ -3289,7 +3317,7 @@ void cbEditor::OnContextMenuEntry(wxCommandEvent& event)
     else if (id == idFoldingToggleCurrent)
         ToggleFoldBlockFromLine();
     else if (id == idOpenUrl)
-        wxLaunchDefaultBrowser(m_pData->GetUrl());
+        wxLaunchDefaultBrowser(m_pData->GetUrl(GetFilename()));
     else if (id == idSplitHorz)
         Split(stHorizontal);
     else if (id == idSplitVert)

« Last Edit: March 20, 2024, 04:56:27 am by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5930
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: new idea: context menu to open the image in doxygen style comment
« Reply #4 on: March 20, 2024, 03:04:06 am »
For another issue:

I see a lot of "\" (the escape) in the regular expression pattern string.

For example, in cbeditor.cpp, there are some patter string like below

Code
        wxRegEx reUrl(wxT("***:("
                                "((ht|f)tp(s?)\\:\\/\\/)"
                                "|(www\\.)"
                              ")"
                              "("
                                "([\\w\\-]+(\\.[\\w\\-]+)+)"
                                "|localhost"
                              ")"
                              "(\\/?)([\\w\\-\\.\\?\\,\\'\\/\\\\\\+&amp;%\\$#]*)?"
                              "([\\d\\w\\.\\/\\%\\+\\-\\=\\&amp;\\?\\:\\\\\\&quot;\\'\\,\\|\\~\\;]*)"));

Can we use the C++ raw string? Which we can remove a lot of "\".

Any ideas?

If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.