136
135
KActionCollection* collection = _actionCollection;
138
KAction* nextViewAction = new KAction( i18n("Next Tab") , this );
139
KAction* previousViewAction = new KAction( i18n("Previous Tab") , this );
140
KAction* nextContainerAction = new KAction( i18n("Next View Container") , this);
142
KAction* moveViewLeftAction = new KAction( i18n("Move Tab Left") , this );
143
KAction* moveViewRightAction = new KAction( i18n("Move Tab Right") , this );
137
KAction* nextViewAction = new KAction( i18nc("@action Shortcut entry", "Next Tab") , this );
138
KAction* previousViewAction = new KAction( i18nc("@action Shortcut entry", "Previous Tab") , this );
139
KAction* lastViewAction = new KAction( i18nc("@action Shortcut entry", "Switch to Last Tab") , this);
140
KAction* nextContainerAction = new KAction( i18nc("@action Shortcut entry", "Next View Container") , this);
142
KAction* moveViewLeftAction = new KAction( i18nc("@action Shortcut entry", "Move Tab Left") , this );
143
KAction* moveViewRightAction = new KAction( i18nc("@action Shortcut entry", "Move Tab Right") , this );
145
145
// list of actions that should only be enabled when there are multiple view
146
146
// containers open
234
237
// keyboard shortcut only actions
235
KShortcut nextViewShortcut = nextViewAction->shortcut();
236
nextViewShortcut.setPrimary( QKeySequence(Qt::SHIFT+Qt::Key_Right) );
237
nextViewShortcut.setAlternate( QKeySequence(Qt::CTRL+Qt::Key_PageDown) );
238
nextViewAction->setShortcut(nextViewShortcut);
238
nextViewAction->setShortcut( QKeySequence(Qt::SHIFT+Qt::Key_Right) );
239
239
connect( nextViewAction, SIGNAL(triggered()) , this , SLOT(nextView()) );
240
240
_viewSplitter->addAction(nextViewAction);
242
KShortcut previousViewShortcut = previousViewAction->shortcut();
243
previousViewShortcut.setPrimary( QKeySequence(Qt::SHIFT+Qt::Key_Left) );
244
previousViewShortcut.setAlternate( QKeySequence(Qt::CTRL+Qt::Key_PageUp) );
245
previousViewAction->setShortcut(previousViewShortcut);
242
previousViewAction->setShortcut( QKeySequence(Qt::SHIFT+Qt::Key_Left) );
246
243
connect( previousViewAction, SIGNAL(triggered()) , this , SLOT(previousView()) );
247
244
_viewSplitter->addAction(previousViewAction);
427
437
// iterate over each session which has a view in the current active
428
438
// container and create a new view for that session in a new container
429
439
QListIterator<QWidget*> existingViewIter(_viewSplitter->activeContainer()->views());
431
441
ViewContainer* container = 0;
433
443
while (existingViewIter.hasNext())
435
445
Session* session = _sessionMap[(TerminalDisplay*)existingViewIter.next()];
436
446
TerminalDisplay* display = createTerminalDisplay(session);
437
const Profile::Ptr info = SessionManager::instance()->sessionProfile(session);
438
applyProfile(display, info, false);
447
const Profile::Ptr profile = SessionManager::instance()->sessionProfile(session);
448
applyProfileToView(display, profile);
439
449
ViewProperties* properties = createController(session,display);
441
451
_sessionMap[display] = session;
443
453
// create a container using settings from the first
444
454
// session in the previous container
445
455
if ( !container )
446
container = createContainer(info);
457
container = createContainer(profile);
458
applyProfileToContainer(container, profile);
448
int tabBarMode = info->property<int>(Profile::TabBarMode);
449
if ( tabBarMode == Profile::AlwaysHideTabBar )
450
container->setNavigationDisplayMode(ViewContainer::AlwaysHideNavigation);
451
else if ( tabBarMode == Profile::AlwaysShowTabBar )
452
container->setNavigationDisplayMode(ViewContainer::AlwaysShowNavigation);
453
else if ( tabBarMode == Profile::ShowTabBarAsNeeded )
454
container->setNavigationDisplayMode(ViewContainer::ShowNavigationAsNeeded);
455
461
container->addView(display,properties);
456
462
session->addView( display );
526
532
SessionController* controller = new SessionController(session,view,this);
527
533
connect( controller , SIGNAL(focused(SessionController*)) , this , SLOT(controllerChanged(SessionController*)) );
528
534
connect( session , SIGNAL(destroyed()) , controller , SLOT(deleteLater()) );
535
connect( session , SIGNAL(primaryScreenInUse(bool)) ,
536
controller , SLOT(setupPrimaryScreenSpecificActions(bool)) );
537
connect( session , SIGNAL(selectedText(QString)) ,
538
controller , SLOT(updateCopyAction(QString)) );
529
539
connect( view , SIGNAL(destroyed()) , controller , SLOT(deleteLater()) );
531
541
// if this is the first controller created then set it as the active controller
565
575
disconnect( session , SIGNAL(finished()) , this , SLOT(sessionFinished()) );
566
576
connect( session , SIGNAL(finished()) , this , SLOT(sessionFinished()) );
578
TerminalDisplay* display = createTerminalDisplay(session);
579
const Profile::Ptr profile = SessionManager::instance()->sessionProfile(session);
580
applyProfileToView(display, profile);
568
582
bool isFirst = _sessionMap.isEmpty();
569
TerminalDisplay* display = createTerminalDisplay(session);
570
applyProfile(display,SessionManager::instance()->sessionProfile(session),isFirst);
584
applyProfileToContainer(container, profile);
572
586
// set initial size
573
587
display->setSize(80,40);
601
614
emit splitViewToggle(false);
617
// new tab will be put at the end by default.
620
// TODO: currently, whether new tab should be put after current tab is a per
621
// profile setting, while in concept it should be per ViewManager or global
622
// setting. The current implementation is limited by the design of Profile.h
623
// It should be re-implmented at some appropriate time in the future.
624
// comment by jekyllwu
625
Profile::Ptr profile = SessionManager::instance()->sessionProfile(session);
626
int newTabBehavior = profile->property<int>(Profile::NewTabBehavior);
627
if ( newTabBehavior == Profile::PutNewTabAfterCurrentTab )
629
QWidget* view = activeView();
632
QList<QWidget*> views = _viewSplitter->activeContainer()->views();
633
index = views.indexOf(view) + 1;
605
637
// iterate over the view containers owned by this view manager
606
638
// and create a new terminal display for the session in each of them, along with
607
639
// a controller for the session/display pair
608
640
QListIterator<ViewContainer*> containerIter(_viewSplitter->containers());
610
641
while ( containerIter.hasNext() )
612
643
ViewContainer* container = containerIter.next();
613
createView(session,container,-1);
644
createView(session, container, index);
618
ViewContainer* ViewManager::createContainer(const Profile::Ptr info)
648
ViewContainer* ViewManager::createContainer(const Profile::Ptr profile)
622
const int tabPosition = info->property<int>(Profile::TabBarPosition);
652
const int tabPosition = profile->property<int>(Profile::TabBarPosition);
624
654
ViewContainer::NavigationPosition position = ( tabPosition == Profile::TabBarTop ) ?
625
655
ViewContainer::NavigationPositionTop :
635
665
new TabbedViewContainer(position,_viewSplitter);
637
667
connect(container,
638
SIGNAL(detachTab(ViewContainer*, QWidget*)),
668
SIGNAL(detachTab(ViewContainer*,QWidget*)),
640
SLOT(detachView(ViewContainer*, QWidget*))
670
SLOT(detachView(ViewContainer*,QWidget*))
642
672
connect(container,
643
SIGNAL(closeTab(ViewContainer*, QWidget*)),
673
SIGNAL(closeTab(ViewContainer*,QWidget*)),
645
SLOT(closeTabFromContainer(ViewContainer*, QWidget*)));
675
SLOT(closeTabFromContainer(ViewContainer*,QWidget*)));
696
728
// a method should be devised to only enable those that are used, perhaps
697
729
// by using a separate action collection.
731
const bool enable = (_navigationMethod != NoNavigation) ;
701
734
action = collection->action( "next-view" );
702
if ( action ) action->setEnabled( _navigationMethod != NoNavigation );
735
if ( action ) action->setEnabled( enable );
704
737
action = collection->action( "previous-view" );
705
if ( action ) action->setEnabled( _navigationMethod != NoNavigation );
738
if ( action ) action->setEnabled( enable );
740
action = collection->action( "last-tab" );
741
if ( action ) action->setEnabled( enable );
707
743
action = collection->action( "split-view-left-right" );
708
if ( action ) action->setEnabled( _navigationMethod != NoNavigation );
744
if ( action ) action->setEnabled( enable );
710
746
action = collection->action( "split-view-top-bottom" );
711
if ( action ) action->setEnabled( _navigationMethod != NoNavigation );
747
if ( action ) action->setEnabled( enable );
713
749
action = collection->action( "rename-session" );
714
if ( action ) action->setEnabled( _navigationMethod != NoNavigation );
750
if ( action ) action->setEnabled( enable );
716
752
action = collection->action( "move-view-left" );
717
if ( action ) action->setEnabled( _navigationMethod != NoNavigation );
753
if ( action ) action->setEnabled( enable );
719
755
action = collection->action( "move-view-right" );
720
if ( action ) action->setEnabled( _navigationMethod != NoNavigation );
756
if ( action ) action->setEnabled( enable );
763
799
TerminalDisplay* ViewManager::createTerminalDisplay(Session* session)
765
TerminalDisplay* display = new TerminalDisplay(0);
767
//TODO Temporary settings used here
768
display->setBellMode(TerminalDisplay::NotifyBell);
769
display->setTerminalSizeHint(true);
770
display->setTripleClickMode(TerminalDisplay::SelectWholeLine);
771
display->setTerminalSizeStartup(true);
772
display->setScrollBarPosition(TerminalDisplay::ScrollBarRight);
773
display->setRandomSeed(session->sessionId() * 31);
801
TerminalDisplay* display = new TerminalDisplay(0);
802
display->setRandomSeed(session->sessionId() * 31);
778
const ColorScheme* ViewManager::colorSchemeForProfile(const Profile::Ptr info) const
807
const ColorScheme* ViewManager::colorSchemeForProfile(const Profile::Ptr profile) const
780
809
const ColorScheme* colorScheme = ColorSchemeManager::instance()->
781
findColorScheme(info->colorScheme());
810
findColorScheme(profile->colorScheme());
782
811
if ( !colorScheme )
783
812
colorScheme = ColorSchemeManager::instance()->defaultColorScheme();
784
813
Q_ASSERT( colorScheme );
786
815
return colorScheme;
789
void ViewManager::applyProfile(TerminalDisplay* view , const Profile::Ptr info,
790
bool applyContainerSettings)
818
void ViewManager::applyProfileToView(TerminalDisplay* view , const Profile::Ptr profile)
794
const ColorScheme* colorScheme = colorSchemeForProfile(info);
796
822
// menu bar visibility
797
emit setMenuBarVisibleRequest( info->property<bool>(Profile::ShowMenuBar) );
823
emit setMenuBarVisibleRequest( profile->property<bool>(Profile::ShowMenuBar) );
799
emit setSaveGeometryOnExitRequest( info->property<bool>(Profile::SaveGeometryOnExit) );
825
emit setSaveGeometryOnExitRequest( profile->property<bool>(Profile::SaveGeometryOnExit) );
801
827
emit updateWindowIcon();
803
// tab bar visibility
804
if (applyContainerSettings)
806
ViewContainer* container = _viewSplitter->activeContainer();
807
int tabBarMode = info->property<int>(Profile::TabBarMode);
808
int tabBarPosition = info->property<int>(Profile::TabBarPosition);
809
bool showNewCloseButtons = info->property<bool>(Profile::ShowNewAndCloseTabButtons);
811
if ( tabBarMode == Profile::AlwaysHideTabBar )
812
container->setNavigationDisplayMode(ViewContainer::AlwaysHideNavigation);
813
else if ( tabBarMode == Profile::AlwaysShowTabBar )
814
container->setNavigationDisplayMode(ViewContainer::AlwaysShowNavigation);
815
else if ( tabBarMode == Profile::ShowTabBarAsNeeded )
816
container->setNavigationDisplayMode(ViewContainer::ShowNavigationAsNeeded);
818
ViewContainer::NavigationPosition position = container->navigationPosition();
820
if ( tabBarPosition == Profile::TabBarTop )
821
position = ViewContainer::NavigationPositionTop;
822
else if ( tabBarPosition == Profile::TabBarBottom )
823
position = ViewContainer::NavigationPositionBottom;
825
if ( container->supportedNavigationPositions().contains(position) )
826
container->setNavigationPosition(position);
828
if (showNewCloseButtons)
830
container->setFeatures(container->features()
831
| ViewContainer::QuickNewView | ViewContainer::QuickCloseView);
832
container->setNewViewMenu(createNewViewMenu());
835
container->setFeatures(container->features()
836
& ~ViewContainer::QuickNewView & ~ViewContainer::QuickCloseView);
839
// load colour scheme
840
830
ColorEntry table[TABLE_COLORS];
831
const ColorScheme* colorScheme = colorSchemeForProfile(profile);
842
832
colorScheme->getColorTable(table , view->randomSeed() );
843
833
view->setColorTable(table);
844
834
view->setOpacity(colorScheme->opacity());
835
view->setWallpaper(colorScheme->wallpaper());
847
view->setAntialias(info->property<bool>(Profile::AntiAliasFonts));
848
view->setBoldIntense(info->property<bool>(Profile::BoldIntense));
849
view->setVTFont(info->font());
838
view->setAntialias(profile->property<bool>(Profile::AntiAliasFonts));
839
view->setBoldIntense(profile->property<bool>(Profile::BoldIntense));
840
view->setVTFont(profile->font());
851
842
// set scroll-bar position
852
int scrollBarPosition = info->property<int>(Profile::ScrollBarPosition);
843
int scrollBarPosition = profile->property<int>(Profile::ScrollBarPosition);
854
if ( scrollBarPosition == Profile::ScrollBarHidden )
855
view->setScrollBarPosition(TerminalDisplay::NoScrollBar);
856
else if ( scrollBarPosition == Profile::ScrollBarLeft )
845
if ( scrollBarPosition == Profile::ScrollBarLeft )
857
846
view->setScrollBarPosition(TerminalDisplay::ScrollBarLeft);
858
847
else if ( scrollBarPosition == Profile::ScrollBarRight )
859
848
view->setScrollBarPosition(TerminalDisplay::ScrollBarRight);
849
else if ( scrollBarPosition == Profile::ScrollBarHidden )
850
view->setScrollBarPosition(TerminalDisplay::ScrollBarHidden);
852
// show hint about termianl size after resizing
853
view->setShowTerminalSizeHint(profile->property<bool>(Profile::ShowTerminalSizeHint));
861
855
// terminal features
862
bool blinkingCursor = info->property<bool>(Profile::BlinkingCursorEnabled);
863
view->setBlinkingCursor(blinkingCursor);
856
bool blinkingCursor = profile->property<bool>(Profile::BlinkingCursorEnabled);
857
view->setBlinkingCursorEnabled(blinkingCursor);
865
bool blinkingText = info->property<bool>(Profile::BlinkingTextEnabled);
859
bool blinkingText = profile->property<bool>(Profile::BlinkingTextEnabled);
866
860
view->setBlinkingTextEnabled(blinkingText);
868
bool tripleClickMode = info->property<bool>(Profile::TripleClickMode);
869
view->setTripleClickMode(tripleClickMode ? TerminalDisplay::SelectForwardsFromCursor : TerminalDisplay::SelectWholeLine);
871
view->setUnderlineLinks(info->property<bool>(Profile::UnderlineLinksEnabled));
873
bool bidiEnabled = info->property<bool>(Profile::BidiRenderingEnabled);
862
int tripleClickMode = profile->property<int>(Profile::TripleClickMode);
863
view->setTripleClickMode( TerminalDisplay::TripleClickMode(tripleClickMode) );
865
view->setUnderlineLinks(profile->property<bool>(Profile::UnderlineLinksEnabled));
867
bool bidiEnabled = profile->property<bool>(Profile::BidiRenderingEnabled);
874
868
view->setBidiEnabled(bidiEnabled);
877
int cursorShape = info->property<int>(Profile::CursorShape);
871
int cursorShape = profile->property<int>(Profile::CursorShape);
879
873
if ( cursorShape == Profile::BlockCursor )
880
874
view->setKeyboardCursorShape(TerminalDisplay::BlockCursor);
884
878
view->setKeyboardCursorShape(TerminalDisplay::UnderlineCursor);
887
bool useCustomColor = info->property<bool>(Profile::UseCustomCursorColor);
888
const QColor& cursorColor = info->property<QColor>(Profile::CustomCursorColor);
881
bool useCustomColor = profile->property<bool>(Profile::UseCustomCursorColor);
882
const QColor& cursorColor = profile->property<QColor>(Profile::CustomCursorColor);
890
884
view->setKeyboardCursorColor(!useCustomColor,cursorColor);
892
886
// word characters
893
view->setWordCharacters( info->property<QString>(Profile::WordCharacters) );
887
view->setWordCharacters( profile->property<QString>(Profile::WordCharacters) );
890
void ViewManager::applyProfileToContainer(ViewContainer* container , const Profile::Ptr profile)
892
int tabBarMode = profile->property<int>(Profile::TabBarMode);
893
int tabBarPosition = profile->property<int>(Profile::TabBarPosition);
894
bool showNewCloseButtons = profile->property<bool>(Profile::ShowNewAndCloseTabButtons);
896
if ( tabBarMode == Profile::AlwaysHideTabBar )
897
container->setNavigationDisplayMode(ViewContainer::AlwaysHideNavigation);
898
else if ( tabBarMode == Profile::AlwaysShowTabBar )
899
container->setNavigationDisplayMode(ViewContainer::AlwaysShowNavigation);
900
else if ( tabBarMode == Profile::ShowTabBarAsNeeded )
901
container->setNavigationDisplayMode(ViewContainer::ShowNavigationAsNeeded);
903
ViewContainer::NavigationPosition position = container->navigationPosition();
904
if ( tabBarPosition == Profile::TabBarTop )
905
position = ViewContainer::NavigationPositionTop;
906
else if ( tabBarPosition == Profile::TabBarBottom )
907
position = ViewContainer::NavigationPositionBottom;
909
if ( container->supportedNavigationPositions().contains(position) )
910
container->setNavigationPosition(position);
912
if (showNewCloseButtons)
914
container->setFeatures(container->features()
915
| ViewContainer::QuickNewView | ViewContainer::QuickCloseView);
916
container->setNewViewMenu(createNewViewMenu());
920
container->setFeatures(container->features()
921
& ~ViewContainer::QuickNewView & ~ViewContainer::QuickCloseView);
896
925
void ViewManager::updateViewsForSession(Session* session)
915
944
iter.value() != 0 &&
916
945
SessionManager::instance()->sessionProfile(iter.value()) == profile )
918
applyProfile(iter.key(),profile,true);
947
applyProfileToView(iter.key(),profile);
951
// update containers only when this view manager only contains one session and
952
// that session is associated with this profile
954
// FIXME: this is over complex and still not ideal.
955
// TODO: settings influcing containers really should be moved out from profile.
956
QList<Session*> sessions = _sessionMap.values().toSet().toList();
957
if ( sessions.count() == 1 &&
958
SessionManager::instance()->sessionProfile(sessions[0]) == profile )
960
QListIterator<ViewContainer*> containerIter(_viewSplitter->containers());
961
while ( containerIter.hasNext() )
963
ViewContainer* container = containerIter.next();
964
applyProfileToContainer(container, profile);