mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Closing of editor tabs
This commit is contained in:
parent
bcd9e53904
commit
f3a660fec3
@ -50,6 +50,7 @@ class Boss(QObject):
|
||||
fl.rename_requested.connect(self.rename_requested)
|
||||
fl.edit_file.connect(self.edit_file_requested)
|
||||
self.gui.central.current_editor_changed.connect(self.apply_current_editor_state)
|
||||
self.gui.central.close_requested.connect(self.editor_close_requested)
|
||||
|
||||
def mkdtemp(self, prefix=''):
|
||||
self.container_count += 1
|
||||
@ -271,7 +272,25 @@ class Boss(QObject):
|
||||
actions['editor-undo'].setEnabled(ed.undo_available)
|
||||
actions['editor-redo'].setEnabled(ed.redo_available)
|
||||
actions['editor-save'].setEnabled(ed.is_modified)
|
||||
self.gui.keyboard.set_mode(ed.syntax)
|
||||
self.gui.keyboard.set_mode(ed.syntax)
|
||||
else:
|
||||
self.gui.keyboard.set_mode('other')
|
||||
|
||||
def editor_close_requested(self, editor):
|
||||
name = None
|
||||
for n, ed in self.editors.iteritems():
|
||||
if ed is editor:
|
||||
name = n
|
||||
if not name:
|
||||
return
|
||||
if editor.is_modified:
|
||||
if not question_dialog(self.gui, _('Unsaved changes'), _(
|
||||
'There are unsaved changes in %s. Are you sure you want to close'
|
||||
' this editor?') % name):
|
||||
return
|
||||
self.editors.pop(name)
|
||||
self.gui.central.close_editor(editor)
|
||||
editor.break_cycles()
|
||||
|
||||
def do_editor_save(self):
|
||||
ed = self.gui.central.current_editor
|
||||
|
@ -71,6 +71,13 @@ class Editor(QMainWindow):
|
||||
b.addAction(actions['editor-undo'])
|
||||
b.addAction(actions['editor-redo'])
|
||||
|
||||
def break_cycles(self):
|
||||
self.modification_state_changed.disconnect()
|
||||
self.undo_redo_state_changed.disconnect()
|
||||
self.editor.undoAvailable.disconnect()
|
||||
self.editor.redoAvailable.disconnect()
|
||||
self.editor.modificationChanged.disconnect()
|
||||
self.editor.setPlainText('')
|
||||
|
||||
def launch_editor(path_to_edit, path_is_raw=False, syntax='html'):
|
||||
if path_is_raw:
|
||||
|
@ -22,6 +22,7 @@ class Central(QStackedWidget):
|
||||
' The central widget, hosts the editors '
|
||||
|
||||
current_editor_changed = pyqtSignal()
|
||||
close_requested = pyqtSignal(object)
|
||||
|
||||
def __init__(self, parent=None):
|
||||
QStackedWidget.__init__(self, parent)
|
||||
@ -50,6 +51,11 @@ class Central(QStackedWidget):
|
||||
else:
|
||||
self.modified_icon = QIcon(I('modified.png'))
|
||||
self.editor_tabs.currentChanged.connect(self.current_editor_changed)
|
||||
self.editor_tabs.tabCloseRequested.connect(self._close_requested)
|
||||
|
||||
def _close_requested(self, index):
|
||||
editor = self.editor_tabs.widget(index)
|
||||
self.close_requested.emit(editor)
|
||||
|
||||
def add_editor(self, name, editor):
|
||||
fname = name.rpartition('/')[2]
|
||||
@ -61,6 +67,13 @@ class Central(QStackedWidget):
|
||||
self.setCurrentIndex(1)
|
||||
self.editor_tabs.setCurrentWidget(editor)
|
||||
|
||||
def close_editor(self, editor):
|
||||
for i in xrange(self.editor_tabs.count()):
|
||||
if self.editor_tabs.widget(i) is editor:
|
||||
self.editor_tabs.removeTab(i)
|
||||
return True
|
||||
return False
|
||||
|
||||
def editor_modified(self, *args):
|
||||
tb = self.editor_tabs.tabBar()
|
||||
for i in xrange(self.editor_tabs.count()):
|
||||
|
Loading…
x
Reference in New Issue
Block a user