Implement spacer and separator count change
Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
This commit is contained in:
parent
631334219c
commit
32fae6fb82
@ -36,6 +36,9 @@ class ToolbarTools(Falkon.PluginInterface, QtCore.QObject):
|
|||||||
self.config.settingsFile = os.path.join(settingsPath, "ToolbarTools", "settings.ini")
|
self.config.settingsFile = os.path.join(settingsPath, "ToolbarTools", "settings.ini")
|
||||||
self.config.load()
|
self.config.load()
|
||||||
|
|
||||||
|
self.config.spacerCountChanged.connect(self.onSpacerCountChanged)
|
||||||
|
self.config.separatorCountChanged.connect(self.onSeparatorCountChanged)
|
||||||
|
|
||||||
plugins = Falkon.MainApplication.instance().plugins()
|
plugins = Falkon.MainApplication.instance().plugins()
|
||||||
|
|
||||||
plugins.mainWindowCreated.connect(self.onMainWindowCreated)
|
plugins.mainWindowCreated.connect(self.onMainWindowCreated)
|
||||||
@ -58,23 +61,65 @@ class ToolbarTools(Falkon.PluginInterface, QtCore.QObject):
|
|||||||
settings = SettingsDialog(self.config, parent)
|
settings = SettingsDialog(self.config, parent)
|
||||||
settings.exec_()
|
settings.exec_()
|
||||||
|
|
||||||
def onMainWindowCreated(self, window):
|
def addSpacer(self, window, id):
|
||||||
for id in range(1, self.config.spacerCount + 1):
|
spacer = Spacer(id, self.config.spacerMaxWidth)
|
||||||
spacer = Spacer(id, self.config.spacerMaxWidth)
|
self.config.spacerMaxWidthChanged.connect(spacer.setMaximumWidth)
|
||||||
window.navigationBar().addWidget(spacer, spacer.id(), spacer.name())
|
window.navigationBar().addWidget(spacer, spacer.id(), spacer.name())
|
||||||
|
|
||||||
if window not in self.spacers:
|
if window not in self.spacers:
|
||||||
self.spacers[window] = {}
|
self.spacers[window] = {}
|
||||||
|
if id not in self.spacers[window]:
|
||||||
self.spacers[window][id] = spacer
|
self.spacers[window][id] = spacer
|
||||||
|
|
||||||
for id in range(1, self.config.separatorCount + 1):
|
def addSeparator(self, window, id):
|
||||||
separator = Separator(id, self.config.separatorWidth)
|
separator = Separator(id, self.config.separatorWidth)
|
||||||
window.navigationBar().addWidget(separator, separator.id(), separator.name())
|
self.config.separatorWidthChanged.connect(separator.setMinimumWidth)
|
||||||
|
window.navigationBar().addWidget(separator, separator.id(), separator.name())
|
||||||
|
|
||||||
if window not in self.separators:
|
if window not in self.separators:
|
||||||
self.separators[window] = {}
|
self.separators[window] = {}
|
||||||
|
if id not in self.separators[window]:
|
||||||
self.separators[window][id] = separator
|
self.separators[window][id] = separator
|
||||||
|
|
||||||
|
def onSpacerCountChanged(self, count):
|
||||||
|
count = count + 1
|
||||||
|
|
||||||
|
for window in Falkon.MainApplication.instance().windows():
|
||||||
|
if window in self.spacers:
|
||||||
|
lenght = len(self.spacers[window]) + 1
|
||||||
|
|
||||||
|
if count > lenght:
|
||||||
|
for id in range(lenght, count):
|
||||||
|
self.addSpacer(window, id)
|
||||||
|
elif count < lenght:
|
||||||
|
for id in range(count, lenght):
|
||||||
|
if id in self.spacers[window]:
|
||||||
|
window.navigationBar().removeWidget(self.spacers[window][id].id())
|
||||||
|
del self.spacers[window][id]
|
||||||
|
|
||||||
|
def onSeparatorCountChanged(self, count):
|
||||||
|
count = count + 1
|
||||||
|
|
||||||
|
for window in Falkon.MainApplication.instance().windows():
|
||||||
|
if window in self.separators:
|
||||||
|
lenght = len(self.separators[window]) + 1
|
||||||
|
|
||||||
|
if count > lenght:
|
||||||
|
for id in range(lenght, count):
|
||||||
|
self.addSeparator(window, id)
|
||||||
|
elif count < lenght:
|
||||||
|
for id in range(count, lenght):
|
||||||
|
if id in self.separators[window]:
|
||||||
|
window.navigationBar().removeWidget(self.separators[window][id].id())
|
||||||
|
del self.separators[window][id]
|
||||||
|
|
||||||
|
def onMainWindowCreated(self, window):
|
||||||
|
for id in range(1, self.config.spacerCount + 1):
|
||||||
|
self.addSpacer(window, id)
|
||||||
|
|
||||||
|
for id in range(1, self.config.separatorCount + 1):
|
||||||
|
self.addSeparator(window, id)
|
||||||
|
|
||||||
def mainWindowDeleted(self, window):
|
def mainWindowDeleted(self, window):
|
||||||
if window in self.spacers:
|
if window in self.spacers:
|
||||||
for id, spacer in list(self.spacers[window].items()):
|
for id, spacer in list(self.spacers[window].items()):
|
||||||
|
Loading…
Reference in New Issue
Block a user