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 16 Lines | 68 | public: | |||
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. | 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. | 79 | * Constructs a new container to hold the views if no container has yet been created. | ||
80 | */ | 80 | */ | ||
81 | void createView(TabbedViewContainer *tabWidget, Session *session); | 81 | void createView(TabbedViewContainer *tabWidget, Session *session); | ||
82 | 82 | | |||
83 | /* | ||||
84 | * Applies the view-specific settings associated with specified @p profile | ||||
85 | * to the terminal display @p view. | ||||
86 | */ | ||||
87 | void applyProfileToView(TerminalDisplay *view, const Profile::Ptr &profile); | ||||
88 | | ||||
83 | /** | 89 | /** | ||
84 | * Return the main widget for the view manager which | 90 | * Return the main widget for the view manager which | ||
85 | * holds all of the views managed by this ViewManager instance. | 91 | * holds all of the views managed by this ViewManager instance. | ||
86 | */ | 92 | */ | ||
87 | QWidget *widget() const; | 93 | QWidget *widget() const; | ||
88 | 94 | | |||
89 | /** | 95 | /** | ||
90 | * Returns the view manager's active view. | 96 | * Returns the view manager's active view. | ||
▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Line(s) | |||||
186 | /** | 192 | /** | ||
187 | * Returns whether the @p profile has the blur setting enabled | 193 | * Returns whether the @p profile has the blur setting enabled | ||
188 | */ | 194 | */ | ||
189 | static bool profileHasBlurEnabled(const Profile::Ptr &profile); | 195 | static bool profileHasBlurEnabled(const Profile::Ptr &profile); | ||
190 | 196 | | |||
191 | /** returns the active tab from the view | 197 | /** returns the active tab from the view | ||
192 | */ | 198 | */ | ||
193 | TabbedViewContainer *activeContainer(); | 199 | TabbedViewContainer *activeContainer(); | ||
194 | 200 | TerminalDisplay *createView(Session *session); | |||
195 | void applyProfileToView(TerminalDisplay *view, const Profile::Ptr &profile); | 201 | void attachView(TerminalDisplay *terminal, Session *session); | ||
196 | 202 | | |||
197 | static const ColorScheme *colorSchemeForProfile(const Profile::Ptr &profile); | 203 | static const ColorScheme *colorSchemeForProfile(const Profile::Ptr &profile); | ||
204 | /** Reorder the terminal display history list */ | ||||
205 | void updateTerminalDisplayHistory(TerminalDisplay *terminalDisplay = nullptr, bool remove = false); | ||||
198 | 206 | | |||
207 | QHash<TerminalDisplay*, Session*> forgetAll(ViewSplitter* splitter); | ||||
208 | Session* forgetTerminal(TerminalDisplay* terminal); | ||||
199 | Q_SIGNALS: | 209 | Q_SIGNALS: | ||
200 | /** Emitted when the last view is removed from the view manager */ | 210 | /** Emitted when the last view is removed from the view manager */ | ||
201 | void empty(); | 211 | void empty(); | ||
202 | 212 | | |||
203 | /** Emitted when a session is detached from a view owned by this ViewManager */ | 213 | /** Emitted when a session is detached from a view owned by this ViewManager */ | ||
204 | void viewDetached(Session *session); | 214 | void terminalsDetached(ViewSplitter *splitter, QHash<TerminalDisplay*, Session*> sessionsMap); | ||
205 | 215 | | |||
206 | /** | 216 | /** | ||
207 | * Emitted when the active view changes. | 217 | * Emitted when the active view changes. | ||
208 | * @param controller The controller associated with the active view | 218 | * @param controller The controller associated with the active view | ||
209 | */ | 219 | */ | ||
210 | void activeViewChanged(SessionController *controller); | 220 | void activeViewChanged(SessionController *controller); | ||
211 | 221 | | |||
212 | /** | 222 | /** | ||
213 | * Emitted when the current session needs unplugged from factory(). | 223 | * Emitted when the current session needs unplugged from factory(). | ||
214 | * @param controller The controller associated with the active view | 224 | * @param controller The controller associated with the active view | ||
215 | */ | 225 | */ | ||
216 | void unplugController(SessionController *controller); | 226 | void unplugController(SessionController *controller); | ||
217 | 227 | | |||
218 | /** | 228 | /** | ||
219 | * Emitted when the list of view properties ( as returned by viewProperties() ) changes. | 229 | * Emitted when the list of view properties ( as returned by viewProperties() ) changes. | ||
220 | * This occurs when views are added to or removed from the active container, or | 230 | * This occurs when views are added to or removed from the active container, or | ||
221 | * if the active container is changed. | 231 | * if the active container is changed. | ||
222 | */ | 232 | */ | ||
223 | void viewPropertiesChanged(const QList<ViewProperties *> &propertiesList); | 233 | void viewPropertiesChanged(const QList<ViewProperties *> &propertiesList); | ||
224 | 234 | | |||
225 | /** | 235 | /** | ||
226 | * Emitted when the number of views containers changes. This is used to disable or | | |||
227 | * enable menu items which can only be used when there are one or multiple containers | | |||
228 | * visible. | | |||
229 | * | | |||
230 | * @param multipleViews True if there are multiple view containers open or false if there is | | |||
231 | * just a single view. | | |||
232 | */ | | |||
233 | void splitViewToggle(bool multipleViews); | | |||
234 | | ||||
235 | /** | | |||
236 | * Emitted when menu bar visibility changes because a profile that requires so is | 236 | * Emitted when menu bar visibility changes because a profile that requires so is | ||
237 | * activated. | 237 | * activated. | ||
238 | */ | 238 | */ | ||
239 | void setMenuBarVisibleRequest(bool); | 239 | void setMenuBarVisibleRequest(bool); | ||
240 | void updateWindowIcon(); | 240 | void updateWindowIcon(); | ||
241 | 241 | | |||
242 | void blurSettingChanged(bool); | 242 | void blurSettingChanged(bool); | ||
243 | 243 | | |||
244 | /** Requests creation of a new view with the default profile. */ | 244 | /** Requests creation of a new view with the default profile. */ | ||
245 | void newViewRequest(TabbedViewContainer *tabWidget); | 245 | void newViewRequest(); | ||
246 | /** Requests creation of a new view, with the selected profile. */ | 246 | /** Requests creation of a new view, with the selected profile. */ | ||
247 | void newViewWithProfileRequest(TabbedViewContainer *tabWidget, const Profile::Ptr&); | 247 | void newViewWithProfileRequest(const Profile::Ptr&); | ||
248 | 248 | | |||
249 | public Q_SLOTS: | 249 | public Q_SLOTS: | ||
250 | /** DBus slot that returns the number of sessions in the current view. */ | 250 | /** DBus slot that returns the number of sessions in the current view. */ | ||
251 | Q_SCRIPTABLE int sessionCount(); | 251 | Q_SCRIPTABLE int sessionCount(); | ||
252 | 252 | | |||
253 | /** | 253 | /** | ||
254 | * DBus slot that returns the unique ids of the sessions in the | 254 | * DBus slot that returns the unique ids of the sessions in the | ||
255 | * current view. The returned list is not sorted. | 255 | * current view. The returned list is not sorted. | ||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | |||||
309 | 309 | | |||
310 | /** DBus slot that sets ALL tabs' width to match their text */ | 310 | /** DBus slot that sets ALL tabs' width to match their text */ | ||
311 | Q_SCRIPTABLE void setTabWidthToText(bool); | 311 | Q_SCRIPTABLE void setTabWidthToText(bool); | ||
312 | 312 | | |||
313 | private Q_SLOTS: | 313 | private Q_SLOTS: | ||
314 | // called when the "Split View Left/Right" menu item is selected | 314 | // called when the "Split View Left/Right" menu item is selected | ||
315 | void splitLeftRight(); | 315 | void splitLeftRight(); | ||
316 | void splitTopBottom(); | 316 | void splitTopBottom(); | ||
317 | void closeActiveContainer(); | | |||
318 | void closeOtherContainers(); | | |||
319 | void expandActiveContainer(); | 317 | void expandActiveContainer(); | ||
320 | void shrinkActiveContainer(); | 318 | void shrinkActiveContainer(); | ||
321 | 319 | | |||
322 | // called when the "Detach View" menu item is selected | 320 | // called when the "Detach View" menu item is selected | ||
323 | void detachActiveView(); | 321 | void detachActiveView(); | ||
322 | void detachActiveTab(); | ||||
324 | void updateDetachViewState(); | 323 | void updateDetachViewState(); | ||
325 | 324 | | |||
326 | // called when a session terminates - the view manager will delete any | 325 | // called when a session terminates - the view manager will delete any | ||
327 | // views associated with the session | 326 | // views associated with the session | ||
328 | void sessionFinished(); | 327 | void sessionFinished(); | ||
329 | // called when one view has been destroyed | 328 | // called when one view has been destroyed | ||
330 | void viewDestroyed(QWidget *view); | 329 | void viewDestroyed(QWidget *view); | ||
331 | 330 | | |||
332 | // controller detects when an associated view is given the focus | 331 | // controller detects when an associated view is given the focus | ||
333 | // and emits a signal. ViewManager listens for that signal | 332 | // and emits a signal. ViewManager listens for that signal | ||
334 | // and then plugs the action into the UI | 333 | // and then plugs the action into the UI | ||
335 | //void viewFocused( SessionController* controller ); | 334 | //void viewFocused( SessionController* controller ); | ||
336 | 335 | | |||
337 | // called when the active view in a ViewContainer changes, so | 336 | // called when the active view in a ViewContainer changes, so | ||
338 | // that we can plug the appropriate actions into the UI | 337 | // that we can plug the appropriate actions into the UI | ||
339 | void viewActivated(QWidget *view); | 338 | void viewActivated(TerminalDisplay *view); | ||
339 | | ||||
340 | void focusUp(); | ||||
341 | void focusDown(); | ||||
342 | void focusLeft(); | ||||
343 | void focusRight(); | ||||
340 | 344 | | |||
341 | // called when "Next View" shortcut is activated | 345 | // called when "Next View" shortcut is activated | ||
342 | void nextView(); | 346 | void nextView(); | ||
343 | 347 | | |||
344 | // called when "Previous View" shortcut is activated | 348 | // called when "Previous View" shortcut is activated | ||
345 | void previousView(); | 349 | void previousView(); | ||
346 | 350 | | |||
347 | // called when "Switch to last tab" shortcut is activated | 351 | // called when "Switch to last tab" shortcut is activated | ||
Show All 22 Lines | |||||
370 | 374 | | |||
371 | // moves active view to the left | 375 | // moves active view to the left | ||
372 | void moveActiveViewLeft(); | 376 | void moveActiveViewLeft(); | ||
373 | // moves active view to the right | 377 | // moves active view to the right | ||
374 | void moveActiveViewRight(); | 378 | void moveActiveViewRight(); | ||
375 | // switches to the view at visual position 'index' | 379 | // switches to the view at visual position 'index' | ||
376 | // in the current container | 380 | // in the current container | ||
377 | void switchToView(int index); | 381 | void switchToView(int index); | ||
382 | // gives focus and switches the terminal display, changing tab if needed | ||||
383 | void switchToTerminalDisplay(TerminalDisplay *terminalDisplay); | ||||
378 | 384 | | |||
379 | // called when a SessionController gains focus | 385 | // called when a SessionController gains focus | ||
380 | void controllerChanged(SessionController *controller); | 386 | void controllerChanged(SessionController *controller); | ||
381 | 387 | | |||
382 | // called when a ViewContainer requests a view be | 388 | /* Detaches the tab at index tabIdx */ | ||
383 | // moved | 389 | void detachTab(int tabIdx); | ||
384 | void containerMoveViewRequest(int index, int sessionControllerId); | | |||
385 | | ||||
386 | void detachView(TabbedViewContainer *container, QWidget *view); | | |||
387 | 390 | | |||
388 | private: | 391 | private: | ||
389 | Q_DISABLE_COPY(ViewManager) | 392 | Q_DISABLE_COPY(ViewManager) | ||
390 | 393 | | |||
391 | void createView(Session *session, TabbedViewContainer *container, int index); | 394 | void createView(Session *session, TabbedViewContainer *container, int index); | ||
392 | 395 | | |||
393 | void setupActions(); | 396 | void setupActions(); | ||
394 | 397 | | |||
395 | // takes a view from a view container owned by a different manager and places it in | 398 | // takes a view from a view container owned by a different manager and places it in | ||
396 | // newContainer owned by this manager | 399 | // newContainer owned by this manager | ||
397 | void takeView(ViewManager *otherManager, TabbedViewContainer *otherContainer, | 400 | void takeView(ViewManager *otherManager, TabbedViewContainer *otherContainer, | ||
398 | TabbedViewContainer *newContainer, TerminalDisplay *view); | 401 | TabbedViewContainer *newContainer, TerminalDisplay *view); | ||
399 | void splitView(Qt::Orientation orientation); | 402 | void splitView(Qt::Orientation orientation); | ||
400 | 403 | | |||
401 | // creates a new container which can hold terminal displays | 404 | // creates a new container which can hold terminal displays | ||
402 | TabbedViewContainer *createContainer(); | 405 | TabbedViewContainer *createContainer(); | ||
403 | // removes a container and emits appropriate signals | | |||
404 | void removeContainer(TabbedViewContainer *container); | | |||
405 | 406 | | |||
406 | // creates a new terminal display | 407 | // creates a new terminal display | ||
407 | // the 'session' is used so that the terminal display's random seed | 408 | // the 'session' is used so that the terminal display's random seed | ||
408 | // can be set to something which depends uniquely on that session | 409 | // can be set to something which depends uniquely on that session | ||
409 | TerminalDisplay *createTerminalDisplay(Session *session = nullptr); | 410 | TerminalDisplay *createTerminalDisplay(Session *session = nullptr); | ||
410 | 411 | | |||
411 | // creates a new controller for a session/display pair which provides the menu | 412 | // creates a new controller for a session/display pair which provides the menu | ||
412 | // actions associated with that view, and exposes basic information | 413 | // actions associated with that view, and exposes basic information | ||
413 | // about the session ( such as title and associated icon ) to the display. | 414 | // about the session ( such as title and associated icon ) to the display. | ||
414 | SessionController *createController(Session *session, TerminalDisplay *view); | 415 | SessionController *createController(Session *session, TerminalDisplay *view); | ||
416 | void removeController(SessionController* controller); | ||||
417 | | ||||
418 | // Activates a different terminal when the TerminalDisplay | ||||
419 | // closes or is detached and another one should be focused. | ||||
420 | // It will activate the last used terminal within the same splitView | ||||
421 | // if possible otherwise it will focus the last used tab | ||||
422 | void focusAnotherTerminal(ViewSplitter *toplevelSplitter); | ||||
423 | | ||||
424 | void activateLastUsedView(bool reverse); | ||||
415 | 425 | | |||
416 | private: | 426 | private: | ||
417 | QPointer<ViewSplitter> _viewSplitter; | 427 | QPointer<TabbedViewContainer> _viewContainer; | ||
418 | QPointer<SessionController> _pluggedController; | 428 | QPointer<SessionController> _pluggedController; | ||
419 | 429 | | |||
420 | QHash<TerminalDisplay *, Session *> _sessionMap; | 430 | QHash<TerminalDisplay *, Session *> _sessionMap; | ||
421 | 431 | | |||
422 | KActionCollection *_actionCollection; | 432 | KActionCollection *_actionCollection; | ||
423 | 433 | | |||
424 | NavigationMethod _navigationMethod; | 434 | NavigationMethod _navigationMethod; | ||
425 | NavigationVisibility _navigationVisibility; | 435 | NavigationVisibility _navigationVisibility; | ||
426 | NewTabBehavior _newTabBehavior; | 436 | NewTabBehavior _newTabBehavior; | ||
427 | int _managerId; | 437 | int _managerId; | ||
428 | static int lastManagerId; | 438 | static int lastManagerId; | ||
439 | QList<TerminalDisplay *> _terminalDisplayHistory; | ||||
440 | int _terminalDisplayHistoryIndex; | ||||
441 | | ||||
442 | // List of actions that should only be enabled when there are multiple view | ||||
443 | // containers open | ||||
444 | QList<QAction *> _multiTabOnlyActions; | ||||
445 | QList<QAction *> _multiSplitterOnlyActions; | ||||
446 | | ||||
429 | }; | 447 | }; | ||
430 | } | 448 | } | ||
431 | 449 | | |||
432 | #endif | 450 | #endif |