Commit 3ddc6496 authored by Jekyll Wu's avatar Jekyll Wu

Add cmdline options for the visibility of menubar and tabbar

Since the menubar and tarbar settings are now global instead of per
profile , those cmdline options are useful to allow users to override
the defautl behavior.

The --hide-menubar and --hide-tabbar options can be used together
to simulate the miminal interface of xterm. I'm not sure whether
--show-menubar and --show-tabbar will be widely used , but add them at
the moment for the sake of completeness.
parent 927848c5
......@@ -866,6 +866,30 @@ title: This is the title;; command: run me
<parameter>dir</parameter> as the initial working directory.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--show-menubar</option></term>
<listitem><para><action>Show</action> the menubar, overriding the default behavior.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--hide-menubar</option></term>
<listitem><para><action>Hide</action> the menubar, overriding the default behavior.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--show-tabbar</option></term>
<listitem><para><action>Show</action> the tabbar, overriding the default behavior.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--hide-tabbar</option></term>
<listitem><para><action>Hide</action> the tabbar, overriding the default behavior.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--hold, --noclose</option></term>
<listitem><para><action>Do not close</action> the initial session automatically when it ends.
......
......@@ -298,7 +298,29 @@ MainWindow* Application::processWindowArgs(KCmdLineArgs* args)
if (window == 0) {
window = newMainWindow();
// override default menubar visibility
if (args->isSet("show-menubar")) {
window->setMenuBarInitialVisibility(true);
}
if (args->isSet("hide-menubar")) {
window->setMenuBarInitialVisibility(false);
}
// override default tabbbar visibility
// FIXME: remove those magic number
// see ViewContainer::NavigationVisibility
if (args->isSet("show-tabbar")) {
// always show
window->setNavigationVisibility(0);
}
if (args->isSet("hide-tabbar")) {
// never show
window->setNavigationVisibility(2);
}
}
return window;
}
......
......@@ -62,6 +62,7 @@ MainWindow::MainWindow()
: KXmlGuiWindow()
, _bookmarkHandler(0)
, _pluggedController(0)
, _menuBarInitialVisibility(true)
, _menuBarInitialVisibilityApplied(false)
{
// It is userful to have translucent terminal area
......@@ -630,26 +631,50 @@ void MainWindow::showSettingsDialog()
void MainWindow::applyKonsoleSettings()
{
setMenuBarInitialVisibility(KonsoleSettings::showMenuBarByDefault());
if (KonsoleSettings::allowMenuAccelerators()) {
restoreMenuAccelerators();
} else {
removeMenuAccelerators();
}
ViewManager::NavigationOptions options;
options.visibility = KonsoleSettings::tabBarVisibility();
options.position = KonsoleSettings::tabBarPosition();
options.newTabBehavior = KonsoleSettings::newTabBehavior();
options.showQuickButtons = KonsoleSettings::showQuickButtons();
options.styleSheet = KonsoleSettings::tabBarStyleSheet();
_viewManager->updateNavigationOptions(options);
setNavigationVisibility(KonsoleSettings::tabBarVisibility());
setNavigationPosition(KonsoleSettings::tabBarPosition());
setNavigationStyleSheet(KonsoleSettings::tabBarStyleSheet());
setNavigationBehavior(KonsoleSettings::newTabBehavior());
setShowQuickButtons(KonsoleSettings::showQuickButtons());
// setAutoSaveSettings("MainWindow", KonsoleSettings::saveGeometryOnExit());
updateWindowCaption();
}
void MainWindow::setNavigationVisibility(int visibility)
{
_viewManager->setNavigationVisibility(visibility);
}
void MainWindow::setNavigationPosition(int position)
{
_viewManager->setNavigationPosition(position);
}
void MainWindow::setNavigationStyleSheet(const QString& styleSheet)
{
_viewManager->setNavigationStyleSheet(styleSheet);
}
void MainWindow::setNavigationBehavior(int behavior)
{
_viewManager->setNavigationBehavior(behavior);
}
void MainWindow::setShowQuickButtons(bool show)
{
_viewManager->setShowQuickButtons(show);
}
void MainWindow::activateMenuBar()
{
const QList<QAction*> menuActions = menuBar()->actions();
......@@ -689,6 +714,10 @@ void MainWindow::configureNotifications()
KNotifyConfigWidget::configure(this);
}
void MainWindow::setMenuBarInitialVisibility(bool visible)
{
_menuBarInitialVisibility = visible;
}
void MainWindow::showEvent(QShowEvent* aEvent)
{
// Make sure the 'initial' visibility is applied only once.
......@@ -698,9 +727,8 @@ void MainWindow::showEvent(QShowEvent* aEvent)
// moment. Otherwise, the initial visibility will be determined by
// what KMainWindow has automatically stored in konsolerc, but not by
// what users has explicitly configured .
menuBar()->setVisible(KonsoleSettings::showMenuBarByDefault());
_toggleMenuBarAction->setChecked(KonsoleSettings::showMenuBarByDefault());
menuBar()->setVisible(_menuBarInitialVisibility);
_toggleMenuBarAction->setChecked(_menuBarInitialVisibility);
_menuBarInitialVisibilityApplied = true;
}
......
......@@ -99,6 +99,17 @@ public:
*/
void setFocus();
/**
* Set the initial visibility of the menubar.
*/
void setMenuBarInitialVisibility(bool visible);
void setNavigationVisibility(int visibility);
void setNavigationPosition(int position);
void setNavigationStyleSheet(const QString& stylesheet);
void setNavigationBehavior(int behavior);
void setShowQuickButtons(bool show);
signals:
/**
......@@ -196,6 +207,7 @@ private:
QPointer<SessionController> _pluggedController;
bool _menuBarInitialVisibility;
bool _menuBarInitialVisibilityApplied;
};
......
......@@ -631,7 +631,20 @@ ViewContainer* ViewManager::createContainer()
container = new StackedViewContainer(_viewSplitter);
}
applyNavigationOptions(container);
// FIXME: these code feels duplicated
container->setNavigationVisibility(_navigationVisibility);
container->setNavigationPosition(_navigationPosition);
container->setStyleSheet(_navigationStyleSheet);
if (_showQuickButtons) {
container->setFeatures(container->features()
| ViewContainer::QuickNewView
| ViewContainer::QuickCloseView);
container->setNewViewMenu(createNewViewMenu());
} else {
container->setFeatures(container->features()
& ~ViewContainer::QuickNewView
& ~ViewContainer::QuickCloseView);
}
// connect signals and slots
connect(container , SIGNAL(viewAdded(QWidget*,ViewProperties*)) , _containerSignalMapper ,
......@@ -1047,45 +1060,58 @@ void ViewManager::closeTabFromContainer(ViewContainer* container, QWidget* tab)
controller->closeSession();
}
void ViewManager::updateNavigationOptions(NavigationOptions options)
void ViewManager::setNavigationVisibility(int visibility)
{
// since we have defined all valid values in konsole.kcfg, we can be sure
// all these values are safe to be cast into corresponding enum.
_navigationVisibility =
static_cast<ViewContainer::NavigationVisibility>(options.visibility);
_navigationPosition =
static_cast<ViewContainer::NavigationPosition>(options.position);
_newTabBehavior =
static_cast<NewTabBehavior>(options.newTabBehavior);
_showQuickButtons = options.showQuickButtons;
_navigationStyleSheet = options.styleSheet;
static_cast<ViewContainer::NavigationVisibility>(visibility);
foreach(ViewContainer* container, _viewSplitter->containers()) {
applyNavigationOptions(container);
container->setNavigationVisibility(_navigationVisibility);
}
}
void ViewManager::setNavigationPosition(int position)
{
_navigationPosition =
static_cast<ViewContainer::NavigationPosition>(position);
foreach(ViewContainer* container, _viewSplitter->containers()) {
Q_ASSERT(container->supportedNavigationPositions().contains(_navigationPosition));
container->setNavigationPosition(_navigationPosition);
}
}
void ViewManager::applyNavigationOptions(ViewContainer* container)
void ViewManager::setNavigationStyleSheet(const QString& styleSheet)
{
_navigationStyleSheet = styleSheet;
container->setNavigationVisibility(_navigationVisibility);
foreach(ViewContainer* container, _viewSplitter->containers()) {
container->setStyleSheet(_navigationStyleSheet);
}
}
Q_ASSERT(container->supportedNavigationPositions().contains(_navigationPosition));
container->setNavigationPosition(_navigationPosition);
void ViewManager::setShowQuickButtons(bool show)
{
_showQuickButtons = show;
if (_showQuickButtons) {
container->setFeatures(container->features()
| ViewContainer::QuickNewView
| ViewContainer::QuickCloseView);
container->setNewViewMenu(createNewViewMenu());
} else {
container->setFeatures(container->features()
& ~ViewContainer::QuickNewView
& ~ViewContainer::QuickCloseView);
foreach(ViewContainer* container, _viewSplitter->containers()) {
if (_showQuickButtons) {
container->setFeatures(container->features()
| ViewContainer::QuickNewView
| ViewContainer::QuickCloseView);
container->setNewViewMenu(createNewViewMenu());
} else {
container->setFeatures(container->features()
& ~ViewContainer::QuickNewView
& ~ViewContainer::QuickCloseView);
}
}
}
container->setStyleSheet(_navigationStyleSheet);
void ViewManager::setNavigationBehavior(int behavior)
{
_newTabBehavior = static_cast<NewTabBehavior>(behavior);
}
#include "ViewManager.moc"
......
......@@ -136,14 +136,6 @@ public:
PutNewTabAfterCurrentTab = 1
};
struct NavigationOptions {
int visibility;
int position;
int newTabBehavior;
bool showQuickButtons;
QString styleSheet;
};
/**
* Sets the type of widget provided to navigate between open sessions
* in a container. The changes will only apply to newly created containers.
......@@ -176,8 +168,11 @@ public:
void saveSessions(KConfigGroup& group);
void restoreSessions(const KConfigGroup& group);
void updateNavigationOptions(NavigationOptions options);
void applyNavigationOptions(ViewContainer* container);
void setNavigationVisibility(int visibility);
void setNavigationPosition(int position);
void setNavigationBehavior(int behavior);
void setNavigationStyleSheet(const QString& styleSheet);
void setShowQuickButtons(bool show);
int managerId() const;
......
......@@ -169,6 +169,10 @@ void fillCommandLineOptions(KCmdLineOptions& options)
options.add("background-mode",
ki18n("Start Konsole in the background and bring to the front"
" when Ctrl+Shift+F12 (by default) is pressed"));
options.add("show-menubar", ki18n("Show the menubar, overriding the default setting"));
options.add("hide-menubar", ki18n("Hide the menubar, overriding the default setting"));
options.add("show-tabbar", ki18n("Show the tabbar, overriding the default setting"));
options.add("hide-tabbar", ki18n("Hide the tabbar, overriding the default setting"));
options.add("list-profiles", ki18n("List the available profiles"));
options.add("list-profile-properties",
ki18n("List all the profile properties names and their type"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment