summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--kate/tabbarextension/plugin_katetabbarextension.cpp105
-rw-r--r--kate/tabbarextension/plugin_katetabbarextension.h82
2 files changed, 108 insertions, 79 deletions
diff --git a/kate/tabbarextension/plugin_katetabbarextension.cpp b/kate/tabbarextension/plugin_katetabbarextension.cpp
index 8ceb642..462161b 100644
--- a/kate/tabbarextension/plugin_katetabbarextension.cpp
+++ b/kate/tabbarextension/plugin_katetabbarextension.cpp
@@ -62,28 +62,17 @@ extern "C"
}
}
-KatePluginFactory::KatePluginFactory()
+TQObject* KatePluginFactory::createObject(TQObject *parent,
+ const char *name, const char*, const TQStringList&)
{
- s_instance = new TDEInstance( "kate" );
-}
-
-KatePluginFactory::~KatePluginFactory()
-{
- delete s_instance;
-}
-
-TQObject* KatePluginFactory::createObject(
- TQObject* parent, const char* name, const char*, const TQStringList & )
-{
- return new KatePluginTabBarExtension( parent, name );
+ return new KatePluginTabBarExtension(parent, name);
}
TDEInstance* KatePluginFactory::s_instance = 0L;
// BEGIN KatePluginTabBarExtension
-KatePluginTabBarExtension::KatePluginTabBarExtension(
- TQObject* parent, const char* name )
- : Kate::Plugin ( (Kate::Application*)parent, name ),
+KatePluginTabBarExtension::KatePluginTabBarExtension(TQObject *parent, const char *name)
+ : Kate::Plugin((Kate::Application*)parent, name),
pConfig(new TDEConfig("katetabbarextensionpluginrc"))
{
pConfig->setGroup("global");
@@ -93,7 +82,7 @@ KatePluginTabBarExtension::~KatePluginTabBarExtension()
{
while (m_views.count() > 0)
{
- removeView(m_views.at(0)->win);
+ removeView(m_views.at(0)->win);
}
delete pConfig;
@@ -103,11 +92,12 @@ void KatePluginTabBarExtension::addView(Kate::MainWindow *win)
{
PluginView *view = new PluginView ();
- bool bHoriz = pConfig->readBoolEntry("horizontal orientation", true);
- bool sort = pConfig->readBoolEntry("sort", true);
+ bool bHoriz = pConfig->readBoolEntry("horizontal orientation", true);
+ bool bSort = pConfig->readBoolEntry("sort", true);
+ bool bCloseOnMiddleClick = pConfig->readBoolEntry("closeOnMiddleClick", false);
- view->tabbar = new KateTabBarExtension( application()->documentManager(),
- win, bHoriz, sort, 0, "tabs_hbox");
+ view->tabbar = new KateTabBarExtension(application()->documentManager(),
+ win, bHoriz, bSort, bCloseOnMiddleClick, 0, "tabs_hbox");
new KWidgetAction(view->tabbar, "tab_bar_widget",
TDEShortcut::null(), 0, 0, view->actionCollection(), "tabbar_widget");
@@ -122,8 +112,8 @@ void KatePluginTabBarExtension::addView(Kate::MainWindow *win)
TDEToolBar* toolbar = dynamic_cast<TDEToolBar*>
(win->guiFactory()->container("tabbarExtensionToolBar", view));
if (toolbar) {
- connect(toolbar, TQT_SIGNAL( orientationChanged(Qt::Orientation) ),
- view->tabbar, TQT_SLOT( slotMoved(Qt::Orientation) ));
+ connect(toolbar, TQT_SIGNAL(orientationChanged(Qt::Orientation)),
+ view->tabbar, TQT_SLOT(slotMoved(Qt::Orientation)));
}
}
@@ -140,6 +130,7 @@ void KatePluginTabBarExtension::removeView(Kate::MainWindow *win)
pConfig->writeEntry("horizontal orientation",
view->tabbar->orientation()==Qt::Horizontal?true:false);
pConfig->writeEntry("sort", view->tabbar->sortByName());
+ pConfig->writeEntry("closeOnMiddleClick", view->tabbar->closeOnMiddleClick());
pConfig->sync();
}
@@ -161,14 +152,16 @@ Kate::PluginConfigPage* KatePluginTabBarExtension::configPage(
return (Kate::PluginConfigPage*)p;
}
-void KatePluginTabBarExtension::initConfigPage( KateTabBarExtensionConfigPage* p )
+void KatePluginTabBarExtension::initConfigPage(KateTabBarExtensionConfigPage *p)
{
p->pSortAlpha->setChecked(m_views.at(0)->tabbar->sortByName());
+ p->pCloseOnMiddleClick->setChecked(m_views.at(0)->tabbar->closeOnMiddleClick());
}
-void KatePluginTabBarExtension::applyConfig( KateTabBarExtensionConfigPage* p )
+void KatePluginTabBarExtension::applyConfig(KateTabBarExtensionConfigPage *p)
{
m_views.at(0)->tabbar->setSortByName(p->pSortAlpha->isChecked());
+ m_views.at(0)->tabbar->setCloseOnMiddleClick(p->pCloseOnMiddleClick->isChecked());
// sync m_config in destructor
}
// END KatePluginTabBarExtension
@@ -191,13 +184,6 @@ KateTabBarButton::KateTabBarButton(Kate::ViewManager* pViewManager,
connect(this, TQT_SIGNAL(toggled(bool)), TQT_SLOT(setOn(bool)));
}
-KateTabBarButton::~KateTabBarButton() {}
-
-uint KateTabBarButton::documentNumber()
-{
- return myDocID;
-}
-
void KateTabBarButton::setDirty(bool d)
{
if (d) {
@@ -221,6 +207,20 @@ void KateTabBarButton::setText( const TQString& newText)
}
}
+void KateTabBarButton::mouseReleaseEvent(TQMouseEvent *e)
+{
+ // Only handle middle click events when no keyboard modifier is pressed
+ if (e->button() == TQt::MidButton && !(e->state() & TQt::KeyButtonMask))
+ {
+ emit middleButtonPressed(this);
+ }
+ else
+ {
+ // Invoke parent handler for unwanted events
+ TQPushButton::mouseReleaseEvent(e);
+ }
+}
+
TQString KateTabBarButton::fullName() const
{
if (doc) {
@@ -262,9 +262,9 @@ void KateTabBarButton::setOn(bool on)
// END KateTabBarButton
// BEGIN KateTabBarExtension
-KateTabBarExtension::KateTabBarExtension( Kate::DocumentManager *pDocManager,
+KateTabBarExtension::KateTabBarExtension(Kate::DocumentManager *pDocManager,
Kate::MainWindow *win, bool bHorizOrientation, bool bSort,
- TQWidget* parent, const char* name, WFlags f )
+ bool bCloseOnMiddleClick, TQWidget* parent, const char* name, WFlags f)
: TQWidget(parent, name, f),
pCurrentTab(0), m_win(win), m_docManager(pDocManager), m_sort(false)
{
@@ -291,10 +291,9 @@ KateTabBarExtension::KateTabBarExtension( Kate::DocumentManager *pDocManager,
TQT_SLOT(slotDocumentDeleted(uint)));
setSortByName(bSort);
+ setCloseOnMiddleClick(bCloseOnMiddleClick);
}
-KateTabBarExtension::~KateTabBarExtension() {}
-
void KateTabBarExtension::slotMoved(Qt::Orientation o)
{
// the tabbar moved (top, right, bottom, left or fluently)
@@ -311,16 +310,6 @@ void KateTabBarExtension::slotMoved(Qt::Orientation o)
m_orientation = o;
}
-Qt::Orientation KateTabBarExtension::orientation() const
-{
- return m_orientation;
-}
-
-bool KateTabBarExtension::sortByName() const
-{
- return m_sort;
-}
-
void KateTabBarExtension::setSortByName(bool sbn)
{
if (m_sort != sbn) {
@@ -359,6 +348,8 @@ void KateTabBarExtension::slotDocumentCreated (Kate::Document *doc)
KateTabBarButton* tab = new KateTabBarButton(m_win->viewManager(), doc, this);
connect(tab, TQT_SIGNAL(myToggled(KateTabBarButton*)),
TQT_SLOT(slotActivateView(KateTabBarButton*)));
+ connect(tab, TQT_SIGNAL(middleButtonPressed(KateTabBarButton*)),
+ TQT_SLOT(slotRequestDocClose(KateTabBarButton*)));
connect(doc, TQT_SIGNAL(nameChanged(Kate::Document *)),
TQT_SLOT(slotNameChanged(Kate::Document *)));
connect(doc, TQT_SIGNAL(modStateChanged(Kate::Document *)),
@@ -471,6 +462,14 @@ void KateTabBarExtension::slotViewChanged ()
}
}
}
+
+void KateTabBarExtension::slotRequestDocClose(KateTabBarButton *tab)
+{
+ if (closeOnMiddleClick() && tab)
+ {
+ m_docManager->closeDocument(tab->document());
+ }
+}
// END KateTabBarExtension
// BEGIN KateTabBarExtensionConfigPage
@@ -481,23 +480,17 @@ KateTabBarExtensionConfigPage::KateTabBarExtensionConfigPage(
TQVBoxLayout* top = new TQVBoxLayout(this, 0,
KDialogBase::spacingHint());
- TQGroupBox* gb = new TQGroupBox( i18n("Sorting Behavior"),
- this, "tab_bar_extension_config_page_layout" );
- gb->setColumnLayout(1, Qt::Vertical);
+ TQGroupBox* gb = new TQGroupBox(1, Qt::Horizontal, i18n("Behavior options"),
+ this, "tab_bar_extension_config_page_layout" );
gb->setInsideSpacing(KDialogBase::spacingHint());
pSortAlpha = new TQCheckBox(i18n("Sort files alphabetically"), gb);
+ pCloseOnMiddleClick = new TQCheckBox(i18n("Close document on mouse middle click"), gb);
top->add(gb);
top->addStretch(1);
// throw signal changed
connect(pSortAlpha, TQT_SIGNAL(toggled(bool)), this, TQT_SIGNAL(changed()));
-}
-
-KateTabBarExtensionConfigPage::~KateTabBarExtensionConfigPage() {}
-
-void KateTabBarExtensionConfigPage::apply()
-{
- emit configPageApplyRequest( this );
+ connect(pCloseOnMiddleClick, TQT_SIGNAL(toggled(bool)), this, TQT_SIGNAL(changed()));
}
// END KateTabBarExtensionConfigPage
diff --git a/kate/tabbarextension/plugin_katetabbarextension.h b/kate/tabbarextension/plugin_katetabbarextension.h
index 7ce300c..0d16d69 100644
--- a/kate/tabbarextension/plugin_katetabbarextension.h
+++ b/kate/tabbarextension/plugin_katetabbarextension.h
@@ -48,7 +48,7 @@ class TQCheckBox;
class KateTabBarButton;
/**
- * Same as TQPtrList. Only difference is: overwrite comapreItems() for sorting reason.
+ * Same as TQPtrList. Only difference is: overwrite compareItems() for sorting reason.
*/
class MyPtrList : public TQPtrList <KateTabBarButton>
{
@@ -61,14 +61,14 @@ class MyPtrList : public TQPtrList <KateTabBarButton>
class KatePluginFactory : public KLibFactory
{
Q_OBJECT
-
+
public:
- KatePluginFactory();
- virtual ~KatePluginFactory();
+ KatePluginFactory() { s_instance = new TDEInstance( "kate" ); }
+ virtual ~KatePluginFactory() { delete s_instance; }
- virtual TQObject* createObject( TQObject* parent = 0, const char* pname = 0,
- const char* name = TQOBJECT_OBJECT_NAME_STRING, const TQStringList &args = TQStringList() );
+ virtual TQObject* createObject(TQObject *parent = 0, const char *pname = 0,
+ const char *name = TQOBJECT_OBJECT_NAME_STRING, const TQStringList &args = TQStringList());
private:
static TDEInstance* s_instance;
@@ -97,12 +97,17 @@ class KateTabBarButton: public TQPushButton
/**
* standard destructor (emtpy)
*/
- ~KateTabBarButton();
+ ~KateTabBarButton() {}
/**
* @return the unique document ID
*/
- uint documentNumber();
+ uint documentNumber() { return myDocID; }
+
+ /**
+ * @return the document pointer
+ */
+ Kate::Document* document() { return doc; }
/**
* get the document's full name (eg. main.cpp), used for comparison
@@ -126,7 +131,13 @@ class KateTabBarButton: public TQPushButton
* set text for this tab
* @param newText new text
*/
- virtual void setText( const TQString& newText);
+ virtual void setText(const TQString& newText);
+
+ /**
+ * mouse release event handler to provide middle click functionality
+ * @param e the mouse event
+ */
+ virtual void mouseReleaseEvent(TQMouseEvent *e);
signals:
/**
@@ -135,6 +146,12 @@ class KateTabBarButton: public TQPushButton
*/
void myToggled(KateTabBarButton* tab);
+ /**
+ * signal emitted when the middle button is pressed
+ * @param tab pointer to the button that emitted the signal
+ */
+ void middleButtonPressed(KateTabBarButton* tab);
+
public slots:
/**
* control the ToggleButton
@@ -168,22 +185,23 @@ class KateTabBarExtension : public TQWidget
* @param name name of widget
* @param f widget flags
*/
- KateTabBarExtension( Kate::DocumentManager *pDocManager,
+ KateTabBarExtension(Kate::DocumentManager *pDocManager,
Kate::MainWindow *win, bool bHorizOrientation, bool bSort,
- TQWidget * parent = 0, const char * name = 0, WFlags f = 0 );
+ bool bCloseOnMiddleClick, TQWidget *parent = 0,
+ const char *name = 0, WFlags f = 0);
/** standard destructor */
- ~KateTabBarExtension();
+ ~KateTabBarExtension() {}
/**
* @return the tabbar's orientation
*/
- Qt::Orientation orientation() const;
+ Qt::Orientation orientation() const { return m_orientation; }
/**
* @return true, when sorting is alphabetically
*/
- bool sortByName() const;
+ bool sortByName() const { return m_sort; }
/**
* set sorting type
@@ -196,6 +214,17 @@ class KateTabBarExtension : public TQWidget
*/
void updateSort();
+ /**
+ * @return true when closing a document with mouse middle click is allowed
+ */
+ bool closeOnMiddleClick() const { return m_closeOnMiddleClick; }
+
+ /**
+ * set flag to enable/disable "close document on mouse middle click" feature
+ * @param cmc true -> enabled, false -> disabled
+ */
+ void setCloseOnMiddleClick(bool cmc) { m_closeOnMiddleClick = cmc; }
+
public slots:
/**
* called when a new document is created/loaded
@@ -246,15 +275,22 @@ class KateTabBarExtension : public TQWidget
*/
void slotMoved(Qt::Orientation o);
+ /**
+ * called when we want to close the document associated with the tab
+ * @param tab pointer to the button that represents the active view
+ */
+ void slotRequestDocClose(KateTabBarButton *tab);
+
private:
KateTabBarButton* pCurrentTab; ///< pointer to the current tab
- TQBoxLayout* top; ///< layout that contains all tabs
+ TQBoxLayout* top; ///< layout that contains all tabs
Kate::MainWindow* m_win; ///< pointer to the main window
Kate::DocumentManager* m_docManager; ///< pointer to the document manager
// TQPtrList <KateTabBarButton> m_tabs; ///< list containing all tabs
MyPtrList m_tabs; ///< list containing all tabs
Qt::Orientation m_orientation; ///< save tabbar's orientation
bool m_sort; ///< how to sort
+ bool m_closeOnMiddleClick; ///< Enable/disable "close document on mouse middle click" feature
};
/**
@@ -268,17 +304,16 @@ class KateTabBarExtensionConfigPage : public Kate::PluginConfigPage
friend class KatePluginTabBarExtension;
public:
- KateTabBarExtensionConfigPage (TQObject* parent = 0L, TQWidget *parentWidget = 0L);
- ~KateTabBarExtensionConfigPage ();
+ KateTabBarExtensionConfigPage(TQObject* parent = 0L, TQWidget *parentWidget = 0L);
+ ~KateTabBarExtensionConfigPage() {}
/**
* Reimplemented from Kate::PluginConfigPage
* just emits configPageApplyRequest( this ).
*/
- virtual void apply();
-
- virtual void reset () { ; }
- virtual void defaults () { ; }
+ virtual void apply() { emit configPageApplyRequest(this); }
+ virtual void reset() {}
+ virtual void defaults() {}
signals:
/**
@@ -293,6 +328,7 @@ class KateTabBarExtensionConfigPage : public Kate::PluginConfigPage
private:
TQCheckBox* pSortAlpha;
+ TQCheckBox* pCloseOnMiddleClick;
};
class KatePluginTabBarExtension : public Kate::Plugin, Kate::PluginViewInterface, Kate::PluginConfigInterfaceExtension
@@ -301,7 +337,7 @@ class KatePluginTabBarExtension : public Kate::Plugin, Kate::PluginViewInterface
public:
- KatePluginTabBarExtension( TQObject* parent = 0, const char* name = 0 );
+ KatePluginTabBarExtension(TQObject* parent = 0, const char* name = 0);
virtual ~KatePluginTabBarExtension();
void addView (Kate::MainWindow *win);
@@ -311,7 +347,7 @@ class KatePluginTabBarExtension : public Kate::Plugin, Kate::PluginViewInterface
Kate::PluginConfigPage *configPage (uint , TQWidget *w, const char *name=0);
TQString configPageName(uint) const { return i18n("Tab Bar Extension"); }
TQString configPageFullName(uint) const { return i18n("Configure Tab Bar Extension"); }
- TQPixmap configPagePixmap (uint number = 0, int size = TDEIcon::SizeSmall) const { return 0L; }
+ TQPixmap configPagePixmap (uint = 0, int = TDEIcon::SizeSmall) const { return 0L; }
public slots:
void applyConfig( KateTabBarExtensionConfigPage* );