@@ -8,7 +8,9 @@ namespace Gitpodify {
8
8
export const NAV_BTN_ID = "gitpod-btn-nav" ;
9
9
export const NAV_BTN_CLASS = "gitpod-nav-btn" ;
10
10
export const NAV_BTN_CLASS_SELECTOR = "." + NAV_BTN_CLASS ;
11
-
11
+
12
+ export const EDIT_BTN_ID = "gitpod-btn-file" ;
13
+
12
14
export const CSS_REF_BTN_CONTAINER = "gitpod-btn-container" ;
13
15
export const CSS_REF_NO_CONTAINER = "no-container" ;
14
16
}
@@ -23,6 +25,7 @@ export class GitHubInjector extends InjectorBase {
23
25
new PullInjector ( ) ,
24
26
new IssueInjector ( ) ,
25
27
new FileInjector ( ) ,
28
+ new EditFileButtonInjector ( ) ,
26
29
new NavigationInjector ( ) ,
27
30
new EmptyRepositoryInjector ( ) ,
28
31
] ) ;
@@ -113,9 +116,13 @@ abstract class ButtonInjectorBase implements ButtonInjector {
113
116
const primaryButtons = actionbar . getElementsByClassName ( "btn-primary" ) ;
114
117
if ( primaryButtons && primaryButtons . length > 1 ) {
115
118
Array . from ( primaryButtons )
116
- . slice ( 0 , primaryButtons . length - 1 )
117
- . forEach ( primaryButton => primaryButton . classList . replace ( "btn-primary" , "btn-secondary" ) ) ;
119
+ . slice ( 0 , primaryButtons . length - 1 )
120
+ . forEach ( primaryButton => primaryButton . classList . replace ( "btn-primary" , "btn-secondary" ) ) ;
118
121
}
122
+
123
+ // Edit File Menu Options - Open in Gitpod
124
+ const editFileButton = document . querySelector ( '.Box-header .select-menu .SelectMenu-list' ) as ParentNode ;
125
+ editFileButton . prepend ( this . renderEditButton ( currentUrl , openAsPopup ) ) ;
119
126
}
120
127
121
128
protected renderButton ( url : string , openAsPopup : boolean ) : HTMLElement {
@@ -147,6 +154,20 @@ abstract class ButtonInjectorBase implements ButtonInjector {
147
154
protected adjustButton ( a : HTMLAnchorElement ) {
148
155
// do nothing
149
156
}
157
+
158
+ protected renderEditButton ( url : string , openAsPopup : boolean ) : HTMLElement {
159
+ const a = document . createElement ( 'a' ) ;
160
+ a . id = Gitpodify . EDIT_BTN_ID ;
161
+ a . title = "Edit this file in Gitpod" ;
162
+ a . text = "Open in Gitpod" ;
163
+ a . href = url ;
164
+ a . target = "_blank" ;
165
+ if ( openAsPopup ) {
166
+ makeOpenInPopup ( a ) ;
167
+ }
168
+ a . className = "SelectMenu-item js-blob-dropdown-click width-full d-flex flex-justify-between color-fg-default f5 text-normal" ;
169
+ return a ;
170
+ }
150
171
}
151
172
152
173
class PullInjector extends ButtonInjectorBase {
@@ -169,6 +190,16 @@ class IssueInjector extends ButtonInjectorBase {
169
190
}
170
191
}
171
192
193
+ class EditFileButtonInjector extends ButtonInjectorBase {
194
+ constructor ( ) {
195
+ super ( "" , "gitpod-file-edit-btn" ) ;
196
+ }
197
+
198
+ isApplicableToCurrentPage ( ) : boolean {
199
+ return window . location . pathname . includes ( "/blob/" ) ;
200
+ }
201
+ }
202
+
172
203
class FileInjector extends ButtonInjectorBase {
173
204
constructor ( ) {
174
205
super ( ".repository-content > div > div > div" , "gitpod-file-btn" ) ;
0 commit comments