本文整理汇总了Python中gi.repository.Gedit.commands_save_document方法的典型用法代码示例。如果您正苦于以下问题:Python Gedit.commands_save_document方法的具体用法?Python Gedit.commands_save_document怎么用?Python Gedit.commands_save_document使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gi.repository.Gedit
的用法示例。
在下文中一共展示了Gedit.commands_save_document方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from gi.repository import Gedit [as 别名]
# 或者: from gi.repository.Gedit import commands_save_document [as 别名]
def __init__(self, window, panel, all_docs, node):
self._window = window
self._panel = panel
self._node = node
self._error = False
self._signal_ids = {}
self._counter = 0
if all_docs:
docs = window.get_documents()
else:
docs = [window.get_active_document()]
docs_to_save = [doc for doc in docs if doc.get_modified()]
signals = {}
for doc in docs_to_save:
signals[doc] = doc.connect('saving', self.on_document_saving)
if len(docs_to_save) == len(docs) and len(docs) != 0:
Gedit.commands_save_all_documents(window)
else:
for doc in docs_to_save:
Gedit.commands_save_document(window, doc)
for doc in docs_to_save:
doc.disconnect(signals[doc])
self.run_tool()
示例2: save_file
# 需要导入模块: from gi.repository import Gedit [as 别名]
# 或者: from gi.repository.Gedit import commands_save_document [as 别名]
def save_file(self):
"""
Trigger the 'Save' action
(used by ToolAction before tool run)
"""
tab = self._active_tab_decorator.tab
Gedit.commands_save_document(tab.get_toplevel(), tab.get_document())
示例3: on_focus_out_event
# 需要导入模块: from gi.repository import Gedit [as 别名]
# 或者: from gi.repository.Gedit import commands_save_document [as 别名]
def on_focus_out_event(self, widget, focus):
for n, doc in enumerate(self.window.get_unsaved_documents()):
if doc.is_untouched():
# nothing to do
continue
if doc.is_untitled():
# provide a default filename
now = datetime.datetime.now()
assure_path_exists(dirname)
filename = now.strftime(dirname + "%Y%m%d-%H%M%S-%%d.txt") % (n + 1)
doc.set_location(Gio.file_parse_name(filename))
# save the document
Gedit.commands_save_document(self.window, doc)
示例4: on_focus_out_event
# 需要导入模块: from gi.repository import Gedit [as 别名]
# 或者: from gi.repository.Gedit import commands_save_document [as 别名]
def on_focus_out_event(self, widget, focus):
for doc in self.window.get_unsaved_documents():
if doc.is_untouched():
# nothing to do
continue
if doc.is_untitled():
# provide a default filename
now = datetime.datetime.now()
filename = now.strftime("/tmp/gedit.unsaved.%Y%m%d-%H%M%S.txt")
doc.set_location(Gio.file_parse_name(filename))
# save the document
Gedit.commands_save_document(self.window, doc)
示例5: __init__
# 需要导入模块: from gi.repository import Gedit [as 别名]
# 或者: from gi.repository.Gedit import commands_save_document [as 别名]
def __init__(self, window, panel, docs, node):
self._window = window
self._panel = panel
self._node = node
self._error = False
self._counter = len(docs)
self._signal_ids = {}
self._counter = 0
signals = {}
for doc in docs:
signals[doc] = doc.connect('saving', self.on_document_saving)
Gedit.commands_save_document(window, doc)
doc.disconnect(signals[doc])
示例6: save
# 需要导入模块: from gi.repository import Gedit [as 别名]
# 或者: from gi.repository.Gedit import commands_save_document [as 别名]
def save(view):
window = view.get_toplevel()
Gedit.commands_save_document(window, view.get_buffer())
return commander.commands.result.HIDE
示例7: action_handler
# 需要导入模块: from gi.repository import Gedit [as 别名]
# 或者: from gi.repository.Gedit import commands_save_document [as 别名]
#.........这里部分代码省略.........
if not vi:
return
vi.delete_selection()
elif curr_action == "select_all":
vi = self.view
if not vi:
return
vi.select_all()
elif curr_action == "sentence_end":
self.inserttext('. ')
elif curr_action == "line_end":
self.inserttext('\n')
elif curr_action == "delete_line":
doc = self.document
if not doc:
return
for _ in range(num):
doc.begin_user_action()
ei = self.get_cursor_position(doc)
si = self.get_cursor_position(doc)
si.set_line(ei.get_line())
ei.forward_to_line_end()
doc.delete(si, ei)
doc.end_user_action()
elif curr_action == "delete_sentence":
doc = self.document
if not doc:
return
for _ in range(num):
doc.begin_user_action()
ei = self.get_cursor_position(doc)
si = self.get_cursor_position(doc)
if not si.starts_sentence():
si.backward_sentence_start()
si.backward_char()
ei.forward_sentence_end()
doc.delete(si, ei)
doc.end_user_action()
elif curr_action == "delete_word":
doc = self.document
if not doc:
return
for _ in range(num):
doc.begin_user_action()
ei = self.get_cursor_position(doc)
si = self.get_cursor_position(doc)
si.backward_word_start()
si.backward_char()
ei.forward_word_end()
doc.delete(si, ei)
doc.end_user_action()
elif curr_action == "clear_document":
doc = self.document
if not doc:
return
doc.begin_user_action()
doc.set_text('')
doc.end_user_action()
elif curr_action == "new_document":
self.window.create_tab(True)
elif curr_action == "save_document":
doc = self.document
if not doc:
return
Gedit.commands_save_document(self.window, doc)
elif curr_action == "save_as_document":
# get complete text from current document
doc = self.document
txt = doc.get_text(doc.get_start_iter(), doc.get_end_iter(), False)
gfile_path = FileSaveAsDialog(self.window).file_dialog_handler(txt)
if gfile_path is not None:
# the file has been created by above function and we load it
Gedit.commands_load_location(self.window, gfile_path, None, 0, 0)
elif curr_action == "close_document":
doc = self.document
if not doc:
return
tab = self.tab
if not tab:
return
u_docs = self.window.get_unsaved_documents()
if self.document not in u_docs:
self.window.close_tab(tab)
else:
# to prevent data loss
self.bottom_bar_text_set("You might want to save this document before closing it.")
elif curr_action == "force_close_document":
tab = self.tab
if not tab:
return
self.window.close_tab(tab)
elif curr_action == "exit":
u_docs = self.window.get_unsaved_documents()
if len(u_docs) == 0:
sys.exit()
else:
self.bottom_bar_text_set("You might want to save all documents before quitting.")
else:
self.bottom_bar_text_set("WEIRD STATE! How did you reach this state? O_O")
return
示例8: save
# 需要导入模块: from gi.repository import Gedit [as 别名]
# 或者: from gi.repository.Gedit import commands_save_document [as 别名]
def save(self):
if not self.doc.is_untouched():
Gedit.commands_save_document(self.window, self.doc)
self.timeouts['save'] = None
return False