2021-11-17 03:41:24 +00:00
|
|
|
# Python imports
|
|
|
|
import copy
|
2022-04-03 04:23:33 +00:00
|
|
|
import traceback
|
|
|
|
from os.path import isdir
|
2021-11-17 03:41:24 +00:00
|
|
|
|
2021-12-07 04:44:39 +00:00
|
|
|
# Lib imports
|
2021-11-17 03:41:24 +00:00
|
|
|
import gi
|
2022-12-09 05:33:04 +00:00
|
|
|
gi.require_version('Gtk', '3.0')
|
2021-12-07 04:44:39 +00:00
|
|
|
gi.require_version('Gdk', '3.0')
|
2022-12-09 05:33:04 +00:00
|
|
|
from gi.repository import Gtk
|
2022-11-29 04:34:13 +00:00
|
|
|
from gi.repository import Gdk
|
|
|
|
from gi.repository import Gio
|
2021-11-17 03:41:24 +00:00
|
|
|
|
|
|
|
# Application imports
|
2022-02-20 07:32:51 +00:00
|
|
|
from .tab_mixin import TabMixin
|
2021-11-17 03:41:24 +00:00
|
|
|
|
2021-10-10 06:45:55 +00:00
|
|
|
|
2022-10-02 03:12:14 +00:00
|
|
|
class WindowException(Exception):
|
|
|
|
...
|
|
|
|
|
|
|
|
|
2021-10-10 06:45:55 +00:00
|
|
|
class WindowMixin(TabMixin):
|
|
|
|
"""docstring for WindowMixin"""
|
2022-02-20 07:32:51 +00:00
|
|
|
|
2021-11-17 03:41:24 +00:00
|
|
|
def get_fm_window(self, wid):
|
2022-02-25 23:58:11 +00:00
|
|
|
return self.fm_controller.get_window_by_nickname(f"window_{wid}")
|
2021-11-17 03:41:24 +00:00
|
|
|
|
2022-02-25 23:58:11 +00:00
|
|
|
def set_bottom_labels(self, tab):
|
2023-03-05 03:45:29 +00:00
|
|
|
event_system.emit("set_bottom_labels", (tab,))
|
2021-11-28 04:03:00 +00:00
|
|
|
|
2021-11-17 03:41:24 +00:00
|
|
|
def set_window_title(self):
|
2022-02-25 23:58:11 +00:00
|
|
|
wid, tid = self.fm_controller.get_active_wid_and_tid()
|
2021-11-28 21:16:21 +00:00
|
|
|
notebook = self.builder.get_object(f"window_{wid}")
|
2022-02-25 23:58:11 +00:00
|
|
|
tab = self.get_fm_window(wid).get_tab_by_id(tid)
|
|
|
|
dir = tab.get_current_directory()
|
2021-11-28 21:16:21 +00:00
|
|
|
|
|
|
|
for _notebook in self.notebooks:
|
2021-12-05 00:23:00 +00:00
|
|
|
ctx = _notebook.get_style_context()
|
2021-11-28 21:16:21 +00:00
|
|
|
ctx.remove_class("notebook-selected-focus")
|
2021-12-07 01:38:59 +00:00
|
|
|
ctx.add_class("notebook-unselected-focus")
|
2021-11-28 21:16:21 +00:00
|
|
|
|
2021-12-05 00:23:00 +00:00
|
|
|
ctx = notebook.get_style_context()
|
2021-12-07 01:38:59 +00:00
|
|
|
ctx.remove_class("notebook-unselected-focus")
|
2021-11-28 21:16:21 +00:00
|
|
|
ctx.add_class("notebook-selected-focus")
|
|
|
|
|
2022-09-03 22:01:41 +00:00
|
|
|
self.window.set_title(f"{app_name} ~ {dir}")
|
2022-02-25 23:58:11 +00:00
|
|
|
self.set_bottom_labels(tab)
|
2021-11-17 03:41:24 +00:00
|
|
|
|
|
|
|
def set_path_text(self, wid, tid):
|
|
|
|
path_entry = self.builder.get_object("path_entry")
|
2022-02-25 23:58:11 +00:00
|
|
|
tab = self.get_fm_window(wid).get_tab_by_id(tid)
|
|
|
|
path_entry.set_text(tab.get_current_directory())
|
2021-11-17 03:41:24 +00:00
|
|
|
|
2022-02-25 23:58:11 +00:00
|
|
|
def grid_set_selected_items(self, icons_grid):
|
2022-12-09 05:33:04 +00:00
|
|
|
new_items = icons_grid.get_selected_items()
|
|
|
|
items_size = len(new_items)
|
|
|
|
selected_items = event_system.emit_and_await("get_selected_files")
|
2022-11-26 20:44:38 +00:00
|
|
|
|
2022-12-09 05:33:04 +00:00
|
|
|
if items_size == 1:
|
2022-11-26 20:44:38 +00:00
|
|
|
# NOTE: If already in selection, likely dnd else not so wont readd
|
2022-12-09 05:33:04 +00:00
|
|
|
if new_items[0] in selected_items:
|
2022-11-26 20:44:38 +00:00
|
|
|
self.dnd_left_primed += 1
|
|
|
|
# NOTE: If in selection but trying to just select an already selected item.
|
|
|
|
if self.dnd_left_primed > 1:
|
|
|
|
self.dnd_left_primed = 0
|
2022-12-09 05:33:04 +00:00
|
|
|
selected_items.clear()
|
2022-11-26 20:44:38 +00:00
|
|
|
|
|
|
|
# NOTE: Likely trying dnd, just readd to selection the former set.
|
|
|
|
# Prevents losing highlighting of grid selected.
|
2022-12-09 05:33:04 +00:00
|
|
|
for path in selected_items:
|
2022-11-26 20:44:38 +00:00
|
|
|
icons_grid.select_path(path)
|
|
|
|
|
2022-12-09 05:33:04 +00:00
|
|
|
if items_size > 0:
|
|
|
|
event_system.emit("set_selected_files", (new_items,))
|
2022-11-26 22:06:39 +00:00
|
|
|
else:
|
|
|
|
self.dnd_left_primed = 0
|
2022-12-09 05:33:04 +00:00
|
|
|
selected_items.clear()
|
2021-11-21 20:50:32 +00:00
|
|
|
|
2022-02-25 23:58:11 +00:00
|
|
|
def grid_icon_single_click(self, icons_grid, eve):
|
2021-11-17 03:41:24 +00:00
|
|
|
try:
|
2022-12-04 08:45:26 +00:00
|
|
|
event_system.emit("hide_path_menu")
|
2022-02-25 23:58:11 +00:00
|
|
|
wid, tid = icons_grid.get_name().split("|")
|
2022-03-08 01:18:55 +00:00
|
|
|
self.fm_controller.set_wid_and_tid(wid, tid)
|
2021-11-22 22:24:44 +00:00
|
|
|
self.set_path_text(wid, tid)
|
|
|
|
self.set_window_title()
|
2021-11-17 03:41:24 +00:00
|
|
|
|
|
|
|
if eve.type == Gdk.EventType.BUTTON_RELEASE and eve.button == 1: # l-click
|
2022-11-26 20:44:38 +00:00
|
|
|
if self.ctrl_down:
|
|
|
|
self.dnd_left_primed = 0
|
|
|
|
|
2021-11-17 03:41:24 +00:00
|
|
|
if self.single_click_open: # FIXME: need to find a way to pass the model index
|
2022-02-25 23:58:11 +00:00
|
|
|
self.grid_icon_double_click(icons_grid)
|
2021-11-17 03:41:24 +00:00
|
|
|
elif eve.type == Gdk.EventType.BUTTON_RELEASE and eve.button == 3: # r-click
|
2022-12-04 04:03:05 +00:00
|
|
|
event_system.emit("show_context_menu")
|
2021-11-17 03:41:24 +00:00
|
|
|
|
2022-10-02 03:12:14 +00:00
|
|
|
except WindowException as e:
|
2023-02-24 05:03:29 +00:00
|
|
|
logger.info(repr(e))
|
2022-12-07 00:41:52 +00:00
|
|
|
self.display_message(settings.get_error_color(), f"{repr(e)}")
|
2021-11-17 03:41:24 +00:00
|
|
|
|
2022-02-25 23:58:11 +00:00
|
|
|
def grid_icon_double_click(self, icons_grid, item, data=None):
|
2021-11-17 03:41:24 +00:00
|
|
|
try:
|
2022-02-25 23:58:11 +00:00
|
|
|
if self.ctrl_down and self.shift_down:
|
2022-02-15 03:12:07 +00:00
|
|
|
self.unset_keys_and_data()
|
2021-12-02 01:22:03 +00:00
|
|
|
self.execute_files(in_terminal=True)
|
|
|
|
return
|
2022-02-25 23:58:11 +00:00
|
|
|
elif self.ctrl_down:
|
2022-02-15 03:12:07 +00:00
|
|
|
self.unset_keys_and_data()
|
2021-12-02 01:22:03 +00:00
|
|
|
self.execute_files()
|
|
|
|
return
|
|
|
|
|
2021-12-07 01:38:59 +00:00
|
|
|
|
2022-03-07 03:27:47 +00:00
|
|
|
state = self.get_current_state()
|
|
|
|
notebook = self.builder.get_object(f"window_{state.wid}")
|
2022-02-25 23:58:11 +00:00
|
|
|
tab_label = self.get_tab_label(notebook, icons_grid)
|
2021-11-17 03:41:24 +00:00
|
|
|
|
2022-03-07 03:27:47 +00:00
|
|
|
fileName = state.store[item][1]
|
|
|
|
dir = state.tab.get_current_directory()
|
2021-12-26 06:32:45 +00:00
|
|
|
file = f"{dir}/{fileName}"
|
2021-11-17 03:41:24 +00:00
|
|
|
|
2021-12-25 09:20:39 +00:00
|
|
|
if isdir(file):
|
2022-03-07 03:27:47 +00:00
|
|
|
state.tab.set_path(file)
|
|
|
|
self.update_tab(tab_label, state.tab, state.store, state.wid, state.tid)
|
2021-11-30 06:21:50 +00:00
|
|
|
else:
|
2022-12-07 05:36:10 +00:00
|
|
|
event_system.emit("open_files")
|
2022-10-02 03:12:14 +00:00
|
|
|
except WindowException as e:
|
2022-04-03 04:23:33 +00:00
|
|
|
traceback.print_exc()
|
2022-12-07 00:41:52 +00:00
|
|
|
self.display_message(settings.get_error_color(), f"{repr(e)}")
|
2021-11-17 03:41:24 +00:00
|
|
|
|
2021-11-21 03:00:34 +00:00
|
|
|
|
|
|
|
|
2022-02-25 23:58:11 +00:00
|
|
|
def grid_on_drag_set(self, icons_grid, drag_context, data, info, time):
|
|
|
|
action = icons_grid.get_name()
|
2021-11-21 20:50:32 +00:00
|
|
|
wid, tid = action.split("|")
|
2022-02-25 23:58:11 +00:00
|
|
|
store = icons_grid.get_model()
|
|
|
|
treePaths = icons_grid.get_selected_items()
|
2021-12-27 23:27:57 +00:00
|
|
|
# NOTE: Need URIs as URI format for DnD to work. Will strip 'file://'
|
2022-12-09 05:33:04 +00:00
|
|
|
# further down call chain when doing internal fm stuff.
|
2021-12-27 23:27:57 +00:00
|
|
|
uris = self.format_to_uris(store, wid, tid, treePaths)
|
2021-12-27 06:33:30 +00:00
|
|
|
uris_text = '\n'.join(uris)
|
2021-11-17 03:41:24 +00:00
|
|
|
|
|
|
|
data.set_uris(uris)
|
2021-12-27 06:33:30 +00:00
|
|
|
data.set_text(uris_text, -1)
|
2021-11-17 03:41:24 +00:00
|
|
|
|
2022-02-25 23:58:11 +00:00
|
|
|
def grid_on_drag_motion(self, icons_grid, drag_context, x, y, data):
|
2022-12-03 04:10:41 +00:00
|
|
|
current = '|'.join(self.fm_controller.get_active_wid_and_tid())
|
|
|
|
target = icons_grid.get_name()
|
|
|
|
wid, tid = target.split("|")
|
|
|
|
store = icons_grid.get_model()
|
|
|
|
path_at_loc = None
|
2022-01-30 00:18:21 +00:00
|
|
|
|
2022-12-03 04:10:41 +00:00
|
|
|
try:
|
2023-04-30 23:43:12 +00:00
|
|
|
data = icons_grid.get_dest_item_at_pos(x, y)
|
|
|
|
path_at_loc = data[0]
|
|
|
|
drop_position = data[1]
|
2022-12-03 04:10:41 +00:00
|
|
|
highlighted_item_path = icons_grid.get_drag_dest_item().path
|
2023-04-30 23:43:12 +00:00
|
|
|
if path_at_loc and path_at_loc == highlighted_item_path and drop_position == Gtk.IconViewDropPosition.DROP_INTO:
|
2022-12-03 04:10:41 +00:00
|
|
|
uri = self.format_to_uris(store, wid, tid, highlighted_item_path)[0].replace("file://", "")
|
|
|
|
self.override_drop_dest = uri if isdir(uri) else None
|
2023-04-30 23:43:12 +00:00
|
|
|
else:
|
|
|
|
self.override_drop_dest = None
|
2022-12-03 04:10:41 +00:00
|
|
|
except Exception as e:
|
2023-04-30 23:43:12 +00:00
|
|
|
self.override_drop_dest = None
|
2022-01-30 00:18:21 +00:00
|
|
|
|
|
|
|
if target not in current:
|
2022-03-08 01:18:55 +00:00
|
|
|
self.fm_controller.set_wid_and_tid(wid, tid)
|
2022-01-30 00:18:21 +00:00
|
|
|
|
2021-11-17 03:41:24 +00:00
|
|
|
|
|
|
|
def grid_on_drag_data_received(self, widget, drag_context, x, y, data, info, time):
|
|
|
|
if info == 80:
|
2022-12-09 05:33:04 +00:00
|
|
|
uris = data.get_uris()
|
|
|
|
state = event_system.emit_and_await("get_current_state")
|
|
|
|
dest = f"{state.tab.get_current_directory()}" if not self.override_drop_dest else self.override_drop_dest
|
2022-01-29 22:47:42 +00:00
|
|
|
if len(uris) == 0:
|
2021-12-27 06:33:30 +00:00
|
|
|
uris = data.get_text().split("\n")
|
2022-01-29 22:47:42 +00:00
|
|
|
|
|
|
|
from_uri = '/'.join(uris[0].replace("file://", "").split("/")[:-1])
|
|
|
|
if from_uri != dest:
|
2022-12-07 05:36:10 +00:00
|
|
|
event_system.emit("move_files", (uris, dest))
|
2021-11-17 03:41:24 +00:00
|
|
|
|
2022-01-29 22:47:42 +00:00
|
|
|
|
2022-02-25 23:58:11 +00:00
|
|
|
def create_new_tab_notebook(self, widget=None, wid=None, path=None):
|
2022-03-13 22:32:37 +00:00
|
|
|
self.create_tab(wid, None, path)
|