PICARD-1695: Make scripts sortable by drag and drop

This commit is contained in:
Philipp Wolfer
2019-12-17 15:48:51 +01:00
parent 500622851e
commit b1a8fbb2b5
3 changed files with 4 additions and 59 deletions

View File

@@ -33,6 +33,7 @@ from picard.script import ScriptParser
from picard.util import restore_method
from picard.ui import HashableListWidgetItem
from picard.ui.moveable_list_view import MoveableListView
from picard.ui.options import (
OptionsCheckError,
OptionsPage,
@@ -170,6 +171,8 @@ class ScriptingOptionsPage(OptionsPage):
font = QtGui.QFont('Monospace')
font.setStyleHint(QtGui.QFont.TypeWriter)
self.ui.tagger_script.setFont(font)
self.move_view = MoveableListView(self.ui.script_list, self.ui.move_up_button,
self.ui.move_down_button)
def delete_selected_script(self):
indexes = self.ui.script_list.selectedIndexes()
@@ -181,24 +184,6 @@ class ScriptingOptionsPage(OptionsPage):
if items:
self.rename_script(items[0])
def move_selected_script_up(self):
indexes = self.ui.script_list.selectedIndexes()
if indexes:
row = indexes[0].row()
self.move_script(row, 1)
new_index = self.ui.script_list.model().index(row - 1, 0)
selection = self.ui.script_list.selectionModel()
selection.select(new_index, QtCore.QItemSelectionModel.Clear | QtCore.QItemSelectionModel.SelectCurrent)
def move_selected_script_down(self):
indexes = self.ui.script_list.selectedIndexes()
if indexes:
row = indexes[0].row()
self.move_script(row, -1)
new_index = self.ui.script_list.model().index(row + 1, 0)
selection = self.ui.script_list.selectionModel()
selection.select(new_index, QtCore.QItemSelectionModel.Clear | QtCore.QItemSelectionModel.SelectCurrent)
def script_name_changed(self):
items = self.ui.script_list.selectedItems()
if items:
@@ -259,13 +244,6 @@ class ScriptingOptionsPage(OptionsPage):
elif row < self.last_selected_script_pos:
self.last_selected_script_pos -= 1
def move_script(self, row, step):
item1 = self.ui.script_list.item(row)
item2 = self.ui.script_list.item(row - step)
if item1 and item2:
list_item = self.ui.script_list.takeItem(row)
self.ui.script_list.insertItem(row - step, list_item)
def live_update_and_check(self):
items = self.ui.script_list.selectedItems()
if items:
@@ -304,6 +282,7 @@ class ScriptingOptionsPage(OptionsPage):
self.last_selected_script_pos = config.persist["last_selected_script_pos"]
last_selected_script = self.ui.script_list.item(self.last_selected_script_pos)
if last_selected_script:
self.ui.script_list.setCurrentItem(last_selected_script)
last_selected_script.setSelected(True)
self.restore_state()

View File

@@ -99,8 +99,6 @@ class Ui_ScriptingOptionsPage(object):
self.script_list.itemSelectionChanged.connect(ScriptingOptionsPage.script_selected)
self.remove_button.clicked.connect(ScriptingOptionsPage.delete_selected_script)
self.rename_button.clicked.connect(ScriptingOptionsPage.rename_selected_script)
self.move_up_button.clicked.connect(ScriptingOptionsPage.move_selected_script_up)
self.move_down_button.clicked.connect(ScriptingOptionsPage.move_selected_script_down)
QtCore.QMetaObject.connectSlotsByName(ScriptingOptionsPage)
ScriptingOptionsPage.setTabOrder(self.enable_tagger_scripts, self.add_button)
ScriptingOptionsPage.setTabOrder(self.add_button, self.script_list)

View File

@@ -295,38 +295,6 @@
</hint>
</hints>
</connection>
<connection>
<sender>move_up_button</sender>
<signal>clicked()</signal>
<receiver>ScriptingOptionsPage</receiver>
<slot>move_selected_script_up()</slot>
<hints>
<hint type="sourcelabel">
<x>428</x>
<y>475</y>
</hint>
<hint type="destinationlabel">
<x>302</x>
<y>275</y>
</hint>
</hints>
</connection>
<connection>
<sender>move_down_button</sender>
<signal>clicked()</signal>
<receiver>ScriptingOptionsPage</receiver>
<slot>move_selected_script_down()</slot>
<hints>
<hint type="sourcelabel">
<x>464</x>
<y>475</y>
</hint>
<hint type="destinationlabel">
<x>302</x>
<y>275</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>add_script()</slot>