@ -22,6 +22,12 @@
# include <QMessageBox>
# include <functional>
# ifdef HAVE_QDBUS
# include <QtDBus/QtDBus>
# include "windowadaptor.h"
# endif
# include "terminalconfig.h"
# include "mainwindow.h"
# include "tabwidget.h"
# include "termwidgetholder.h"
@ -29,7 +35,8 @@
# include "properties.h"
# include "propertiesdialog.h"
# include "bookmarkswidget.h"
# include "qterminalapp.h"
# include "dbusaddressable.h"
typedef std : : function < bool ( MainWindow & ) > checkfn ;
Q_DECLARE_METATYPE ( checkfn )
@ -37,18 +44,30 @@ Q_DECLARE_METATYPE(checkfn)
// TODO/FXIME: probably remove. QSS makes it unusable on mac...
# define QSS_DROP "MainWindow {border: 1px solid rgba(0, 0, 0, 50%);}\n"
MainWindow : : MainWindow ( const QString & work_dir ,
const QString & command ,
MainWindow : : MainWindow ( TerminalConfig & cfg ,
bool dropMode ,
QWidget * parent ,
Qt : : WindowFlags f )
: QMainWindow ( parent , f ) ,
m_initShell ( command ) ,
m_initWorkDir ( work_dir ) ,
DBusAddressable ( " /windows " ) ,
tabPosition ( NULL ) ,
scrollBarPosition ( NULL ) ,
keyboardCursorShape ( NULL ) ,
tabPosMenu ( NULL ) ,
scrollPosMenu ( NULL ) ,
keyboardCursorShapeMenu ( NULL ) ,
settingOwner ( NULL ) ,
presetsMenu ( NULL ) ,
m_config ( cfg ) ,
m_dropLockButton ( 0 ) ,
m_dropMode ( dropMode )
{
# ifdef HAVE_QDBUS
registerAdapter < WindowAdaptor , MainWindow > ( this ) ;
# endif
QTerminalApp : : Instance ( ) - > addWindow ( this ) ;
setAttribute ( Qt : : WA_TranslucentBackground ) ;
setAttribute ( Qt : : WA_DeleteOnClose ) ;
setupUi ( this ) ;
Properties : : Instance ( ) - > migrate_settings ( ) ;
@ -88,26 +107,39 @@ MainWindow::MainWindow(const QString& work_dir,
consoleTabulator - > setAutoFillBackground ( true ) ;
connect ( consoleTabulator , SIGNAL ( closeTabNotification ( ) ) , SLOT ( close ( ) ) ) ;
consoleTabulator - > setWorkDirectory ( work_dir ) ;
consoleTabulator - > setTabPosition ( ( QTabWidget : : TabPosition ) Properties : : Instance ( ) - > tabsPos ) ;
//consoleTabulator->setShellProgram(command);
setup_FileMenu_Actions ( ) ;
setup_ActionsMenu_Actions ( ) ;
setup_ViewMenu_Actions ( ) ;
// apply props
propertiesChanged ( ) ;
setupCustomDirs ( ) ;
connect ( consoleTabulator , & TabWidget : : currentTitleChanged , this , & MainWindow : : onCurrentTitleChanged ) ;
connect ( menu_Actions , SIGNAL ( aboutToShow ( ) ) , this , SLOT ( aboutToShowActionsMenu ( ) ) ) ;
connect ( menu_Actions , SIGNAL ( aboutToShow ( ) ) , this , SLOT ( updateDisabledActions ( ) ) ) ;
/* The tab should be added after all changes are made to
the main window ; otherwise , the initial prompt might
get jumbled because of changes in internal geometry . */
consoleTabulator - > addNewTab ( command ) ;
consoleTabulator - > addNewTab ( m_config ) ;
}
void MainWindow : : rebuildActions ( )
{
// Delete all setting-related QObjects
delete settingOwner ;
settingOwner = new QWidget ( this ) ;
settingOwner - > setGeometry ( 0 , 0 , 0 , 0 ) ;
// Then create them again
setup_FileMenu_Actions ( ) ;
setup_ActionsMenu_Actions ( ) ;
setup_ViewMenu_Actions ( ) ;
}
MainWindow : : ~ MainWindow ( )
{
QTerminalApp : : Instance ( ) - > removeWindow ( this ) ;
}
void MainWindow : : enableDropMode ( )
@ -145,22 +177,22 @@ void MainWindow::setup_Action(const char *name, QAction *action, const char *def
QList < QKeySequence > shortcuts ;
Properties: : Instance ( ) - > actions[ name ] = action ;
actions[ name ] = action ;
foreach ( const QString & sequenceString , settings . value ( name , defaultShortcut ) . toString ( ) . split ( ' | ' ) )
shortcuts . append ( QKeySequence : : fromString ( sequenceString ) ) ;
Properties: : Instance ( ) - > actions[ name ] - > setShortcuts ( shortcuts ) ;
actions[ name ] - > setShortcuts ( shortcuts ) ;
if ( receiver )
{
connect ( Properties: : Instance ( ) - > actions[ name ] , SIGNAL ( triggered ( bool ) ) , receiver , slot ) ;
addAction ( Properties: : Instance ( ) - > actions[ name ] ) ;
connect ( actions[ name ] , SIGNAL ( triggered ( bool ) ) , receiver , slot ) ;
addAction ( actions[ name ] ) ;
}
if ( menu )
menu - > addAction ( Properties: : Instance ( ) - > actions[ name ] ) ;
menu - > addAction ( actions[ name ] ) ;
if ( ! data . isNull ( ) )
Properties: : Instance ( ) - > actions[ name ] - > setData ( data ) ;
actions[ name ] - > setData ( data ) ;
}
void MainWindow : : setup_ActionsMenu_Actions ( )
@ -170,68 +202,77 @@ void MainWindow::setup_ActionsMenu_Actions()
const checkfn checkTabs = & MainWindow : : hasMultipleTabs ;
const checkfn checkSubterminals = & MainWindow : : hasMultipleSubterminals ;
setup_Action ( CLEAR_TERMINAL , new QAction ( QIcon : : fromTheme ( " edit-clear " ) , tr ( " &Clear Current Tab " ) , this ) ,
menu_Actions - > clear ( ) ;
setup_Action ( CLEAR_TERMINAL , new QAction ( QIcon : : fromTheme ( " edit-clear " ) , tr ( " &Clear Active Terminal " ) , settingOwner ) ,
CLEAR_TERMINAL_SHORTCUT , consoleTabulator , SLOT ( clearActiveTerminal ( ) ) , menu_Actions ) ;
menu_Actions - > addSeparator ( ) ;
data . setValue ( checkTabs ) ;
setup_Action ( TAB_NEXT , new QAction ( QIcon : : fromTheme ( " go-next " ) , tr ( " &Next Tab " ) , this ) ,
setup_Action ( TAB_NEXT , new QAction ( QIcon : : fromTheme ( " go-next " ) , tr ( " &Next Tab " ) , settingOwner ) ,
TAB_NEXT_SHORTCUT , consoleTabulator , SLOT ( switchToRight ( ) ) , menu_Actions , data ) ;
setup_Action ( TAB_PREV , new QAction ( QIcon : : fromTheme ( " go-previous " ) , tr ( " &Previous Tab " ) , this ) ,
setup_Action ( TAB_PREV , new QAction ( QIcon : : fromTheme ( " go-previous " ) , tr ( " &Previous Tab " ) , settingOwner ) ,
TAB_PREV_SHORTCUT , consoleTabulator , SLOT ( switchToLeft ( ) ) , menu_Actions , data ) ;
setup_Action ( MOVE_LEFT , new QAction ( tr ( " Move Tab &Left " ) , this ) ,
setup_Action ( MOVE_LEFT , new QAction ( tr ( " Move Tab &Left " ) , settingOwner ) ,
MOVE_LEFT_SHORTCUT , consoleTabulator , SLOT ( moveLeft ( ) ) , menu_Actions , data ) ;
setup_Action ( MOVE_RIGHT , new QAction ( tr ( " Move Tab &Right " ) , this ) ,
setup_Action ( MOVE_RIGHT , new QAction ( tr ( " Move Tab &Right " ) , settingOwner ) ,
MOVE_RIGHT_SHORTCUT , consoleTabulator , SLOT ( moveRight ( ) ) , menu_Actions , data ) ;
menu_Actions - > addSeparator ( ) ;
setup_Action ( SPLIT_HORIZONTAL , new QAction ( tr ( " Split Terminal &Horizontally " ) , this ) ,
setup_Action ( SPLIT_HORIZONTAL , new QAction ( tr ( " Split Terminal &Horizontally " ) , settingOwner ) ,
NULL , consoleTabulator , SLOT ( splitHorizontally ( ) ) , menu_Actions ) ;
setup_Action ( SPLIT_VERTICAL , new QAction ( tr ( " Split Terminal &Vertically " ) , this ) ,
setup_Action ( SPLIT_VERTICAL , new QAction ( tr ( " Split Terminal &Vertically " ) , settingOwner ) ,
NULL , consoleTabulator , SLOT ( splitVertically ( ) ) , menu_Actions ) ;
data . setValue ( checkSubterminals ) ;
setup_Action ( SUB_COLLAPSE , new QAction ( tr ( " &Collapse Subterminal " ) , this ) ,
setup_Action ( SUB_COLLAPSE , new QAction ( tr ( " &Collapse Subterminal " ) , settingOwner ) ,
NULL , consoleTabulator , SLOT ( splitCollapse ( ) ) , menu_Actions , data ) ;
setup_Action ( SUB_NEXT , new QAction ( QIcon : : fromTheme ( " go-up " ) , tr ( " N&ext Subterminal " ) , this ) ,
SUB_NEXT_SHORTCUT , consoleTabulator , SLOT ( switchNextSubterminal ( ) ) , menu_Actions , data ) ;
setup_Action ( SUB_TOP , new QAction ( QIcon : : fromTheme ( " go-up " ) , tr ( " &Top Subterminal " ) , settingOwner ) ,
SUB_TOP_SHORTCUT , consoleTabulator , SLOT ( switchTopSubterminal ( ) ) , menu_Actions , data ) ;
setup_Action ( SUB_BOTTOM , new QAction ( QIcon : : fromTheme ( " go-down " ) , tr ( " &Bottom Subterminal " ) , settingOwner ) ,
SUB_BOTTOM_SHORTCUT , consoleTabulator , SLOT ( switchBottomSubterminal ( ) ) , menu_Actions , data ) ;
setup_Action ( SUB_LEFT , new QAction ( QIcon : : fromTheme ( " go-previous " ) , tr ( " L&eft Subterminal " ) , settingOwner ) ,
SUB_LEFT_SHORTCUT , consoleTabulator , SLOT ( switchLeftSubterminal ( ) ) , menu_Actions , data ) ;
setup_Action ( SUB_RIGHT , new QAction ( QIcon : : fromTheme ( " go-next " ) , tr ( " R&ight Subterminal " ) , settingOwner ) ,
SUB_RIGHT_SHORTCUT , consoleTabulator , SLOT ( switchRightSubterminal ( ) ) , menu_Actions , data ) ;
setup_Action ( SUB_PREV , new QAction ( QIcon : : fromTheme ( " go-down " ) , tr ( " P&revious Subterminal " ) , this ) ,
SUB_PREV_SHORTCUT , consoleTabulator , SLOT ( switchPrevSubterminal ( ) ) , menu_Actions , data ) ;
menu_Actions - > addSeparator ( ) ;
// Copy and Paste are only added to the table for the sake of bindings at the moment; there is no Edit menu, only a context menu.
setup_Action ( COPY_SELECTION , new QAction ( QIcon : : fromTheme ( " edit-copy " ) , tr ( " Copy &Selection " ) , this ) ,
setup_Action ( COPY_SELECTION , new QAction ( QIcon : : fromTheme ( " edit-copy " ) , tr ( " Copy &Selection " ) , settingOwner ) ,
COPY_SELECTION_SHORTCUT , consoleTabulator , SLOT ( copySelection ( ) ) , menu_Edit ) ;
setup_Action ( PASTE_CLIPBOARD , new QAction ( QIcon : : fromTheme ( " edit-paste " ) , tr ( " Paste Clip&board " ) , this ) ,
setup_Action ( PASTE_CLIPBOARD , new QAction ( QIcon : : fromTheme ( " edit-paste " ) , tr ( " Paste Clip&board " ) , settingOwner ) ,
PASTE_CLIPBOARD_SHORTCUT , consoleTabulator , SLOT ( pasteClipboard ( ) ) , menu_Edit ) ;
setup_Action ( PASTE_SELECTION , new QAction ( QIcon : : fromTheme ( " edit-paste " ) , tr ( " Paste S&election " ) , this ) ,
setup_Action ( PASTE_SELECTION , new QAction ( QIcon : : fromTheme ( " edit-paste " ) , tr ( " Paste S&election " ) , settingOwner ) ,
PASTE_SELECTION_SHORTCUT , consoleTabulator , SLOT ( pasteSelection ( ) ) , menu_Edit ) ;
setup_Action ( ZOOM_IN , new QAction ( QIcon : : fromTheme ( " zoom-in " ) , tr ( " Zoom &in " ) , this ) ,
setup_Action ( ZOOM_IN , new QAction ( QIcon : : fromTheme ( " zoom-in " ) , tr ( " Zoom &in " ) , settingOwner ) ,
ZOOM_IN_SHORTCUT , consoleTabulator , SLOT ( zoomIn ( ) ) , menu_Edit ) ;
setup_Action ( ZOOM_OUT , new QAction ( QIcon : : fromTheme ( " zoom-out " ) , tr ( " Zoom &out " ) , this ) ,
setup_Action ( ZOOM_OUT , new QAction ( QIcon : : fromTheme ( " zoom-out " ) , tr ( " Zoom &out " ) , settingOwner ) ,
ZOOM_OUT_SHORTCUT , consoleTabulator , SLOT ( zoomOut ( ) ) , menu_Edit ) ;
setup_Action ( ZOOM_RESET , new QAction ( QIcon : : fromTheme ( " zoom-original " ) , tr ( " Zoom rese&t " ) , this ) ,
setup_Action ( ZOOM_RESET , new QAction ( QIcon : : fromTheme ( " zoom-original " ) , tr ( " Zoom rese&t " ) , settingOwner ) ,
ZOOM_RESET_SHORTCUT , consoleTabulator , SLOT ( zoomReset ( ) ) , menu_Edit ) ;
menu_Actions - > addSeparator ( ) ;
setup_Action ( FIND , new QAction ( QIcon : : fromTheme ( " edit-find " ) , tr ( " &Find... " ) , this ) ,
setup_Action ( FIND , new QAction ( QIcon : : fromTheme ( " edit-find " ) , tr ( " &Find... " ) , settingOwner ) ,
FIND_SHORTCUT , this , SLOT ( find ( ) ) , menu_Actions ) ;
#if 0
@ -252,63 +293,66 @@ void MainWindow::setup_ActionsMenu_Actions()
connect ( act , SIGNAL ( triggered ( ) ) , consoleTabulator , SLOT ( loadSession ( ) ) ) ;
# endif
setup_Action ( TOGGLE_MENU , new QAction ( tr ( " &Toggle Menu " ) , this ) ,
TOGGLE_MENU_SHORTCUT , this , SLOT ( find ( ) ) ) ;
setup_Action ( TOGGLE_MENU , new QAction ( tr ( " &Toggle Menu " ) , settingOwner ) ,
TOGGLE_MENU_SHORTCUT , this , SLOT ( toggleMenu ( ) ) ) ;
// this is correct - add action to main window - not to menu to keep toggle working
// Add global rename current session shortcut
setup_Action ( RENAME_SESSION , new QAction ( tr ( " Rename session " ) , this ) ,
setup_Action ( RENAME_SESSION , new QAction ( tr ( " Rename session " ) , settingOwner ) ,
RENAME_SESSION_SHORTCUT , consoleTabulator , SLOT ( renameCurrentSession ( ) ) ) ;
// this is correct - add action to main window - not to menu
// apply props
propertiesChanged ( ) ;
}
void MainWindow : : setup_FileMenu_Actions ( )
{
setup_Action ( ADD_TAB , new QAction ( QIcon : : fromTheme ( " list-add " ) , tr ( " &New Tab " ) , this ) ,
menu_File - > clear ( ) ;
setup_Action ( ADD_TAB , new QAction ( QIcon : : fromTheme ( " list-add " ) , tr ( " &New Tab " ) , settingOwner ) ,
ADD_TAB_SHORTCUT , this , SLOT ( addNewTab ( ) ) , menu_File ) ;
QMenu * presetsMenu = new QMenu ( tr ( " New Tab From &Preset " ) , this ) ;
presetsMenu - > addAction ( QIcon ( ) , tr ( " 1 &Terminal " ) ,
consoleTabulator , SLOT ( addNewTab ( ) ) ) ;
presetsMenu - > addAction ( QIcon ( ) , tr ( " 2 &Horizontal Terminals " ) ,
consoleTabulator , SLOT ( preset2Horizontal ( ) ) ) ;
presetsMenu - > addAction ( QIcon ( ) , tr ( " 2 &Vertical Terminals " ) ,
consoleTabulator , SLOT ( preset2Vertical ( ) ) ) ;
presetsMenu - > addAction ( QIcon ( ) , tr ( " 4 Terminal&s " ) ,
consoleTabulator , SLOT ( preset4Terminals ( ) ) ) ;
if ( presetsMenu = = NULL ) {
presetsMenu = new QMenu ( tr ( " New Tab From &Preset " ) , this ) ;
presetsMenu - > addAction ( QIcon ( ) , tr ( " 1 &Terminal " ) ,
this , SLOT ( addNewTab ( ) ) ) ;
presetsMenu - > addAction ( QIcon ( ) , tr ( " 2 &Horizontal Terminals " ) ,
consoleTabulator , SLOT ( preset2Horizontal ( ) ) ) ;
presetsMenu - > addAction ( QIcon ( ) , tr ( " 2 &Vertical Terminals " ) ,
consoleTabulator , SLOT ( preset2Vertical ( ) ) ) ;
presetsMenu - > addAction ( QIcon ( ) , tr ( " 4 Terminal&s " ) ,
consoleTabulator , SLOT ( preset4Terminals ( ) ) ) ;
}
menu_File - > addMenu ( presetsMenu ) ;
setup_Action ( CLOSE_TAB , new QAction ( QIcon : : fromTheme ( " list-remove " ) , tr ( " &Close Tab " ) , this ) ,
setup_Action ( CLOSE_TAB , new QAction ( QIcon : : fromTheme ( " list-remove " ) , tr ( " &Close Tab " ) , settingOwner ) ,
CLOSE_TAB_SHORTCUT , consoleTabulator , SLOT ( removeCurrentTab ( ) ) , menu_File ) ;
setup_Action ( NEW_WINDOW , new QAction ( QIcon : : fromTheme ( " window-new " ) , tr ( " &New Window " ) , this ) ,
setup_Action ( NEW_WINDOW , new QAction ( QIcon : : fromTheme ( " window-new " ) , tr ( " &New Window " ) , settingOwner ) ,
NEW_WINDOW_SHORTCUT , this , SLOT ( newTerminalWindow ( ) ) , menu_File ) ;
menu_File - > addSeparator ( ) ;
setup_Action ( PREFERENCES , actProperties , " " , this , SLOT ( actProperties_triggered ( ) ) , menu_File ) ;
setup_Action ( PREFERENCES , new QAction ( tr ( " &Preferences... " ) , settingOwner ) , " " , this , SLOT ( actProperties_triggered ( ) ) , menu_File ) ;
menu_File - > addSeparator ( ) ;
setup_Action ( QUIT , actQuit, " " , this , SLOT ( close ( ) ) , menu_File ) ;
setup_Action ( QUIT , new QAction( QIcon : : fromTheme ( " appli ca tion-exit" ) , tr ( " & Quit" ) , settingOwner ) , " " , this , SLOT ( close ( ) ) , menu_File ) ;
}
void MainWindow : : setup_ViewMenu_Actions ( )
{
QAction * hideBordersAction = new QAction ( tr ( " &Hide Window Borders " ) , this ) ;
menu_Window - > clear ( ) ;
QAction * hideBordersAction = new QAction ( tr ( " &Hide Window Borders " ) , settingOwner ) ;
hideBordersAction - > setCheckable ( true ) ;
hideBordersAction - > setVisible ( ! m_dropMode ) ;
setup_Action ( HIDE_WINDOW_BORDERS , hideBordersAction ,
NULL , this , SLOT ( toggleBorderless ( ) ) , menu_Window ) ;
//Properties::Instance()->actions[HIDE_WINDOW_BORDERS]->setObjectName("toggle_Borderless");
// TODO/FIXME: it's broken somehow. When I call toggleBorderless() here the non-responsive window appear
// Properties::Instance()-> actions[HIDE_WINDOW_BORDERS]->setChecked(Properties::Instance()->borderless);
// actions[HIDE_WINDOW_BORDERS]->setChecked(Properties::Instance()->borderless);
// if (Properties::Instance()->borderless)
// toggleBorderless();
QAction * showTabBarAction = new QAction ( tr ( " &Show Tab Bar " ) , this ) ;
QAction * showTabBarAction = new QAction ( tr ( " &Show Tab Bar " ) , settingOwner ) ;
//toggleTabbar->setObjectName("toggle_TabBar");
showTabBarAction - > setCheckable ( true ) ;
showTabBarAction - > setChecked ( ! Properties : : Instance ( ) - > tabBarless ) ;
@ -316,30 +360,33 @@ void MainWindow::setup_ViewMenu_Actions()
NULL , this , SLOT ( toggleTabBar ( ) ) , menu_Window ) ;
toggleTabBar ( ) ;
QAction * toggleFullscreen = new QAction ( tr ( " Fullscreen " ) , this ) ;
QAction * toggleFullscreen = new QAction ( tr ( " Fullscreen " ) , settingOwner ) ;
toggleFullscreen - > setCheckable ( true ) ;
toggleFullscreen - > setChecked ( false ) ;
setup_Action ( FULLSCREEN , toggleFullscreen ,
FULLSCREEN_SHORTCUT , this , SLOT ( showFullscreen ( bool ) ) , menu_Window ) ;
setup_Action ( TOGGLE_BOOKMARKS , m_bookmarksDock - > toggleViewAction ( ) ,
setup_Action ( TOGGLE_BOOKMARKS , new QAction ( tr ( " Toggle Bookmarks " ) , settingOwner ) ,
TOGGLE_BOOKMARKS_SHORTCUT , NULL , NULL , menu_Window ) ;
menu_Window - > addSeparator ( ) ;
/* tabs position */
tabPosition = new QActionGroup ( this ) ;
QAction * tabBottom = new QAction ( tr ( " &Bottom " ) , this ) ;
QAction * tabTop = new QAction ( tr ( " &Top " ) , this ) ;
QAction * tabRight = new QAction ( tr ( " &Right " ) , this ) ;
QAction * tabLeft = new QAction ( tr ( " &Left " ) , this ) ;
tabPosition - > addAction ( tabTop ) ;
tabPosition - > addAction ( tabBottom ) ;
tabPosition - > addAction ( tabLeft ) ;
tabPosition - > addAction ( tabRight ) ;
for ( int i = 0 ; i < tabPosition - > actions ( ) . size ( ) ; + + i )
tabPosition - > actions ( ) . at ( i ) - > setCheckable ( true ) ;
if ( tabPosition = = NULL ) {
tabPosition = new QActionGroup ( this ) ;
QAction * tabBottom = new QAction ( tr ( " &Bottom " ) , this ) ;
QAction * tabTop = new QAction ( tr ( " &Top " ) , this ) ;
QAction * tabRight = new QAction ( tr ( " &Right " ) , this ) ;
QAction * tabLeft = new QAction ( tr ( " &Left " ) , this ) ;
tabPosition - > addAction ( tabTop ) ;
tabPosition - > addAction ( tabBottom ) ;
tabPosition - > addAction ( tabLeft ) ;
tabPosition - > addAction ( tabRight ) ;
for ( int i = 0 ; i < tabPosition - > actions ( ) . size ( ) ; + + i )
tabPosition - > actions ( ) . at ( i ) - > setCheckable ( true ) ;
}
if ( tabPosition - > actions ( ) . count ( ) > Properties : : Instance ( ) - > tabsPos )
tabPosition - > actions ( ) . at ( Properties : : Instance ( ) - > tabsPos ) - > setChecked ( true ) ;
@ -347,96 +394,84 @@ void MainWindow::setup_ViewMenu_Actions()
connect ( tabPosition , SIGNAL ( triggered ( QAction * ) ) ,
consoleTabulator , SLOT ( changeTabPosition ( QAction * ) ) ) ;
tabPosMenu = new QMenu ( tr ( " &Tabs Layout " ) , menu_Window ) ;
tabPosMenu - > setObjectName ( " tabPosMenu " ) ;
if ( tabPosMenu = = NULL ) {
tabPosMenu = new QMenu ( tr ( " &Tabs Layout " ) , menu_Window ) ;
tabPosMenu - > setObjectName ( " tabPosMenu " ) ;
for ( int i = 0 ; i < tabPosition - > actions ( ) . size ( ) ; + + i ) {
tabPosMenu - > addAction ( tabPosition - > actions ( ) . at ( i ) ) ;
}
for ( int i = 0 ; i < tabPosition - > actions ( ) . size ( ) ; + + i ) {
tabPosMenu - > addAction ( tabPosition - > actions ( ) . at ( i ) ) ;
}
connect ( menu_Window , SIGNAL ( hovered ( QAction * ) ) ,
this , SLOT ( updateActionGroup ( QAction * ) ) ) ;
connect ( menu_Window , SIGNAL ( hovered ( QAction * ) ) ,
this , SLOT ( updateActionGroup ( QAction * ) ) ) ;
}
menu_Window - > addMenu ( tabPosMenu ) ;
/* */
/* Scrollbar */
scrollBarPosition = new QActionGroup ( this ) ;
QAction * scrollNone = new QAction ( tr ( " &None " ) , this ) ;
QAction * scrollRight = new QAction ( tr ( " &Right " ) , this ) ;
QAction * scrollLeft = new QAction ( tr ( " &Left " ) , this ) ;
/* order of insertion is dep. on QTermWidget::ScrollBarPosition enum */
scrollBarPosition - > addAction ( scrollNone ) ;
scrollBarPosition - > addAction ( scrollLeft ) ;
scrollBarPosition - > addAction ( scrollRight ) ;
for ( int i = 0 ; i < scrollBarPosition - > actions ( ) . size ( ) ; + + i )
scrollBarPosition - > actions ( ) . at ( i ) - > setCheckable ( true ) ;
if ( Properties : : Instance ( ) - > scrollBarPos < scrollBarPosition - > actions ( ) . size ( ) )
scrollBarPosition - > actions ( ) . at ( Properties : : Instance ( ) - > scrollBarPos ) - > setChecked ( true ) ;
connect ( scrollBarPosition , SIGNAL ( triggered ( QAction * ) ) ,
if ( scrollBarPosition = = NULL ) {
scrollBarPosition = new QActionGroup ( this ) ;
QAction * scrollNone = new QAction ( tr ( " &None " ) , this ) ;
QAction * scrollRight = new QAction ( tr ( " &Right " ) , this ) ;
QAction * scrollLeft = new QAction ( tr ( " &Left " ) , this ) ;
/* order of insertion is dep. on QTermWidget::ScrollBarPosition enum */
scrollBarPosition - > addAction ( scrollNone ) ;
scrollBarPosition - > addAction ( scrollLeft ) ;
scrollBarPosition - > addAction ( scrollRight ) ;
for ( int i = 0 ; i < scrollBarPosition - > actions ( ) . size ( ) ; + + i )
scrollBarPosition - > actions ( ) . at ( i ) - > setCheckable ( true ) ;
if ( Properties : : Instance ( ) - > scrollBarPos < scrollBarPosition - > actions ( ) . size ( ) )
scrollBarPosition - > actions ( ) . at ( Properties : : Instance ( ) - > scrollBarPos ) - > setChecked ( true ) ;
connect ( scrollBarPosition , SIGNAL ( triggered ( QAction * ) ) ,
consoleTabulator , SLOT ( changeScrollPosition ( QAction * ) ) ) ;
scrollPosMenu = new QMenu ( tr ( " S&crollbar Layout " ) , menu_Window ) ;
scrollPosMenu - > setObjectName ( " scrollPosMenu " ) ;
}
if ( scrollPosMenu = = NULL ) {
scrollPosMenu = new QMenu ( tr ( " S&crollbar Layout " ) , menu_Window ) ;
scrollPosMenu - > setObjectName ( " scrollPosMenu " ) ;
for ( int i = 0 ; i < scrollBarPosition - > actions ( ) . size ( ) ; + + i ) {
scrollPosMenu - > addAction ( scrollBarPosition - > actions ( ) . at ( i ) ) ;
for ( int i = 0 ; i < scrollBarPosition - > actions ( ) . size ( ) ; + + i ) {
scrollPosMenu - > addAction ( scrollBarPosition - > actions ( ) . at ( i ) ) ;
}
}
menu_Window - > addMenu ( scrollPosMenu ) ;
/* Keyboard cursor shape */
keyboardCursorShape = new QActionGroup ( this ) ;
QAction * block = new QAction ( tr ( " &BlockCursor " ) , this ) ;
QAction * underline = new QAction ( tr ( " &UnderlineCursor " ) , this ) ;
QAction * ibeam = new QAction ( tr ( " &IBeamCursor " ) , this ) ;
/* order of insertion is dep. on QTermWidget::KeyboardCursorShape enum */
keyboardCursorShape - > addAction ( block ) ;
keyboardCursorShape - > addAction ( underline ) ;
keyboardCursorShape - > addAction ( ibeam ) ;
for ( int i = 0 ; i < keyboardCursorShape - > actions ( ) . size ( ) ; + + i )
keyboardCursorShape - > actions ( ) . at ( i ) - > setCheckable ( true ) ;
if ( Properties : : Instance ( ) - > keyboardCursorShape < keyboardCursorShape - > actions ( ) . size ( ) )
keyboardCursorShape - > actions ( ) . at ( Properties : : Instance ( ) - > keyboardCursorShape ) - > setChecked ( true ) ;
connect ( keyboardCursorShape , SIGNAL ( triggered ( QAction * ) ) ,
consoleTabulator , SLOT ( changeKeyboardCursorShape ( QAction * ) ) ) ;
if ( keyboardCursorShape = = NULL ) {
keyboardCursorShape = new QActionGroup ( this ) ;
QAction * block = new QAction ( tr ( " &BlockCursor " ) , this ) ;
QAction * underline = new QAction ( tr ( " &UnderlineCursor " ) , this ) ;
QAction * ibeam = new QAction ( tr ( " &IBeamCursor " ) , this ) ;
/* order of insertion is dep. on QTermWidget::KeyboardCursorShape enum */
keyboardCursorShape - > addAction ( block ) ;
keyboardCursorShape - > addAction ( underline ) ;
keyboardCursorShape - > addAction ( ibeam ) ;
for ( int i = 0 ; i < keyboardCursorShape - > actions ( ) . size ( ) ; + + i )
keyboardCursorShape - > actions ( ) . at ( i ) - > setCheckable ( true ) ;
if ( Properties : : Instance ( ) - > keyboardCursorShape < keyboardCursorShape - > actions ( ) . size ( ) )
keyboardCursorShape - > actions ( ) . at ( Properties : : Instance ( ) - > keyboardCursorShape ) - > setChecked ( true ) ;
connect ( keyboardCursorShape , SIGNAL ( triggered ( QAction * ) ) ,
consoleTabulator , SLOT ( changeKeyboardCursorShape ( QAction * ) ) ) ;
}
keyboardCursorShapeMenu = new QMenu ( tr ( " &Keyboard Cursor Shape " ) , menu_Window ) ;
keyboardCursorShapeMenu - > setObjectName ( " keyboardCursorShapeMenu " ) ;
if ( keyboardCursorShapeMenu = = NULL ) {
keyboardCursorShapeMenu = new QMenu ( tr ( " &Keyboard Cursor Shape " ) , menu_Window ) ;
keyboardCursorShapeMenu - > setObjectName ( " keyboardCursorShapeMenu " ) ;
for ( int i = 0 ; i < keyboardCursorShape - > actions ( ) . size ( ) ; + + i ) {
keyboardCursorShapeMenu - > addAction ( keyboardCursorShape - > actions ( ) . at ( i ) ) ;
for ( int i = 0 ; i < keyboardCursorShape - > actions ( ) . size ( ) ; + + i ) {
keyboardCursorShapeMenu - > addAction ( keyboardCursorShape - > actions ( ) . at ( i ) ) ;
}
}
menu_Window - > addMenu ( keyboardCursorShapeMenu ) ;
}
void MainWindow : : setup_ContextMenu_Actions ( QMenu * contextMenu ) const
{
contextMenu - > addAction ( Properties : : Instance ( ) - > actions [ COPY_SELECTION ] ) ;
contextMenu - > addAction ( Properties : : Instance ( ) - > actions [ PASTE_CLIPBOARD ] ) ;
contextMenu - > addAction ( Properties : : Instance ( ) - > actions [ PASTE_SELECTION ] ) ;
contextMenu - > addAction ( Properties : : Instance ( ) - > actions [ ZOOM_IN ] ) ;
contextMenu - > addAction ( Properties : : Instance ( ) - > actions [ ZOOM_OUT ] ) ;
contextMenu - > addAction ( Properties : : Instance ( ) - > actions [ ZOOM_RESET ] ) ;
contextMenu - > addSeparator ( ) ;
contextMenu - > addAction ( Properties : : Instance ( ) - > actions [ CLEAR_TERMINAL ] ) ;
contextMenu - > addAction ( Properties : : Instance ( ) - > actions [ SPLIT_HORIZONTAL ] ) ;
contextMenu - > addAction ( Properties : : Instance ( ) - > actions [ SPLIT_VERTICAL ] ) ;
# warning TODO / FIXME: disable the action when there is only one terminal
contextMenu - > addAction ( Properties : : Instance ( ) - > actions [ SUB_COLLAPSE ] ) ;
contextMenu - > addSeparator ( ) ;
contextMenu - > addAction ( Properties : : Instance ( ) - > actions [ TOGGLE_MENU ] ) ;
contextMenu - > addAction ( Properties : : Instance ( ) - > actions [ PREFERENCES ] ) ;
}
void MainWindow : : setupCustomDirs ( )
{
const QSettings settings ;
@ -451,7 +486,7 @@ void MainWindow::on_consoleTabulator_currentChanged(int)
void MainWindow : : toggleTabBar ( )
{
Properties : : Instance ( ) - > tabBarless
= ! Properties: : Instance ( ) - > actions[ SHOW_TAB_BAR ] - > isChecked ( ) ;
= ! actions[ SHOW_TAB_BAR ] - > isChecked ( ) ;
consoleTabulator - > showHideTabBar ( ) ;
}
@ -461,7 +496,7 @@ void MainWindow::toggleBorderless()
show ( ) ;
setWindowState ( Qt : : WindowActive ) ; /* don't loose focus on the window */
Properties : : Instance ( ) - > borderless
= Properties: : Instance ( ) - > actions[ HIDE_WINDOW_BORDERS ] - > isChecked ( ) ; realign ( ) ;
= actions[ HIDE_WINDOW_BORDERS ] - > isChecked ( ) ; realign ( ) ;
}
void MainWindow : : toggleMenu ( )
@ -478,6 +513,12 @@ void MainWindow::showFullscreen(bool fullscreen)
setWindowState ( windowState ( ) & ~ Qt : : WindowFullScreen ) ;
}
void MainWindow : : toggleBookmarks ( )
{
m_bookmarksDock - > toggleViewAction ( ) - > trigger ( ) ;
}
void MainWindow : : closeEvent ( QCloseEvent * ev )
{
if ( ! Properties : : Instance ( ) - > askOnExit
@ -550,6 +591,8 @@ void MainWindow::actProperties_triggered()
void MainWindow : : propertiesChanged ( )
{
rebuildActions ( ) ;
QApplication : : setStyle ( Properties : : Instance ( ) - > guiStyle ) ;
setWindowOpacity ( 1.0 - Properties : : Instance ( ) - > appTransparency / 100.0 ) ;
consoleTabulator - > setTabPosition ( ( QTabWidget : : TabPosition ) Properties : : Instance ( ) - > tabsPos ) ;
@ -560,7 +603,7 @@ void MainWindow::propertiesChanged()
m_bookmarksDock - > setVisible ( Properties : : Instance ( ) - > useBookmarks
& & Properties : : Instance ( ) - > bookmarksVisible ) ;
m_bookmarksDock- > toggleViewAction ( ) - > setVisible ( Properties : : Instance ( ) - > useBookmarks ) ;
actions[ TOGGLE_BOOKMARKS ] - > setVisible ( Properties : : Instance ( ) - > useBookmarks ) ;
if ( Properties : : Instance ( ) - > useBookmarks )
{
@ -569,7 +612,6 @@ void MainWindow::propertiesChanged()
onCurrentTitleChanged ( consoleTabulator - > currentIndex ( ) ) ;
Properties : : Instance ( ) - > saveSettings ( ) ;
realign ( ) ;
}
@ -585,8 +627,9 @@ void MainWindow::realign()
geometry . moveCenter ( desktop . center ( ) ) ;
// do not use 0 here - we need to calculate with potential panel on top
geometry . setTop ( desktop . top ( ) ) ;
setGeometry ( geometry ) ;
if ( geometry ! = this - > geometry ( ) ) {
setGeometry ( geometry ) ;
}
}
}
@ -645,7 +688,12 @@ bool MainWindow::event(QEvent *event)
void MainWindow : : newTerminalWindow ( )
{
MainWindow * w = new MainWindow ( m_initWorkDir , m_initShell , false ) ;
TerminalConfig cfg ;
TermWidgetHolder * ch = consoleTabulator - > terminalHolder ( ) ;
if ( ch )
cfg . provideCurrentDirectory ( ch - > currentTerminal ( ) - > impl ( ) - > workingDirectory ( ) ) ;
MainWindow * w = new MainWindow ( cfg , false ) ;
w - > show ( ) ;
}
@ -662,6 +710,7 @@ void MainWindow::bookmarksDock_visibilityChanged(bool visible)
void MainWindow : : addNewTab ( )
{
TerminalConfig cfg ;
if ( Properties : : Instance ( ) - > terminalsPreset = = 3 )
consoleTabulator - > preset4Terminals ( ) ;
else if ( Properties : : Instance ( ) - > terminalsPreset = = 2 )
@ -669,7 +718,8 @@ void MainWindow::addNewTab()
else if ( Properties : : Instance ( ) - > terminalsPreset = = 1 )
consoleTabulator - > preset2Horizontal ( ) ;
else
consoleTabulator - > addNewTab ( ) ;
consoleTabulator - > addNewTab ( cfg ) ;
updateDisabledActions ( ) ;
}
void MainWindow : : onCurrentTitleChanged ( int index )
@ -695,7 +745,7 @@ bool MainWindow::hasMultipleSubterminals()
return consoleTabulator - > terminalHolder ( ) - > findChildren < TermWidget * > ( ) . count ( ) > 1 ;
}
void MainWindow : : aboutToShowActionsMenu ( )
void MainWindow : : updateDisabledActions ( )
{
const QList < QAction * > actions = menu_Actions - > actions ( ) ;
for ( QAction * action : actions ) {
@ -705,3 +755,39 @@ void MainWindow::aboutToShowActionsMenu()
}
}
}
QMap < QString , QAction * > & MainWindow : : leaseActions ( ) {
return actions ;
}
# ifdef HAVE_QDBUS
QDBusObjectPath MainWindow : : getActiveTab ( )
{
return qobject_cast < TermWidgetHolder * > ( consoleTabulator - > currentWidget ( ) ) - > getDbusPath ( ) ;
}
QList < QDBusObjectPath > MainWindow : : getTabs ( )
{
QList < QDBusObjectPath > tabs ;
for ( int i = 0 ; i < consoleTabulator - > count ( ) ; + + i )
{
tabs . push_back ( qobject_cast < TermWidgetHolder * > ( consoleTabulator - > widget ( i ) ) - > getDbusPath ( ) ) ;
}
return tabs ;
}
QDBusObjectPath MainWindow : : newTab ( const QHash < QString , QVariant > & termArgs )
{
TerminalConfig cfg = TerminalConfig : : fromDbus ( termArgs ) ;
int idx = consoleTabulator - > addNewTab ( cfg ) ;
return qobject_cast < TermWidgetHolder * > ( consoleTabulator - > widget ( idx ) ) - > getDbusPath ( ) ;
}
void MainWindow : : closeWindow ( )
{
close ( ) ;
}
# endif