Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Add "open in new window" option to tabs context menu #134

Merged
merged 27 commits into from
Mar 11, 2016

Conversation

davidgross
Copy link
Contributor

This creates a workaround for #39

I have added a context menu option for opening a tab in a new window.

I placed it in the "reveal in treeview, reopen closed tab" section, below the split section.

It just spawns a new atom session, and then opens the file in question, and closes it in the current(old) window.

It will prompt the user to save the file before closing the tab in the old window, if there are unsaved changes.

tab-bar-view coffee - -home-grosda-work-atom-tabs - atom_003

This is still a work in progress...

This allows a user to open a file in a new tab.

*However* it simply opens the file, so if the file to be opened in a new
window has un-saved changes, it will prompt the user to save their
changes before it completes.
@davidgross davidgross changed the title 🐛 Add "open this in new window" option to tabs context menu Add "open this in new window" option to tabs context menu Apr 27, 2015

{type: 'separator'}

{label: 'Open this tab in new window', command: 'tabs:open-tab-in-new-window'}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind title-casing this to match the other commands?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, done.

@davidgross
Copy link
Contributor Author

The other thing not in this, is a jasmine test to confirm that the button actually works. I have not written tests with that before, it seems that the open window button is not tested in the tree view, which is what I based my "Open Tab In New Window" button on. And a grep in the atom repo didn't result in anything that helped me either(it may be there, I just didn't find it).

@davidgross
Copy link
Contributor Author

Oh, and the name of the button, it feels poorly worded to me, but it was the best I could come up with. If there is a more succinct way of working it, I am happy to change it.

@lee-dohm
Copy link
Contributor

@davidgross I think you can just call it "Open In New Window", since they have already clicked the tab to get the context menu, yes? That would be the same title as is used when right-clicking a file in the Tree View.

@davidgross
Copy link
Contributor Author

@lee-dohm Yeah, that makes sense, doing that now.

@@ -24,6 +24,7 @@ class TabBarView extends View
'tabs:split-down': => @splitTab('splitDown')
'tabs:split-left': => @splitTab('splitLeft')
'tabs:split-right': => @splitTab('splitRight')
'tabs:open-tab-in-new-window': => @openTabInNewWindow()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind renaming this to tabs:open-in-new-window to match the new context menu entry name?

@mnquintana mnquintana self-assigned this May 2, 2015
@mnquintana
Copy link
Contributor

Other than the one comment, would you mind adding some specs for this?

@davidgross
Copy link
Contributor Author

@mnquintana Sorry...apparently I am not getting email about this, I just happened to check this page, and see the comments.

Do you mean "specs" as in the tests? or specs as in more detail on what this does? ( I assume the tests?)

I changed the tabs command name.

@mnquintana
Copy link
Contributor

@davidgross Sorry, yup, specs meaning tests. Thanks!

@davidgross
Copy link
Contributor Author

@mnquintana tests added, hopefully they work like I think they do.

@davidgross davidgross changed the title Add "open this in new window" option to tabs context menu Add "open in new window" option to tabs context menu May 7, 2015
itemURI = item.getPath() ? ''
else if typeof item.getUri is 'function'
itemURI = item.getUri() ? ''
atom.open({pathsToOpen: [itemURI], newWindow: true})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A tab could have non of above functions (getURI, getPath, getUri). Wouldn't it better to check if itemURI has a value before closing the existing tab and opening a new window with maybe empty paths...

cc @mnquintana

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jerone did you mean something like this?

openInNewWindow: (tab) ->
    tab ?= @children('.right-clicked')[0]
    item = tab.item
    return unless item?
    if typeof item.getURI is 'function'
      itemURI = item.getURI() ? ''
    else if typeof item.getPath is 'function'
      itemURI = item.getPath() ? ''
    else if typeof item.getUri is 'function'
      itemURI = item.getUri() ? ''
    return unless itemURI?
    atom.open({pathsToOpen: [itemURI], newWindow: true})
    @closeTab(tab)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidgross commented on 12 mei 2015 20:10 CEST:

@jerone did you mean something like this?

Yeah.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ? '' might be redundant then.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I stole that from onDragStart.....

updated openInNewWindow path logic to confirm valid path before closing tab
and opening new window with that path.
@mnquintana mnquintana removed their assignment Mar 10, 2016
@davidgross
Copy link
Contributor Author

Oh, hold it, I mis-read what you said, I thought you were using the 'open in new tab' on the TreeView on the left side.

@lee-dohm
Copy link
Contributor

Ok cool ... was just typing up some new repro steps 😆

@davidgross
Copy link
Contributor Author

Ok, I am reproducing that.

The reason that is happening is I am calling atom.open, and passing two 'pathsToOpen' strings, in an array.
specifically, atom.project.getPaths() and itemURI

see:
https://github.com/davidgross/tabs/blob/master/lib/tab-bar-view.coffee#L161-L162

I am currently seeing if I can make that behavior change....

@davidgross
Copy link
Contributor Author

ok, so it looks like I would need to be able to set the project path separately, and I am not sure I can do that from the atom.open() call.

atom iself or tree-view is trying to be smart, and open the project paths related to the pathsToOpen,

so when I pass both, it sets the project as the atom.project.getPaths(), and then adds another project for the parent directory of the itemURI that I am passing....

Thoughts?

@lee-dohm
Copy link
Contributor

Ok, I was afraid of that 😀 I think a modification to atom.open will need to be created. I'll poke around a little bit on this and if everything looks good, I'll merge it tonight.

@danielbayley
Copy link

so when I pass both, it sets the project as the atom.project.getPaths(), and then adds another project for the parent directory of the itemURI that I am passing…

I think I have this exact same problem in my modular-keymaps package.

lee-dohm added a commit that referenced this pull request Mar 11, 2016
Add "open in new window" option to tabs context menu
@lee-dohm lee-dohm merged commit aa18d9f into atom:master Mar 11, 2016
@lee-dohm
Copy link
Contributor

Thanks for your amazing perseverance @davidgross 😀

@OneHoopyFrood
Copy link

This is a good workaround, but doesn't really fix #39. Please don't forget about this feature!

@NicoHood
Copy link

NicoHood commented Apr 19, 2016

I agree.
I've tested the latest beta and the feature aimed in the PR works great, however it would be more intuitive to drop the tab somewhere else and a now windows will pop up.

Also if you open a new windows and move another tab to the new windows, it does not disappear on the old. But if you split the screen (in a single window) it does. So the moved tab should also disappear. This is a new bug.

@davidgross
Copy link
Contributor Author

I agree with you ( @colepanike and @NicoHood ).

However, because of the limitations in Atom itself(not the tabs plugin) that is not possible(or I could not find a way to make it happen), for now, I keep hoping they will add a mouseDragOutOfWindow type event that will allow drag-and-drop-in-new-window type actions, they have added a lot of stuff to the atom api, I think it is getting closer.

Also, once you have a new window open, you can drag tabs between windows(you probably already knew that...but there it is anyway).

@NicoHood
Copy link

NicoHood commented Apr 19, 2016

We then should open a new issue for this feature request and then link issue #39 with this feature.

I think you missed my edit while typing your answer. Please reread the 2nd part of my answer :)

@davidgross
Copy link
Contributor Author

@NicoHood indeed :)

And you are right about that bug, I'll look into that.

@davidgross
Copy link
Contributor Author

@NicoHood
That is not a new bug, looks like it is un-related to my open-in-new-window method, we should open a separate issue for that, probably(unless there is one, in which case I did not see it in a cursory look a the current issues).

@NicoHood
Copy link

Go ahead, I think you can give the error description more details than me.

@OneHoopyFrood
Copy link

OneHoopyFrood commented Apr 19, 2016

Agree with previous, and also petition that #39 is not solved and should be re-opened.
(It's locked, or I'd comment there)

@lee-dohm
Copy link
Contributor

@colepanike #39 isn't closed.

@lee-dohm
Copy link
Contributor

lee-dohm commented Apr 19, 2016

@colepanike @NicoHood #39 isn't closed. The reason it isn't closed is so we don't forget about the feature. Please don't open a new issue that is a duplicate of an existing one, we'll just have to close it.

@OneHoopyFrood
Copy link

Ah, so it isn't. Sorry. Should have looked at current state. I confused the referenced thread closure for the closure of the primary thread.

@davidgross
Copy link
Contributor Author

@lee-dohm is there an existing issue for the 'drag-tab-to-other-window-but-not-closing-original-tab' bug?

@riclf
Copy link

riclf commented May 13, 2016

#39 is locked and no longer open for new comments, so it is not possible to comment there.

I am not reading it exactly as I am imaging it so I'd like to take the opportunity to state it here- On occasion I want to expand my open work on to a second screen. So I'd like to grab an open tab and drag it over to a second screen where it will exist in a new instance of Atom on the second screen. Firefox is a good place to see that working as it should.

Programmatically this is already nearly being done in that you can drag an open tab in one instance to an open instance of Atom on a second screen. So it seems that the logical extension would be to check if an Atom instance in currently open, if not, open one, and receive the tab.

This UX is in recognizing the multi-screen world devs are working in these days.

@davidgross
Copy link
Contributor Author

@riclf that is what this is a work-around for. Atom itself(not the tabs plugin) will need some changes to make drag-tab-out-to-new-window work properly.

@blah238
Copy link

blah238 commented Jun 3, 2016

This does not work with Markdown Preview :(

@tomchambers2
Copy link

I guess its a limitation of this method, but this feature doesn't work if the file is unsaved.

@NicoHood
Copy link

This does not work if you open a new document (ctrl + n) which is not safed yet. It only works for saved docs.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.