-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
DesktopHooks.java
161 lines (138 loc) · 4.98 KB
/
DesktopHooks.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
* DesktopHooks.java
*
* Copyright (C) 2009-11 by RStudio, Inc.
*
* 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.application;
import com.google.gwt.core.client.GWT;
import com.google.inject.Inject;
import org.rstudio.core.client.command.AppCommand;
import org.rstudio.core.client.files.FileSystemItem;
import org.rstudio.core.client.js.BaseExpression;
import org.rstudio.core.client.js.JsObjectInjector;
import org.rstudio.studio.client.application.events.EventBus;
import org.rstudio.studio.client.application.events.SaveActionChangedEvent;
import org.rstudio.studio.client.application.events.SaveActionChangedHandler;
import org.rstudio.studio.client.application.model.SaveAction;
import org.rstudio.studio.client.common.GlobalDisplay;
import org.rstudio.studio.client.common.filetypes.FileTypeRegistry;
import org.rstudio.studio.client.projects.events.OpenProjectFileEvent;
import org.rstudio.studio.client.server.Server;
import org.rstudio.studio.client.workbench.WorkbenchContext;
import org.rstudio.studio.client.workbench.commands.Commands;
import org.rstudio.studio.client.workbench.views.source.SourceShim;
/**
* Any methods on this class are automatically made available to the
* Qt frame code.
*/
public class DesktopHooks
{
@BaseExpression("$wnd.desktopHooks")
interface DesktopHooksInjector extends JsObjectInjector<DesktopHooks> {}
private static final DesktopHooksInjector injector =
GWT.create(DesktopHooksInjector.class);
@Inject
public DesktopHooks(Commands commands,
EventBus events,
GlobalDisplay globalDisplay,
Server server,
FileTypeRegistry fileTypeRegistry,
WorkbenchContext workbenchContext,
SourceShim sourceShim)
{
commands_ = commands;
events_ = events;
globalDisplay_ = globalDisplay;
server_ = server;
fileTypeRegistry_ = fileTypeRegistry;
workbenchContext_ = workbenchContext;
sourceShim_ = sourceShim;
events_.addHandler(SaveActionChangedEvent.TYPE,
new SaveActionChangedHandler()
{
public void onSaveActionChanged(SaveActionChangedEvent event)
{
saveAction_ = event.getAction();
}
});
injector.injectObject(this);
addCopyHook();
}
private native void addCopyHook() /*-{
var clean = function() {
setTimeout(function() {
$wnd.desktop.cleanClipboard(false);
}, 100)
};
$wnd.addEventListener("copy", clean, true);
$wnd.addEventListener("cut", clean, true);
}-*/;
String getActiveProjectDir()
{
if (workbenchContext_.getActiveProjectDir() != null)
return workbenchContext_.getActiveProjectDir().getPath();
else
return "";
}
void invokeCommand(String cmdId)
{
commands_.getCommandById(cmdId).execute();
}
boolean isCommandVisible(String commandId)
{
AppCommand command = commands_.getCommandById(commandId);
return command != null && command.isVisible();
}
boolean isCommandEnabled(String commandId)
{
AppCommand command = commands_.getCommandById(commandId);
return command != null && command.isEnabled();
}
String getCommandLabel(String commandId)
{
AppCommand command = commands_.getCommandById(commandId);
return command != null ? command.getMenuLabel(true) : "";
}
void openFile(String filePath)
{
// get the file system item
FileSystemItem file = FileSystemItem.createFile(filePath);
if (file.isDirectory())
return;
// this used to be possible but shouldn't be anymore
// (since we screen out .rproj from calling sendMessage
// within DesktopMain.cpp
if (file.getExtension().equalsIgnoreCase(".rproj"))
return;
// open the file. pass false for second param to prevent
// the default handler (the browser) from taking it
fileTypeRegistry_.openFile(file, false);
}
void quitR()
{
commands_.quitSession().execute();
}
int getSaveAction()
{
return saveAction_.getAction();
}
String getREnvironmentPath()
{
return workbenchContext_.getREnvironmentPath();
}
private final Commands commands_;
private final EventBus events_;
private final GlobalDisplay globalDisplay_;
private final Server server_;
private final FileTypeRegistry fileTypeRegistry_;
private final WorkbenchContext workbenchContext_;
private final SourceShim sourceShim_;
private SaveAction saveAction_ = SaveAction.saveAsk();
}