Add eaf-open-doc command.

master
Andy Stewart 6 years ago
parent 0e25dc27fe
commit 19f5874c7d
  1. 4
      README.md
  2. 6
      README.zh-CN.md
  3. 8
      app/pdf-viewer/buffer.py
  4. 35
      eaf.el

@ -90,6 +90,8 @@ echo 'export LANG=zh_CN.UTF-8' >> ~/.bashrc
5. For EAF Browser download to work, please install ```aria2```.
5. For EAF Doc Viewer to work, please install ```libreoffice```.
### Dependency List
Packages listed as **Core** are mandatory for EAF to work, whereas other packages are optional - install if you want to use corresponding EAF Application.
@ -106,6 +108,7 @@ Packages listed as **Core** are mandatory for EAF to work, whereas other package
| aria2p | pip3 | Browser | Send download requests to Aria2 daemon |
| aria2 | pacman (Arch) | Browser | Download files from the web |
| wetty | yarn | Terminal | Communicate between browser and local TTY |
| libreoffice | pacman | Doc Viewer | Convert doc file to pdf |
## Launch EAF Applications
| Application Name | Launch |
@ -125,6 +128,7 @@ Packages listed as **Core** are mandatory for EAF to work, whereas other package
| Airshare | `M-x eaf-open-airshare` |
| RSS Reader | `M-x eaf-open-rss-reader` |
| Mindmap | `M-x eaf-create-mindmap` or `M-x eaf-open-mindmap` |
| Doc Viewer | `M-x eaf-open-doc` |
| Demo | `M-x eaf-open-demo` to verify basic functionality |
- To open the file under the cursor in `dired` using appropriate EAF Application, use `eaf-open-this-from-dired` instead.

@ -88,6 +88,8 @@ echo 'export LANG=zh_CN.UTF-8' >> ~/.bashrc
5. EAF浏览器的下载功能依赖aria2,还需要你额外安装 ```aria2``` 这个工具。
6. EAF办公文档阅读器需要你额外安装 ```libreoffice``` 这个工具。
### 依赖列表
**核心** 分类代表必备依赖,这些包必须安装好EAF才能工作。其余依赖都可选,若想其使用对应的应用时,你才需要安装这些依赖。当然我们推荐先把所有依赖都安装好,等到真正使用的时候就不用再次折腾。
@ -104,6 +106,7 @@ echo 'export LANG=zh_CN.UTF-8' >> ~/.bashrc
| aria2p | pip3 | 浏览器 | 发送下载请求给Aria2 Daemon |
| aria2 | pacman (Arch) | 浏览器 | 下载网络文件 |
| wetty | yarn | 终端模拟器 | 通过浏览器与本地TTY交互 |
| libreoffice | pacman | 办公文档阅读器 | 转换doc文件为pdf格式 |
## EAF应用启动命令
| 应用名称 | 启动命令 |
@ -122,7 +125,8 @@ echo 'export LANG=zh_CN.UTF-8' >> ~/.bashrc
| 二维码上传文件 | `M-x eaf-file-receiver-qrcode` |
| 无线分享 | `M-x eaf-open-airshare` 输入要分享给手机的字符串 |
| RSS新闻阅读器 | `M-x eaf-open-rss-reader` |
| 思维导图 | `M-x eaf-create-mindmap` or `M-x eaf-open-mindmap` |
| 思维导图 | `M-x eaf-create-mindmap` or `M-x eaf-open-mindmap` |
| 办公文档阅读器 | `M-x eaf-open-doc` |
| 演示程序 | `M-x eaf-open-demo` |
- 在`dired`文件管理器中,建议绑定按键到命令 `eaf-open-this-from-dired` ,它会自动用合适的EAF应用来打开文件。

@ -37,6 +37,7 @@ class AppBuffer(Buffer):
def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict):
Buffer.__init__(self, buffer_id, url, arguments, emacs_var_dict, False, QColor(0, 0, 0, 255))
self.delete_temp_file = arguments == "temp_pdf_file"
self.add_widget(PdfViewerWidget(url, config_dir, QColor(0, 0, 0, 255), buffer_id, emacs_var_dict))
self.buffer_widget.translate_double_click_word.connect(self.translate_text)
@ -45,6 +46,13 @@ class AppBuffer(Buffer):
"toggle_read_mode", "toggle_inverted_mode", "toggle_mark_link"]:
self.build_widget_method(method_name)
def handle_destroy(self):
if self.delete_temp_file:
if os.path.exists(self.url):
os.remove(self.url)
super.handle_destroy(self)
def get_table_file(self):
return self.buffer_widget.table_file_path

@ -506,6 +506,11 @@ Try not to modify this alist directly. Use `eaf-setq' to modify instead."
"The extension list of mindmap application."
:type 'cons)
(defcustom eaf-doc-extension-list
'("docx" "doc")
"The extension list of doc application."
:type 'cons)
(defcustom eaf-mua-get-html
'(("^gnus-" . eaf-gnus-get-html)
("^mu4e-" . eaf-mu4e-get-html)
@ -1416,12 +1421,15 @@ choose a search engine defined in `eaf-browser-search-engines'"
Other files will open normally with `dired-find-file' or `dired-find-alternate-file'"
(interactive)
(dolist (file (dired-get-marked-files))
(cond ((eaf--get-app-for-extension
(eaf-get-file-name-extension file))
(eaf-open file))
(eaf-find-alternate-file-in-dired
(dired-find-alternate-file))
(t (dired-find-file)))))
(cond
((member (eaf-get-file-name-extension file) eaf-doc-extension-list)
(eaf-open-doc file))
((eaf--get-app-for-extension
(eaf-get-file-name-extension file))
(eaf-open file))
(eaf-find-alternate-file-in-dired
(dired-find-alternate-file))
(t (dired-find-file)))))
;;;###autoload
(define-obsolete-function-alias 'eaf-file-open-in-dired #'eaf-open-this-from-dired)
@ -1578,6 +1586,21 @@ Make sure that your smartphone is connected to the same WiFi network as this com
(interactive "fOpen EAF Mind Map: ")
(eaf-open file "mindmap"))
(defun eaf-open-doc (file)
(interactive "fOpen doc: ")
(if (executable-find "libreoffice")
(progn
(message "Converting %s to PDF format, EAF will start after convert finish." file)
(make-process
:name ""
:buffer " *eaf-open-doc*"
:command (list "libreoffice" "--headless" "--convert-to" "pdf" (file-truename file) "--outdir" "/tmp")
:sentinel (lambda (process event)
(when (string= (substring event 0 -1) "finished")
(eaf-open (format "%s/%s.pdf" "/tmp" (file-name-base file)) "pdf-viewer" "temp_pdf_file")
))))
(message "Please install libreoffice to convert doc to pdf.")))
(dbus-register-signal
:session "com.lazycat.eaf" "/com/lazycat/eaf"
"com.lazycat.eaf" "edit_focus_text"

Loading…
Cancel
Save