Menu

#177 Corrections

Future
open
None
5
2019-08-14
2019-08-11
No

Hi, I made five corrections to the program, can you incorporate them? related to wxwidgets error messages and the single instance function in Ubuntu did not work correctly.

src/xmlcopyeditor.cpp

@@ -330,10 +330,9 @@
{
lang = systemLocale;
}
- server = new MyServer;
+
if ( singleInstanceCheck )
{
- server->Create ( IPC_SERVICE );
wxString name;
name.Printf ( _T ( "xmlcopyeditor-%s" ), wxGetUserId().c_str() );
checker = new wxSingleInstanceChecker ( name );
@@ -344,6 +343,9 @@
return false;
}
}
+
+ server = new MyServer;
+ server->Create ( IPC_SERVICE );

myLocale.Init ( lang, wxLOCALE_LOAD_DEFAULT );

@@ -3551,7 +3553,7 @@
return;

wxString defaultFile, defaultDir;
  • defaultFile = doc->getShortFileName();
  • defaultFile = doc->getFullFileName();
    defaultDir = doc->getDirectory();
    if ( defaultDir.empty() )
    defaultDir = mLastDir;

src/mynotebook.cpp

@@ -46,7 +46,7 @@

void MyNotebook::OnLeftDown ( wxMouseEvent& event )
{
- int page = GetSelection();
+ int page = HitTest ( wxPoint ( event.GetX(), event.GetY() ) );
if ( page == -1 )
{
event.Skip();
@@ -64,7 +64,7 @@

void MyNotebook::OnMiddleDown ( wxMouseEvent& event )
{
- int page = GetSelection();
+ int page = HitTest ( wxPoint ( event.GetX(), event.GetY() ) );
if ( page == -1 )
{
event.Skip();
@@ -78,7 +78,7 @@

void MyNotebook::OnRightDown ( wxMouseEvent& event )
{
- rightClickPage = GetSelection();
+ rightClickPage = HitTest ( wxPoint ( event.GetX(), event.GetY() ) );
if ( rightClickPage == -1 )
{
event.Skip();

Discussion

  • Zane U. Ji

    Zane U. Ji - 2019-08-11

    You're modifying a quite old version of the source code if you create the patch correctly.

    If you reversed the order of the original file and the patched file, then I am wondering why

    server = new MyServer;
    

    has to be moved? It seems that the change leads to a potential memory leak. Please correct me if I am wrong.

     
  • Jairo Grateron

    Jairo Grateron - 2019-08-12

    Hello, the last modification is not correct since the error persists. Basically there is a race condition when running xmlcopyeditor simultaneously. It is not necessary to use the wxSingleInstanceChecker class since the server ensures if there is another program running.

    @@ -233,10 +233,8 @@

    MyApp::~MyApp()
    {
    - if (checker)
    - delete checker;
    - if (server)
    - delete server;
    + delete checker;
    + delete server;
    }

    bool MyApp::OnInit()
    @@ -335,14 +333,19 @@

    if ( singleInstanceCheck )
    {
    
    • server = new MyServer;
    • if (!server->Create ( IPC_SERVICE ))
    • wxString name;
    • name.Printf ( _T ( "xmlcopyeditor-%s" ), wxGetUserId().c_str() );
    • checker = new wxSingleInstanceChecker ( name );
    • if ( checker->IsAnotherRunning() )
      {
      MyClient client;
      if ( client.talkToServer ( argc, argv ) )
      return false;
      }
      }
      +
    • server = new MyServer;
    • server->Create ( IPC_SERVICE );

      myLocale.Init ( lang, wxLOCALE_LOAD_DEFAULT );

    @@ -3550,7 +3553,7 @@
    return;

    wxString defaultFile, defaultDir;
    
    • defaultFile = doc->getShortFileName();
    • defaultFile = doc->getFullFileName();
      defaultDir = doc->getDirectory();
      if ( defaultDir.empty() )
      defaultDir = mLastDir;

    I have been testing and it works well, a small contribution to this magnificent program that I use daily.

    attached warnings that were corrected

     
  • Jairo Grateron

    Jairo Grateron - 2019-08-12

    I attach the patch

     
  • Zane U. Ji

    Zane U. Ji - 2019-08-14

    The file name change is merged [da26cf].

    However, the single instance patch doesn't work on Windows since wxServer is a alias for wxDDEServer.

     

    Related

    Commit: [da26cf]


Log in to post a comment.