import refactoring
This commit is contained in:
parent
3ccd9815ef
commit
81af05c9f6
|
@ -8,12 +8,12 @@ def main():
|
|||
# Create "File Window" 1
|
||||
window = window_controller.create_window()
|
||||
window.set_nickname("Win1")
|
||||
window_controller.add_view_for_window_by_nickname(window.get_nickname())
|
||||
window_controller.add_tab_for_window_by_nickname(window.get_nickname())
|
||||
|
||||
# Create "File Window" 2
|
||||
window2 = window_controller.create_window()
|
||||
window2.set_nickname("Win2")
|
||||
window_controller.add_view_for_window_by_nickname(window2.get_nickname())
|
||||
window_controller.add_tab_for_window_by_nickname(window2.get_nickname())
|
||||
|
||||
window_controller.list_windows()
|
||||
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
from shellfm.windows.controller import WindowController
|
||||
|
||||
|
||||
def main():
|
||||
print("\n\n-------------------------------------------\n\n")
|
||||
window_controller = WindowController()
|
||||
|
||||
# Create "File Window" 1
|
||||
window = window_controller.create_window()
|
||||
window.set_nickname("Win1")
|
||||
window_controller.add_tab_for_window_by_nickname(window.get_nickname())
|
||||
|
||||
# Create "File Window" 2
|
||||
window2 = window_controller.create_window()
|
||||
window2.set_nickname("Win2")
|
||||
window_controller.add_tab_for_window_by_nickname(window2.get_nickname())
|
||||
|
||||
window_controller.list_windows()
|
||||
|
||||
|
||||
print("\n\n-------------------------------------------\n\n")
|
||||
window2.set_is_hidden(True)
|
||||
window_controller.list_windows()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -40,20 +40,20 @@ class WindowController:
|
|||
return window
|
||||
|
||||
|
||||
def add_view_for_window(self, win_id):
|
||||
def add_tab_for_window(self, win_id):
|
||||
for window in self._windows:
|
||||
if window.get_id() == win_id:
|
||||
return window.create_view()
|
||||
return window.create_tab()
|
||||
|
||||
def add_view_for_window_by_name(self, name):
|
||||
def add_tab_for_window_by_name(self, name):
|
||||
for window in self._windows:
|
||||
if window.get_name() == name:
|
||||
return window.create_view()
|
||||
return window.create_tab()
|
||||
|
||||
def add_view_for_window_by_nickname(self, nickname):
|
||||
def add_tab_for_window_by_nickname(self, nickname):
|
||||
for window in self._windows:
|
||||
if window.get_nickname() == nickname:
|
||||
return window.create_view()
|
||||
return window.create_tab()
|
||||
|
||||
def pop_window(self):
|
||||
self._windows.pop()
|
||||
|
@ -116,33 +116,33 @@ class WindowController:
|
|||
print(f"Name: {window.get_name()}")
|
||||
print(f"Nickname: {window.get_nickname()}")
|
||||
print(f"Is Hidden: {window.is_hidden()}")
|
||||
print(f"View Count: {window.get_views_count()}")
|
||||
print(f"Tab Count: {window.get_tabs_count()}")
|
||||
print("\n-------------------------\n")
|
||||
|
||||
|
||||
|
||||
def list_files_from_views_of_window(self, win_id):
|
||||
def list_files_from_tabs_of_window(self, win_id):
|
||||
for window in self._windows:
|
||||
if window.get_id() == win_id:
|
||||
window.list_files_from_views()
|
||||
window.list_files_from_tabs()
|
||||
break
|
||||
|
||||
def get_views_count(self, win_id):
|
||||
def get_tabs_count(self, win_id):
|
||||
for window in self._windows:
|
||||
if window.get_id() == win_id:
|
||||
return window.get_views_count()
|
||||
return window.get_tabs_count()
|
||||
|
||||
def get_views_from_window(self, win_id):
|
||||
def get_tabs_from_window(self, win_id):
|
||||
for window in self._windows:
|
||||
if window.get_id() == win_id:
|
||||
return window.get_all_views()
|
||||
return window.get_all_tabs()
|
||||
|
||||
|
||||
|
||||
|
||||
def unload_views_and_windows(self):
|
||||
def unload_tabs_and_windows(self):
|
||||
for window in self._windows:
|
||||
window.get_all_views().clear()
|
||||
window.get_all_tabs().clear()
|
||||
|
||||
self._windows.clear()
|
||||
|
||||
|
@ -153,9 +153,9 @@ class WindowController:
|
|||
if len(self._windows) > 0:
|
||||
windows = []
|
||||
for window in self._windows:
|
||||
views = []
|
||||
for view in window.get_all_views():
|
||||
views.append(view.get_current_directory())
|
||||
tabs = []
|
||||
for tab in window.get_all_tabs():
|
||||
tabs.append(tab.get_current_directory())
|
||||
|
||||
windows.append(
|
||||
[
|
||||
|
@ -165,7 +165,7 @@ class WindowController:
|
|||
"Name": window.get_name(),
|
||||
"Nickname": window.get_nickname(),
|
||||
"isHidden": f"{window.is_hidden()}",
|
||||
'views': views
|
||||
'tabs': tabs
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
@ -18,7 +18,7 @@ from .icons.icon import Icon
|
|||
from .path import Path
|
||||
|
||||
|
||||
class View(Settings, FileHandler, Launcher, Icon, Path):
|
||||
class Tab(Settings, FileHandler, Launcher, Icon, Path):
|
||||
def __init__(self):
|
||||
self.logger = None
|
||||
self._id_length = 10
|
|
@ -6,7 +6,7 @@ from random import randint
|
|||
|
||||
|
||||
# Application imports
|
||||
from .views.view import View
|
||||
from .tabs.tab import Tab
|
||||
|
||||
|
||||
class Window:
|
||||
|
@ -16,45 +16,40 @@ class Window:
|
|||
self._name = ""
|
||||
self._nickname = ""
|
||||
self._isHidden = False
|
||||
self._views = []
|
||||
self._tabs = []
|
||||
|
||||
self._generate_id()
|
||||
self._set_name()
|
||||
|
||||
|
||||
def create_view(self):
|
||||
view = View()
|
||||
self._views.append(view)
|
||||
return view
|
||||
def create_tab(self):
|
||||
tab = Tab()
|
||||
self._tabs.append(tab)
|
||||
return tab
|
||||
|
||||
def pop_view(self):
|
||||
self._views.pop()
|
||||
def pop_tab(self):
|
||||
self._tabs.pop()
|
||||
|
||||
def delete_view_by_id(self, vid):
|
||||
for view in self._views:
|
||||
if view.get_id() == vid:
|
||||
self._views.remove(view)
|
||||
def delete_tab_by_id(self, vid):
|
||||
for tab in self._tabs:
|
||||
if tab.get_id() == vid:
|
||||
self._tabs.remove(tab)
|
||||
break
|
||||
|
||||
|
||||
def get_view_by_id(self, vid):
|
||||
for view in self._views:
|
||||
if view.get_id() == vid:
|
||||
return view
|
||||
def get_tab_by_id(self, vid):
|
||||
for tab in self._tabs:
|
||||
if tab.get_id() == vid:
|
||||
return tab
|
||||
|
||||
def get_view_by_index(self, index):
|
||||
return self._views[index]
|
||||
def get_tab_by_index(self, index):
|
||||
return self._tabs[index]
|
||||
|
||||
def get_views_count(self):
|
||||
return len(self._views)
|
||||
|
||||
def get_all_views(self):
|
||||
return self._views
|
||||
|
||||
def list_files_from_views(self):
|
||||
for view in self._views:
|
||||
print(view.get_files())
|
||||
def get_tabs_count(self):
|
||||
return len(self._tabs)
|
||||
|
||||
def get_all_tabs(self):
|
||||
return self._tabs
|
||||
|
||||
def get_id(self):
|
||||
return self._id
|
||||
|
@ -68,7 +63,9 @@ class Window:
|
|||
def is_hidden(self):
|
||||
return self._isHidden
|
||||
|
||||
|
||||
def list_files_from_tabs(self):
|
||||
for tab in self._tabs:
|
||||
print(tab.get_files())
|
||||
|
||||
|
||||
def set_nickname(self, nickname):
|
||||
|
@ -80,6 +77,7 @@ class Window:
|
|||
def _set_name(self):
|
||||
self._name = "window_" + self.get_id()
|
||||
|
||||
|
||||
def _random_with_N_digits(self, n):
|
||||
range_start = 10**(n-1)
|
||||
range_end = (10**n)-1
|
||||
|
|
Loading…
Reference in New Issue