Zim

I need the start & end's line number of the selection parameters in custom tool

Asked by YPWang

Dear all:
       i hack a version base on revno: 261 that custom tool can be supported new two parameters start & end's line number for selection area. i create a script that will do something for selection word. for example: i want a list order by numbering.
list_1 1. list_1
list_2 ---> 2. list_2
list_3 3. list_3

so, if i know the exact area, i can easy to do the feature.

sorry, i don't know another way to let Maintainer know my patch. so i paste in this question. i am a new if this is impolite behavior. please let me know i have not to do this again.

=== modified file 'zim/gui/applications.py'
--- zim/gui/applications.py 2010-05-30 19:35:24 +0000
+++ zim/gui/applications.py 2010-06-06 11:30:32 +0000
@@ -609,6 +609,15 @@

   if '%D' in cmd:
    cmd[cmd.index('%D')] = notebook.get_document_root() or ''
+ cmd[cmd.index('%D')] = text
+
+ if '%S' in cmd:
+ text = str(pageview.get_start_y_of_setlection())
+ cmd[cmd.index('%S')] = text
+
+ if '%E' in cmd:
+ text = str(pageview.get_end_y_of_setlection())
+ cmd[cmd.index('%E')] = text

   if '%t' in cmd:
    text = pageview.get_selection() or pageview.get_word()

=== modified file 'zim/gui/customtools.py'
--- zim/gui/customtools.py 2010-05-30 19:35:24 +0000
+++ zim/gui/customtools.py 2010-06-06 11:26:55 +0000
@@ -177,6 +177,8 @@
 <b>%n</b> the notebook location (file or folder)
 <b>%D</b> the document root (if any)
 <b>%t</b> the selected text or word under cursor
+<b>%S</b> the start line number of the selection
+<b>%E</b> the end line number of the selection
 </tt>
 ''') ) # T: Short help text in "Edit Custom Tool" dialog. The "%" is literal - please include the html formatting

=== modified file 'zim/gui/pageview.py'
--- zim/gui/pageview.py 2010-05-30 18:33:18 +0000
+++ zim/gui/pageview.py 2010-06-06 11:16:01 +0000
@@ -3144,6 +3144,22 @@
   else:
    return None

+ def get_start_y_of_setlection(self):
+ buffer = self.view.get_buffer()
+ start_y, end_y = buffer.get_selection_bounds()
+ if start_y:
+ return start_y.get_line()
+ else:
+ return None
+
+ def get_end_y_of_setlection(self):
+ buffer = self.view.get_buffer()
+ start_y, end_y = buffer.get_selection_bounds()
+ if end_y:
+ return end_y.get_line()
+ else:
+ return None
+
  def get_word(self):
   buffer = self.view.get_buffer()
   buffer.select_word()

Question information

Language:
English Edit question
Status:
Solved
For:
Zim Edit question
Assignee:
No assignee Edit question
Solved by:
Jaap Karssenberg
Solved:
Last query:
Last reply:
Revision history for this message
Best Jaap Karssenberg (jaap.karssenberg) said :
#1

Please use bug reports to file a patch. Questions are for FAQ like stuff.

One problem I see with this patch is that the pageview line number do
not have to match the line numbers in the source file, so this will go
wrong in many cases.

I think the only way to get this right is to do it with a plugin.

Regards,

Jaap

Revision history for this message
YPWang (blue119) said :
#2

Thanks Jaap Karssenberg, that solved my question.