Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
gnome-builder
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Günther Wagner
gnome-builder
Commits
d1fd52cf
Commit
d1fd52cf
authored
Jul 05, 2017
by
Christian Hergert
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
html-preview: port to new editor design
Straightforward port to the new Editor and Layout API
parent
c6751ba4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
23 deletions
+33
-23
data/gtk/menus.ui
data/gtk/menus.ui
+1
-3
plugins/html-preview/html_preview_plugin/__init__.py
plugins/html-preview/html_preview_plugin/__init__.py
+27
-16
plugins/html-preview/html_preview_plugin/gtk/menus.ui
plugins/html-preview/html_preview_plugin/gtk/menus.ui
+5
-4
No files found.
data/gtk/menus.ui
View file @
d1fd52cf
...
...
@@ -246,12 +246,10 @@
<section
id=
"editor-document-section"
>
<attribute
name=
"label"
translatable=
"yes"
>
Document
</attribute>
<item>
<attribute
name=
"id"
>
editor-document-open-in-new-frame
</attribute>
<attribute
name=
"label"
translatable=
"yes"
>
Open in New Frame
</attribute>
<attribute
name=
"action"
>
layoutstack.open-in-new-frame
</attribute>
</item>
<item>
<attribute
name=
"label"
translatable=
"yes"
>
Open Preview
</attribute>
</item>
<item>
<attribute
name=
"label"
translatable=
"yes"
>
Print…
</attribute>
<attribute
name=
"action"
>
editor-view.print
</attribute>
...
...
plugins/html-preview/html_preview_plugin/__init__.py
View file @
d1fd52cf
...
...
@@ -166,6 +166,7 @@ class HtmlWorkbenchAddin(GObject.Object, Ide.WorkbenchAddin):
try
:
from
docutils.core
import
publish_string
except
ImportError
:
Ide
.
warning
(
"Failed to load docutils.core module"
)
return
can_preview_rst
=
True
...
...
@@ -178,6 +179,7 @@ class HtmlWorkbenchAddin(GObject.Object, Ide.WorkbenchAddin):
try
:
import
sphinx
except
ImportError
:
Ide
.
warning
(
"Failed to load sphinx module"
)
return
can_preview_sphinx
=
True
...
...
@@ -192,11 +194,11 @@ class HtmlPreviewAddin(GObject.Object, Ide.EditorViewAddin):
self
.
sphinx_basedir
=
None
self
.
sphinx_builddir
=
None
group
=
view
.
get_action_group
(
'editor-view'
)
self
.
action
=
Gio
.
SimpleAction
(
name
=
'preview-as-html'
,
enabled
=
True
)
self
.
action
.
connect
(
'activate'
,
lambda
*
_
:
self
.
preview_activated
(
view
))
actions
=
view
.
get_action_group
(
'view'
)
actions
.
add_action
(
self
.
action
)
group
.
add_action
(
self
.
action
)
document
=
view
.
get_buffer
()
language
=
document
.
get_language
()
...
...
@@ -205,8 +207,11 @@ class HtmlPreviewAddin(GObject.Object, Ide.EditorViewAddin):
self
.
do_language_changed
(
language_id
)
def
do_unload
(
self
,
view
):
actions
=
view
.
get_action_group
(
'view'
)
actions
.
remove_action
(
'preview-as-html'
)
group
=
view
.
get_action_group
(
'editor-view'
)
group
.
remove_action
(
'preview-as-html'
)
self
.
view
=
None
self
.
workbench
=
None
def
do_language_changed
(
self
,
language_id
):
enabled
=
(
language_id
in
(
'html'
,
'markdown'
,
'rst'
))
...
...
@@ -216,7 +221,7 @@ class HtmlPreviewAddin(GObject.Object, Ide.EditorViewAddin):
if
self
.
lang_id
==
'rst'
:
if
not
self
.
sphinx_basedir
:
document
=
self
.
view
.
get_
document
()
document
=
self
.
view
.
get_
buffer
()
path
=
document
.
get_file
().
get_file
().
get_path
()
self
.
sphinx_basedir
=
self
.
search_sphinx_base_dir
(
path
)
...
...
@@ -252,14 +257,21 @@ class HtmlPreviewAddin(GObject.Object, Ide.EditorViewAddin):
self
.
show_missing_docutils_message
(
view
)
return
document
=
view
.
get_
document
()
document
=
view
.
get_
buffer
()
web_view
=
HtmlPreviewView
(
document
,
self
.
sphinx_basedir
,
self
.
sphinx_builddir
,
visible
=
True
)
stack
=
view
.
get_ancestor
(
Ide
.
LayoutStack
)
stack
.
add
(
web_view
)
column
=
view
.
get_ancestor
(
Ide
.
LayoutGridColumn
)
grid
=
column
.
get_ancestor
(
Ide
.
LayoutGrid
)
index
=
grid
.
child_get_property
(
column
,
'index'
)
# If we are past first stack, use the 0 column stack
# otherwise create or reuse a stack to the right.
index
+=
-
1
if
index
>
0
else
1
column
=
grid
.
get_nth_column
(
index
)
column
.
add
(
web_view
)
self
.
action
.
set_enabled
(
False
)
web_view
.
connect
(
'destroy'
,
lambda
*
_
:
self
.
web_view_destroyed
(
web_view
))
...
...
@@ -341,20 +353,19 @@ class HtmlPreviewView(Ide.LayoutView):
elif
id
==
'rst'
:
self
.
rst
=
True
document
.
connect
(
'notify::title'
,
self
.
on_title_changed
)
document
.
connect
(
'changed'
,
self
.
on_changed
)
self
.
webview
.
connect
(
'destroy'
,
self
.
web_view_destroyed
)
self
.
on_changed
(
document
)
self
.
on_title_changed
(
document
)
def
on_title_changed
(
self
,
buffer
):
self
.
set_title
(
"%s %s"
%
(
buffer
.
get_title
(),
_
(
"(Preview)"
)))
def
web_view_destroyed
(
self
,
web_view
):
self
.
document
.
disconnect_by_func
(
self
.
on_changed
)
def
do_get_title
(
self
):
title
=
self
.
document
.
get_title
()
return
'%s (Preview)'
%
title
def
do_get_document
(
self
):
return
self
.
document
def
get_markdown
(
self
,
text
):
text
=
text
.
replace
(
"
\"
"
,
"
\\\"
"
).
replace
(
"
\n
"
,
"
\\
n"
)
params
=
(
HtmlPreviewData
.
MARKDOWN_CSS
,
...
...
plugins/html-preview/html_preview_plugin/gtk/menus.ui
View file @
d1fd52cf
<?xml version="1.0"?>
<interface>
<menu
id=
"ide-
layout-stack
-menu"
>
<section
id=
"
ide-layout-stack-menu-preview
-section"
>
<menu
id=
"ide-
editor-view-document
-menu"
>
<section
id=
"
editor-document
-section"
>
<item>
<attribute
name=
"label"
translatable=
"yes"
>
Preview as HTML
</attribute>
<attribute
name=
"action"
>
view.preview-as-html
</attribute>
<attribute
name=
"after"
>
editor-document-open-in-new-frame
</attribute>
<attribute
name=
"label"
translatable=
"yes"
>
Open Preview
</attribute>
<attribute
name=
"action"
>
editor-view.preview-as-html
</attribute>
</item>
</section>
</menu>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment