Changeset View
Changeset View
Standalone View
Standalone View
src/ViewManager.h
Show All 15 Lines | 1 | /* | |||
---|---|---|---|---|---|
16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
17 | 02110-1301 USA. | 17 | 02110-1301 USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #ifndef VIEWMANAGER_H | 20 | #ifndef VIEWMANAGER_H | ||
21 | #define VIEWMANAGER_H | 21 | #define VIEWMANAGER_H | ||
22 | 22 | | |||
23 | // Qt | 23 | // Qt | ||
24 | #include <QAction> | ||||
24 | #include <QHash> | 25 | #include <QHash> | ||
25 | #include <QObject> | 26 | #include <QObject> | ||
26 | #include <QPointer> | 27 | #include <QPointer> | ||
27 | 28 | | |||
28 | // Konsole | 29 | // Konsole | ||
29 | #include "Profile.h" | 30 | #include "Profile.h" | ||
30 | 31 | | |||
31 | class KActionCollection; | 32 | class KActionCollection; | ||
32 | class KConfigGroup; | 33 | class KConfigGroup; | ||
33 | 34 | | |||
34 | namespace Konsole { | 35 | namespace Konsole { | ||
35 | class ColorScheme; | 36 | class ColorScheme; | ||
36 | class Session; | 37 | class Session; | ||
37 | class TerminalDisplay; | 38 | class TerminalDisplay; | ||
38 | class TabbedViewContainer; | 39 | class TabbedViewContainer; | ||
39 | class SessionController; | 40 | class SessionController; | ||
40 | class ViewProperties; | 41 | class ViewProperties; | ||
41 | class ViewSplitter; | 42 | class ViewSplitter; | ||
42 | class TabbedViewContainer; | 43 | class TabbedViewContainer; | ||
43 | 44 | | |||
44 | /** | 45 | /** | ||
45 | * Manages the terminal display widgets in a Konsole window or part. | 46 | * Manages the terminal display widgets in a Konsole window or part. | ||
46 | * | 47 | * | ||
47 | * When a view manager is created, it constructs a splitter widget ( accessed via | 48 | * When a view manager is created, it constructs a tab widget ( accessed via | ||
48 | * widget() ) to hold one or more view containers. Each view container holds | 49 | * widget() ) to hold one or more view splitters. Each view splitter holds | ||
49 | * one or more terminal displays and a navigation widget ( eg. tabs or a list ) | 50 | * one or more terminal displays and splitters. | ||
50 | * to allow the user to navigate between the displays in that container. | | |||
51 | * | 51 | * | ||
52 | * The view manager provides menu actions ( defined in the 'konsoleui.rc' XML file ) | 52 | * The view manager provides menu actions ( defined in the 'konsoleui.rc' XML file ) | ||
53 | * to manipulate the views and view containers - for example, actions to split the view | 53 | * to manipulate the views and view containers - for example, actions to split the view | ||
54 | * left/right or top/bottom, detach a view from the current window and navigate between | 54 | * left/right or top/bottom, detach a view from the current window and navigate between | ||
55 | * views and containers. These actions are added to the collection specified in the | 55 | * views and containers. These actions are added to the collection specified in the | ||
56 | * ViewManager's constructor. | 56 | * ViewManager's constructor. | ||
57 | * | 57 | * | ||
58 | * The view manager provides facilities to construct display widgets for a terminal | 58 | * The view manager provides facilities to construct display widgets for a terminal | ||
Show All 11 Lines | 68 | public: | |||
70 | * Constructs a new view manager with the specified @p parent. | 70 | * Constructs a new view manager with the specified @p parent. | ||
71 | * View-related actions defined in 'konsoleui.rc' are created | 71 | * View-related actions defined in 'konsoleui.rc' are created | ||
72 | * and added to the specified @p collection. | 72 | * and added to the specified @p collection. | ||
73 | */ | 73 | */ | ||
74 | ViewManager(QObject *parent, KActionCollection *collection); | 74 | ViewManager(QObject *parent, KActionCollection *collection); | ||
75 | ~ViewManager() Q_DECL_OVERRIDE; | 75 | ~ViewManager() Q_DECL_OVERRIDE; | ||
76 | 76 | | |||
77 | /** | 77 | /** | ||
78 | * Creates a new view to display the output from and deliver input to @p session. | | |||
79 | * Constructs a new container to hold the views if no container has yet been created. | | |||
80 | */ | | |||
81 | void createView(TabbedViewContainer *tabWidget, Session *session); | | |||
82 | | ||||
83 | /** | | |||
84 | * Applies the view-specific settings associated with specified @p profile | 78 | * Applies the view-specific settings associated with specified @p profile | ||
85 | * to the terminal display @p view. | 79 | * to the terminal display @p view. | ||
86 | */ | 80 | */ | ||
87 | void applyProfileToView(TerminalDisplay *view, const Profile::Ptr &profile); | 81 | void applyProfileToView(TerminalDisplay *view, const Profile::Ptr &profile); | ||
88 | 82 | | |||
89 | /** | 83 | /** | ||
90 | * Return the main widget for the view manager which | 84 | * Return the main widget for the view manager which | ||
91 | * holds all of the views managed by this ViewManager instance. | 85 | * holds all of the views managed by this ViewManager instance. | ||
▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Line(s) | |||||
192 | /** | 186 | /** | ||
193 | * Returns whether the @p profile has the blur setting enabled | 187 | * Returns whether the @p profile has the blur setting enabled | ||
194 | */ | 188 | */ | ||
195 | static bool profileHasBlurEnabled(const Profile::Ptr &profile); | 189 | static bool profileHasBlurEnabled(const Profile::Ptr &profile); | ||
196 | 190 | | |||
197 | /** returns the active tab from the view | 191 | /** returns the active tab from the view | ||
198 | */ | 192 | */ | ||
199 | TabbedViewContainer *activeContainer(); | 193 | TabbedViewContainer *activeContainer(); | ||
194 | TerminalDisplay *createView(Session *session); | ||||
195 | void attachView(TerminalDisplay *terminal, Session *session); | ||||
196 | | ||||
197 | /** Reorder the terminal display history list */ | ||||
198 | void updateTerminalDisplayHistory(TerminalDisplay *terminalDisplay = nullptr, bool remove = false); | ||||
200 | 199 | | |||
200 | QHash<TerminalDisplay*, Session*> forgetAll(ViewSplitter* splitter); | ||||
201 | Session* forgetTerminal(TerminalDisplay* terminal); | ||||
201 | Q_SIGNALS: | 202 | Q_SIGNALS: | ||
202 | /** Emitted when the last view is removed from the view manager */ | 203 | /** Emitted when the last view is removed from the view manager */ | ||
203 | void empty(); | 204 | void empty(); | ||
204 | 205 | | |||
205 | /** Emitted when a session is detached from a view owned by this ViewManager */ | 206 | /** Emitted when a session is detached from a view owned by this ViewManager */ | ||
206 | void viewDetached(Session *session); | 207 | void terminalsDetached(ViewSplitter *splitter, QHash<TerminalDisplay*, Session*> sessionsMap); | ||
207 | 208 | | |||
208 | /** | 209 | /** | ||
209 | * Emitted when the active view changes. | 210 | * Emitted when the active view changes. | ||
210 | * @param controller The controller associated with the active view | 211 | * @param controller The controller associated with the active view | ||
211 | */ | 212 | */ | ||
212 | void activeViewChanged(SessionController *controller); | 213 | void activeViewChanged(SessionController *controller); | ||
213 | 214 | | |||
214 | /** | 215 | /** | ||
215 | * Emitted when the current session needs unplugged from factory(). | 216 | * Emitted when the current session needs unplugged from factory(). | ||
216 | * @param controller The controller associated with the active view | 217 | * @param controller The controller associated with the active view | ||
217 | */ | 218 | */ | ||
218 | void unplugController(SessionController *controller); | 219 | void unplugController(SessionController *controller); | ||
219 | 220 | | |||
220 | /** | 221 | /** | ||
221 | * Emitted when the list of view properties ( as returned by viewProperties() ) changes. | 222 | * Emitted when the list of view properties ( as returned by viewProperties() ) changes. | ||
222 | * This occurs when views are added to or removed from the active container, or | 223 | * This occurs when views are added to or removed from the active container, or | ||
223 | * if the active container is changed. | 224 | * if the active container is changed. | ||
224 | */ | 225 | */ | ||
225 | void viewPropertiesChanged(const QList<ViewProperties *> &propertiesList); | 226 | void viewPropertiesChanged(const QList<ViewProperties *> &propertiesList); | ||
226 | 227 | | |||
227 | /** | 228 | /** | ||
228 | * Emitted when the number of views containers changes. This is used to disable or | | |||
229 | * enable menu items which can only be used when there are one or multiple containers | | |||
230 | * visible. | | |||
231 | * | | |||
232 | * @param multipleViews True if there are multiple view containers open or false if there is | | |||
233 | * just a single view. | | |||
234 | */ | | |||
235 | void splitViewToggle(bool multipleViews); | | |||
236 | | ||||
237 | /** | | |||
238 | * Emitted when menu bar visibility changes because a profile that requires so is | 229 | * Emitted when menu bar visibility changes because a profile that requires so is | ||
239 | * activated. | 230 | * activated. | ||
240 | */ | 231 | */ | ||
241 | void setMenuBarVisibleRequest(bool); | 232 | void setMenuBarVisibleRequest(bool); | ||
242 | void updateWindowIcon(); | 233 | void updateWindowIcon(); | ||
243 | 234 | | |||
244 | void blurSettingChanged(bool); | 235 | void blurSettingChanged(bool); | ||
245 | 236 | | |||
246 | /** Requests creation of a new view with the default profile. */ | 237 | /** Requests creation of a new view with the default profile. */ | ||
247 | void newViewRequest(TabbedViewContainer *tabWidget); | 238 | void newViewRequest(); | ||
248 | /** Requests creation of a new view, with the selected profile. */ | 239 | /** Requests creation of a new view, with the selected profile. */ | ||
249 | void newViewWithProfileRequest(TabbedViewContainer *tabWidget, const Profile::Ptr&); | 240 | void newViewWithProfileRequest(const Profile::Ptr&); | ||
250 | 241 | | |||
251 | public Q_SLOTS: | 242 | public Q_SLOTS: | ||
252 | /** DBus slot that returns the number of sessions in the current view. */ | 243 | /** DBus slot that returns the number of sessions in the current view. */ | ||
253 | Q_SCRIPTABLE int sessionCount(); | 244 | Q_SCRIPTABLE int sessionCount(); | ||
254 | 245 | | |||
255 | /** | 246 | /** | ||
256 | * DBus slot that returns the unique ids of the sessions in the | 247 | * DBus slot that returns the unique ids of the sessions in the | ||
257 | * current view. The returned list is not sorted. | 248 | * current view. The returned list is not sorted. | ||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | |||||
311 | 302 | | |||
312 | /** DBus slot that sets ALL tabs' width to match their text */ | 303 | /** DBus slot that sets ALL tabs' width to match their text */ | ||
313 | Q_SCRIPTABLE void setTabWidthToText(bool); | 304 | Q_SCRIPTABLE void setTabWidthToText(bool); | ||
314 | 305 | | |||
315 | private Q_SLOTS: | 306 | private Q_SLOTS: | ||
316 | // called when the "Split View Left/Right" menu item is selected | 307 | // called when the "Split View Left/Right" menu item is selected | ||
317 | void splitLeftRight(); | 308 | void splitLeftRight(); | ||
318 | void splitTopBottom(); | 309 | void splitTopBottom(); | ||
319 | void closeActiveContainer(); | | |||
320 | void closeOtherContainers(); | | |||
321 | void expandActiveContainer(); | 310 | void expandActiveContainer(); | ||
322 | void shrinkActiveContainer(); | 311 | void shrinkActiveContainer(); | ||
323 | 312 | | |||
324 | // called when the "Detach View" menu item is selected | 313 | // called when the "Detach View" menu item is selected | ||
325 | void detachActiveView(); | 314 | void detachActiveView(); | ||
315 | void detachActiveTab(); | ||||
326 | void updateDetachViewState(); | 316 | void updateDetachViewState(); | ||
327 | 317 | | |||
328 | // called when a session terminates - the view manager will delete any | 318 | // called when a session terminates - the view manager will delete any | ||
329 | // views associated with the session | 319 | // views associated with the session | ||
330 | void sessionFinished(); | 320 | void sessionFinished(); | ||
331 | // called when one view has been destroyed | 321 | // called when one view has been destroyed | ||
332 | void viewDestroyed(QWidget *view); | 322 | void viewDestroyed(QWidget *view); | ||
333 | 323 | | |||
334 | // controller detects when an associated view is given the focus | 324 | // controller detects when an associated view is given the focus | ||
335 | // and emits a signal. ViewManager listens for that signal | 325 | // and emits a signal. ViewManager listens for that signal | ||
336 | // and then plugs the action into the UI | 326 | // and then plugs the action into the UI | ||
337 | //void viewFocused( SessionController* controller ); | 327 | //void viewFocused( SessionController* controller ); | ||
338 | 328 | | |||
339 | // called when the active view in a ViewContainer changes, so | 329 | // called when the active view in a ViewContainer changes, so | ||
340 | // that we can plug the appropriate actions into the UI | 330 | // that we can plug the appropriate actions into the UI | ||
341 | void viewActivated(QWidget *view); | 331 | void viewActivated(TerminalDisplay *view); | ||
332 | | ||||
333 | void focusUp(); | ||||
334 | void focusDown(); | ||||
335 | void focusLeft(); | ||||
336 | void focusRight(); | ||||
342 | 337 | | |||
343 | // called when "Next View" shortcut is activated | 338 | // called when "Next View" shortcut is activated | ||
344 | void nextView(); | 339 | void nextView(); | ||
345 | 340 | | |||
346 | // called when "Previous View" shortcut is activated | 341 | // called when "Previous View" shortcut is activated | ||
347 | void previousView(); | 342 | void previousView(); | ||
348 | 343 | | |||
349 | // called when "Switch to last tab" shortcut is activated | 344 | // called when "Switch to last tab" shortcut is activated | ||
Show All 22 Lines | |||||
372 | 367 | | |||
373 | // moves active view to the left | 368 | // moves active view to the left | ||
374 | void moveActiveViewLeft(); | 369 | void moveActiveViewLeft(); | ||
375 | // moves active view to the right | 370 | // moves active view to the right | ||
376 | void moveActiveViewRight(); | 371 | void moveActiveViewRight(); | ||
377 | // switches to the view at visual position 'index' | 372 | // switches to the view at visual position 'index' | ||
378 | // in the current container | 373 | // in the current container | ||
379 | void switchToView(int index); | 374 | void switchToView(int index); | ||
375 | // gives focus and switches the terminal display, changing tab if needed | ||||
376 | void switchToTerminalDisplay(TerminalDisplay *terminalDisplay); | ||||
380 | 377 | | |||
381 | // called when a SessionController gains focus | 378 | // called when a SessionController gains focus | ||
382 | void controllerChanged(SessionController *controller); | 379 | void controllerChanged(SessionController *controller); | ||
383 | 380 | | |||
384 | // called when a ViewContainer requests a view be | 381 | /* Detaches the tab at index tabIdx */ | ||
385 | // moved | 382 | void detachTab(int tabIdx); | ||
386 | void containerMoveViewRequest(int index, int sessionControllerId); | | |||
387 | | ||||
388 | void detachView(TabbedViewContainer *container, QWidget *view); | | |||
389 | 383 | | |||
390 | private: | 384 | private: | ||
391 | Q_DISABLE_COPY(ViewManager) | 385 | Q_DISABLE_COPY(ViewManager) | ||
392 | 386 | | |||
393 | void createView(Session *session, TabbedViewContainer *container, int index); | | |||
394 | static const ColorScheme *colorSchemeForProfile(const Profile::Ptr &profile); | 387 | static const ColorScheme *colorSchemeForProfile(const Profile::Ptr &profile); | ||
395 | 388 | | |||
396 | void setupActions(); | 389 | void setupActions(); | ||
397 | 390 | | |||
398 | // takes a view from a view container owned by a different manager and places it in | 391 | // takes a view from a view container owned by a different manager and places it in | ||
399 | // newContainer owned by this manager | 392 | // newContainer owned by this manager | ||
400 | void takeView(ViewManager *otherManager, TabbedViewContainer *otherContainer, | 393 | void takeView(ViewManager *otherManager, TabbedViewContainer *otherContainer, | ||
401 | TabbedViewContainer *newContainer, TerminalDisplay *view); | 394 | TabbedViewContainer *newContainer, TerminalDisplay *view); | ||
402 | void splitView(Qt::Orientation orientation); | 395 | void splitView(Qt::Orientation orientation); | ||
403 | 396 | | |||
404 | // creates a new container which can hold terminal displays | 397 | // creates a new container which can hold terminal displays | ||
405 | TabbedViewContainer *createContainer(); | 398 | TabbedViewContainer *createContainer(); | ||
406 | // removes a container and emits appropriate signals | | |||
407 | void removeContainer(TabbedViewContainer *container); | | |||
408 | 399 | | |||
409 | // creates a new terminal display | 400 | // creates a new terminal display | ||
410 | // the 'session' is used so that the terminal display's random seed | 401 | // the 'session' is used so that the terminal display's random seed | ||
411 | // can be set to something which depends uniquely on that session | 402 | // can be set to something which depends uniquely on that session | ||
412 | TerminalDisplay *createTerminalDisplay(Session *session = nullptr); | 403 | TerminalDisplay *createTerminalDisplay(Session *session = nullptr); | ||
413 | 404 | | |||
414 | // creates a new controller for a session/display pair which provides the menu | 405 | // creates a new controller for a session/display pair which provides the menu | ||
415 | // actions associated with that view, and exposes basic information | 406 | // actions associated with that view, and exposes basic information | ||
416 | // about the session ( such as title and associated icon ) to the display. | 407 | // about the session ( such as title and associated icon ) to the display. | ||
417 | SessionController *createController(Session *session, TerminalDisplay *view); | 408 | SessionController *createController(Session *session, TerminalDisplay *view); | ||
409 | void removeController(SessionController* controller); | ||||
410 | | ||||
411 | // Activates a different terminal when the TerminalDisplay | ||||
412 | // closes or is detached and another one should be focused. | ||||
413 | // It will activate the last used terminal within the same splitView | ||||
414 | // if possible otherwise it will focus the last used tab | ||||
415 | void focusAnotherTerminal(ViewSplitter *toplevelSplitter); | ||||
416 | | ||||
417 | void activateLastUsedView(bool reverse); | ||||
418 | 418 | | |||
419 | private: | 419 | private: | ||
420 | QPointer<ViewSplitter> _viewSplitter; | 420 | QPointer<TabbedViewContainer> _viewContainer; | ||
421 | QPointer<SessionController> _pluggedController; | 421 | QPointer<SessionController> _pluggedController; | ||
422 | 422 | | |||
423 | QHash<TerminalDisplay *, Session *> _sessionMap; | 423 | QHash<TerminalDisplay *, Session *> _sessionMap; | ||
424 | 424 | | |||
425 | KActionCollection *_actionCollection; | 425 | KActionCollection *_actionCollection; | ||
426 | 426 | | |||
427 | NavigationMethod _navigationMethod; | 427 | NavigationMethod _navigationMethod; | ||
428 | NavigationVisibility _navigationVisibility; | 428 | NavigationVisibility _navigationVisibility; | ||
429 | NewTabBehavior _newTabBehavior; | 429 | NewTabBehavior _newTabBehavior; | ||
430 | int _managerId; | 430 | int _managerId; | ||
431 | static int lastManagerId; | 431 | static int lastManagerId; | ||
432 | QList<TerminalDisplay *> _terminalDisplayHistory; | ||||
433 | int _terminalDisplayHistoryIndex; | ||||
434 | | ||||
435 | // List of actions that should only be enabled when there are multiple view | ||||
436 | // containers open | ||||
437 | QList<QAction *> _multiTabOnlyActions; | ||||
438 | QList<QAction *> _multiSplitterOnlyActions; | ||||
439 | | ||||
432 | }; | 440 | }; | ||
433 | } | 441 | } | ||
434 | 442 | | |||
435 | #endif | 443 | #endif |