Skip to content

Commit

Permalink
[pyqgis-console] add save button to history dialog, minor fixes for c…
Browse files Browse the repository at this point in the history
…38b8cb
  • Loading branch information
slarosa committed Nov 2, 2013
1 parent 169f646 commit a411e79
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
31 changes: 22 additions & 9 deletions python/console/console_history_dlg.ui
Expand Up @@ -29,7 +29,7 @@
<property name="horizontalSpacing">
<number>6</number>
</property>
<item row="2" column="1">
<item row="2" column="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
Expand All @@ -39,14 +39,7 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QPushButton" name="reloadHistory">
<property name="text">
<string>Reload</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<item row="0" column="0" colspan="3">
<widget class="QListView" name="listView">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
Expand All @@ -60,6 +53,26 @@
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QPushButton" name="reloadHistory">
<property name="text">
<string>Reload</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="saveHistory">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
</layout>
Expand Down
17 changes: 11 additions & 6 deletions python/console/console_sci.py
Expand Up @@ -633,11 +633,15 @@ def __init__(self, parent):
self.deleteScut.activated.connect(self._deleteItem)
self.listView.doubleClicked.connect(self._runHistory)
self.reloadHistory.clicked.connect(self._reloadHistory)
self.saveHistory.clicked.connect(self._saveHistory)

def _runHistory(self, item):
cmd = item.data(Qt.DisplayRole)
self.parent.runCommand(unicode(cmd))

def _saveHistory(self):
self.parent.writeHistoryFile(True)

def _reloadHistory(self):
self.model.clear()
for i in self.parent.history:
Expand All @@ -651,9 +655,10 @@ def _reloadHistory(self):

def _deleteItem(self):
itemsSelected = self.listView.selectionModel().selectedIndexes()
item = itemsSelected[0].row()
## Remove item from the command history (just for the current session)
self.parent.history.pop(item)
self.parent.historyIndex -= 1
## Remove row from the command history dialog
self.model.removeRow(item)
if itemsSelected:
item = itemsSelected[0].row()
## Remove item from the command history (just for the current session)
self.parent.history.pop(item)
self.parent.historyIndex -= 1
## Remove row from the command history dialog
self.model.removeRow(item)

0 comments on commit a411e79

Please sign in to comment.