Skip to content

Commit

Permalink
Add a Select sub menu with 5 options to select pages
Browse files Browse the repository at this point in the history
  • Loading branch information
kbengs authored and jeromerobert committed Aug 7, 2020
1 parent 1c37fb8 commit 65c564d
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 1 deletion.
62 changes: 62 additions & 0 deletions data/menu.ui
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,36 @@ along with PDF-Arranger. If not, see <http://www.gnu.org/licenses/>.
</item>
</section>
</submenu>
<submenu>
<attribute name="label" translatable="yes">_Select</attribute>
<section>
<item>
<attribute name="label" translatable="yes">Select _All</attribute>
<attribute name="action">win.select</attribute>
<attribute name="target" type="i">0</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Deselect All</attribute>
<attribute name="action">win.select</attribute>
<attribute name="target" type="i">1</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Select _Odd Pages</attribute>
<attribute name="action">win.select</attribute>
<attribute name="target" type="i">2</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Select _Even Pages</attribute>
<attribute name="action">win.select</attribute>
<attribute name="target" type="i">3</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Invert Selection</attribute>
<attribute name="action">win.select</attribute>
<attribute name="target" type="i">4</attribute>
</item>
</section>
</submenu>
<section>
<item>
<attribute name="label" translatable="yes">Zoom _In</attribute>
Expand Down Expand Up @@ -185,6 +215,38 @@ along with PDF-Arranger. If not, see <http://www.gnu.org/licenses/>.
</section>
</submenu>
</section>
<section>
<submenu>
<attribute name="label" translatable="yes">_Select</attribute>
<section>
<item>
<attribute name="label" translatable="yes">Select _All</attribute>
<attribute name="action">win.select</attribute>
<attribute name="target" type="i">0</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Deselect All</attribute>
<attribute name="action">win.select</attribute>
<attribute name="target" type="i">1</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Select _Odd Pages</attribute>
<attribute name="action">win.select</attribute>
<attribute name="target" type="i">2</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Select _Even Pages</attribute>
<attribute name="action">win.select</attribute>
<attribute name="target" type="i">3</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Invert Selection</attribute>
<attribute name="action">win.select</attribute>
<attribute name="target" type="i">4</attribute>
</item>
</section>
</submenu>
</section>
<section>
<item>
<attribute name="label" translatable="yes">Rotate _Left</attribute>
Expand Down
35 changes: 34 additions & 1 deletion pdfarranger/pdfarranger.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ def __create_actions(self):
('cut', self.on_action_cut),
('copy', self.on_action_copy),
('paste', self.on_action_paste, 'i'),
('select', self.on_action_select, 'i'),
('about', self.about_dialog),
])

Expand All @@ -373,6 +374,8 @@ def __create_actions(self):
('copy', '<Ctrl>c'),
('paste(0)', '<Ctrl>v'),
('paste(1)', '<Ctrl><Shift>v'),
('select(0)', '<Ctrl>a'),
('select(1)', '<Ctrl><Shift>a'),
('main-menu', 'F10'),
]
for a, k in accels:
Expand Down Expand Up @@ -1112,6 +1115,36 @@ def set_paste_location(self, pastemode, data_is_filepaths):
ref_to = Gtk.TreeRowReference.new(model, selection[0])
return ref_to, before

def on_action_select(self, _action, option, _unknown):
"""Selects items according to selected option."""
selectoptions = {0: 'ALL', 1: 'DESELECT', 2: 'ODD', 3: 'EVEN', 4: 'INVERT'}
selectoption = selectoptions[option.get_int32()]
model = self.iconview.get_model()
if selectoption == 'ALL':
self.iconview.select_all()
elif selectoption == 'DESELECT':
self.iconview.unselect_all()
elif selectoption == 'ODD':
for row in model:
page_number = row[3]
if page_number % 2:
self.iconview.select_path(row.path)
else:
self.iconview.unselect_path(row.path)
elif selectoption == 'EVEN':
for row in model:
page_number = row[3]
if page_number % 2:
self.iconview.unselect_path(row.path)
else:
self.iconview.select_path(row.path)
elif selectoption == 'INVERT':
for row in model:
if self.iconview.path_is_selected(row.path):
self.iconview.unselect_path(row.path)
else:
self.iconview.select_path(row.path)

@staticmethod
def iv_drag_begin(iconview, context):
"""Sets custom drag icon."""
Expand Down Expand Up @@ -1657,7 +1690,7 @@ def reset_export_file(self, model, _path, _itr=None, _user_data=None):
def __update_num_pages(self, model, _path=None, _itr=None, _user_data=None):
num_pages = len(model)
self.uiXML.get_object("num_pages").set_text(str(num_pages))
for a in ["save", "save-as"]:
for a in ["save", "save-as", "select"]:
self.window.lookup_action(a).set_enabled(num_pages > 0)

def error_message_dialog(self, msg, msg_type=Gtk.MessageType.ERROR):
Expand Down

0 comments on commit 65c564d

Please sign in to comment.