/*
 * SourceSatelliteWindow.java
 *
 * Copyright (C) 2009-15 by RStudio, Inc.
 *
 * Unless you have received this program directly from RStudio pursuant
 * to the terms of a commercial license agreement with RStudio, then
 * this program is licensed to you under the terms of version 3 of the
 * GNU Affero General Public License. This program is distributed WITHOUT
 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
 *
 */

package org.rstudio.studio.client.workbench.views.source;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;

import org.rstudio.studio.client.application.events.EventBus;
import org.rstudio.studio.client.application.ui.CodeSearchLauncher;
import org.rstudio.studio.client.common.satellite.SatelliteWindow;
import org.rstudio.studio.client.workbench.ui.FontSizeManager;
import org.rstudio.studio.client.workbench.views.source.model.SourceWindowParams;

@Singleton
public class SourceSatelliteWindow extends SatelliteWindow
                                   implements SourceSatelliteView
{

   @Inject
   public SourceSatelliteWindow(Provider<EventBus> pEventBus,
                                Provider<FontSizeManager> pFSManager, 
                                Provider<SourceSatellitePresenter> pPresenter,
                                Provider<SourceWindowManager> pWindowManager,
                                CodeSearchLauncher launcher)
   {
      super(pEventBus, pFSManager);
      pPresenter_ = pPresenter;
      pWindowManager_ = pWindowManager;
   }

   @Override
   protected void onInitialize(LayoutPanel mainPanel, JavaScriptObject params)
   {
      SourceWindowParams windowParams = params.cast();
      String title = null;
      if (windowParams != null)
      {
         pWindowManager_.get().setSourceWindowOrdinal(
               windowParams.getOrdinal());
         title = windowParams.getTitle();
      }
      if (title == null)
         title = "";
      else
         title += " - ";
      title += "RStudio Source Editor";
      Window.setTitle(title);
      

      SourceSatellitePresenter appPresenter = pPresenter_.get();
      
      // make it fill the containing layout panel
      Widget presWidget = appPresenter.asWidget();
      mainPanel.add(presWidget);
      mainPanel.setWidgetLeftRight(presWidget, 0, Unit.PX, 0, Unit.PX);
      mainPanel.setWidgetTopBottom(presWidget, 0, Unit.PX, 0, Unit.PX);
   }

   @Override
   public void reactivate(JavaScriptObject params)
   {
   }
   
   @Override 
   public Widget getWidget()
   {
      return this;
   }
   
   private final Provider<SourceSatellitePresenter> pPresenter_;
   private final Provider<SourceWindowManager> pWindowManager_;
}
@@ -984,16 +984,75 @@
 leton;%0A%0A
+import org.rstudio.studio.client.application.DesktopHooks;%0A
 import o
@@ -1822,24 +1822,94 @@
 dowManager,%0A
+                                Provider%3CDesktopHooks%3E pDesktopHooks,%0A
             
@@ -2070,16 +2070,81 @@
 anager;%0A
+      %0A      // inject desktop hooks%0A      pDesktopHooks.get(); %0A
    %7D%0A%0A  

add desktop hooks to the source window