On Feb 6, 3:36 pm, yin sun <[email protected]> wrote:
> try this patch,
I tried that patch, but I noticed two issues:
* If you close all tabs, the editor won't automatically open a new tab
for you. In itself it's not a big issue, however UliPad won't open any
files unless you have at least one open tab;
* If you have more than one open tab, and you close the first tab, the
file name on UliPad's window bar is not updated.
So I played some more with the code in mixins/EditorFactory.py, and
came up with the following patch (UNIX diff format):
172c172,175
< if index < 0 or index > len(self.getDocuments()):
---
> documents = self.getDocuments()
> if 0 <= index and index < len(documents):
> return documents[index]
> else:
174d176
< return self.getDocuments()[index]
352,361c355,359
< # if index >= len(self.getDocuments()):
< # index = len(self.getDocuments())-1
< # if index >= 0:
< # self.switch(self.getDoc(index))
< # else:
< # self.new()
< # self.document.SetFocus()
< #if the page to close is not selected, no need to switch page
< if index == selected:
< if index > 0:
---
> # If there are no pages left, create one
> if len(self.getDocuments()) == 0:
> self.new()
> # No need to switch pages if the closed page was not selected
> elif index == selected:
364d361
< # only swith page when there is a page to switch to
366,367c364
< else:
< self.new()
---
> # Whatever the case, set focus to the selected page
Alternatively, below is the complete code for the affected methods,
with changes already applied:
def getDoc(self, index):
documents = self.getDocuments()
if 0 <= index and index < len(documents):
return documents[index]
else:
return None
# ...
def closefile(self, document):
try:
index = self.getIndex(document)
except:
return
self.callplugin('beforeclosefile', self, document)
selected = self.GetSelection()
self.skip_closing = True
self.skip_page_change = True
self.DeletePage(index)
# If there are no pages left, create one
if len(self.getDocuments()) == 0:
self.new()
# No need to switch pages if the closed page was not selected
elif index == selected:
if index >= len(self.getDocuments()):
index = len(self.getDocuments()) - 1
self.switch(self.getDoc(index))
# Whatever the case, set focus to the selected page
self.document.SetFocus()
self.callplugin('afterclosefile', self)
It's relatively simple to open mixins/EditorFactory.py in a plain-text
editor, locate the methods above and copy/paste the updated code. You
can even use UliPad itself to apply the changes; just restart it after
saving the file.
--
Ja ne,
Helio Perroni Filho
https://www.google.com/profiles/xperroni