Skip to content

Commit 25613e4

Browse files
committed
Merge branch 'gs_530_2' into 'master'
Implemented "Open explorer" contextual menu. See merge request eng/ide/gnatstudio!873
2 parents 942e27f + aba3ccf commit 25613e4

File tree

7 files changed

+121
-0
lines changed

7 files changed

+121
-0
lines changed

share/plug-ins/explorer.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"""Contextual menu: 'Open in system file explorer'
2+
3+
This plugin adds a contextual menu on files and directories in
4+
the Project View and File View, to reveal the object in the system
5+
file explorer.
6+
7+
"""
8+
9+
import os
10+
import sys
11+
import GPS
12+
from gs_utils import interactive
13+
import subprocess
14+
15+
16+
def can_execute(context):
17+
"""A filter to only allow this action for project or files view"""
18+
return (
19+
context.file() is not None or context.directory() is not None
20+
) and context.module_name in ["Files_View", "Project_Explorer_Project"]
21+
22+
23+
@interactive(
24+
name="Open in system file explorer",
25+
contextual="Open in system file explorer",
26+
filter=can_execute
27+
)
28+
def on_activate():
29+
restored = os.environ.copy()
30+
for k in os.environ:
31+
if k.startswith("GPS_STARTUP_"):
32+
old = k[12:]
33+
if os.environ[k] == "_ABSENT_VARIABLE_":
34+
if old in restored.keys():
35+
restored.pop(old)
36+
else:
37+
restored[old] = os.environ[k]
38+
39+
path = GPS.current_context().directory()
40+
41+
if path is None:
42+
if GPS.current_context().file() is not None:
43+
path = GPS.current_context().file().path
44+
else:
45+
path = '.'
46+
47+
if sys.platform == "win32":
48+
e = 'explorer.exe'
49+
path = '"' + path + '"'
50+
else:
51+
e = 'xdg-open'
52+
53+
try:
54+
subprocess.run([e, path], env=restored)
55+
except Exception as ex:
56+
GPS.Console().write(str(ex))
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
project Default is
2+
3+
package Compiler is
4+
for Switches ("Ada") use ("-g", "-O2");
5+
end Compiler;
6+
7+
for Main use ("main.adb");
8+
9+
end Default;
10+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
with Ada.Text_IO;
2+
3+
procedure Main is
4+
5+
procedure P1;
6+
procedure P2;
7+
8+
procedure P1 is
9+
Var : Boolean := False;
10+
begin
11+
P2;
12+
end P1;
13+
14+
procedure P2 is
15+
Var : Boolean := True;
16+
begin
17+
Ada.Text_IO.Put_Line ("Hello");
18+
end P2;
19+
20+
21+
begin
22+
P1;
23+
end Main;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
if [ "$OS" != "Windows_NT" ]; then
2+
export PATH=`pwd`:$PATH
3+
echo `pwd`/ > home.txt
4+
$GPS -Pdefault --load=python:test.py
5+
diff -u home.txt args.txt
6+
fi
7+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import GPS
2+
from gs_utils.internal.utils import *
3+
4+
"""
5+
Verify that 'Open in system file explorer' action
6+
works.
7+
8+
"""
9+
10+
11+
@run_test_driver
12+
def test_driver():
13+
prj_view = Project_View()
14+
yield prj_view.open_and_yield()
15+
explorer = get_widget_by_name("Project Explorer Tree")
16+
explorer.expand_row(Gtk.TreePath((0, 0)), True)
17+
prj_view.select_by_name(column=1, value="main.adb")
18+
yield wait_idle()
19+
GPS.execute_action("Open in system file explorer")
20+
yield wait_idle()
21+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
title: 'gs.530_open_explorer'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
echo "$1" > args.txt
3+

0 commit comments

Comments
 (0)