Kaydet (Commit) ecec5524 authored tarafından Samuel Mehrbrodt's avatar Samuel Mehrbrodt Kaydeden (comit) Thorsten Behrens

tdf#102274 Closing LibreOffice should not kill active UNO connections

When closing the last window, check whether there are active UNO connections.
If that's the case, just close the window, don't terminate the application
so that the connected application keeps working.

This doesn't affect the behavior of "File->Exit LibreOffice". In that case,
the application still gets terminated and existing connections are closed.

Change-Id: If2d22d51c9b566be8abd51969f35c80896ed4767
Reviewed-on: https://gerrit.libreoffice.org/29018Reviewed-by: 's avatarThorsten Behrens <Thorsten.Behrens@CIB.de>
Tested-by: 's avatarThorsten Behrens <Thorsten.Behrens@CIB.de>
üst fced5de4
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#include <services.h> #include <services.h>
#include <general.h> #include <general.h>
#include <com/sun/star/bridge/BridgeFactory.hpp>
#include <com/sun/star/bridge/XBridgeFactory2.hpp>
#include <com/sun/star/frame/Desktop.hpp> #include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/frame/XController.hpp> #include <com/sun/star/frame/XController.hpp>
#include <com/sun/star/frame/CommandGroup.hpp> #include <com/sun/star/frame/CommandGroup.hpp>
...@@ -293,6 +295,12 @@ IMPL_LINK_NOARG(CloseDispatcher, impl_asyncCallback, LinkParamNone*, void) ...@@ -293,6 +295,12 @@ IMPL_LINK_NOARG(CloseDispatcher, impl_asyncCallback, LinkParamNone*, void)
css::uno::Reference< css::frame::XFramesSupplier > xDesktop( css::frame::Desktop::create(xContext), css::uno::UNO_QUERY_THROW); css::uno::Reference< css::frame::XFramesSupplier > xDesktop( css::frame::Desktop::create(xContext), css::uno::UNO_QUERY_THROW);
FrameListAnalyzer aCheck1(xDesktop, xCloseFrame, FrameListAnalyzer::E_HELP | FrameListAnalyzer::E_BACKINGCOMPONENT); FrameListAnalyzer aCheck1(xDesktop, xCloseFrame, FrameListAnalyzer::E_HELP | FrameListAnalyzer::E_BACKINGCOMPONENT);
// Check for existing UNO connections.
// NOTE: There is a race between checking this and connections being created/destroyed before
// we close the frame / terminate the app.
css::uno::Reference<css::bridge::XBridgeFactory2> bridgeFac( css::bridge::BridgeFactory::create(xContext) );
bool bHasActiveConnections = bridgeFac->getExistingBridges().getLength() > 0;
// a) If the current frame (where the close dispatch was requested for) does not have // a) If the current frame (where the close dispatch was requested for) does not have
// any parent frame ... it will close this frame only. Such frame isn't part of the // any parent frame ... it will close this frame only. Such frame isn't part of the
// global desktop tree ... and such frames are used as "implementation details" only. // global desktop tree ... and such frames are used as "implementation details" only.
...@@ -310,13 +318,15 @@ IMPL_LINK_NOARG(CloseDispatcher, impl_asyncCallback, LinkParamNone*, void) ...@@ -310,13 +318,15 @@ IMPL_LINK_NOARG(CloseDispatcher, impl_asyncCallback, LinkParamNone*, void)
else if (aCheck1.m_bReferenceIsHelp) else if (aCheck1.m_bReferenceIsHelp)
bCloseFrame = true; bCloseFrame = true;
// c) If we are already in "backing mode", we have to terminate // c) If we are already in "backing mode", we terminate the application, if no active UNO connections are found.
// the application, if this special frame is closed. // If there is an active UNO connection, we only close the frame and leave the application alive.
// It doesn't matter, how many other frames (can be the help or hidden frames only) // It doesn't matter, how many other frames (can be the help or hidden frames only) are open then.
// are open then. else if (aCheck1.m_bReferenceIsBacking) {
// => terminate the application! if (bHasActiveConnections)
else if (aCheck1.m_bReferenceIsBacking) bCloseFrame = true;
bTerminateApp = true; else
bTerminateApp = true;
}
// d) Otherwhise we have to: close all views to the same document, close the // d) Otherwhise we have to: close all views to the same document, close the
// document inside our own frame and decide then again, what has to be done! // document inside our own frame and decide then again, what has to be done!
...@@ -352,7 +362,9 @@ IMPL_LINK_NOARG(CloseDispatcher, impl_asyncCallback, LinkParamNone*, void) ...@@ -352,7 +362,9 @@ IMPL_LINK_NOARG(CloseDispatcher, impl_asyncCallback, LinkParamNone*, void)
// application or establish the backing mode now. // application or establish the backing mode now.
// And that depends from the dispatched URL ... // And that depends from the dispatched URL ...
{ {
if (eOperation == E_CLOSE_FRAME) if (bHasActiveConnections)
bCloseFrame = true;
else if (eOperation == E_CLOSE_FRAME)
bTerminateApp = true; bTerminateApp = true;
else if( SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::EModule::STARTMODULE) ) else if( SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::EModule::STARTMODULE) )
bEstablishBackingMode = true; bEstablishBackingMode = true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment