Re: [PATCH] Add new "Open new Tab"-Tab to the tab bar
TK Soh <[email protected]>
| Newsgroups | gmane.editors.nedit.user |
|---|---|
| Message-ID | <[email protected]> |
OT: where do you host your nedit repo? I'm trying to refresh my local clone. Thanks. TK On Sun, Oct 25, 2009 at 2:24 PM, Bert Wesarg <bert.wesarg-gM/[email protected]> wrote: > On Fri, Oct 23, 2009 at 07:26, Greg Edwards <[email protected]> wrote: >> With the advent of tabbed web browsers, some of which have a "+" button on >> the far right of the tab area to create a new tab (certainly my Safari 4 >> anyway), I now find myself hitting the Nedit "x" button to open a new tab, >> but of course closing the current Nedit tab instead, quite the opposite of >> what I wanted. >> How much chance would there be to make the "x" act as a "+", and put an "x" >> on the Motif tabs ? (I know the answer to part B sadly - a Motif tab is just >> some sort of XmLabel subclass with a tabby shape, no chance of "x" there). > I personally like the 'floating' "+" from firefox 3.5 more, that is, a 'tab' > right of all other tabs, and if you click it, you get a new Untitled, and only > one close button, like it is today in NEdit. Here is a rough patch that > implements this. > > BTW, you can put any widget inside the tabs, NEdit puts a BubbleButton in to > get a tooltip. > > Regards, > Bert > > --- > Microline/XmL/Folder.c | 2 +- > source/window.c | 56 ++++++++++++++++++++++++++++++++++++------------ > 2 files changed, 43 insertions(+), 15 deletions(-) > > diff --git a/Microline/XmL/Folder.c b/Microline/XmL/Folder.c > index 270cf96..2610199 100644 > --- a/Microline/XmL/Folder.c > +++ b/Microline/XmL/Folder.c > @@ -1658,7 +1658,7 @@ ConstraintInitialize(Widget req, > /* add child to tabs list */ > if (f->folder.tabAllocCount < f->folder.tabCount + 1) > { > - f->folder.tabAllocCount *= 2; > + f->folder.tabAllocCount += 32; > f->folder.tabs = (Widget *)realloc((char *)f->folder.tabs, > sizeof(Widget) * f->folder.tabAllocCount); > } > diff --git a/source/window.c b/source/window.c > index 89473a8..995eea2 100644 > --- a/source/window.c > +++ b/source/window.c > @@ -152,7 +152,7 @@ static Pixmap createBitmapWithDepth(Widget w, char *data, unsigned int width, > unsigned int height); > static WindowInfo *getNextTabWindow(WindowInfo *window, int direction, > int crossWin, int wrap); > -static Widget addTab(Widget folder, const char *string); > +static Widget addTab(Widget folder, const char *string, int isNewTabTab); > static int compareWindowNames(const void *windowA, const void *windowB); > static int getTabPosition(Widget tab); > static Widget manageToolBars(Widget toolBarsForm); > @@ -614,7 +614,8 @@ WindowInfo *CreateWindow(const char *name, char *geometry, int iconic) > XtAddCallback(window->tabBar, XmNactivateCallback, > raiseTabCB, NULL); > > - window->tab = addTab(window->tabBar, name); > + addTab(window->tabBar, " + ", True); > + window->tab = addTab(window->tabBar, name, False); > > /* A form to hold the stats line text and line/col widgets */ > window->statsLineForm = XtVaCreateWidget("statsLineForm", > @@ -821,19 +822,23 @@ static void tabClickEH(Widget w, XtPointer clientData, XEvent *event) > /* > ** add a tab to the tab bar for the new document. > */ > -static Widget addTab(Widget folder, const char *string) > +static Widget addTab(Widget folder, const char *string, int isNewTabTab) > { > Widget tooltipLabel, tab; > - XmString s1; > + XmString s1, s2; > > s1 = XmStringCreateSimple((char *)string); > + if (isNewTabTab) > + s2 = XmStringCreateSimple("New Document"); > + else > + s2 = s1; > tab = XtVaCreateManagedWidget("tab", > xrwsBubbleButtonWidgetClass, folder, > /* XmNmarginWidth, <[email protected]>, */ > /* XmNmarginHeight, <[email protected]>, */ > /* XmNalignment, <[email protected]>, */ > XmNlabelString, s1, > - XltNbubbleString, s1, > + XltNbubbleString, s2, > XltNshowBubble, GetPrefToolTips(), > XltNautoParkBubble, True, > XltNslidingBubble, False, > @@ -841,6 +846,8 @@ static Widget addTab(Widget folder, const char *string) > /* XltNbubbleDuration, 8000,*/ > NULL); > XmStringFree(s1); > + if (isNewTabTab) > + XmStringFree(s2); > > /* there's things to do as user click on the tab */ > XtAddEventHandler(tab, ButtonPressMask, False, > @@ -864,6 +871,17 @@ static Widget addTab(Widget folder, const char *string) > AddTabContextMenuAction(tab); > #endif /* LESSTIF_VERSION */ > > + if (!isNewTabTab) { > + WidgetList tabList; > + int tabCount; > + Widget t; > + XtVaGetValues(folder, XmNtabWidgetList, &tabList, > + XmNtabCount, &tabCount, NULL); > + t = tabList[tabCount - 1]; > + tabList[tabCount - 1] = tabList[tabCount - 2]; > + tabList[tabCount - 2] = t; > + } > + > return tab; > } > > @@ -915,7 +933,7 @@ void SortTabBar(WindowInfo *window) > XtVaGetValues(window->tabBar, XmNtabWidgetList, &tabList, > XmNtabCount, &tabCount, NULL); > > - for (i=0, j=0; i<tabCount && j<nDoc; i++) { > + for (i=0, j=0; i<(tabCount-1) && j<nDoc; i++) { > if (tabList[i]->core.being_destroyed) > continue; > > @@ -2500,7 +2518,7 @@ static void saveYourselfCB(Widget w, Widget appShell, XtPointer callData) > XtVaGetValues(topWin->tabBar, XmNtabWidgetList, &tabs, > XmNtabCount, &tabCount, NULL); > > - for (i=0; i< tabCount; i++) { > + for (i=0; i< (tabCount-1); i++) { > win = TabToWindow(tabs[i]); > if (win->filenameSet) { > /* add filename */ > @@ -3441,7 +3459,7 @@ WindowInfo* CreateDocument(WindowInfo* shellWindow, const char* name) > /* Set the requested hardware tab distance and useTabs in the text buffer */ > BufSetTabDistance(window->buffer, GetPrefTabDist(PLAIN_LANGUAGE_MODE)); > window->buffer->useTabs = GetPrefInsertTabs(); > - window->tab = addTab(window->tabBar, name); > + window->tab = addTab(window->tabBar, name, False); > > /* add the window to the global window list, update the Windows menus */ > InvalidateWindowMenus(); > @@ -3514,7 +3532,7 @@ static WindowInfo *getNextTabWindow(WindowInfo *window, int direction, > XtVaGetValues(win->tabBar, XmNtabWidgetList, &tabList, > XmNtabCount, &tabCount, NULL); > > - for (i=0; i< tabCount; i++) { > + for (i=0; i< (tabCount-1); i++) { > tabs[tabTotalCount++] = tabList[i]; > } > } > @@ -3524,7 +3542,7 @@ static WindowInfo *getNextTabWindow(WindowInfo *window, int direction, > XtVaGetValues(window->tabBar, XmNtabWidgetList, &tabList, > XmNtabCount, &tabCount, NULL); > > - for (i=0; i< tabCount; i++) { > + for (i=0; i< (tabCount-1); i++) { > if (TabToWindow(tabList[i])) /* make sure tab is valid */ > tabs[tabTotalCount++] = tabList[i]; > } > @@ -3572,7 +3590,7 @@ static int getTabPosition(Widget tab) > XtVaGetValues(tabBar, XmNtabWidgetList, &tabList, > XmNtabCount, &tabCount, NULL); > > - for (i=0; i< tabCount; i++) { > + for (i=0; i< (tabCount-1); i++) { > if (tab == tabList[i]) > return i; > } > @@ -4690,10 +4708,20 @@ static void raiseTabCB(Widget w, XtPointer clientData, XtPointer callData) > XmLFolderCallbackStruct *cbs = (XmLFolderCallbackStruct *)callData; > WidgetList tabList; > Widget tab; > + int tabCount; > > - XtVaGetValues(w, XmNtabWidgetList, &tabList, NULL); > - tab = tabList[cbs->pos]; > - RaiseDocument(TabToWindow(tab)); > + XtVaGetValues(w, XmNtabWidgetList, &tabList, XmNtabCount, &tabCount, NULL); > + if (cbs->pos < (tabCount-1)) { > + tab = tabList[cbs->pos]; > + RaiseDocument(TabToWindow(tab)); > + } else { > + WindowInfo *window = lastFocusDocument; > + if (!window) > + window = TabToWindow(tabList[cbs->pos - 2]); > + EditNewFile(window, NULL, False, NULL, window->path, False); > + CheckCloseDim(); > + cbs->allowActivate = 0; > + } > } > > static Widget containingPane(Widget w) > -- > tg: (58cda00..) bw/newTabTab (depends on: master) > -- > NEdit Discuss mailing list - [email protected] > http://www.nedit.org/mailman/listinfo/discuss > -- NEdit Discuss mailing list - [email protected] http://www.nedit.org/mailman/listinfo/discuss